Skip to content

fix(SlippageIssuanceModule): Fix issuance & redemption flows to not update position units #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions contracts/protocol/modules/v1/SlippageIssuanceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ contract SlippageIssuanceModule is DebtIssuanceModule {

/* ============ External Functions ============ */

/**
* @dev Reverts upon calling. Call `issueWithSlippage` instead.
*/
function issue(ISetToken /*_setToken*/, uint256 /*_quantity*/, address /*_to*/) external override(DebtIssuanceModule) {
revert("Call issueWithSlippage instead");
}

/**
* @dev Reverts upon calling. Call `redeemWithSlippage` instead.
*/
function redeem(ISetToken /*_setToken*/, uint256 /*_quantity*/, address /*_to*/) external override(DebtIssuanceModule) {
revert("Call redeemWithSlippage instead");
}

/**
* Deposits components to the SetToken, replicates any external module component positions and mints
* the SetToken. If the token has a debt position all collateral will be transferred in first then debt
Expand Down Expand Up @@ -76,8 +90,6 @@ contract SlippageIssuanceModule is DebtIssuanceModule {

address hookContract = _callManagerPreIssueHooks(_setToken, _setQuantity, msg.sender, _to);

_callModulePreIssueHooks(_setToken, _setQuantity);

bool isIssue = true;

(
Expand All @@ -86,6 +98,8 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
uint256 protocolFee
) = calculateTotalFees(_setToken, _setQuantity, isIssue);

_callModulePreIssueHooks(_setToken, quantityWithFees);

// Scoping logic to avoid stack too deep errors
{
(
Expand Down Expand Up @@ -148,11 +162,6 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
{
_validateInputs(_setQuantity, _checkedComponents, _minTokenAmountsOut);

_callModulePreRedeemHooks(_setToken, _setQuantity);

// Place burn after pre-redeem hooks because burning tokens may lead to false accounting of synced positions
_setToken.burn(msg.sender, _setQuantity);

bool isIssue = false;

(
Expand All @@ -161,6 +170,11 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
uint256 protocolFee
) = calculateTotalFees(_setToken, _setQuantity, isIssue);

_callModulePreRedeemHooks(_setToken, quantityNetFees);

// Place burn after pre-redeem hooks because burning tokens may lead to false accounting of synced positions
_setToken.burn(msg.sender, _setQuantity);

(
address[] memory components,
uint256[] memory equityUnits,
Expand Down
Loading