BondingCurveBase_v1.sol
Last updated
Last updated
Inherits: IBondingCurveBase_v1, Module_v1
Author: Inverter Network
Manages the issuance of token for collateral along a bonding curve in the Inverter Network, including fee handling and sell functionality control.
Provides core functionalities for issuance operations, fee adjustments, and issuance calculations. Fee calculations utilize BPS for precision. Issuance-specific calculations should be implemented in derived contracts.
Base Points used for percentage calculation. This value represents 100%.
The token the curve will mint and burn from.
Indicates whether the buy functionality is open or not. Enabled = true || disabled = false.
Buy fee expressed in base points, i.e. 0% = 0; 1% = 100; 10% = 1000.
Accumulated project trading fees collected from deposits made by users when engaging with the bonding curve-based funding manager. Collected in collateral.
Storage gap for future upgrades.
See {IERC165-supportsInterface}.
Modifier to guarantee the buying functionality is enabled.
Modifier to guarantee token recipient is valid.
Buy tokens on behalf of a specified receiver address.
Redirects to the internal function _buyOrder
by passing the receiver address and deposit amount.
Parameters
_receiver
address
The address that will receive the bought tokens.
_depositAmount
uint256
The amount of collateral token deposited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Buy tokens for the sender's address.
Redirects to the internal function _buyOrder
by passing the sender's address and deposit amount.
Parameters
_depositAmount
uint256
The amount of collateral token depoisited.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Opens the buying functionality for the token.
Only callable by the {Orchestrator_v1} admin. Reverts if buying is already open.
Closes the buying functionality for the token.
Only callable by the {Orchestrator_v1} admin. Reverts if buying is already closed.
Sets the fee percentage for buying tokens, 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.
Calculates the amount of tokens to be minted based on a given deposit amount.
This function takes into account any applicable buy fees before computing the token amount to be minted. Revert when _depositAmount
is zero.
Parameters
_depositAmount
uint256
The amount of tokens deposited by the user.
Returns
mintAmount
uint256
The amount of new tokens that will be minted as a result of the deposit.
Withdraw project collateral fee to the receiver address.
Parameters
_receiver
address
The address that will receive the fee.
_amount
uint256
The amount of fee to withdraw.
Returns the address of the issuance token.
Calculates and returns the static price for buying the issuance token.
Returns
<none>
uint256
uint The static price for buying the issuance token.
Function used for wrapping the call to the external contract responsible for calculating the issuing amount. This function is an abstract function and must be implemented in the downstream contract.
Parameters
_depositAmount
uint256
The amount of collateral token that is deposited.
Returns
<none>
uint256
uint Return the amount of tokens to be issued.
Internal function to handle the buying of tokens. This function performs the core logic for buying tokens. It transfers the collateral, deducts any applicable fees, and mints new tokens for the buyer.
Parameters
_receiver
address
The address that will receive the bought tokens.
_depositAmount
uint256
The amount of collateral to deposit for buying tokens.
_minAmountOut
uint256
The minimum acceptable amount the user expects to receive from the transaction.
Returns
totalIssuanceTokenMinted
uint256
The total amount of issuance token minted during this function call.
collateralFeeAmount
uint256
The amount of collateral token subtracted as fee.
Virtual function to handle issuance tokens after a successful buy.
Parameters
_receiver
address
The address for which the issuance tokens will be handled.
_issuanceTokenAmount
uint256
The amount of issuance tokens to handle.
Virtual function to handle collateral tokens before a buy.
Parameters
_provider
address
The address from which the collateral tokens will be sent.
_amount
uint256
The amount of collateral tokens to handle.
Sets the buy transaction fee, expressed in BPS.
Parameters
_fee
uint256
The fee percentage to set for buy transactions.
Returns the collateral and issuance fee percentage retrieved from the fee manager for a specific operation.
Returns
collateralTreasury
address
The address the protocol fee in collateral should be sent to.
issuanceTreasury
address
The address the protocol fee in issuance should be sent to.
collateralFeePercentage
uint256
The percentage fee to be collected from the collateral token being deposited or redeemed, expressed in BPS.
issuanceFeePercentage
uint256
The percentage fee to be collected from the issuance token being deposited or minted, expressed in BPS.
*Calculates the proportion of the fees for the given amount and returns them plus the amount minus the fees. Reverts under the following two conditions:
if (project fee + protocol fee) > BPS
if protocol fee amount or project fee amounts == 0 given the fee percentage is not zero. This would indicate a rouding down to zero due to integer division.*
Parameters
_totalAmount
uint256
The amount from which the fees will be taken.
_protocolFee
uint256
The protocol fee percentage in relation to the BPS that will be applied to the totalAmount
.
_projectFee
uint256
The project fee percentage in relation to the BPS that will be applied to the totalAmount
.
Returns
netAmount
uint256
The total amount minus the combined fee amount.
protocolFeeAmount
uint256
The fee amount of the protocol fee.
projectFeeAmount
uint256
The fee amount of the project fee.
Internal function to transfer protocol fees to the treasury.
Parameters
_treasury
address
The address of the protocol treasury.
_token
IERC20
The token to transfer the fees from.
_feeAmount
uint256
The amount of fees to transfer.
Sets the issuance token for the FundingManager. This function updates the issuanceToken
state variable and should be be overridden by the implementation contract if extra validation around the token characteristics is needed.
Parameters
_issuanceToken
address
The token which will be issued by the Bonding Curve.
Checks if the buy functionality is enabled.
Validates the recipient address.
Validates the project fee.
Internal function to add project fee collected to the state variable
Parameters
_projectFeeAmount
uint256
The amount of fee collected
Ensures that the deposit amount and min amount out are not zero.
Parameters
_depositAmount
uint256
Deposit amount.
_minAmountOut
uint256
Minimum amount out.`
Mints new tokens.
Parameters
_to
address
The address of the recipient.
_amount
uint256
The amount of tokens to mint.
Burns tokens.
Parameters
_from
address
The address of the owner.
_amount
uint256
The amount of tokens to burn.