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:

  1. Approved allowance by sender should be ≥ amount (sufficient amount allowed)

  2. Attached value is equal to quote output

targetChainId can be found herearrow-up-right (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.

circle-exclamation

After the message is processed, the TokensReleased event will be emitted on the destination chain by the respective adapter smart contract.\

Last updated