deBridge 백서

deBridge

원문

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

| | ------------- | --------- | ---------------------------------- | | `_debridgeId` | `bytes32` | Id of an asset, see getDebridgeId. | | `_name` | `string` | Asset's name. | | `_symbol` | `string` | Asset's symbol. | | `_decimals` | `uint8` | Asset's decimals. | ### getChainId ```solidity theme={null} function getChainId() public returns (uint256 cid) ``` Get current chain id. ### version ```solidity theme={null} function version() external returns (uint256) ``` Get this contract's version. # DeBridgeTokenDeployer Source: https://docs.debridge.com/dmp-details/dev-guides/evm/transfers/DeBridgeTokenDeployer DeBridgeTokenDeployer contract details - fields, functions, and structs. Deploys a deToken (DeBridgeTokenProxy) for an asset. *** ## Variables ### tokenImplementation ```solidity theme={null} address public tokenImplementation; ``` Address of deBridgeToken implementation ### deBridgeTokenAdmin ```solidity theme={null} address public deBridgeTokenAdmin; ``` An address to set as admin for any deployed deBridgeToken ### debridgeAddress ```solidity theme={null} address public debridgeAddress; ``` Debridge gate address ### getDeployedAssetAddress ```solidity theme={null} mapping(bytes32 => address) public getDeployedAssetAddress; ``` Maps debridge id to deBridgeToken address ### overridedTokens ```solidity theme={null} mapping(bytes32 => struct DeBridgeTokenDeployer.OverridedTokenInfo) public overridedTokens; ``` Maps debridge id to overridden token info (name, symbol). Used when autogenerated values are not ideal. *** ## Functions ### initialize ```solidity theme={null} function initialize( address _tokenImplementation, address _deBridgeTokenAdmin, address _debridgeAddress ) public ``` Constructor that initializes the most important configurations. #### Parameters: | Name | Type | Description | | --------------------- | ------- | ----------------------------------------- | | \_tokenImplementation | address | Address of deBridgeToken implementation | | \_deBridgeTokenAdmin | address | Address to set as admin for deBridgeToken | | \_debridgeAddress | address | DeBridge gate address | *** ### deployAsset ```solidity theme={null} function deployAsset( bytes32 _debridgeId, string _name, string _symbol, uint8 _decimals ) external returns (address deBridgeTokenAddress) ``` Deploy a deToken for an asset #### Parameters: | Name | Type | Description | | ------------ | ------- | ---------------- | | \_debridgeId | bytes32 | Asset identifier | | \_name | string | Asset name | | \_symbol | string | Asset symbol | | \_decimals | uint8 | Asset decimals | *** ### implementation ```solidity theme={null} function implementation() public returns (address) ``` Beacon getter for the deBridgeToken contracts *** ### setTokenImplementation ```solidity theme={null} function setTokenImplementation( address _impl ) external ``` Set deBridgeToken implementation contract address #### Parameters: | Name | Type | Description | | ------ | ------- | --------------------------------------------- | | \_impl | address | Wrapped asset implementation contract address | *** ### setDeBridgeTokenAdmin ```solidity theme={null} function setDeBridgeTokenAdmin( address _deBridgeTokenAdmin ) external ``` Set admin for any deployed deBridgeToken. #### Parameters: | Name | Type | Description | | -------------------- | ------- | -------------- | | \_deBridgeTokenAdmin | address | Admin address. | *** ### setDebridgeAddress ```solidity theme={null} function setDebridgeAddress( address _debridgeAddress ) external ``` Sets core debridge contract address. #### Parameters: | Name | Type | Description | | ----------------- | ------- | ----------------- | | \_debridgeAddress | address | Debridge address. | *** ### setOverridedTokenInfo ```solidity theme={null} function setOverridedTokenInfo( bytes32[] _debridgeIds, struct DeBridgeTokenDeployer.OverridedTokenInfo[] _tokens ) external ``` Override specific tokens name/symbol #### Parameters: | Name | Type | Description | | ------------- | -------------------------------------------------- | ------------------------------------ | | \_debridgeIds | bytes32\[] | Array of debridgeIds for tokens | | \_tokens | struct DeBridgeTokenDeployer.OverridedTokenInfo\[] | Array of new name/symbols for tokens | *** ### version ```solidity theme={null} function version() external returns (uint256) ``` Get this contract's version *** ## Structs ### OverridedTokenInfo ```solidity theme={null} struct OverridedTokenInfo { bool accept; string name; string symbol; } ``` # OraclesManager Source: https://docs.debridge.com/dmp-details/dev-guides/evm/transfers/OraclesManager OraclesManager contract details - fields and functions. The base contract for oracles management. Allows adding/removing oracles, managing the minimal required amount of confirmations. *** ## Variables ### minConfirmations ```solidity theme={null} uint8 public minConfirmations; ``` Minimal required confirmations ### excessConfirmations ```solidity theme={null} uint8 public excessConfirmations; ``` Minimal required confirmations in case of too many confirmations ### requiredOraclesCount ```solidity theme={null} uint8 public requiredOraclesCount; ``` Count of required oracles ### oracleAddresses ```solidity theme={null} address[] public oracleAddresses; ``` Oracle addresses ### getOracleInfo ```solidity theme={null} mapping(address => struct IOraclesManager.OracleInfo) public getOracleInfo; ``` Maps an oracle address to the oracle details *** ## Functions ### initialize ```solidity theme={null} function initialize( uint8 _minConfirmations, uint8 _excessConfirmations ) internal ``` Constructor that initializes the most important configurations. #### Parameters: | Name | Type | Description | | --------------------- | ----- | ------------------------------------------------------- | | \_minConfirmations | uint8 | Minimal required confirmations. | | \_excessConfirmations | uint8 | Minimal confirmations in case of too many confirmations | *** ### setMinConfirmations ```solidity theme={null} function setMinConfirmations( uint8 _minConfirmations ) external ``` Sets minimal required confirmations. #### Parameters: | Name | Type | Description | | ------------------ | ----- | ------------------------------- | | \_minConfirmations | uint8 | Minimal required confirmations. | *** ### setExcessConfirmations ```solidity theme={null} function setExcessConfirmations( uint8 _excessConfirmations ) external ``` Sets minimal required confirmations in case of too many confirmations. #### Parameters: | Name | Type | Description | | --------------------- | ----- | ------------------------------------------------------- | | \_excessConfirmations | uint8 | Minimal confirmations in case of too many confirmations | *** ### addOracles ```solidity theme={null} function addOracles( address[] _oracles, bool[] _required ) external ``` Add oracles. #### Parameters: | Name | Type | Description | | ---------- | ---------- | ------------------------------------------------------------------------- | | \_oracles | address\[] | Oracles' addresses. | | \_required | bool\[] | A transfer will not be confirmed without oracles having required set true | *** ### updateOracle ```solidity theme={null} function updateOracle( address _oracle, bool _isValid, bool _required ) external ``` Update an oracle. #### Parameters: | Name | Type | Description | | ---------- | ------- | -------------------------------------------------------------- | | \_oracle | address | An oracle address. | | \_isValid | bool | Is this oracle valid (i.e. should it be treated as an oracle)? | | \_required | bool | If true, a transfer will not be confirmed without this oracle. | # SignatureVerifier Source: https://docs.debridge.com/dmp-details/dev-guides/evm/transfers/SignatureVerifier SignatureVerifier contract details - fields and functions. Used to verify that a transfer is signed by oracles. *** ## Variables ### confirmationThreshold ```solidity theme={null} uint8 public confirmationThreshold; ``` Number of required confirmations per block after the extra check is enabled ### submissionsInBlock ```solidity theme={null} uint40 public submissionsInBlock; ``` Submissions count in current block ### currentBlock ```solidity theme={null} uint40 public currentBlock; ``` Current block ### debridgeAddress ```solidity theme={null} address public debridgeAddress; ``` Debridge gate address *** ## Functions ### initialize ```solidity theme={null} function initialize( uint8 _minConfirmations, uint8 _confirmationThreshold, uint8 _excessConfirmations ) public ``` Constructor that initializes the most important configurations. #### Parameters: | Name | Type | Description | | ----------------------- | ----- | ---------------------------------------------------- | | \_minConfirmations | uint8 | Common confirmations count. | | \_confirmationThreshold | uint8 | Confirmations per block after extra check is enabled | | \_excessConfirmations | uint8 | Confirmations count in case of excess activity | *** ### submit ```solidity theme={null} function submit( bytes32 _submissionId, bytes _signatures, uint8 _excessConfirmations ) external ``` Check confirmation (validate signatures) for the transfer request. #### Parameters: | Name | Type | Description | | --------------------- | ------- | -------------------------------- | | \_submissionId | bytes32 | Submission identifier. | | \_signatures | bytes | Array of signatures by oracles. | | \_excessConfirmations | uint8 | Override min confirmations count | *** ### setThreshold ```solidity theme={null} function setThreshold( uint8 _confirmationThreshold ) external ``` Sets minimal required confirmations. #### Parameters: | Name | Type | Description | | ----------------------- | ----- | ------------------ | | \_confirmationThreshold | uint8 | Confirmation info. | *** ### setDebridgeAddress ```solidity theme={null} function setDebridgeAddress( address _debridgeAddress ) external ``` Sets core debridge contract address. #### Parameters: | Name | Type | Description | | ----------------- | ------- | ----------------- | | \_debridgeAddress | address | Debridge address. | *** ### isValidSignature ```solidity theme={null} function isValidSignature( bytes32 _submissionId, bytes _signature ) external returns (bool) ``` Check is valid signature #### Parameters: | Name | Type | Description | | -------------- | ------- | ---------------------- | | \_submissionId | bytes32 | Submission identifier. | | \_signature | bytes | Signature by oracle. | *** ### \_countSignatures ```solidity theme={null} function _countSignatures( bytes _signatures ) internal returns (uint256) ``` *** ### version ```solidity theme={null} function version() external returns (uint256) ``` Get this contract's version # WethGate Source: https://docs.debridge.com/dmp-details/dev-guides/evm/transfers/WethGate WethGate contract details - fields, functions, and events. Upgradable contracts cannot receive ether via `transfer` because of increased `SLOAD` gas cost. We use this non-upgradeable contract as the recipient and then immediately transfer to an upgradable contract. More details about this issue can be found [here](https://forum.openzeppelin.com/t/openzeppelin-upgradeable-contracts-affected-by-istanbul-hardfork/1616). *** ## Variables ### weth ```solidity theme={null} contract IWETH public weth; ``` Wrapped native token contract *** ## Functions ### constructor ```solidity theme={null} function constructor( contract IWETH _weth ) public ``` ### withdraw ```solidity theme={null} function withdraw( address receiver, uint256 wad ) external ``` Transfer assets to a receiver. #### Parameters: | Name | Type | Description | | -------- | ------- | ------------------------------------ | | receiver | address | This address will receive a transfer | | wad | uint256 | Amount in wei | *** ### \_safeTransferETH ```solidity theme={null} function _safeTransferETH( address _to, uint256 _value ) internal ``` ### receive ```solidity theme={null} function receive() external ``` ### version ```solidity theme={null} function version() external returns (uint256) ``` Get this contract's version *** ## Events ### Withdrawal ```solidity theme={null} event Withdrawal( address receiver, uint256 wad ) ``` Emitted when any amount is withdrawn. # Gathering Data for the Claim Source: https://docs.debridge.com/dmp-details/dev-guides/gathering-data-for-claim Data sources and steps required to build a claim transaction. To claim a submission, a call to the deBridgeGate.claim() method on the destination chain must be crafted using data taken from various sources. Though deSDK already [provides a handy method for this](https://github.com/debridge-finance/desdk#tracking-and-executing-claims), we explain here where to take and how to prepare this data. * `_debridgeId`, `_amount`, `_receiver`, `_nonce` can be taken from the corresponding args of the Sent event, * `_chainIdFrom` is obviously the ID of the origin chain, * `_signatures` is the string with the signatures concatenated without a delimiter (don't forget to strip hexadecimal prefixes from each but the first); signatures can be pulled from the deBridge API, * `_autoParams` is the encoded `SubmissionAutoParamsFrom` struct, which is the derivative of the `SubmissionAutoParamsTo` with `nativeSender` taken from the Se`nt event: so you need to decode `\_autoParams`against the`SubmissionAutoParamsTo`struct, add the fifth element, and encode back against the`SubmissionAutoParamsFrom\` struct. This simple diagram shows the flow of the properties; dashed lines indicate the necessity of data decoding/encoding/unpacking/packing, while the straight line shows that the datum should be passed as is: <img alt="Gathering Data for Claims" /> After all these elements are combined into one single call, you can sign and broadcast your transaction and wait for the `Claimed` event. This will indicate a successful submission. # Off-Chain External Call Preparation Source: https://docs.debridge.com/dmp-details/dev-guides/solana/off-chain-external-call-preparation How to serialize and assemble off-chain external call data for Solana. Instructions should be serialized one by one, final calldata is a concatenation of separately serialized instructions. For the info about the rewards, substitutions, and expenses check the previous section. Solana's `TransactionInstructions` could be serialized into calldata format using [`@debridge-finance/debridge-external-call`](https://www.npmjs.com/package/@debridge-finance/debridge-external-call) npm package: ```typescript theme={null} import * as wasm from "@debridge-finance/debridge-external-call"; import { PublicKey, TransactionInstruction } from "@solana/web3.js"; /** * Substitutes amount at offset with `walletBalance(accounts[account_index]) - subtraction` */ type AmountSubstitution = { /** * big or little endian */ is_big_endian: boolean; /** * At what offset substitution should be done */ offset: number; /** * index of account in TransactionInstruction.keys to get balance for */ account_index: number; /** * Amount to deduct from wallet balance */ subtraction: number; }; /** * Since we don't know submissionAuth at the moment of calldata preparation we can prepare substitution to replace * account at `index` with actual ATA(submissionAuth, tokenMint) during execution */ type WalletSubstitution = { /** * Token mint to calculate ATA for */ token_mint: string; /** * Account at this index will be replaced with ATA(submissionAuth, tokenMint) during execution */ index: number; }; /** * Structure required by wasm module */ interface IExtIx { keys: { pubkey: string; isSigner: boolean; isWritable: boolean; }[]; data: Buffer; programId: string; } function ixToIExtIx(ix: TransactionInstruction): IExtIx { return { keys: ix.keys.map((meta) => ({ pubkey: meta.pubkey.toBase58(), isSigner: meta.isSigner, isWritable: meta.isWritable, })), programId: ix.programId.toBase58(), data: ix.data, }; } function serialize( instruction: TransactionInstruction, substitutions?: { amountSubstitutions?: AmountSubstitution[]; walletSubstitutions?: WalletSubstitution[]; }, expense?: bigint, reward?: bigint, isInMandatoryBlock: boolean = false, ) { const ixWrapper = new wasm.ExternalInstructionWrapper( reward, expense, isInMandatoryBlock, substitutions?.amountSubstitutions ?? [], substitutions?.walletSubstitutions ?? [], ixToIExtIx(instruction), ); return ixWrapper.serialize(); } const ix1: TransactionInstruction; const ix2: TransactionInstruction; const serializedIx1 = serialize(ix1, undefined, 1000n); const serializedIx2 = serialize(ix2, undefined, 2000n); const calldata = Buffer.concat([serializedIx1, serializedIx2 /** rest serialized instructions if any */]); ``` # On-Chain External Call Preparation Source: https://docs.debridge.com/dmp-details/dev-guides/solana/on-chain-external-call-preparation On-Chain External Call Preparation: Pubkey placeholders, Instruction, and Expenses. Preparing an extcall to call programs on Solana is simple: # Instruction Identify the Instruction-s you need to call in Solana. For example, the following Instruction ```solidity theme={null} Instruction { // Constant // 0x8c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f859 program_id: Pubkey::from_str("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL").unwrap(), accounts: vec![ // Pubkey Auth Placeholder, constant AccountMeta { // 0x1968562fef0aab1b1d8f99d44306595cd4ba41d7cc899c007a774d23ad702ff6 pubkey: Pubkey::from_str("2iBUASRfDHgEkuZ91Lvos5NxwnmiryHrNbWBfEVqHRQZ") .unwrap(), is_signer: true, is_writable: true, }, // Can be any - not important, will be replaced by substituion later AccountMeta { // 0x9f3d96f657370bf1dbb3313efba51ea7a08296ac33d77b949e1b62d538db37f2 pubkey: Pubkey::from_str("BicJ4dmuWD3bfBrJyKKeqzczWDSGUepUpaKWmC6XRoJZ") .unwrap(), is_signer: false, is_writable: true, }, ], // Constant data: vec![1], } ``` can be represented in Solidity as follows: ```solidity theme={null} DeBridgeSolana.AccountMeta[] memory accountMetas = new DeBridgeSolana.AccountMeta[](2); accountMetas[0] = DeBridgeSolana.AccountMeta({ // 2iBUASRfDHgEkuZ91Lvos5NxwnmiryHrNbWBfEVqHRQZ pubkey: 0x1968562fef0aab1b1d8f99d44306595cd4ba41d7cc899c007a774d23ad702ff6, is_signer: true, is_writable: true }); accountMetas[1] = DeBridgeSolana.AccountMeta({ // BicJ4dmuWD3bfBrJyKKeqzczWDSGUepUpaKWmC6XRoJZ pubkey: 0x9f3d96f657370bf1dbb3313efba51ea7a08296ac33d77b949e1b62d538db37f2, is_signer: false, is_writable: true }); DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] instruction: DeBridgeSolana.Instruction({ // ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL program_id: 0x8c97258f4e2489f1bb3d1029148e0d830b5a1399daff1084048e7bd8dbe9f859, accounts: accountMetas, data: hex"1" }) }); ``` # Expenses Determine how much lamports your instruction spends on the destination network (most often, for account creation). Record this value as expenses. Each instruction is technically worth 5000 lamports (since we can't determine how many resources it will spend in advance, the implication is that it can be executed in a separate transaction). Therefore, 5000 + expenses is the estimate of how much lamports will cost the execution. ```solidity theme={null} DeBridgeSolana.ExternalInstruction memory externalInstruction = DeBridgeSolana.ExternalInstruction({ // [...] expense: 5000, }); ``` # Pubkey substituion Determine which accounts in the instruction are input-dependent and cannot be passed directly from the user for security reasons. For example, if there is a PDA in the destination n
프로젝트로 돌아가기