1+ /*
2+ Copyright 2022 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+ pragma experimental "ABIEncoderV2 " ;
20+
21+ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
22+
23+ import { IPerpV2LeverageModuleV2 } from "./IPerpV2LeverageModuleV2.sol " ;
24+ import { ISetToken } from "./ISetToken.sol " ;
25+
26+ /**
27+ * @title IPerpV2BasisTradingModule
28+ * @author Set Protocol
29+ *
30+ * Interface for the PerpV2BasisTradingModule. Only specifies Manager permissioned functions, events
31+ * and getters. PerpV2BasisTradingModule also inherits from ModuleBaseV2 and SetTokenAccessible which support
32+ * additional methods.
33+ */
34+ interface IPerpV2BasisTradingModule is IPerpV2LeverageModuleV2 {
35+
36+ /* ============ Structs ============ */
37+
38+ struct FeeState {
39+ address feeRecipient; // Address to accrue fees to
40+ uint256 maxPerformanceFeePercentage; // Max performance fee manager commits to using (1% = 1e16, 100% = 1e18)
41+ uint256 performanceFeePercentage; // Performance fees accrued to manager (1% = 1e16, 100% = 1e18)
42+ }
43+
44+ /* ============ Events ============ */
45+
46+ /**
47+ * @dev Emitted on performance fee update
48+ * @param _setToken Instance of SetToken
49+ * @param _newPerformanceFee New performance fee percentage (1% = 1e16)
50+ */
51+ event PerformanceFeeUpdated (ISetToken indexed _setToken , uint256 _newPerformanceFee );
52+
53+ /**
54+ * @dev Emitted on fee recipient update
55+ * @param _setToken Instance of SetToken
56+ * @param _newFeeRecipient New performance fee recipient
57+ */
58+ event FeeRecipientUpdated (ISetToken indexed _setToken , address _newFeeRecipient );
59+
60+ /**
61+ * @dev Emitted on funding withdraw
62+ * @param _setToken Instance of SetToken
63+ * @param _collateralToken Token being withdrawn as funding (USDC)
64+ * @param _amountWithdrawn Amount of funding being withdrawn from Perp (USDC)
65+ * @param _managerFee Amount of performance fee accrued to manager (USDC)
66+ * @param _protocolFee Amount of performance fee accrued to protocol (USDC)
67+ */
68+ event FundingWithdrawn (
69+ ISetToken indexed _setToken ,
70+ IERC20 _collateralToken ,
71+ uint256 _amountWithdrawn ,
72+ uint256 _managerFee ,
73+ uint256 _protocolFee
74+ );
75+
76+ /* ============ State Variable Getters ============ */
77+
78+ // Mapping to store fee settings for each SetToken
79+ function feeSettings (ISetToken _setToken ) external view returns (FeeState memory );
80+
81+ // Mapping to store funding that has been settled on Perpetual Protocol due to actions via this module
82+ // and hasn't been withdrawn for reinvesting yet. Values are stored in precise units (10e18).
83+ function settledFunding (ISetToken _settledFunding ) external view returns (uint256 );
84+
85+ /* ============ External Functions ============ */
86+
87+ /**
88+ * @dev MANAGER ONLY: Initializes this module to the SetToken and sets fee settings. Either the SetToken needs to
89+ * be on the allowed list or anySetAllowed needs to be true.
90+ *
91+ * @param _setToken Instance of the SetToken to initialize
92+ */
93+ function initialize (
94+ ISetToken _setToken ,
95+ FeeState memory _settings
96+ )
97+ external ;
98+
99+ /**
100+ * @dev MANAGER ONLY: Similar to PerpV2LeverageModuleV2#trade. Allows manager to buy or sell perps to change exposure
101+ * to the underlying baseToken. Any pending funding that would be settled during opening a position on Perpetual
102+ * protocol is added to (or subtracted from) `settledFunding[_setToken]` and can be withdrawn later using
103+ * `withdrawFundingAndAccrueFees` by the SetToken manager.
104+ * NOTE: Calling a `nonReentrant` function from another `nonReentrant` function is not supported. Hence, we can't
105+ * add the `nonReentrant` modifier here because `PerpV2LeverageModuleV2#trade` function has a reentrancy check.
106+ * NOTE: This method doesn't update the externalPositionUnit because it is a function of UniswapV3 virtual
107+ * token market prices and needs to be generated on the fly to be meaningful.
108+ *
109+ * @param _setToken Instance of the SetToken
110+ * @param _baseToken Address virtual token being traded
111+ * @param _baseQuantityUnits Quantity of virtual token to trade in position units
112+ * @param _quoteBoundQuantityUnits Max/min of vQuote asset to pay/receive when buying or selling
113+ */
114+ function tradeAndTrackFunding (
115+ ISetToken _setToken ,
116+ address _baseToken ,
117+ int256 _baseQuantityUnits ,
118+ uint256 _quoteBoundQuantityUnits
119+ )
120+ external ;
121+
122+ /**
123+ * @dev MANAGER ONLY: Withdraws tracked settled funding (in USDC) from the PerpV2 Vault to a default position
124+ * on the SetToken. Collects manager and protocol performance fees on the withdrawn amount.
125+ * This method is useful when withdrawing funding to be reinvested into the Basis Trading product.
126+ *
127+ * NOTE: Within PerpV2, `withdraw` settles `owedRealizedPnl` and any pending funding payments
128+ * to the Perp vault prior to transfer.
129+ *
130+ * @param _setToken Instance of the SetToken
131+ * @param _notionalFunding Notional amount of funding to withdraw (in USDC decimals)
132+ */
133+ function withdrawFundingAndAccrueFees (
134+ ISetToken _setToken ,
135+ uint256 _notionalFunding
136+ )
137+ external ;
138+
139+ /**
140+ * @dev MANAGER ONLY. Update performance fee percentage.
141+ *
142+ * @param _setToken Instance of SetToken
143+ * @param _newFee New performance fee percentage in precise units (1e16 = 1%)
144+ */
145+ function updatePerformanceFee (
146+ ISetToken _setToken ,
147+ uint256 _newFee
148+ )
149+ external ;
150+
151+ /**
152+ * @dev MANAGER ONLY. Update performance fee recipient (address to which performance fees are sent).
153+ *
154+ * @param _setToken Instance of SetToken
155+ * @param _newFeeRecipient Address of new fee recipient
156+ */
157+ function updateFeeRecipient (ISetToken _setToken , address _newFeeRecipient )
158+ external ;
159+ }
0 commit comments