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

feat: Layerzero airdrop native gas #127

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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