Wrapped Asset Bridge
Wrapped asset bridge allows bridging ERC20
tokens and native gas tokens (e.g. ETH
) from existing EVM chains (e.g. Ethereum, Avalanche, BSC, etc.) to subnets or brand new EVM chains where those assets do not exist natively. It supports mapping the same wrapped token to multiple tokens on other chains. E.g. moving native USDC from Ethereum or Avalanche to NewChainX will result in the same wrapped asset on NewChainX.
Deployment and configuration
- Deploy
OriginalTokenBridge.sol
on existing EVM chains. - Deploy
WrappedTokenBridge.sol
on the new EVM chain. - Call
setTrustedRemoteAddress
inWrappedTokenBridge
contract and in eachOriginalTokenBridge
contract. - For each token you want to bridge (e.g.,
USDC
,WETH
, etc), deployWrappedERC20
contract on the new EVM chain. Make sure to setdecimals
in theWrappedERC20
to the number of decimals used in the original token you want to bridge (e.g.,6
decimals forUSDC
,18
decimals forWETH
). If you want to add an additional functionality to the wrapped token, inherit it fromWrappedERC20
and add a custom logic to the derived contract. - For each token you want to bridge, call
registerToken(address token, uint8 sharedDecimals)
function inOriginalTokenBridge
andregisterToken(address localToken, uint16 remoteChainId, address remoteToken)
function inWrappedTokenBridge
. Each wrapped token can be mapped to multiple original tokens on different chains (e.g.USDC
on the new chain is mapped toUSDC
on Ethereum andUSDC
on Avalanche).
Bridging from a native asset EVM chain to a new EVM chain
- Call
estimateBridgeFee(bool useZro, bytes calldata adapterParams)
inOriginalTokenBridge
contract. - Call
bridge(address token, uint amountLD, address to, LzLib.CallParams calldata callParams, bytes memory adapterParams)
inOriginalTokenBridge
contract to bridgeERC20
tokens passingnativeFee
obtained earlier as a value. This will lockERC20
tokens inOriginalTokenBridge
contract and send a LayerZero message to theWrappedTokenBridge
on another chain to mint wrapped tokens. To bridgeETH
usebridgeNative(uint amountLD, address to, LzLib.CallParams calldata callParams, bytes memory adapterParams)
function and pass a sum ofnativeFee
and amount as a value.
Bridging from a new EVM chain to a native asset EVM
- Call
estimateBridgeFee(uint16 remoteChainId, bool useZro, bytes calldata adapterParams)
inWrappedTokenBridge
. - Call
bridge(address localToken, uint16 remoteChainId, uint amount, address to, bool unwrapWeth, LzLib.CallParams calldata callParams, bytes memory adapterParams)
supplyingnativeFee
obtained earlier as a value. This will burn wrapped tokens and send a LayerZero message toOriginalTokenBridge
contract on another chain to unlock original tokens.