Giter VIP home page Giter VIP logo

crosschain-router's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.