@harvest-finance/harvest-strategy-arbitrum 0.0.1-security → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @harvest-finance/harvest-strategy-arbitrum might be problematic. Click here for more details.

Files changed (199) hide show
  1. package/README.md +127 -5
  2. package/contracts/base/Controller.sol +358 -0
  3. package/contracts/base/Drip.sol +86 -0
  4. package/contracts/base/PotPool.sol +367 -0
  5. package/contracts/base/ProfitSharingReceiver.sol +38 -0
  6. package/contracts/base/Reader.sol +54 -0
  7. package/contracts/base/RewardForwarder.sol +109 -0
  8. package/contracts/base/VaultProxy.sol +34 -0
  9. package/contracts/base/VaultStorage.sol +205 -0
  10. package/contracts/base/VaultV1.sol +371 -0
  11. package/contracts/base/VaultV1GMX.sol +465 -0
  12. package/contracts/base/VaultV2.sol +111 -0
  13. package/contracts/base/VaultV2GMX.sol +111 -0
  14. package/contracts/base/factory/MegaFactory.sol +120 -0
  15. package/contracts/base/factory/interface/IPoolFactory.sol +6 -0
  16. package/contracts/base/factory/interface/IStrategyFactory.sol +6 -0
  17. package/contracts/base/factory/interface/IVaultFactory.sol +7 -0
  18. package/contracts/base/factory/pool/PotPoolFactory.sol +41 -0
  19. package/contracts/base/factory/strategy/UpgradableStrategyFactory.sol +19 -0
  20. package/contracts/base/factory/vault/RegularVaultFactory.sol +34 -0
  21. package/contracts/base/incentives/GlobalIncentivesExecutor.sol +85 -0
  22. package/contracts/base/incentives/GlobalIncentivesHelper.sol +174 -0
  23. package/contracts/base/incentives/NotifyHelperGeneric.sol +61 -0
  24. package/contracts/base/incentives/NotifyHelperStateful.sol +290 -0
  25. package/contracts/base/incentives/ViewerNotifyHelperStateful.sol +25 -0
  26. package/contracts/base/inheritance/Controllable.sol +25 -0
  27. package/contracts/base/inheritance/ControllableInit.sol +30 -0
  28. package/contracts/base/inheritance/Governable.sol +28 -0
  29. package/contracts/base/inheritance/GovernableInit.sol +50 -0
  30. package/contracts/base/inheritance/IUpgradeSource.sol +7 -0
  31. package/contracts/base/inheritance/OwnableWhitelist.sol +17 -0
  32. package/contracts/base/inheritance/Storage.sol +35 -0
  33. package/contracts/base/interface/IBalDex.sol +7 -0
  34. package/contracts/base/interface/IController.sol +132 -0
  35. package/contracts/base/interface/IDex.sol +9 -0
  36. package/contracts/base/interface/IERC4626.sol +261 -0
  37. package/contracts/base/interface/IGMXStrategy.sol +37 -0
  38. package/contracts/base/interface/IGlobalIncentivesHelper.sol +6 -0
  39. package/contracts/base/interface/IPotPool.sol +70 -0
  40. package/contracts/base/interface/IProfitSharingReceiver.sol +9 -0
  41. package/contracts/base/interface/IRewardForwarder.sol +57 -0
  42. package/contracts/base/interface/IStrategy.sol +37 -0
  43. package/contracts/base/interface/IUniversalLiquidator.sol +21 -0
  44. package/contracts/base/interface/IUniversalLiquidatorRegistry.sol +20 -0
  45. package/contracts/base/interface/IUpgradeSource.sol +9 -0
  46. package/contracts/base/interface/IVault.sol +58 -0
  47. package/contracts/base/interface/IVaultGMX.sol +71 -0
  48. package/contracts/base/interface/aura/IAuraBaseRewardPool.sol +25 -0
  49. package/contracts/base/interface/aura/IAuraBooster.sol +17 -0
  50. package/contracts/base/interface/aura/IAuraDepositor.sol +7 -0
  51. package/contracts/base/interface/balancer/Gauge.sol +22 -0
  52. package/contracts/base/interface/balancer/IBVault.sol +580 -0
  53. package/contracts/base/interface/balancer/IBalancerMinter.sol +114 -0
  54. package/contracts/base/interface/balancer/IGyroPool.sol +7 -0
  55. package/contracts/base/interface/balancer/linearPool/ILinearPool.sol +184 -0
  56. package/contracts/base/interface/balancer/linearPool/ILinearPoolFactory.sol +16 -0
  57. package/contracts/base/interface/balancer/linearPool/ILinearPoolRebalancer.sol +8 -0
  58. package/contracts/base/interface/balancer/linearPool/IPoolSwapStructs.sol +56 -0
  59. package/contracts/base/interface/compound/CTokenInterface.sol +29 -0
  60. package/contracts/base/interface/compound/IComptroller.sol +9 -0
  61. package/contracts/base/interface/dolomite/IDepositWithdraw.sol +13 -0
  62. package/contracts/base/interface/dolomite/IDolomiteMargin.sol +15 -0
  63. package/contracts/base/interface/dolomite/IRewardsDistributor.sol +11 -0
  64. package/contracts/base/interface/gamma/IClearing.sol +7 -0
  65. package/contracts/base/interface/gamma/IHypervisor.sol +9 -0
  66. package/contracts/base/interface/gamma/IUniProxy.sol +14 -0
  67. package/contracts/base/interface/gmx/EventUtils.sol +253 -0
  68. package/contracts/base/interface/gmx/ICallbackReceiver.sol +119 -0
  69. package/contracts/base/interface/gmx/IDataStore.sol +7 -0
  70. package/contracts/base/interface/gmx/IExchangeRouter.sol +38 -0
  71. package/contracts/base/interface/gmx/IGMXViewer.sol +7 -0
  72. package/contracts/base/interface/gmx/IHandler.sol +12 -0
  73. package/contracts/base/interface/gmx/IMarket.sol +7 -0
  74. package/contracts/base/interface/gmx/IOracle.sol +6 -0
  75. package/contracts/base/interface/gmx/IPriceFeed.sol +12 -0
  76. package/contracts/base/interface/gmx/IReader.sol +49 -0
  77. package/contracts/base/interface/gmx/IRoleStore.sol +6 -0
  78. package/contracts/base/interface/ipor/Errors.sol +20 -0
  79. package/contracts/base/interface/ipor/FuseStorageLib.sol +71 -0
  80. package/contracts/base/interface/ipor/FusesLib.sol +149 -0
  81. package/contracts/base/interface/ipor/IFuseCommon.sol +9 -0
  82. package/contracts/base/interface/ipor/IFuseInstantWithdraw.sol +14 -0
  83. package/contracts/base/interface/ipor/IMarketBalanceFuse.sol +10 -0
  84. package/contracts/base/interface/ipor/IPriceOracleMiddleware.sol +42 -0
  85. package/contracts/base/interface/ipor/IporMath.sol +110 -0
  86. package/contracts/base/interface/ipor/PlasmaVaultConfigLib.sol +106 -0
  87. package/contracts/base/interface/ipor/PlasmaVaultLib.sol +293 -0
  88. package/contracts/base/interface/ipor/PlasmaVaultStorageLib.sol +352 -0
  89. package/contracts/base/interface/merkl/IDistributor.sol +6 -0
  90. package/contracts/base/interface/notional/INProxy.sol +44 -0
  91. package/contracts/base/interface/notional/IPrimeToken.sol +6 -0
  92. package/contracts/base/interface/venus/IRewardsDistributor.sol +6 -0
  93. package/contracts/base/interface/weth/IWETH.sol +39 -0
  94. package/contracts/base/ipor/Erc4626BalanceFuse.sol +54 -0
  95. package/contracts/base/ipor/Erc4626SupplyFuse.sol +134 -0
  96. package/contracts/base/noop/NoopStrategyUpgradeable.sol +90 -0
  97. package/contracts/base/upgradability/BaseUpgradeabilityProxy.sol +60 -0
  98. package/contracts/base/upgradability/BaseUpgradeableStrategy.sol +144 -0
  99. package/contracts/base/upgradability/BaseUpgradeableStrategyStorage.sol +284 -0
  100. package/contracts/base/upgradability/IUpgradable.sol +7 -0
  101. package/contracts/base/upgradability/ReentrancyGuardUpgradeable.sol +51 -0
  102. package/contracts/base/upgradability/StrategyProxy.sol +34 -0
  103. package/contracts/strategies/aura/AuraStrategy.sol +403 -0
  104. package/contracts/strategies/aura/AuraStrategyMainnet_MORE_GYD.sol +32 -0
  105. package/contracts/strategies/aura/AuraStrategyMainnet_sUSDe_GYD.sol +31 -0
  106. package/contracts/strategies/aura/AuraStrategyMainnet_waFRAX_sFRAX.sol +31 -0
  107. package/contracts/strategies/aura/AuraStrategyMainnet_waGHO_GYD.sol +31 -0
  108. package/contracts/strategies/aura/AuraStrategyMainnet_waUSDC_GHO.sol +32 -0
  109. package/contracts/strategies/aura/AuraStrategyMainnet_waUSDC_GYD.sol +31 -0
  110. package/contracts/strategies/aura/AuraStrategyMainnet_waUSDT_GYD.sol +31 -0
  111. package/contracts/strategies/aura/AuraStrategyMainnet_wstETH_GYD.sol +31 -0
  112. package/contracts/strategies/camelot/CamelotV3Strategy.sol +304 -0
  113. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_ARB_USDC.sol +28 -0
  114. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_ETH_USDC.sol +28 -0
  115. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_ETH_USDT.sol +28 -0
  116. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_GMX_ETH.sol +28 -0
  117. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_GRAIL_ETH.sol +28 -0
  118. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_USDC_USDT.sol +28 -0
  119. package/contracts/strategies/camelot/CamelotV3StrategyMainnet_WBTC_ETH.sol +28 -0
  120. package/contracts/strategies/dolomite/DolomiteLendStrategy.sol +273 -0
  121. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_DAI.sol +26 -0
  122. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_GMX.sol +26 -0
  123. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_USDC.sol +26 -0
  124. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_USDCe.sol +26 -0
  125. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_USDT.sol +26 -0
  126. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_WBTC.sol +26 -0
  127. package/contracts/strategies/dolomite/DolomiteLendStrategyMainnet_WETH.sol +26 -0
  128. package/contracts/strategies/fluid/FluidLendStrategy.sol +241 -0
  129. package/contracts/strategies/fluid/FluidLendStrategyMainnet_ETH.sol +25 -0
  130. package/contracts/strategies/fluid/FluidLendStrategyMainnet_USDC.sol +25 -0
  131. package/contracts/strategies/fluid/FluidLendStrategyMainnet_USDT.sol +25 -0
  132. package/contracts/strategies/gmx/GMXStrategy.sol +472 -0
  133. package/contracts/strategies/gmx/GMXStrategyMainnet_WBTC.sol +25 -0
  134. package/contracts/strategies/gmx/GMXViewer.sol +110 -0
  135. package/contracts/strategies/notional/NotionalStrategy.sol +223 -0
  136. package/contracts/strategies/notional/NotionalStrategyMainnet_nETH.sol +27 -0
  137. package/contracts/strategies/notional/NotionalStrategyMainnet_nUSDC.sol +27 -0
  138. package/contracts/strategies/notional/NotionalStrategyMainnet_nUSDT.sol +27 -0
  139. package/contracts/strategies/notional/NotionalStrategyMainnet_nwstETH.sol +27 -0
  140. package/contracts/strategies/venus/VenusFoldStrategy.sol +591 -0
  141. package/contracts/strategies/venus/VenusFoldStrategyMainnet_ARB.sol +32 -0
  142. package/contracts/strategies/venus/VenusFoldStrategyMainnet_ETH_core.sol +32 -0
  143. package/contracts/strategies/venus/VenusFoldStrategyMainnet_ETH_lsd.sol +32 -0
  144. package/contracts/strategies/venus/VenusFoldStrategyMainnet_USDC.sol +32 -0
  145. package/contracts/strategies/venus/VenusFoldStrategyMainnet_USDT.sol +32 -0
  146. package/contracts/strategies/venus/VenusFoldStrategyMainnet_WBTC.sol +32 -0
  147. package/hardhat.config.js +60 -0
  148. package/index.js +42 -0
  149. package/package.json +38 -6
  150. package/scripts/01-deploy-vault-regular-with-upgradable-strategy.js +41 -0
  151. package/scripts/02-deploy-vault-regular.js +35 -0
  152. package/scripts/03-deploy-upgradable-strategy.js +40 -0
  153. package/scripts/04-deploy-new-implementation.js +24 -0
  154. package/scripts/05-deploy-GMXViewer.js +17 -0
  155. package/scripts/06-deploy-GMXVault.js +49 -0
  156. package/scripts/07-deploy-ipor-fuses.js +29 -0
  157. package/scripts/08-deploy-drip.js +20 -0
  158. package/scripts/README.md +55 -0
  159. package/scripts/utils.js +22 -0
  160. package/test/aura/more-gyd.js +140 -0
  161. package/test/aura/susde-gyd.js +140 -0
  162. package/test/aura/wafrax-sfrax.js +140 -0
  163. package/test/aura/wagho-gyd.js +140 -0
  164. package/test/aura/wausdc-gho.js +141 -0
  165. package/test/aura/wausdc-gyd.js +140 -0
  166. package/test/aura/wausdt-gyd.js +140 -0
  167. package/test/aura/wsteth-gyd.js +138 -0
  168. package/test/camelot/arb-usdc.js +125 -0
  169. package/test/camelot/eth-usdc.js +125 -0
  170. package/test/camelot/eth-usdt.js +125 -0
  171. package/test/camelot/gmx-eth.js +125 -0
  172. package/test/camelot/grail-eth.js +125 -0
  173. package/test/camelot/usdc-usdt.js +125 -0
  174. package/test/camelot/wbtc-eth.js +125 -0
  175. package/test/dolomite/dai.js +127 -0
  176. package/test/dolomite/gmx.js +134 -0
  177. package/test/dolomite/usdc.js +127 -0
  178. package/test/dolomite/usdce.js +127 -0
  179. package/test/dolomite/usdt.js +127 -0
  180. package/test/dolomite/wbtc.js +127 -0
  181. package/test/dolomite/weth.js +127 -0
  182. package/test/fluid/eth.js +127 -0
  183. package/test/fluid/usdc.js +134 -0
  184. package/test/fluid/usdt.js +134 -0
  185. package/test/gmx/wbtc.js +184 -0
  186. package/test/notional/neth.js +133 -0
  187. package/test/notional/nusdc.js +133 -0
  188. package/test/notional/nusdt.js +133 -0
  189. package/test/notional/nwsteth.js +133 -0
  190. package/test/test-config.js +28 -0
  191. package/test/utilities/Utils.js +96 -0
  192. package/test/utilities/hh-utils.js +248 -0
  193. package/test/utilities/make-vault.js +16 -0
  194. package/test/venus/arb.js +135 -0
  195. package/test/venus/eth-core.js +133 -0
  196. package/test/venus/eth-lsd.js +133 -0
  197. package/test/venus/usdc.js +133 -0
  198. package/test/venus/usdt.js +133 -0
  199. package/test/venus/wbtc.js +133 -0
