Giter Site home page Giter Site logo

crosschain-router's Introduction

How to deploy router swap

0. compile

requires at least Go version 1.18

make all

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

1. deploy AnyswapRouter

deploy a AnyswapRouter contract for each supported blockchain

eg. AnyswapV6Router.sol

2. deploy AnyswapERC20

deploy a AnyswapERC20 contract for each token on each blockchain

eg. AnyswapV6ERC20.sol

eg. AnyswapV6ERC20-NonEVM.sol

3. deploy RouterConfig

deploy a RouterConfig contract to store router bridge configs

eg. RouterConfigV2.sol

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:

function setChainConfig(uint256 chainID, string blockChain, string routerContract, uint64 confirmations, uint64 initialHeight, string extra)

4.2 set token config

call the following contract function:

function setTokenConfig(string tokenID, uint256 chainID, string tokenAddr, uint8 decimals, uint256 version, string routerContract, string extra)

4.3 set swap and fee config

we may not set swap and fee config between all fromChainIDs and toChainIDs, and we'll use the following logic to decide the actual config to use.

the actual swap config is decided by the following steps
1. if _swapConfig[tokenID][srcChainID][dstChainID] exist, then use it.
2. else if _swapConfig[tokenID][srcChainID][0] exist, then use it.
3. else if _swapConfig[tokenID][0][dstChainID] exist, then use it.
4. else use _swapConfig[tokenID][0][0].
the actual fee config is decided by the following steps
1. if _feeConfig[tokenID][srcChainID][dstChainID] exist, then use it.
2. else if _feeConfig[tokenID][srcChainID][0] exist, then use it.
3. else if _feeConfig[tokenID][0][dstChainID] exist, then use it.
4. else use _feeConfig[tokenID][0][0].
  1. set swap and fee config in batch
    struct SwapConfig2 {
        uint256 FromChainID;
        uint256 ToChainID;
        uint256 MaximumSwap;
        uint256 MinimumSwap;
        uint256 BigValueThreshold;
    }

    struct FeeConfig2 {
        uint256 FromChainID;
        uint256 ToChainID;
        uint256 MaximumSwapFee;
        uint256 MinimumSwapFee;
        uint256 SwapFeeRatePerMillion;
    }

    function setSwapConfigs(string memory tokenID, SwapConfig2[] calldata configs)
    function setFeeConfigs(string memory tokenID, FeeConfig2[] calldata configs)
  1. query swap and fee config in batch
    function getAllSwapConfigs(string memory tokenID) external view returns (SwapConfig2[] memory)
    function getAllFeeConfigs(string memory tokenID) external view returns (FeeConfig2[] memory)

4.3.1 set swap and fee config meantime

call the following contract function:

function setSwapAndFeeConfig(
        string tokenID, uint256 srcChainID, uint256 dstChainID,
        uint256 maxSwap, uint256 minSwap, uint256 bigSwap,
        uint256 maxFee, uint256 minFee, uint256 feeRate)

4.3.2 set swap config alone

call the following contract function to set swap config:

max/min/big value always uses decimals 18 (like precision).

function setSwapConfig(string tokenID, uint256 srcChainID, uint256 dstChainID, uint256 maxSwap, uint256 minSwap, uint256 bigSwap)

swap config is stored in a map with keys tokenID,srcChainID,dstChainID

mapping (bytes32 => mapping(uint256 => mapping(uint256 => SwapConfig))) private _swapConfig;

4.3.3 set fee config alone

call the following contract function:

rate is per million ration.

max/min value always uses decimals 18 (like precision).

function setFeeConfig(string tokenID, uint256 srcChainID, uint256 dstChainID, uint256 maxFee, uint256 minFee, uint256 feeRate)

fee config is stored in a map with keys tokenID,srcChainID,dstChainID

mapping (bytes32 => mapping(uint256 => mapping(uint256 => FeeConfig))) private _feeConfig;

4.4 set mpc address's public key

call the following contract function:

function setMPCPubkey(address addr, string pubkey);

5. add local config file

please ref. config-example.toml

the following is the major config items:

config item description
Identifier must have prefix 'routerswap'
SwapType eg. erc20swap, nftswap, anycallswap
SwapSubType anycall has subtype of v5 and v6
[Server] only need by swap server
[Server.MongoDB] use mongodb database
[Server.APIServer] provide rpc service
[Oracle] only need by swap oracle
[Extra] extra configs
[OnChain] get onchain router configs in samrt contract
[Gateways] query block and tx info from full nodes' rpc
[MPC] use mpc to do threshold signing

Notation:

the MPC is a security Multi-Party threshold Computation, for more info, please refer FastMulThreshold-DSA

Because the complexity of MPC, we can use private key to sign tx for easy testing.

set the following config items in the [MPC] section:

[MPC]
# use private key instead (use for testing)
SignWithPrivateKey = true

# set signer's private key, key is chain ID (use for testing)
[MPC.SignerPrivateKeys]
4  = "1111111111111111111111111111111111111111111111111111111111111111"
97 = "2222222222222222222222222222222222222222222222222222222222222222"

for more info, please ref. config-sign-with-privatekey-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

crosschain-router's People

Contributors

bohaosk avatar ccsols avatar gaozhengxin avatar jowenshaw avatar potti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crosschain-router's Issues

Multichain compatibility documentation needs improvement

I am trying to add Multichain support to my token. The documentation needs a lot of improvement, which is why I am filing these questions as a bug report

I have followed the advice here:

https://docs.multichain.org/developer-guide/how-to-develop-under-anyswap-erc20-standards

I have several questions:

(1) Is it true that you only need the three functions mint(address,uint256), burn(address,uint256) and underlying() (returning address(0)) to get full Multichain compatibliity? (This is my implementation of these functions.)

Are there other functions that are not required, but will provide additional Multichain-supported functionality, such as transferWithPermit?

In particular, I assume functions like deposit, withdrawal, vault functionality, etc. do not need to be included in my token?

(2) How do I obtain the official approved router addresses for Multichain? Somewhere in your documentation, it says that the router addresses can be obtained on request, but that they will be available programmatically in future. How far away is the programmatic API for fetching router addresses? Where do you hold the official list of router addresses currently?

(3) I also wanted to ask about the permitting API supported in the Anyswap V5 template (but not present in the V6 template). Specifically, in the functions permit​ and transferWithPermit​, there is this line:

require(verifyEIP712(target, hashStruct, v, r, s) || verifyPersonalSign(target, hashStruct, v, r, s));​

This actually breaks EIP2612 compatibility for the permit​ function, because verifyPersonalSign​ is not supported in the EIP2612​ standard -- it uses this different format for the permit hash:

keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", DOMAIN_SEPARATOR, hash))​

What is the purpose of this? Under what circumstances will a user submit a signed message to an Anyswap token signed using the following hash? How are these signatures produced? By wallet software? Is this sort of signature support needed in Multichain?

(4) Once my token is compatible with Multichain, and launched, how do I get it listed on your site?

(5) What precautions do you take to ensure your routers are bug-free and never compromised? Do you offer any sort of recourse or compensation for runaway minting or burning of tokens, due to some bug or security vulnerability in your code?

Anyswap Routing issue

Hello
I used the router instead of the bridge and I have 600k stuck in anyUSDC with no liquidity on any chain to remove my funds.

How do I access my funds?

How to use anySwapOutUnderlying when underlying is false

I read your wiki that tell to use the function anySwapOutUnderlying(anyToken, to, amount, toChainID). However I see some object have underlying: false, so how to I use anySwapOutUnderlying when underlying: false. Thank you.

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.