deBridge 백서

deBridge

원문

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

L element on the page | | `v` | `string` | Widget version (possible value: `'1'`) | | `mode` | `string` | Type of project (possible value: `'deswap'`) | | `title` | `string` | Widget header | | `width` | `number` | Width of the widget | | `height` | `number` | Height of the widget | | `inputChain` | `number` | ID of the input chain (possible values: `1`, `56`, `137`, `42161`, `43114`) | | `outputChain` | `number` | ID of the output chain (same values as above) | | `inputCurrency` | `string` | Address of the input token | | `outputCurrency` | `string` | Address of the output token | | `address` | `string` | Address of the receiver | | `amount` | `string` | Amount to exchange | | `lang` | `string` | Default language (possible values: `'en'`, `'fr'`, `'jp'`, `'ko'`, `'ru'`, `'vi'`, `'zh'`) | | `styles` | `string` | Base64-encoded styles object | | `theme` | `string` | Theme mode (possible values: `'dark'`, `'light'`) | | `r` | `string` | Integrator referral code | <Accordion title="Example"> ```json theme={null} { "element": "debridgeWidget", "v": "1", "mode": "deswap", "title": "deSwap", "width": "600", "height": "800", "inputChain": "56", "outputChain": "1", "inputCurrency": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", "outputCurrency": "0xdac17f958d2ee523a2206206994597c13d831ec7", "address": "0x64023dEcf09f20bA403305F5A2946b5b33d1933B", "amount": "10", "lang": "en", "mode": "deswap", "styles": "eyJmb250RmFtaWx5IjoiQWJlbCJ9", "theme": "dark", "r": "3981" } ``` </Accordion> ## Styles The styles field contains the fields: ```typescript theme={null} { appBackground: string, appAccentBg: string, chartBg:string, primary: string, secondary: string, badge: string, borderColor: string, borderRadius: number, fontColor:string, fontColorAccent:string, fontFamily: string } ``` <img alt="Widget Styles" /> <Accordion title="HTML Example"> ```html theme={null} <html> <head> <script src="https://app.debridge.com/assets/scripts/widget.js"></script> </head> <body> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Widget Example</title> </head> <body> <div id="debridgeWidget"></div> <script> const script = document.createElement("script"); script.src = "https://app.debridge.com/assets/scripts/widget.js"; script.onload = () => { console.log("✅ Widget script loaded!"); if (window.deBridge) { window.deBridge.widget({ "v": "1", "element": "debridgeWidget", "title": "", "description": "", "width": "600", "height": "800", "r": "31805", "supportedChains": { "inputChains": { "1": "all", "10": "all", "56": "all", "100": "all", "137": "all", "146": "all", "388": "all", "747": "all", "998": "all", "999": "all", "1088": "all", "1329": "all", "1514": "all", "2741": "all", "4158": "all", "5000": "all", "8453": "all", "32769": "all", "42161": "all", "43114": "all", "50104": "all", "59144": "all", "60808": "all", "80094": "all", "98866": "all", "7565164": "all", "245022934": "all" }, "outputChains": { "1": "all", "10": "all", "56": "all", "100": "all", "137": "all", "146": "all", "388": "all", "747": "all", "998": "all", "999": "all", "1088": "all", "1329": "all", "1514": "all", "2741": "all", "4158": "all", "5000": "all", "8453": "all", "32769": "all", "42161": "all", "43114": "all", "50104": "all", "59144": "all", "60808": "all", "80094": "all", "98866": "all", "7565164": "all", "245022934": "all" } }, "inputChain": 7565164, "outputChain": 42161, "inputCurrency": "11111111111111111111111111111111111111111", "outputCurrency": "0xaf88d065e77c8cc2239327c5edb3a432268e5831", "address": "", "showSwapTransfer": true, "amount": "", "outputAmount": "", "isAmountFromNotModifiable": false, "isAmountToNotModifiable": false, "lang": "en", "mode": "deswap", "isEnableCalldata": false, "styles": "e30=", "theme": "dark", "isHideLogo": false, "logo": "", "disabledWallets": [], "disabledElements": [] }); } else { console.error("❌ debridgeWidget not found on window"); } }; script.onerror = () => { console.error("❌ Failed to load widget script"); }; document.head.appendChild(script); </script> <div id="debridgeWidget"></div> </body> </html> ``` </Accordion> # deBridge Widget events and methods ## Widget Initialization The widget is initialized asynchronously using: ```typescript theme={null} const widget = await deBridge.widget(params); ``` ## Events The widget object supports several event listeners that respond to specific actions. Each event can be registered using: ```typescript theme={null} widget.on('eventName', (event, params) => { // Handle event logic here }); ``` ### Available Events ### `needConnect` * Triggered when the widget requires a connection. * Example handler: ```ts theme={null} widget.on('needConnect', (widget) => { console.log('needConnect event', widget); }); ``` ### `order` * Triggered when an order is created. * Parameters: * `params.status`: Order status. * Example handler: ```ts theme={null} widget.on('order', (widget, params) => { console.log('order params', params); }); ``` ### `singleChainSwap` * Triggered when a single-chain swap occurs. * Example handler: ```ts theme={null} widget.on('singleChainSwap', (widget, params) => { console.log('singleChainSwap params', params); }); ``` ### `bridge` * Triggered when a deport transaction occurs. * Parameters: * `params.status`: Bridge status. * Example handler: ```ts theme={null} widget.on('bridge', (widget, params) => { console.log('deport event', widget, params); }); ``` ### `callData` * Triggered when call data for an order is required. * Example handler: ```ts theme={null} widget.on('callData', (widget, params) => { if ( params.createOrderParams.takeChainId == 137 && params.createOrderParams.takeTokenAddress == "0x2791..." ) { return { to: "0x...", data: "0x..." }; } return null; }); ``` ### `inputChainChanged` * Triggered when the input chain is changed. * Example handler: ```ts theme={null} widget.on('inputChainChanged', (widget, params) => { console.log('inputChainChanged event', widget, params); }); ``` ### `outputChainChanged` * Triggered when the output chain is changed. * Example handler: ```ts theme={null} widget.on('outputChainChanged', (widget, params) => { console.log('outputChainChanged event', widget, params); }); ``` ### `inputTokenChanged` * Triggered when the input token is changed. * Example handler: ```ts theme={null} widget.on('inputTokenChanged', (widget, params) => { console.log('inputTokenChanged event', widget, params); }); ``` ### `outputTokenChanged` * Triggered when the output token is changed. * Example handler: ```ts theme={null} widget.on('outputTokenChanged', (widget, params) => { console.log('outputTokenChanged event', widget, params); }); ``` ## Methods The widget object provides several methods to programmatically interact with it. ### `disconnect()` Disconnects the connected wallet in the widget. * Example usage: ```ts theme={null} widget.disconnect(); ``` ### `changeInputChain(chainId)` Changes the input chain to the specified `chainId`. * Example usage: ```ts theme={null} widget.changeInputChain(1); ``` ### `changeOutputChain(chainId)` Changes the output chain to the specified `chainId`. * Example usage: ```ts theme={null} widget.changeOutputChain(10); ``` ### `changeInputToken(tokenAddress)` Changes the input token using the given token address. * Example usage: ```ts theme={null} widget.changeInputToken('0x...'); ``` ### `changeOutputToken(tokenAddress)` Changes the output token using the given token address. * Example usage: ```ts theme={null} widget.changeOutputToken('0x...'); ``` ### `setExternalEVMWallet(walletConfig)` Connects an external EVM-compatible wallet. * Example usage: ```ts theme={null} widget.setExternalEVMWallet({ provider: window.phantom?.ethereum, name: "Metamask", imageSrc: 'https://app.debridge.com/assets/images/dln-details/wallet/metamask.svg' }); ``` ### `setExternalSolanaWallet(walletConfig)` Connects an external Solana-compatible wallet. * Example usage: ```ts theme={null} widget.setExternalSolanaWallet({ provider: window.solana, name: "Phantom", imageSrc: 'https://app.debridge.com/assets/images/dln-details/wallet/phenom.svg' }); ``` ### `setReceiverAddress(address)` Sets the receiver's wallet address. * Example usage: ```ts theme={null} widget.setReceiverAddress('0x...'); ``` ### `setAffiliateFee(feeConfig)` Sets the affiliate fee for Solana and EVM networks. * Example usage: ```ts theme={null} widget.setAffiliateFee({ solana: { affiliateFeePercent: '0.5', affiliateFeeRecipient: 'B5...', }, evm: { affiliateFeePercent: '1', affiliateFeeRecipient: '0x...', } }); ``` # deBridge Widget builder The builder is available at [https://app.debridge.com/widget](https://app.debridge.com/widget) and contains: * Widget settings fields * Widget preview * Field with source code for embedding in the application # Work Algorithm * Fill in the fields of widget settings to see your future widget. All field changes are updated in real time. * Once UI and other settings suit your requirements, you can just copy the source code to your project to embed the widget according to the "Widget embedding" section. # Getting Started Source: https://docs.debridge.com/dmp-details/dePort/getting-started Getting started with dePort – a native bridge for assets that allows protocols to bridge tokens and create utility for their synthetic representation on other chains. <img alt="dePort" /> [dePort](https://app.debridge.com/deport) is a native bridge for assets that allows protocols to bridge tokens and create utility for their synthetic representation (deTokens) on other chains. dePort utilizes a lock-and-mint approach where the native token is locked/unlocked in a deBridgeGate smart contract on the native (source) chain and its synthetic representation (deAsset) is minted/burnt in secondary (target) chains. For each asset, under the native chain, we assume the unique blockchain where the token was originally created. Secondary chains are blockchains supported by deBridge to which tokens can be transferred/bridged and where deAssets are minted. # Collateralization Each of the tokens locked in the native chain have the associated wrapped asset on the target chains. By design, the protocol ensures that the total supply of each deAsset that can be minted on secondary chains is always 1:1 backed by the asset collateral locked in the deBridgeGate smart contract on the native chain. That provides more secure and reliable user experience and guarantees that the user will not face a liquidity imbalance problem which has been encountered in other bridging solutions, where users face significant delays after they already locked liquidity in a bridge. # Listing at deBridge The deBridge protocol is universal and there are no listing requirements. Any arbitrary token can be bridged. If the token is bridged for the first time, together with the validation transaction validators sign a unique deployId that is passed to the destination chain and contains the following parameters: * Native token smart contract address * Native chain Id * Token name * Token symbol * Decimals The wrapped (deAsset) is deployed on the target chain automatically together with the first claim of the wrapped asset. Thus, no additional actions are required from the user, listing is performed automatically by deBridge validators who sign a unique deployment ID. At deBridge, we care about user experience and strive to minimize unnecessary actions to be performed by protocol users. # Transfer Flow Source: https://docs.debridge.com/dmp-details/dePort/transfer-flow dePort Transfer Flow: Transfers From Native (Source) Chain and Cross-Chain Transfers Execution Time. <img alt="DePort Transfers Flow" /> # Transfers From Native (Source) Chain Let's consider the situation where the user or smart contracts performs a transfer of the asset and data from chain A to chain B. Then the following steps are performed: * If the transferred asset isn't the base blockchain asset (i.e ETH or BNB) the approved method is called or the permit is signed. Then the `send` method of the `DebridgeGate` contract is invoked. The transferred amount of the asset is locked in the smart contract or burnt (for deAssets in secondary chains). The % component of the protocol's fee is deducted from the amount and transferred to the treasury, fix component of the fee is paid by the user in the base chain asset and also transferred to the treasury. * `DebridgeGate` smart contract calculates the unique hash of cross-chain transaction based on the set of unique parameters: ```solidity theme={null} _debridgeID = keccak256(abi.encodePacked(_chainId, _tokenAddress)); bytes memory packedSubmission = abi.encodePacked( SUBMISSION_PREFIX, _debridgeId, getChainId(), _chainIdTo, _amount, _receiver, nonce ); submissionId = keccak256( abi.encodePacked( packedSubmission, autoParams.executionFee, autoParams.flags, keccak256(autoParams.fallbackAddress), isHashedData ? autoParams.data : abi.encodePacked(keccak256(autoParams.data)), keccak256(abi.encodePacked(msg.sender)) ) ); ``` `debridgeID` is a hash of concatenation of the token native chain Id and native token address. * deBridge validation nodes track events emitted by `deBridgeGate` smart contract and after a minimum number of blocks confirmations validators submit the transfer identifier (`submissionId`) to the `deBridgeAggregator` contract on the target chain. `submissionId` is calculated as a hash of concatenation: * The user or any arbitrary wallet (e.g. Keeper service) can call `claim` method of `deBridgeGate` by passing all transaction parameters and all validators' signatures. Smart contract will restore `submissionId` based on the set of passed parameters and if the minimum required number of validators' signatures is valid, the transaction is treated by the protocol as valid and the asset is minted/unlocked to the receiver address and data is executed through the callProxy. deBridge protocol supports multi-chain routing when users can transfer deAssets between secondary chains directly, without the need to route them through the native chain. These transfers work in the same way, but deAsset is burnt in the chain where the transfer is originated and the corresponding amount of deAsset is minted on the target chain. # Cross-Chain Transfers Execution Time Cross-chain transfer through deBridge normally takes a few minutes and the delay is caused by two factors: * The finality of the transaction on the blockchain where the transfer is originated * Time required for claim transaction to get into the block on the destination chain Each blockchain has a different block generation time and requires a different number of block confirmations for ensured transaction finality, thus before validating the transaction validators must wait for its finality. # Cross-Chain Call Lifecycle Source: https://docs.debridge.com/dmp-details/dev-guides/cross-chain-call-lifecycle Lifecycle of a cross-chain call from submission to claim. Blockchains by their nature are siloed environments that cannot directly communicate with each other. That is why any messaging protocol is a complex set of components, making any cross-chain transaction a multistage process, so just initiating a cross-chain transaction typically is not enough. It is important to understand how the deBridge infrastructure works so you can manage your submissions (either manually or even automatically) consciously and confidently. The following scheme visualizes a normal cycle of a typical cross-chain call, as it may look for the [conceptual cross-chain dApp](https://github.com/debridge-finance/debridge-cross-chain-dapp-example) where Incrementor is used as an example of the smart contract that sends a cross-chain message: <img alt="Cross-chain Call Lifecycle" /> When a call to the `deBridgeGate.send()` method is made on the origin (source) chain, the gate contract validates the input (its args and the `autoParams` struct), and if everything is correct (the data is unambiguous, the input asset covers the fees, etc), a special `Sent` event is emitted. This event exposes the following details of the submission: * `submissionId`, the identifier of the cross-chain transaction you've initiated; * `debridgeId`, the cross-chain identifier of the input asset, needed to correctly handle tokens across supported chains; * `args` and the `autoParams` structure that contains information about the passed message. You are advised to monitor this event to ensure your submission has been accepted and the cross-chain transaction has been initiated. [deBridge validators](https://app.debridge.com/validation-progress) listen for these events emitted by the deBridgeGate smart contract deployed on all supported chains, and for each tracked event validator performs the following set of actions: * waits a specific amount of block confirmations (12 block confirmations for supported EVM chains, and 256 block confirmations for the Polygon network) to ensure the finality of the transaction where the event has been emitted, * validates the args and the structure, * if the data is correct, sign the message with its own private key, and publish the signature to Arweave. <Note> Note: Validators' financial responsibility to be enabled through [Slashing and Delegated Staking](/dmp-details/dmp/slashing-and-delegated-staking). </Note> After the minimum required number of validators have signed the message (eight at the time of writing, ⅔ of all possible signatures), the submission is confirmed and may be claimed on the destination chain. <Note> You can access the actual minimum required number of signatures by querying the `minConfirmations` property of the `signatureVerifier` contract: ```solidity theme={null} ISignatureVerifier(IDebridgeGate(deBridgeGate).signatureVerifier).minConfirmations ``` </Note> To claim the submission, a claiming transaction should be crafted, signed, and sent to the blockchain. Such transaction must contain a call to the `claim()` method of the `deBridgeGate` contract with the submission's data (taken from the `Sent` event) and minimal required number of validators' signatures provided as its args. Worth mentioning that such transactions may be signed and sent by anyone who is willing to pay the gas for its' execution on the destination chain. There is no security implication because during the claiming phase the `deBridgeGate` contract first checks the integrity of the message (the args and the `autoParams` struct that was initially passed to the `send()` method on the origin chain) by verifying each validator's signature against their public key, and then executing the instructions this message contains. There are three ways to trigger a claiming transaction: * manually, by visiting [deExplorer](https://explorer.debridge.com/), where you can find your cross-chain transaction by its `submissionId` or even by the hash of the origin transaction, then sign the prepared claiming transaction using the browser wallet (MetaMask, etc); <img alt="Claim Details" /> * automatically, by specifying sufficient `executionFee` property within your submission: in this case, Claimers will execute the transaction and deliver the message in case the supplied on the source chain `executionFee` (included gas) covers their gas on the destination chain. Claimer may wait to deliver the message (submission) in case of gas price spikes (if the value of the included gas becomes less than the cost of execution). In this case, you should trigger a claiming txn on your own, either manually or programmatically, and you'll receive back
프로젝트로 돌아가기