deBridge 백서

deBridge

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 31쪽 중 22쪽

etwork that depends on some unique transfer identifier, then we need to form `PubkeySubstitutions`. This gives the following Solidity code: ```solidity theme={null} bytes[] memory seeds = new bytes[](3); seeds[0] = DeBridgeSolanaPubkeySubstitutions.getSubmissionAuthSeed(); seeds[1] = DeBridgeSolanaPubkeySubstitutions.getArbitrarySeed( abi.encodePacked(bytes32(tokenId)) // input parameter ); seeds[2] = DeBridgeSolanaPubkeySubstitutions.getArbitrarySeed( abi.encodePacked(bytes32(splNativeMint)) // input parameter ); DeBridgeSolana.PubkeySubstitutionTuple[] memory pubkeySubstitutions = new DeBridgeSolana.PubkeySubstitutionTuple[](1); pubkeySubstitutions[0] = DeBridgeSolana.PubkeySubstitutionTuple({ u64: 1, data: DeBridgeSolanaPubkeySubstitutions.serialize( DeBridgeSolanaPubkeySubstitutions.BySeeds({ program_id: ASSOCIATED_TOKEN_PROGRAM, // input parameter seeds: seeds, bump: 0 // None }) ) }); DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] pubkey_substitutions: pubkeySubstitutions }); ``` If the user can't break protocol rules by passing any Pubkey, then you can take that key directly from the user's input and you don't need substitution. ## Pubkey placeholders As well as pubkey substitutions, placeholders could be used to substitute extcall accounts, but placeholders can't be used to calculate ATA during extcall execution. At the moment we have following placeholders: * **Wallet Placeholder** : `J4vKrc4pCdtiHpxFDfBy4iyZ22Uf7fBjJyJ817k4673y` - if you set this pubkey to some account, it will be replaced by actual Submission Wallet during execution. Submission wallet is a [token account](https://github.com/solana-labs/solana-program-library/blob/523156a0cdd9cada27036bd72d326bc40c00f85f/token/program/src/state.rs#L83-L106) that contains transferred tokens during execution. * **Submission Placehoder** : `7cu34CRu47UZKLRHjt9kFPhuoYyHCzAafGiGWz83GNFs` will be replaced by [Submission account](https://github.com/debridge-finance/debridge-solana-sdk/blob/5c3f5149504daddab38d5383ae6c8c15efb4235c/src/debridge_accounts.rs#L59-L79) during execution. Submission account contains transfer metadata such as native sender, send from chain, etc. * **Authority Placeholder** : `2iBUASRfDHgEkuZ91Lvos5NxwnmiryHrNbWBfEVqHRQZ` will be replaced by Submission Authority account during execution. Submission authority is an owner/authority account for Submission Wallet. It is this account that manages [On-Chain external call preparation for Solana](/dmp-details/dev-guides/solana/on-chain-external-call-preparation#expenses). If both placeholder and substitution are used for the same account, only substitution will be performed. # DataSubstitution If you need a transfer amount as part of your transfer and it cannot be calculated in advance, then you must use `DataSubstitution`. One substitution is now available (`SubmissionAuthWalletAmount`) which works as follows. Takes the `account_index` account of the current instruction, interprets it as a token account, takes its balance, chooses its encoding (big endian, little endian), use `substration` and inserts it into the current instruction by `offset` before calling it. ```solidity theme={null} // use DeBridgeSolanaDataSubstitutions to generate data substutions DeBridgeSolana.DataSubstitution[] memory dataSubstitutions = new DeBridgeSolana.DataSubstitution[](0); DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] data_substitutions: dataSubstitutions }); ``` This way you can transfer the whole wallet balance except for some part of it (e.g. for the next transfers). # Reward The last step is to set the reward. Since for almost any transfer it will depend on the difference between the price of the fee and the price of SOL asset, it will almost always be reported externally. The reward should cover 5000 lamports and all expenses. In the execution phase, the executor evaluates the 5000 + expenses in the translation token and if the reward covers the execution, then it executes the translation. ```solidity theme={null} DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] reward: 5000 }); ``` # Final This algorithm should be done for each instruction in your extcall. The total instruction set must be less than 10 kilobytes. When you have prepared all the necessary instructions, you need to generate a binary buffer and send it through deBridge as external call: ```solidity theme={null} DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] }); // or import the lib: using DeBridgeSolanaSerializer for DeBridgeSolana.ExternalInstruction; DeBridgeSolanaSerializer.serialize(externalInstruction); ``` # Sending Cross-Chain Messages Source: https://docs.debridge.com/dmp-details/dev-guides/solana/sending-cross-chain-messages Sending cross-chain messages from Solana using deBridge programs. To streamline communication with deBridge programs on the Solana blockchain, the debridge-solana-sdk has been developed. This Rust SDK allows for easy and efficient connection to the deBridge infrastructure, which enables decentralized transfers of messages and value between different supported blockchains. To start using our sdk, add it to dependencies by cargo: ```shell theme={null} cargo add debridge-solana-sdk ``` If you use the Anchor framework, then your program calling for a deBridge send might look like this: ```rust theme={null} 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 {} ``` You can use any account in your logic. However, the remaining accounts you pass on will have to be created by the client. Our SDK provides an [example](https://github.com/debridge-finance/debridge-solana-sdk/tree/master/example-program/ts-examples) of how to use the TypeScript library. For this example it is: ```ts theme={null} 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(); ``` The dependency packages that are used: * [@debridge-finance/solana-contracts-client](https://www.npmjs.com/package/@debridge-finance/solana-contracts-client) * [@debridge-finance/solana-utils](https://www.npmjs.com/package/@debridge-finance/solana-utils) * [@coral-xyz/anchor](https://www.npmjs.com/package/@coral-xyz/anchor) * [@solana/web3.js](https://www.npmjs.com/package/@solana/web3.js) For detailed examples, within the SDK there is an [example-program](https://github.com/debridge-finance/debridge-solana-sdk/tree/master/example-program) project that allows you to see examples of various integrations and the corresponding client code for them. For example: * [send\_via\_debridge](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L38) * [send\_via\_debridge\_with\_native\_fixed\_fee](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L69) * [send\_via\_debridge\_with\_exact\_amount](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L140) * [send\_via\_debridge\_with\_asset\_fixed\_fee](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L69) * [send\_via\_debridge\_with\_execution\_fee](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L177) * [send\_via\_debridge\_with\_external\_call](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L211) * [send\_message\_via\_debridge](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L259) * [check\_claiming](https://github.com/debridge-finance/debridge-solana-sdk/blob/7bb2ed38a135d3550dadfd00bdc78f50c19a701d/example-program/programs/debridge-solana-sdk-example/src/lib.rs#L371) # Deployed Contracts Source: https://docs.debridge.com/dmp-details/dmp/deployed-contracts Deployed contracts for deBridge Messaging Protocol (DMP). ## deBridge IaaS Subscription ### Proxy & Implementation | **Label** | **Address** | | ---------------- | ----------------------------------------------------------------------------------------------------------------------- | | `Proxy` | [`0x2328Ee20fA271073328DC94e52Dd5b61aa0C91A7`](https://etherscan.io/address/0x2328Ee20fA271073328DC94e52Dd5b61aa0C91A7) | | `Implementation` | [`0xf46b9e22a2a5B07bd2F601d9A59b4E01424f5E35`](https://etherscan.io/address/0xf46b9e22a2a5B07bd2F601d9A59b4E01424f5E35) | ## deBridge Messaging Protocol (DMP) For deBridge Liquidity Network (DLN) contracts, please refer to [this article](/dln-details/overview/deployed-contracts). ### Solana | **Smart Contract** | **Address** | **Description** | | ------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | `deBridge` | [`DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh`](https://solscan.io/account/DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh) | This contract is the main point of cross-chain interactions coming from users and protocols. It enables sending and execution of cross-chain messages. | | `deBridge Settings` | [`DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft`](https://solscan.io/account/DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft) | Settings program stores validators' signatures and controls all protocols parameters such as fees, consensus algorithms, validators' public keys. | ### EVM | | DeBridgeGate | DeBridgeToken | DeBridgeTokenDeployer | SignatureVerifier | CallProxy | WethGate | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | | **Description** | Main entry point for cross-chain interactions; `send` moves messages + assets | Wrapped asset (deAsset) 1 : 1 collateral-backed | Factory that deploys new deAssets | Validates ≥ 2⁄3 validator signatures before execution | Executes the external call that accompanies a transferred message | Non-upgradeable Ether receiver that immediately forwards funds to an upgradeable contract, avoiding the `transfer` gas-limit issue(\[docs.debridge.com]\[1]) | | **Github** | [LINK](https://github.com/debridge-finance/debridge-contracts-v1/blob/main/contracts/transfers/DeBridgeGate.sol) | [LINK](https://github.com/debridge-finance/debridge-contracts-v1/blob/main/contracts/periphery/DeBridgeToken.sol) | [LINK](https://github.com/debridge-finance/debridge-contracts-v1/blob/main/contracts/transfers/DeBridgeTokenDeployer.sol) | [LINK](https://github.com/debridge-finance/debridge-contracts-v1/blob/main/contracts/transfers/SignatureVerifier.sol) | [LINK](https://github.com/debridge-finance/debridge-contracts-v1/blob/main/contracts/periphery/CallProxy.sol) | [LINK](https://github.com/debridge-finance/debridge-contracts-v1/blob/main/contracts/transfers/WethGate.sol) | | **Chain** | | | | | | | | Ethereum | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://etherscan.io/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b](https://etherscan.io/address/0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://etherscan.io/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://etherscan.io/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://etherscan.io/address/0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824) | [0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59](https://etherscan.io/address/0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59#code) | | BNB Chain | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://bscscan.com/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b](https://bscscan.com/address/0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://bscscan.com/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://bscscan.com/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://bscscan.com/address/0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824#code) | [0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59](https://bscscan.com/address/0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59#code) | | Polygon | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://polygonscan.com/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b](https://polygonscan.com/address/0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://polygonscan.com/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://polygonscan.com/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://polygonscan.com/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA#code) | [0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59](https://polygonscan.com/address/0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59#code) | | Robinhood | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://robinhoodchain.blockscout.com/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF](https://robinhoodchain.blockscout.com/address/0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://robinhoodchain.blockscout.com/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://robinhoodchain.blockscout.com/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://robinhoodchain.blockscout.com/address/0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824) | | | Arc | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://explorer.arc.io/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF](https://explorer.arc.io/address/0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://explorer.arc.io/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://explorer.arc.io/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://explorer.arc.io/address/0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824) | | | Arbitrum | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://arbiscan.io/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b](https://arbiscan.io/address/0xf8A2902c0a5f817F5e22C82f453538d3f0734C2b) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://arbiscan.io/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://arbiscan.io/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://arbiscan.io/address/0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824#code) | | | Avalanche | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://snowtrace.io/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF](https://snowtrace.io/address/0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://snowtrace.io/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c](https://snowtrace.io/address/0x949b3B3c098348b879C9e4F15cecc8046d9C8A8c) | [0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824](https://snowtrace.io/address/0x8a0C79F5532f3b2a16AD1E4282A5DAF81928a824#code) | [0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59](https://snowtrace.io/address/0xFCf83648b8cDeF62e5d03319a6f1FCE16e4D6A59#code) | | Linea | [0x43dE2d77BF8027e25dBD179B491e8d64f38398aA](https://lineascan.build/address/0x43dE2d77BF8027e25dBD179B491e8d64f38398aA) | [0x55C93b20Dd2F790AC429D6341a022A781791654A](https://lineascan.build/address/0x55C93b20Dd2F790AC429D6341a022A781791654A) | [0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464](https://lineascan.build/address/0x8244d6Ffe0695B30b2bAD424683Ee3bc534Ea464) | [0x949b3B3c098348b879C9e4F15cec
프로젝트로 돌아가기