GithubHelp home page GithubHelp logo

dapp-whisperer / ibbtc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from defidollar/ibbtc

0.0 0.0 0.0 1.67 MB

Interest-Bearing Bitcoin

License: MIT License

Solidity 41.55% JavaScript 58.45%

ibbtc's Introduction

Interest-bearing Badger BTC (ibBTC)

  • bBTC.sol is the interest-bearing bitcoin ERC20 token.

  • A peak refers to any third party integration in the protocol. The system is designed to support many such peaks which can be added or removed later and allow for custom logic specific to the peak. BadgerSettPeak.sol let's to mint/redeem bBTC with/in Badger Sett LP tokens. There is a configurable mint and redeem fee, charged in bBTC.

  • Core.sol is responsible for actually minting/burning the bBTC tokens. core.totalSystemAssets() provides the summation of all LP tokens held in all peaks, denominated in bitcoin. For e.g. a Sett LP token held in BadgerSettPeak is priced as:

function _settToBtc(CurvePool memory pool, uint amount) internal view returns(uint) {
    return amount
        .mul(pool.sett.getPricePerFullShare())
        .mul(pool.swap.get_virtual_price())
        .div(1e36);
}

This has the affect that as various strategies are employed on the sett, and the underlying curve pool LP token accrues interest (from trading fee), it is reflected in totalSystemAssets(). Then it becomes straight-forward to price a bBTC like so:

function getPricePerFullShare() override public view returns (uint) {
    uint _totalSupply = IERC20(address(bBTC)).totalSupply();
    if (_totalSupply > 0) {
        return totalSystemAssets().mul(1e18).div(_totalSupply);
    }
    return 1e18;
}

getPricePerFullShare() is used to determine the bBTC:bSett exchange rate.

Compile

npm run compile

Tests

Needs Alchemy API key. export ALCHEMY=<API_KEY>

npm t
  • Run against deployed contracts
npm run test:dryrun

Deployments

  • Local
npx hardhat node
npx hardhat run scripts/deploy.js --network local

Addresses will be written to deployments/local.json.

  • Mainnet
export PRIVATE_KEY=
export INFURA_PROJECT_ID=

npx hardhat run scripts/deployMainnet.js --network mainnet

Addresses will be written to deployments/mainnet.json.

Coverage

npm run coverage

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.