@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,120 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "@openzeppelin/contracts/access/Ownable.sol";
5
+ import "./interface/IStrategyFactory.sol";
6
+ import "./interface/IVaultFactory.sol";
7
+ import "./interface/IPoolFactory.sol";
8
+
9
+ import "../interface/IVault.sol";
10
+ import "../inheritance/Governable.sol";
11
+
12
+ contract MegaFactory is Ownable {
13
+
14
+ enum VaultType {
15
+ None,
16
+ Regular
17
+ }
18
+
19
+ enum StrategyType {
20
+ None,
21
+ Upgradable
22
+ }
23
+
24
+ address public potPoolFactory;
25
+ mapping(uint256 => address) public vaultFactories;
26
+ mapping(uint256 => address) public strategyFactories;
27
+
28
+ struct CompletedDeployment {
29
+ VaultType vaultType;
30
+ address Underlying;
31
+ address NewVault;
32
+ address NewStrategy;
33
+ address NewPool;
34
+ }
35
+
36
+ event DeploymentCompleted(string id);
37
+
38
+ mapping (string => CompletedDeployment) public completedDeployments;
39
+ mapping (address => bool) public authorizedDeployers;
40
+
41
+ address public multisig;
42
+ address public actualStorage;
43
+
44
+ /* methods to make compatible with Storage */
45
+ function governance() external view returns (address) {
46
+ return address(this); // fake governance
47
+ }
48
+
49
+ function isGovernance(address addr) external view returns (bool) {
50
+ return addr == address(this); // fake governance
51
+ }
52
+
53
+ function isController(address addr) external view returns (bool) {
54
+ return addr == address(this); // fake controller
55
+ }
56
+
57
+ modifier onlyAuthorizedDeployer(string memory id) {
58
+ require(completedDeployments[id].vaultType == VaultType.None, "cannot reuse id");
59
+ require(authorizedDeployers[msg.sender], "unauthorized deployer");
60
+ _;
61
+ emit DeploymentCompleted(id);
62
+ }
63
+
64
+ constructor(address _storage, address _multisig) {
65
+ multisig = _multisig;
66
+ actualStorage = _storage;
67
+ setAuthorization(owner(), true);
68
+ setAuthorization(multisig, true);
69
+ }
70
+
71
+ function setAuthorization(address userAddress, bool isDeployer) public onlyOwner {
72
+ authorizedDeployers[userAddress] = isDeployer;
73
+ }
74
+
75
+ function setVaultFactory(uint256 vaultType, address factoryAddress) external onlyOwner {
76
+ vaultFactories[vaultType] = factoryAddress;
77
+ }
78
+
79
+ function setStrategyFactory(uint256 strategyType, address factoryAddress) external onlyOwner {
80
+ strategyFactories[strategyType] = factoryAddress;
81
+ }
82
+
83
+ function setPotPoolFactory(address factoryAddress) external onlyOwner {
84
+ potPoolFactory = factoryAddress;
85
+ }
86
+
87
+ function createRegularVault(string calldata id, address underlying) external onlyAuthorizedDeployer(id) {
88
+ address vault = IVaultFactory(vaultFactories[uint256(VaultType.Regular)]).deploy(
89
+ actualStorage,
90
+ underlying
91
+ );
92
+
93
+ completedDeployments[id] = CompletedDeployment(
94
+ VaultType.Regular,
95
+ underlying,
96
+ vault,
97
+ address(0),
98
+ IPoolFactory(potPoolFactory).deploy(actualStorage, vault)
99
+ );
100
+ }
101
+
102
+ function createRegularVaultUsingUpgradableStrategy(string calldata id, address underlying, address strategyImplementation) external onlyAuthorizedDeployer(id) {
103
+ address vault = IVaultFactory(vaultFactories[uint256(VaultType.Regular)]).deploy(
104
+ address(this), // using this as initial storage, then switching to actualStorage
105
+ underlying
106
+ );
107
+
108
+ address strategy = IStrategyFactory(strategyFactories[uint256(StrategyType.Upgradable)]).deploy(actualStorage, vault, strategyImplementation);
109
+ IVault(vault).setStrategy(strategy);
110
+ Governable(vault).setStorage(actualStorage);
111
+
112
+ completedDeployments[id] = CompletedDeployment(
113
+ VaultType.Regular,
114
+ underlying,
115
+ vault,
116
+ strategy,
117
+ IPoolFactory(potPoolFactory).deploy(actualStorage, vault)
118
+ );
119
+ }
120
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IPoolFactory {
5
+ function deploy(address _storage, address _vault) external returns (address);
6
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IStrategyFactory {
5
+ function deploy(address _storage, address _vault, address _providedStrategyAddress) external returns (address);
6
+ }
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IVaultFactory {
5
+ function deploy(address _storage, address _underlying) external returns (address);
6
+ function info(address vault) external view returns(address Underlying, address NewVault);
7
+ }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import "../../inheritance/Governable.sol";
6
+ import "../../inheritance/OwnableWhitelist.sol";
7
+ import "../interface/IPoolFactory.sol";
8
+ import "../../PotPool.sol";
9
+
10
+ contract PotPoolFactory is OwnableWhitelist, IPoolFactory {
11
+ address public iFARM = 0x9dCA587dc65AC0a043828B0acd946d71eb8D46c1;
12
+ uint256 public poolDefaultDuration = 604800; // 7 days
13
+
14
+ function setPoolDefaultDuration(uint256 _value) external onlyOwner {
15
+ poolDefaultDuration = _value;
16
+ }
17
+
18
+ function deploy(address actualStorage, address vault) override external onlyWhitelisted returns (address) {
19
+ address actualGovernance = Governable(vault).governance();
20
+
21
+ string memory tokenSymbol = ERC20(vault).symbol();
22
+ address[] memory rewardDistribution = new address[](1);
23
+ rewardDistribution[0] = actualGovernance;
24
+ address[] memory rewardTokens = new address[](1);
25
+ rewardTokens[0] = iFARM;
26
+ PotPool pool = new PotPool(
27
+ rewardTokens,
28
+ vault,
29
+ poolDefaultDuration,
30
+ rewardDistribution,
31
+ actualStorage,
32
+ string(abi.encodePacked("p", tokenSymbol)),
33
+ string(abi.encodePacked("p", tokenSymbol)),
34
+ ERC20(vault).decimals()
35
+ );
36
+
37
+ Ownable(pool).transferOwnership(actualGovernance);
38
+
39
+ return address(pool);
40
+ }
41
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "../interface/IStrategyFactory.sol";
5
+ import "../../upgradability/StrategyProxy.sol";
6
+ import "../../inheritance/OwnableWhitelist.sol";
7
+
8
+ interface IInitializableStrategy {
9
+ function initializeStrategy(address _storage, address _vault) external;
10
+ }
11
+
12
+ contract UpgradableStrategyFactory is OwnableWhitelist, IStrategyFactory {
13
+ function deploy(address actualStorage, address vault, address upgradableStrategyImplementation) override external onlyWhitelisted returns (address) {
14
+ StrategyProxy proxy = new StrategyProxy(upgradableStrategyImplementation);
15
+ IInitializableStrategy strategy = IInitializableStrategy(address(proxy));
16
+ strategy.initializeStrategy(actualStorage, vault);
17
+ return address(proxy);
18
+ }
19
+ }
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "../../VaultProxy.sol";
5
+ import "../../interface/IVault.sol";
6
+ import "../interface/IVaultFactory.sol";
7
+ import "../../inheritance/OwnableWhitelist.sol";
8
+
9
+ contract RegularVaultFactory is OwnableWhitelist, IVaultFactory {
10
+ address public vaultImplementation = 0x54Cbc624F1648AC4820b960EFde9574B25386cFD;
11
+ address public lastDeployedAddress = address(0);
12
+
13
+ function deploy(address _storage, address underlying) override external onlyWhitelisted returns (address) {
14
+ lastDeployedAddress = address(new VaultProxy(vaultImplementation));
15
+ IVault(lastDeployedAddress).initializeVault(
16
+ _storage,
17
+ underlying,
18
+ 10000,
19
+ 10000
20
+ );
21
+
22
+ return lastDeployedAddress;
23
+ }
24
+
25
+ function changeDefaultImplementation(address newImplementation) external onlyOwner {
26
+ require(newImplementation != address(0), "Must be set");
27
+ vaultImplementation = newImplementation;
28
+ }
29
+
30
+ function info(address vault) override external view returns(address Underlying, address NewVault) {
31
+ Underlying = IVault(vault).underlying();
32
+ NewVault = vault;
33
+ }
34
+ }
@@ -0,0 +1,85 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "../inheritance/Controllable.sol";
5
+ import "../interface/IGlobalIncentivesHelper.sol";
6
+
7
+ import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
8
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
9
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
10
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
11
+
12
+
13
+ contract GlobalIncentivesExecutor is Controllable {
14
+
15
+ using SafeMathUpgradeable for uint256;
16
+ using SafeERC20Upgradeable for IERC20Upgradeable;
17
+
18
+ mapping (address => bool) public notifier;
19
+ mapping (address => bool) public changer;
20
+
21
+ address[] public tokens;
22
+ uint256[] public totals;
23
+ address public globalIncentivesHelper;
24
+ uint256 public mostRecentWeeksEmissionTimestamp;
25
+
26
+ event ChangerSet(address indexed account, bool value);
27
+ event NotifierSet(address indexed account, bool value);
28
+
29
+ modifier onlyChanger {
30
+ require(changer[msg.sender] || msg.sender == governance(), "Only changer");
31
+ _;
32
+ }
33
+
34
+ modifier onlyNotifier {
35
+ require(notifier[msg.sender] || msg.sender == governance(), "Only notifier");
36
+ _;
37
+ }
38
+
39
+ constructor(address _storage, address _globalIncentivesHelper) Controllable(_storage) {
40
+ globalIncentivesHelper = _globalIncentivesHelper;
41
+ }
42
+
43
+ function updateData(
44
+ address[] calldata _tokens,
45
+ uint256[] calldata _totals,
46
+ uint256 baseTimestamp
47
+ ) external onlyChanger {
48
+ tokens = _tokens;
49
+ totals = _totals;
50
+ if (baseTimestamp > 0) {
51
+ // 0 means "do not reset"
52
+ mostRecentWeeksEmissionTimestamp = baseTimestamp;
53
+ } else {
54
+ require(mostRecentWeeksEmissionTimestamp > 0, "you have to configure mostRecentWeeksEmissionTimestamp");
55
+ }
56
+ }
57
+
58
+ function execute() external onlyNotifier {
59
+ require(mostRecentWeeksEmissionTimestamp > 0, "mostRecentWeeksEmissionTimestamp was never configured");
60
+ require(mostRecentWeeksEmissionTimestamp.add(1 weeks) <= block.timestamp, "too early");
61
+ for (uint256 i = 0; i < tokens.length; i++) {
62
+ uint256 globalIncentivesHelperBalance = IERC20Upgradeable(tokens[i]).balanceOf(globalIncentivesHelper);
63
+ require(globalIncentivesHelperBalance >= totals[i], "not enough balance");
64
+ }
65
+ mostRecentWeeksEmissionTimestamp = mostRecentWeeksEmissionTimestamp.add(1 weeks);
66
+ IGlobalIncentivesHelper(globalIncentivesHelper).notifyPools(tokens, totals, mostRecentWeeksEmissionTimestamp);
67
+ }
68
+
69
+ /// Returning the governance
70
+ function transferGovernance(address target, address newStorage) external onlyGovernance {
71
+ Governable(target).setStorage(newStorage);
72
+ }
73
+
74
+ /// The governance configures whitelists
75
+ function setChanger(address who, bool value) external onlyGovernance {
76
+ changer[who] = value;
77
+ emit ChangerSet(who, value);
78
+ }
79
+
80
+ /// The governance configures whitelists
81
+ function setNotifier(address who, bool value) external onlyGovernance {
82
+ notifier[who] = value;
83
+ emit NotifierSet(who, value);
84
+ }
85
+ }
@@ -0,0 +1,174 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "./NotifyHelperStateful.sol";
5
+ import "./NotifyHelperGeneric.sol";
6
+ import "../inheritance/Controllable.sol";
7
+
8
+ import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
9
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
10
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
11
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
12
+
13
+
14
+ contract GlobalIncentivesHelper is Controllable {
15
+
16
+ using SafeMathUpgradeable for uint256;
17
+ using SafeERC20Upgradeable for IERC20Upgradeable;
18
+
19
+ address public helperControlStorage;
20
+ address public notifyHelperGeneric;
21
+ address public escrow;
22
+ address public reserve;
23
+ address public farm;
24
+
25
+ event ChangerSet(address indexed account, bool value);
26
+ event NotifierSet(address indexed account, bool value);
27
+ event Vesting(address pool, uint256 amount);
28
+ event PoolChanged(address indexed pool, uint256 percentage, uint256 notificationType, bool vests);
29
+
30
+ enum NotificationType {
31
+ VOID, AMPLIFARM, FARM, TRANSFER, PROFIT_SHARE, TOKEN
32
+ }
33
+
34
+ mapping (address => address) public tokenToHelper;
35
+ mapping (address => bool) public changer;
36
+ mapping (address => bool) public notifier;
37
+
38
+ modifier onlyChanger {
39
+ require(changer[msg.sender] || msg.sender == governance(), "Only changer");
40
+ _;
41
+ }
42
+
43
+ modifier onlyNotifier {
44
+ require(notifier[msg.sender] || msg.sender == governance(), "Only notifier");
45
+ _;
46
+ }
47
+
48
+ constructor(
49
+ address _storage,
50
+ address _farm,
51
+ address _farmHelper,
52
+ address _notifyHelperGeneric,
53
+ address _escrow,
54
+ address _reserve
55
+ ) Controllable(_storage) {
56
+ tokenToHelper[_farm] = _farmHelper;
57
+ farm = _farm;
58
+ notifyHelperGeneric = _notifyHelperGeneric;
59
+ helperControlStorage = address(new Storage());
60
+ escrow = _escrow;
61
+ reserve = _reserve;
62
+ }
63
+
64
+ function notifyPools(address[] calldata tokens, uint256[] calldata totals, uint256 timestamp) external onlyNotifier {
65
+ for (uint256 i = 0; i < tokens.length; i++) {
66
+ // IERC20Upgradeable(tokens[i]).safeTransferFrom(msg.sender, address(this), totals[i]);
67
+ IERC20Upgradeable(tokens[i]).approve(tokenToHelper[tokens[i]], totals[i]);
68
+ NotifyHelperStateful(tokenToHelper[tokens[i]]).notifyPools(totals[i], timestamp);
69
+ }
70
+ }
71
+
72
+ // uses generic helper
73
+ function newToken(address token) external onlyChanger {
74
+ newTokenWithHelper(token, notifyHelperGeneric);
75
+ }
76
+
77
+ // uses a specific notify helper
78
+ function newTokenWithHelper(address token, address notifyHelper) public onlyChanger {
79
+ require(tokenToHelper[token] == address(0), "Token already initialized");
80
+ tokenToHelper[token] = address(new NotifyHelperStateful(
81
+ helperControlStorage,
82
+ notifyHelper, // the universal helper should be sufficient in all cases
83
+ token,
84
+ address(0), // no iFARM/ampliFARM notify helper is needed
85
+ escrow,
86
+ reserve
87
+ ));
88
+ if (notifyHelper == notifyHelperGeneric) {
89
+ NotifyHelperGeneric(notifyHelper).setWhitelist(tokenToHelper[token], true);
90
+ }
91
+ NotifyHelperStateful(tokenToHelper[token]).setNotifier(address(this), true);
92
+ NotifyHelperStateful(tokenToHelper[token]).setNotifier(governance(), true);
93
+ NotifyHelperStateful(tokenToHelper[token]).setChanger(address(this), true);
94
+ NotifyHelperStateful(tokenToHelper[token]).setChanger(governance(), true);
95
+ }
96
+
97
+ function resetToken(address token) public onlyChanger {
98
+ tokenToHelper[token] = address(0);
99
+ }
100
+
101
+ /// Whitelisted entity makes changes to the notifications
102
+ function setPoolBatch(
103
+ address[] calldata tokens,
104
+ address[] calldata poolAddress,
105
+ uint256[] calldata poolPercentage,
106
+ NotificationType[] calldata notificationType,
107
+ bool[] calldata vests) external onlyChanger {
108
+ for (uint256 i = 0; i < poolAddress.length; i++) {
109
+ setPool(tokens[i], poolAddress[i], poolPercentage[i], notificationType[i], vests[i]);
110
+ }
111
+ }
112
+
113
+ /// Pool management, adds, updates or removes a transfer/notification
114
+ function setPool(
115
+ address token,
116
+ address poolAddress,
117
+ uint256 poolPercentage,
118
+ NotificationType notificationType,
119
+ bool vests
120
+ ) public onlyChanger {
121
+ if (token == farm) {
122
+ require(notificationType != NotificationType.TOKEN, "With FARM, use FARM, AMPLIFARM, or TRANSFER");
123
+ }
124
+ if (notificationType == NotificationType.TOKEN) {
125
+ // we use type translation so that we can use the same contract
126
+ NotifyHelperStateful(tokenToHelper[token]).setPool(poolAddress, poolPercentage,
127
+ NotifyHelperStateful.NotificationType(uint256(NotificationType.FARM)), vests);
128
+ } else {
129
+ NotifyHelperStateful(tokenToHelper[token]).setPool(poolAddress, poolPercentage,
130
+ NotifyHelperStateful.NotificationType(uint256(notificationType)), vests);
131
+ }
132
+ emit PoolChanged(poolAddress, poolPercentage, uint256(notificationType), vests);
133
+ }
134
+
135
+ /// emergency draining of tokens and ETH as there should be none staying here
136
+ function emergencyDrain(address token, uint256 amount) public onlyGovernance {
137
+ if (token == address(0)) {
138
+ payable(msg.sender).transfer(amount);
139
+ } else {
140
+ IERC20Upgradeable(token).safeTransfer(msg.sender, amount);
141
+ }
142
+ }
143
+
144
+ /// Configuration method for vesting for governance
145
+ function setVestingEscrow(address token, address _escrow) external onlyGovernance {
146
+ NotifyHelperStateful(tokenToHelper[token]).setVestingEscrow(_escrow);
147
+ }
148
+
149
+ /// Configuration method for vesting for governance
150
+ function setVesting(address token, uint256 _numerator, uint256 _denominator) external onlyGovernance {
151
+ NotifyHelperStateful(tokenToHelper[token]).setVesting(_numerator, _denominator);
152
+ }
153
+
154
+ function notificationExists(address token, address poolAddress) public view returns(bool) {
155
+ return NotifyHelperStateful(tokenToHelper[token]).notificationExists(poolAddress);
156
+ }
157
+
158
+ /// Returning the governance
159
+ function transferGovernance(address target, address newStorage) external onlyGovernance {
160
+ Governable(target).setStorage(newStorage);
161
+ }
162
+
163
+ /// The governance configures whitelists
164
+ function setChanger(address who, bool value) external onlyGovernance {
165
+ changer[who] = value;
166
+ emit ChangerSet(who, value);
167
+ }
168
+
169
+ /// The governance configures whitelists
170
+ function setNotifier(address who, bool value) external onlyGovernance {
171
+ notifier[who] = value;
172
+ emit NotifierSet(who, value);
173
+ }
174
+ }
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
5
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
6
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
7
+ import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
8
+
9
+ import "../inheritance/Controllable.sol";
10
+ import "../PotPool.sol";
11
+
12
+ contract NotifyHelperGeneric is Controllable {
13
+
14
+ using SafeMathUpgradeable for uint256;
15
+ using SafeERC20Upgradeable for IERC20Upgradeable;
16
+
17
+ event WhitelistSet(address who, bool value);
18
+
19
+ mapping (address => bool) public alreadyNotified;
20
+ mapping (address => bool) public whitelist;
21
+
22
+ modifier onlyWhitelisted {
23
+ require(whitelist[msg.sender] || msg.sender == governance(), "Only whitelisted");
24
+ _;
25
+ }
26
+
27
+ constructor(address _storage)
28
+ Controllable(_storage) {
29
+ setWhitelist(governance(), true);
30
+ }
31
+
32
+ function setWhitelist(address who, bool value) public onlyWhitelisted {
33
+ whitelist[who] = value;
34
+ emit WhitelistSet(who, value);
35
+ }
36
+
37
+ /**
38
+ * Notifies all the pools, safe guarding the notification amount.
39
+ */
40
+ function notifyPools(uint256[] memory amounts,
41
+ address[] memory pools,
42
+ uint256 sum, address _token
43
+ ) public onlyWhitelisted {
44
+ require(amounts.length == pools.length, "Amounts and pools lengths mismatch");
45
+ for (uint i = 0; i < pools.length; i++) {
46
+ alreadyNotified[pools[i]] = false;
47
+ }
48
+
49
+ uint256 check = 0;
50
+ for (uint i = 0; i < pools.length; i++) {
51
+ require(amounts[i] > 0, "Notify zero");
52
+ require(!alreadyNotified[pools[i]], "Duplicate pool");
53
+ IERC20Upgradeable token = IERC20Upgradeable(_token);
54
+ token.safeTransferFrom(msg.sender, pools[i], amounts[i]);
55
+ PotPool(pools[i]).notifyTargetRewardAmount(_token, amounts[i]);
56
+ check = check.add(amounts[i]);
57
+ alreadyNotified[pools[i]] = true;
58
+ }
59
+ require(sum == check, "Wrong check sum");
60
+ }
61
+ }