项目作者: aalu1418

项目描述 :
sCFX: a wrapped, interest-bearing native token on Conflux Network
高级语言: JavaScript
项目地址: git://github.com/aalu1418/tokenized-stake.git
创建时间: 2020-11-22T00:56:05Z
项目社区:https://github.com/aalu1418/tokenized-stake

开源协议:MIT License

下载


Tokenized Stake + Interest Bearing CFX

Using Conflux Network staking to create interest-bearing wrapped CFX in the ERC-20 token standard.

Testnet deployed address: 0x890cE2348eD62C0DF79eB0d81b0c7C3aCD103670

NOTE: This project is not audited. It is simply a demonstration of an idea for building on Conflux.

Interactions

  • Basic ERC-20 functionality (balanceOf, transfer, transferFrom, approve, allowance, totalSupply)
  • receive is the default fallback for depositing CFX to convert into sCFX. To interact, send greater than 1 CFX to contract address.
  • withdraw is called when converting sCFX to CFX. It withdraws all of a users sCFX.

Developer Notes

THe base of the smart contract is the Open Zeppelin ERC-20 template in order to start from a audited and prove-secure contract.

The main modifications are as follows (+ associated functionality for calculating interest, staking, unstaking):

  • Intermediary step for the _transfer() function to calculate interest and mint interest for the sender and recipient before calling the origin _transfer() function
  • Fallback function receive() for receiving deposits to convert CFX into sCFX
  • withdraw() function that allows a user to convert all their sCFX into CFX

When deploying, 1 CFX is deposited into the contract to make sure withdraws can always be processed (there is always 1 CFX that can be staked).

Uses Conflux Truffle and the Conflux docker image.

Improvements:

  • Better + more complete test cases
  • More efficient interest calculation (values are currently hard coded in a way to create a binary search for calculating interest)
  • Withdraw function for specific amounts instead of all
  • Mechanism to deposit less than 1 CFX

Local Testing

Start Docker image:

  1. docker pull confluxchain/conflux-rust
  2. docker run -p 12537:12537 --name cfx-node confluxchain/conflux-rust

Run test cases:

  1. cfxtruffle test

Test cases are using the built in Mocha/Chai testing framework Truffle Assertions

Clear docker image:

  1. docker kill cfx-node
  2. docker rm cfx-node

Testnet Deployment

Command to deploy to testnet:

  1. cfxtruffle deploy --network testnet

.env file setup:

  1. PRIVATE_KEY=<insert private key here>

Current testnet deployment:

  1. 1_deploy.js
  2. ===========
  3. Replacing 'StakedCFX'
  4. ---------------------
  5. > transaction hash: 0x11189da87f7e39b4b340cce3e04583ca5f6e95d810198062571b828bda2b1689
  6. > Blocks: 4 Seconds: 4
  7. > contract address: 0x890cE2348eD62C0DF79eB0d81b0c7C3aCD103670
  8. > block number: 3716174
  9. > block timestamp: 1606575225
  10. > account: 0x15fd1E4F13502b1a8BE110F100EC001d0270552d
  11. > balance: 354.341266202675765994
  12. > gas used: 2755284 (0x2a0ad4)
  13. > gas price: 20 GDrip
  14. > value sent: 1 CFX
  15. > total cost: 1.05510568 CFX
  16. > Saving artifacts
  17. -------------------------------------
  18. > Total cost: 1.05510568 CFX
  19. Summary
  20. =======
  21. > Total deployments: 1
  22. > Final cost: 1.05510568 CFX