LayerZero Bridge
Bridge vault shares across chains using LayerZero V2. Learn how to use bridge functions and components.
Introduction
Functionalities for cross-chain bridging of vault shares using LayerZero V2. Comprehensive examples may be found in BridgeButton.tsx and DepositAndBridgeButton.tsx.
To enable LayerZero bridging, provide the LayerZero teller contract address when initializing the provider:
bridge
This function bridges existing vault shares to another chain via LayerZero V2.
Inputs
- signer: an ethers
JsonRPCSigner. If you are using viem, you may use this example to create an ethers signer out of a viem wallet client: ethers.tsx - shareAmount: a decimal adjusted (human readable)
stringthat represents the amount of vault shares to bridge - destinationChain: an encoded
stringrepresenting the destination chain (useencodeBridgeWildCardfromlayerzero-chainsutils) - maxFee: a decimal adjusted (human readable)
stringrepresenting the maximum fee willing to pay for bridging - feeToken: the token to pay fees in, in the format:
- address: fee token contract address
- decimals: decimal precision of the fee token
- displayName: display name of the fee token
Outputs
- A promise that returns a
BridgeStatusobject- initiated: boolean representing if the bridge function has been called and is in progress
- loading: boolean representing if there is a bridge transaction ongoing
- success (optional): boolean representing if the bridge action succeeded
- error (optional): string representing why a bridge failed
- tx_hash (optional): the string of a successful bridge transaction hash
Example
depositAndBridge
This function deposits tokens and immediately bridges the minted shares to another chain in a single transaction.
Inputs
- signer: an ethers
JsonRPCSigner - tokenAddress: the contract address of the token to deposit
- depositAmount: a decimal adjusted (human readable)
stringthat represents the amount of tokens to deposit - minimumMint: a decimal adjusted (human readable)
stringrepresenting minimum shares to mint (slippage protection) - destinationChain: an encoded
stringrepresenting the destination chain - maxFee: a decimal adjusted (human readable)
stringrepresenting the maximum fee willing to pay - feeToken: the token to pay fees in
Outputs
- A promise that returns a
DepositAndBridgeStatusobject with the same structure asBridgeStatus
Example
bridgeStatus
Returns the current status of a bridge operation.
Inputs
- None
Outputs
- A
BridgeStatusobject containing the current bridge transaction state
Example
depositAndBridgeStatus
Returns the current status of a deposit and bridge operation.
Inputs
- None
Outputs
- A
DepositAndBridgeStatusobject containing the current transaction state