@harvest-finance/harvest-strategy-polygon 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-polygon might be problematic. Click here for more details.

Files changed (485) hide show
  1. package/README.md +110 -5
  2. package/contracts/base/Controller.sol +125 -0
  3. package/contracts/base/ControllerV2.sol +363 -0
  4. package/contracts/base/FeeRewardForwarder.sol +163 -0
  5. package/contracts/base/PotPool.sol +360 -0
  6. package/contracts/base/ProfitSharingReceiver.sol +39 -0
  7. package/contracts/base/RewardForwarderV2.sol +109 -0
  8. package/contracts/base/Vault.sol +344 -0
  9. package/contracts/base/VaultERC4626.sol +113 -0
  10. package/contracts/base/VaultProxy.sol +35 -0
  11. package/contracts/base/VaultStorage.sol +199 -0
  12. package/contracts/base/VaultStorageV2.sol +196 -0
  13. package/contracts/base/VaultV2.sol +369 -0
  14. package/contracts/base/ape-base/MiniApeV2Strategy.sol +322 -0
  15. package/contracts/base/ape-base/interface/IMiniChefV2.sol +31 -0
  16. package/contracts/base/ape-base/interface/IRewarder.sol +10 -0
  17. package/contracts/base/factory/MegaFactory.sol +120 -0
  18. package/contracts/base/factory/interface/IPoolFactory.sol +6 -0
  19. package/contracts/base/factory/interface/IStrategyFactory.sol +6 -0
  20. package/contracts/base/factory/interface/IVaultFactory.sol +7 -0
  21. package/contracts/base/factory/pool/PotPoolFactory.sol +43 -0
  22. package/contracts/base/factory/strategy/UpgradableStrategyFactory.sol +19 -0
  23. package/contracts/base/factory/vault/RegularVaultFactory.sol +34 -0
  24. package/contracts/base/incentives/GlobalIncentivesHelper.sol +167 -0
  25. package/contracts/base/incentives/NotifyHelperGeneric.sol +61 -0
  26. package/contracts/base/incentives/NotifyHelperStateful.sol +290 -0
  27. package/contracts/base/inheritance/Controllable.sol +26 -0
  28. package/contracts/base/inheritance/ControllableInit.sol +31 -0
  29. package/contracts/base/inheritance/Governable.sol +29 -0
  30. package/contracts/base/inheritance/GovernableInit.sol +51 -0
  31. package/contracts/base/inheritance/IUpgradeSource.sol +8 -0
  32. package/contracts/base/inheritance/OwnableWhitelist.sol +17 -0
  33. package/contracts/base/inheritance/RewardTokenProfitNotifier.sol +48 -0
  34. package/contracts/base/inheritance/Storage.sol +36 -0
  35. package/contracts/base/interface/IController.sol +30 -0
  36. package/contracts/base/interface/IControllerV2.sol +135 -0
  37. package/contracts/base/interface/IERC4626.sol +263 -0
  38. package/contracts/base/interface/IFeeRewardForwarder.sol +9 -0
  39. package/contracts/base/interface/IProfitSharingReceiver.sol +10 -0
  40. package/contracts/base/interface/IRewardForwarder.sol +58 -0
  41. package/contracts/base/interface/IRewardPool.sol +34 -0
  42. package/contracts/base/interface/IStrategy.sol +25 -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 +8 -0
  46. package/contracts/base/interface/IVault.sol +35 -0
  47. package/contracts/base/interface/aave/DataTypes.sol +266 -0
  48. package/contracts/base/interface/aave/IAToken.sol +37 -0
  49. package/contracts/base/interface/aave/IPool.sol +13 -0
  50. package/contracts/base/interface/balancer/Gauge.sol +22 -0
  51. package/contracts/base/interface/balancer/IBVault.sol +557 -0
  52. package/contracts/base/interface/balancer/IBalancerMinter.sol +114 -0
  53. package/contracts/base/interface/balancer/linearPool/ILinearPool.sol +185 -0
  54. package/contracts/base/interface/balancer/linearPool/ILinearPoolFactory.sol +16 -0
  55. package/contracts/base/interface/balancer/linearPool/ILinearPoolRebalancer.sol +8 -0
  56. package/contracts/base/interface/balancer/linearPool/IPoolSwapStructs.sol +57 -0
  57. package/contracts/base/interface/caviar/ICaviarChef.sol +16 -0
  58. package/contracts/base/interface/compound/IComet.sol +114 -0
  59. package/contracts/base/interface/compound/ICometRewards.sol +17 -0
  60. package/contracts/base/interface/curve/Gauge.sol +25 -0
  61. package/contracts/base/interface/curve/ICurveDeposit_2token.sol +25 -0
  62. package/contracts/base/interface/curve/ICurveDeposit_2token_underlying.sol +31 -0
  63. package/contracts/base/interface/curve/ICurveDeposit_3token.sol +25 -0
  64. package/contracts/base/interface/curve/ICurveDeposit_3token_meta.sol +20 -0
  65. package/contracts/base/interface/curve/ICurveDeposit_3token_underlying.sol +31 -0
  66. package/contracts/base/interface/curve/ICurveDeposit_4token.sol +25 -0
  67. package/contracts/base/interface/curve/ICurveDeposit_4token_meta.sol +20 -0
  68. package/contracts/base/interface/curve/ICurveDeposit_4token_underlying.sol +31 -0
  69. package/contracts/base/interface/curve/ICurveDeposit_5token.sol +25 -0
  70. package/contracts/base/interface/curve/ICurveDeposit_5token_meta.sol +20 -0
  71. package/contracts/base/interface/curve/ICurveDeposit_5token_underlying.sol +31 -0
  72. package/contracts/base/interface/curve/ICurveDeposit_6token.sol +25 -0
  73. package/contracts/base/interface/curve/ICurveDeposit_6token_meta.sol +20 -0
  74. package/contracts/base/interface/gamma/IClearing.sol +8 -0
  75. package/contracts/base/interface/gamma/IHypervisor.sol +17 -0
  76. package/contracts/base/interface/gamma/IStakingRewards.sol +35 -0
  77. package/contracts/base/interface/gamma/IUniProxy.sol +15 -0
  78. package/contracts/base/interface/kyber/IDMMExchangeRouter.sol +69 -0
  79. package/contracts/base/interface/kyber/IDMMFactory.sol +35 -0
  80. package/contracts/base/interface/kyber/IDMMLiquidityRouter.sol +204 -0
  81. package/contracts/base/interface/kyber/IDMMPool.sol +42 -0
  82. package/contracts/base/interface/kyber/IDMMRouter01.sol +12 -0
  83. package/contracts/base/interface/kyber/IDMMRouter02.sol +55 -0
  84. package/contracts/base/interface/kyber/IKyberZap.sol +7 -0
  85. package/contracts/base/interface/merkl/IDistributor.sol +6 -0
  86. package/contracts/base/interface/morpho/IMetaMorpho.sol +7 -0
  87. package/contracts/base/interface/pearl/IGauge.sol +13 -0
  88. package/contracts/base/interface/pearl/IPair.sol +44 -0
  89. package/contracts/base/interface/pearl/IRouter.sol +305 -0
  90. package/contracts/base/interface/quickswap/IDragonLair.sol +25 -0
  91. package/contracts/base/interface/quickswap/IMasterChef.sol +13 -0
  92. package/contracts/base/interface/uniswap/IUniswapV2Factory.sol +15 -0
  93. package/contracts/base/interface/uniswap/IUniswapV2Migrator.sol +6 -0
  94. package/contracts/base/interface/uniswap/IUniswapV2Pair.sol +59 -0
  95. package/contracts/base/interface/uniswap/IUniswapV2Router01.sol +96 -0
  96. package/contracts/base/interface/uniswap/IUniswapV2Router02.sol +137 -0
  97. package/contracts/base/interface/uniswap/IUniswapV3Pool.sol +24 -0
  98. package/contracts/base/interface/uniswap/IUniswapV3Router.sol +64 -0
  99. package/contracts/base/interface/uniswap/IWETH.sol +8 -0
  100. package/contracts/base/interface/uniswap/pool/IUniswapV3PoolActions.sol +103 -0
  101. package/contracts/base/interface/uniswap/pool/IUniswapV3PoolDerivedState.sol +40 -0
  102. package/contracts/base/interface/uniswap/pool/IUniswapV3PoolEvents.sol +121 -0
  103. package/contracts/base/interface/uniswap/pool/IUniswapV3PoolImmutables.sol +35 -0
  104. package/contracts/base/interface/uniswap/pool/IUniswapV3PoolOwnerActions.sol +23 -0
  105. package/contracts/base/interface/uniswap/pool/IUniswapV3PoolState.sol +116 -0
  106. package/contracts/base/masterchef-base/MasterChefHodlStrategy.sol +240 -0
  107. package/contracts/base/masterchef-base/MasterChefStrategy.sol +364 -0
  108. package/contracts/base/masterchef-base/interfaces/IMasterChef.sol +12 -0
  109. package/contracts/base/migration/vaultMigratable_2JPYv2.sol +87 -0
  110. package/contracts/base/migration/vaultMigratable_bal2EUR_PAR.sol +121 -0
  111. package/contracts/base/migration/vaultMigratable_bal2EUR_agEUR.sol +121 -0
  112. package/contracts/base/migration/vaultMigratable_balMaticX.sol +153 -0
  113. package/contracts/base/migration/vaultMigratable_balStMatic.sol +153 -0
  114. package/contracts/base/noop/NoopStrategy.sol +89 -0
  115. package/contracts/base/noop/NoopStrategyUpgradeable.sol +92 -0
  116. package/contracts/base/sushi-base/MiniChefV2Strategy.sol +380 -0
  117. package/contracts/base/sushi-base/interface/IMiniChefV2.sol +31 -0
  118. package/contracts/base/sushi-base/interface/IRewarder.sol +9 -0
  119. package/contracts/base/sushi-base/lib/BoringERC20.sol +30 -0
  120. package/contracts/base/upgradability/Address.sol +33 -0
  121. package/contracts/base/upgradability/BaseUpgradeabilityProxy.sol +61 -0
  122. package/contracts/base/upgradability/BaseUpgradeableStrategy.sol +111 -0
  123. package/contracts/base/upgradability/BaseUpgradeableStrategyStorage.sol +176 -0
  124. package/contracts/base/upgradability/BaseUpgradeableStrategyStorageV2.sol +290 -0
  125. package/contracts/base/upgradability/BaseUpgradeableStrategyV2.sol +145 -0
  126. package/contracts/base/upgradability/IUpgradable.sol +7 -0
  127. package/contracts/base/upgradability/Proxy.sol +71 -0
  128. package/contracts/base/upgradability/ReentrancyGuard.sol +57 -0
  129. package/contracts/base/upgradability/ReentrancyGuardUpgradeable.sol +51 -0
  130. package/contracts/base/upgradability/StrategyProxy.sol +35 -0
  131. package/contracts/base/wmatic/WMATIC.sol +8 -0
  132. package/contracts/strategies/aave/AaveSupplyStrategy.sol +213 -0
  133. package/contracts/strategies/aave/AaveSupplyStrategyMainnet_DAI.sol +23 -0
  134. package/contracts/strategies/aave/AaveSupplyStrategyMainnet_EURS.sol +23 -0
  135. package/contracts/strategies/aave/AaveSupplyStrategyMainnet_USDC.sol +23 -0
  136. package/contracts/strategies/aave/AaveSupplyStrategyMainnet_USDCe.sol +23 -0
  137. package/contracts/strategies/aave/AaveSupplyStrategyMainnet_USDT.sol +23 -0
  138. package/contracts/strategies/ape/ApeStrategyMainnet_BANANA_MATIC.sol +36 -0
  139. package/contracts/strategies/ape/ApeStrategyMainnet_BNB_MATIC.sol +36 -0
  140. package/contracts/strategies/ape/ApeStrategyMainnet_BTC_MATIC.sol +36 -0
  141. package/contracts/strategies/ape/ApeStrategyMainnet_DAI_MATIC.sol +36 -0
  142. package/contracts/strategies/ape/ApeStrategyMainnet_DAI_USDC.sol +37 -0
  143. package/contracts/strategies/ape/ApeStrategyMainnet_ETH_MATIC.sol +36 -0
  144. package/contracts/strategies/ape/ApeStrategyMainnet_USDT_MATIC.sol +36 -0
  145. package/contracts/strategies/aura/AuraStrategy.sol +347 -0
  146. package/contracts/strategies/aura/AuraStrategyMainnet_jEUR_PAR.sol +30 -0
  147. package/contracts/strategies/aura/interface/IAuraBaseRewardPool.sol +25 -0
  148. package/contracts/strategies/aura/interface/IAuraBooster.sol +17 -0
  149. package/contracts/strategies/aura/interface/IAuraDepositor.sol +7 -0
  150. package/contracts/strategies/balancer/BalancerStrategyV3.sol +509 -0
  151. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_2BRL.sol +39 -0
  152. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_2BRLUSD.sol +38 -0
  153. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_2EUR_PAR.sol +34 -0
  154. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_2EUR_PARv2.sol +34 -0
  155. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_2EUR_agEUR.sol +34 -0
  156. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_MATIC_USDC_ETH_BAL.sol +32 -0
  157. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_MaticX.sol +37 -0
  158. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_MaticX_amMatic.sol +38 -0
  159. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_SPHERE_MATIC.sol +34 -0
  160. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_TNGBL_USDC.sol +34 -0
  161. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_WBTC_ETH_USDC.sol +32 -0
  162. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_bbamusd.sol +36 -0
  163. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_frxETH.sol +32 -0
  164. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_frxETH_amWETH.sol +35 -0
  165. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_stETH.sol +35 -0
  166. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_stMatic.sol +36 -0
  167. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_stMatic_amMatic.sol +39 -0
  168. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_tetuBal.sol +36 -0
  169. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_wUSDR_USDC.sol +34 -0
  170. package/contracts/strategies/balancer/BalancerStrategyV3Mainnet_wstETH_amWETH.sol +37 -0
  171. package/contracts/strategies/balancer/interface/Gauge.sol +26 -0
  172. package/contracts/strategies/balancer/interface/IBVault.sol +557 -0
  173. package/contracts/strategies/balancer/interface/IBalanceMinter.sol +114 -0
  174. package/contracts/strategies/complifi/ComplifiDerivStrategy.sol +381 -0
  175. package/contracts/strategies/complifi/ComplifiDerivStrategyMainnet_ETH5x.sol +35 -0
  176. package/contracts/strategies/complifi/ComplifiStrategy.sol +362 -0
  177. package/contracts/strategies/complifi/ComplifiStrategyMainnet_COMFI_WETH.sol +34 -0
  178. package/contracts/strategies/complifi/interfaces/ILiquidityMining.sol +13 -0
  179. package/contracts/strategies/complifi/interfaces/ILiquidityPool.sol +63 -0
  180. package/contracts/strategies/complifi/interfaces/IProxyActions.sol +10 -0
  181. package/contracts/strategies/complifi/interfaces/IUSDCVault.sol +55 -0
  182. package/contracts/strategies/compound/CompoundStrategy.sol +296 -0
  183. package/contracts/strategies/compound/CompoundStrategyMainnet_USDC.sol +28 -0
  184. package/contracts/strategies/compound/CompoundStrategyMainnet_USDT.sol +28 -0
  185. package/contracts/strategies/compound-blue/CompoundBlueStrategy.sol +292 -0
  186. package/contracts/strategies/compound-blue/CompoundBlueStrategyMainnet_ETH.sol +27 -0
  187. package/contracts/strategies/compound-blue/CompoundBlueStrategyMainnet_USDC.sol +27 -0
  188. package/contracts/strategies/compound-blue/CompoundBlueStrategyMainnet_USDT.sol +27 -0
  189. package/contracts/strategies/convex/ConvexStrategyMainnet_3CRV.sol +40 -0
  190. package/contracts/strategies/convex/ConvexStrategyMainnet_3CRYPTO.sol +37 -0
  191. package/contracts/strategies/convex/ConvexStrategyMainnet_CRV_3CRYPTO copy.sol +37 -0
  192. package/contracts/strategies/convex/ConvexStrategyMainnet_MATIC_3CRYPTO.sol +37 -0
  193. package/contracts/strategies/convex/ConvexStrategyMainnet_USDR.sol +40 -0
  194. package/contracts/strategies/convex/ConvexStrategyMainnet_aCRV.sol +38 -0
  195. package/contracts/strategies/convex/base/ConvexStrategy.sol +480 -0
  196. package/contracts/strategies/convex/interface/IBaseRewardPool.sol +13 -0
  197. package/contracts/strategies/convex/interface/IBooster.sol +10 -0
  198. package/contracts/strategies/gamma-merkl/GammaMerklStrategy.sol +272 -0
  199. package/contracts/strategies/gamma-merkl/GammaMerklStrategyMainnet_QS_ETH_USDC.sol +25 -0
  200. package/contracts/strategies/gamma-merkl/GammaMerklStrategyMainnet_QS_ETH_USDT.sol +25 -0
  201. package/contracts/strategies/gamma-merkl/GammaMerklStrategyMainnet_QS_MATIC_USDT.sol +25 -0
  202. package/contracts/strategies/gamma-merkl/GammaMerklStrategyMainnet_QS_TBTC_ETH.sol +25 -0
  203. package/contracts/strategies/gamma-merkl/GammaMerklStrategyMainnet_QS_WBTC_ETH_w.sol +25 -0
  204. package/contracts/strategies/genomes/NoopStrategy_GENE_ETH.sol +23 -0
  205. package/contracts/strategies/genomes/NoopStrategy_GNOME_ETH.sol +23 -0
  206. package/contracts/strategies/idle/IdleFinanceStrategy.sol +240 -0
  207. package/contracts/strategies/idle/IdleStrategyDAIMainnet.sol +33 -0
  208. package/contracts/strategies/idle/IdleStrategyUSDCMainnet.sol +33 -0
  209. package/contracts/strategies/idle/IdleStrategyWETHMainnet.sol +30 -0
  210. package/contracts/strategies/idle/interface/IdleToken.sol +58 -0
  211. package/contracts/strategies/jarvis/JarvisHodlStrategyV3.sol +351 -0
  212. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2CAD.sol +34 -0
  213. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2EUR.sol +34 -0
  214. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2EUR_EURT.sol +34 -0
  215. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2EUR_EURe.sol +34 -0
  216. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2EUR_PAR.sol +34 -0
  217. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2JPY.sol +34 -0
  218. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2JPYv2.sol +34 -0
  219. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2NZD.sol +34 -0
  220. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_2SGD.sol +34 -0
  221. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_jCHF_USDC.sol +35 -0
  222. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_jCHF_WETH.sol +35 -0
  223. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_jEUR_USDC.sol +35 -0
  224. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_jEUR_WETH.sol +35 -0
  225. package/contracts/strategies/jarvis/JarvisHodlStrategyV3Mainnet_jGBP_USDC.sol +35 -0
  226. package/contracts/strategies/jarvis/JarvisStrategyV3.sol +281 -0
  227. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_AUR3_USDC.sol +27 -0
  228. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_AURJUL22_WETH.sol +27 -0
  229. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_DEN2_4EUR.sol +27 -0
  230. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_DEN3_4EUR.sol +27 -0
  231. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_DEN4_4EUR.sol +27 -0
  232. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTANGLENOV22_2EURagEUR.sol +27 -0
  233. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTANGLE_2EURagEUR.sol +27 -0
  234. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTJUL22_USDC.sol +27 -0
  235. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTMAY22_USDC.sol +27 -0
  236. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTMIMONOV22_2EURPAR.sol +27 -0
  237. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTMIMO_2EURPAR.sol +27 -0
  238. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTNOV22_USDC.sol +27 -0
  239. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_JRTSEP22_USDC.sol +27 -0
  240. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_QUI_2CAD.sol +27 -0
  241. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_SES_2JPY.sol +28 -0
  242. package/contracts/strategies/jarvis/JarvisStrategyV3Mainnet_agDEN_2EUR.sol +27 -0
  243. package/contracts/strategies/jarvis/interface/IElysianFields.sol +11 -0
  244. package/contracts/strategies/jarvis/interface/IKyberFairLaunch.sol +13 -0
  245. package/contracts/strategies/jarvis/interface/IKyberRewardLocker.sol +9 -0
  246. package/contracts/strategies/meshswap/MeshswapStrategy.sol +304 -0
  247. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_MESH_oMOOI.sol +30 -0
  248. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_MESH_oZEMIT.sol +30 -0
  249. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_USDC_oUSDC.sol +31 -0
  250. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_USDT_oUSDT.sol +31 -0
  251. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_WMATIC_MESH.sol +27 -0
  252. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_WMATIC_USDC.sol +28 -0
  253. package/contracts/strategies/meshswap/MeshswapStrategyMainnet_WMATIC_USDT.sol +28 -0
  254. package/contracts/strategies/meshswap/interface/IExchange.sol +9 -0
  255. package/contracts/strategies/meshswap/interface/IRouter.sol +68 -0
  256. package/contracts/strategies/pearl/CaviarStrategy.sol +244 -0
  257. package/contracts/strategies/pearl/CaviarStrategyMainnet_CVR.sol +26 -0
  258. package/contracts/strategies/pearl/PearlHodlStrategy.sol +254 -0
  259. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_CVR_PEARL.sol +27 -0
  260. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_DAI_USDR.sol +27 -0
  261. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_ETH_USDR.sol +27 -0
  262. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_MATIC_USDR.sol +27 -0
  263. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_PEARL_USDR.sol +27 -0
  264. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_STAR_USDR.sol +27 -0
  265. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_TNGBL_USDR.sol +27 -0
  266. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_USDC_USDR.sol +27 -0
  267. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_USDT_USDR.sol +27 -0
  268. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_WBTC_USDR.sol +27 -0
  269. package/contracts/strategies/pearl/PearlHodlStrategyMainnet_wUSDR_USDR.sol +27 -0
  270. package/contracts/strategies/quick-gamma/QuickGammaStrategy.sol +400 -0
  271. package/contracts/strategies/quick-gamma/QuickGammaStrategyMainnet_MATIC_ETH_narrow.sol +31 -0
  272. package/contracts/strategies/quick-gamma/QuickGammaStrategyMainnet_MATIC_ETH_wide.sol +31 -0
  273. package/contracts/strategies/quick-gamma/QuickGammaStrategyMainnet_MATIC_USDC_narrow.sol +31 -0
  274. package/contracts/strategies/quick-gamma/QuickGammaStrategyMainnet_MATIC_USDC_wide.sol +31 -0
  275. package/contracts/strategies/quick-gamma/QuickGammaStrategyMainnet_USDC_ETH_narrow.sol +34 -0
  276. package/contracts/strategies/quick-gamma/QuickGammaStrategyMainnet_USDC_ETH_wide.sol +34 -0
  277. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2.sol +348 -0
  278. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2Mainnet_USDC_DAI.sol +28 -0
  279. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2Mainnet_USDC_USDT.sol +29 -0
  280. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2Mainnet_WBTC_ETH_narrow.sol +28 -0
  281. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2Mainnet_WBTC_USDC_narrow.sol +28 -0
  282. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2Mainnet_cbETH_ETH.sol +28 -0
  283. package/contracts/strategies/quick-gamma/QuickGammaStrategyV2Mainnet_wstETH_ETH.sol +28 -0
  284. package/contracts/strategies/uniswap-gamma/UniswapGammaStrategy.sol +312 -0
  285. package/contracts/strategies/uniswap-gamma/UniswapGammaStrategyMainnet_USDC_DAI.sol +28 -0
  286. package/contracts/strategies/uniswap-gamma/UniswapGammaStrategyMainnet_USDC_USDT.sol +28 -0
  287. package/contracts/strategies/uniswap-gamma/UniswapGammaStrategyMainnet_USDC_WETH.sol +28 -0
  288. package/contracts/strategies/uniswap-gamma/UniswapGammaStrategyMainnet_WMATIC_USDC.sol +28 -0
  289. package/contracts/strategies/yel/YelStrategy.sol +350 -0
  290. package/contracts/strategies/yel/YelStrategyMainnet_YEL_WETH.sol +29 -0
  291. package/hardhat.config.js +58 -0
  292. package/index.js +42 -0
  293. package/package.json +56 -6
  294. package/scripts/01-deploy-vault-regular-with-upgradable-strategy.js +41 -0
  295. package/scripts/02-deploy-vault-regular.js +35 -0
  296. package/scripts/03-deploy-upgradable-strategy.js +34 -0
  297. package/scripts/04-deploy-new-implementation.js +24 -0
  298. package/scripts/README.md +55 -0
  299. package/scripts/utils.js +42 -0
  300. package/test/aave/dai.js +207 -0
  301. package/test/aave/eurs.js +207 -0
  302. package/test/aave/usdc.js +206 -0
  303. package/test/aave/usdce.js +206 -0
  304. package/test/aave/usdt.js +206 -0
  305. package/test/ape/banana-matic.js +157 -0
  306. package/test/ape/bnb-matic.js +159 -0
  307. package/test/ape/btc-matic.js +159 -0
  308. package/test/ape/dai-matic.js +159 -0
  309. package/test/ape/dai-usdc.js +163 -0
  310. package/test/ape/eth-matic.js +158 -0
  311. package/test/ape/usdt-matic.js +159 -0
  312. package/test/aura/jeur-par.js +135 -0
  313. package/test/balancer/2brl_v3.js +123 -0
  314. package/test/balancer/2brlusd_v3.js +123 -0
  315. package/test/balancer/2eur_ageur.js +141 -0
  316. package/test/balancer/2eur_par.js +141 -0
  317. package/test/balancer/2eur_par_v2.js +123 -0
  318. package/test/balancer/bbamusd_v3.js +124 -0
  319. package/test/balancer/btc.js +131 -0
  320. package/test/balancer/frxETH.js +123 -0
  321. package/test/balancer/frxeth_amweth.js +123 -0
  322. package/test/balancer/matic_usdc_eth_bal.js +123 -0
  323. package/test/balancer/maticx_ammatic.js +123 -0
  324. package/test/balancer/maticx_v2.js +120 -0
  325. package/test/balancer/maticx_v3.js +141 -0
  326. package/test/balancer/polybase.js +131 -0
  327. package/test/balancer/polybase_v2.js +121 -0
  328. package/test/balancer/polydefi.js +131 -0
  329. package/test/balancer/polydefi2.js +131 -0
  330. package/test/balancer/qipool.js +136 -0
  331. package/test/balancer/sphere_matic.js +123 -0
  332. package/test/balancer/stETH.js +123 -0
  333. package/test/balancer/stable.js +131 -0
  334. package/test/balancer/stable_v2.js +121 -0
  335. package/test/balancer/stmatic_ammatic.js +123 -0
  336. package/test/balancer/stmatic_v2.js +120 -0
  337. package/test/balancer/stmatic_v3.js +141 -0
  338. package/test/balancer/tetubal_v3.js +123 -0
  339. package/test/balancer/tngbl_usdc.js +123 -0
  340. package/test/balancer/tricrypto.js +131 -0
  341. package/test/balancer/tusd_stable.js +142 -0
  342. package/test/balancer/usdc_weth.js +136 -0
  343. package/test/balancer/usdc_weth_v2.js +123 -0
  344. package/test/balancer/wbtc_eth_usdc.js +123 -0
  345. package/test/balancer/wbtc_weth.js +136 -0
  346. package/test/balancer/wsteth_amweth.js +123 -0
  347. package/test/balancer/wusdr_usdc.js +123 -0
  348. package/test/compound/usdc.js +127 -0
  349. package/test/compound/usdt.js +129 -0
  350. package/test/compound-blue/eth.js +136 -0
  351. package/test/compound-blue/usdc.js +136 -0
  352. package/test/compound-blue/usdt.js +136 -0
  353. package/test/convex/3crv.js +123 -0
  354. package/test/convex/3crypto.js +123 -0
  355. package/test/convex/acrv.js +123 -0
  356. package/test/convex/crv_3crypto.js +123 -0
  357. package/test/convex/matic_3crypto.js +123 -0
  358. package/test/convex/usdr.js +123 -0
  359. package/test/core/emission-fork.js +197 -0
  360. package/test/core/emission.js +209 -0
  361. package/test/core/vault_upgrade.js +129 -0
  362. package/test/curve/aave.js +132 -0
  363. package/test/curve/atricrypto3.js +135 -0
  364. package/test/curve/eurtusd.js +135 -0
  365. package/test/gamma-merkl/qs-eth-usdc.js +212 -0
  366. package/test/gamma-merkl/qs-eth-usdt.js +213 -0
  367. package/test/gamma-merkl/qs-matic-usdt.js +213 -0
  368. package/test/gamma-merkl/qs-tbtc-eth.js +213 -0
  369. package/test/gamma-merkl/qs-wbtc-eth-w.js +213 -0
  370. package/test/genomes/gene-eth.js +115 -0
  371. package/test/genomes/gnome-eth.js +115 -0
  372. package/test/idle/dai.js +129 -0
  373. package/test/idle/usdc.js +128 -0
  374. package/test/idle/weth.js +128 -0
  375. package/test/jarvis/2cad-hodl.js +183 -0
  376. package/test/jarvis/2cad-update-nov22.js +182 -0
  377. package/test/jarvis/2cad-update.js +177 -0
  378. package/test/jarvis/2cad-update2.js +182 -0
  379. package/test/jarvis/2cad-update3.js +182 -0
  380. package/test/jarvis/2eur-ageur-update-nov22.js +182 -0
  381. package/test/jarvis/2eur-ageur-update.js +182 -0
  382. package/test/jarvis/2eur-eure-hodl.js +176 -0
  383. package/test/jarvis/2eur-eurt-hodl.js +176 -0
  384. package/test/jarvis/2eur-eurt-update-nov22.js +182 -0
  385. package/test/jarvis/2eur-hodl.js +176 -0
  386. package/test/jarvis/2eur-par-hodl.js +176 -0
  387. package/test/jarvis/2eur-par-update-nov22.js +182 -0
  388. package/test/jarvis/2jpy-hodl.js +244 -0
  389. package/test/jarvis/2jpy-update-nov22.js +182 -0
  390. package/test/jarvis/2jpy-update.js +177 -0
  391. package/test/jarvis/2jpy-update2.js +182 -0
  392. package/test/jarvis/2jpyv2-upgrade.js +184 -0
  393. package/test/jarvis/2nzd-hodl.js +176 -0
  394. package/test/jarvis/2nzd-update.js +182 -0
  395. package/test/jarvis/2sgd-hodl.js +176 -0
  396. package/test/jarvis/2sgd-update-nov22.js +182 -0
  397. package/test/jarvis/2sgd-update.js +182 -0
  398. package/test/jarvis/2sgd-update2.js +182 -0
  399. package/test/jarvis/4eur-hodl-upgrade.js +177 -0
  400. package/test/jarvis/4eur-hodl.js +183 -0
  401. package/test/jarvis/4eur-update.js +181 -0
  402. package/test/jarvis/4eur-update2.js +181 -0
  403. package/test/jarvis/agden-2eur.js +222 -0
  404. package/test/jarvis/aur-usdc-v2.js +115 -0
  405. package/test/jarvis/aur-usdc.js +127 -0
  406. package/test/jarvis/aur3-usdc.js +115 -0
  407. package/test/jarvis/aurjul22-weth.js +222 -0
  408. package/test/jarvis/den-4eur.js +115 -0
  409. package/test/jarvis/den2-4eur.js +220 -0
  410. package/test/jarvis/den3-4eur.js +220 -0
  411. package/test/jarvis/den4-4eur.js +220 -0
  412. package/test/jarvis/jchf-usdc-hodl-v2.js +184 -0
  413. package/test/jarvis/jchf-usdc-hodl-v3.js +178 -0
  414. package/test/jarvis/jchf-usdc-hodl.js +193 -0
  415. package/test/jarvis/jchf-weth-hodl.js +176 -0
  416. package/test/jarvis/jeur-usdc-hodl-v2.js +184 -0
  417. package/test/jarvis/jeur-usdc-hodl-v3.js +178 -0
  418. package/test/jarvis/jeur-usdc-hodl.js +193 -0
  419. package/test/jarvis/jeur-weth-hodl.js +176 -0
  420. package/test/jarvis/jgbp-usdc-hodl-v2.js +184 -0
  421. package/test/jarvis/jgbp-usdc-hodl-v3.js +178 -0
  422. package/test/jarvis/jgbp-usdc-hodl.js +193 -0
  423. package/test/jarvis/jrtangle-2eurageur.js +220 -0
  424. package/test/jarvis/jrtanglenov22-2eurageur.js +220 -0
  425. package/test/jarvis/jrtjul22-usdc.js +115 -0
  426. package/test/jarvis/jrtmay22-usdc.js +115 -0
  427. package/test/jarvis/jrtmimo-2eurpar.js +220 -0
  428. package/test/jarvis/jrtmimonov22-2eurpar.js +220 -0
  429. package/test/jarvis/jrtnov22-usdc.js +220 -0
  430. package/test/jarvis/jrtsep22-usdc.js +220 -0
  431. package/test/jarvis/qui-2cad.js +218 -0
  432. package/test/jarvis/ses-2jpy.js +222 -0
  433. package/test/meshswap/mesh-omooi.js +197 -0
  434. package/test/meshswap/mesh-ozemit.js +197 -0
  435. package/test/meshswap/usdc-ousdc.js +197 -0
  436. package/test/meshswap/usdt-ousdt.js +197 -0
  437. package/test/meshswap/wmatic-mesh.js +197 -0
  438. package/test/meshswap/wmatic-usdc.js +197 -0
  439. package/test/meshswap/wmatic-usdt.js +197 -0
  440. package/test/mstable/musd.js +123 -0
  441. package/test/pearl/cvr-pearl.js +198 -0
  442. package/test/pearl/cvr.js +133 -0
  443. package/test/pearl/dai-usdr.js +198 -0
  444. package/test/pearl/eth-usdr.js +198 -0
  445. package/test/pearl/matic-usdr.js +198 -0
  446. package/test/pearl/pearl-usdr.js +198 -0
  447. package/test/pearl/star-usdr.js +186 -0
  448. package/test/pearl/tngbl-usdr.js +198 -0
  449. package/test/pearl/usdc-usdr.js +198 -0
  450. package/test/pearl/usdt-usdr.js +198 -0
  451. package/test/pearl/wbtc-usdr.js +198 -0
  452. package/test/pearl/wusdr-usdr.js +198 -0
  453. package/test/popsicle/ice-weth.js +128 -0
  454. package/test/quick/eth-matic.js +132 -0
  455. package/test/quick/eth-usdt.js +140 -0
  456. package/test/quick/ifarm-quick.js +147 -0
  457. package/test/quick/matic-usdc.js +145 -0
  458. package/test/quick/psp-matic.js +124 -0
  459. package/test/quick/wbtc-eth.js +145 -0
  460. package/test/quick-gamma/cbeth-eth.js +207 -0
  461. package/test/quick-gamma/matic-eth-narrow.js +201 -0
  462. package/test/quick-gamma/matic-eth-wide.js +197 -0
  463. package/test/quick-gamma/matic-usdc-narrow.js +197 -0
  464. package/test/quick-gamma/matic-usdc-wide.js +197 -0
  465. package/test/quick-gamma/upgrade/matic-eth-narrow.js +204 -0
  466. package/test/quick-gamma/upgrade/matic-usdc-narrow.js +199 -0
  467. package/test/quick-gamma/usdc-dai.js +209 -0
  468. package/test/quick-gamma/usdc-eth-narrow.js +197 -0
  469. package/test/quick-gamma/usdc-eth-wide.js +197 -0
  470. package/test/quick-gamma/usdc-usdt.js +209 -0
  471. package/test/quick-gamma/wbtc-eth-narrow.js +207 -0
  472. package/test/quick-gamma/wbtc-usdc-narrow.js +209 -0
  473. package/test/quick-gamma/wsteth-eth.js +207 -0
  474. package/test/sushi/eth-usdt.js +153 -0
  475. package/test/sushi/matic-eth.js +138 -0
  476. package/test/sushi/usdc-eth.js +153 -0
  477. package/test/test-config.js +24 -0
  478. package/test/uniswap-gamma/usdc-dai.js +212 -0
  479. package/test/uniswap-gamma/usdc-usdt.js +212 -0
  480. package/test/uniswap-gamma/usdc-weth.js +212 -0
  481. package/test/uniswap-gamma/wmatic-usdc.js +210 -0
  482. package/test/utilities/Utils.js +96 -0
  483. package/test/utilities/hh-utils.js +242 -0
  484. package/test/utilities/make-vault.js +10 -0
  485. package/test/yel/yel-wmatic.js +129 -0
