Skip to content

Commit

Permalink
Merge pull request #194 from bnb-chain/feat/addressCheck
Browse files Browse the repository at this point in the history
Feat/address check
  • Loading branch information
Halibao-Lala authored Dec 13, 2024
2 parents 50d62ed + c1aefab commit e1a39ce
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .release/.changeset/few-seals-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Update meson validation
12 changes: 12 additions & 0 deletions packages/canonical-bridge-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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);
});
});
2 changes: 1 addition & 1 deletion packages/canonical-bridge-sdk/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
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
6 changes: 6 additions & 0 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @bnb-chain/canonical-bridge-widget

## 0.5.10

### Patch Changes

- 63c1a6a: Token transfer parameters validation

## 0.5.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-widget/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e1a39ce

Please sign in to comment.