Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cake/gas limit1129 #157

Merged
merged 9 commits into from
Dec 3, 2024
5 changes: 5 additions & 0 deletions .release/.changeset/metal-forks-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Show input error message when wallet is connected
6 changes: 6 additions & 0 deletions packages/canonical-bridge-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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.1",
"version": "0.4.2",
"description": "canonical bridge sdk",
"author": "bnb-chain",
"private": false,
Expand Down
26 changes: 22 additions & 4 deletions packages/canonical-bridge-sdk/src/layerZero/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,25 @@ export class LayerZero {
}: ISendCakeTokenInput): Promise<Hash> {
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,
Expand Down Expand Up @@ -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,
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.5

### Patch Changes

- 792cae1: Check Layerzero destination gas limit

## 0.5.4

### 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.4",
"version": "0.5.5",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
({
Expand Down Expand Up @@ -59,15 +60,15 @@ 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) {
// eslint-disable-next-line no-console
console.log(e);
}
},
[fromChain?.chainType, solBalance],
[fromChain?.chainType, solBalance, isWalletCompatible],
);

return {
Expand Down
Loading