CrossChain-Router

module
v3.5.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 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(string 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

Output:

tokenID is test
chainID is 46688
token config struct is {
  "TokenID": "test",
  "Decimals": 18,
  "ContractAddress": "0xb302f922b24420f3a3048dddc4e2761ce37ea098",
  "ContractVersion": 4
}
set token config input data is 0xba6e0d0f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000b6600000000000000000000000000000000000000000000000000000000000000012000000000000000000000000b302f922b24420f3a3048dddc4e2761ce37ea098000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000047465737400000000000000000000000000000000000000000000000000000000
4.3 set swap config

call the following contract function:

setSwapConfig(string tokenID, uint256 toChainID, SwapConfig config)

Notice: you should set swap config for all tokenIDs and all toChainIDs.

input data can be generated by the following method.

./build/bin/swaprouter config genSetSwapConfigData --c.ToChainID 46688 --c.TokenID test --c.MaximumSwap 1000000 --c.MinimumSwap 100 --c.BigValueThreshold 100000 --c.SwapFeeRate 0.001 --c.MaximumSwapFee 10 --c.MinimumSwapFee 1.5

Output:

tokenID is test
toChainID is 46688
swap config struct is {
  "MaximumSwap": 1000000000000000000000000,
  "MinimumSwap": 100000000000000000000,
  "BigValueThreshold": 100000000000000000000000,
  "SwapFeeRatePerMillion": 1000,
  "MaximumSwapFee": 10000000000000000000,
  "MinimumSwapFee": 1500000000000000000
}
set swap config input data is 0xca29ee960000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000b66000000000000000000000000000000000000000000000d3c21bcecceda10000000000000000000000000000000000000000000000000000056bc75e2d6310000000000000000000000000000000000000000000000000152d02c7e14af680000000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000014d1120d7b16000000000000000000000000000000000000000000000000000000000000000000047465737400000000000000000000000000000000000000000000000000000000
4.4 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

8. RPC api

please ref. server rpc api

Directories

Path Synopsis
Package admin provides methods to sign message and to verify signed message
Package admin provides methods to sign message and to verify signed message
Package build provide customized methods to build project.
Package build provide customized methods to build project.
cmd
swaprouter command
Command swaprouter is main program to start swap router or its sub commands.
Command swaprouter is main program to start swap router or its sub commands.
utils
Package utils provides common sub commands and command flags.
Package utils provides common sub commands and command flags.
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
build
Package build - build tools nolint
Package build - build tools nolint
Package leveldb - leveldb wrapper nolint Package leveldb is a wrapper of goleveldb.
Package leveldb - leveldb wrapper nolint Package leveldb is a wrapper of goleveldb.
Package log is a wrapper of logrus.
Package log is a wrapper of logrus.
Package mongodb is a wrapper of mongo-go-driver that defines the collections and CRUD apis on them.
Package mongodb is a wrapper of mongo-go-driver that defines the collections and CRUD apis on them.
Package mpc is a client of mpc server, doing the sign and accept tasks.
Package mpc is a client of mpc server, doing the sign and accept tasks.
Package params provides common version info and config items.
Package params provides common version info and config items.
Package router inits bridges and loads onchain configs.
Package router inits bridges and loads onchain configs.
bridge
Package bridge init router bridge and load / reload configs.
Package bridge init router bridge and load / reload configs.
rpc
client
Package client provides methods to do http GET / POST request.
Package client provides methods to do http GET / POST request.
restapi
Package restapi provides RESTful RPC service.
Package restapi provides RESTful RPC service.
rpcapi
Package rpcapi provides JSON RPC service.
Package rpcapi provides JSON RPC service.
server
Package server provides JSON/RESTful RPC service.
Package server provides JSON/RESTful RPC service.
Package tokens defines the common interfaces and supported bridges in sub directories.
Package tokens defines the common interfaces and supported bridges in sub directories.
eth
Package eth implements the bridge interfaces to support routering.
Package eth implements the bridge interfaces to support routering.
eth/abicoder
Package abicoder is simple tool to pack datas like solidity abi.
Package abicoder is simple tool to pack datas like solidity abi.
tests command
tests/eth
Package eth test eth router by implementing `tokens.IBridge` interface.
Package eth test eth router by implementing `tokens.IBridge` interface.
crypto
Package crypto provides facilities for ecdsa encryption and decryption.
Package crypto provides facilities for ecdsa encryption and decryption.
keystore
Package keystore encrypt private key and save on disk uses JSON encoding.
Package keystore encrypt private key and save on disk uses JSON encoding.
rlp
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.
Package types - eth types like transaction, receipt and logs nolint Package types defines the eth-like core types (Transaction, etc) and RPC result types.
Package types - eth types like transaction, receipt and logs nolint Package types defines the eth-like core types (Transaction, etc) and RPC result types.
Package worker includes all the tasks and jobs to process router swaps.
Package worker includes all the tasks and jobs to process router swaps.

Jump to

Keyboard shortcuts

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