From 517bf53b5e9f93c02286e0a6e258000b2731df13 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 18 Dec 2024 17:13:05 +1000 Subject: [PATCH 01/35] feat: Aggregate Meson API --- .../token-config/mainnet/useTransferConfig.ts | 8 +++++--- .../src/core/constants/index.ts | 4 ++++ .../aggregator/adapters/meson/MesonAdapter.ts | 13 +++++++++---- .../src/modules/aggregator/adapters/meson/types.ts | 2 ++ .../src/modules/aggregator/index.ts | 1 + 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts b/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts index aab46a77..f9c81db6 100644 --- a/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts +++ b/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts @@ -3,26 +3,28 @@ import { ICBridgeTransferConfig, IDeBridgeTransferConfig, ITransferConfig, + IMesonChain, } from '@bnb-chain/canonical-bridge-widget'; import axios from 'axios'; import { env } from '@/core/env'; import stargateConfig from '@/token-config/mainnet/stargate/config.json'; import layerZeroConfig from '@/token-config/mainnet/layerZero/config.json'; -import mesonConfig from '@/token-config/mainnet/meson/config.json'; export function useTransferConfig() { const [transferConfig, setTransferConfig] = useState(); useEffect(() => { const initConfig = async () => { - const [cBridgeRes, deBridgeRes] = await Promise.all([ + const [cBridgeRes, deBridgeRes, MesonRes] = await Promise.all([ axios.get<{ data: ICBridgeTransferConfig }>(`${env.SERVER_ENDPOINT}/api/bridge/cbridge`), axios.get<{ data: IDeBridgeTransferConfig }>(`${env.SERVER_ENDPOINT}/api/bridge/debridge`), + axios.get<{ data: IMesonChain[] }>(`${env.SERVER_ENDPOINT}/api/bridge/meson`), ]); const cBridgeConfig = cBridgeRes.data.data; const deBridgeConfig = handleDeBridgeConfig(deBridgeRes.data.data); + const mesonConfig = MesonRes.data.data; const transferConfig: ITransferConfig = { defaultSelectedInfo: { @@ -172,7 +174,7 @@ export function useTransferConfig() { bridgedTokenGroups: [], }, meson: { - config: mesonConfig.result as any, + config: mesonConfig, exclude: { chains: [], tokens: { 42161: ['SOL'] }, diff --git a/packages/canonical-bridge-widget/src/core/constants/index.ts b/packages/canonical-bridge-widget/src/core/constants/index.ts index 3fcb0064..b5e85a41 100644 --- a/packages/canonical-bridge-widget/src/core/constants/index.ts +++ b/packages/canonical-bridge-widget/src/core/constants/index.ts @@ -51,3 +51,7 @@ export const MIN_SOL_TO_ENABLED_TX = 0.05; export const EVM_NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000'; export const SOLANA_NATIVE_TOKEN_ADDRESS = '11111111111111111111111111111111'; + +export const NON_EVM_CHAIN_ID_MAP = { + tron: 728126428, +}; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts index 8fdd43ae..726e6ab2 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts @@ -3,6 +3,7 @@ import { BridgeType } from '@bnb-chain/canonical-bridge-sdk'; import { BaseAdapter, ITransferTokenPair } from '@/modules/aggregator/shared/BaseAdapter'; import { IMesonChain, IMesonToken } from '@/modules/aggregator/adapters/meson/types'; import { isNativeToken } from '@/core/utils/address'; +import { NON_EVM_CHAIN_ID_MAP } from '@/core/constants'; // const SUPPORTED_CHAIN_IDS = [56, 97, 3448148188, 728126428]; // const SUPPORTED_TOKENS = ['USDT', 'USDC']; @@ -24,7 +25,11 @@ export class MesonAdapter extends BaseAdapter(); filteredChains.forEach((chain) => { - chainMap.set(Number(chain.chainId), chain); + const chainId = + chain.chainId === 'tron' ? NON_EVM_CHAIN_ID_MAP['tron'] : Number(chain.chainId); + if (!!Number(chainId)) { + chainMap.set(chainId, chain); + } }); this.chains = filteredChains; @@ -38,13 +43,13 @@ export class MesonAdapter extends BaseAdapter>(); chains.forEach((chain) => { - const chainId = Number(chain.chainId); + const chainId = chain.chainId === 'tron' ? 728126428 : Number(chain.chainId); const filteredTokens = chain.tokens.filter((token) => { const isExcludedToken = this.checkIsExcludedToken({ excludedList: this.excludedTokens?.[chainId], - tokenSymbol: token?.id?.toUpperCase(), - tokenAddress: token.addr, + tokenSymbol: token?.symbol?.toUpperCase(), + tokenAddress: token.addr ?? '0x0000000000000000000000000000000000000000', }); // native token transfer requires smart contract deployment. Ignore it for now. return !isExcludedToken && !isNativeToken(token.addr); diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/types.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/types.ts index fc107639..1fc30956 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/types.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/types.ts @@ -1,5 +1,7 @@ export interface IMesonToken { id: string; + symbol: string; + name: string; addr: string; decimals: number; min: string; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/index.ts b/packages/canonical-bridge-widget/src/modules/aggregator/index.ts index 8541ef67..2f64b305 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/index.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/index.ts @@ -3,3 +3,4 @@ export * from '@/modules/aggregator/adapters/cBridge/types'; export * from '@/modules/aggregator/adapters/deBridge/types'; export * from '@/modules/aggregator/adapters/layerZero/types'; export * from '@/modules/aggregator/adapters/stargate/types'; +export * from '@/modules/aggregator/adapters/meson/types'; From 1744cd7fa5412f500e167eab8b0054d9302eb3e9 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 18 Dec 2024 19:55:18 +1000 Subject: [PATCH 02/35] feat: Update meson token name, symbol and address --- .../aggregator/adapters/meson/MesonAdapter.ts | 12 ++++++------ .../transfer/components/Button/TransferButton.tsx | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts index 726e6ab2..f0d06df7 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts @@ -59,7 +59,7 @@ export class MesonAdapter extends BaseAdapter()); filteredTokens.forEach((token) => { - symbolMap.get(chainId)?.set(token.id?.toUpperCase(), token); + symbolMap.get(chainId)?.set(token.symbol?.toUpperCase(), token); }); tokenMap.set(chainId, filteredTokens); @@ -85,7 +85,7 @@ export class MesonAdapter extends BaseAdapter Date: Mon, 23 Dec 2024 19:50:24 +1000 Subject: [PATCH 03/35] feat: Stargate token aggregation --- .../token-config/mainnet/useTransferConfig.ts | 8 +- .../src/stargate/index.ts | 2 +- .../src/core/utils/string.ts | 5 + .../adapters/stargate/StargateAdapter.ts | 131 ++++++++++++------ .../stargate/components/StarGateOption.tsx | 4 +- .../adapters/stargate/const/index.ts | 46 +++--- .../stargate/hooks/useGetStarGateFees.ts | 21 +-- .../stargate/hooks/useStargateTransfer.ts | 4 +- .../hooks/useStargateTransferParams.ts | 5 +- .../aggregator/adapters/stargate/types.ts | 18 +-- .../src/modules/aggregator/types.ts | 7 +- .../components/Button/TransferButton.tsx | 14 +- .../transfer/hooks/useLoadingBridgeFees.ts | 2 +- .../transfer/hooks/usePreSelectRoute.ts | 6 +- .../modules/transfer/hooks/useToTokenInfo.ts | 8 +- 15 files changed, 161 insertions(+), 120 deletions(-) diff --git a/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts b/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts index d58da146..d95131c5 100644 --- a/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts +++ b/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts @@ -4,11 +4,11 @@ import { IDeBridgeTransferConfig, ITransferConfig, IMesonChain, + IStargateApiTokenConfig, } from '@bnb-chain/canonical-bridge-widget'; import axios from 'axios'; import { env } from '@/core/env'; -import stargateConfig from '@/token-config/mainnet/stargate/config.json'; import layerZeroConfig from '@/token-config/mainnet/layerZero/config.json'; export function useTransferConfig() { @@ -16,15 +16,19 @@ export function useTransferConfig() { useEffect(() => { const initConfig = async () => { - const [cBridgeRes, deBridgeRes, MesonRes] = await Promise.all([ + const [cBridgeRes, deBridgeRes, StargateRes, MesonRes] = await Promise.all([ axios.get<{ data: ICBridgeTransferConfig }>(`${env.SERVER_ENDPOINT}/api/bridge/cbridge`), axios.get<{ data: IDeBridgeTransferConfig }>(`${env.SERVER_ENDPOINT}/api/bridge/debridge`), + axios.get<{ data: IStargateApiTokenConfig[] }>( + `${env.SERVER_ENDPOINT}/api/bridge/stargate`, + ), axios.get<{ data: IMesonChain[] }>(`${env.SERVER_ENDPOINT}/api/bridge/meson`), ]); const cBridgeConfig = cBridgeRes.data.data; const deBridgeConfig = handleDeBridgeConfig(deBridgeRes.data.data); const mesonConfig = MesonRes.data.data; + const stargateConfig = StargateRes.data.data; const transferConfig: ITransferConfig = { defaultSelectedInfo: { diff --git a/packages/canonical-bridge-sdk/src/stargate/index.ts b/packages/canonical-bridge-sdk/src/stargate/index.ts index d4a7f20a..f6ea108b 100644 --- a/packages/canonical-bridge-sdk/src/stargate/index.ts +++ b/packages/canonical-bridge-sdk/src/stargate/index.ts @@ -297,7 +297,7 @@ export class Stargate { }); if (fromApiTokenAddr.toLowerCase() !== fromTokenAddress.toLowerCase()) { console.log('Stargate from token address not matched'); - console.log('fromBridgeAddress', fromBridgeAddress); + console.log('fromTokenAddress', fromTokenAddress); console.log('from token address in API', fromApiTokenAddr); return false; } diff --git a/packages/canonical-bridge-widget/src/core/utils/string.ts b/packages/canonical-bridge-widget/src/core/utils/string.ts index 78c9278a..9ef19ee7 100644 --- a/packages/canonical-bridge-widget/src/core/utils/string.ts +++ b/packages/canonical-bridge-widget/src/core/utils/string.ts @@ -53,3 +53,8 @@ export function utf8ToHex(utf8Str: any) { export function includesIgnoreCase(strArr: string[], target: string) { return !!strArr?.find((e) => e.toUpperCase() === target?.toUpperCase()); } + +export function capitalizeFirst(text: string) { + if (typeof text !== 'string') return ''; + return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase(); +} diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/StargateAdapter.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/StargateAdapter.ts index 3e26baf4..fbc489be 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/StargateAdapter.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/StargateAdapter.ts @@ -1,32 +1,49 @@ -import { BridgeType } from '@bnb-chain/canonical-bridge-sdk'; +import { BridgeType, IStargateBridgeTokenInfo } from '@bnb-chain/canonical-bridge-sdk'; import { - IStargateTransferConfig, IStargateChain, - IStargateToken, + IStargateApiTokenConfig, } from '@/modules/aggregator/adapters/stargate/types'; import { BaseAdapter, ITransferTokenPair } from '@/modules/aggregator/shared/BaseAdapter'; +import { stargateChainKey } from '@/modules/aggregator/adapters/stargate/const'; +import { capitalizeFirst } from '@/core/utils/string'; export class StargateAdapter extends BaseAdapter< - IStargateTransferConfig, + IStargateApiTokenConfig[], IStargateChain, - IStargateToken + IStargateBridgeTokenInfo > { public bridgeType: BridgeType = 'stargate'; protected initChains() { - const { chains, tokens } = this.config; - - const filteredChains = chains.filter((chain) => { - const hasChainConfig = this.includedChains.includes(chain.chainId); - const isExcludedChain = this.excludedChains.includes(chain.chainId); - const hasToken = tokens[chain.chainId]?.length > 0; - return hasChainConfig && !isExcludedChain && hasToken; + const tokens = this.config; + + const filteredChains: IStargateChain[] = []; + const filteredTokens = tokens.filter((token) => { + const chainId = stargateChainKey[token.chainKey.toUpperCase()]; + if (!!chainId) { + const hasChainConfig = this.includedChains.includes(chainId); + const isExcludedChain = this.excludedChains.includes(chainId); + return hasChainConfig && !isExcludedChain; + } else { + return false; + } }); const chainMap = new Map(); - filteredChains.forEach((chain) => { - chainMap.set(chain.chainId, chain); + filteredTokens.forEach((token) => { + const chainId = stargateChainKey[token.chainKey.toUpperCase()]; + // Do not add duplicate chain + if (!chainMap.get(chainId)) { + chainMap.set(chainId, { + chainId: chainId, + chainName: capitalizeFirst(token.chainName), + }); + filteredChains.push({ + chainId: chainId, + chainName: capitalizeFirst(token.chainName), + }); + } }); this.chains = filteredChains; @@ -34,33 +51,54 @@ export class StargateAdapter extends BaseAdapter< } protected initTokens() { - const { tokens } = this.config; + const tokens = this.config; - const tokenMap = new Map(); - const symbolMap = new Map>(); - Object.entries(tokens).forEach(([id, chainTokens]) => { - const chainId = Number(id); - - const filteredTokens = chainTokens.filter((token) => { + const tokenMap = new Map(); + const symbolMap = new Map>(); + const filteredTokens = tokens.filter((token) => { + const chainId = stargateChainKey[token.chainKey.toUpperCase()]; + if (chainId) { const isExcludedToken = this.checkIsExcludedToken({ excludedList: this.excludedTokens?.[chainId], - tokenSymbol: token.symbol?.toUpperCase(), + tokenSymbol: token.token.symbol?.toUpperCase(), tokenAddress: token.address, }); return !isExcludedToken; - }); - - if (filteredTokens.length > 0 && this.chainMap.has(chainId)) { - symbolMap.set(chainId, new Map()); - - filteredTokens.forEach((token) => { - symbolMap.get(chainId)?.set(token.symbol?.toUpperCase(), token); - }); - - tokenMap.set(chainId, filteredTokens); } }); + if (filteredTokens.length > 0) { + filteredTokens.forEach((token) => { + const chainId = stargateChainKey[token.chainKey.toUpperCase()]; + if (this.chainMap.has(chainId) && chainId) { + const existToken = symbolMap.get(chainId); + if (existToken) { + // remove duplicate token + const existTokenSymbol = symbolMap.get(chainId)?.get(token.token.symbol?.toUpperCase()); + if (existTokenSymbol) { + symbolMap.get(chainId)?.delete(token.token.symbol?.toUpperCase()); + // eslint-disable-next-line no-console + console.log( + `Duplicate Stargate token ${token.token.symbol} symbol in ${token.chainName}`, + ); + } else { + symbolMap.get(chainId)?.set(token.token.symbol?.toUpperCase(), token); + } + } else { + symbolMap.set(chainId, new Map()); + symbolMap.get(chainId)?.set(token.token.symbol?.toUpperCase(), token); + } + + const existTokens = tokenMap.get(chainId); + if (existTokens && existTokens?.length > 0) { + tokenMap.set(chainId, existTokens?.concat(token)); + } else { + tokenMap.set(chainId, [token]); + } + } + }); + } + this.tokenMap = tokenMap; this.symbolMap = symbolMap; } @@ -68,7 +106,7 @@ export class StargateAdapter extends BaseAdapter< protected initTransferMap() { const transferMap = new Map< number, - Map>> + Map>> >(); this.chains.forEach((fromChain) => { @@ -76,16 +114,19 @@ export class StargateAdapter extends BaseAdapter< if (fromChain.chainId !== toChain.chainId && fromChain.network === toChain.network) { const fromTokens = this.tokenMap.get(fromChain.chainId) ?? []; - const transferableTokenMap = new Map>(); + const transferableTokenMap = new Map< + string, + ITransferTokenPair + >(); fromTokens.forEach((fromToken) => { const toToken = this.getToToken({ fromChainId: fromChain.chainId, toChainId: toChain.chainId, - fromTokenSymbol: fromToken.symbol?.toUpperCase(), + fromTokenSymbol: fromToken.token.symbol?.toUpperCase(), }); if (toToken) { - const tokenPair: ITransferTokenPair = { + const tokenPair: ITransferTokenPair = { fromChainId: fromChain.chainId, toChainId: toChain.chainId, fromToken, @@ -93,7 +134,7 @@ export class StargateAdapter extends BaseAdapter< fromTokenAddress: fromToken.address, toTokenAddress: toToken.address, }; - transferableTokenMap.set(fromToken.symbol?.toUpperCase(), tokenPair); + transferableTokenMap.set(fromToken.token.symbol?.toUpperCase(), tokenPair); } }); @@ -101,7 +142,7 @@ export class StargateAdapter extends BaseAdapter< if (!transferMap.has(fromChain.chainId)) { transferMap.set( fromChain.chainId, - new Map>>(), + new Map>>(), ); } transferMap.get(fromChain.chainId)?.set(toChain.chainId, transferableTokenMap); @@ -123,16 +164,16 @@ export class StargateAdapter extends BaseAdapter< }; } - public getTokenInfo({ chainId, token }: { chainId: number; token: IStargateToken }) { + public getTokenInfo({ chainId, token }: { chainId: number; token: IStargateBridgeTokenInfo }) { return { - name: token.name, - symbol: token.symbol, - address: token.address, - decimals: token.decimals, + name: token.token.symbol, + symbol: token.token.symbol, + address: token.token.address, + decimals: token.token.decimals, ...this.getTokenDisplaySymbolAndIcon({ chainId, - tokenAddress: token.address, - defaultSymbol: token.symbol, + tokenAddress: token.token.address, + defaultSymbol: token.token.symbol, }), }; } diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/components/StarGateOption.tsx b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/components/StarGateOption.tsx index 3c0985e8..630855da 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/components/StarGateOption.tsx +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/components/StarGateOption.tsx @@ -56,8 +56,8 @@ export const StarGateOption = () => { ); const onSelectBridge = useCallback(() => { - if (!selectedToken?.stargate?.raw?.bridgeAddress || isError) return; - const bridgeAddress = selectedToken.stargate.raw?.bridgeAddress; + if (!selectedToken?.stargate?.raw?.address || isError) return; + const bridgeAddress = selectedToken.stargate.raw?.address; dispatch( setTransferActionInfo({ bridgeType: 'stargate', diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/const/index.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/const/index.ts index d1ae31e5..90d89491 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/const/index.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/const/index.ts @@ -1,24 +1,24 @@ -export const stargateChainKey: { [key: number]: string } = { - 1: 'ethereum', - 10: 'optimism', - 14: 'flare', - 56: 'bsc', - 137: 'polygon', - 250: 'fantom', - 1088: 'metis', - 1116: 'coredao', - 1329: 'sei', - 1625: 'gravity', - 2222: 'kava', - 5000: 'mantle', - 8217: 'klaytn', - 8453: 'base', - 8822: 'iota', - 42161: 'arbitrum', - 43114: 'avalanche', - 59144: 'linea', - 167000: 'taiko', - 534352: 'scroll', - 1313161554: 'aurora', - 1380012617: 'rarible', +export const stargateChainKey: { [key: string]: number } = { + ETHEREUM: 1, + OPTIMISM: 10, + FLARE: 14, + BSC: 56, + POLYGON: 137, + FANTOM: 250, + METIS: 1088, + COREDAO: 1116, + SEI: 1329, + GRAVITY: 1625, + KAVA: 2222, + MANTLE: 5000, + KLAYTN: 8217, + BASE: 8453, + IOTA: 8822, + ARBITRUM: 42161, + AVALANCHE: 43114, + LINEA: 59144, + TAIKO: 167000, + SCROLL: 534352, + AURORA: 1313161554, + RARIBLE: 1380012617, }; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useGetStarGateFees.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useGetStarGateFees.ts index e71ebf14..77764506 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useGetStarGateFees.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useGetStarGateFees.ts @@ -42,7 +42,7 @@ export const useGetStargateFees = () => { const allowedSendAmount = useMemo(() => { if (estimatedAmount?.stargate && estimatedAmount?.stargate?.[0]) { const fees = estimatedAmount?.stargate; - const decimal = selectedToken?.stargate?.raw?.decimals ?? (18 as number); + const decimal = selectedToken?.stargate?.raw?.token?.decimals ?? (18 as number); const allowedMin = Number(formatUnits(fees[0].minAmountLD, decimal)); const allowedMax = Number(formatUnits(fees[0].maxAmountLD, decimal)); return { @@ -51,18 +51,18 @@ export const useGetStargateFees = () => { }; } return null; - }, [estimatedAmount?.stargate, selectedToken?.stargate?.raw?.decimals]); + }, [estimatedAmount?.stargate, selectedToken?.stargate?.raw?.token?.decimals]); const isAllowSendError = useMemo(() => { if (estimatedAmount?.stargate && estimatedAmount?.stargate?.[0]) { const fees = estimatedAmount?.stargate; - const decimal = selectedToken?.stargate?.raw?.decimals ?? (18 as number); + const decimal = selectedToken?.stargate?.raw?.token?.decimals ?? (18 as number); const allowedMin = Number(formatUnits(fees[0].minAmountLD, decimal)); const allowedMax = Number(formatUnits(fees[0].maxAmountLD, decimal)); return Number(sendValue) < allowedMin || Number(sendValue) > allowedMax; } return false; - }, [estimatedAmount?.stargate, selectedToken?.stargate?.raw?.decimals, sendValue]); + }, [estimatedAmount?.stargate, selectedToken?.stargate?.raw?.token?.decimals, sendValue]); const stargateFeeSorting = useCallback( // fees are response of quoteOFT @@ -74,8 +74,8 @@ export const useGetStargateFees = () => { let isDisplayError = false; const receiver = address || DEFAULT_ADDRESS; - const bridgeAddress = selectedToken?.stargate?.raw?.bridgeAddress as `0x${string}`; - const decimal = selectedToken?.stargate?.raw?.decimals ?? (18 as number); + const bridgeAddress = selectedToken?.stargate?.raw?.address as `0x${string}`; + const decimal = selectedToken?.stargate?.raw?.token?.decimals ?? (18 as number); const allowedMin = Number(formatUnits(fees[0].minAmountLD, decimal)); const allowedMax = Number(formatUnits(fees[0].maxAmountLD, decimal)); const amount = parseUnits(sendValue, decimal); @@ -118,7 +118,8 @@ export const useGetStargateFees = () => { }); let nativeFee = quoteSendResponse!.nativeFee; if ( - selectedToken?.stargate?.raw?.address === '0x0000000000000000000000000000000000000000' + selectedToken?.stargate?.raw?.token?.address === + '0x0000000000000000000000000000000000000000' ) { nativeFee += args.amountLD; } @@ -146,16 +147,16 @@ export const useGetStargateFees = () => { // gas fee let allowance = null; if ( - selectedToken?.stargate?.raw?.address !== + selectedToken?.stargate?.raw?.token?.address !== '0x0000000000000000000000000000000000000000' ) { allowance = await publicClient.readContract({ - address: selectedToken?.stargate?.raw?.address + address: selectedToken?.stargate?.raw?.token?.address ? (selectedToken?.address as `0x${string}`) : ('' as `0x${string}`), abi: ERC20_TOKEN, functionName: 'allowance', - args: [address as `0x${string}`, selectedToken?.stargate?.raw?.bridgeAddress], + args: [address as `0x${string}`, selectedToken?.stargate?.raw?.address], chainId: fromChain?.id, enabled: !!address && diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransfer.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransfer.ts index bc63eed3..ab84ad77 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransfer.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransfer.ts @@ -46,7 +46,7 @@ export const useStargateTransfer = () => { return; } try { - const bridgeAddress = selectedToken.stargate?.raw?.bridgeAddress as `0x${string}`; + const bridgeAddress = selectedToken.stargate?.raw?.address as `0x${string}`; const quoteOFTResponse = await bridgeSDK.stargate.getQuoteOFT({ publicClient: publicClient, @@ -89,7 +89,7 @@ export const useStargateTransfer = () => { ) return; try { - const bridgeAddress = selectedToken.stargate?.raw?.bridgeAddress as `0x${string}`; + const bridgeAddress = selectedToken.stargate?.raw?.address as `0x${string}`; const amountReceivedLD = estimatedAmount?.stargate[2].amountReceivedLD; const sendParams = { ...args }; if (amountReceivedLD) { diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransferParams.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransferParams.ts index 9d22653e..683cc562 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransferParams.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/hooks/useStargateTransferParams.ts @@ -22,7 +22,10 @@ export const useStargateTransferParams = (): { args: IStargateParams | null } => if (!debouncedSendValue || !toTokenInfo || !selectedToken) { return null; } - const amount = parseUnits(debouncedSendValue, selectedToken?.stargate?.raw?.decimals || 18); + const amount = parseUnits( + debouncedSendValue, + selectedToken?.stargate?.raw?.token?.decimals || 18, + ); // random address for getting fee details without connecting to wallet const receiver = address || DEFAULT_ADDRESS; return { diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/types.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/types.ts index 5e90f9de..cbab9f86 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/types.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/stargate/types.ts @@ -1,18 +1,3 @@ -export interface IStargateToken { - address: string; - bridgeAddress: string; - decimals: number; - type?: string; - symbol: string; - endpointID: number; - name: string; -} - -export interface IStargateTransferConfig { - chains: IStargateChain[]; - tokens: Record; -} - export interface IStargateChain { chainId: number; chainName: string; @@ -78,6 +63,9 @@ export interface IStargateBridgeTokenInfo { sharedDecimals: number; } +export interface IStargateApiTokenConfig extends IStargateBridgeTokenInfo { + endpointID?: number; +} export interface IStargateTokenList { v1: IStargateBridgeTokenInfo[]; v2: IStargateBridgeTokenInfo[]; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/types.ts b/packages/canonical-bridge-widget/src/modules/aggregator/types.ts index a49742c1..3496e520 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/types.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/types.ts @@ -19,9 +19,8 @@ import { } from '@/modules/aggregator/adapters/layerZero/types'; import { StargateAdapter } from '@/modules/aggregator/adapters/stargate/StargateAdapter'; import { + IStargateApiTokenConfig, IStargateChain, - IStargateToken, - IStargateTransferConfig, } from '@/modules/aggregator/adapters/stargate/types'; import { IMesonChain, IMesonToken } from '@/modules/aggregator/adapters/meson/types'; import { MesonAdapter } from '@/modules/aggregator/adapters/meson/MesonAdapter'; @@ -87,7 +86,7 @@ export interface IBridgeToken extends IBridgeTokenBaseInfo { stargate?: IBridgeTokenBaseInfo & { isCompatible: boolean; isMatched: boolean; - raw?: IStargateToken; + raw?: IStargateApiTokenConfig; }; layerZero?: IBridgeTokenBaseInfo & { isCompatible: boolean; @@ -149,7 +148,7 @@ export interface ITransferConfig { bridgedTokenGroups?: string[][]; }; stargate?: { - config: IStargateTransferConfig; + config: IStargateApiTokenConfig[]; exclude?: { chains?: number[]; tokens?: Record; diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/Button/TransferButton.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/Button/TransferButton.tsx index 7b13584d..c7273459 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/Button/TransferButton.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/Button/TransferButton.tsx @@ -328,14 +328,14 @@ export function TransferButton({ } else if (transferActionInfo.bridgeType === 'stargate' && address) { const isValidToken = await bridgeSDK.stargate.validateStargateToken({ fromBridgeAddress: transferActionInfo.bridgeAddress as `0x${string}`, - toBridgeAddress: toToken?.stargate?.raw?.bridgeAddress as `0x${string}`, - fromTokenAddress: selectedToken?.stargate?.raw?.address as `0x${string}`, - fromTokenSymbol: selectedToken?.stargate?.raw?.symbol as string, - fromTokenDecimals: selectedToken?.stargate?.raw?.decimals as number, + toBridgeAddress: toToken?.stargate?.raw?.address as `0x${string}`, + fromTokenAddress: selectedToken?.stargate?.raw?.token?.address as `0x${string}`, + fromTokenSymbol: selectedToken?.stargate?.raw?.token?.symbol as string, + fromTokenDecimals: selectedToken?.stargate?.raw?.token?.decimals as number, fromChainId: fromChain?.id, - toTokenAddress: toToken?.stargate?.raw?.address as `0x${string}`, - toTokenSymbol: toToken?.stargate?.raw?.symbol as string, - toTokenDecimals: toToken?.stargate?.raw?.decimals as number, + toTokenAddress: toToken?.stargate?.raw?.token?.address as `0x${string}`, + toTokenSymbol: toToken?.stargate?.raw?.token?.symbol as string, + toTokenDecimals: toToken?.stargate?.raw?.token?.decimals as number, toChainId: toChain?.id, amount: Number(sendValue), dstEndpointId: toToken?.stargate?.raw?.endpointID as number, diff --git a/packages/canonical-bridge-widget/src/modules/transfer/hooks/useLoadingBridgeFees.ts b/packages/canonical-bridge-widget/src/modules/transfer/hooks/useLoadingBridgeFees.ts index 0523b220..cdd2c9b1 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/hooks/useLoadingBridgeFees.ts +++ b/packages/canonical-bridge-widget/src/modules/transfer/hooks/useLoadingBridgeFees.ts @@ -152,7 +152,7 @@ export const useLoadingBridgeFees = () => { layerZeroV2: toToken?.stargate?.raw?.endpointID, }, bridgeAddress: { - stargate: selectedToken?.stargate?.raw?.bridgeAddress as `0x${string}`, + stargate: selectedToken?.stargate?.raw?.address as `0x${string}`, layerZero: selectedToken?.layerZero?.raw?.bridgeAddress as `0x${string}`, }, isPegged: selectedToken?.isPegged, diff --git a/packages/canonical-bridge-widget/src/modules/transfer/hooks/usePreSelectRoute.ts b/packages/canonical-bridge-widget/src/modules/transfer/hooks/usePreSelectRoute.ts index ad2a96d4..b29678cb 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/hooks/usePreSelectRoute.ts +++ b/packages/canonical-bridge-widget/src/modules/transfer/hooks/usePreSelectRoute.ts @@ -36,13 +36,13 @@ export const usePreSelectRoute = () => { ); } else if ( bridgeType === 'stargate' && - selectedToken?.stargate?.raw?.bridgeAddress && + selectedToken?.stargate?.raw?.address && stargateEst.status === 'fulfilled' ) { dispatch( setTransferActionInfo({ bridgeType: 'stargate', - bridgeAddress: selectedToken?.stargate?.raw?.bridgeAddress as `0x${string}`, + bridgeAddress: selectedToken?.stargate?.raw?.address as `0x${string}`, }), ); } else if (bridgeType === 'layerZero' && layerZeroEst.status === 'fulfilled') { @@ -68,7 +68,7 @@ export const usePreSelectRoute = () => { [ dispatch, selectedToken?.layerZero?.raw?.bridgeAddress, - selectedToken?.stargate?.raw?.bridgeAddress, + selectedToken?.stargate?.raw?.address, cBridgeAddress, fromChain, ], diff --git a/packages/canonical-bridge-widget/src/modules/transfer/hooks/useToTokenInfo.ts b/packages/canonical-bridge-widget/src/modules/transfer/hooks/useToTokenInfo.ts index 932a4c45..77a848ca 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/hooks/useToTokenInfo.ts +++ b/packages/canonical-bridge-widget/src/modules/transfer/hooks/useToTokenInfo.ts @@ -10,7 +10,7 @@ export const useToTokenInfo = () => { return { cBridge: toTokenInfo?.cBridge?.raw?.token.decimal || 0, deBridge: toTokenInfo?.deBridge?.raw?.decimals || 0, - stargate: selectedToken?.stargate?.raw?.decimals || 0, + stargate: selectedToken?.stargate?.raw?.token?.decimals || 0, layerZero: selectedToken?.layerZero?.raw?.decimals || 0, meson: selectedToken?.meson?.raw?.decimals || 0, }; @@ -19,7 +19,7 @@ export const useToTokenInfo = () => { return { cBridge: toTokenInfo?.cBridge?.raw?.token.address || '', deBridge: toTokenInfo?.deBridge?.raw?.address || '', - stargate: toTokenInfo?.stargate?.raw?.address || '', + stargate: toTokenInfo?.stargate?.raw?.token?.address || '', layerZero: toTokenInfo?.layerZero?.raw?.address || '', meson: toTokenInfo?.meson?.raw?.addr || 0, }; @@ -29,14 +29,14 @@ export const useToTokenInfo = () => { return { cBridge: toTokenInfo?.cBridge?.raw?.token.symbol || '', deBridge: toTokenInfo?.deBridge?.raw?.symbol || '', - stargate: toTokenInfo?.stargate?.raw?.symbol || '', + stargate: toTokenInfo?.stargate?.raw?.token?.symbol || '', layerZero: toTokenInfo?.layerZero?.raw?.symbol || '', meson: toTokenInfo?.meson?.raw?.id?.toUpperCase() || '', }; }, [ toTokenInfo?.cBridge?.raw?.token.symbol, toTokenInfo?.deBridge?.raw?.symbol, - toTokenInfo?.stargate?.raw?.symbol, + toTokenInfo?.stargate?.raw?.token?.symbol, toTokenInfo?.layerZero?.raw?.symbol, toTokenInfo?.meson?.raw?.id, ]); From b930ad496a0fdece4ab68923c0b32948bbfd9167 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Mon, 23 Dec 2024 17:57:01 +0800 Subject: [PATCH 04/35] feat: Add more token info to token element --- .release/.changeset/serious-cars-worry.md | 5 +++++ apps/canonical-bridge-ui/next-env.d.ts | 2 +- apps/canonical-bridge-ui/package.json | 1 - .../components/SelectModal/ChooseTokenModal.tsx | 3 +++ .../components/SelectButton/TokenSelectButton.tsx | 2 +- .../TransferOverview/RouteInfo/RouteTitle.tsx | 5 ++++- .../TransferOverview/RouteInfo/TokenInfoTooltip.tsx | 13 +++++++++---- 7 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 .release/.changeset/serious-cars-worry.md diff --git a/.release/.changeset/serious-cars-worry.md b/.release/.changeset/serious-cars-worry.md new file mode 100644 index 00000000..910f2f9c --- /dev/null +++ b/.release/.changeset/serious-cars-worry.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/canonical-bridge-widget": patch +--- + +Add more token info to token element diff --git a/apps/canonical-bridge-ui/next-env.d.ts b/apps/canonical-bridge-ui/next-env.d.ts index a4a7b3f5..4f11a03d 100644 --- a/apps/canonical-bridge-ui/next-env.d.ts +++ b/apps/canonical-bridge-ui/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/apps/canonical-bridge-ui/package.json b/apps/canonical-bridge-ui/package.json index 01771be5..b9c0ef73 100644 --- a/apps/canonical-bridge-ui/package.json +++ b/apps/canonical-bridge-ui/package.json @@ -51,7 +51,6 @@ "eslint-config-next": "14.2.3", "lint-staged": "~13.0.3", "prettier": "~2.7.1", - "supports-color": "8.1.1", "typescript": "5.5.4" }, "lint-staged": { diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx b/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx index af62c3ca..778f48de 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx +++ b/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx @@ -110,6 +110,9 @@ export function ChooseTokenModal(props: ChooseTokenModalProps) { isActive={isActive} isDisabled={isDisabled} data-address={item.address} + data-name={item.name} + data-symbol={item.symbol} + data-display-symbol={item.displaySymbol} incompatibleTooltip={formatMessage({ id: 'select-modal.token.incompatible.tooltip', })} diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/SelectButton/TokenSelectButton.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/SelectButton/TokenSelectButton.tsx index aea43e14..2e61c386 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/SelectButton/TokenSelectButton.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/SelectButton/TokenSelectButton.tsx @@ -43,7 +43,7 @@ export function TokenSelectButton(props: SelectButtonProps) { diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/RouteTitle.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/RouteTitle.tsx index 9aceabc9..d14b494a 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/RouteTitle.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/RouteTitle.tsx @@ -53,7 +53,7 @@ export const RouteTitle = ({ {toTokenInfo && hoverToShowTokenAddress && ( @@ -125,6 +125,9 @@ export const ToTokenInfo = React.forwardRef( justifyContent="flex-start" className="bccb-widget-route-token-to-address" data-address={toTokenInfo.address} + data-name={toTokenInfo.name} + data-symbol={toTokenInfo.symbol} + data-display-symbol={toTokenInfo.displaySymbol} > { + const tokenAddress = tokenInfo?.address ?? ''; + const theme = useTheme(); const nativeToken = useMemo( () => isNativeToken(tokenAddress, chainType), @@ -42,7 +44,10 @@ export const TokenInfoTooltip = ({ return ( From 30af8b3fdb11962b062f3fa0979c0b95f28293c7 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Mon, 23 Dec 2024 18:51:00 +0800 Subject: [PATCH 05/35] chore: Release --- .release/.changeset/pre.json | 11 +++++ ....timestamp-1734950241948-d28c013da946b.mjs | 44 +++++++++++++++++++ packages/canonical-bridge-widget/CHANGELOG.md | 6 +++ packages/canonical-bridge-widget/package.json | 2 +- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .release/.changeset/pre.json create mode 100644 packages/canonical-bridge-sdk/vite.config.ts.timestamp-1734950241948-d28c013da946b.mjs diff --git a/.release/.changeset/pre.json b/.release/.changeset/pre.json new file mode 100644 index 00000000..e3455c6f --- /dev/null +++ b/.release/.changeset/pre.json @@ -0,0 +1,11 @@ +{ + "mode": "pre", + "tag": "alpha", + "initialVersions": { + "@bnb-chain/canonical-bridge-sdk": "0.4.5", + "@bnb-chain/canonical-bridge-widget": "0.5.15" + }, + "changesets": [ + "serious-cars-worry" + ] +} diff --git a/packages/canonical-bridge-sdk/vite.config.ts.timestamp-1734950241948-d28c013da946b.mjs b/packages/canonical-bridge-sdk/vite.config.ts.timestamp-1734950241948-d28c013da946b.mjs new file mode 100644 index 00000000..914888b9 --- /dev/null +++ b/packages/canonical-bridge-sdk/vite.config.ts.timestamp-1734950241948-d28c013da946b.mjs @@ -0,0 +1,44 @@ +// vite.config.ts +import { defineConfig } from "file:///Users/liwen/Documents/bnb-chain/canonical-bridge/common/temp/node_modules/.pnpm/vite@4.5.5_@types+node@22.7.5_terser@5.36.0/node_modules/vite/dist/node/index.js"; +import react from "file:///Users/liwen/Documents/bnb-chain/canonical-bridge/common/temp/node_modules/.pnpm/@vitejs+plugin-react@4.3.3_vite@4.5.5_@types+node@22.7.5_terser@5.36.0_/node_modules/@vitejs/plugin-react/dist/index.mjs"; +import dts from "file:///Users/liwen/Documents/bnb-chain/canonical-bridge/common/temp/node_modules/.pnpm/vite-plugin-dts@3.9.1_@types+node@22.7.5_rollup@3.29.5_typescript@5.5.4_vite@4.5.5_@types+node@22.7.5_terser@5.36.0_/node_modules/vite-plugin-dts/dist/index.mjs"; +import peerDepsExternal from "file:///Users/liwen/Documents/bnb-chain/canonical-bridge/common/temp/node_modules/.pnpm/rollup-plugin-peer-deps-external@2.2.4_rollup@3.29.5/node_modules/rollup-plugin-peer-deps-external/dist/rollup-plugin-peer-deps-external.js"; +import path from "path"; +var __vite_injected_original_dirname = "/Users/liwen/Documents/bnb-chain/canonical-bridge/packages/canonical-bridge-sdk"; +var vite_config_default = defineConfig({ + plugins: [ + react(), + dts({ + include: "src" + }) + ], + resolve: { + alias: { + "@": path.resolve(__vite_injected_original_dirname, "src") + } + }, + build: { + target: "esnext", + minify: false, + lib: { + formats: ["es"], + entry: { + index: "src/index.ts" + } + }, + rollupOptions: { + plugins: [ + peerDepsExternal({ + includeDependencies: true + }) + ], + output: { + chunkFileNames: "common.js" + } + } + } +}); +export { + vite_config_default as default +}; +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMvbGl3ZW4vRG9jdW1lbnRzL2JuYi1jaGFpbi9jYW5vbmljYWwtYnJpZGdlL3BhY2thZ2VzL2Nhbm9uaWNhbC1icmlkZ2Utc2RrXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ZpbGVuYW1lID0gXCIvVXNlcnMvbGl3ZW4vRG9jdW1lbnRzL2JuYi1jaGFpbi9jYW5vbmljYWwtYnJpZGdlL3BhY2thZ2VzL2Nhbm9uaWNhbC1icmlkZ2Utc2RrL3ZpdGUuY29uZmlnLnRzXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ltcG9ydF9tZXRhX3VybCA9IFwiZmlsZTovLy9Vc2Vycy9saXdlbi9Eb2N1bWVudHMvYm5iLWNoYWluL2Nhbm9uaWNhbC1icmlkZ2UvcGFja2FnZXMvY2Fub25pY2FsLWJyaWRnZS1zZGsvdml0ZS5jb25maWcudHNcIjtpbXBvcnQgeyBkZWZpbmVDb25maWcgfSBmcm9tICd2aXRlJztcbmltcG9ydCByZWFjdCBmcm9tICdAdml0ZWpzL3BsdWdpbi1yZWFjdCc7XG5pbXBvcnQgZHRzIGZyb20gJ3ZpdGUtcGx1Z2luLWR0cyc7XG5pbXBvcnQgcGVlckRlcHNFeHRlcm5hbCBmcm9tICdyb2xsdXAtcGx1Z2luLXBlZXItZGVwcy1leHRlcm5hbCc7XG5pbXBvcnQgcGF0aCBmcm9tICdwYXRoJztcblxuLy8gaHR0cHM6Ly92aXRlanMuZGV2L2NvbmZpZy9cbmV4cG9ydCBkZWZhdWx0IGRlZmluZUNvbmZpZyh7XG4gIHBsdWdpbnM6IFtcbiAgICByZWFjdCgpLFxuICAgIGR0cyh7XG4gICAgICBpbmNsdWRlOiAnc3JjJyxcbiAgICB9KSxcbiAgXSxcbiAgcmVzb2x2ZToge1xuICAgIGFsaWFzOiB7XG4gICAgICAnQCc6IHBhdGgucmVzb2x2ZShfX2Rpcm5hbWUsICdzcmMnKSxcbiAgICB9LFxuICB9LFxuICBidWlsZDoge1xuICAgIHRhcmdldDogJ2VzbmV4dCcsXG4gICAgbWluaWZ5OiBmYWxzZSxcbiAgICBsaWI6IHtcbiAgICAgIGZvcm1hdHM6IFsnZXMnXSxcbiAgICAgIGVudHJ5OiB7XG4gICAgICAgIGluZGV4OiAnc3JjL2luZGV4LnRzJyxcbiAgICAgIH0sXG4gICAgfSxcbiAgICByb2xsdXBPcHRpb25zOiB7XG4gICAgICBwbHVnaW5zOiBbXG4gICAgICAgIHBlZXJEZXBzRXh0ZXJuYWwoe1xuICAgICAgICAgIGluY2x1ZGVEZXBlbmRlbmNpZXM6IHRydWUsXG4gICAgICAgIH0pLFxuICAgICAgXSxcbiAgICAgIG91dHB1dDoge1xuICAgICAgICBjaHVua0ZpbGVOYW1lczogJ2NvbW1vbi5qcycsXG4gICAgICB9LFxuICAgIH0sXG4gIH0sXG59KTtcbiJdLAogICJtYXBwaW5ncyI6ICI7QUFBK1osU0FBUyxvQkFBb0I7QUFDNWIsT0FBTyxXQUFXO0FBQ2xCLE9BQU8sU0FBUztBQUNoQixPQUFPLHNCQUFzQjtBQUM3QixPQUFPLFVBQVU7QUFKakIsSUFBTSxtQ0FBbUM7QUFPekMsSUFBTyxzQkFBUSxhQUFhO0FBQUEsRUFDMUIsU0FBUztBQUFBLElBQ1AsTUFBTTtBQUFBLElBQ04sSUFBSTtBQUFBLE1BQ0YsU0FBUztBQUFBLElBQ1gsQ0FBQztBQUFBLEVBQ0g7QUFBQSxFQUNBLFNBQVM7QUFBQSxJQUNQLE9BQU87QUFBQSxNQUNMLEtBQUssS0FBSyxRQUFRLGtDQUFXLEtBQUs7QUFBQSxJQUNwQztBQUFBLEVBQ0Y7QUFBQSxFQUNBLE9BQU87QUFBQSxJQUNMLFFBQVE7QUFBQSxJQUNSLFFBQVE7QUFBQSxJQUNSLEtBQUs7QUFBQSxNQUNILFNBQVMsQ0FBQyxJQUFJO0FBQUEsTUFDZCxPQUFPO0FBQUEsUUFDTCxPQUFPO0FBQUEsTUFDVDtBQUFBLElBQ0Y7QUFBQSxJQUNBLGVBQWU7QUFBQSxNQUNiLFNBQVM7QUFBQSxRQUNQLGlCQUFpQjtBQUFBLFVBQ2YscUJBQXFCO0FBQUEsUUFDdkIsQ0FBQztBQUFBLE1BQ0g7QUFBQSxNQUNBLFFBQVE7QUFBQSxRQUNOLGdCQUFnQjtBQUFBLE1BQ2xCO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDOyIsCiAgIm5hbWVzIjogW10KfQo= diff --git a/packages/canonical-bridge-widget/CHANGELOG.md b/packages/canonical-bridge-widget/CHANGELOG.md index 0bffbd30..f3a6c442 100644 --- a/packages/canonical-bridge-widget/CHANGELOG.md +++ b/packages/canonical-bridge-widget/CHANGELOG.md @@ -1,5 +1,11 @@ # @bnb-chain/canonical-bridge-widget +## 0.5.16-alpha.0 + +### Patch Changes + +- b930ad4: Add more token info to token element + ## 0.5.15 ### Patch Changes diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index 9e780e73..759e8df2 100644 --- a/packages/canonical-bridge-widget/package.json +++ b/packages/canonical-bridge-widget/package.json @@ -1,6 +1,6 @@ { "name": "@bnb-chain/canonical-bridge-widget", - "version": "0.5.15", + "version": "0.5.16-alpha.0", "description": "canonical bridge widget", "author": "bnb-chain", "private": false, From 61cbb0e9d24751b174d960eecc2551daa4012051 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Tue, 24 Dec 2024 14:13:44 +0800 Subject: [PATCH 06/35] fix: Modify optimism endpointID to 30111 --- apps/canonical-bridge-server/src/common/constants/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/canonical-bridge-server/src/common/constants/index.ts b/apps/canonical-bridge-server/src/common/constants/index.ts index 1d172896..280ff0a6 100644 --- a/apps/canonical-bridge-server/src/common/constants/index.ts +++ b/apps/canonical-bridge-server/src/common/constants/index.ts @@ -69,7 +69,7 @@ export const STARGATE_CHAIN_INFO = [ { chainId: 10, chainName: 'Optimism', - endpointID: 30110, + endpointID: 30111, }, { chainId: 14, From ef7a857ea580036631bac50db9567b03cdf78259 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Tue, 24 Dec 2024 15:46:42 +0800 Subject: [PATCH 07/35] fix: Fix security issues --- .github/workflows/release.yaml | 6 +- .github/workflows/server.yaml | 1 + .release/scripts/install.js | 1 - .vscode/settings.json | 1 + apps/canonical-bridge-server/.env.example | 2 +- apps/canonical-bridge-server/Dockerfile | 3 + .../core/components/VConsole/index.tsx | 15 + apps/canonical-bridge-ui/next-env.d.ts | 2 +- apps/canonical-bridge-ui/package.json | 7 +- apps/canonical-bridge-ui/pages/_app.tsx | 2 + apps/canonical-bridge-ui/pages/_document.tsx | 10 - .../token-config/mainnet/meson/config.json | 1134 ----------------- .../token-config/mainnet/stargate/config.json | 601 --------- common/config/rush/pnpm-lock.yaml | 750 +++++++---- packages/canonical-bridge-sdk/package.json | 6 +- packages/canonical-bridge-widget/package.json | 4 +- 16 files changed, 522 insertions(+), 2023 deletions(-) create mode 100644 apps/canonical-bridge-ui/core/components/VConsole/index.tsx delete mode 100644 apps/canonical-bridge-ui/token-config/mainnet/meson/config.json delete mode 100644 apps/canonical-bridge-ui/token-config/mainnet/stargate/config.json diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f4b058f6..67dda9c2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,7 +4,7 @@ on: push: branches: - main - - alpha + - alpha/packages paths: - .release/** @@ -45,11 +45,11 @@ jobs: node common/scripts/install-run-rush.js build -t @bnb-chain/canonical-bridge-widget - name: Enter pre mode - if: ${{steps.get-branch.outputs.branch == 'alpha'}} + if: ${{steps.get-branch.outputs.branch == 'alpha/packages'}} run: cd .release && pnpm ci:enter - name: Create and publish alpha versions - if: ${{steps.get-branch.outputs.branch == 'alpha'}} + if: ${{steps.get-branch.outputs.branch == 'alpha/packages'}} uses: changesets/action@v1 with: version: pnpm ci:alpha-version diff --git a/.github/workflows/server.yaml b/.github/workflows/server.yaml index 0465f8ad..2e93fafb 100644 --- a/.github/workflows/server.yaml +++ b/.github/workflows/server.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - alpha/server paths: - apps/canonical-bridge-server/** diff --git a/.release/scripts/install.js b/.release/scripts/install.js index a881d541..60b69542 100644 --- a/.release/scripts/install.js +++ b/.release/scripts/install.js @@ -6,7 +6,6 @@ process.chdir(rootDir); console.log('Install changeset dependencies...'); exec('pnpm install', (err, stdout) => { - console.log('shshshshsh'); if (stdout) { console.log(stdout); } diff --git a/.vscode/settings.json b/.vscode/settings.json index e7884581..63ef4b16 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -60,6 +60,7 @@ "tronwallet", "tronweb", "unauthenticate", + "vconsole", "viem", "Wagmi", "walletkit" diff --git a/apps/canonical-bridge-server/.env.example b/apps/canonical-bridge-server/.env.example index db801b5b..58b52e75 100644 --- a/apps/canonical-bridge-server/.env.example +++ b/apps/canonical-bridge-server/.env.example @@ -10,4 +10,4 @@ STARGATE_ENDPOINT='https://mainnet.stargate-api.com/v1/metadata?version=v2' MESON_ENDPOINT=https://relayer.meson.fi/api/v1 REDIS_URL=http://127.0.0.1:6379 -DATABASE_URL=mysql://test:xxx@localhost:3306/bridge +DATABASE_URL= diff --git a/apps/canonical-bridge-server/Dockerfile b/apps/canonical-bridge-server/Dockerfile index c31451c6..4a18b954 100644 --- a/apps/canonical-bridge-server/Dockerfile +++ b/apps/canonical-bridge-server/Dockerfile @@ -1,6 +1,9 @@ FROM busybox:1.36.1 as builder FROM node:20-buster +RUN useradd -u 9000 appuser +USER appuser + WORKDIR /opt/deploy COPY . . diff --git a/apps/canonical-bridge-ui/core/components/VConsole/index.tsx b/apps/canonical-bridge-ui/core/components/VConsole/index.tsx new file mode 100644 index 00000000..4a9a701b --- /dev/null +++ b/apps/canonical-bridge-ui/core/components/VConsole/index.tsx @@ -0,0 +1,15 @@ +import { useMemo } from 'react'; + +export function VConsole() { + useMemo(async () => { + if (typeof window !== 'undefined') { + try { + new (await import('vconsole')).default(); + } catch (err) { + // eslint-disable-next-line no-console + console.log(`Init vconsole error!`, err); + } + } + }, []); + return null; +} diff --git a/apps/canonical-bridge-ui/next-env.d.ts b/apps/canonical-bridge-ui/next-env.d.ts index 4f11a03d..a4a7b3f5 100644 --- a/apps/canonical-bridge-ui/next-env.d.ts +++ b/apps/canonical-bridge-ui/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/apps/canonical-bridge-ui/package.json b/apps/canonical-bridge-ui/package.json index b9c0ef73..a70b79cc 100644 --- a/apps/canonical-bridge-ui/package.json +++ b/apps/canonical-bridge-ui/package.json @@ -21,8 +21,8 @@ "@solana/web3.js": "~1.95.4", "@tanstack/react-query": "~5.50.1", "@tronweb3/tronwallet-adapter-react-hooks": "~1.1.9", - "axios": "~1.6.8", - "next": "~14.1.1", + "axios": "~1.7.4", + "next": "~14.2.21", "pino-pretty": "~11.2.1", "polished": "~4.3.1", "react": "~18.3.1", @@ -30,7 +30,8 @@ "supports-color": "~9.4.0", "tronweb": "~6.0.0", "viem": "~2.21.14", - "wagmi": "^2" + "wagmi": "^2", + "vconsole": "~3.15.1" }, "devDependencies": { "@babel/core": "^7.21.4", diff --git a/apps/canonical-bridge-ui/pages/_app.tsx b/apps/canonical-bridge-ui/pages/_app.tsx index 8f21c5c4..a42d224f 100644 --- a/apps/canonical-bridge-ui/pages/_app.tsx +++ b/apps/canonical-bridge-ui/pages/_app.tsx @@ -5,6 +5,7 @@ import { AppProps } from 'next/app'; import { ThemeProvider } from '@/core/components/ThemeProvider'; import { SvgDefs } from '@/core/components/icons/SvgDefs'; +import { VConsole } from '@/core/components/VConsole'; const queryClient = new QueryClient({ defaultOptions: { @@ -19,6 +20,7 @@ const queryClient = new QueryClient({ export default function App({ Component, ...restProps }: AppProps) { return ( <> + diff --git a/apps/canonical-bridge-ui/pages/_document.tsx b/apps/canonical-bridge-ui/pages/_document.tsx index ccd364da..6950a6a6 100644 --- a/apps/canonical-bridge-ui/pages/_document.tsx +++ b/apps/canonical-bridge-ui/pages/_document.tsx @@ -10,16 +10,6 @@ export default class Document extends NextDocument { - -