EOSIO.token <> EOSIO.token Fungible Tokens
This guide will essentially map the tokenpeg.spec.js unit test.
Resources:
Steps:
  • ​Install Zeus if not installed, zeus is used to unbox or install all the necessary dependencies to compile and deploy the necessary contracts.
Ensure you're using node version 12, IPFS can be picky with other versions
1
mkdir tokenpeg; cd tokenpeg
2
zeus box create
3
zeus unbox tokenpeg
Copied!
  • Add LiquidX mapping file
/zeus_boxes/liquidx/models/eosio-chains/liquidjungl3.json
The following file is for the destination's chain information.
1
# remove existing JSON file to not confuse the compiler
2
rm -rf ./zeus_boxes/liquidx/models/eosio-chains/
3
mkdir ./zeus_boxes/liquidx/models/eosio-chains/
4
touch ./zeus_boxes/liquidx/models/eosio-chains/liquidjungl3.json
5
vim ./zeus_boxes/liquidx/models/eosio-chains/liquidjungl3.json
Copied!
1
{
2
"dsp_port": 3117,
3
"webhook_dapp_port": 8813,
4
"nodeos_host": "jungle3.cryptolions.io",
5
"nodeos_port": 443,
6
"secured": true,
7
"nodeos_state_history_port": 8887,
8
"nodeos_p2p_port": 12451,
9
"nodeos_endpoint": "https://jungle3.cryptolions.io:443",
10
"demux_port": 1232,
11
"name": "liquidjungl3",
12
"local": false
13
}
Copied!
/zeus_boxes/liquidx/models/liquidx-mappings/sidechain_name.dappservices.json
This file allows for the compiler to insert relevant chain information into the contract header.
1
# remove existing JSON
2
rm -rf ./zeus_boxes/liquidx/models/liquidx-mappings/
3
mkdir ./zeus_boxes/liquidx/models/liquidx-mappings/
4
touch ./zeus_boxes/liquidx/models/liquidx-mappings/liquidjungl3.dappservices.json
5
vim ./zeus_boxes/liquidx/models/liquidx-mappings/liquidjungl3.dappservices.json
Copied!
1
{
2
"sidechain_name": "liquidjungl3",
3
"mainnet_account": "dappservices",
4
"chain_account": "testdappxxxx"
5
}
Copied!
  • Compile contracts
1
zeus compile tokenpeg; zeus compile tokenpegx
Copied!
Examine ./contracts/eos/dappservices/dappservices.config.hpp and you will see the mapping field populate into c++ definitions, if you see TEST1, you need to delete the existing mapping files
  • Create 3 Kylin and 3 Jungle Accounts​
    • Kylin token contract Account (token being bridged eosio.token.cpp)
    • Kylin bridge contract Account (tokenpeg.cpp)
    • Kylin test Account no contract
    • Jungle token contract Account (token on Jungle to mint/burn tokens eosio.token.cpp)
    • Jungle bridge contract Account (tokenpegx.cpp)
    • Jungle test Account no contract
1
export KYLIN_BRIDGE_ACCOUNT=tokenexample
2
export KYLIN_TOKEN_ACCOUNT=token4bridge
3
export KYLIN_TEST_ACCOUNT=natdeveloper
4
export KYLIN_ENDPOINT=https://kylin.eosn.io
5
export JUNGLE_BRIDGE_ACCOUNT=tokenexample
6
export JUNGLE_TOKEN_ACCOUNT=token4bridge
7
export JUNGLE_TEST_ACCOUNT=natdeveloper
8
export JUNGLE_ENDPOINT=https://jungle3.cryptolions.io:443
Copied!
  • Setup tokenpeg on the Kylin token contract Account and tokenpegx on the Jungle token contract Account using zeus migrate.
  • Import private keys
1
zeus key import $KYLIN_BRIDGE_ACCOUNT --owner-private-key 5JPPPML... --active-private-key 5KdLRibwg1v... --network=kylin
2
zeus key import $JUNGLE_BRIDGE_ACCOUNT --owner-private-key 5KkDxt... --active-private-key 5KkDxtfyKQQ... --network=jungle3
3
zeus key import $KYLIN_TOKEN_ACCOUNT --owner-private-key 5JPPPML... --active-private-key 5KdLRibwg1v... --network=kylin
4
zeus key import $JUNGLE_TOKEN_ACCOUNT --owner-private-key 5KkDxt... --active-private-key 5KkDxtfyKQQ... --network=jungle3
Copied!
  • Create contract deployment files located in ./zeus_boxes/contract-migrations-extensions/models/contract-deployments/
