From e3fc53aa26612036b5a2f1d453d2061fcf45a2d2 Mon Sep 17 00:00:00 2001 From: perfogic Date: Fri, 6 Sep 2024 15:34:55 +0700 Subject: [PATCH] feat: add usdc --- components/page/bridge/hooks/useGetFee.ts | 19 +++++++++++++++++-- constants/contract.ts | 11 +++++++++++ constants/tokens.ts | 23 +++++++++++++++++++++-- hooks/useLoadToken.ts | 3 +++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/components/page/bridge/hooks/useGetFee.ts b/components/page/bridge/hooks/useGetFee.ts index e41d4bc..8eedec3 100644 --- a/components/page/bridge/hooks/useGetFee.ts +++ b/components/page/bridge/hooks/useGetFee.ts @@ -5,6 +5,7 @@ import { useAuthOraiAddress } from "@/stores/authentication/selector"; import { BigDecimal } from "@oraichain/oraidex-common"; import { TonbridgeBridgeClient } from "@oraichain/tonbridge-contracts-sdk"; import { useEffect, useState } from "react"; +import { MappingJettonWalletAddress } from "@/constants/contract"; const useGetFee = ({ token }: { token: TokenType }) => { const oraiAddress = useAuthOraiAddress(); @@ -29,8 +30,22 @@ const useGetFee = ({ token }: { token: TokenType }) => { network.CW_TON_BRIDGE ); + // TODO: change to jetton wallet address of bridge adapter instead + + console.log( + MappingJettonWalletAddress[tokenInTon?.contractAddress] == + "EQAacZPtQpnIHS1PlQgVaceb_I4v2HE3rvrZC91ynSRqXd9d" + ); + if ( + MappingJettonWalletAddress[tokenInTon?.contractAddress] == + "EQAacZPtQpnIHS1PlQgVaceb_I4v2HE3rvrZC91ynSRqXd9d" + ) { + setTokenFee(15); + return; + } const tokenFeeConfig = await tonBridgeClient.tokenFee({ - remoteTokenDenom: tokenInTon?.contractAddress, + remoteTokenDenom: + MappingJettonWalletAddress[tokenInTon?.contractAddress], }); if (tokenFeeConfig) { @@ -71,7 +86,7 @@ const useGetFee = ({ token }: { token: TokenType }) => { ); const config = await tonBridgeClient.pairMapping({ - key: tokenInTon?.contractAddress, + key: MappingJettonWalletAddress[tokenInTon?.contractAddress], }); const pairMapping = config.pair_mapping; diff --git a/constants/contract.ts b/constants/contract.ts index cef3b9e..f4063dc 100644 --- a/constants/contract.ts +++ b/constants/contract.ts @@ -24,21 +24,32 @@ export const TonInteractionContract = { export const TonTokensContract = { [Environment.Mainnet]: { usdt: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs", + jUSDC: "EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728", // jUSDT: "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA", ton: TON_ZERO_ADDRESS, }, [Environment.Staging]: { usdt: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs", jUSDT: "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA", + jUSDC: "EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728", ton: TON_ZERO_ADDRESS, }, [Environment.Testnet]: { usdt: "EQA5FnPP13uZPJQq7aj6UHLEukJJZSZW053cU1Wu6R6BpYYB", jUSDT: "EQA5FnPP13uZPJQq7aj6UHLEukJJZSZW053cU1Wu6R6BpYYB", + jUSDC: "EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728", ton: TON_ZERO_ADDRESS, }, }; +export const MappingJettonWalletAddress = { + "EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728": + "EQAacZPtQpnIHS1PlQgVaceb_I4v2HE3rvrZC91ynSRqXd9d", + EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs: + "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs", + EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c: TON_ZERO_ADDRESS, +}; + export const CwInteractionContract = { [Environment.Mainnet]: { cosmwasmBridge: diff --git a/constants/tokens.ts b/constants/tokens.ts index 81c0c59..291f58b 100644 --- a/constants/tokens.ts +++ b/constants/tokens.ts @@ -1,7 +1,7 @@ import { Environment } from "./ton"; import { TonTokensContract } from "./contract"; -import { UsdtIcon, TetherIcon } from "@/assets/icons/token"; -import { USDT_CONTRACT } from "@oraichain/oraidex-common"; +import { UsdtIcon, TetherIcon, UsdcIcon } from "@/assets/icons/token"; +import { USDC_CONTRACT, USDT_CONTRACT } from "@oraichain/oraidex-common"; import { TonNetworkICon } from "@/assets/icons/network"; export type TokenType = { @@ -28,6 +28,16 @@ export const OraichainTokenList: TokenType[] = [ coingeckoId: "tether", decimal: 6, }, + { + chainId: "Oraichain", + name: "USD Coin", + symbol: "USDC", + Icon: UsdcIcon, + contractAddress: USDC_CONTRACT, + denom: "usdc", + coingeckoId: "bridged-usd-coin-ton-bridge", + decimal: 6, + }, // { // chainId: "Oraichain", // name: "Tether", @@ -82,6 +92,15 @@ export const TonTokenList = (network: Environment): TokenType[] => [ coingeckoId: "tether", decimal: 6, }, + { + name: "USD Coin", + symbol: "USDC", + Icon: UsdcIcon, + contractAddress: TonTokensContract[network]?.jUSDC, + denom: "ton20_usdc", + coingeckoId: "bridged-usd-coin-ton-bridge", + decimal: 6, + }, // { // name: "Jetton USDT", // symbol: "jUSDT", diff --git a/hooks/useLoadToken.ts b/hooks/useLoadToken.ts index 1be0a5c..de055ae 100644 --- a/hooks/useLoadToken.ts +++ b/hooks/useLoadToken.ts @@ -274,6 +274,9 @@ export const useLoadTonBalance = ({ const token = TonTokenList(tonNetwork).find( (e) => e.contractAddress === data.token ); + console.log({ + data: data, + }); amountDetail = { ...amountDetail,