Integration
Smart contract integration
L1->L2
To send funds L1->L2, call the sendToL2
method on the L1 Bridge contract:
The relayer
and relayerFee
are required for most routes. You can get these values from the Hop SDK.
L2->L1 and L2->L2
To send funds L2->L1 or L2->L2, call the swapAndSend
method on the L2 AMM Wrapper contract:
Note: Do not set destinationAmountOutMin
and destinationDeadline
when sending to L1 because there is no AMM on L1, otherwise the computed transferId will be invalid and the transfer will be unbondable. These parameters should be set to 0
when sending to L1.
L2 hTokens->L2 or L2 hTokens -> L1
To send hTokens L2->L2 or hTokens L2->L1, call the send
method on the L2 Bridge contract:
Note: There are no hTokens on L1 so sending L2 hUSDC to L1 means you'll receive USDC on L1.
Note: Do not set amountOutMin
and deadline
when sending to L1 because there is no AMM on L1, otherwise the computed transferId will be invalid and the transfer will be unbondable. These parameters should be set to 0
when sending to L1.
Sending ETH vs Token
When sending native asset from source chain (ie ETH on Ethereum, Optimism, Arbitrum, or XDAI on Gnosis Chain, or MATIC on Polygon), set the transaction value
to match the amount
parameter.
swapAndSend vs send
swapAndSend
(on L2 AMM Wrapper) on the source chain swaps your canonical token (eg USDC) to hTokens (eg hUSDC) and burns the hTokens and then you receive the canonical tokens (eg USDC) on the destination chain.
send
on (on L2 Bridge) is for only dealing with hTokens. The send
method on the source chain takes your hTokens (ie hUSDC), burns the hTokens and then you receive hTokens (eg hUSDC) on the destination chain.
swapAndSend is what you'd want to use most of the time since the canonical tokens are what users are interested in.
Calling Hop from smart contract for transfers
Some good examples you can check out as a reference are:
InstaDapp DSA connector contracts (helpers.sol)
LI.FI bridge aggregator contracts (HopFacet.sol)
AMM Deposit
Use the addLiquidity
method on the Swap contract.
AMM Withdraw
Use the removeLiquidityOneToken
method on the Swap contract. You can also use the removeLiquidity
method to receive proportional canonical tokens and h-tokens.
Contract addresses
The L1 Bridge addresses, L2 Bridge addresses, L2 AMM wrapper addresses, AMM addresses (Saddle Swap contracts), and other Hop contract addresses can be found on this link:
Calculating Bonder Fee
There's a REST API you can use to get estimated bonder fee. See API docs.
Getting transfer status
There's a REST API you can use to get transfer status. See API docs.
Last updated