MoCHelperLib

View Source: contracts/MoCHelperLib.sol

MoCHelperLib - version: 0.1.12

Structs

MocLibConfig

struct MocLibConfig {
 uint256 reservePrecision,
 uint256 dayPrecision,
 uint256 mocPrecision
}

Contract Members

Constants & Variables

uint256 internal constant UINT256_MAX;

Functions

getMaxInt

Returns max uint256 value constant.

function getMaxInt(struct MoCHelperLib.MocLibConfig ) public pure
returns(uint256)

Returns

max uint256 value constant

Arguments

inrateAvg

Calculates average interest using integral function: T = Rate = a * (x ** b) + c

function inrateAvg(struct MoCHelperLib.MocLibConfig config, uint256 tMax, uint256 power, uint256 tMin, uint256 abRat1, uint256 abRat2) public view
returns(uint256)

Returns

average interest rate [using mocPrecision]

Arguments

spotInrate

⚠ This has been deprecated since the Proposal to remove leveraged positions from the protocol was approved, however it is necessary to maintain the contracts and their documentation for legacy support.

Calculates spot interest rate that BProx owners should pay to BPro owners: Rate = tMax * (abRatio ** power) + tMin

function spotInrate(struct MoCHelperLib.MocLibConfig config, uint256 tMax, uint256 power, uint256 tMin, uint256 abRatio) public view
returns(uint256)

Arguments

potential

Calculates potential interests function with given parameters: Rate = a * (x ** b) + c

function potential(struct MoCHelperLib.MocLibConfig config, uint256 a, uint256 b, uint256 c, uint256 value) public view
returns(uint256)

Arguments

avgInt

Calculates average of the integral function: T = ( (c * xf + ((a * (xf ** (b + 1))) / (b + 1))) - (c * xi + ((a * (xi ** (b + 1))) / (b + 1))) ) / (xf - xi)

function avgInt(struct MoCHelperLib.MocLibConfig config, uint256 a, uint256 b, uint256 c, uint256 value1, uint256 value2) public view
returns(uint256)

Returns

average interest rate [using mocPrecision]

Arguments

integral

Calculates integral of the exponential function: T = c * (value) + (a * value ** (b + 1)) / (b + 1))

function integral(struct MoCHelperLib.MocLibConfig config, uint256 a, uint256 b, uint256 c, uint256 value) public view
returns(uint256)

Returns

integration result [using mocPrecision]

Arguments

abundanceRatio

Relation between docs in bucket 0 and Doc total supply

function abundanceRatio(struct MoCHelperLib.MocLibConfig config, uint256 doc0, uint256 doct) public view
returns(uint256)

Returns

abundance ratio [using mocPrecision]

Arguments

bproSpotDiscountRate

Returns the Ratio to apply to BPro Price in discount situations: SpotDiscountRate = TPD * (utpdu - cob) / (uptdu -liq)

function bproSpotDiscountRate(struct MoCHelperLib.MocLibConfig libConfig, uint256 bproLiqDiscountRate, uint256 liq, uint256 utpdu, uint256 cov) public view
returns(uint256)

Returns

Spot discount rate [using mocPrecision]

Arguments

maxBProWithDiscount

Max amount of BPro to available with discount: MaxBProWithDiscount = (uTPDU * nDOC * PEG - (nBTC * B)) / (TPusd * TPD)

function maxBProWithDiscount(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 nDoc, uint256 utpdu, uint256 peg, uint256 btcPrice, uint256 bproUsdPrice, uint256 spotDiscount) public view
returns(uint256)

Returns

Total BPro amount [using mocPrecision]

Arguments

maxBProWithDiscountAux

Max amount of BPro to available with discount: MaxBProWithDiscount = (uTPDU * nDOC * PEG - (nBTC * B)) / (TPusd * TPD)

function maxBProWithDiscountAux(struct MoCHelperLib.MocLibConfig libConfig, uint256 nbUsdValue, uint256 nDoc, uint256 utpdu, uint256 peg, uint256 bproDiscountPrice) internal view
returns(uint256)

Returns

Total BPro amount [using mocPrecision]

Arguments

lockedBitcoin

Calculates Locked bitcoin

function lockedBitcoin(struct MoCHelperLib.MocLibConfig libConfig, uint256 btcPrice, uint256 nDoc, uint256 peg) public view
returns(uint256)

Returns

Locked bitcoin [using reservePrecision]

Arguments

liquidationPrice

Calculates price at liquidation event as a relation between the doc total supply and the amount of RBTC available to distribute

function liquidationPrice(struct MoCHelperLib.MocLibConfig libConfig, uint256 rbtcAmount, uint256 nDoc) public view
returns(uint256)

Returns

Price at liquidation event [using mocPrecision]

Arguments

bproTecPrice

Calculates BPro BTC price: TPbtc = (nB-LB) / nTP

function bproTecPrice(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 lb, uint256 nTP) public view
returns(uint256)

Returns

BPro BTC price [using reservePrecision]

Arguments

bproxBProPrice

⚠ This has been deprecated since the Proposal to remove leveraged positions from the protocol was approved, however it is necessary to maintain the contracts and their documentation for legacy support.

Calculates BPro BTC price: BProxInBPro = bproxTecPrice / bproPrice

function bproxBProPrice(struct MoCHelperLib.MocLibConfig libConfig, uint256 bproxTecPrice, uint256 bproPrice) public view
returns(uint256)

Returns

BProx price in BPro [using mocPrecision]

Arguments

applyDiscountRate

Returns a new value with the discountRate applied: TPbtc = (price)* (1 - discountRate)

function applyDiscountRate(struct MoCHelperLib.MocLibConfig libConfig, uint256 price, uint256 discountRate) public view
returns(uint256)

