diff --git a/.release/.changeset/few-seals-press.md b/.release/.changeset/few-seals-press.md new file mode 100644 index 00000000..3a7bfd71 --- /dev/null +++ b/.release/.changeset/few-seals-press.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/canonical-bridge-widget": patch +--- + +Update meson validation diff --git a/packages/canonical-bridge-sdk/CHANGELOG.md b/packages/canonical-bridge-sdk/CHANGELOG.md index 30b32f8a..23c8d470 100644 --- a/packages/canonical-bridge-sdk/CHANGELOG.md +++ b/packages/canonical-bridge-sdk/CHANGELOG.md @@ -1,5 +1,17 @@ # @bnb-chain/canonical-bridge-sdk +## 0.4.4 + +### Patch Changes + +- d81727c: Update meson token validation + +## 0.4.3 + +### Patch Changes + +- 63c1a6a: Token transfer parameters validation + ## 0.4.2 ### Patch Changes diff --git a/packages/canonical-bridge-sdk/__tests__/meson/index.test.ts b/packages/canonical-bridge-sdk/__tests__/meson/index.test.ts index 1ed1cc60..f9cdc636 100644 --- a/packages/canonical-bridge-sdk/__tests__/meson/index.test.ts +++ b/packages/canonical-bridge-sdk/__tests__/meson/index.test.ts @@ -257,4 +257,61 @@ describe('Meson SDK validation', () => { }) ).toBe(true); }); + + it('Test 14: Meson validation with from tron token', async () => { + expect( + await bridge.validateMesonToken({ + fromChainId: 728126428, + fromTokenAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', + fromTokenSymbol: 'usdt', + fromTokenDecimals: 6, + fromChainType: 'tron', + toChainId: 56, + toTokenAddress: '0x55d398326f99059ff775485246999027b3197955', + toTokenDecimals: 18, + toChainType: 'evm', + toTokenSymbol: 'usdt', + amount: 5, + mesonEndpoint: 'https://relayer.meson.fi/api/v1', + }) + ).toBe(true); + }); + + it('Test 15: Meson validation with to tron token', async () => { + expect( + await bridge.validateMesonToken({ + fromChainId: 56, + fromTokenAddress: '0x55d398326f99059ff775485246999027b3197955', + fromTokenSymbol: 'usdt', + fromTokenDecimals: 18, + fromChainType: 'evm', + toChainId: 728126428, + toTokenAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', + toTokenDecimals: 6, + toChainType: 'tron', + toTokenSymbol: 'usdt', + amount: 5, + mesonEndpoint: 'https://relayer.meson.fi/api/v1', + }) + ).toBe(true); + }); + + it('Test 16: Meson validation with wrong to tron token', async () => { + expect( + await bridge.validateMesonToken({ + fromChainId: 56, + fromTokenAddress: '0x55d398326f99059ff775485246999027b3197955', + fromTokenSymbol: 'usdt', + fromTokenDecimals: 18, + fromChainType: 'evm', + toChainId: 728126428, + toTokenAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6txx', + toTokenDecimals: 6, + toChainType: 'tron', + toTokenSymbol: 'usdt', + amount: 5, + mesonEndpoint: 'https://relayer.meson.fi/api/v1', + }) + ).toBe(false); + }); }); diff --git a/packages/canonical-bridge-sdk/package.json b/packages/canonical-bridge-sdk/package.json index 3e4fa486..3792a777 100644 --- a/packages/canonical-bridge-sdk/package.json +++ b/packages/canonical-bridge-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@bnb-chain/canonical-bridge-sdk", - "version": "0.4.2", + "version": "0.4.4", "description": "canonical bridge sdk", "author": "bnb-chain", "private": false, diff --git a/packages/canonical-bridge-sdk/src/meson/index.ts b/packages/canonical-bridge-sdk/src/meson/index.ts index 44749cf8..fbfda7fd 100644 --- a/packages/canonical-bridge-sdk/src/meson/index.ts +++ b/packages/canonical-bridge-sdk/src/meson/index.ts @@ -192,8 +192,11 @@ export class Meson { const { data: mesonConfig } = await axios.get<{ result: IMesonTokenList[]; }>(`${mesonEndpoint}/limits`, { timeout: VALIDATION_API_TIMEOUT }); - const fromHexNum = fromChainId?.toString(16); - const toHexNum = toChainId?.toString(16); + + const fromHexNum = + fromChainType === 'tron' ? 'tron' : `0x${fromChainId?.toString(16)}`; + const toHexNum = + toChainType === 'tron' ? 'tron' : `0x${toChainId?.toString(16)}`; // from token validation const validFromToken = mesonConfig.result.filter((chainInfo) => { const fromTokenInfo = chainInfo.tokens.filter( @@ -211,7 +214,7 @@ export class Meson { console.log('Meson from token info', fromTokenInfo); } return ( - chainInfo.chainId === `0x${fromHexNum}` && + chainInfo.chainId === fromHexNum && fromTokenInfo?.length > 0 && !!fromTokenInfo ); @@ -232,7 +235,7 @@ export class Meson { console.log('Meson to token info', toTokenInfo); } return ( - chainInfo.chainId === `0x${toHexNum}` && + chainInfo.chainId === toHexNum && toTokenInfo?.length > 0 && !!toTokenInfo ); diff --git a/packages/canonical-bridge-sdk/src/meson/types/index.ts b/packages/canonical-bridge-sdk/src/meson/types/index.ts index 9789a982..11bd9dbe 100644 --- a/packages/canonical-bridge-sdk/src/meson/types/index.ts +++ b/packages/canonical-bridge-sdk/src/meson/types/index.ts @@ -25,10 +25,10 @@ export interface IMesonTokenValidateParams { fromChainId?: number; toChainId?: number; fromTokenSymbol: string; - fromTokenAddress: `0x${string}`; + fromTokenAddress: string; fromTokenDecimals: number; fromChainType?: string; - toTokenAddress?: `0x${string}`; + toTokenAddress?: string; toTokenDecimals?: number; toChainType?: string; toTokenSymbol?: string; diff --git a/packages/canonical-bridge-widget/CHANGELOG.md b/packages/canonical-bridge-widget/CHANGELOG.md index 12e52512..dd4b7769 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.10 + +### Patch Changes + +- 63c1a6a: Token transfer parameters validation + ## 0.5.9 ### Patch Changes diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index d2c6686b..ab0d33e4 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.9", + "version": "0.5.10", "description": "canonical bridge widget", "author": "bnb-chain", "private": false, 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 dfc3e557..efd65ea0 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 @@ -250,7 +250,7 @@ export function TransferButton({ } else if (transferActionInfo.bridgeType === 'deBridge') { try { let deBridgeHash: string | undefined; - const isValidToken = await await bridgeSDK.deBridge.validateDeBridgeToken({ + const isValidToken = await bridgeSDK.deBridge.validateDeBridgeToken({ fromChainId: fromChain?.id, toChainId: toChain?.id, fromTokenSymbol: selectedToken.symbol,