Crates.io | debridge-solana-sdk |
lib.rs | debridge-solana-sdk |
version | 1.0.1 |
source | src |
created_at | 2023-06-29 11:13:35.24599 |
updated_at | 2023-07-04 10:04:45.948849 |
description | debridge-solana-sdk allows you to easily and quickly connect your Solana programs to the debridge infrastructure. Debridge protocol enables decentralized transfers of arbitrary messages and value between various blockchains. |
homepage | |
repository | |
max_upload_size | |
id | 903185 |
size | 91,524 |
debridge-solana-sdk allows you to easily and quickly connect your Solana programs to the debridge infrastructure. Debridge protocol enables decentralized transfers of arbitrary messages and value between various blockchains. See Debridge documentation for more information docs.
This example show how you can send some tokens and message to any supported chain using debridge-solana-sdk crate.
Debridge-solana-sdk doesn't depend on any solana framework like Anchor and can be connected to any Solana program. But for simplifying example we will use example program built with Anchor.
anchor init send-via-debridge
Next step is add debridge-solana-sdk crate to program dependency:
cargo add --git ssh://git@github.com/debridge-finance/debridge-solana-sdk.git debridge-solana-sdk
Add in ./send-via-debridge/programs/src/lib.rs
code of simple smart contract that transfer tokens and message to other
chain with debridge solana program:
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(
SendIx {
target_chain_id: chain_ids::POLYGON_CHAIN_ID,
receiver: hex::decode("bd1e72155Ce24E57D0A026e0F7420D6559A7e651").unwrap(),
is_use_asset_fee: false,
amount: 1000,
submission_params: None,
referral_code: None,
},
ctx.remaining_accounts,
)
.map_err(|err| err.into())
}
}
#[derive(Accounts)]
pub struct SendViaDebridge {}
To see program examples please visit:
Build program with anchor:
cd example_program; anchor build
Deploy program
solana program deploy --program-id target/deploy/send_via_debridge-keypair.json ./target/deploy/send_via_debridge.so
Add file ./send-via-debridge/tests/send-via-debridge.ts
with next test case:
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { SendViaDebridge } from "../target/types/send_via_debridge";
import { AccountMeta, PublicKey, Signer } from "@solana/web3.js";
function accountsToMeta() {
const result: AccountMeta[] = [
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("6SW1N9Rq2TqT3uQCD4F5zwtTTSFSarZmfyrk829SzsBX"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("So11111111111111111111111111111111111111112"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("8gjgVkHXTttCoSGGtzucFkJUWujQ8pgWuvnHCLSN7i3o"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("7FmGdfJfDrrM6P68y7jijjj4xU9rH3hsUK2Kyp54iJUx"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("8L81QZBfwA6Xi9zd49fyUfMRWJBCAxiUxd6jGHPnu1BQ"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("CcjkxrCJvfXrmds78hwCnovkdmTgE12wqojiVLrtW1qn"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("5MgAaNomDg4Y88v7gJ7LSWAyoLpDfcfbXZGQQnFddjJT"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("2LKQceMRwfJNZovtSbsHmfszDYM5kTZHajFry2nqD2pi"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("BzoSTqbp8vZ54Baq2K4LTwGnC8fYvKiEFQDNxdEDnosG"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("11111111111111111111111111111111"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("dPLMV1ky3H61yRGFfNC6AYmzBePhsdes9oNZ7chPbYW"),
},
{
isSigner: false,
isWritable: true,
pubkey: new PublicKey("2cU8vjsMnRcusX1WdwZy1AwCLrUWbDw6frnk3XDz3VVK"),
},
{
isSigner: true,
isWritable: true,
pubkey: new PublicKey("FsiBNh2KcPrjZFMF7EBCWpUpAo95DfrMXB2U2XrqSFWF"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("4kQYWVy6Vu8YUXVp5BgQC12ZX1HLRUfkK3bLzBFFjnNW"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("APMGxdbtubfWLQUACsN2yv2pxkvAgWwuxBe8ohFYoB37"),
},
{
isSigner: false,
isWritable: false,
pubkey: new PublicKey("DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh"),
},
];
return result;
}
describe("send-via-debridge", async () => {
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.SendViaDebridge as Program<SendViaDebridge>;
it("Send via Debridge!", async () => {
const builder = await program.methods
.sendViaDebridge()
.signers([program.provider.wallet.payer]);
builder.remainingAccounts([...accountsToMeta()]);
let tx = await builder.rpc();
console.log("Your transaction signature", tx);
});
});
Then in ./send-via-debridge/Anchor.toml
change cluster to mainnet
to use Debridge production contract:
[provider]
cluster = "mainnet"
To run test use with build and deploy contract use:
anchor test
To test running only use:
anchor test --skip-build --skip-deploy
Examples of sdk using you can find in example solana program by path ./send-via-debridge/exampleprogram