1
zeus create contract-deployment tokenpeg $KYLIN_BRIDGE_ACCOUNT kylin
2
zeus create contract-deployment tokenpegx $JUNGLE_BRIDGE_ACCOUNT jungle3
3
zeus create contract-deployment eosio.token $KYLIN_TOKEN_ACCOUNT kylin
4
zeus create contract-deployment eosio.token $JUNGLE_TOKEN_ACCOUNT jungle3
Copied!
  • Migrate contracts to Kylin/Jungle
Zeus Migrate
cleos set contract
1
zeus migrate tokenpeg --network=kylin --creator $KYLIN_BRIDGE_ACCOUNT --no-reset --no-compile-all --creator-key=""
2
zeus migrate tokenpegx --network=jungle3 --creator $JUNGLE_BRIDGE_ACCOUNT --no-reset --no-compile-all --creator-key=""
3
zeus migrate eosio.token --network=kylin --creator $KYLIN_TOKEN_ACCOUNT --no-reset --no-compile-all --creator-key=""
4
zeus migrate eosio.token --network=jungle3 --creator $JUNGLE_TOKEN_ACCOUNT --no-reset --no-compile-all --creator-key=""
Copied!
1
# if migration fails
2
cd contracts/eos
3
cleos -u $KYLIN_ENDPOINT set contract $KYLIN_BRIDGE_ACCOUNT tokenpeg
4
cleos -u $JUNGLE_ENDPOINT set contract $JUNGLE_BRIDGE_ACCOUNT tokenpegx
5
cleos -u $KYLIN_ENDPOINT set contract $KYLIN_TOKEN_ACCOUNT eosio.token
6
cleos -u $JUNGLE_ENDPOINT set contract $JUNGLE_TOKEN_ACCOUNT eosio.token
Copied!
  • Initialize token contracts
  • Create
Create tokens
For Kylin, we'll set the issuer to the token contract, this is to simulate a pre-existing token that is being bridged to Jungle3.
Only Jungle3 we will set the issuer to the bridge contract so that it can issue tokens when they come across the bridge. We will also issue those tokens to the
Kylin
Jungle3
1
export MAX_SUPPLY="1000000.0000 TKN"
2
export ISSUER=$KYLIN_TOKEN_ACCOUNT # token contract itself
3
cleos -u $KYLIN_ENDPOINT push action $KYLIN_TOKEN_ACCOUNT create "[\"$ISSUER\",\"$MAX_SUPPLY\"]" -p $KYLIN_TOKEN_ACCOUNT@active
Copied!
1
export MAX_SUPPLY="1000000.0000 TKN"
2
export ISSUER=$JUNGLE_BRIDGE_ACCOUNT # bridge contract so it can issue/burn
3
cleos -u $JUNGLE_ENDPOINT push action $JUNGLE_TOKEN_ACCOUNT create "[\"$ISSUER\",\"$MAX_SUPPLY\"]" -p $JUNGLE_TOKEN_ACCOUNT@active
Copied!
If you get errors such as Transaction exceeded the current network usage limit imposed on the transaction, see the Kylin / Jungle account setup guides to get more tokens and to stake for more resources.
  • Issue test tokens
We will issue some test tokens to our test account.
1
export TO=$KYLIN_TOKEN_ACCOUNT
2
export QUANTITY="10.0000 TKN"
3
export MEMO="issuing tokens"
4
cleos -u $KYLIN_ENDPOINT push action $KYLIN_TOKEN_ACCOUNT issue "[\"$TO\",\"$QUANTITY\",\"$MEMO\"]" -p $KYLIN_TOKEN_ACCOUNT@active
Copied!
  • Transfer test tokens
