@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,304 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "@openzeppelin/contracts/utils/math/Math.sol";
5
+ import "@openzeppelin/contracts/utils/math/SafeMath.sol";
6
+ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7
+ import "../../base/upgradability/BaseUpgradeableStrategy.sol";
8
+ import "../../base/interface/IUniversalLiquidator.sol";
9
+ import "../../base/interface/gamma/IHypervisor.sol";
10
+ import "../../base/interface/gamma/IUniProxy.sol";
11
+ import "../../base/interface/gamma/IClearing.sol";
12
+ import "../../base/interface/IVault.sol";
13
+ import "../../base/interface/IPotPool.sol";
14
+
15
+ contract CamelotV3Strategy is BaseUpgradeableStrategy {
16
+
17
+ using SafeMath for uint256;
18
+ using SafeERC20 for IERC20;
19
+
20
+ address public constant xGrail = address(0x3CAaE25Ee616f2C8E13C74dA0813402eae3F496b);
21
+ address public constant harvestMSIG = address(0xf3D1A027E858976634F81B7c41B09A05A46EdA21);
22
+
23
+ // additional storage slots (on top of BaseUpgradeableStrategy ones) are defined here
24
+ bytes32 internal constant _XGRAIL_VAULT_SLOT = 0xd445aff5601e22e4f2e49f44eb54e33aa29670745d5241914b5369f65f9d43d0;
25
+ bytes32 internal constant _POTPOOL_SLOT = 0x7f4b50847e7d7a4da6a6ea36bfb188c77e9f093697337eb9a876744f926dd014;
26
+ bytes32 internal constant _UNIPROXY_SLOT = 0x09ff9720152edb4fad4ed05a0b77258f0fce17715f9397342eb08c8d7f965234;
27
+
28
+ // this would be reset on each upgrade
29
+ address[] public rewardTokens;
30
+
31
+ constructor() BaseUpgradeableStrategy() {
32
+ assert(_XGRAIL_VAULT_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.xGrailVault")) - 1));
33
+ assert(_POTPOOL_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.potPool")) - 1));
34
+ assert(_UNIPROXY_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.uniProxy")) - 1));
35
+ }
36
+
37
+ function initializeBaseStrategy(
38
+ address _storage,
39
+ address _underlying,
40
+ address _vault,
41
+ address _grail,
42
+ address _xGrailVault,
43
+ address _potPool,
44
+ address _uniProxy
45
+ ) public initializer {
46
+
47
+ BaseUpgradeableStrategy.initialize(
48
+ _storage,
49
+ _underlying,
50
+ _vault,
51
+ _underlying,
52
+ _grail,
53
+ harvestMSIG
54
+ );
55
+
56
+ setAddress(_XGRAIL_VAULT_SLOT, _xGrailVault);
57
+ setAddress(_POTPOOL_SLOT, _potPool);
58
+ setAddress(_UNIPROXY_SLOT, _uniProxy);
59
+ }
60
+
61
+ function depositArbCheck() public pure returns(bool) {
62
+ return true;
63
+ }
64
+
65
+ function unsalvagableTokens(address token) public view returns (bool) {
66
+ return (token == rewardToken() || token == underlying());
67
+ }
68
+
69
+ /*
70
+ * In case there are some issues discovered about the pool or underlying asset
71
+ * Governance can exit the pool properly
72
+ * The function is only used for emergency to exit the pool
73
+ */
74
+ function emergencyExit() public onlyGovernance {
75
+ _setPausedInvesting(true);
76
+ }
77
+
78
+ /*
79
+ * Resumes the ability to invest into the underlying reward pools
80
+ */
81
+
82
+ function continueInvesting() public onlyGovernance {
83
+ _setPausedInvesting(false);
84
+ }
85
+
86
+ function addRewardToken(address _token) public onlyGovernance {
87
+ rewardTokens.push(_token);
88
+ }
89
+
90
+ // We assume that all the tradings can be done on Uniswap
91
+ function _liquidateRewards(uint256 _xGrailAmount) internal {
92
+ if (!sell()) {
93
+ // Profits can be disabled for possible simplified and rapid exit
94
+ emit ProfitsNotCollected(sell(), false);
95
+ return;
96
+ }
97
+
98
+ address _rewardToken = rewardToken();
99
+ address _universalLiquidator = universalLiquidator();
100
+ for (uint256 i; i < rewardTokens.length; i++) {
101
+ address token = rewardTokens[i];
102
+ uint256 balance = IERC20(token).balanceOf(address(this));
103
+ if (balance == 0) {
104
+ continue;
105
+ }
106
+ if (token != _rewardToken){
107
+ IERC20(token).safeApprove(_universalLiquidator, 0);
108
+ IERC20(token).safeApprove(_universalLiquidator, balance);
109
+ IUniversalLiquidator(_universalLiquidator).swap(token, _rewardToken, balance, 1, address(this));
110
+ }
111
+ }
112
+
113
+ uint256 rewardBalance = IERC20(_rewardToken).balanceOf(address(this));
114
+ uint256 notifyBalance;
115
+ if (_xGrailAmount > rewardBalance.mul(9)) {
116
+ notifyBalance = rewardBalance.mul(10);
117
+ } else {
118
+ notifyBalance = rewardBalance.add(_xGrailAmount);
119
+ }
120
+ _notifyProfitInRewardToken(_rewardToken, notifyBalance);
121
+ uint256 remainingRewardBalance = IERC20(_rewardToken).balanceOf(address(this));
122
+
123
+ if (remainingRewardBalance < 1e6) {
124
+ _handleXGrail();
125
+ return;
126
+ }
127
+
128
+ _depositToGamma();
129
+ _handleXGrail();
130
+ }
131
+
132
+ function _handleXGrail() internal {
133
+ uint256 balance = IERC20(xGrail).balanceOf(address(this));
134
+ if (balance == 0) { return; }
135
+ address _xGrailVault = xGrailVault();
136
+ address _potPool = potPool();
137
+
138
+ IERC20(xGrail).safeApprove(_xGrailVault, 0);
139
+ IERC20(xGrail).safeApprove(_xGrailVault, balance);
140
+ IVault(_xGrailVault).deposit(balance);
141
+
142
+ uint256 vaultBalance = IERC20(_xGrailVault).balanceOf(address(this));
143
+ IERC20(_xGrailVault).safeTransfer(_potPool, vaultBalance);
144
+ IPotPool(_potPool).notifyTargetRewardAmount(_xGrailVault, vaultBalance);
145
+ }
146
+
147
+ function _depositToGamma() internal {
148
+ address _underlying = underlying();
149
+ address _clearing = IUniProxy(uniProxy()).clearance();
150
+ address _token0 = IHypervisor(_underlying).token0();
151
+ address _token1 = IHypervisor(_underlying).token1();
152
+ (uint256 toToken0, uint256 toToken1) = _calculateToTokenAmounts();
153
+ (uint256 amount0, uint256 amount1) = _swapToTokens(_token0, _token1, toToken0, toToken1);
154
+ (uint256 min1, uint256 max1) = IClearing(_clearing).getDepositAmount(_underlying, _token0, amount0);
155
+ if (amount1 < min1) {
156
+ (,uint256 max0) = IClearing(_clearing).getDepositAmount(_underlying, _token1, amount1);
157
+ if (amount0 > max0) {
158
+ amount0 = max0;
159
+ }
160
+ } else if (amount1 > max1) {
161
+ amount1 = max1;
162
+ }
163
+ uint256[4] memory minIn = [uint(0), uint(0), uint(0), uint(0)];
164
+
165
+ IERC20(_token0).safeApprove(_underlying, 0);
166
+ IERC20(_token0).safeApprove(_underlying, amount0);
167
+ IERC20(_token1).safeApprove(_underlying, 0);
168
+ IERC20(_token1).safeApprove(_underlying, amount1);
169
+ IUniProxy(uniProxy()).deposit(amount0, amount1, address(this), _underlying, minIn);
170
+ }
171
+
172
+ function _calculateToTokenAmounts() internal view returns(uint256, uint256){
173
+ address pool = underlying();
174
+ (uint256 poolBalance0, uint256 poolBalance1) = IHypervisor(pool).getTotalAmounts();
175
+ address clearing = IUniProxy(uniProxy()).clearance();
176
+ uint256 sqrtPrice0In1 = uint256(IClearing(clearing).getSqrtTwapX96(pool, 1));
177
+ uint256 price0In1 = sqrtPrice0In1.mul(sqrtPrice0In1).div(uint(2**(96 * 2)).div(1e18));
178
+ uint256 totalPoolBalanceIn1 = poolBalance0.mul(price0In1).div(1e18).add(poolBalance1);
179
+ uint256 poolWeight0 = poolBalance0.mul(price0In1).div(totalPoolBalanceIn1);
180
+
181
+ uint256 rewardBalance = IERC20(rewardToken()).balanceOf(address(this));
182
+ uint256 toToken0 = rewardBalance.mul(poolWeight0).div(1e18);
183
+ uint256 toToken1 = rewardBalance.sub(toToken0);
184
+ return (toToken0, toToken1);
185
+ }
186
+
187
+ function _swapToTokens(
188
+ address tokenOut0,
189
+ address tokenOut1,
190
+ uint256 toToken0,
191
+ uint256 toToken1
192
+ ) internal returns(uint256, uint256){
193
+ address tokenIn = rewardToken();
194
+ address _universalLiquidator = universalLiquidator();
195
+ uint256 token0Amount;
196
+ if (tokenIn != tokenOut0){
197
+ IERC20(tokenIn).safeApprove(_universalLiquidator, 0);
198
+ IERC20(tokenIn).safeApprove(_universalLiquidator, toToken0);
199
+ IUniversalLiquidator(_universalLiquidator).swap(tokenIn, tokenOut0, toToken0, 1, address(this));
200
+ token0Amount = IERC20(tokenOut0).balanceOf(address(this));
201
+ } else {
202
+ // otherwise we assme token0 is the reward token itself
203
+ token0Amount = toToken0;
204
+ }
205
+
206
+ uint256 token1Amount;
207
+ if (tokenIn != tokenOut1){
208
+ IERC20(tokenIn).safeApprove(_universalLiquidator, 0);
209
+ IERC20(tokenIn).safeApprove(_universalLiquidator, toToken1);
210
+ IUniversalLiquidator(_universalLiquidator).swap(tokenIn, tokenOut1, toToken1, 1, address(this));
211
+ token1Amount = IERC20(tokenOut1).balanceOf(address(this));
212
+ } else {
213
+ // otherwise we assme token0 is the reward token itself
214
+ token1Amount = toToken1;
215
+ }
216
+ return (token0Amount, token1Amount);
217
+ }
218
+
219
+ /*
220
+ * Withdraws all the asset to the vault
221
+ */
222
+ function withdrawAllToVault() public restricted {
223
+ address _underlying = underlying();
224
+ uint256 xGrailReward = IERC20(xGrail).balanceOf(address(this));
225
+ _liquidateRewards(xGrailReward);
226
+ IERC20(_underlying).safeTransfer(vault(), IERC20(_underlying).balanceOf(address(this)));
227
+ }
228
+
229
+ /*
230
+ * Withdraws all the asset to the vault
231
+ */
232
+ function withdrawToVault(uint256 amount) public restricted {
233
+ IERC20(underlying()).safeTransfer(vault(), amount);
234
+ }
235
+
236
+ /*
237
+ * Note that we currently do not have a mechanism here to include the
238
+ * amount of reward that is accrued.
239
+ */
240
+ function investedUnderlyingBalance() external view returns (uint256) {
241
+ return IERC20(underlying()).balanceOf(address(this));
242
+ }
243
+
244
+ /*
245
+ * Governance or Controller can claim coins that are somehow transferred into the contract
246
+ * Note that they cannot come in take away coins that are used and defined in the strategy itself
247
+ */
248
+ function salvage(address recipient, address token, uint256 amount) external onlyControllerOrGovernance {
249
+ // To make sure that governance cannot come in and take away the coins
250
+ require(!unsalvagableTokens(token), "token is defined as not salvagable");
251
+ IERC20(token).safeTransfer(recipient, amount);
252
+ }
253
+
254
+ /*
255
+ * Get the reward, sell it in exchange for underlying, invest what you got.
256
+ * It's not much, but it's honest work.
257
+ *
258
+ * Note that although `onlyNotPausedInvesting` is not added here,
259
+ * calling `investAllUnderlying()` affectively blocks the usage of `doHardWork`
260
+ * when the investing is being paused by governance.
261
+ */
262
+ function doHardWork() external onlyNotPausedInvesting restricted {
263
+ uint256 xGrailReward = IERC20(xGrail).balanceOf(address(this));
264
+ _liquidateRewards(xGrailReward);
265
+ }
266
+
267
+ /**
268
+ * Can completely disable claiming rewards and selling. Good for emergency withdraw in the
269
+ * simplest possible way.
270
+ */
271
+ function setSell(bool s) public onlyGovernance {
272
+ _setSell(s);
273
+ }
274
+
275
+ function setXGrailVault(address _value) public onlyGovernance {
276
+ require(xGrailVault() == address(0), "Hodl vault already set");
277
+ setAddress(_XGRAIL_VAULT_SLOT, _value);
278
+ }
279
+
280
+ function xGrailVault() public view returns (address) {
281
+ return getAddress(_XGRAIL_VAULT_SLOT);
282
+ }
283
+
284
+ function setPotPool(address _value) public onlyGovernance {
285
+ require(potPool() == address(0), "PotPool already set");
286
+ setAddress(_POTPOOL_SLOT, _value);
287
+ }
288
+
289
+ function potPool() public view returns (address) {
290
+ return getAddress(_POTPOOL_SLOT);
291
+ }
292
+
293
+ function _setUniProxy(address _value) public onlyGovernance {
294
+ setAddress(_UNIPROXY_SLOT, _value);
295
+ }
296
+
297
+ function uniProxy() public view returns (address) {
298
+ return getAddress(_UNIPROXY_SLOT);
299
+ }
300
+
301
+ function finalizeUpgrade() external onlyGovernance {
302
+ _finalizeUpgrade();
303
+ }
304
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_ARB_USDC is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0x29237292F15BC3615BFCc0D958C265Aa64527FB2);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_ETH_USDC is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0xd7Ef5Ac7fd4AAA7994F3bc1D273eAb1d1013530E);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_ETH_USDT is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0x9330e26b5Fc0b7c417C6bD901528d5c65BE5cdf2);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_GMX_ETH is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0x9bdb8335619bA4E20Bea1321f8E32f45fD6e6e22);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_GRAIL_ETH is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0x97D81162B96D57476CcF170595a39c1DC76676c9);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_USDC_USDT is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0xf662d78C79F6a3a6Fa70160fcE1085A9218D114e);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+
2
+ //SPDX-License-Identifier: Unlicense
3
+ pragma solidity 0.8.26;
4
+
5
+ import "./CamelotV3Strategy.sol";
6
+
7
+ contract CamelotV3StrategyMainnet_WBTC_ETH is CamelotV3Strategy {
8
+
9
+ constructor() {}
10
+
11
+ function initializeStrategy(
12
+ address _storage,
13
+ address _vault
14
+ ) public initializer {
15
+ address underlying = address(0x56c87c3892d3917895bAe1A4cAcf6ea23a4DB84d);
16
+ address grail = address(0x3d9907F9a368ad0a51Be60f7Da3b97cf940982D8);
17
+ CamelotV3Strategy.initializeBaseStrategy(
18
+ _storage,
19
+ underlying,
20
+ _vault,
21
+ grail,
22
+ address(0xFA10759780304c2B8d34B051C039899dFBbcad7f),
23
+ address(0),
24
+ address(0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E) //UniProxy
25
+ );
26
+ rewardTokens = [grail];
27
+ }
28
+ }