FM_BC_Bancor_Redeeming_VirtualSupply_v1.sol
Last updated
Last updated
Inherits: IFM_BC_Bancor_Redeeming_VirtualSupply_v1, IFundingManager_v1, VirtualIssuanceSupplyBase_v1, VirtualCollateralSupplyBase_v1, RedeemingBondingCurveBase_v1
Author: Inverter Network
This contract enables the issuance and redeeming of tokens on a bonding curve, using a virtual supply for both the issuance and the collateral as input. It integrates Aragon's {BancorFormula} to manage the calculations for token issuance and redemption rates based on specified reserve ratios.
Inherits {BondingCurveBase_v1}, {RedeemingBondingCurveBase_v1}, {VirtualIssuanceSupplyBase_v1}, and {VirtualCollateralSupplyBase_v1}. Implements formulaWrapper functions for bonding curve calculations using the {BancorFormula}. {Orchestrator_v1} Admin manages configuration such as virtual supplies and reserve ratios. Ensure interaction adheres to defined transactional limits and decimal precision requirements to prevent computational overflows or underflows.
The interface of the Bancor Formula used to calculate the issuance and redeeming amount.
Value is used to convert deposit amount to 18 decimals, which is required by the {BancorFormula}. which is required by the Bancor formula.
Parts per million used for calculation the reserve ratio for the Bancor formula.
The reserve ratio for buying determines the rate of price growth. It is a measure of the fraction of the Token's value that is held in reserve. The value is a number between 0 and 100%, expressed in PPM. A higher reserve ratio means slower price growth. See Bancor Formula contract for reference.
The reserve ratio for selling determines the rate of price growth. It is a measure of the fraction of the Token's value that is held in reserve. The value is a number between 0 and 100%, expressed in PPM. A higher reserve ratio means slower price growth. See Bancor Formula contract for reference.
Token that is accepted by this funding manager for deposits.
Token decimals of the Orchestrator token, which is used as collateral and stores within implementation for gas saving.
Token decimals of the issuance token, which is stored within the implementation for gas saving.
Storage gap for future upgrades.
See {IERC165-supportsInterface}.
Modifier to guarantee the buying and selling functionalities are closed.
Buy tokens on behalf of a specified receiver address. This function is subject to a transactional limit, determined by the deposit token's decimal precision and the underlying bonding curve algorithm.
Redirects to the internal function _buyOrder
by passing the receiver address and deposit amount. Important: The {BancorFormula} has an upper computational limit of (10^38). For tokens with 18 decimal places, this effectively leaves a maximum allowable deposit amount of (10^20). While this is substantially large, it is crucial to be aware of this constraint. Transactions exceeding this limit will be reverted.
Parameters
_receiver
address
The address that will receive the bought tokens.
_depositAmount
uint256
The amount of collateral token depoisited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Buy tokens for the sender's address. This function is subject to a transactional limit, determined by the deposit token's decimal precision and the underlying bonding curve algorithm.
Redirects to the internal function _buyOrder
by passing the sender's address and deposit amount. Important: The {BancorFormula} has an upper computational limit of (10^38). While this is substantially large, it is crucial to be aware of this constraint. Transactions exceeding this limit will be reverted.
Parameters
_depositAmount
uint256
The amount of collateral token depoisited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Redeem tokens and direct the proceeds to a specified receiver address. This function is subject to a transactional limit, determined by the issuing token's decimal precision and the underlying bonding curve algorithm.
Redirects to the internal function _sellOrder
by passing the receiver address and deposit amount. Important: The {BancorFormula} has an upper computational limit of (10^26). For tokens with 18 decimal places, this effectively leaves a maximum allowable deposit amount of (10^8), or 100,000,000. Transactions exceeding this limit will be reverted.
Parameters
_receiver
address
The address that will receive the redeemed tokens.
_depositAmount
uint256
The amount of issued token to deposited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Redeem collateral for the sender's address. This function is subject to a transactional limit, determined by the issuing token's decimal precision and the underlying bonding curve algorithm.
Redirects to the internal function _sellOrder
by passing the sender's address and deposit amount. Important: The {BancorFormula} has an upper computational limit of (10^26). For tokens with 18 decimal places, this effectively leaves a maximum allowable deposit amount of (10^8), or 100,000,000. Transactions exceeding this limit will be reverted.
Parameters
_depositAmount
uint256
The amount of issued token depoisited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Returns reserve ratio set for buying, used in the {BancorFormula} contract.
Returns
<none>
uint32
Reserve Ratio for buying.
Returns reserve ratio set for selling, used in the {BancorFormula} contract.
Returns
<none>
uint32
Reserve Ratio for selling.
Calculates and returns the static price for buying the issuance token. The return value is formatted in PPM.
Calculates the static price for either selling or buying the issuance token, based on the provided issuance token supply, collateral supply, and buy or sell reserve ratio. Note: The reserve ratio specifies whether the sell or buy price is returned. The formula used is: PPM * PPM * collateralSupply / (issuanceTokenSupply * reserveRatio). The formula is based on Aragon's BatchedBancorMarketMaker, which can be found here: https://github.com/AragonBlack/fundraising/blob/5ad1332955bab9d36cfad345ae92b7ad7dc0bdbe/apps/batched-bancor-market-maker/contracts/BatchedBancorMarketMaker.sol#L415
Returns
<none>
uint256
uint The static price for buying the issuance token.
Calculates and returns the static price for selling the issuance token. The return value is formatted in PPM.
Returns
<none>
uint256
uint The static price for selling the issuance token.
Returns the token.
Returns
<none>
IERC20
The token.
Transfer a specified amount of Tokens to a designated receiver address.
This function MUST be restricted to be called only by the {Orchestrator_v1}.
Parameters
to
address
The address that will receive the tokens.
amount
uint256
The amount of tokens to be transfered.
Sets the virtual issuance supply to a new value.
This function calls the internal function _setVirtualIssuanceSupply
. The function must be implemented by the downstream contract. The downstream contract should manage access control for setting the supply.
Parameters
_virtualSupply
uint256
The new value to set for the virtual issuance supply.
Sets the virtual collateral supply to a new value.
This function should call the internal function _setVirtualCollateralSupply
. The function must be implemented by the downstream contract. The downstream contract should manage access control for setting the supply.
Parameters
_virtualSupply
uint256
The new value to set for the virtual collateral supply.
Set the reserve ratio used for issuing tokens on a bonding curve.
This function can only be called by the {Orchestrator_v1} admin.
Parameters
_reserveRatio
uint32
The new reserve ratio for buying, expressed in PPM.
Set the reserve ratio used for redeeming tokens on a bonding curve.
This function can only be called by the {Orchestrator_v1} admin.
Parameters
_reserveRatio
uint32
The new reserve ratio for selling, expressed in PPM.
Calculates the amount of tokens to mint for a given deposit amount using the {BancorFormula}. This internal function is an override of {BondingCurveBase_v1}'s abstract function. It handles decimal conversions and calculations through the bonding curve.
Parameters
_depositAmount
uint256
The amount of collateral deposited to purchase tokens.
Returns
mintAmount
uint256
The amount of tokens that will be minted.
Calculates the amount of collateral to be received when redeeming a given amount of tokens. This internal function is an override of {RedeemingBondingCurveBase_v1}'s abstract function. It handles decimal conversions and calculations through the bonding curve. Note the {BancorFormula} assumes 18 decimals for all tokens.
Parameters
_depositAmount
uint256
The amount of tokens to be redeemed for collateral.
Returns
redeemAmount
uint256
The amount of collateral that will be received.
Sets the issuance token for the Bonding Curve Funding Manager. This function overrides the internal function set in {BondingCurveBase_v1}, adding an input validation specific for the {BancorFormula} utilizing implementation, after which it updates the issuanceToken
state variable and caches the decimals as issuanceTokenDecimals
.
Parameters
_issuanceToken
address
The token which will be issued by the Bonding Curve.
Internal function to directly set the virtual collateral supply to a new value.
Parameters
_virtualSupply
uint256
The new value to set for the virtual collateral supply.
Internal function to directly set the virtual issuance supply to a new value. Virtual supply cannot be zero, or result in rounded down being zero when conversion is done for use in the Bancor Formulat.
Parameters
_virtualSupply
uint256
The new value to set for the virtual issuance supply.
Sets the reserve ratio for buying tokens. The function will revert if the ratio is greater than the constant PPM.
Parameters
_reserveRatio
uint32
The reserve ratio to be set for buying tokens. Must be <= PPM.
Sets the reserve ratio for selling tokens. Similar to its counterpart for buying, this function sets the reserve ratio for selling tokens. The function will revert if the ratio is greater than the constant PPM.
Parameters
_reserveRatio
uint32
The reserve ratio to be set for selling tokens. Must be <= PPM.
Validates the reserve ratio for buying and selling. The function will revert if the ratio is greater than the constant PPM.
Parameters
_reserveRatio
uint32
The reserve ratio to be validated. Must be <= PPM.
Checks if the buy and sell functionality is closed.
Handles incoming collateral tokens by transferring them from the provider.
Parameters
_provider
address
The address that provides the collateral tokens.
_amount
uint256
The amount of collateral tokens to handle.
Handles issuance tokens by minting them to the receiver.
Parameters
_receiver
address
The address that will receive the bought tokens.
_issuanceTokenAmount
uint256
The amount of issuance tokens to handle.
Handles collateral tokens by transferring them to the receiver.
Parameters
_receiver
address
The address that will receive the collateral tokens.
_collateralTokenAmount
uint256
The amount of collateral tokens to handle.