Skip to content

Commit 44d97ed

Browse files
authored
Brian/slippage issuance (#162)
Issuance module that allows for issue/redeem of assets that may be susceptible to slippage. Allows user to set slippage limit similar to a Uniswap trade. Additional functionality added to helper functions to give better estimates of required components by taking into account positional changes during issue/redeem.
1 parent 5a96f11 commit 44d97ed

File tree

7 files changed

+2232
-0
lines changed

7 files changed

+2232
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright 2020 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
pragma solidity 0.6.10;
19+
20+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
21+
22+
import { ISetToken } from "./ISetToken.sol";
23+
24+
25+
/**
26+
* CHANGELOG:
27+
* - Added a module level issue hook that can be used to set state ahead of component level
28+
* issue hooks
29+
* - Added view function that return expected positional adjustments during issue/redeem to
30+
* the issuance module in order to give more accurate token flow information
31+
*/
32+
interface IModuleIssuanceHookV2 {
33+
34+
function moduleIssueHook(ISetToken _setToken, uint256 _setTokenQuantity) external;
35+
function moduleRedeemHook(ISetToken _setToken, uint256 _setTokenQuantity) external;
36+
37+
function componentIssueHook(
38+
ISetToken _setToken,
39+
uint256 _setTokenQuantity,
40+
IERC20 _component,
41+
bool _isEquity
42+
) external;
43+
44+
function componentRedeemHook(
45+
ISetToken _setToken,
46+
uint256 _setTokenQuantity,
47+
IERC20 _component,
48+
bool _isEquity
49+
) external;
50+
51+
/**
52+
* 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+
* | ------------------------------------|
63+
*/
64+
function getIssuanceAdjustments(
65+
ISetToken _setToken,
66+
uint256 _setTokenQuantity
67+
)
68+
external
69+
view
70+
returns (int256[] memory, int256[] memory);
71+
72+
/**
73+
* Adjustments should return the NET CHANGE in POSITION UNITS for each component in the SetToken's
74+
* components array. Each entry in the returned arrays should index to the same component in the
75+
* SetToken's components array (called using getComponents()). Directional adjustments should be made
76+
* according to the following table (i.e. returning a negative debt number means debt is reduced during
77+
* issue/redeem):
78+
* | ------------------------------------|
79+
* | Type | Positive | Negative |
80+
* | ----- |---------- | --------------|
81+
* | Equity | Add Equity| Equity Reduced|
82+
* | Debt | Add Debt | Debt Reduced |
83+
* | ------------------------------------|
84+
*/
85+
function getRedemptionAdjustments(
86+
ISetToken _setToken,
87+
uint256 _setTokenQuantity
88+
)
89+
external
90+
view
91+
returns (int256[] memory, int256[] memory);
92+
}

contracts/mocks/protocol/module/DebtModuleMock.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ contract DebtModuleMock is ModuleBase {
4444
address public module;
4545
bool public moduleIssueHookCalled;
4646
bool public moduleRedeemHookCalled;
47+
mapping(address=>int256) public equityIssuanceAdjustment;
48+
mapping(address=>int256) public debtIssuanceAdjustment;
4749

4850
constructor(IController _controller, address _module) public ModuleBase(_controller) {
4951
module = _module;
@@ -53,6 +55,14 @@ contract DebtModuleMock is ModuleBase {
5355
_setToken.editExternalPosition(_token, address(this), _amount.toInt256().mul(-1), "");
5456
}
5557

58+
function addEquityIssuanceAdjustment(address _token, int256 _amount) external {
59+
equityIssuanceAdjustment[_token] = _amount;
60+
}
61+
62+
function addDebtIssuanceAdjustment(address _token, int256 _amount) external {
63+
debtIssuanceAdjustment[_token] = _amount;
64+
}
65+
5666
function moduleIssueHook(ISetToken /*_setToken*/, uint256 /*_setTokenQuantity*/) external { moduleIssueHookCalled = true; }
5767
function moduleRedeemHook(ISetToken /*_setToken*/, uint256 /*_setTokenQuantity*/) external { moduleRedeemHookCalled = true; }
5868

@@ -82,6 +92,45 @@ contract DebtModuleMock is ModuleBase {
8292
_setToken.invokeTransfer(_component, address(this), notionalAmount);
8393
}
8494

95+
96+
function getIssuanceAdjustments(
97+
ISetToken _setToken,
98+
uint256 /* _setTokenQuantity */
99+
)
100+
external
101+
view
102+
returns (int256[] memory, int256[] memory)
103+
{
104+
address[] memory components = _setToken.getComponents();
105+
int256[] memory equityAdjustments = new int256[](components.length);
106+
int256[] memory debtAdjustments = new int256[](components.length);
107+
for(uint256 i = 0; i < components.length; i++) {
108+
equityAdjustments[i] = equityIssuanceAdjustment[components[i]];
109+
debtAdjustments[i] = debtIssuanceAdjustment[components[i]];
110+
}
111+
112+
return (equityAdjustments, debtAdjustments);
113+
}
114+
115+
function getRedemptionAdjustments(
116+
ISetToken _setToken,
117+
uint256 /* _setTokenQuantity */
118+
)
119+
external
120+
view
121+
returns (int256[] memory, int256[] memory)
122+
{
123+
address[] memory components = _setToken.getComponents();
124+
int256[] memory equityAdjustments = new int256[](components.length);
125+
int256[] memory debtAdjustments = new int256[](components.length);
126+
for(uint256 i = 0; i < components.length; i++) {
127+
equityAdjustments[i] = equityIssuanceAdjustment[components[i]];
128+
debtAdjustments[i] = debtIssuanceAdjustment[components[i]];
129+
}
130+
131+
return (equityAdjustments, debtAdjustments);
132+
}
133+
85134
function initialize(ISetToken _setToken) external {
86135
_setToken.initializeModule();
87136
IDebtIssuanceModule(module).registerToIssuanceModule(_setToken);

contracts/protocol/modules/DebtIssuanceModule.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard {
417417
)
418418
external
419419
view
420+
virtual
420421
returns (address[] memory, uint256[] memory, uint256[] memory)
421422
{
422423
(

0 commit comments

Comments
 (0)