diff --git a/.release/.changeset/metal-forks-train.md b/.release/.changeset/metal-forks-train.md new file mode 100644 index 00000000..517f5c51 --- /dev/null +++ b/.release/.changeset/metal-forks-train.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/canonical-bridge-widget": patch +--- + +Show input error message when wallet is connected diff --git a/packages/canonical-bridge-sdk/CHANGELOG.md b/packages/canonical-bridge-sdk/CHANGELOG.md index 68841823..30b32f8a 100644 --- a/packages/canonical-bridge-sdk/CHANGELOG.md +++ b/packages/canonical-bridge-sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # @bnb-chain/canonical-bridge-sdk +## 0.4.2 + +### Patch Changes + +- 792cae1: Check Layerzero destination gas limit + ## 0.4.1 ### Patch Changes diff --git a/packages/canonical-bridge-sdk/package.json b/packages/canonical-bridge-sdk/package.json index cf4bb52a..e11573d4 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.1", + "version": "0.4.2", "description": "canonical bridge sdk", "author": "bnb-chain", "private": false, diff --git a/packages/canonical-bridge-sdk/src/layerZero/index.ts b/packages/canonical-bridge-sdk/src/layerZero/index.ts index b0e5eff1..e250cbbd 100644 --- a/packages/canonical-bridge-sdk/src/layerZero/index.ts +++ b/packages/canonical-bridge-sdk/src/layerZero/index.ts @@ -38,16 +38,25 @@ export class LayerZero { }: ISendCakeTokenInput): Promise { try { const address32Bytes = pad(userAddress, { size: 32 }); + // check destination chain gas limit + const dstGasLimit = await publicClient.readContract({ + address: bridgeAddress, + abi: CAKE_PROXY_OFT_ABI, + functionName: 'minDstGasLookup', + args: [dstEndpoint, 0], + }); + const gasLimit = + dstGasLimit !== 0n && !!dstGasLimit ? dstGasLimit : gasAmount; /* version 1 - send token * version 2 - send token and air drop native gas on destination chain * https://docs.layerzero.network/v1/developers/evm/evm-guides/advanced/relayer-adapter-parameters#airdrop */ const adapterParams = version === 1 - ? encodePacked(['uint16', 'uint256'], [version, gasAmount]) + ? encodePacked(['uint16', 'uint256'], [version, gasLimit]) : encodePacked( ['uint16', 'uint', 'uint', 'address'], - [2, gasAmount, airDropGas, dstAddress] + [2, gasLimit, airDropGas, dstAddress] ); const fees = await publicClient.readContract({ address: bridgeAddress, @@ -122,13 +131,22 @@ export class LayerZero { dstAddress = '0x', }: IGetEstimateFeeInput) { try { + // check destination chain gas limit + const dstGasLimit = await publicClient.readContract({ + address: bridgeAddress, + abi: CAKE_PROXY_OFT_ABI, + functionName: 'minDstGasLookup', + args: [dstEndpoint, 0], + }); + const gasLimit = + dstGasLimit !== 0n && !!dstGasLimit ? dstGasLimit : gasAmount; const address32Bytes = pad(userAddress, { size: 32 }); const adapterParams = version === 1 - ? encodePacked(['uint16', 'uint256'], [version, gasAmount]) + ? encodePacked(['uint16', 'uint256'], [version, gasLimit]) : encodePacked( ['uint16', 'uint', 'uint', 'address'], - [2, gasAmount, airDropGas, dstAddress] + [2, gasLimit, airDropGas, dstAddress] ); const fees = await publicClient.readContract({ address: bridgeAddress, diff --git a/packages/canonical-bridge-widget/CHANGELOG.md b/packages/canonical-bridge-widget/CHANGELOG.md index f9ed6d81..0915dd58 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.5 + +### Patch Changes + +- 792cae1: Check Layerzero destination gas limit + ## 0.5.4 ### Patch Changes diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index 52df5051..83a29389 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.4", + "version": "0.5.5", "description": "canonical bridge widget", "author": "bnb-chain", "private": false, diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/layerZero/hooks/useGetLayerZeroFees.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/layerZero/hooks/useGetLayerZeroFees.ts index d149e52e..37a5462c 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/layerZero/hooks/useGetLayerZeroFees.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/layerZero/hooks/useGetLayerZeroFees.ts @@ -52,7 +52,14 @@ export const useGetLayerZeroFees = () => { ); const address32Bytes = pad(address || DEFAULT_ADDRESS, { size: 32 }); - const adapterParams = encodePacked(['uint16', 'uint256'], [1, 200000n]); + const dstGasLimit = await publicClient.readContract({ + address: bridgeAddress, + abi: CAKE_PROXY_OFT_ABI, + functionName: 'minDstGasLookup', + args: [toTokenInfo?.layerZero?.raw?.endpointID, 0], + }); + const gasLimit = dstGasLimit !== 0n && !!dstGasLimit ? dstGasLimit : 200000n; + const adapterParams = encodePacked(['uint16', 'uint256'], [1, gasLimit]); const callParams = [ address, '0x0000000000000000000000000000000000000000', // zroPaymentAddress diff --git a/packages/canonical-bridge-widget/src/modules/transfer/hooks/useInputValidation.ts b/packages/canonical-bridge-widget/src/modules/transfer/hooks/useInputValidation.ts index 1c87beb6..27044a96 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/hooks/useInputValidation.ts +++ b/packages/canonical-bridge-widget/src/modules/transfer/hooks/useInputValidation.ts @@ -6,11 +6,12 @@ import { formatNumber } from '@/core/utils/number'; import { useAppSelector } from '@/modules/store/StoreProvider'; import { useSolanaBalance } from '@/modules/wallet/hooks/useSolanaBalance'; import { MIN_SOL_TO_ENABLED_TX } from '@/core/constants'; +import { useIsWalletCompatible } from '@/modules/wallet/hooks/useIsWalletCompatible'; export const useInputValidation = () => { const { data } = useSolanaBalance(); + const isWalletCompatible = useIsWalletCompatible(); const solBalance = Number(data?.formatted); - const fromChain = useAppSelector((state) => state.transfer.fromChain); const validateInput = useCallback( ({ @@ -59,7 +60,7 @@ export const useInputValidation = () => { } else { return { text: `${formatNumber(balance)}`, isError: false }; } - } else { + } else if (isWalletCompatible) { return { isError: true, text: 'You have insufficient balance' }; } } catch (e: any) { @@ -67,7 +68,7 @@ export const useInputValidation = () => { console.log(e); } }, - [fromChain?.chainType, solBalance], + [fromChain?.chainType, solBalance, isWalletCompatible], ); return {