Skip to content

Commit

Permalink
fix(SlippageIssuanceModule): Fix issuance & redemption flows to not u…
Browse files Browse the repository at this point in the history
…pdate position units (#254)

* Reapply all fixes by Brain; Skip package.json changes

* Fix SIM

* Fix PerpV2LeverageModule<>SIM integration tests

* Fix BTM <> SIM integration tests

* Add tests to ensure base token position unit does not update on issuance and redemption

* Bump package to 0.10.3-basis.0 and publish

* Override issue and redeem; Add tests

* Reset package version to 0.10.3
  • Loading branch information
Sachin authored May 20, 2022
1 parent c04e399 commit 9be3d1b
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 151 deletions.
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

0 comments on commit 9be3d1b

Please sign in to comment.