Skip to content

buy operations would revert due to incorrect fee handling #750

@MehdiKarimi81

Description

@MehdiKarimi81

The _processProtocolFeeViaTransfer function attempts to transfer collateralProtocolFeeAmount to the collateralTreasury. However, since _handleCollateralTokensBeforeBuy transfers all the funds to the project treasury, no collateral remains in the funding manager, causing _buyOrder to revert.

(
uint netDeposit,
uint collateralProtocolFeeAmount,
uint projectFeeAmount
) = _calculateNetAndSplitFees(
_depositAmount, collateralBuyFeePercentage, buyFee
);
// collateral Fee Amount is the combination of protocolFeeAmount plus the projectFeeAmount
collateralFeeAmount = collateralProtocolFeeAmount + projectFeeAmount;
// Calculate token amount based on upstream formula
uint issuanceTokenAmount = _issueTokensFormulaWrapper(netDeposit);
totalIssuanceTokenMinted = issuanceTokenAmount;
// Get net amount, protocol and project fee amounts. Currently there is no issuance project
// fee enabled
uint issuanceProtocolFeeAmount;
(
issuanceTokenAmount,
issuanceProtocolFeeAmount, /* projectFeeAmount */
) = _calculateNetAndSplitFees(
issuanceTokenAmount, issuanceBuyFeePercentage, 0
);
// Revert if the token amount is lower than the minimum amount the user expects
if (issuanceTokenAmount < _minAmountOut) {
revert Module__BondingCurveBase__InsufficientOutputAmount();
}
// ------------------------------------------------------------
// Interactions
// Handle collateral tokens before buy
_handleCollateralTokensBeforeBuy(_msgSender(), _depositAmount);
// Process protocol fee on incoming collateral tokens
_processProtocolFeeViaTransfer(
collateralTreasury, collateralToken, collateralProtocolFeeAmount
);

/// @inheritdoc BondingCurveBase_v1
/// @dev Implementation transfer collateral tokens to the project treasury.
function _handleCollateralTokensBeforeBuy(address _provider, uint _amount)
internal
virtual
override
{
IERC20(token()).safeTransferFrom(_provider, _projectTreasury, _amount);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions