This is the contract code of Conflux PoS pool, which is developed by Solidity. All contracts are in the contracts
directory. There are four components:
- Core Space Pool:
PoSPool.sol
- Core Space VotingEscrow:
VotingEscrow.sol
- eSpace Pool:
eSpace/eSpacePoSPool.sol
andeSpacePoolBridge.sol
- eSpace VotingEscrow:
eSpace/VotingEscrow.sol
The Core Space Pool
is the basic component of the whole project, which manages the user's stake and reward. The rest three components are optional.
This project uses hardhat
to compile and test the contract.
- Install nodejs and npm
- Clone this repo
- Install dependencies:
npm install
- cp
.env.example
to.env
and set the env variables:ETH_RPC_URL
: Conflux eSpace RPC URLCFX_RPC_URL
: Conflux Core space RPC URLPRIVATE_KEY
: Private key of the deployer, make sure it has enough CFX balance(1200 CFX for Core space, if you want to deploy eSpace pool, you need to have 50 CFX in eSpace)CFX_NETWORK_ID
: Core space network id, 1029 formainnet
, 1 for testnet
- Run
npx hardhat compile
to compile all the contracts
To run a PoS pool, a Conflux node is required. Check Conflux documentation run a node
for how to set up a node.
After the node is set up, and the blockchain data is fully synced, you can run this command to get the PoS validator register data:
# in your node directory
./conflux rpc local pos register --power 1
[
"0xe335b451bec7e19d019851f49580b6748d00adfb589d42bc0758a5fexxxxxxxx7da46c45000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000030854063b730fa72ff838bef2aa9b09230c95517ba63642e0416b9f76259cf58f6xxxxxxxxe0124a01632979c2ec8d27bf00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002102f96260693bf7fc9b9895098ca260293386d0262be2a74d013c4b766e55faa5c400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000003086e50d6b8580e2dea53252f86b9b66db57fa4000129e06a934069ce334580161fdxxxxxxxx70b41b7c7d90cc60610d5b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002012591fdc1651212ea8f7f3092a4677f5xxxxxxxx26462fc51f4e1113728da85b",
"bec7exxxxxxxx1f49580b6748d00adfb589d42bc0758a5fecaa1bfdcxxxxxxxx"
]
The first string is the registerData
, and the second string is the pos address of your pos node. Add a variable POS_REGIST_DATA
in .env
file, and set it to the registerData
string.
There are two contracts that need to be deployed:
PoSPool.sol
: The core contract of PoS pool, which is used to manage the user's stake and reward.PoolManager.sol
: A simple manager contract just stores the pool's address.
Step 1. Deploy the PoolManager
contract:
npx hardhat run scripts/core/01_deploy_poolManager.js --network cfxTestnet
After the command runs successfully, you will see the PoolManager
contract address in output, and add it to .env
file as POOL_MANAGER_ADDRESS
.
Step 2. Deploy the PoSPool
contract:
npx hardhat run scripts/core/02_deploy_pool.js --network cfxTestnet
After the command runs successfully, you will get the PoSPool
contract address, and add it to .env
file as POOL_ADDRESS
.
Step 3. Add the PoSPool
address to the PoolManager
contract:
node bin/pool.js PoolManager addPool your-pool-address
The PoolManager
address can be used to set up the pool UI, when the UI is ready, Conflux Core Space users can stake CFX to the pool and earn PoS rewards.
Note: The commands above are for testnet, if you want to deploy the contracts to mainnet, change the --network
parameter to cfxMainnet
.
If you want your pool to support eSpace, or support participation in Conflux on-chain parameters voting and community governance voting, you need to deploy the additional components. Check related documents for how to deploy them.