Skip to content

Commit

Permalink
feat: Layerzero airdrop native gas
Browse files Browse the repository at this point in the history
  • Loading branch information
Halibao-Lala committed Nov 13, 2024
1 parent c3507aa commit dfa318b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/canonical-bridge-sdk/src/layerZero/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ export class LayerZero {
walletClient,
gasAmount = 200000n,
version = 1,
airDropGas = 0n,
dstAddress = '0x',
}: ISendCakeTokenInput): Promise<Hash> {
try {
const address32Bytes = pad(userAddress, { size: 32 });
const adapterParams = encodePacked(
['uint16', 'uint256'],
[version, 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', 'uint', 'uint', 'address'],
[2, gasAmount, airDropGas, dstAddress]
);
const fees = await publicClient.readContract({
address: bridgeAddress,
abi: CAKE_PROXY_OFT_ABI,
Expand Down Expand Up @@ -109,13 +118,18 @@ export class LayerZero {
publicClient,
gasAmount = 200000n,
version = 1,
airDropGas = 0n,
dstAddress = '0x',
}: IGetEstimateFeeInput) {
try {
const address32Bytes = pad(userAddress, { size: 32 });
const adapterParams = encodePacked(
['uint16', 'uint256'],
[version, gasAmount]
);
const adapterParams =
version === 1
? encodePacked(['uint16', 'uint256'], [version, gasAmount])
: encodePacked(
['uint16', 'uint', 'uint', 'address'],
[2, gasAmount, airDropGas, dstAddress]
);
const fees = await publicClient.readContract({
address: bridgeAddress,
abi: CAKE_PROXY_OFT_ABI,
Expand Down
4 changes: 4 additions & 0 deletions packages/canonical-bridge-sdk/src/layerZero/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface ISendCakeTokenInput {
version?: number;
publicClient: PublicClient;
walletClient: WalletClient;
dstAddress?: `0x${string}`;
airDropGas?: bigint;
}

export interface IGetEstimateFeeInput {
Expand All @@ -21,6 +23,8 @@ export interface IGetEstimateFeeInput {
gasAmount?: bigint;
version?: number;
publicClient: PublicClient;
dstAddress?: `0x${string}`;
airDropGas?: bigint;
}

export interface LayerZeroToken {
Expand Down

0 comments on commit dfa318b

Please sign in to comment.