Now we will transfer the issued tokens to the test account.
1
export FROM=$KYLIN_TOKEN_ACCOUNT
2
export TO=$KYLIN_TEST_ACCOUNT
3
export QUANTITY="10.0000 TKN"
4
export MEMO="don't spend it all in one place!"
5
cleos -u $KYLIN_ENDPOINT push action $KYLIN_TOKEN_ACCOUNT transfer "[\"$FROM\",\"$TO\",\"$QUANTITY\",\"$MEMO\"]" -p $KYLIN_TOKEN_ACCOUNT@active
Copied!
  • Stake for services
Now that we've prepared that part let's move onto staking DAPP for services. First stop is the faucet for some DAPP tokens here. Use the account that has the tokenpeg contract set to it.
  • Stake to required services vRAM, LiquidHarmony Oracles, and LiquidScheduler
Using the DSP Portal we can see these packages:
Below we'll select each package then stake for it.
vRAM
LiquidHarmony
LiquidScheduler
1
export PROVIDER=heliosselene
2
export PACKAGE=ipfs1
3
export SERVICE=ipfsservice1
4
export QUANTITY="10.0000 DAPP"
5
cleos -u $KYLIN_ENDPOINT push action dappservices selectpkg "[\"$KYLIN_BRIDGE_ACCOUNT\",\"$PROVIDER\",\"$SERVICE\",\"$PACKAGE\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
6
cleos -u $KYLIN_ENDPOINT push action dappservices stake "[\"$KYLIN_BRIDGE_ACCOUNT\",\"$PROVIDER\",\"$SERVICE\",\"$QUANTITY\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
Copied!
1
export PROVIDER=heliosselene
2
export PACKAGE=xpackage
3
export SERVICE=oracleservic
4
export QUANTITY="10.0000 DAPP"
5
cleos -u $KYLIN_ENDPOINT push action dappservices selectpkg "[\"$KYLIN_BRIDGE_ACCOUNT\",\"$PROVIDER\",\"$SERVICE\",\"$PACKAGE\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
6
cleos -u $KYLIN_ENDPOINT push action dappservices stake "[\"$KYLIN_BRIDGE_ACCOUNT\",\"$PROVIDER\",\"$SERVICE\",\"$QUANTITY\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
Copied!
1
export PROVIDER=heliosselene
2
export PACKAGE=cronservices
3
export SERVICE=cronservices
4
export QUANTITY="10.0000 DAPP"
5
cleos -u $KYLIN_ENDPOINT push action dappservices selectpkg "[\"$KYLIN_BRIDGE_ACCOUNT\",\"$PROVIDER\",\"$SERVICE\",\"$PACKAGE\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
6
cleos -u $KYLIN_ENDPOINT push action dappservices stake "[\"$KYLIN_BRIDGE_ACCOUNT\",\"$PROVIDER\",\"$SERVICE\",\"$QUANTITY\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
Copied!
  • LiquidX stake
In order to stake for services on Jungle3, a LiquidX mapping must be created, for more detail see here.
Kylin
Jungle3 setlink
Jungle3 add dsp
1
export OWNER=$KYLIN_BRIDGE_ACCOUNT
2
export CHAIN_ACCOUNT=$JUNGLE_BRIDGE_ACCOUNT
3
export CHAIN_NAME=liquidjungl3
4
cleos -u $KYLIN_ENDPOINT push action liquidxxxxxx addaccount "[\"$OWNER\",\"$CHAIN_ACCOUNT\",\"$CHAIN_NAME\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
Copied!
1
export OWNER=$JUNGLE_BRIDGE_ACCOUNT
2
export MAINNET_OWNER=$KYLIN_BRIDGE_ACCOUNT
3
cleos -u $JUNGLE_ENDPOINT push action testdappxxxx setlink "[\"$OWNER\",\"$MAINNET_OWNER\"]" -p $JUNGLE_BRIDGE_ACCOUNT@active
Copied!
1
export OWNER=$JUNGLE_BRIDGE_ACCOUNT
2
export DSP=$PROVIDER
3
cleos -u $JUNGLE_ENDPOINT push action testdappxxxx adddsp "[\"$OWNER\",\"$DSP\"]" -p $JUNGLE_BRIDGE_ACCOUNT@active
Copied!
  • Initialize
