Skip to content

Commit

Permalink
Add support for source token info for WH Liquidity Layer (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinoConti authored Feb 6, 2025
1 parent ea3579c commit 812eafd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wormscan-ui",
"version": "2.0.13",
"version": "2.0.14",
"private": true,
"source": "src/index.html",
"@parcel/resolver-default": {
Expand Down
1 change: 1 addition & 0 deletions src/pages/Submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const SubmitYourProtocol = () => {
a.innerHTML?.includes("recipientChain") ||
a.innerHTML?.includes("refundChainId") ||
a.innerHTML?.includes("targetChainId") ||
a.innerHTML?.includes("destinationChain") ||
a.innerHTML?.includes("sourceChainId") ||
a.innerHTML?.includes("destChainId") ||
a.innerHTML?.includes("toChain") ||
Expand Down
58 changes: 50 additions & 8 deletions src/pages/Tx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
IManualCctpResponse,
tryGetAddressInfo,
tryGetWrappedToken,
getLiquidityLayerTokenInfo,
} from "src/utils/cryptoToolkit";
import { getPorticoInfo } from "src/utils/wh-portico-rpc";
import { useRecoilState } from "recoil";
Expand All @@ -56,6 +57,7 @@ import {
GATEWAY_APP_ID,
GR_APP_ID,
IStatus,
LIQUIDITY_LAYER_APP_ID,
MAYAN_MCTP_APP_ID,
NTT_APP_ID,
PORTAL_APP_ID,
Expand Down Expand Up @@ -122,7 +124,7 @@ const Tx = () => {
const { data: chainLimitsData, isLoading: isLoadingLimits } = useQuery(["getLimit"], () =>
getClient()
.governor.getLimit()
.catch(() => null),
.catch((): null => null),
);

const cancelRequests = useRef(false);
Expand Down Expand Up @@ -275,7 +277,7 @@ const Tx = () => {
}
return null;
})
.catch(() => {
.catch((): null => {
return null;
});

Expand All @@ -294,7 +296,7 @@ const Tx = () => {
}
return null;
})
.catch(() => {
.catch((): null => {
return null;
});

Expand Down Expand Up @@ -331,19 +333,18 @@ const Tx = () => {
let solanaResponse: IManualCctpResponse | null;
let suiResponse: IManualCctpResponse | null;
let aptosResponse: IManualCctpResponse | null;

if (canBeSolanaTxHash) {
solanaResponse = await getSolanaCctp(network, txHash).catch(() => null);
solanaResponse = await getSolanaCctp(network, txHash).catch((): null => null);
suiResponse = solanaResponse
? null
: await getSuiCctp(network, txHash).catch(() => null);
: await getSuiCctp(network, txHash).catch((): null => null);
aptosResponse = null;
}

if (isEvmTxHash) {
solanaResponse = null;
suiResponse = null;
aptosResponse = await getAptosCctp(network, txHash).catch(() => null);
aptosResponse = await getAptosCctp(network, txHash).catch((): null => null);
}

const resp: IManualCctpResponse = solanaResponse || suiResponse || aptosResponse;
Expand Down Expand Up @@ -668,6 +669,47 @@ const Tx = () => {
}
// ----

// check Wormhole Liquidity Layer
if (data?.content?.standarizedProperties?.appIds?.includes(LIQUIDITY_LAYER_APP_ID)) {
if (data.content.payload?.payloadId === 11) {
const liquidityLayerTokenInfo = await getLiquidityLayerTokenInfo(
network,
data.sourceChain?.transaction?.txHash,
data.sourceChain?.chainId,
);

if (liquidityLayerTokenInfo) {
if (liquidityLayerTokenInfo.type === "SwapAndForwardedEth") {
data.data = {
symbol:
network === "Testnet"
? testnetNativeCurrencies[chainIdToChain(data.sourceChain?.chainId)]
: mainnetNativeCurrencies[chainIdToChain(data.sourceChain?.chainId)],
tokenAmount: String(+liquidityLayerTokenInfo.amountIn / 10 ** 18),
usdAmount: "",
};
}

if (
liquidityLayerTokenInfo.type === "ForwardedERC20" ||
liquidityLayerTokenInfo.type === "SwapAndForwardedERC20"
) {
data.data = {
symbol: liquidityLayerTokenInfo.symbol,
tokenAmount: String(
+liquidityLayerTokenInfo.amountIn / 10 ** liquidityLayerTokenInfo.decimals,
),
usdAmount: "",
};

data.content.standarizedProperties.tokenAddress = liquidityLayerTokenInfo.token;
data.content.standarizedProperties.tokenChain = data.sourceChain?.chainId;
}
}
}
}
// ----

// Check Standard Relayer
if (data?.content?.standarizedProperties?.appIds?.includes(GR_APP_ID)) {
// TODO: handle generic relayer non-vaa txns without rpcs (shows no amount)
Expand Down Expand Up @@ -1197,7 +1239,7 @@ const Tx = () => {
}
// ----

// check Mayan
// check Mayan MCTP
if (data?.content?.standarizedProperties?.appIds?.includes(MAYAN_MCTP_APP_ID)) {
if (data?.content?.payload?.action === 1 || data?.content?.payload?.action === 3) {
try {
Expand Down
1 change: 1 addition & 0 deletions src/pages/VaaParser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const VaaParser = () => {
a.innerHTML?.includes("recipientChain") ||
a.innerHTML?.includes("refundChainId") ||
a.innerHTML?.includes("targetChainId") ||
a.innerHTML?.includes("destinationChain") ||
a.innerHTML?.includes("sourceChainId") ||
a.innerHTML?.includes("destChainId") ||
a.innerHTML?.includes("toChain") ||
Expand Down
35 changes: 35 additions & 0 deletions src/utils/cryptoToolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ interface IGeckoTokenInfoResponse {
};
}

interface ILiquidityLayerTokenInfoResponse {
type:
| "ForwardedERC20"
| "SwapAndForwardedERC20"
| "SwapAndForwardedEth"
| "SwapAndForwardedERC20";
token?: string;
amountIn?: string;
swapProtocol?: string;
middleToken?: string;
middleAmount?: string;
mayanProtocol?: string;
mayanData?: string;
symbol?: string;
decimals?: number;
}

const BFF_URL = process.env.WORMSCAN_BFF_URL;

export const getGeckoTokenInfo = async (
Expand All @@ -77,6 +94,24 @@ export const getGeckoTokenInfo = async (
}
};

export const getLiquidityLayerTokenInfo = async (
network: Network,
txHash: string,
chainId: ChainId,
) => {
try {
const liquidityLayerTokenInfoRequest = await fetchWithTimeout(
`${BFF_URL}/fastTransfers/getInfo?network=${network}&txHash=${txHash}&chainId=${chainId}`,
);

const liquidityLayerTokenInfoResponse =
(await liquidityLayerTokenInfoRequest.json()) as ILiquidityLayerTokenInfoResponse;
return liquidityLayerTokenInfoResponse;
} catch (e) {
return null;
}
};

export const getCoinMarketCapTokenInfo = async (symbol: string): Promise<any> => {
try {
const coinMarketCapTokenInfoRequest = await fetchWithTimeout(
Expand Down

0 comments on commit 812eafd

Please sign in to comment.