@@ -0,0 +1,253 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ pragma solidity 0.8.26;
3
+
4
+ library EventUtils {
5
+ struct EmitPositionDecreaseParams {
6
+ bytes32 key;
7
+ address account;
8
+ address market;
9
+ address collateralToken;
10
+ bool isLong;
11
+ }
12
+
13
+ struct EventLogData {
14
+ AddressItems addressItems;
15
+ UintItems uintItems;
16
+ IntItems intItems;
17
+ BoolItems boolItems;
18
+ Bytes32Items bytes32Items;
19
+ BytesItems bytesItems;
20
+ StringItems stringItems;
21
+ }
22
+
23
+ struct AddressItems {
24
+ AddressKeyValue[] items;
25
+ AddressArrayKeyValue[] arrayItems;
26
+ }
27
+
28
+ struct UintItems {
29
+ UintKeyValue[] items;
30
+ UintArrayKeyValue[] arrayItems;
31
+ }
32
+
33
+ struct IntItems {
34
+ IntKeyValue[] items;
35
+ IntArrayKeyValue[] arrayItems;
36
+ }
37
+
38
+ struct BoolItems {
39
+ BoolKeyValue[] items;
40
+ BoolArrayKeyValue[] arrayItems;
41
+ }
42
+
43
+ struct Bytes32Items {
44
+ Bytes32KeyValue[] items;
45
+ Bytes32ArrayKeyValue[] arrayItems;
46
+ }
47
+
48
+ struct BytesItems {
49
+ BytesKeyValue[] items;
50
+ BytesArrayKeyValue[] arrayItems;
51
+ }
52
+
53
+ struct StringItems {
54
+ StringKeyValue[] items;
55
+ StringArrayKeyValue[] arrayItems;
56
+ }
57
+
58
+ struct AddressKeyValue {
59
+ string key;
60
+ address value;
61
+ }
62
+
63
+ struct AddressArrayKeyValue {
64
+ string key;
65
+ address[] value;
66
+ }
67
+
68
+ struct UintKeyValue {
69
+ string key;
70
+ uint256 value;
71
+ }
72
+
73
+ struct UintArrayKeyValue {
74
+ string key;
75
+ uint256[] value;
76
+ }
77
+
78
+ struct IntKeyValue {
79
+ string key;
80
+ int256 value;
81
+ }
82
+
83
+ struct IntArrayKeyValue {
84
+ string key;
85
+ int256[] value;
86
+ }
87
+
88
+ struct BoolKeyValue {
89
+ string key;
90
+ bool value;
91
+ }
92
+
93
+ struct BoolArrayKeyValue {
94
+ string key;
95
+ bool[] value;
96
+ }
97
+
98
+ struct Bytes32KeyValue {
99
+ string key;
100
+ bytes32 value;
101
+ }
102
+
103
+ struct Bytes32ArrayKeyValue {
104
+ string key;
105
+ bytes32[] value;
106
+ }
107
+
108
+ struct BytesKeyValue {
109
+ string key;
110
+ bytes value;
111
+ }
112
+
113
+ struct BytesArrayKeyValue {
114
+ string key;
115
+ bytes[] value;
116
+ }
117
+
118
+ struct StringKeyValue {
119
+ string key;
120
+ string value;
121
+ }
122
+
123
+ struct StringArrayKeyValue {
124
+ string key;
125
+ string[] value;
126
+ }
127
+
128
+ function initItems(AddressItems memory items, uint256 size) internal pure {
129
+ items.items = new EventUtils.AddressKeyValue[](size);
130
+ }
131
+
132
+ function initArrayItems(AddressItems memory items, uint256 size) internal pure {
133
+ items.arrayItems = new EventUtils.AddressArrayKeyValue[](size);
134
+ }
135
+
136
+ function setItem(AddressItems memory items, uint256 index, string memory key, address value) internal pure {
137
+ items.items[index].key = key;
138
+ items.items[index].value = value;
139
+ }
140
+
141
+ function setItem(AddressItems memory items, uint256 index, string memory key, address[] memory value) internal pure {
142
+ items.arrayItems[index].key = key;
143
+ items.arrayItems[index].value = value;
144
+ }
145
+
146
+ function initItems(UintItems memory items, uint256 size) internal pure {
147
+ items.items = new EventUtils.UintKeyValue[](size);
148
+ }
149
+
150
+ function initArrayItems(UintItems memory items, uint256 size) internal pure {
151
+ items.arrayItems = new EventUtils.UintArrayKeyValue[](size);
152
+ }
153
+
154
+ function setItem(UintItems memory items, uint256 index, string memory key, uint256 value) internal pure {
155
+ items.items[index].key = key;
156
+ items.items[index].value = value;
157
+ }
158
+
159
+ function setItem(UintItems memory items, uint256 index, string memory key, uint256[] memory value) internal pure {
160
+ items.arrayItems[index].key = key;
161
+ items.arrayItems[index].value = value;
162
+ }
163
+
164
+ function initItems(IntItems memory items, uint256 size) internal pure {
165
+ items.items = new EventUtils.IntKeyValue[](size);
166
+ }
167
+
168
+ function initArrayItems(IntItems memory items, uint256 size) internal pure {
169
+ items.arrayItems = new EventUtils.IntArrayKeyValue[](size);
170
+ }
171
+
172
+ function setItem(IntItems memory items, uint256 index, string memory key, int256 value) internal pure {
173
+ items.items[index].key = key;
174
+ items.items[index].value = value;
175
+ }
176
+
177
+ function setItem(IntItems memory items, uint256 index, string memory key, int256[] memory value) internal pure {
178
+ items.arrayItems[index].key = key;
179
+ items.arrayItems[index].value = value;
180
+ }
181
+
182
+ function initItems(BoolItems memory items, uint256 size) internal pure {
183
+ items.items = new EventUtils.BoolKeyValue[](size);
184
+ }
185
+
186
+ function initArrayItems(BoolItems memory items, uint256 size) internal pure {
187
+ items.arrayItems = new EventUtils.BoolArrayKeyValue[](size);
188
+ }
189
+
190
+ function setItem(BoolItems memory items, uint256 index, string memory key, bool value) internal pure {
191
+ items.items[index].key = key;
192
+ items.items[index].value = value;
193
+ }
194
+
195
+ function setItem(BoolItems memory items, uint256 index, string memory key, bool[] memory value) internal pure {
196
+ items.arrayItems[index].key = key;
197
+ items.arrayItems[index].value = value;
198
+ }
199
+
200
+ function initItems(Bytes32Items memory items, uint256 size) internal pure {
201
+ items.items = new EventUtils.Bytes32KeyValue[](size);
202
+ }
203
+
204
+ function initArrayItems(Bytes32Items memory items, uint256 size) internal pure {
205
+ items.arrayItems = new EventUtils.Bytes32ArrayKeyValue[](size);
206
+ }
207
+
208
+ function setItem(Bytes32Items memory items, uint256 index, string memory key, bytes32 value) internal pure {
209
+ items.items[index].key = key;
210
+ items.items[index].value = value;
211
+ }
212
+
213
+ function setItem(Bytes32Items memory items, uint256 index, string memory key, bytes32[] memory value) internal pure {
214
+ items.arrayItems[index].key = key;
215
+ items.arrayItems[index].value = value;
216
+ }
217
+
218
+ function initItems(BytesItems memory items, uint256 size) internal pure {
219
+ items.items = new EventUtils.BytesKeyValue[](size);
220
+ }
221
+
222
+ function initArrayItems(BytesItems memory items, uint256 size) internal pure {
223
+ items.arrayItems = new EventUtils.BytesArrayKeyValue[](size);
224
+ }
225
+
226
+ function setItem(BytesItems memory items, uint256 index, string memory key, bytes memory value) internal pure {
227
+ items.items[index].key = key;
228
+ items.items[index].value = value;
229
+ }
230
+
231
+ function setItem(BytesItems memory items, uint256 index, string memory key, bytes[] memory value) internal pure {
232
+ items.arrayItems[index].key = key;
233
+ items.arrayItems[index].value = value;
234
+ }
235
+
236
+ function initItems(StringItems memory items, uint256 size) internal pure {
237
+ items.items = new EventUtils.StringKeyValue[](size);
238
+ }
239
+
240
+ function initArrayItems(StringItems memory items, uint256 size) internal pure {
241
+ items.arrayItems = new EventUtils.StringArrayKeyValue[](size);
242
+ }
243
+
244
+ function setItem(StringItems memory items, uint256 index, string memory key, string memory value) internal pure {
245
+ items.items[index].key = key;
246
+ items.items[index].value = value;
247
+ }
248
+
249
+ function setItem(StringItems memory items, uint256 index, string memory key, string[] memory value) internal pure {
250
+ items.arrayItems[index].key = key;
251
+ items.arrayItems[index].value = value;
252
+ }
253
+ }
@@ -0,0 +1,119 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./EventUtils.sol";
5
+
6
+ interface ICallbackReceiver {
7
+ // @dev there is a limit on the number of fields a struct can have when being passed
8
+ // or returned as a memory variable which can cause "Stack too deep" errors
9
+ // use sub-structs to avoid this issue
10
+ // @param addresses address values
11
+ // @param numbers number values
12
+ // @param flags boolean values
13
+ struct DepositProps {
14
+ DepositAddresses addresses;
15
+ DepositNumbers numbers;
16
+ Flags flags;
17
+ }
18
+
19
+ // @dev there is a limit on the number of fields a struct can have when being passed
20
+ // or returned as a memory variable which can cause "Stack too deep" errors
21
+ // use sub-structs to avoid this issue
22
+ // @param addresses address values
23
+ // @param numbers number values
24
+ // @param flags boolean values
25
+ struct WithdrawalProps {
26
+ WithdrawalAddresses addresses;
27
+ WithdrawalNumbers numbers;
28
+ Flags flags;
29
+ }
30
+
31
+ // @param account the account depositing liquidity
32
+ // @param receiver the address to send the liquidity tokens to
33
+ // @param callbackContract the callback contract
34
+ // @param uiFeeReceiver the ui fee receiver
35
+ // @param market the market to deposit to
36
+ struct DepositAddresses {
37
+ address account;
38
+ address receiver;
39
+ address callbackContract;
40
+ address uiFeeReceiver;
41
+ address market;
42
+ address initialLongToken;
43
+ address initialShortToken;
44
+ address[] longTokenSwapPath;
45
+ address[] shortTokenSwapPath;
46
+ }
47
+
48
+ // @param initialLongTokenAmount the amount of long tokens to deposit
49
+ // @param initialShortTokenAmount the amount of short tokens to deposit
50
+ // @param minMarketTokens the minimum acceptable number of liquidity tokens
51
+ // @param updatedAtBlock the block that the deposit was last updated at
52
+ // sending funds back to the user in case the deposit gets cancelled
53
+ // @param executionFee the execution fee for keepers
54
+ // @param callbackGasLimit the gas limit for the callbackContract
55
+ struct DepositNumbers {
56
+ uint256 initialLongTokenAmount;
57
+ uint256 initialShortTokenAmount;
58
+ uint256 minMarketTokens;
59
+ uint256 updatedAtBlock;
60
+ uint256 updatedAtTime;
61
+ uint256 executionFee;
62
+ uint256 callbackGasLimit;
63
+ }
64
+
65
+ // @param account The account to withdraw for.
66
+ // @param receiver The address that will receive the withdrawn tokens.
67
+ // @param callbackContract The contract that will be called back.
68
+ // @param uiFeeReceiver The ui fee receiver.
69
+ // @param market The market on which the withdrawal will be executed.
70
+ struct WithdrawalAddresses {
71
+ address account;
72
+ address receiver;
73
+ address callbackContract;
74
+ address uiFeeReceiver;
75
+ address market;
76
+ address[] longTokenSwapPath;
77
+ address[] shortTokenSwapPath;
78
+ }
79
+
80
+ // @param marketTokenAmount The amount of market tokens that will be withdrawn.
81
+ // @param minLongTokenAmount The minimum amount of long tokens that must be withdrawn.
82
+ // @param minShortTokenAmount The minimum amount of short tokens that must be withdrawn.
83
+ // @param updatedAtBlock The block at which the withdrawal was last updated.
84
+ // @param executionFee The execution fee for the withdrawal.
85
+ // @param callbackGasLimit The gas limit for calling the callback contract.
86
+ struct WithdrawalNumbers {
87
+ uint256 marketTokenAmount;
88
+ uint256 minLongTokenAmount;
89
+ uint256 minShortTokenAmount;
90
+ uint256 updatedAtBlock;
91
+ uint256 updatedAtTime;
92
+ uint256 executionFee;
93
+ uint256 callbackGasLimit;
94
+ }
95
+
96
+ // @param shouldUnwrapNativeToken whether to unwrap the native token when
97
+ struct Flags {
98
+ bool shouldUnwrapNativeToken;
99
+ }
100
+ // @dev called after a deposit execution
101
+ // @param key the key of the deposit
102
+ // @param deposit the deposit that was executed
103
+ function afterDepositExecution(bytes32 key, DepositProps memory deposit, EventUtils.EventLogData memory eventData) external;
104
+
105
+ // @dev called after a deposit cancellation
106
+ // @param key the key of the deposit
107
+ // @param deposit the deposit that was cancelled
108
+ function afterDepositCancellation(bytes32 key, DepositProps memory deposit, EventUtils.EventLogData memory eventData) external;
109
+
110
+ // @dev called after a withdrawal execution
111
+ // @param key the key of the withdrawal
112
+ // @param withdrawal the withdrawal that was executed
113
+ function afterWithdrawalExecution(bytes32 key, WithdrawalProps memory withdrawal, EventUtils.EventLogData memory eventData) external;
114
+
115
+ // @dev called after a withdrawal cancellation
116
+ // @param key the key of the withdrawal
117
+ // @param withdrawal the withdrawal that was cancelled
118
+ function afterWithdrawalCancellation(bytes32 key, WithdrawalProps memory withdrawal, EventUtils.EventLogData memory eventData) external;
119
+ }
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IDataStore {
5
+ function getAddress(bytes32 key) external view returns (address);
6
+ function getUint(bytes32 key) external view returns (uint256);
7
+ }
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IExchangeRouter {
5
+ struct CreateDepositParams {
6
+ address receiver;
7
+ address callbackContract;
8
+ address uiFeeReceiver;
9
+ address market;
10
+ address initialLongToken;
11
+ address initialShortToken;
12
+ address[] longTokenSwapPath;
13
+ address[] shortTokenSwapPath;
14
+ uint256 minMarketTokens;
15
+ bool shouldUnwrapNativeToken;
16
+ uint256 executionFee;
17
+ uint256 callbackGasLimit;
18
+ }
19
+ struct CreateWithdrawalParams {
20
+ address receiver;
21
+ address callbackContract;
22
+ address uiFeeReceiver;
23
+ address market;
24
+ address[] longTokenSwapPath;
25
+ address[] shortTokenSwapPath;
26
+ uint256 minLongTokenAmount;
27
+ uint256 minShortTokenAmount;
28
+ bool shouldUnwrapNativeToken;
29
+ uint256 executionFee;
30
+ uint256 callbackGasLimit;
31
+ }
32
+
33
+ function sendWnt(address receiver, uint256 amount) external payable;
34
+ function sendTokens(address token, address receiver, uint256 amount) external payable;
35
+ function createDeposit(CreateDepositParams calldata params) external payable returns (bytes32);
36
+ function createWithdrawal(CreateWithdrawalParams calldata params) external payable returns (bytes32);
37
+ function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
38
+ }
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IGMXViewer {
5
+ function getWithdrawalAmountOut(address market, uint256 amount, bool stalenessCheck) external view returns (uint256);
6
+ function getDepositAmountOut(address market, uint256 amount, bool stalenessCheck) external view returns (uint256);
7
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IHandler {
5
+ struct SetPricesParams {
6
+ address[] tokens;
7
+ address[] providers;
8
+ bytes[] data;
9
+ }
10
+ function executeDeposit(bytes32 key, SetPricesParams calldata oracleParams) external;
11
+ function executeWithdrawal(bytes32 key, SetPricesParams calldata oracleParams) external;
12
+ }
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IMarket {
5
+ function dataStore() external view returns (address);
6
+ function roleStore() external view returns (address);
7
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IOracle {
5
+ function getPriceFeedMultiplier(address dataStore, address token) external view returns (uint256);
6
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IPriceFeed {
5
+ function latestRoundData() external view returns (
6
+ uint80 roundId,
7
+ int256 answer,
8
+ uint256 startedAt,
9
+ uint256 updatedAt,
10
+ uint80 answeredInRound
11
+ );
12
+ }
@@ -0,0 +1,49 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./IMarket.sol";
5
+
6
+ interface IReader {
7
+ struct PriceProps {
8
+ uint256 min;
9
+ uint256 max;
10
+ }
11
+ struct MarketProps {
12
+ address marketToken;
13
+ address indexToken;
14
+ address longToken;
15
+ address shortToken;
16
+ }
17
+ struct MarketPrices {
18
+ PriceProps indexTokenPrice;
19
+ PriceProps longTokenPrice;
20
+ PriceProps shortTokenPrice;
21
+ }
22
+ enum SwapPricingType {
23
+ TwoStep,
24
+ Shift,
25
+ Atomic
26
+ }
27
+
28
+ function getMarket(address dataStore, address key) external view returns (MarketProps memory);
29
+
30
+ function getDepositAmountOut(
31
+ address dataStore,
32
+ MarketProps memory market,
33
+ MarketPrices memory prices,
34
+ uint256 longTokenAmount,
35
+ uint256 shortTokenAmount,
36
+ address uiFeeReceiver,
37
+ SwapPricingType swapPricingType,
38
+ bool includeVirtualInventoryImpact
39
+ ) external view returns (uint256);
40
+
41
+ function getWithdrawalAmountOut(
42
+ address dataStore,
43
+ MarketProps memory market,
44
+ MarketPrices memory prices,
45
+ uint256 marketTokenAmount,
46
+ address uiFeeReceiver,
47
+ SwapPricingType swapPricingType
48
+ ) external view returns (uint256, uint256);
49
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IRoleStore {
5
+ function hasRole(address account, bytes32 roleKey) external view returns (bool);
6
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ pragma solidity 0.8.26;
3
+
4
+ /// @title Errors in Ipor Fusion
5
+ library Errors {
6
+ /// @notice Error when wrong address is used
7
+ error WrongAddress();
8
+ /// @notice Error when wrong value is used
9
+ error WrongValue();
10
+ /// @notice Error when wrong decimals are used
11
+ error WrongDecimals();
12
+ /// @notice Error when wrong array length is used
13
+ error WrongArrayLength();
14
+ /// @notice Error when wrong caller is used
15
+ error WrongCaller(address caller);
16
+ /// @notice Error when wrong quote currency is used
17
+ error UnsupportedQuoteCurrencyFromOracle();
18
+ /// @notice Error when unsupported price oracle middleware is used
19
+ error UnsupportedPriceOracleMiddleware();
20
+ }
@@ -0,0 +1,71 @@
1
+
2
+ // SPDX-License-Identifier: BUSL-1.1
3
+ pragma solidity 0.8.26;
4
+
5
+ /// @title Fuses storage library responsible for managing storage fuses in the Plasma Vault
6
+ library FuseStorageLib {
7
+ /// @dev keccak256(abi.encode(uint256(keccak256("io.ipor.CfgFuses")) - 1)) & ~bytes32(uint256(0xff));
8
+ bytes32 private constant CFG_FUSES = 0x48932b860eb451ad240d4fe2b46522e5a0ac079d201fe50d4e0be078c75b5400;
9
+
10
+ /// @dev keccak256(abi.encode(uint256(keccak256("io.ipor.CfgFusesArray")) - 1)) & ~bytes32(uint256(0xff));
11
+ bytes32 private constant CFG_FUSES_ARRAY = 0xad43e358bd6e59a5a0c80f6bf25fa771408af4d80f621cdc680c8dfbf607ab00;
12
+
13
+ /// @notice This memory is designed to use with Uniswap V3 fuses
14
+ /// @dev keccak256(abi.encode(uint256(keccak256("io.ipor.UniswapV3TokenIds")) - 1)) & ~bytes32(uint256(0xff));
15
+ bytes32 private constant UNISWAP_V3_TOKEN_IDS = 0x3651659bd419f7c37743f3e14a337c9f9d1cfc4d650d91508f44d1acbe960f00;
16
+
17
+ /// @notice This memory is designed to use with Ramses V2 fuses
18
+ /// @dev keccak256(abi.encode(uint256(keccak256("io.ipor.RamsesV2TokenIds")) - 1)) & ~bytes32(uint256(0xff));
19
+ bytes32 private constant RAMSES_V2_TOKEN_IDS = 0x1a3831a406f27d4d5d820158b29ce95a1e8e840bf416921917aa388e2461b700;
20
+
21
+ /// @custom:storage-location erc7201:io.ipor.CfgFuses
22
+ struct Fuses {
23
+ /// @dev fuse address => If index = 0 - is not granted, otherwise - granted
24
+ mapping(address fuse => uint256 index) value;
25
+ }
26
+
27
+ /// @custom:storage-location erc7201:io.ipor.CfgFusesArray
28
+ struct FusesArray {
29
+ /// @dev value is a fuse address
30
+ address[] value;
31
+ }
32
+
33
+ /// @custom:storage-location erc7201:io.ipor.UniswapV3TokenIds
34
+ struct UniswapV3TokenIds {
35
+ uint256[] tokenIds;
36
+ mapping(uint256 tokenId => uint256 index) indexes;
37
+ }
38
+
39
+ /// @custom:storage-location erc7201:io.ipor.RamsesV2TokenIds
40
+ struct RamsesV2TokenIds {
41
+ uint256[] tokenIds;
42
+ mapping(uint256 tokenId => uint256 index) indexes;
43
+ }
44
+
45
+ /// @notice Gets the fuses storage pointer
46
+ function getFuses() internal pure returns (Fuses storage fuses) {
47
+ assembly {
48
+ fuses.slot := CFG_FUSES
49
+ }
50
+ }
51
+
52
+ /// @notice Gets the fuses array storage pointer
53
+ function getFusesArray() internal pure returns (FusesArray storage fusesArray) {
54
+ assembly {
55
+ fusesArray.slot := CFG_FUSES_ARRAY
56
+ }
57
+ }
58
+
59
+ /// @notice Gets the UniswapV3TokenIds storage pointer
60
+ function getUniswapV3TokenIds() internal pure returns (UniswapV3TokenIds storage uniswapV3TokenIds) {
61
+ assembly {
62
+ uniswapV3TokenIds.slot := UNISWAP_V3_TOKEN_IDS
63
+ }
64
+ }
65
+ /// @notice Gets the UniswapV3TokenIds storage pointer
66
+ function getRamsesV2TokenIds() internal pure returns (RamsesV2TokenIds storage ramsesV2TokenIds) {
67
+ assembly {
68
+ ramsesV2TokenIds.slot := RAMSES_V2_TOKEN_IDS
69
+ }
70
+ }
71
+ }