Bridge
General information about mechanism of work can be found here.
In order to interact with bridge on smart-contract level you need to interact with functions quote and bridgeTokens of the adapter smart-contract on a source chain.
In order to pay for execution on destination chain, LayerZero and DVN fees you need to attach sufficient value on source chain. Calling quote allows you to estimate this value:
function quote(
string calldata symbol,
uint256 amount,
address receiver,
uint32 targetChainId,
bytes calldata _options
) public view returns (uint256 nativeFee)Quote will return you an estimate in root token of the source chain.
Next step is to call bridgeTokens function:
function bridgeTokens(
string calldata symbol,
uint256 amount,
address receiver,
uint32 targetChainId,
bytes calldata _options
)To make call successful you need to make sure of two things:
Approved allowance by sender should be ≥
amount(sufficient amount allowed)Attached value is equal to
quoteoutput
targetChainId can be found here (in column Endpoint Id). receiver address can be customised (it isn't mandatory that receiver is the same address as sender).
_options can be constructed by @layerzerolabs/lz-v2-utilities library. Destination chain gas amount should be included in the call. We recommend to keep it 140000 gas. Example of options usage:
After a successful bridgeTokens call, the TokensBridged event will be emitted to simplify off-chain tracking of transactions.
The amount and fee fields in the TokensBridged event are normalized to 18 decimals in order to support tokens with different numbers of decimals on different chains. Keep in mind that to convert to the original token amount, you need to multiply by 10^tokenDecimals and divide by 10^18.
After the message is processed, the TokensReleased event will be emitted on the destination chain by the respective adapter smart contract.\
Last updated