Skip to content

Commit

Permalink
feat(ui): Add Wormhole transfer models
Browse files Browse the repository at this point in the history
  • Loading branch information
wormat committed Oct 13, 2022
1 parent 978118d commit f11f9da
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/ui/src/models/wormhole/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./formatWormholeAddress";
export * from "./getWrappedTokenInfo";
export * from "./guardiansRpc";
export * from "./solana";
export * from "./transfer";
57 changes: 57 additions & 0 deletions apps/ui/src/models/wormhole/transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { ChainId } from "@certusone/wormhole-sdk";
import type { WrappedTokenInfo } from "@swim-io/core";
import { findOrThrow } from "@swim-io/utils";
import type Decimal from "decimal.js";

import { ECOSYSTEM_LIST } from "../../config";

import { formatWormholeAddress } from "./formatWormholeAddress";

export interface TxResult {
readonly chainId: ChainId;
readonly txId: string;
}

export interface WormholeTokenDetails {
readonly chainId: ChainId;
readonly address: string;
readonly decimals: number;
}

export interface WormholeToken {
readonly symbol: string;
readonly displayName: string;
readonly logo: string;
readonly coinGeckoId: string;
readonly nativeDetails: WormholeTokenDetails;
readonly wrappedDetails: readonly WormholeTokenDetails[];
}

export interface WormholeTransfer {
readonly interactionId: string;
readonly value: Decimal;
readonly sourceDetails: WormholeTokenDetails;
readonly targetDetails: WormholeTokenDetails;
readonly nativeDetails: WormholeTokenDetails;
readonly onTxResult: (txResult: TxResult) => any;
}

export const getWrappedTokenInfoFromNativeDetails = (
sourceChainId: ChainId,
nativeDetails: WormholeTokenDetails,
): WrappedTokenInfo | undefined => {
if (sourceChainId === nativeDetails.chainId) {
return undefined;
}
const nativeEcosystem = findOrThrow(
ECOSYSTEM_LIST,
(ecosystem) => ecosystem.wormholeChainId === nativeDetails.chainId,
);
return {
originAddress: formatWormholeAddress(
nativeEcosystem.protocol,
nativeDetails.address,
),
originChainId: nativeDetails.chainId,
};
};

0 comments on commit f11f9da

Please sign in to comment.