RedeemingBondingCurveBase_v1.sol
Inherits: IRedeemingBondingCurveBase_v1, BondingCurveBase_v1
Author: Inverter Network
Manages the redemption of issuance for collateral along a bonding curve in the Inverter Network, including fee handling and sell functionality control.
Inherits from {BondingCurveBase_v1}. Extends by providing core functionalities for redeem operations, fee adjustments, and redemption calculations. Fee calculations utilize BPS for precision. Redeem-specific calculations should be implemented in derived contracts.
State Variables
sellIsOpen
Indicates whether the sell functionality is open or not. Enabled = true || disabled = false.
bool public sellIsOpen;sellFee
Sell fee expressed in base points, i.e. 0% = 0; 1% = 100; 10% = 1000.
uint public sellFee;__gap
Storage gap for future upgrades.
uint[50] private __gap;Functions
supportsInterface
See {IERC165-supportsInterface}.
sellingIsEnabled
Modifier to guarantee the selling functionality is enabled.
sellTo
Redeem tokens and directs the proceeds to a specified receiver address.
Executes a sell order, with the proceeds being sent directly to the _receiver's address. This function wraps the _sellOrder internal function with specified parameters to handle the transaction and direct the proceeds.
Parameters
_receiver
address
The address that will receive the redeemed tokens.
_depositAmount
uint256
The amount of tokens to be sold.
_minAmountOut
uint256
The minimum acceptable amount of proceeds that the receiver should receive from the sale.
sell
Redeem collateral for the sender's address.
Redirects to the internal function _sellOrder by passing the sender's address and deposit amount.
Parameters
_depositAmount
uint256
The amount of issued token deposited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
openSell
Opens the selling functionality for the collateral.
Only callable by the {Orchestrator_v1} admin. Reverts if selling is already open.
closeSell
Closes the selling functionality for the collateral.
Only callable by the {Orchestrator_v1} admin. Reverts if selling is already closed.
setSellFee
Sets the fee percentage for selling collateral, payed in collateral.
Only callable by the {Orchestrator_v1} admin. The fee cannot exceed 10000 basis points. Reverts if an invalid fee is provided.
Parameters
_fee
uint256
The fee in basis points.
calculateSaleReturn
Calculates the amount of tokens to be redeemed based on a given deposit amount.
This function takes into account any applicable sell fees before computing the collateral amount to be redeemed. Revert when _depositAmount is zero.
Parameters
_depositAmount
uint256
The amount of tokens deposited by the user.
Returns
redeemAmount
uint256
The amount of collateral that will be redeemed as a result of the deposit.
getStaticPriceForSelling
Calculates and returns the static price for selling the issuance token.
Returns
<none>
uint256
uint The static price for selling the issuance token.
_redeemTokensFormulaWrapper
Function used for wrapping the call to the external contract responsible for calculating the redeeming amount. This function is an abstract function and must be implemented in the downstream contract.
Parameters
_depositAmount
uint256
The amount of issuing token that is deposited.
Returns
<none>
uint256
uint Return the amount of collateral to be redeemed.
_sellOrder
Executes a sell order by transferring tokens from the receiver to the contract,. calculating the redeem amount, and finally transferring the redeem amount back to the receiver. This function is internal and not intended for end-user interaction. PLEASE NOTE: The current implementation only requires that enough collateral token is held for redeeming to be possible. No further functionality is implemented which would manages the outflow of collateral, e.g., restricting max redeemable amount per user, or a redeemable amount which differes from the actual balance. Throws an exception if _depositAmount is zero or if there's insufficient collateral in the contract for redemption.
Parameters
_receiver
address
The address receiving the redeem amount.
_depositAmount
uint256
The amount of tokens being sold by the receiver.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Returns
totalCollateralTokenMovedOut
uint256
The total amount of collateral tokens that are transfered away from the collateral token amount of this contract.
issuanceFeeAmount
uint256
The amount of issuance token subtracted as fee.
_handleCollateralTokensAfterSell
Virtual function to handle collateral tokens after a successful sell.
The downstream contract is responsible for implementing checks to ensure the contract has the right balance.
Parameters
_receiver
address
The address for which the collateral tokens will be handled.
_collateralTokenAmount
uint256
The amount of collateral tokens to handle.
_sellingIsEnabledModifier
Checks if the sell functionality is enabled.
_setSellFee
Sets the sell transaction fee, expressed in BPS.
Parameters
_fee
uint256
The fee percentage to set for sell transactions.
Last updated