Giter Site home page Giter Site logo

tokenized-stake's Introduction

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:

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

Run test cases:

cfxtruffle test

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

Clear docker image:

docker kill cfx-node
docker rm cfx-node

Testnet Deployment

Command to deploy to testnet:

cfxtruffle deploy --network testnet

.env file setup:

PRIVATE_KEY=<insert private key here>

Current testnet deployment:

1_deploy.js
===========

   Replacing 'StakedCFX'
   ---------------------
   > transaction hash:    0x11189da87f7e39b4b340cce3e04583ca5f6e95d810198062571b828bda2b1689
   > Blocks: 4            Seconds: 4
   > contract address:    0x890cE2348eD62C0DF79eB0d81b0c7C3aCD103670
   > block number:        3716174
   > block timestamp:     1606575225
   > account:             0x15fd1E4F13502b1a8BE110F100EC001d0270552d
   > balance:             354.341266202675765994
   > gas used:            2755284 (0x2a0ad4)
   > gas price:           20 GDrip
   > value sent:          1 CFX
   > total cost:          1.05510568 CFX

   > Saving artifacts
   -------------------------------------
   > Total cost:          1.05510568 CFX


Summary
=======
> Total deployments:   1
> Final cost:          1.05510568 CFX

tokenized-stake's People

Contributors

aalu1418 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.