Returns

Price with discount applied [using SomePrecision]

Arguments

getInterestCost

Returns the amount of interest to pay: TPbtc = price * interestRate

function getInterestCost(struct MoCHelperLib.MocLibConfig libConfig, uint256 value, uint256 interestRate) public view
returns(uint256)

Returns

Interest cost based on the value and interestRate [using SomePrecision]

Arguments

coverage

Calculates Coverage: Coverage = nB / LB

function coverage(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 lB) public view
returns(uint256)

Returns

Coverage [using mocPrecision]

Arguments

leverageFromCoverage

Calculates Leverage from Coverage: Leverage = C / (C - 1)

function leverageFromCoverage(struct MoCHelperLib.MocLibConfig libConfig, uint256 cov) public view
returns(uint256)

Returns

Leverage [using mocPrecision]

Arguments

leverage

Calculates Leverage: Leverage = nB / (nB - lB)

function leverage(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 lB) public view
returns(uint256)

Returns

Leverage [using mocPrecision]

Arguments

docsBtcValue

Price in BTC of the amount of Docs

function docsBtcValue(struct MoCHelperLib.MocLibConfig libConfig, uint256 amount, uint256 peg, uint256 btcPrice) public view
returns(uint256)

Returns

Total value [using reservePrecision]

Arguments

bproBtcValue

Price in RBTC of the amount of BPros

function bproBtcValue(struct MoCHelperLib.MocLibConfig libConfig, uint256 bproAmount, uint256 bproBtcPrice) public view
returns(uint256)

Returns

Total value [using reservePrecision]

Arguments

maxDoc

Max amount of Docs to issue: MaxDoc = ((nBB)-(CobjB/BconsnDocPEG))/(PEG*(Cobj*B/BCons-1))

function maxDoc(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 cobj, uint256 nDoc, uint256 peg, uint256 btcPrice, uint256 bCons) public view
returns(uint256)

Returns

Total Docs amount [using mocPrecision]

Arguments

maxDocAux

function maxDocAux(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 adjCobj, uint256 nDoc, uint256 peg, uint256 btcPrice) internal view
returns(uint256)

Arguments

maxBPro

Max amount of BPro to redeem: MaxBPro = ((nBB)-(CobjnDoc*PEG))/TPusd

function maxBPro(struct MoCHelperLib.MocLibConfig libConfig, uint256 nB, uint256 cobj, uint256 nDoc, uint256 peg, uint256 btcPrice, uint256 bCons, uint256 bproUsdPrice) public view
returns(uint256)

Returns

Total BPro amount [using mocPrecision]

Arguments

totalBProInBtc

Calculates the total BTC price of the amount of BPros

function totalBProInBtc(struct MoCHelperLib.MocLibConfig libConfig, uint256 amount, uint256 bproPrice) public view
returns(uint256)

Returns

BPro total value in BTC [using reservePrecision]

Arguments

maxDocsWithBtc

Calculates the equivalent in Docs of the btcAmount

function maxDocsWithBtc(struct MoCHelperLib.MocLibConfig libConfig, uint256 btcAmount, uint256 btcPrice) public view
returns(uint256)

Returns

Equivalent Doc amount [using mocPrecision]

Arguments

maxBProWithBtc

Calculates the equivalent in BPro of the btcAmount

function maxBProWithBtc(struct MoCHelperLib.MocLibConfig libConfig, uint256 btcAmount, uint256 bproPrice) public view
returns(uint256)

Returns

Equivalent Bpro amount [using mocPrecision]

Arguments

bucketTransferAmount

Calculates the Btc amount to move from C0 bucket to: toMove = btcAmount * (lev - 1) an L bucket when a BProx minting occurs

function bucketTransferAmount(struct MoCHelperLib.MocLibConfig libConfig, uint256 btcAmount, uint256 lev) public view
returns(uint256)

Returns

btc to move [using reservePrecision]

Arguments

maxBProxBtcValue

⚠ This has been deprecated since the Proposal to remove leveraged positions from the protocol was approved, however it is necessary to maintain the contracts and their documentation for legacy support.

Max amount of BTC allowed to be used to mint bprox: Maxbprox = nDOC/ (PEGB(lev-1))

function maxBProxBtcValue(struct MoCHelperLib.MocLibConfig libConfig, uint256 nDoc, uint256 peg, uint256 btcPrice, uint256 lev) public view
returns(uint256)

Returns

Max bprox BTC value [using reservePrecision]

Arguments

maxMoCWithBtc

Calculates the equivalent in MoC of the btcAmount

function maxMoCWithBtc(struct MoCHelperLib.MocLibConfig , uint256 btcAmount, uint256 btcPrice, uint256 mocPrice) public pure
returns(uint256)

Returns

Equivalent MoC amount

Arguments

mocBtcValue

Calculates the equivalent in BTC of the MoC amount

function mocBtcValue(struct MoCHelperLib.MocLibConfig , uint256 amount, uint256 btcPrice, uint256 mocPrice) public pure
returns(uint256)

Returns

Equivalent MoC amount

Arguments

getPayableAddress

Transform an address to payable address

function getPayableAddress(struct MoCHelperLib.MocLibConfig , address account) public pure
returns(address payable)

Returns

Payable address for account

Arguments

mulr

Rounding product adapted from DSMath but with custom precision

function mulr(uint256 x, uint256 y, uint256 precision) internal pure
returns(z uint256)

Returns

Product

Arguments

pow

Potentiation by squaring adapted from DSMath but with custom precision

function pow(uint256 x, uint256 n, uint256 precision) internal pure
returns(z uint256)

Returns

power

Arguments

Last updated