- @debridge-finance/solana-contracts-client
- @debridge-finance/solana-utils
- @coral-xyz/anchor
- @solana/web3.js
cargo add debridge-solana-sdk
use anchor_lang::prelude::*;
declare_id!("3botMWU4s1Lcs4Q2wQBkZqsCW1vc3N9H9tY9SZYVs5vZ");
#[program]
pub mod send_via_debridge {
use debridge_solana_sdk::prelude::*;
use super::*;
pub fn send_via_debridge(ctx: Context<SendViaDebridge>) -> Result<()> {
invoke_debridge_send(
// Debridge Instruction Data
SendIx {
// Chain id to which the tokens are sent
target_chain_id: chain_ids::POLYGON_CHAIN_ID,
/// Address in `target_chain_id` that will receive the transferred tokens
receiver: hex::decode("bd1e72155Ce24E57D0A026e0F7420D6559A7e651").unwrap(),
// Use of fee in transfer token (not currently enabled)
is_use_asset_fee: false,
// Amount of sending tokens. From this amount fee will be taken
amount: 1000,
// Additional data for tokens sending with auto external execution
submission_params: None,
// Referral code to track your transfers
referral_code: None,
},
// List of accounts used by debridge-program, generated on the client
ctx.remaining_accounts,
)
.map_err(|err| err.into())
}
}
#[derive(Accounts)]
pub struct SendViaDebridge {}
import { DeBridgeSolanaClient } from "@debridge-finance/solana-contracts-client";
import { AnchorProvider, Program, Wallet as AnchorWallet } from "@coral-xyz/anchor";
import { Connection, clusterApiUrl } from "@solana/web3.js";
import { crypto, helpers, WRAPPED_SOL_MINT } from "@debridge-finance/solana-utils";
const connection = new Connection(clusterApiUrl("mainnet-beta"));
const example = new Program(
ExampleIDL,
"3botMWU4s1Lcs4Q2wQBkZqsCW1vc3N9H9tY9SZYVs5vZ",
new AnchorProvider(connection, {} as unknown as AnchorWallet, {}),
);
const deBridge = new DeBridgeSolanaClient(connection, undefined, {
programId: "DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh",
settingsProgramId: "DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft",
});
const chainTo = 137;
const receiver = "0xbd1e72155Ce24E57D0A026e0F7420D6559A7e651";
const amount = 1000;
const tokenMint = WRAPPED_SOL_MINT;
const builder = example.methods.sendViaDebridge(
amount,
Array.from(crypto.normalizeChainId(chainTo)),
helpers.hexToBuffer(receiver),
false,
);
const context = await deBridge.buildSendContext(
sender,
null,
tokenMint,
receiver,
chainTo,
false,
receiver,
);
builder.remainingAccounts([...context.asAccountMeta, { isWritable: false, isSigner: false, pubkey: deBridge.program.programId }]);
const tx = await builder.transaction();