@@ -0,0 +1,380 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+
3
+ pragma solidity 0.6.12;
4
+
5
+ import "@openzeppelin/contracts/math/Math.sol";
6
+ import "@openzeppelin/contracts/math/SafeMath.sol";
7
+ import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
8
+ import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
9
+ import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
10
+ import "../interface/IVault.sol";
11
+ import "../upgradability/BaseUpgradeableStrategy.sol";
12
+ import "./interface/IMiniChefV2.sol";
13
+ import "@uniswap/v2-periphery/contracts/interfaces/IWETH.sol";
14
+
15
+
16
+ contract MiniChefV2Strategy is BaseUpgradeableStrategy {
17
+
18
+ using SafeMath for uint256;
19
+ using SafeERC20 for IERC20;
20
+
21
+ address public constant sushiswapRouterV2 = address(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506);
22
+
23
+ // additional storage slots (on top of BaseUpgradeableStrategy ones) are defined here
24
+ bytes32 internal constant _POOLID_SLOT = 0x3fd729bfa2e28b7806b03a6e014729f59477b530f995be4d51defc9dad94810b;
25
+ bytes32 internal constant _IS_LP_ASSET_SLOT = 0xc2f3dabf55b1bdda20d5cf5fcba9ba765dfc7c9dbaf28674ce46d43d60d58768;
26
+ bytes32 internal constant _SECOND_REWARD_TOKEN_SLOT = 0xd06e5f1f8ce4bdaf44326772fc9785917d444f120d759a01f1f440e0a42d67a3;
27
+
28
+ // this would be reset on each upgrade
29
+ mapping (address => address[]) public uniswapRoutes;
30
+ address[] public secondRewardRoute;
31
+
32
+ constructor() public BaseUpgradeableStrategy() {
33
+ assert(_POOLID_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.poolId")) - 1));
34
+ assert(_IS_LP_ASSET_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.isLpAsset")) - 1));
35
+ assert(_SECOND_REWARD_TOKEN_SLOT == bytes32(uint256(keccak256("eip1967.strategyStorage.secondRewardToken")) - 1));
36
+ }
37
+
38
+ function initializeBaseStrategy(
39
+ address _storage,
40
+ address _underlying,
41
+ address _vault,
42
+ address _rewardPool,
43
+ address _rewardToken,
44
+ address _secondRewardToken,
45
+ uint256 _poolID,
46
+ bool _isLpAsset
47
+ ) public initializer {
48
+
49
+ BaseUpgradeableStrategy.initialize(
50
+ _storage,
51
+ _underlying,
52
+ _vault,
53
+ _rewardPool,
54
+ _rewardToken,
55
+ 80, // profit sharing numerator
56
+ 1000, // profit sharing denominator
57
+ true, // sell
58
+ 1e18, // sell floor
59
+ 12 hours // implementation change delay
60
+ );
61
+
62
+ IERC20 _lpt;
63
+ _lpt = IMiniChefV2(rewardPool()).lpToken(_poolID);
64
+ require(address(_lpt) == underlying(), "Pool Info does not match underlying");
65
+ _setPoolId(_poolID);
66
+
67
+ _setSecondRewardToken(_secondRewardToken);
68
+
69
+ if (_isLpAsset) {
70
+ address uniLPComponentToken0 = IUniswapV2Pair(underlying()).token0();
71
+ address uniLPComponentToken1 = IUniswapV2Pair(underlying()).token1();
72
+
73
+ // these would be required to be initialized separately by governance
74
+ uniswapRoutes[uniLPComponentToken0] = new address[](0);
75
+ uniswapRoutes[uniLPComponentToken1] = new address[](0);
76
+ } else {
77
+ uniswapRoutes[underlying()] = new address[](0);
78
+ }
79
+
80
+ setBoolean(_IS_LP_ASSET_SLOT, _isLpAsset);
81
+ }
82
+
83
+ function depositArbCheck() public pure returns(bool) {
84
+ return true;
85
+ }
86
+
87
+ function rewardPoolBalance() internal view returns (uint256 bal) {
88
+ (bal,) = IMiniChefV2(rewardPool()).userInfo(poolId(), address(this));
89
+ }
90
+
91
+ function exitRewardPool() internal {
92
+ uint256 bal = rewardPoolBalance();
93
+ if (bal != 0) {
94
+ IMiniChefV2(rewardPool()).withdrawAndHarvest(poolId(), bal, address(this));
95
+ }
96
+ }
97
+
98
+ function emergencyExitRewardPool() internal {
99
+ uint256 bal = rewardPoolBalance();
100
+ if (bal != 0) {
101
+ IMiniChefV2(rewardPool()).emergencyWithdraw(poolId(), address(this));
102
+ }
103
+ }
104
+
105
+ function harvestReward() internal {
106
+ IMiniChefV2(rewardPool()).harvest(poolId(), address(this));
107
+ }
108
+
109
+ function unsalvagableTokens(address token) public view returns (bool) {
110
+ return (token == rewardToken() || token == underlying());
111
+ }
112
+
113
+ function enterRewardPool() internal {
114
+ uint256 entireBalance = IERC20(underlying()).balanceOf(address(this));
115
+ IERC20(underlying()).safeApprove(rewardPool(), 0);
116
+ IERC20(underlying()).safeApprove(rewardPool(), entireBalance);
117
+ IMiniChefV2(rewardPool()).deposit(poolId(), entireBalance, address(this));
118
+ }
119
+
120
+ /*
121
+ * In case there are some issues discovered about the pool or underlying asset
122
+ * Governance can exit the pool properly
123
+ * The function is only used for emergency to exit the pool
124
+ */
125
+ function emergencyExit() public onlyGovernance {
126
+ emergencyExitRewardPool();
127
+ _setPausedInvesting(true);
128
+ }
129
+
130
+ /*
131
+ * Resumes the ability to invest into the underlying reward pools
132
+ */
133
+
134
+ function continueInvesting() public onlyGovernance {
135
+ _setPausedInvesting(false);
136
+ }
137
+
138
+ function setLiquidationPath(address _token, address [] memory _route) public onlyGovernance {
139
+ uniswapRoutes[_token] = _route;
140
+ }
141
+
142
+ // We assume that all the tradings can be done on Uniswap
143
+ function _liquidateReward() internal {
144
+ // we can accept 1 as minimum because this is called only by a trusted role
145
+ uint256 amountOutMin = 1;
146
+
147
+ // swap second reward token to reward token
148
+ uint256 secondRewardBalance = IERC20(secondRewardToken()).balanceOf(address(this));
149
+
150
+ // allow Uniswap to sell our reward
151
+ IERC20(secondRewardToken()).safeApprove(sushiswapRouterV2, 0);
152
+ IERC20(secondRewardToken()).safeApprove(sushiswapRouterV2, secondRewardBalance);
153
+
154
+ if (secondRewardBalance > 0) {
155
+ IUniswapV2Router02(sushiswapRouterV2).swapExactTokensForTokens(
156
+ secondRewardBalance,
157
+ amountOutMin,
158
+ secondRewardRoute,
159
+ address(this),
160
+ block.timestamp
161
+ );
162
+ }
163
+
164
+ uint256 rewardBalance = IERC20(rewardToken()).balanceOf(address(this));
165
+ if (!sell() || rewardBalance < sellFloor()) {
166
+ // Profits can be disabled for possible simplified and rapid exit
167
+ emit ProfitsNotCollected(sell(), rewardBalance < sellFloor());
168
+ return;
169
+ }
170
+
171
+ notifyProfitInRewardToken(rewardBalance);
172
+ uint256 remainingRewardBalance = IERC20(rewardToken()).balanceOf(address(this));
173
+
174
+ if (remainingRewardBalance == 0) {
175
+ return;
176
+ }
177
+
178
+ // allow Uniswap to sell our reward
179
+ IERC20(rewardToken()).safeApprove(sushiswapRouterV2, 0);
180
+ IERC20(rewardToken()).safeApprove(sushiswapRouterV2, remainingRewardBalance);
181
+
182
+ if (isLpAsset()) {
183
+ address uniLPComponentToken0 = IUniswapV2Pair(underlying()).token0();
184
+ address uniLPComponentToken1 = IUniswapV2Pair(underlying()).token1();
185
+
186
+ uint256 toToken0 = remainingRewardBalance.div(2);
187
+ uint256 toToken1 = remainingRewardBalance.sub(toToken0);
188
+
189
+ uint256 token0Amount;
190
+
191
+ if (uniswapRoutes[uniLPComponentToken0].length > 1) {
192
+ // if we need to liquidate the token0
193
+ IUniswapV2Router02(sushiswapRouterV2).swapExactTokensForTokens(
194
+ toToken0,
195
+ amountOutMin,
196
+ uniswapRoutes[uniLPComponentToken0],
197
+ address(this),
198
+ block.timestamp
199
+ );
200
+ token0Amount = IERC20(uniLPComponentToken0).balanceOf(address(this));
201
+ } else {
202
+ // otherwise we assme token0 is the reward token itself
203
+ token0Amount = toToken0;
204
+ }
205
+
206
+ uint256 token1Amount;
207
+
208
+ if (uniswapRoutes[uniLPComponentToken1].length > 1) {
209
+ // sell reward token to token1
210
+ IUniswapV2Router02(sushiswapRouterV2).swapExactTokensForTokens(
211
+ toToken1,
212
+ amountOutMin,
213
+ uniswapRoutes[uniLPComponentToken1],
214
+ address(this),
215
+ block.timestamp
216
+ );
217
+ token1Amount = IERC20(uniLPComponentToken1).balanceOf(address(this));
218
+ } else {
219
+ token1Amount = toToken1;
220
+ }
221
+
222
+ // provide token1 and token2 to SUSHI
223
+ IERC20(uniLPComponentToken0).safeApprove(sushiswapRouterV2, 0);
224
+ IERC20(uniLPComponentToken0).safeApprove(sushiswapRouterV2, token0Amount);
225
+
226
+ IERC20(uniLPComponentToken1).safeApprove(sushiswapRouterV2, 0);
227
+ IERC20(uniLPComponentToken1).safeApprove(sushiswapRouterV2, token1Amount);
228
+
229
+ // we provide liquidity to sushi
230
+ uint256 liquidity;
231
+ (,,liquidity) = IUniswapV2Router02(sushiswapRouterV2).addLiquidity(
232
+ uniLPComponentToken0,
233
+ uniLPComponentToken1,
234
+ token0Amount,
235
+ token1Amount,
236
+ 1, // we are willing to take whatever the pair gives us
237
+ 1, // we are willing to take whatever the pair gives us
238
+ address(this),
239
+ block.timestamp
240
+ );
241
+ } else {
242
+ IUniswapV2Router02(sushiswapRouterV2).swapExactTokensForTokens(
243
+ remainingRewardBalance,
244
+ amountOutMin,
245
+ uniswapRoutes[underlying()],
246
+ address(this),
247
+ block.timestamp
248
+ );
249
+ }
250
+ }
251
+
252
+ /*
253
+ * Stakes everything the strategy holds into the reward pool
254
+ */
255
+ function investAllUnderlying() internal onlyNotPausedInvesting {
256
+ // this check is needed, because most of the SNX reward pools will revert if
257
+ // you try to stake(0).
258
+ if(IERC20(underlying()).balanceOf(address(this)) > 0) {
259
+ enterRewardPool();
260
+ }
261
+ }
262
+
263
+ /*
264
+ * Withdraws all the asset to the vault
265
+ */
266
+ function withdrawAllToVault() public restricted {
267
+ if (address(rewardPool()) != address(0)) {
268
+ exitRewardPool();
269
+ }
270
+ _liquidateReward();
271
+ IERC20(underlying()).safeTransfer(vault(), IERC20(underlying()).balanceOf(address(this)));
272
+ }
273
+
274
+ /*
275
+ * Withdraws all the asset to the vault
276
+ */
277
+ function withdrawToVault(uint256 amount) public restricted {
278
+ // Typically there wouldn't be any amount here
279
+ // however, it is possible because of the emergencyExit
280
+ uint256 entireBalance = IERC20(underlying()).balanceOf(address(this));
281
+
282
+ if(amount > entireBalance){
283
+ // While we have the check above, we still using SafeMath below
284
+ // for the peace of mind (in case something gets changed in between)
285
+ uint256 needToWithdraw = amount.sub(entireBalance);
286
+ uint256 toWithdraw = Math.min(rewardPoolBalance(), needToWithdraw);
287
+ IMiniChefV2(rewardPool()).withdraw(poolId(), toWithdraw, address(this));
288
+ }
289
+
290
+ IERC20(underlying()).safeTransfer(vault(), amount);
291
+ }
292
+
293
+ /*
294
+ * Note that we currently do not have a mechanism here to include the
295
+ * amount of reward that is accrued.
296
+ */
297
+ function investedUnderlyingBalance() external view returns (uint256) {
298
+ if (rewardPool() == address(0)) {
299
+ return IERC20(underlying()).balanceOf(address(this));
300
+ }
301
+ // Adding the amount locked in the reward pool and the amount that is somehow in this contract
302
+ // both are in the units of "underlying"
303
+ // The second part is needed because there is the emergency exit mechanism
304
+ // which would break the assumption that all the funds are always inside of the reward pool
305
+ return rewardPoolBalance().add(IERC20(underlying()).balanceOf(address(this)));
306
+ }
307
+
308
+ /*
309
+ * Governance or Controller can claim coins that are somehow transferred into the contract
310
+ * Note that they cannot come in take away coins that are used and defined in the strategy itself
311
+ */
312
+ function salvage(address recipient, address token, uint256 amount) external onlyControllerOrGovernance {
313
+ // To make sure that governance cannot come in and take away the coins
314
+ require(!unsalvagableTokens(token), "token is defined as not salvagable");
315
+ IERC20(token).safeTransfer(recipient, amount);
316
+ }
317
+
318
+ /*
319
+ * Get the reward, sell it in exchange for underlying, invest what you got.
320
+ * It's not much, but it's honest work.
321
+ *
322
+ * Note that although `onlyNotPausedInvesting` is not added here,
323
+ * calling `investAllUnderlying()` affectively blocks the usage of `doHardWork`
324
+ * when the investing is being paused by governance.
325
+ */
326
+ function doHardWork() external onlyNotPausedInvesting restricted {
327
+ harvestReward();
328
+ _liquidateReward();
329
+ investAllUnderlying();
330
+ }
331
+
332
+ /**
333
+ * Can completely disable claiming UNI rewards and selling. Good for emergency withdraw in the
334
+ * simplest possible way.
335
+ */
336
+ function setSell(bool s) public onlyGovernance {
337
+ _setSell(s);
338
+ }
339
+
340
+ /**
341
+ * Sets the minimum amount of CRV needed to trigger a sale.
342
+ */
343
+ function setSellFloor(uint256 floor) public onlyGovernance {
344
+ _setSellFloor(floor);
345
+ }
346
+
347
+ // masterchef rewards pool ID
348
+ function _setPoolId(uint256 _value) internal {
349
+ setUint256(_POOLID_SLOT, _value);
350
+ }
351
+
352
+ function poolId() public view returns (uint256) {
353
+ return getUint256(_POOLID_SLOT);
354
+ }
355
+
356
+ // complexRewarder second reward
357
+ function _setSecondRewardToken(address _address) internal {
358
+ setAddress(_SECOND_REWARD_TOKEN_SLOT, _address);
359
+ }
360
+
361
+ function secondRewardToken() public view returns (address) {
362
+ return getAddress(_SECOND_REWARD_TOKEN_SLOT);
363
+ }
364
+
365
+ function isLpAsset() public view returns (bool) {
366
+ return getBoolean(_IS_LP_ASSET_SLOT);
367
+ }
368
+
369
+ function finalizeUpgrade() external onlyGovernance {
370
+ _finalizeUpgrade();
371
+ // reset the liquidation paths
372
+ // they need to be re-set manually
373
+ if (isLpAsset()) {
374
+ uniswapRoutes[IUniswapV2Pair(underlying()).token0()] = new address[](0);
375
+ uniswapRoutes[IUniswapV2Pair(underlying()).token1()] = new address[](0);
376
+ } else {
377
+ uniswapRoutes[underlying()] = new address[](0);
378
+ }
379
+ }
380
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.6.12;
3
+ pragma experimental ABIEncoderV2;
4
+
5
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6
+ import "./IRewarder.sol";
7
+
8
+ interface IMiniChefV2 {
9
+ struct UserInfo {
10
+ uint256 amount;
11
+ uint256 rewardDebt;
12
+ }
13
+
14
+ struct PoolInfo {
15
+ uint128 accSushiPerShare;
16
+ uint64 lastRewardTime;
17
+ uint64 allocPoint;
18
+ }
19
+
20
+ function rewarder(uint256 _pid) external view returns (IRewarder);
21
+ function poolLength() external view returns (uint256);
22
+ function updatePool(uint256 pid) external returns (IMiniChefV2.PoolInfo memory);
23
+ function userInfo(uint256 _pid, address _user) external view returns (uint256, uint256);
24
+ function lpToken(uint256 _pid) external view returns (IERC20);
25
+ function deposit(uint256 pid, uint256 amount, address to) external;
26
+ function withdraw(uint256 pid, uint256 amount, address to) external;
27
+ function harvest(uint256 pid, address to) external;
28
+ function withdrawAndHarvest(uint256 pid, uint256 amount, address to) external;
29
+ function emergencyWithdraw(uint256 pid, address to) external;
30
+ function pendingSushi(uint256 _pid, address _user) external view returns (uint256 pending);
31
+ }
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity 0.6.12;
4
+ import "../lib/BoringERC20.sol";
5
+ interface IRewarder {
6
+ using BoringERC20 for IERC20;
7
+ function onSushiReward(uint256 pid, address user, address recipient, uint256 sushiAmount, uint256 newLpAmount) external;
8
+ function pendingTokens(uint256 pid, address user, uint256 sushiAmount) external view returns (IERC20[] memory, uint256[] memory);
9
+ }
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity 0.6.12;
3
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
4
+
5
+ library BoringERC20 {
6
+ function safeSymbol(IERC20 token) internal view returns(string memory) {
7
+ (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));
8
+ return success && data.length > 0 ? abi.decode(data, (string)) : "???";
9
+ }
10
+
11
+ function safeName(IERC20 token) internal view returns(string memory) {
12
+ (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));
13
+ return success && data.length > 0 ? abi.decode(data, (string)) : "???";
14
+ }
15
+
16
+ function safeDecimals(IERC20 token) internal view returns (uint8) {
17
+ (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));
18
+ return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;
19
+ }
20
+
21
+ function safeTransfer(IERC20 token, address to, uint256 amount) internal {
22
+ (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));
23
+ require(success && (data.length == 0 || abi.decode(data, (bool))), "BoringERC20: Transfer failed");
24
+ }
25
+
26
+ function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal {
27
+ (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0x23b872dd, from, to, amount));
28
+ require(success && (data.length == 0 || abi.decode(data, (bool))), "BoringERC20: TransferFrom failed");
29
+ }
30
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity 0.6.12;
4
+
5
+ /**
6
+ * Utility library of inline functions on addresses
7
+ *
8
+ * Source https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-solidity/v2.1.3/contracts/utils/Address.sol
9
+ * This contract is copied here and renamed from the original to avoid clashes in the compiled artifacts
10
+ * when the user imports a zos-lib contract (that transitively causes this contract to be compiled and added to the
11
+ * build/artifacts folder) as well as the vanilla Address implementation from an openzeppelin version.
12
+ */
13
+ library OpenZeppelinUpgradesAddress {
14
+ /**
15
+ * Returns whether the target address is a contract
16
+ * @dev This function will return false if invoked during the constructor of a contract,
17
+ * as the code is not actually created until after the constructor finishes.
18
+ * @param account address of the account to check
19
+ * @return whether the target address is a contract
20
+ */
21
+ function isContract(address account) internal view returns (bool) {
22
+ uint256 size;
23
+ // XXX Currently there is no better way to check if there is a contract in an address
24
+ // than to check the size of the code at that address.
25
+ // See https://ethereum.stackexchange.com/a/14016/36603
26
+ // for more details about how this works.
27
+ // TODO Check this again before the Serenity release, because all addresses will be
28
+ // contracts then.
29
+ // solhint-disable-next-line no-inline-assembly
30
+ assembly { size := extcodesize(account) }
31
+ return size > 0;
32
+ }
33
+ }
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity 0.6.12;
4
+
5
+ import './Proxy.sol';
6
+ import './Address.sol';
7
+
8
+ /**
9
+ * @title BaseUpgradeabilityProxy
10
+ * @dev This contract implements a proxy that allows to change the
11
+ * implementation address to which it will delegate.
12
+ * Such a change is called an implementation upgrade.
13
+ */
14
+ contract BaseUpgradeabilityProxy is Proxy {
15
+ /**
16
+ * @dev Emitted when the implementation is upgraded.
17
+ * @param implementation Address of the new implementation.
18
+ */
19
+ event Upgraded(address indexed implementation);
20
+
21
+ /**
22
+ * @dev Storage slot with the address of the current implementation.
23
+ * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
24
+ * validated in the constructor.
25
+ */
26
+ bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
27
+
28
+ /**
29
+ * @dev Returns the current implementation.
30
+ * @return impl Address of the current implementation
31
+ */
32
+ function _implementation() internal view override returns (address impl) {
33
+ bytes32 slot = IMPLEMENTATION_SLOT;
34
+ assembly {
35
+ impl := sload(slot)
36
+ }
37
+ }
38
+
39
+ /**
40
+ * @dev Upgrades the proxy to a new implementation.
41
+ * @param newImplementation Address of the new implementation.
42
+ */
43
+ function _upgradeTo(address newImplementation) internal {
44
+ _setImplementation(newImplementation);
45
+ emit Upgraded(newImplementation);
46
+ }
47
+
48
+ /**
49
+ * @dev Sets the implementation address of the proxy.
50
+ * @param newImplementation Address of the new implementation.
51
+ */
52
+ function _setImplementation(address newImplementation) internal {
53
+ require(OpenZeppelinUpgradesAddress.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address");
54
+
55
+ bytes32 slot = IMPLEMENTATION_SLOT;
56
+
57
+ assembly {
58
+ sstore(slot, newImplementation)
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,111 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+
3
+ pragma solidity 0.6.12;
4
+
5
+ import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
6
+ import "./BaseUpgradeableStrategyStorage.sol";
7
+ import "../inheritance/ControllableInit.sol";
8
+ import "../interface/IController.sol";
9
+ import "../interface/IFeeRewardForwarder.sol";
10
+ import "../interface/merkl/IDistributor.sol";
11
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
12
+ import "@openzeppelin/contracts/math/SafeMath.sol";
13
+ import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
14
+
15
+ contract BaseUpgradeableStrategy is Initializable, ControllableInit, BaseUpgradeableStrategyStorage {
16
+ using SafeMath for uint256;
17
+ using SafeERC20 for IERC20;
18
+
19
+ event ProfitsNotCollected(bool sell, bool floor);
20
+ event ProfitLogInReward(uint256 profitAmount, uint256 feeAmount, uint256 timestamp);
21
+ event ProfitAndBuybackLog(uint256 profitAmount, uint256 feeAmount, uint256 timestamp);
22
+
23
+ modifier restricted() {
24
+ require(msg.sender == vault() || msg.sender == controller()
25
+ || msg.sender == governance(),
26
+ "The sender has to be the controller, governance, or vault");
27
+ _;
28
+ }
29
+
30
+ // This is only used in `investAllUnderlying()`
31
+ // The user can still freely withdraw from the strategy
32
+ modifier onlyNotPausedInvesting() {
33
+ require(!pausedInvesting(), "Action blocked as the strategy is in emergency state");
34
+ _;
35
+ }
36
+
37
+ constructor() public BaseUpgradeableStrategyStorage() {
38
+ }
39
+
40
+ function initialize(
41
+ address _storage,
42
+ address _underlying,
43
+ address _vault,
44
+ address _rewardPool,
45
+ address _rewardToken,
46
+ uint256 _profitSharingNumerator,
47
+ uint256 _profitSharingDenominator,
48
+ bool _sell,
49
+ uint256 _sellFloor,
50
+ uint256 _implementationChangeDelay
51
+ ) public initializer {
52
+ ControllableInit.initialize(
53
+ _storage
54
+ );
55
+ _setUnderlying(_underlying);
56
+ _setVault(_vault);
57
+ _setRewardPool(_rewardPool);
58
+ _setRewardToken(_rewardToken);
59
+ _setProfitSharingNumerator(_profitSharingNumerator);
60
+ _setProfitSharingDenominator(_profitSharingDenominator);
61
+
62
+ _setSell(_sell);
63
+ _setSellFloor(_sellFloor);
64
+ _setNextImplementationDelay(_implementationChangeDelay);
65
+ _setPausedInvesting(false);
66
+ }
67
+
68
+ /**
69
+ * Schedules an upgrade for this vault's proxy.
70
+ */
71
+ function scheduleUpgrade(address impl) public onlyGovernance {
72
+ _setNextImplementation(impl);
73
+ _setNextImplementationTimestamp(block.timestamp.add(nextImplementationDelay()));
74
+ }
75
+
76
+ function _finalizeUpgrade() internal {
77
+ _setNextImplementation(address(0));
78
+ _setNextImplementationTimestamp(0);
79
+ }
80
+
81
+ function shouldUpgrade() external view returns (bool, address) {
82
+ return (
83
+ nextImplementationTimestamp() != 0
84
+ && block.timestamp > nextImplementationTimestamp()
85
+ && nextImplementation() != address(0),
86
+ nextImplementation()
87
+ );
88
+ }
89
+
90
+ function toggleMerklOperator(address merklClaim, address operator) external onlyGovernance {
91
+ IDistributor(merklClaim).toggleOperator(address(this), operator);
92
+ }
93
+
94
+ // reward notification
95
+
96
+ function notifyProfitInRewardToken(uint256 _rewardBalance) internal {
97
+ if( _rewardBalance > 0 ){
98
+ uint256 feeAmount = _rewardBalance.mul(profitSharingNumerator()).div(profitSharingDenominator());
99
+ emit ProfitLogInReward(_rewardBalance, feeAmount, block.timestamp);
100
+ IERC20(rewardToken()).safeApprove(controller(), 0);
101
+ IERC20(rewardToken()).safeApprove(controller(), feeAmount);
102
+
103
+ IController(controller()).notifyFee(
104
+ rewardToken(),
105
+ feeAmount
106
+ );
107
+ } else {
108
+ emit ProfitLogInReward(0, 0, block.timestamp);
109
+ }
110
+ }
111
+ }