Here we will initialize both bridges with their settings. On Kylin we will not allow issuance because the token already exists. On Jungle we allow the bridge contract to issue tokens to mint/burn. We set the minimum transfer to 1 TKN.
Kylin
Jungle3
1
export SISTER_CODE=$JUNGLE_BRIDGE_ACCOUNT
2
export SISTER_CHAIN_NAME="liquidjungl3"
3
export THIS_CHAIN_NAME="kylin"
4
export PROCESSING_ENABLED=1
5
export TOKEN_CONRACT=$KYLIN_TOKEN_ACCOUNT
6
export TOKEN_SYMBOL="4,TKN"
7
export MIN_TRANSFER=10000
8
export TRANSFERS_ENABLED=1
9
export CAN_ISSUE=0
10
export KYLIN_DSP_ENDPOINT=http://kylin-dsp-2.liquidapps.io
11
cleos -u $KYLIN_ENDPOINT push action $KYLIN_BRIDGE_ACCOUNT init "[\"$SISTER_CODE\",\"$SISTER_CHAIN_NAME\",\"$THIS_CHAIN_NAME\",\"$PROCESSING_ENABLED\",\"$TOKEN_CONRACT\",\"$TOKEN_SYMBOL\",\"$MIN_TRANSFER\",\"$TRANSFERS_ENABLED\",\"$CAN_ISSUE\"]" -p $KYLIN_BRIDGE_ACCOUNT@active
Copied!
1
export SISTER_CODE=$KYLIN_BRIDGE_ACCOUNT
2
export SISTER_CHAIN_NAME="kylin"
3
export THIS_CHAIN_NAME="liquidjungl3"
4
export PROCESSING_ENABLED=1
5
export TOKEN_CONRACT=$JUNGLE_TOKEN_ACCOUNT
6
export TOKEN_SYMBOL="4,TKN"
7
export MIN_TRANSFER=10000
8
export TRANSFERS_ENABLED=1
9
export CAN_ISSUE=1
10
cleos -u $JUNGLE_ENDPOINT push action $JUNGLE_BRIDGE_ACCOUNT init "[\"$SISTER_CODE\",\"$SISTER_CHAIN_NAME\",\"$THIS_CHAIN_NAME\",\"$PROCESSING_ENABLED\",\"$TOKEN_CONRACT\",\"$TOKEN_SYMBOL\",\"$MIN_TRANSFER\",\"$TRANSFERS_ENABLED\",\"$CAN_ISSUE\"]" -p $JUNGLE_BRIDGE_ACCOUNT@active
Copied!
  • Transfer
Now we will test with a transfer from the Kylin example user to the Kylin bridge contract, let's see how it goes!!
Kylin
1
export FROM=$KYLIN_TEST_ACCOUNT
2
export TO=$KYLIN_BRIDGE_ACCOUNT
3
export QUANTITY="10.0000 TKN"
4
# destionation_account,destination_chain
5
# this is required as the memo type, it tells the bridge which chain the funds go to and who gets them
6
export MEMO="$JUNGLE_TEST_ACCOUNT,liquidjungl3"
7
cleos -u $KYLIN_ENDPOINT push action $KYLIN_TOKEN_ACCOUNT transfer "[\"$FROM\",\"$TO\",\"$QUANTITY\",\"$MEMO\"]" -p $KYLIN_TEST_ACCOUNT@active
Copied!
  • Confirm
If all goes well you will see the tokens arrive at your Jungle destination account, you can send them back to the bridge contract now to send them back!
Jungle3
1
export FROM=$JUNGLE_TEST_ACCOUNT
2
export TO=$JUNGLE_BRIDGE_ACCOUNT
3
export QUANTITY="10.0000 TKN"
4
# destionation_account,destination_chain
5
# this is required as the memo type, it tells the bridge which chain the funds go to and who gets them
6
export MEMO="$KYLIN_TEST_ACCOUNT,kylin"
7
cleos -u $JUNGLE_ENDPOINT push action $JUNGLE_TOKEN_ACCOUNT transfer "[\"$FROM\",\"$TO\",\"$QUANTITY\",\"$MEMO\"]" -p $JUNGLE_TEST_ACCOUNT@active
Copied!
Note that the memo destination chain is now kylin and no longer liquidjungl3 because we are sending the tokens to kylin.
If the transfers are not going through, ensure that the DSP you are using has enough CPU/NET staked for it
​
Last modified 4mo ago
Copy link