CrossChain-Router

module
v0.0.0-...-1bc71c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: GPL-3.0

README

How to deploy router swap

0. compile

make all

run the above command, it will generate ./build/bin/swaprouter binary.

1. deploy AnyswapRouter

deploy a AnyswapRouter contract for each supported blockchain

2. deploy AnyswapERC20

deploy a AnyswapERC20 contract for each token on each blockchain

3. deploy RouterConfig

deploy a RouterConfig contract to store router bridge configs

4. set router config on chain

call RouterConfig contract to set configs on blcokchain.

The following is the most used functions, please ref. the abi for more info.

4.1 set chain config

call the following contract function:

setChainConfig(uint256 chainID, ChainConfig config)

input data can be generated by the following method.

./build/bin/swaprouter config genSetChainConfigData --c.ChainID 4 --c.BlockChain eth --c.RouterContract 0x3302f922b24420f3a3048dddc4e2761ce37ea098 --c.Confirmations 3 --c.InitialHeight 0

Output:

chain config struct is {
  "ChainID": "4",
  "BlockChain": "eth",
  "RouterContract": "0x3302f922b24420f3a3048dddc4e2761ce37ea098",
  "Confirmations": 3,
  "InitialHeight": 0
}
set chain config input data is 0xdefb3a0d0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000003302f922b24420f3a3048dddc4e2761ce37ea0980000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036574680000000000000000000000000000000000000000000000000000000000
4.2 set token config

call the following contract function:

setTokenConfig(bytes32 tokenID, uint256 chainID, TokenConfig config)

input data can be generated by the following method.

./build/bin/swaprouter config genSetTokenConfigData --c.ChainID 46688 --c.TokenID test --c.Decimals 18 --c.ContractAddress 0xb302f922b24420f3a3048dddc4e2761ce37ea098 --c.ContractVersion 4 --c.MaximumSwap 1000000 --c.MinimumSwap 100 --c.BigValueThreshold 100000 --c.SwapFeeRate 0.001 --c.MaximumSwapFee 10 --c.MinimumSwapFee 1.5

Output:

chainID is 46688
token config struct is {
  "TokenID": "test",
  "Decimals": 18,
  "ContractAddress": "0xb302f922b24420f3a3048dddc4e2761ce37ea098",
  "ContractVersion": 4,
  "MaximumSwap": 1000000,
  "MinimumSwap": 100,
  "BigValueThreshold": 100000,
  "SwapFeeRate": 0.001,
  "MaximumSwapFee": 10,
  "MinimumSwapFee": 1.5
}
set token config input data is 0xbb14e9ff0000000000000000000000000000000000000000000000000000000074657374000000000000000000000000000000000000000000000000000000000000b6600000000000000000000000000000000000000000000000000000000000000012000000000000000000000000b302f922b24420f3a3048dddc4e2761ce37ea098000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000d3c21bcecceda00000000000000000000000000000000000000000000000000000056bc75e2d6310000000000000000000000000000000000000000000000000152d02c7e14af600000000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000014d1120d7b160000
4.3 set mpc address's public key

call the following contract function:

setMPCPubkey(address addr, string pubkey)

5. add local config file

please ref. config-example.toml

6. run swaprouter

# for server run (add '--runserver' option)
setsid ./build/bin/swaprouter --config config.toml --log logs/routerswap.log --runserver

# for oracle run
setsid ./build/bin/swaprouter --config config.toml --log logs/routerswap.log

7. sub commands

get all sub command list and help info, run

./build/bin/swaprouter -h

sub commands:

admin is admin tool

config is tool to process and query config data

scanswap is tool to scan and post swap register

8. RPC api

please ref. server rpc api

Directories

Path Synopsis
cmd
Package common contains various helper functions.
Package common contains various helper functions.
hexutil
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
math
Package math provides integer math utilities.
Package math provides integer math utilities.
internal
rpc
eth
rlp
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL