Ring Protocol
Search…
BondingCurve
A generic RUSD bonding curve

Contract

Description

An abstract bonding curve for purchasing RUSD and routing of the purchased asset to PCV.
The amount of PCV it takes in a purchase transaction to bring the curve to a total amount of RUSD issued T is determined by integrating the price function between the current RUSD amount issued C by the bonding curve and the target amount T after the transaction.
Amount of PCV out for a purchase
The quantity T-C is the amount of RUSD received by the transaction. Since C is a known constant, we solve for T by setting the formula equal to a PCV purchase quantity Q and rearranging terms.
The price should be $1 + b times the peg, where b is the variance buffer and the peg is reported as X per RUSD. In the implementation, we use $1 - b because the peg is inverted so the price relationship is also inverted.

Allocation

Incoming PCV is held temporarily to allow for batch transactions via the allocate() function. The PCV allocation gets split into a weighted list of PCV deposit contracts, (see PCVSplitter). While allocations can be called at any time, there is a 100 RUSD incentive for calling it after each 24 hour window. To determine eligibility for the incentive, simply call isTimeEnded() on the contract. The time until the next incentive is available is remainingTime().
    Minter💰

Events

Purchase
Allocate
BufferUpdate
IncentiveAmountUpdate
Purchase of RUSD on bonding curve
type
param
description
address indexed
_to
recipient of RUSD
uint256
_amountIn
amount of purchase asset
uint256
_amountOut
amount of RUSD
Allocate held PCV
type
param
description
address indexed
_caller
the sender of the allocation transaction
uint256
_amount
the amount of PCV allocated
Governance change of Buffer
type
param
description
uint256
_buffer
new buffer
Changes the RUSD reward for calling allocate()
type
param
description
uint256
_incentiveAmount
new incentive amount

Read-Only Functions

getCurrentPrice

1
function getCurrentPrice() external view returns (Decimal.D256 memory);
Copied!
Returns current instantaneous bonding curve price. The price reported as RUSD per X, with X being the underlying asset. This is analogous to the peg reported by the oracle.
Can be inaccurate if outdated, need to call oracle().isOutdated() to check

getAverageUSDPrice

1
function getAverageUSDPrice(uint256 amountIn)
2
external
3
view
4
returns (Decimal.D256 memory);
Copied!
Returns the average price of a transaction of size amountIn ETH along bonding curve. The price here is reported as USD per RUSD.
Can be inaccurate if outdated, need to call oracle().isOutdated() to check

getAmountOut

1
function getAmountOut(uint256 amountIn)
2
external
3
view
4
returns (uint256 amountOut);
Copied!
Returns the amount amountOutof RUSD received for a purchase of amountIn ETH.
Can be inaccurate if outdated, need to call oracle().isOutdated() to check

buffer

1
function buffer() external view returns (uint256);
Copied!
The multiplier applied to the peg price.

BUFFER_GRANULARITY

1
function BUFFER_GRANULARITY() external view returns (uint256);
Copied!
The granularity of the buffer. Constant at 10,000.

totalPurchased

1
function totalPurchased() external view returns (uint256);
Copied!
Returns the cumulative amount of RUSD issued via the bonding curve. Used in the bonding curve formula as the supply amount.

getTotalPCVHeld

1
function getTotalPCVHeld() external view returns (uint256);
Copied!
Returns the amount of PCV held in the contract and ready for allocation.

incentiveAmount

1
function incentiveAmount() external view returns (uint256);
Copied!
Returns the amount of RUSD sent to the keeper who calls allocate() while the incentive is active.

Public State-Changing Functions

purchase

1
function purchase(address to, uint256 amountIn)
2
external
3
payable
4
returns (uint256 amountOut);
Copied!
Purchase amountOut RUSD along the bonding curve for amountIn ETH and send the RUSD to address to.
emits Purchase
This method is pausable

EOA-Only 👤 State-Changing Functions

allocate

1
function allocate() external;
Copied!
Allocate the PCV held by the bonding curve to the weighted PCV allocations returned by getAllocation().
emits Allocate
This method is pausable

Governor-Only⚖️ State-Changing Functions

setBuffer

1
function setBuffer(uint256 _buffer) external;
Copied!
Sets the buffer to _buffer. Must be less than BUFFER_GRANULARITY
emits BufferUpdate

setIncentiveAmount

1
function setIncentiveAmount(uint256 _incentiveAmount) external;
Copied!
Sets the incentiveAmount to _incentiveAmount
emits IncentiveAmountUpdate

setIncentiveFrequency

1
function setIncentiveFrequency(uint256 _frequency) external;
Copied!
Sets the Timed duration to _frequency
emits DurationUpdate

setAllocation

1
function setAllocation(
2
address[] calldata pcvDeposits,
3
uint256[] calldata ratios
4
) external;
Copied!
Sets the PCV allocation to pcvDeposits with weights ratios. The ratios must sum to ALLOCATION_GRANULARITY which is constant at 10,000.

ABIs

bondingcurve.json
8KB
Binary
BondingCurve ABI
ibondingcurve.json
3KB
Binary
BondingCurve Interface ABI
Last modified 4mo ago