Skip to main content

MoxieBondingCurveV2.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]

initializeSubjectBondingCurve

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

Events

UpdateFees

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

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
);

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();