The Bitlend Protocol is currently deployed on the following networks:
The Bitlend protocol contracts use a system of exponential math, in order to represent fractional quantities with sufficient precision.
Most numbers are represented as a mantissa, an unsigned integer scaled by
1 * 10 ^ 18, in order to perform basic math at a high level of precision.
Prices and exchange rates are scaled by the decimals unique to each asset; bTokens are BRC-20 tokens with 8 decimals, while their underlying tokens vary, and have a public member named decimals.
oneBTokenInUnderlying = exchangeRateCurrent / (1 * 10 ^ (18 + underlyingDecimals - bTokenDecimals))
const bTokenDecimals = 8; // all bTokens have 8 decimal places
const underlying = new web3.eth.Contract(erc20Abi, batAddress);
const bToken = new web3.eth.Contract(bTokenAbi, cBatAddress);
const underlyingDecimals = await underlying.methods.decimals().call();
const exchangeRateCurrent = await bToken.methods.exchangeRateCurrent().call();
const mantissa = 18 + parseInt(underlyingDecimals) - bTokenDecimals;
const oneBTokenInUnderlying = exchangeRateCurrent / Math.pow(10, mantissa);
console.log('1 cBAT can be redeemed for', oneBTokenInUnderlying, 'BAT');
There is no underlying contract for ETH, so to do this with cETH, set
To find the number of underlying tokens that can be redeemed for bTokens, multiply the number of bTokens by the above value
underlyingTokens = bTokenAmount * oneBTokenInUnderlying
Interest rates for each market update on any block in which the ratio of borrowed assets to supplied assets in the market has changed. The amount interest rates are changed depends on the interest rate model smart contract implemented for the market, and the amount of change in the ratio of borrowed assets to supplied assets in the market.
Interest accrues to all suppliers and borrowers in a market when any Ethereum address interacts with the market’s bToken contract, calling one of these functions: mint, redeem, borrow, or repay. Successful execution of one of these functions triggers the
accrueInterestmethod, which causes interest to be added to the underlying balance of every supplier and borrower in the market. Interest accrues for the current block, as well as each prior block in which the
accrueInterestmethod was not triggered (no user interacted with the bToken contract). Interest bitlends only during blocks in which the bToken contract has one of the aforementioned methods invoked.
Here is an example of supply interest accrual:
Alice supplies 1 BTT to the Bitlend protocol. At the time of supply, the
supplyRatePerBlockis 37893605 Wei, or 0.000000000037893605 BTT per block. No one interacts with the bBtt contract for 3 BTTC blocks. On the subsequent 4th block, Bob borrows some BTT. Alice’s underlying balance is now 1.000000000151574420 BTT (which is 37893605 Wei times 4 blocks, plus the original 1 BTT). Alice’s underlying BTT balance in subsequent blocks will have interest accrued based on the new value of 1.000000000151574420 BTT instead of the initial 1 BTT. Note that the
supplyRatePerBlockvalue may change at any time.
The Annual Percentage Yield (APY) for supplying or borrowing in each market can be calculated using the value of
supplyRatePerBlock(for supply APY) or
borrowRatePerBlock(for borrow APY) in this formula:
Rate = bToken.supplyRatePerBlock(); // Integer
Rate = 37893566
BTT Mantissa = 1 * 10 ^ 18 (BTT has 18 decimal places)
Blocks Per Day = 6570 (13.15 seconds per block)
Days Per Year = 365
APY = ((((Rate / BTT Mantissa * Blocks Per Day + 1) ^ Days Per Year)) - 1) * 100