-
Notifications
You must be signed in to change notification settings - Fork 86
How to integrate AnySwap Router
Multichain Router has three parts:
- anyToken contract, it's wrapped LP token for native token, used for liquidity pool
- Underlying token address, it's native token
- Router contract, used for cross-chain swap
No. | Mainnet | chainID |
---|---|---|
1 | Ethereum | 1 |
2 | BSC | 56 |
3 | OkExchain | 66 |
4 | Matic | 137 |
5 | Fantom | 250 |
6 | Avax | 43114 |
7 | Arbitrum | 42161 |
Get all chains list from the endpoint:
https://bridgeapi.multichain.org/data/bridgeChainInfo (latest)
https://bridgeapi.anyswap.exchange/data/bridgeChainInfo
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": USDC,
"0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3": MIM,
"0x6b175474e89094c44da98b954eedeac495271d0f": DAI,
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": WETH,
"0xdac17f958d2ee523a2206206994597c13d831ec7": USDT,
"0xdb25f211ab05b1c97d595516f45794528a807ad8": EURS
Router tokens api endpoint:
V4(latest): https://bridgeapi.multichain.org/v4/tokenlistv4/1
V4: https://bridgeapi.anyswap.exchange/v4/tokenlistv4/1
V3: https://bridgeapi.anyswap.exchange/v3/serverinfoV3?chainId=all&version=all
For stable coins:
https://bridgeapi.anyswap.exchange/v3/serverinfoV3?chainId=all&version=STABLEV3
Take USDC(ethereum) as example:
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": {
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"anyToken": {
"address": "0x7ea2be2df7ba6e54b1a9c70676f668455e329d29",
"name": "USDC",
"symbol": "anyUSDC",
"decimals": 6
},
"underlying": {
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"name": "USDCoin",
"symbol": "USDC",
"decimals": 6
},
"destChains": {},
"price": 1.001,
"logoUrl": "https://assets.coingecko.com/coins/images/6319/large/USD_Coin_icon.png",
"chainId": "1",
"tokenid": "anyUSDC",
"version": "STABLEV3",
"router": "0x6b7a87899490ece95443e979ca9485cbe7e71522",
"routerABI": "anySwapOutUnderlying(anytoken,toAddress,amount,toChainID)"
}
- anyToken contract: anyUSDC 0x7ea2be2df7ba6e54b1a9c70676f668455e329d29
- Underlying token address: USDC 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
- Router contract: 0x6b7a87899490ece95443e979ca9485cbe7e71522
-
Approve underlying token for router contract at first time.
-
Get the
routerABI
function name from bridge API, and call Router contract:anySwapOutUnderlying(anyToken, toAddress, amount, toChainID)
.If the bridged token don't have underlying token, please confirm the item of
routerABI
and useanySwapOut(anyToken, toAddress, amount, toChainID)
.Router Contract ABI JSON File: https://bridgeapi.anyswap.exchange/routerabi
Example transaction: https://etherscan.io/tx/0x8318755719c85110c3c95b635392a380b11c9dd58ae3cedcbc9c5607e3f40df3
-
Sign the
anySwapOutUnderlying
transaction and get txhash. -
Get transaction status from API(update every 5s)
https://scanapi.multichain.org/v3/tx/0x8318755719c85110c3c95b635392a380b11c9dd58ae3cedcbc9c5607e3f40df3 (latest API)
Code Status 0 Pending 3 ExceedLimit(LessThenMinAmount) 8 Confirming 9 Swapping 10 Success 12 BigAmount(Wait24hours) 14 Failure -
Wait minutes to get token on dest chain, check txhash status on explorer:
https://scan.multichain.org/#/tx?params=0x8318755719c85110c3c95b635392a380b11c9dd58ae3cedcbc9c5607e3f40df3 (latest explorer)
Notice: If call router's anySwapOutUnderlying
through your own contract, please contact Multichain team to whitelist your contract. Join dev telegram group.
destChains section has fees and limit info. Take care the MinimumSwap
, if cross-chain amount less then MinimumSwap
, this transaction won't arrive. Cross-chain amount larger then BigValueThreshold
could take up to 12 hours.
"destChains":{
"56":{
"address":"0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
"underlying":{
"address":"0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
"name":"USDCoin",
"symbol":"USDC",
"decimals":18
},
"swapfeeon":1,
"MaximumSwap":"5000000",
"MinimumSwap":"12",
"BigValueThreshold":"1000000",
"SwapFeeRatePerMillion":0.1,
"MaximumSwapFee":"0.9",
"MinimumSwapFee":"0.9",
"anyToken":{
"address":"0x8965349fb649a33a30cbfda057d8ec2c48abe2a2",
"name":"USDC",
"symbol":"anyUSDC",
"decimals":18
}
}
Bridge fee explained:
bridge fee = bridgeAmount * `SwapFeeRatePerMillion` (0.1%)
If fee < `MinimumSwapFee` then fee = `MinimumSwapFee`
else if fee > `MaximumSwapFee` then fee = `MaximumSwapFee`
Take 10,000 USDC as example:
fee = 10,000 * 0.1% = 10 USDC, but fee > 0.9 then the fee = 0.9
Router front-end need to check the dest chain's underlying token liquidity. If the liquidity of the dest chain is insufficient, user will receive anyUSDC LP token, then user need to check the balance in the liquidity pool and redeem USDC from pool when has enough underlying liquidity.
Take USDC as example, if user want to bridge USDC to Fantom, front-end need to check the underlying USDC balance on anyUSDC(Fantom) contract: https://ftmscan.com/address/0x95bf7e307bc1ab0ba38ae10fc27084bc36fcd605
Another case is anyToken contract don't have underlying token settings, use mint/burn model(Like MIM), then this type token don't need check dest chain's underlying token liquidity.