Skip to main content

MoxieBondingCurveV3.sol

Bonding curve contract which enables subject onboarding, buy & sell of subject shares.

Functions

updateFees

Update fee only be called by role UPDATE_FEES_ROLE.

function updateFees(
FeeInput memory _feeInput
) external onlyRole(UPDATE_FEES_ROLE)

Parameters

NameTypeDescription
_feeInputFeeInputFeeinput struct.

updateFormula

Update formula to _formula. It can be done by UPDATE_FORMULA_ROLE.

function updateFormula(
address _formula
) external onlyRole(UPDATE_FORMULA_ROLE)

Parameters

NameTypeDescription
_formulaaddressThe address of the new BancorFormula [computation] contract

updateFeeBeneficiary

Update beneficiary to `_beneficiary. It can be done by UPDATE_BENEFICIARY_ROLE.

function updateFeeBeneficiary(
address _feeBeneficiary
) external onlyRole(UPDATE_BENEFICIARY_ROLE)

Parameters

NameTypeDescription
_feeBeneficiaryaddressThe address of the new beneficiary [to whom fees are to be sent]

updateDefaultGraduationMarketCap

Update the default graduation market cap.

function updateDefaultGraduationMarketCap(
uint256 _defaultGraduationMarketCap
) external onlyRole(UPDATE_GRADUATION_MARKET_CAP_ROLE)

Parameters

NameTypeDescription
_defaultGraduationMarketCapuint256The new default graduation market cap.

updateGraduationMarketCap

Update the graduation market cap for a specific reserve ratio.

function updateGraduationMarketCap(
uint32 _reserveRatio,
uint256 _newGraduationMarketCap
) external onlyRole(UPDATE_GRADUATION_MARKET_CAP_ROLE)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_reserveRatiouint32Initial supply of subject tokens at the time of bonding curve initialization.

initializeSubjectBondingCurve

Initialize Bonding curve for subject, it's called by subject factory.

If the creator coin have reached a certain market cap to be eligible for graduation, the creator coin will automatically graduate to Uniswap V4.

function initializeSubjectBondingCurve(
address _subject,
uint32 _reserveRatio,
uint256 _initialSupply,
uint256 _reserveAmount,
address _platformReferrer
) external whenNotPaused returns (bool)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_reserveRatiouint32Initial supply of subject tokens at the time of bonding curve initialization.
_initialSupplyuint256reserve ratio of subject for bonding curve.
_reserveAmountuint256Initial reserve amount.
_platformReferreraddressThe referrer address that will be rewarded for onboarding a new valid subject to the Moxie protocol.

Return Value

NameTypeDescription
isInitializedbooltrue if bonding curve is initialized. Otherwise, false.

buySharesForV2

Buy shares of subject on behalf of a third party addresss _onBehalfOf and reward the referral fees to the _orderReferrer.

For creator coins that have graduated, this function will buy creator coin directly from the Uniswap V4 pool.

function buySharesForV2(
address _subject,
uint256 _depositAmount,
address _onBehalfOf,
uint256 _minReturnAmountAfterFee,
address _orderReferrer
) external whenNotPaused whenNotTradingPaused(_subject) returns (uint256 shares_) {
shares_ = _buySharesInternal(_subject, _depositAmount, _onBehalfOf, _minReturnAmountAfterFee, _orderReferrer);
}

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_depositAmountuint256Amount of deposit to buy shares.
_onBehalfOfaddressAddress of beneficiary.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.
_orderReferreraddressAddress of order referrer.

Return Value

NameTypeDescription
shares_uint256Number of shares.

buySharesV2

Buy shares of subject for msg.sender and reward the referral fees to the _orderReferrer.

For creator coins that have graduated, this function will buy creator coin directly from the Uniswap V4 pool.

function buySharesV2(
address _subject,
uint256 _depositAmount,
uint256 _minReturnAmountAfterFee,
address _orderReferrer
) external whenNotPaused whenNotTradingPaused(_subject) returns (uint256 shares_) {
shares_ = _buySharesInternal(_subject, _depositAmount, msg.sender, _minReturnAmountAfterFee, _orderReferrer);
}

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_depositAmountuint256Amount of deposit to buy shares.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.
_orderReferreraddressAddress of order referrer.

Return Value

NameTypeDescription
shares_uint256Number of shares.

sellSharesForV2

Sell shares of a subject on behalf of a third party address _onBehalfOf and reward the referral fees to the _orderReferrer.

For creator coins that have graduated, this function will sell creator coin directly to the Uniswap V4 pool.

function sellSharesForV2(
address _subject,
uint256 _sellAmount,
address _onBehalfOf,
uint256 _minReturnAmountAfterFee,
address _orderReferrer
) external whenNotPaused whenNotTradingPaused(_subject) returns (uint256 returnAmount_) {
returnAmount_ =
_sellSharesInternal(_subject, _sellAmount, _onBehalfOf, _minReturnAmountAfterFee, _orderReferrer);
}

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_sellAmountuint256Amount of subject shares to sell.
_onBehalfOfaddressAddress of buy token beneficiary.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.
_orderReferreraddressAddress of order referrer.

Return Value

NameTypeDescription
returnAmount_uint256Amount received in MOXIE from selling subject shares.

sellSharesV2

Sell shares of a subject and reward the referral fees to the _orderReferrer.

For creator coins that have graduated, this function will sell creator coin directly to the Uniswap V4 pool.

function sellSharesV2(
address _subject,
uint256 _sellAmount,
uint256 _minReturnAmountAfterFee,
address _orderReferrer
) external whenNotPaused whenNotTradingPaused(_subject) returns (uint256 returnAmount_) {
returnAmount_ = _sellSharesInternal(_subject, _sellAmount, msg.sender, _minReturnAmountAfterFee, _orderReferrer);
}

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_sellAmountuint256Amount of subject shares to sell.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.
_orderReferreraddressAddress of order referrer.

Return Value

NameTypeDescription
returnAmount_uint256Amount received in MOXIE from selling subject shares.

buySharesFor

Buy shares of a subject on behalf of a beneficiary.

For creator coins that have graduated, this function will buy creator coin directly from the Uniswap V4 pool.

info

If you're looking to earn referral rewards from every buy transaction, use the buySharesForV2 function instead.

function buySharesFor(
address _subject,
uint256 _depositAmount,
address _onBehalfOf,
uint256 _minReturnAmountAfterFee
) external whenNotPaused returns (uint256 shares_)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_depositAmountuint256Amount of deposit to buy shares.
_onBehalfOfaddressAddress of beneficiary.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.

Return Value

NameTypeDescription
shares_uint256Number of shares.

buyShares

Buy shares of a subject.

For creator coins that have graduated, this function will buy creator coin directly from the Uniswap V4 pool.

info

If you're looking to earn referral rewards from every buy transaction, use the buySharesV2 function instead.

function buyShares(
address _subject,
uint256 _depositAmount,
uint256 _minReturnAmountAfterFee
) external whenNotPaused returns (uint256 shares_)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_depositAmountuint256Amount of deposit to buy shares.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.

Return Value

NameTypeDescription
shares_uint256Number of shares.

sellSharesFor

Sell shares of a subject on behalf of a beneficiary.

For creator coins that have graduated, this function will sell creator coin directly to the Uniswap V4 pool.

info

If you're looking to earn referral rewards from every sell transaction, use the sellSharesForV2 function instead.

function sellSharesFor(
address _subject,
uint256 _sellAmount,
address _onBehalfOf,
uint256 _minReturnAmountAfterFee
) external whenNotPaused returns (uint256 returnAmount_)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_sellAmountuint256Amount of subject shares to sell.
_onBehalfOfaddressAddress of buy token beneficiary.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.

Return Value

NameTypeDescription
returnAmount_uint256Amount received in MOXIE from selling subject shares.

sellShares

Sell shares of a subject.

For creator coins that have graduated, this function will sell creator coin directly to the Uniswap V4 pool.

info

If you're looking to earn referral rewards from every sell transaction, use the sellSharesForV2 function instead.

function sellShares(
address _subject,
uint256 _sellAmount,
uint256 _minReturnAmountAfterFee
) external whenNotPaused returns (uint256 returnAmount_)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.
_sellAmountuint256Amount of subject shares to sell.
_minReturnAmountAfterFeeuint256Minimum number of shares that must be received.

Return Value

NameTypeDescription
returnAmount_uint256Amount received in MOXIE from selling subject shares.

subjectGraduated

Check if a subject has graduated.

function subjectGraduated(address _subject) public view returns (bool)

Parameters

NameTypeDescription
_subjectaddressAddress of subject.

Return Value

NameTypeDescription
isGraduatedbooltrue if the subject has graduated. Otherwise, false.

graduationMarketCap

Get the graduation market cap for a specific reserve ratio.

function graduationMarketCap(
uint32 _reserveRatio
) public view returns (uint256)

Parameters

NameTypeDescription
_reserveRatiouint32Initial supply of subject tokens at the time of bonding curve initialization.

Return Value

NameTypeDescription
_graduationMarketCapuint256The graduation market cap for the specific reserve ratio.

distributeSwapFee

Distribute the swap fee to the protocol and subject.

function distributeSwapFee(address _subject) external

Parameters

NameTypeDescription
_subjectaddressAddress of subject.

Events

UpdateFees

event UpdateFees(
uint256 _protocolBuyFeePct,
uint256 _protocolSellFeePct,
uint256 _subjectBuyFeePct,
uint256 _subjectSellFeePct,
uint256 _swapFeeRatioProtocolPct
);

UpdateBeneficiary

event UpdateBeneficiary(address _beneficiary);

UpdateFormula

event UpdateFormula(address _formula);

BondingCurveInitialized

event BondingCurveInitialized(
address _subject,
address _subjectToken,
uint256 _initialSupply,
uint256 _reserve,
uint32 _reserveRatio
);

SubjectSharePurchased

event SubjectSharePurchased(
address _subject,
address _sellToken,
uint256 _sellAmount,
address _buyToken,
uint256 _buyAmount,
address _beneficiary
);

SubjectShareSold

event SubjectShareSold(
address \_subject,
address \_sellToken,
uint256 \_sellAmount,
address \_buyToken,
uint256 \_buyAmount,
address \_beneficiary
);

UpdateReferralFees

event UpdateReferralFees(
uint256 _platformReferrerBuyFeePct,
uint256 _platformReferrerSellFeePct,
uint256 _orderReferrerBuyFeePct,
uint256 _orderReferrerSellFeePct
);

SubjectReserveRatioUpdated

event SubjectReserveRatioUpdated(
address _subject,
uint32 _oldReserveRatio,
uint32 _newReserveRatio
);

TradingPaused

event TradingPaused(
address _subject,
bool _isPaused
);

DefaultGraduationMarketCapUpdated

event DefaultGraduationMarketCapUpdated(
uint256 _oldDefaultGraduationMarketCap,
uint256 _newDefaultGraduationMarketCap
);

GraduationMarketCapUpdated

event GraduationMarketCapUpdated(
uint32 indexed _reserveRatio,
uint256 _oldGraduationMarketCap,
uint256 _newGraduationMarketCap,
bool _isDefault
);

SubjectGraduated

event SubjectGraduated(
address indexed _subject,
PoolId _poolId,
uint256 _tokenId
);

Swap

event Swap(
address indexed _sender,
address indexed _subject,
bool _buySubject,
uint256 _amountIn,
uint256 _amountOut
);

Errors

MoxieBondingCurve_InvalidToken

error MoxieBondingCurve_InvalidToken();

MoxieBondingCurve_InvalidVault

error MoxieBondingCurve_InvalidVault();

MoxieBondingCurve_InvalidBeneficiary

error MoxieBondingCurve_InvalidBeneficiary();

MoxieBondingCurve_InvalidFeePercentage

error MoxieBondingCurve_InvalidFeePercentage();

MoxieBondingCurve_InvalidFormula

error MoxieBondingCurve_InvalidFormula();

MoxieBondingCurve_InvalidTokenManager

error MoxieBondingCurve_InvalidTokenManager();

MoxieBondingCurve_InvalidOwner

error MoxieBondingCurve_InvalidOwner();

MoxieBondingCurve_InvalidSubjectFactory

error MoxieBondingCurve_InvalidSubjectFactory();

MoxieBondingCurve_OnlySubjectFactory

error MoxieBondingCurve_OnlySubjectFactory();

MoxieBondingCurve_InvalidReserveRation

error MoxieBondingCurve_InvalidReserveRation();

MoxieBondingCurve_SubjectAlreadyInitialized

error MoxieBondingCurve_SubjectAlreadyInitialized();

MoxieBondingCurve_SubjectNotInitialized

error MoxieBondingCurve_SubjectNotInitialized();

MoxieBondingCurve_InvalidSubjectSupply

error MoxieBondingCurve_InvalidSubjectSupply();

MoxieBondingCurve_InvalidSubject

error MoxieBondingCurve_InvalidSubject();

MoxieBondingCurve_InvalidDepositAmount

error MoxieBondingCurve_InvalidDepositAmount();

MoxieBondingCurve_InvalidSubjectToken

error MoxieBondingCurve_InvalidSubjectToken();

MoxieBondingCurve_SlippageExceedsLimit

error MoxieBondingCurve_SlippageExceedsLimit();

MoxieBondingCurve_InvalidSellAmount

error MoxieBondingCurve_InvalidSellAmount();

MoxieBondingCurve_InvalidAmount

error MoxieBondingCurve_InvalidAmount();

MoxieBondingCurve_InvalidProtocolRewardAddress

error MoxieBondingCurve_InvalidProtocolRewardAddress();

MoxieBondingCurve_InvalidSubjectRewardAddress

error MoxieBondingCurve_SubjectNotPaused();

MoxieBondingCurve_TradingPaused

error MoxieBondingCurve_TradingPaused();

MoxieBondingCurve_SubjectAlreadyGraduated

error MoxieBondingCurve_SubjectAlreadyGraduated();

MoxieBondingCurve_SubjectReadyForGraduation

error MoxieBondingCurve_SubjectReadyForGraduation();

MoxieBondingCurve_SubjectNotReadyForGraduation

error MoxieBondingCurve_SubjectNotReadyForGraduation();

MoxieBondingCurve_SubjectNotGraduated

error MoxieBondingCurve_SubjectNotGraduated();