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}.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(BondingCurveBase_v1)
returns (bool);
sellingIsEnabled
Modifier to guarantee the selling functionality is enabled.
modifier sellingIsEnabled();
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.
function sellTo(address _receiver, uint _depositAmount, uint _minAmountOut)
public
virtual
sellingIsEnabled
validReceiver(_receiver);
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.
function sell(uint _depositAmount, uint _minAmountOut) public virtual;
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.
function openSell() external virtual onlyOrchestratorAdmin;
closeSell
Closes the selling functionality for the collateral.
Only callable by the {Orchestrator_v1} admin. Reverts if selling is already closed.
function closeSell() external virtual onlyOrchestratorAdmin;
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.
function setSellFee(uint _fee) external virtual onlyOrchestratorAdmin;
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.
function calculateSaleReturn(uint _depositAmount)
public
view
virtual
returns (uint redeemAmount);
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.
function getStaticPriceForSelling() external view virtual returns (uint);
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.
function _redeemTokensFormulaWrapper(uint _depositAmount)
internal
view
virtual
returns (uint);
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.
function _sellOrder(address _receiver, uint _depositAmount, uint _minAmountOut)
internal
returns (uint totalCollateralTokenMovedOut, uint issuanceFeeAmount);
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.
function _handleCollateralTokensAfterSell(
address _receiver,
uint _collateralTokenAmount
) internal virtual;
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.
function _sellingIsEnabledModifier() internal view;
_setSellFee
Sets the sell transaction fee, expressed in BPS.
function _setSellFee(uint _fee) internal virtual;
Parameters
_fee
uint256
The fee percentage to set for sell transactions.
Last updated