Cross-Chain bridge based on Anyswap MPC network.
sudo apt update
sudo apt install docker.io
docker run -itd --name swap --network host --restart always -v /var/lib/docker/swap:/swap anywap/swap
docker exec -d swap swaporacle ...
tools: swapserver swaporacle swapscan swapadmin swaptools (/usr/local/bin)
conf: config-example.toml config-tokenpair-example.toml (/usr/local/bin)
git clone https://github.com/anyswap/CrossChain-Bridge.git
cd crossChain-Bridge
make allafter building, the following files will be generated in ./build/bin directory:
swapserver # server provide api service, and trigger swap processing
swaporacle # oracle take part in mpc signing (can disagree illegal transaction)
config-example.toml
config-tokenpair-example.toml
copy the example config file config-example.toml in ./build/bin directory, and modify it accordingly.
see more, please refer config file example
Identifier should be a short string to identify the bridge (eg. BTC2ETH, BTC2FSN)
MongoDB is used by the server to store swap status and history, you should config according to your modgodb database setting. (the swap oracle don't need it)
APIServer is used by the server to provide API service to register swap and to provide history retrieving. (the swap oracle don't need it)
Oracle is needed by the swap oracle to post swap register RPC requests to swap server
(the swap server don't need Oracle).
BtcExtra is used to customize fees when build transaction on Bitcoin blockchain
SrcChain is used to config the chain of source endpoint of the cross chain bridge.
SrcGateway is used to do RPC request to verify transactions on source blockchain, and to broadcast signed transaction.
DestChain is used to config the chain of dest endpoint of the cross chain bridge.
DestGateway is used to do RPC request to verify transactions on dest blockchain, and to broadcast signed transaction.
Dcrm is used to config DCRM node info and group info.
Initiators is used to specify the server dcrm user (initiators of dcrm sign)
Dcrm.DefaultNode is used to specify default dcrm node to connect.
Dcrm.OtherNodes is an array used by server to specify other initiators of dcrm node.
for the swap server, SignGroups is needed for dcrm signing.
Notice:
If in test enviroment you may run more than one program of swap servers on one machine,
Please specify different log file name to clarify the outputs.
And please specify different config files for each server,
and assgin KeystoreFile, PasswordFile and RPCAddress etc. separatly.
copy the example config file config-tokenpair-example.toml in ./build/bin directory, and modify it accordingly.
see more, please refer token pair config file example
pair ID of this token pair, must be unique.
SrcToken is used to config the token of source endpoint of the cross chain bridge.
DestToken is used to config the token of dest endpoint of the cross chain bridge.
setsid ./build/bin/swapserver --verbosity 6 --config build/bin/config.toml --pairsdir build/bin/tokenpairs --log build/bin/logs/server.logsetsid ./build/bin/swaporacle --verbosity 6 --config build/bin/config.toml --pairsdir build/bin/tokenpairs --log build/bin/logs/oracle.logswapserver and swaporacle has the following subcommands:
help - to see hep info.
version - to show the version.
license - to show the license
Running swapserver and swaporacle to provide cross chain bridge service, we must prepare the following things firstly and config them rightly. Otherwise the program will not run or run rightly. To ensure this, we have add many checkings to the config items.
For the config file, please refer config file example
-
create Mongodb database (shared by all swap servers of the bridge provider)
config
[MongoDB]section accordingly (eg.DbURL,DbName,UserName,Password)For security reason, we suggest:
- change the mongodb
port( defaults to27017) - enable
auth - create user with passord to access the database
- change the mongodb
-
create MPC group
For example, we take creating
2/3 thesholdjonitly managed MPC group as an example.we have 3 users in the MPC group, each user is running a
gdcrmnode to perform MPC functions.user1- build raw tx and trigger MPC signinguser2,user3- verify tx and accept the MPC signing withAGREE/DISAGREEresult
After created MPC group,
We can get the corresponding
MPC addresseson supported blockchains. Then we should configDcrmAddressin[SrcToken]and[DestToken]section according to the blockchain of them.We should config the
[Dcrm]section accordingly( eg.GroupID,TotalOracles,Mode,DefaultNode, etc.)And we should config the following
[Dcrm]section items sparately for each user in the MPC group:KeystoreFilePasswordFileRPCAddress
For example,
we are configing
user1now, we should configKeystoreFileandPasswordFileuseuser1's keystore and password file (we will getuser1's private key to sign a MPC requesting).And we should config
RPCAddressto the RPC address of the runninggdcrmnode ofuser1(we will do RPC calls to this address to complete MPC signing or accepting, etc.) -
create MPC sub-groups for signing
In the above step we have created a
2/3 thresholdMPC group.In signing we only need 2 members to agree.
So we prepared the sub-groups (
2/2) for signing. (eg. user1 + user2, user1 + user3) please see more detail about MPC hereAfter created, we should config
SignGroupsin[Dcrm]accordingly. -
create mapping asset (eg. mBTC) contract
with MPC accountmBTC is an smart contract inherit from
ERC20and add two methods:SwapinandSwapout.please see more here about mBTC
After created mBTC, we should config
ContractAddressin[DestToken]section. -
config
[APIServer]sectionThe swap server provides RPC service to query swap status and swap history. etc.
Please see more here about crossChain-Bridge-API
We should config
Port(defaults to11556), andAllowedOrigins(CORS defaults to empty array.["*"]for allow any) -
config
[SrcChain],[SrcGateway]We should config
APIAddressin[SrcGateway]section, to post RPC request to the running full node to get transaction, broadcat transaction etc.Config
[SrcChain], ref. to the following example:BlockChain = "Bitcoin" # required NetID = "TestNet3" # required Confirmations = 0 # suggest >= 6 for Mainnet # required InitialHeight = 0 EnableScan = false
-
config
[DestChain],[DestGateway]We should config
APIAddressin[DestGateway]section, to post RPC request to the running full node to get transaction, broadcat transaction etc.Config
[DestChain]like[SrcChain]. -
config
Identifierto identify your crosschain bridgeThis should be a short string to identify the bridge (eg.
BTC2ETH,BTC2FSN)Different MPC group can have same Identifier.
It only matter if you want use a MPC group to provide multiple crosschain bridge service, and config each bridge with a different identifier (
Notice: This way is not suggested) -
config
[BtcExtra]When build and sign transaction on Bitcoin blockchain, we can customize the following items:
MinRelayFee = 400 RelayFeePerKb = 2000 UtxoAggregateMinCount = 20 UtxoAggregateMinValue = 1000000
If not configed, the default vlaue will be used (in fact, the above values are the defaults)
-
config
[SrcToken]Config
[SrcToken], ref. to the following example:ID = "" Name = "Bitcoin Coin" Symbol = "BTC" Decimals = 8 # required Description = "Bitcoin Coin" ContractAddress = "" DepositAddress = "mq6XaNvFWiSJtfGYiGakkRdXNrqH6V4Jpu" # required DcrmAddress = "mfwPnCuht2b4Lvb5XTds4Rvzy3jZ2ZWrBL" # required DcrmPubkey = "045c8648793e4867af465691685000ae841dccab0b011283139d2eae454b569d5789f01632e13a75a5aad8480140e895dd671cae3639f935750bea7ae4b5a25122" MaximumSwap = 1000.0 # required MinimumSwap = 0.00001 # required SwapFeeRate = 0.001 # required MaximumSwapFee = 0.01 MinimumSwapFee = 0.00001 PlusGasPricePercentage = 15 BigValueThreshold = 5.0 DisableSwap = false
For ERC20 token, we should config
ID = "ERC20"andContractAddressto the token's contract address. -
config
[DestToken]Config
[DestToken]like[SrcToken].Don't forget to config
ContractAddressin[DestToken]section (see step 4) -
config
PairIDto identify token pair
repeat step 10, 11, 12 to prepare multiple token pairs config,
put them in a directory (will be referenced by --pairsdir command line option)