Skip to content

Commit 1c4e271

Browse files
authored
Brian/slippage iss review changes (#164)
Change logic to have modules return diff in position units and do the conversion on the SIP. Small javadoc updates.
1 parent 44d97ed commit 1c4e271

File tree

3 files changed

+671
-1190
lines changed

3 files changed

+671
-1190
lines changed

contracts/interfaces/IModuleIssuanceHookV2.sol

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 Set Labs Inc.
2+
Copyright 2021 Set Labs Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -50,16 +50,9 @@ interface IModuleIssuanceHookV2 {
5050

5151
/**
5252
* Adjustments should return the NET CHANGE in POSITION UNITS for each component in the SetToken's
53-
* components array. Each entry in the returned arrays should index to the same component in the
54-
* SetToken's components array (called using getComponents()). Directional adjustments should be made
55-
* according to the following table (i.e. returning a negative debt number means debt is reduced during
56-
* issue/redeem):
57-
* | ------------------------------------|
58-
* | Type | Positive | Negative |
59-
* | ----- |---------- | --------------|
60-
* | Equity | Add Equity| Equity Reduced|
61-
* | Debt | Add Debt | Debt Reduced |
62-
* | ------------------------------------|
53+
* components array (i.e. if debt is greater than current debt position unit return negative number).
54+
* Each entry in the returned arrays should index to the same component in the SetToken's components
55+
* array (called using getComponents()).
6356
*/
6457
function getIssuanceAdjustments(
6558
ISetToken _setToken,

contracts/protocol/modules/SlippageIssuanceModule.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { Position } from "../lib/Position.sol";
3434
* @title SlippageIssuanceModule
3535
* @author Set Protocol
3636
*
37-
* The SlippageIssuanceModule is a module that enables users to issue and redeem SetTokens that requires a transaction that incurs slippage.
37+
* The SlippageIssuanceModule is a module that enables users to issue and redeem SetTokens that requires a transaction that incurs slippage
3838
* in order to replicate the Set. Like the DebtIssuanceModule, module hooks are added to allow for syncing of positions, and component
3939
* level hooks are added to ensure positions are replicated correctly. The manager can define arbitrary issuance logic in the manager hook,
4040
* as well as specify issue and redeem fees. The getRequiredComponentIssuanceUnits and it's redemption counterpart now also include any
@@ -190,6 +190,8 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
190190
);
191191
}
192192

193+
/* ============ External View Functions ============ */
194+
193195
/**
194196
* Calculates the amount of each component needed to collateralize passed issue quantity plus fees of Sets as well as amount of debt
195197
* that will be returned to caller. Overrides inherited function to take into account position updates from pre action module hooks.
@@ -271,6 +273,8 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
271273
);
272274
}
273275

276+
/* ============ Internal Functions ============ */
277+
274278
/**
275279
* Similar to _calculateRequiredComponentIssuanceUnits but adjustments for positions that will be updated DURING the issue
276280
* or redeem process are added in. Adjustments can be either positive or negative, a negative debt adjustment means there
@@ -306,7 +310,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
306310
uint256[] memory totalEquityUnits = new uint256[](components.length);
307311
uint256[] memory totalDebtUnits = new uint256[](components.length);
308312
for (uint256 i = 0; i < components.length; i++) {
309-
// NOTE: If equityAdjustment is negative and exceeds debtUnits in absolute value this will revert
313+
// NOTE: If equityAdjustment is negative and exceeds equityUnits in absolute value this will revert
310314
uint256 adjustedEquityUnits = equityUnits[i].toInt256().add(_equityAdjustments[i]).toUint256();
311315

312316
// Use preciseMulCeil to round up to ensure overcollateration when small issue quantities are provided
@@ -316,7 +320,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule {
316320
adjustedEquityUnits.preciseMul(_quantity);
317321

318322
// NOTE: If debtAdjustment is negative and exceeds debtUnits in absolute value this will revert
319-
uint256 adjustedDebtUnits = debtUnits[i].toInt256().add(_debtAdjustments[i]).toUint256();
323+
uint256 adjustedDebtUnits = debtUnits[i].toInt256().sub(_debtAdjustments[i]).toUint256();
320324

321325
// Use preciseMulCeil to round up to ensure overcollateration when small redeem quantities are provided
322326
// and preciseMul to round down to ensure overcollateration when small issue quantities are provided

0 commit comments

Comments
 (0)