Skip to content

Commit

Permalink
refactor(ui): Remove WormholeChainId and use library export
Browse files Browse the repository at this point in the history
  • Loading branch information
wormat committed Aug 17, 2022
1 parent 6996bc4 commit 133f49c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 54 deletions.
22 changes: 11 additions & 11 deletions apps/ui/src/config/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ChainId as WormholeChainId } from "@certusone/wormhole-sdk";
import { CHAINS as WORMHOLE_CHAIN_ID } from "@certusone/wormhole-sdk";
import type { ReadonlyRecord } from "@swim-io/utils";
import { filterMap } from "@swim-io/utils";

Expand All @@ -11,8 +13,6 @@ import KARURA_SVG from "../images/ecosystems/karura.svg";
import POLYGON_SVG from "../images/ecosystems/polygon.svg";
import SOLANA_SVG from "../images/ecosystems/solana.svg";

import { WormholeChainId } from "./wormhole";

export const enum Protocol {
Solana = "solana-protocol",
Evm = "evm",
Expand Down Expand Up @@ -110,71 +110,71 @@ export const ECOSYSTEM_LIST: readonly Ecosystem[] = [
{
id: EcosystemId.Solana,
protocol: Protocol.Solana,
wormholeChainId: WormholeChainId.Solana,
wormholeChainId: WORMHOLE_CHAIN_ID.solana,
displayName: "Solana",
logo: SOLANA_SVG,
nativeTokenSymbol: "SOL",
},
{
id: EcosystemId.Ethereum,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Ethereum,
wormholeChainId: WORMHOLE_CHAIN_ID.ethereum,
displayName: "Ethereum",
logo: ETHEREUM_SVG,
nativeTokenSymbol: "ETH",
},
{
id: EcosystemId.Bnb,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Bnb,
wormholeChainId: WORMHOLE_CHAIN_ID.bsc,
displayName: "BNB Chain",
logo: BNB_SVG,
nativeTokenSymbol: "BNB",
},
{
id: EcosystemId.Avalanche,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Avalanche,
wormholeChainId: WORMHOLE_CHAIN_ID.avalanche,
displayName: "Avalanche",
logo: AVALANCHE_SVG,
nativeTokenSymbol: "AVAX",
},
{
id: EcosystemId.Polygon,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Polygon,
wormholeChainId: WORMHOLE_CHAIN_ID.polygon,
displayName: "Polygon",
logo: POLYGON_SVG,
nativeTokenSymbol: "MATIC",
},
{
id: EcosystemId.Aurora,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Aurora,
wormholeChainId: WORMHOLE_CHAIN_ID.aurora,
displayName: "Aurora",
logo: AURORA_SVG,
nativeTokenSymbol: "ETH",
},
{
id: EcosystemId.Fantom,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Fantom,
wormholeChainId: WORMHOLE_CHAIN_ID.fantom,
displayName: "Fantom",
logo: FANTOM_SVG,
nativeTokenSymbol: "FTM",
},
{
id: EcosystemId.Karura,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Karura,
wormholeChainId: WORMHOLE_CHAIN_ID.karura,
displayName: "Karura",
logo: KARURA_SVG,
nativeTokenSymbol: "KAR",
},
{
id: EcosystemId.Acala,
protocol: Protocol.Evm,
wormholeChainId: WormholeChainId.Acala,
wormholeChainId: WORMHOLE_CHAIN_ID.acala,
displayName: "Acala",
logo: ACALA_SVG,
nativeTokenSymbol: "ACA",
Expand Down
1 change: 0 additions & 1 deletion apps/ui/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export * from "./ecosystem";
export * from "./pools";
export * from "./tokens";
export * from "./utils";
export * from "./wormhole";

export interface Config {
readonly ecosystems: ReadonlyRecord<EcosystemId, Ecosystem>;
Expand Down
18 changes: 0 additions & 18 deletions apps/ui/src/config/wormhole.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getEmitterAddressSolana } from "@certusone/wormhole-sdk";
import {
CHAINS as WORMHOLE_CHAIN_ID,
getEmitterAddressSolana,
} from "@certusone/wormhole-sdk";
import type { AccountInfo as TokenAccount } from "@solana/spl-token";
import type { Transaction } from "@solana/web3.js";
import { findOrThrow, isEachNotNull } from "@swim-io/utils";
Expand All @@ -9,7 +12,6 @@ import {
ECOSYSTEMS,
EcosystemId,
Protocol,
WormholeChainId,
getSolanaTokenDetails,
getTokenDetailsForEcosystem,
} from "../../config";
Expand Down Expand Up @@ -238,7 +240,7 @@ export const useFromSolanaTransferMutation = () => {
);
const vaaBytesResponse = await getSignedVaaWithRetry(
[...wormhole.rpcUrls],
WormholeChainId.Solana,
WORMHOLE_CHAIN_ID.solana,
emitterAddress,
sequence,
undefined,
Expand Down
5 changes: 3 additions & 2 deletions apps/ui/src/models/wormhole/attestation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CHAINS as WORMHOLE_CHAIN_ID,
attestFromEth,
attestFromSolana,
createWrappedOnEth,
Expand All @@ -13,7 +14,7 @@ import type { WormholeConfig } from "@swim-io/core";
import type { ContractReceipt } from "ethers";

import type { EvmSpec, WormholeChainSpec } from "../../config";
import { ECOSYSTEMS, EcosystemId, WormholeChainId } from "../../config";
import { ECOSYSTEMS, EcosystemId } from "../../config";
import type { SolanaConnection } from "../solana";
import { DEFAULT_MAX_RETRIES } from "../solana";
import type { EvmWalletAdapter, SolanaWalletAdapter } from "../wallets";
Expand Down Expand Up @@ -99,7 +100,7 @@ export const setUpSplTokensOnEvm = async (
attestations.map(({ emitterAddress, sequence }) =>
getSignedVaaWithRetry(
[...rpcUrls],
WormholeChainId.Solana,
WORMHOLE_CHAIN_ID.solana,
emitterAddress,
sequence,
),
Expand Down
9 changes: 6 additions & 3 deletions apps/ui/src/models/wormhole/evm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { getAllowanceEth } from "@certusone/wormhole-sdk";
import {
CHAINS as WORMHOLE_CHAIN_ID,
getAllowanceEth,
} from "@certusone/wormhole-sdk";
import { PublicKey } from "@solana/web3.js";
import type { ethers } from "ethers";

import type { TokenSpec, WormholeChainSpec } from "../../config";
import { WormholeChainId, getTokenDetailsForEcosystem } from "../../config";
import { getTokenDetailsForEcosystem } from "../../config";
import type { EvmTx } from "../crossEcosystem";

import { approveEth, transferFromEth } from "./overrides";
Expand Down Expand Up @@ -114,7 +117,7 @@ export const lockEvmToken = async ({
evmSigner,
evmTokenDetails.address,
transferAmountAtomicString,
WormholeChainId.Solana,
WORMHOLE_CHAIN_ID.solana,
new PublicKey(splTokenAccountAddress).toBytes(),
);

Expand Down
12 changes: 5 additions & 7 deletions apps/ui/src/models/wormhole/solana.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { ChainId as WormholeChainId } from "@certusone/wormhole-sdk";
import {
CHAINS as WORMHOLE_CHAIN_ID,
chunks,
createPostVaaInstructionSolana,
createVerifySignaturesInstructionsSolana,
Expand All @@ -16,11 +18,7 @@ import { PublicKey } from "@solana/web3.js";
import { createMemoIx } from "@swim-io/solana";

import type { TokenSpec, WormholeChainSpec } from "../../config";
import {
EcosystemId,
WormholeChainId,
getSolanaTokenDetails,
} from "../../config";
import { EcosystemId, getSolanaTokenDetails } from "../../config";
import type { SolanaTx } from "../crossEcosystem";
import type { SolanaConnection } from "../solana";
import {
Expand Down Expand Up @@ -185,7 +183,7 @@ export async function* generateUnlockSplTokenTxIds(
throw new Error("No Solana public key");
}
const retries =
wormholeChainId === WormholeChainId.Polygon
wormholeChainId === WORMHOLE_CHAIN_ID.polygon
? POLYGON_WORMHOLE_RETRIES
: DEFAULT_WORMHOLE_RETRIES;
const { vaaBytes } = await getSignedVaaWithRetry(
Expand Down Expand Up @@ -238,7 +236,7 @@ export const unlockSplToken = async (
throw new Error("No Solana public key");
}
const retries =
wormholeChainId === WormholeChainId.Polygon
wormholeChainId === WORMHOLE_CHAIN_ID.polygon
? POLYGON_WORMHOLE_RETRIES
: DEFAULT_WORMHOLE_RETRIES;
const { vaaBytes } = await getSignedVaaWithRetry(
Expand Down
17 changes: 8 additions & 9 deletions apps/ui/src/pages/TestPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion, i18next/no-literal-string */
import { approveEth, getForeignAssetEth } from "@certusone/wormhole-sdk";
import {
CHAINS as WORMHOLE_CHAIN_ID,
approveEth,
getForeignAssetEth,
} from "@certusone/wormhole-sdk";
import {
EuiButton,
EuiCheckbox,
Expand All @@ -25,12 +29,7 @@ import shallow from "zustand/shallow.js";

import { ConnectButton } from "../components/ConnectButton";
import type { EvmEcosystemId } from "../config";
import {
EcosystemId,
Protocol,
WormholeChainId,
getSolanaTokenDetails,
} from "../config";
import { EcosystemId, Protocol, getSolanaTokenDetails } from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment, useNotification } from "../core/store";
import {
Expand Down Expand Up @@ -372,7 +371,7 @@ const TestPage = (): ReactElement => {
const foreignAsset = await getForeignAssetEth(
ethereumChain.wormhole.tokenBridge,
evmConnections[EcosystemId.Ethereum].provider,
WormholeChainId.Solana,
WORMHOLE_CHAIN_ID.solana,
wormholeAsset,
);
console.info(`${token}: ${String(foreignAsset)}`);
Expand All @@ -389,7 +388,7 @@ const TestPage = (): ReactElement => {
const foreignAsset = await getForeignAssetEth(
bnbChain.wormhole.tokenBridge,
evmConnections[EcosystemId.Bnb].provider,
WormholeChainId.Solana,
WORMHOLE_CHAIN_ID.solana,
wormholeAsset,
);
console.info(`${token}: ${String(foreignAsset)}`);
Expand Down

0 comments on commit 133f49c

Please sign in to comment.