@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,403 @@
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 "@openzeppelin/contracts/token/ERC20/ERC20.sol";
8
+ import "../../base/interface/IUniversalLiquidator.sol";
9
+ import "../../base/upgradability/BaseUpgradeableStrategy.sol";
10
+ import "../../base/interface/balancer/IBVault.sol";
11
+ import "../../base/interface/balancer/IGyroPool.sol";
12
+ import "../../base/interface/aura/IAuraBooster.sol";
13
+ import "../../base/interface/aura/IAuraBaseRewardPool.sol";
14
+
15
+ import "hardhat/console.sol";
16
+
17
+ contract AuraStrategy is BaseUpgradeableStrategy {
18
+
19
+ using SafeMath for uint256;
20
+ using SafeERC20 for IERC20;
21
+
22
+ address public constant weth = address(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1);
23
+ address public constant harvestMSIG = address(0xf3D1A027E858976634F81B7c41B09A05A46EdA21);
24
+ address public constant bVault = address(0xBA12222222228d8Ba445958a75a0704d566BF2C8);
25
+ address public constant booster = address(0x98Ef32edd24e2c92525E59afc4475C1242a30184);
26
+
27
+ // additional storage slots (on top of BaseUpgradeableStrategy ones) are defined here
28
+ bytes32 internal constant _AURA_POOLID_SLOT = 0xbc10a276e435b4e9a9e92986f93a224a34b50c1898d7551c38ef30a08efadec4;
29
+ bytes32 internal constant _BALANCER_POOLID_SLOT = 0xbf3f653715dd45c84a3367d2975f271307cb967d6ce603dc4f0def2ad909ca64;
30
+ bytes32 internal constant _DEPOSIT_TOKEN_SLOT = 0x219270253dbc530471c88a9e7c321b36afda219583431e7b6c386d2d46e70c86;
31
+ bytes32 internal constant _GYRO_POOL_SLOT = 0xf0b0faebb2d15ab4125ed190c9e3f2c678e7706246396073a319fa77463a0455;
32
+
33
+ // this would be reset on each upgrade
34
+ address[] public rewardTokens;
35
+
36
+ constructor() BaseUpgradeableStrategy() {
37
+ assert(_AURA_POOLID_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.auraPoolId")) - 1));
38
+ assert(_BALANCER_POOLID_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.balancerPoolId")) - 1));
39
+ assert(_DEPOSIT_TOKEN_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.depositToken")) - 1));
40
+ assert(_GYRO_POOL_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.gyroPool")) - 1));
41
+ }
42
+
43
+ function initializeBaseStrategy(
44
+ address _storage,
45
+ address _underlying,
46
+ address _vault,
47
+ address _rewardPool,
48
+ bytes32 _balancerPoolID,
49
+ uint256 _auraPoolID,
50
+ address _depositToken,
51
+ bool _gyroPool
52
+ ) public initializer {
53
+
54
+ BaseUpgradeableStrategy.initialize(
55
+ _storage,
56
+ _underlying,
57
+ _vault,
58
+ _rewardPool,
59
+ weth,
60
+ harvestMSIG
61
+ );
62
+
63
+ (address _lpt,) = IBVault(bVault).getPool(_balancerPoolID);
64
+ require(_lpt == _underlying, "Underlying mismatch");
65
+ (_lpt,,,,,) = IAuraBooster(booster).poolInfo(_auraPoolID);
66
+ require(_lpt == underlying(), "Pool Info does not match underlying");
67
+
68
+ _setAuraPoolId(_auraPoolID);
69
+ _setBalancerPoolId(_balancerPoolID);
70
+ _setDepositToken(_depositToken);
71
+ _setGyroPool(_gyroPool);
72
+ }
73
+
74
+ function depositArbCheck() public pure returns(bool) {
75
+ return true;
76
+ }
77
+
78
+ function _rewardPoolBalance() internal view returns (uint256 balance) {
79
+ balance = IAuraBaseRewardPool(rewardPool()).balanceOf(address(this));
80
+ }
81
+
82
+ function _emergencyExitRewardPool() internal {
83
+ uint256 stakedBalance = _rewardPoolBalance();
84
+ if (stakedBalance != 0) {
85
+ IAuraBaseRewardPool(rewardPool()).withdrawAllAndUnwrap(false); //don't claim rewards
86
+ }
87
+ }
88
+
89
+ function _partialWithdrawalRewardPool(uint256 amount) internal {
90
+ IAuraBaseRewardPool(rewardPool()).withdrawAndUnwrap(amount, false); //don't claim rewards at this point
91
+ }
92
+
93
+ function _exitRewardPool() internal {
94
+ uint256 stakedBalance = _rewardPoolBalance();
95
+ if (stakedBalance != 0) {
96
+ IAuraBaseRewardPool(rewardPool()).withdrawAllAndUnwrap(true);
97
+ }
98
+ }
99
+
100
+ function _enterRewardPool() internal {
101
+ address underlying_ = underlying();
102
+ uint256 entireBalance = IERC20(underlying_).balanceOf(address(this));
103
+ IERC20(underlying_).safeApprove(booster, 0);
104
+ IERC20(underlying_).safeApprove(booster, entireBalance);
105
+ IAuraBooster(booster).depositAll(auraPoolId(), true); //deposit and stake
106
+ }
107
+
108
+ function _investAllUnderlying() internal onlyNotPausedInvesting {
109
+ if(IERC20(underlying()).balanceOf(address(this)) > 0) {
110
+ _enterRewardPool();
111
+ }
112
+ }
113
+
114
+ /*
115
+ * In case there are some issues discovered about the pool or underlying asset
116
+ * Governance can exit the pool properly
117
+ * The function is only used for emergency to exit the pool
118
+ */
119
+ function emergencyExit() public onlyGovernance {
120
+ _emergencyExitRewardPool();
121
+ _setPausedInvesting(true);
122
+ }
123
+
124
+ /*
125
+ * Resumes the ability to invest into the underlying reward pools
126
+ */
127
+ function continueInvesting() public onlyGovernance {
128
+ _setPausedInvesting(false);
129
+ }
130
+
131
+ function unsalvagableTokens(address token) public view returns (bool) {
132
+ return (token == rewardToken() || token == underlying());
133
+ }
134
+
135
+ function addRewardToken(address _token) public onlyGovernance {
136
+ rewardTokens.push(_token);
137
+ }
138
+
139
+ function changeDepositToken(address _depositToken) public onlyGovernance {
140
+ _setDepositToken(_depositToken);
141
+ }
142
+
143
+ function _approveIfNeed(address token, address spender, uint256 amount) internal {
144
+ uint256 allowance = IERC20(token).allowance(address(this), spender);
145
+ if (amount > allowance) {
146
+ IERC20(token).safeApprove(spender, 0);
147
+ IERC20(token).safeApprove(spender, amount);
148
+ }
149
+ }
150
+
151
+ function _balancerDeposit(
152
+ address tokenIn,
153
+ bytes32 poolId,
154
+ uint256 amountIn,
155
+ uint256 minAmountOut,
156
+ bool gyroPool
157
+ ) internal {
158
+ (address[] memory poolTokens, uint256[] memory poolBalances,) = IBVault(bVault).getPoolTokens(poolId);
159
+ uint256 _nTokens = poolTokens.length;
160
+
161
+ IAsset[] memory assets = new IAsset[](_nTokens);
162
+ uint256[] memory amountsIn = new uint256[](_nTokens);
163
+ bytes memory userData;
164
+ if (gyroPool) {
165
+ (uint256 amount0, uint256 amount1, uint256 exactAmountOut) = _getGyroAmounts(tokenIn, amountIn, poolTokens, poolBalances);
166
+ for (uint256 i = 0; i < _nTokens; i++) {
167
+ assets[i] = IAsset(poolTokens[i]);
168
+ }
169
+ amountsIn[0] = amount0;
170
+ amountsIn[1] = amount1;
171
+ IBVault.JoinKind joinKind = IBVault.JoinKind.ALL_TOKENS_IN_FOR_EXACT_BPT_OUT;
172
+
173
+ userData = abi.encode(joinKind, exactAmountOut);
174
+ _approveIfNeed(poolTokens[0], bVault, amount0);
175
+ _approveIfNeed(poolTokens[1], bVault, amount1);
176
+ } else {
177
+ for (uint256 i = 0; i < _nTokens; i++) {
178
+ assets[i] = IAsset(poolTokens[i]);
179
+ amountsIn[i] = poolTokens[i] == tokenIn ? amountIn : 0;
180
+ }
181
+ IBVault.JoinKind joinKind = IBVault.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT;
182
+ userData = abi.encode(joinKind, amountsIn, minAmountOut);
183
+ _approveIfNeed(tokenIn, bVault, amountIn);
184
+ }
185
+
186
+ IBVault.JoinPoolRequest memory request;
187
+ request.assets = assets;
188
+ request.maxAmountsIn = amountsIn;
189
+ request.userData = userData;
190
+ request.fromInternalBalance = false;
191
+
192
+ IBVault(bVault).joinPool(
193
+ poolId,
194
+ address(this),
195
+ address(this),
196
+ request
197
+ );
198
+ }
199
+
200
+ function _getGyroAmounts(
201
+ address tokenIn,
202
+ uint256 amountIn,
203
+ address[] memory poolTokens,
204
+ uint256[] memory poolBalances
205
+ ) internal returns(uint256 amount0, uint256 amount1, uint256 amountOut) {
206
+ address _universalLiquidator = universalLiquidator();
207
+ address _underlying = underlying();
208
+
209
+ uint256 token0Weight;
210
+ uint256 token1Weight;
211
+ {
212
+ uint256 token0Decimals = ERC20(poolTokens[0]).decimals();
213
+ uint256 token1Decimals = ERC20(poolTokens[1]).decimals();
214
+ uint256 normalisedBalance0 = poolBalances[0].mul(1e18).div(10**token0Decimals);
215
+ uint256 normalisedBalance1 = poolBalances[1].mul(1e18).div(10**token1Decimals);
216
+ uint256 totalPoolBalanceIn1 = normalisedBalance0.mul(IGyroPool(_underlying).getPrice()).div(1e18).add(normalisedBalance1);
217
+ token0Weight = normalisedBalance0.mul(IGyroPool(_underlying).getPrice()).div(totalPoolBalanceIn1);
218
+ token1Weight = normalisedBalance1.mul(1e18).div(totalPoolBalanceIn1);
219
+ }
220
+
221
+ if (tokenIn == poolTokens[0]) {
222
+ uint256 swapAmount = amountIn.mul(token1Weight).div(1e18);
223
+ IERC20(tokenIn).safeApprove(_universalLiquidator, 0);
224
+ IERC20(tokenIn).safeApprove(_universalLiquidator, swapAmount);
225
+ IUniversalLiquidator(_universalLiquidator).swap(tokenIn, poolTokens[1], swapAmount, 1, address(this));
226
+ } else {
227
+ uint256 swapAmount = amountIn.mul(token0Weight).div(1e18);
228
+ IERC20(tokenIn).safeApprove(_universalLiquidator, 0);
229
+ IERC20(tokenIn).safeApprove(_universalLiquidator, swapAmount);
230
+ IUniversalLiquidator(_universalLiquidator).swap(tokenIn, poolTokens[0], swapAmount, 1, address(this));
231
+ }
232
+
233
+ (,poolBalances,) = IBVault(bVault).getPoolTokens(balancerPoolId());
234
+
235
+ uint256 balance0 = IERC20(poolTokens[0]).balanceOf(address(this));
236
+ uint256 balance1 = IERC20(poolTokens[1]).balanceOf(address(this));
237
+ uint256 amountOut0 = balance0.mul(IGyroPool(_underlying).getActualSupply()).div(poolBalances[0]);
238
+ uint256 amountOut1 = balance1.mul(IGyroPool(_underlying).getActualSupply()).div(poolBalances[1]);
239
+
240
+ return(balance0, balance1, Math.min(amountOut0, amountOut1).mul(9999).div(10000));
241
+ }
242
+
243
+ function _liquidateReward() internal {
244
+ if (!sell()) {
245
+ // Profits can be disabled for possible simplified and rapid exit
246
+ emit ProfitsNotCollected(sell(), false);
247
+ return;
248
+ }
249
+ address _rewardToken = rewardToken();
250
+ address _universalLiquidator = universalLiquidator();
251
+ for(uint256 i = 0; i < rewardTokens.length; i++){
252
+ address token = rewardTokens[i];
253
+ uint256 rewardBalance = IERC20(token).balanceOf(address(this));
254
+ if (rewardBalance == 0) {
255
+ continue;
256
+ }
257
+ if (token != _rewardToken){
258
+ IERC20(token).safeApprove(_universalLiquidator, 0);
259
+ IERC20(token).safeApprove(_universalLiquidator, rewardBalance);
260
+ IUniversalLiquidator(_universalLiquidator).swap(token, _rewardToken, rewardBalance, 1, address(this));
261
+ }
262
+ }
263
+
264
+ uint256 rewardBalance = IERC20(_rewardToken).balanceOf(address(this));
265
+ _notifyProfitInRewardToken(_rewardToken, rewardBalance);
266
+ uint256 remainingRewardBalance = IERC20(_rewardToken).balanceOf(address(this));
267
+
268
+ if (remainingRewardBalance == 0) {
269
+ return;
270
+ }
271
+
272
+ address _depositToken = depositToken();
273
+ if (_depositToken != _rewardToken) {
274
+ IERC20(_rewardToken).safeApprove(_universalLiquidator, 0);
275
+ IERC20(_rewardToken).safeApprove(_universalLiquidator, remainingRewardBalance);
276
+ IUniversalLiquidator(_universalLiquidator).swap(_rewardToken, _depositToken, remainingRewardBalance, 1, address(this));
277
+ }
278
+
279
+ uint256 tokenBalance = IERC20(_depositToken).balanceOf(address(this));
280
+ if (tokenBalance > 0 && !(_depositToken == underlying())) {
281
+ _balancerDeposit(
282
+ _depositToken,
283
+ balancerPoolId(),
284
+ tokenBalance,
285
+ 1,
286
+ gyroPool()
287
+ );
288
+ }
289
+ }
290
+
291
+ /** Withdraws all the asset to the vault
292
+ */
293
+ function withdrawAllToVault() public restricted {
294
+ address _underlying = underlying();
295
+ _exitRewardPool();
296
+ _liquidateReward();
297
+ IERC20(_underlying).safeTransfer(vault(), IERC20(_underlying).balanceOf(address(this)));
298
+ }
299
+
300
+ /** Withdraws specific amount of asset to the vault
301
+ */
302
+ function withdrawToVault(uint256 amount) public restricted {
303
+ address _underlying = underlying();
304
+ // Typically there wouldn't be any amount here
305
+ // however, it is possible because of the emergencyExit
306
+ uint256 entireBalance = IERC20(_underlying).balanceOf(address(this));
307
+
308
+ if(amount > entireBalance){
309
+ // While we have the check above, we still using SafeMath below
310
+ // for the peace of mind (in case something gets changed in between)
311
+ uint256 needToWithdraw = amount.sub(entireBalance);
312
+ uint256 toWithdraw = Math.min(_rewardPoolBalance(), needToWithdraw);
313
+ _partialWithdrawalRewardPool(toWithdraw);
314
+ }
315
+ IERC20(_underlying).safeTransfer(vault(), amount);
316
+ }
317
+
318
+ /*
319
+ * Note that we currently do not have a mechanism here to include the
320
+ * amount of reward that is accrued.
321
+ */
322
+ function investedUnderlyingBalance() external view returns (uint256) {
323
+ // Adding the amount locked in the reward pool and the amount that is somehow in this contract
324
+ // both are in the units of "underlying"
325
+ // The second part is needed because there is the emergency exit mechanism
326
+ // which would break the assumption that all the funds are always inside of the reward pool
327
+ return _rewardPoolBalance().add(IERC20(underlying()).balanceOf(address(this)));
328
+ }
329
+
330
+ /*
331
+ * Governance or Controller can claim coins that are somehow transferred into the contract
332
+ * Note that they cannot come in take away coins that are used and defined in the strategy itself
333
+ */
334
+ function salvage(address recipient, address token, uint256 amount) external onlyControllerOrGovernance {
335
+ // To make sure that governance cannot come in and take away the coins
336
+ require(!unsalvagableTokens(token), "token is defined as not salvagable");
337
+ IERC20(token).safeTransfer(recipient, amount);
338
+ }
339
+
340
+ /*
341
+ * Get the reward, sell it in exchange for underlying, invest what you got.
342
+ * It's not much, but it's honest work.
343
+ *
344
+ * Note that although `onlyNotPausedInvesting` is not added here,
345
+ * calling `investAllUnderlying()` affectively blocks the usage of `doHardWork`
346
+ * when the investing is being paused by governance.
347
+ */
348
+ function doHardWork() external onlyNotPausedInvesting restricted {
349
+ IAuraBaseRewardPool(rewardPool()).getReward();
350
+ _liquidateReward();
351
+ _investAllUnderlying();
352
+ }
353
+
354
+ /**
355
+ * Can completely disable claiming UNI rewards and selling. Good for emergency withdraw in the
356
+ * simplest possible way.
357
+ */
358
+ function setSell(bool s) public onlyGovernance {
359
+ _setSell(s);
360
+ }
361
+
362
+ /** Aura deposit pool ID
363
+ */
364
+ function _setAuraPoolId(uint256 _value) internal {
365
+ setUint256(_AURA_POOLID_SLOT, _value);
366
+ }
367
+
368
+ /** Balancer deposit pool ID
369
+ */
370
+ function _setBalancerPoolId(bytes32 _value) internal {
371
+ setBytes32(_BALANCER_POOLID_SLOT, _value);
372
+ }
373
+
374
+ function auraPoolId() public view returns (uint256) {
375
+ return getUint256(_AURA_POOLID_SLOT);
376
+ }
377
+
378
+ function balancerPoolId() public view returns (bytes32) {
379
+ return getBytes32(_BALANCER_POOLID_SLOT);
380
+ }
381
+
382
+ function _setDepositToken(address _address) internal {
383
+ setAddress(_DEPOSIT_TOKEN_SLOT, _address);
384
+ }
385
+
386
+ function depositToken() public view returns (address) {
387
+ return getAddress(_DEPOSIT_TOKEN_SLOT);
388
+ }
389
+
390
+ function _setGyroPool(bool _value) internal {
391
+ setBoolean(_GYRO_POOL_SLOT, _value);
392
+ }
393
+
394
+ function gyroPool() public view returns (bool) {
395
+ return getBoolean(_GYRO_POOL_SLOT);
396
+ }
397
+
398
+ function finalizeUpgrade() external onlyGovernance {
399
+ _finalizeUpgrade();
400
+ }
401
+
402
+ receive() external payable {} // this is needed for the receiving Matic
403
+ }
@@ -0,0 +1,32 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_MORE_GYD is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0x4284c68f567903537E2d9Ff726fdF8591E431DDC);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address usdc = address(0xaf88d065e77c8cC2239327C5EDb3A432268e5831);
18
+ address gyd = address(0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8);
19
+ address rewardPool = address(0x159e8E79b63f345461613c97c58B21509287f647);
20
+ AuraStrategy.initializeBaseStrategy(
21
+ _storage,
22
+ underlying,
23
+ _vault,
24
+ rewardPool,
25
+ 0x4284c68f567903537e2d9ff726fdf8591e431ddc0002000000000000000005b5, // Balancer Pool id
26
+ 90, // Aura Pool id
27
+ gyd, // depositToken
28
+ true // gyroPool
29
+ );
30
+ rewardTokens = [aura, bal, usdc];
31
+ }
32
+ }
@@ -0,0 +1,31 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_sUSDe_GYD is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0xdeEaF8B0A8Cf26217261b813e085418C7dD8F1eE);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address gyd = address(0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8);
18
+ address rewardPool = address(0x2d7cFe43BcDf10137924a20445B763Fb40E5871c);
19
+ AuraStrategy.initializeBaseStrategy(
20
+ _storage,
21
+ underlying,
22
+ _vault,
23
+ rewardPool,
24
+ 0xdeeaf8b0a8cf26217261b813e085418c7dd8f1ee00020000000000000000058f, // Balancer Pool id
25
+ 82, // Aura Pool id
26
+ gyd, // depositToken
27
+ true // gyroPool
28
+ );
29
+ rewardTokens = [aura, bal];
30
+ }
31
+ }
@@ -0,0 +1,31 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_waFRAX_sFRAX is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0x36C2f879f446c3b6533f9703745C0504f3a84885);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address sFrax = address(0xe3b3FE7bcA19cA77Ad877A5Bebab186bEcfAD906);
18
+ address rewardPool = address(0xE6940b5FF5C0b4A09576667c7F71953a200e666A);
19
+ AuraStrategy.initializeBaseStrategy(
20
+ _storage,
21
+ underlying,
22
+ _vault,
23
+ rewardPool,
24
+ 0x36c2f879f446c3b6533f9703745c0504f3a84885000200000000000000000591, // Balancer Pool id
25
+ 81, // Aura Pool id
26
+ sFrax, // depositToken
27
+ true // gyroPool
28
+ );
29
+ rewardTokens = [aura, bal];
30
+ }
31
+ }
@@ -0,0 +1,31 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_waGHO_GYD is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0xff38cC0cE0DE4476C5a3e78675b48420A851035B);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address gyd = address(0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8);
18
+ address rewardPool = address(0x005DF7aC723E45Af4d7475A612a02f0565Eb3778);
19
+ AuraStrategy.initializeBaseStrategy(
20
+ _storage,
21
+ underlying,
22
+ _vault,
23
+ rewardPool,
24
+ 0xff38cc0ce0de4476c5a3e78675b48420a851035b000200000000000000000593, // Balancer Pool id
25
+ 86, // Aura Pool id
26
+ gyd, // depositToken
27
+ true // gyroPool
28
+ );
29
+ rewardTokens = [aura, bal];
30
+ }
31
+ }
@@ -0,0 +1,32 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_waUSDC_GHO is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0x46472CBA35E6800012aA9fcC7939Ff07478C473E);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address gho = address(0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33);
18
+ address arb = address(0x912CE59144191C1204E64559FE8253a0e49E6548);
19
+ address rewardPool = address(0xe48D1173EE577c1daE45C9CD2D29BD3DfaF02BD6);
20
+ AuraStrategy.initializeBaseStrategy(
21
+ _storage,
22
+ underlying,
23
+ _vault,
24
+ rewardPool,
25
+ 0x46472cba35e6800012aa9fcc7939ff07478c473e00020000000000000000056c, // Balancer Pool id
26
+ 69, // Aura Pool id
27
+ gho, // depositToken
28
+ true // gyroPool
29
+ );
30
+ rewardTokens = [aura, bal, gho, arb];
31
+ }
32
+ }
@@ -0,0 +1,31 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_waUSDC_GYD is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0x6e822c64c00393b2078f2a5BB75c575aB505B55c);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address gyd = address(0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8);
18
+ address rewardPool = address(0x78118Bc631b0eb2FB6A350f12e0334535783e49F);
19
+ AuraStrategy.initializeBaseStrategy(
20
+ _storage,
21
+ underlying,
22
+ _vault,
23
+ rewardPool,
24
+ 0x6e822c64c00393b2078f2a5bb75c575ab505b55c000200000000000000000548, // Balancer Pool id
25
+ 74, // Aura Pool id
26
+ gyd, // depositToken
27
+ true // gyroPool
28
+ );
29
+ rewardTokens = [aura, bal];
30
+ }
31
+ }
@@ -0,0 +1,31 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_waUSDT_GYD is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0x7272163A931DaC5BBe1CB5feFaF959BB65F7346F);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address gyd = address(0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8);
18
+ address rewardPool = address(0x66EeE72121E64Cd5fb67B306087511ca20B1956E);
19
+ AuraStrategy.initializeBaseStrategy(
20
+ _storage,
21
+ underlying,
22
+ _vault,
23
+ rewardPool,
24
+ 0x7272163a931dac5bbe1cb5fefaf959bb65f7346f000200000000000000000549, // Balancer Pool id
25
+ 71, // Aura Pool id
26
+ gyd, // depositToken
27
+ true // gyroPool
28
+ );
29
+ rewardTokens = [aura, bal];
30
+ }
31
+ }
@@ -0,0 +1,31 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./AuraStrategy.sol";
5
+
6
+ contract AuraStrategyMainnet_wstETH_GYD is AuraStrategy {
7
+
8
+ constructor() {}
9
+
10
+ function initializeStrategy(
11
+ address _storage,
12
+ address _vault
13
+ ) public initializer {
14
+ address underlying = address(0x6ce1D1e46548ef657f8D7Ebddfc4BEaDB04F72f3);
15
+ address aura = address(0x1509706a6c66CA549ff0cB464de88231DDBe213B);
16
+ address bal = address(0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8);
17
+ address wsteth = address(0x5979D7b546E38E414F7E9822514be443A4800529);
18
+ address rewardPool = address(0x9af228E16Ed7C9a39A44844860c8c72A4c4a1fDa);
19
+ AuraStrategy.initializeBaseStrategy(
20
+ _storage,
21
+ underlying,
22
+ _vault,
23
+ rewardPool,
24
+ 0x6ce1d1e46548ef657f8d7ebddfc4beadb04f72f30002000000000000000005a1, // Balancer Pool id
25
+ 89, // Aura Pool id
26
+ wsteth, // depositToken
27
+ true // gyroPool
28
+ );
29
+ rewardTokens = [aura, bal];
30
+ }
31
+ }