Skip to content

Commit

Permalink
Merge pull request #190 from bnb-chain/feat/addressCheck
Browse files Browse the repository at this point in the history
chore: Update meson validation for tron token
  • Loading branch information
Halibao-Lala authored Dec 13, 2024
2 parents 8aa95fa + d81727c commit 1a6529a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .release/.changeset/cool-insects-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-sdk": patch
---

Update meson token validation
57 changes: 57 additions & 0 deletions packages/canonical-bridge-sdk/__tests__/meson/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
11 changes: 7 additions & 4 deletions packages/canonical-bridge-sdk/src/meson/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
);
Expand All @@ -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
);
Expand Down
4 changes: 2 additions & 2 deletions packages/canonical-bridge-sdk/src/meson/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a6529a

Please sign in to comment.