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

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 +39 -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,25 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IAuraBaseRewardPool {
5
+
6
+ function balanceOf(address account) external view returns(uint256 amount);
7
+
8
+ function pid() external view returns (uint256 _pid);
9
+
10
+ function stakingToken() external view returns (address _stakingToken);
11
+
12
+ function getReward() external;
13
+
14
+ function stake(uint256 _amount) external;
15
+
16
+ function stakeAll() external;
17
+
18
+ function withdraw(uint256 amount, bool claim) external;
19
+
20
+ function withdrawAll(bool claim) external;
21
+
22
+ function withdrawAndUnwrap(uint256 amount, bool claim) external;
23
+
24
+ function withdrawAllAndUnwrap(bool claim) external;
25
+ }
@@ -0,0 +1,17 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IAuraBooster {
5
+
6
+ function deposit(uint256 _pid, uint256 _amount, bool _stake) external;
7
+
8
+ function depositAll(uint256 _pid, bool _stake) external;
9
+
10
+ function withdraw(uint256 _pid, uint256 _amount) external;
11
+
12
+ function withdrawAll(uint256 _pid) external;
13
+
14
+ function poolInfo(uint256 _pid) external view returns (address lpToken, address, address, address, address, bool);
15
+
16
+ function earmarkRewards(uint256 _pid) external;
17
+ }
@@ -0,0 +1,7 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IAuraDepositor{
5
+ function deposit(uint256, bool) external;
6
+ function lockIncentive() external view returns(uint256);
7
+ }
@@ -0,0 +1,22 @@
1
+ //SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface Gauge {
5
+ function deposit(uint) external;
6
+ function balanceOf(address) external view returns (uint);
7
+ function withdraw(uint) external;
8
+ function user_checkpoint(address) external;
9
+ function claim_rewards() external;
10
+ function bal_pseudo_minter() external view returns (address);
11
+ }
12
+
13
+ interface VotingEscrow {
14
+ function create_lock(uint256 v, uint256 time) external;
15
+ function increase_amount(uint256 _value) external;
16
+ function increase_unlock_time(uint256 _unlock_time) external;
17
+ function withdraw() external;
18
+ }
19
+
20
+ interface Mintr {
21
+ function mint(address) external;
22
+ }
@@ -0,0 +1,580 @@
1
+ // SPDX-License-Identifier: Unlicense
2
+ pragma solidity 0.8.26;
3
+
4
+ interface IAsset {
5
+ }
6
+
7
+ interface IBVault {
8
+ // Internal Balance
9
+ //
10
+ // Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later
11
+ // transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination
12
+ // when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced
13
+ // gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users.
14
+ //
15
+ // Internal Balance management features batching, which means a single contract call can be used to perform multiple
16
+ // operations of different kinds, with different senders and recipients, at once.
17
+
18
+ /**
19
+ * @dev Returns `user`'s Internal Balance for a set of tokens.
20
+ */
21
+ function getInternalBalance(address user, address[] calldata tokens) external view returns (uint256[] memory);
22
+
23
+ /**
24
+ * @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer)
25
+ * and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as
26
+ * it lets integrators reuse a user's Vault allowance.
27
+ *
28
+ * For each operation, if the caller is not `sender`, it must be an authorized relayer for them.
29
+ */
30
+ function manageUserBalance(UserBalanceOp[] calldata ops) external payable;
31
+
32
+ /**
33
+ * @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
34
+ without manual WETH wrapping or unwrapping.
35
+ */
36
+ struct UserBalanceOp {
37
+ UserBalanceOpKind kind;
38
+ IAsset asset;
39
+ uint256 amount;
40
+ address sender;
41
+ address payable recipient;
42
+ }
43
+
44
+ // There are four possible operations in `manageUserBalance`:
45
+ //
46
+ // - DEPOSIT_INTERNAL
47
+ // Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding
48
+ // `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`.
49
+ //
50
+ // ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped
51
+ // and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is
52
+ // relevant for relayers).
53
+ //
54
+ // Emits an `InternalBalanceChanged` event.
55
+ //
56
+ //
57
+ // - WITHDRAW_INTERNAL
58
+ // Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`.
59
+ //
60
+ // ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send
61
+ // it to the recipient as ETH.
62
+ //
63
+ // Emits an `InternalBalanceChanged` event.
64
+ //
65
+ //
66
+ // - TRANSFER_INTERNAL
67
+ // Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`.
68
+ //
69
+ // Reverts if the ETH sentinel value is passed.
70
+ //
71
+ // Emits an `InternalBalanceChanged` event.
72
+ //
73
+ //
74
+ // - TRANSFER_EXTERNAL
75
+ // Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by
76
+ // relayers, as it lets them reuse a user's Vault allowance.
77
+ //
78
+ // Reverts if the ETH sentinel value is passed.
79
+ //
80
+ // Emits an `ExternalBalanceTransfer` event.
81
+
82
+ enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL }
83
+
84
+ /**
85
+ * @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through
86
+ * interacting with Pools using Internal Balance.
87
+ *
88
+ * Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH
89
+ * address.
90
+ */
91
+ event InternalBalanceChanged(address indexed user, address indexed token, int256 delta);
92
+
93
+ /**
94
+ * @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account.
95
+ */
96
+ event ExternalBalanceTransfer(address indexed token, address indexed sender, address recipient, uint256 amount);
97
+
98
+ // Pools
99
+ //
100
+ // There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced
101
+ // functionality:
102
+ //
103
+ // - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the
104
+ // balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads),
105
+ // which increase with the number of registered tokens.
106
+ //
107
+ // - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the
108
+ // balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted
109
+ // constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are
110
+ // independent of the number of registered tokens.
111
+ //
112
+ // - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like
113
+ // minimal swap info Pools, these are called via IMinimalSwapInfoPool.
114
+
115
+ enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN }
116
+
117
+ /**
118
+ * @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which
119
+ * is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be
120
+ * changed.
121
+ *
122
+ * The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`,
123
+ * depending on the chosen specialization setting. This contract is known as the Pool's contract.
124
+ *
125
+ * Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words,
126
+ * multiple Pools may share the same contract.
127
+ *
128
+ * Emits a `PoolRegistered` event.
129
+ */
130
+ function registerPool(PoolSpecialization specialization) external returns (bytes32);
131
+
132
+ /**
133
+ * @dev Emitted when a Pool is registered by calling `registerPool`.
134
+ */
135
+ event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization);
136
+
137
+ /**
138
+ * @dev Returns a Pool's contract address and specialization setting.
139
+ */
140
+ function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);
141
+
142
+ /**
143
+ * @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
144
+ *
145
+ * Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens,
146
+ * exit by receiving registered tokens, and can only swap registered tokens.
147
+ *
148
+ * Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length
149
+ * of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in
150
+ * ascending order.
151
+ *
152
+ * The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset
153
+ * Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`,
154
+ * depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore
155
+ * expected to be highly secured smart contracts with sound design principles, and the decision to register an
156
+ * Asset Manager should not be made lightly.
157
+ *
158
+ * Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset
159
+ * Manager is set, it cannot be changed except by deregistering the associated token and registering again with a
160
+ * different Asset Manager.
161
+ *
162
+ * Emits a `TokensRegistered` event.
163
+ */
164
+ function registerTokens(
165
+ bytes32 poolId,
166
+ address[] calldata tokens,
167
+ address[] calldata assetManagers
168
+ ) external;
169
+
170
+ /**
171
+ * @dev Emitted when a Pool registers tokens by calling `registerTokens`.
172
+ */
173
+ event TokensRegistered(bytes32 indexed poolId, address[] tokens, address[] assetManagers);
174
+
175
+ /**
176
+ * @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
177
+ *
178
+ * Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total
179
+ * balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens
180
+ * must be deregistered in the same `deregisterTokens` call.
181
+ *
182
+ * A deregistered token can be re-registered later on, possibly with a different Asset Manager.
183
+ *
184
+ * Emits a `TokensDeregistered` event.
185
+ */
186
+ function deregisterTokens(bytes32 poolId, address[] calldata tokens) external;
187
+
188
+ /**
189
+ * @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`.
190
+ */
191
+ event TokensDeregistered(bytes32 indexed poolId, address[] tokens);
192
+
193
+ /**
194
+ * @dev Returns detailed information for a Pool's registered token.
195
+ *
196
+ * `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens
197
+ * withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token`
198
+ * equals the sum of `cash` and `managed`.
199
+ *
200
+ * Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`,
201
+ * `managed` or `total` balance to be greater than 2^112 - 1.
202
+ *
203
+ * `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a
204
+ * join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for
205
+ * example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a
206
+ * change for this purpose, and will update `lastChangeBlock`.
207
+ *
208
+ * `assetManager` is the Pool's token Asset Manager.
209
+ */
210
+ function getPoolTokenInfo(bytes32 poolId, address token)
211
+ external
212
+ view
213
+ returns (
214
+ uint256 cash,
215
+ uint256 managed,
216
+ uint256 lastChangeBlock,
217
+ address assetManager
218
+ );
219
+
220
+ /**
221
+ * @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of
222
+ * the tokens' `balances` changed.
223
+ *
224
+ * The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all
225
+ * Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order.
226
+ *
227
+ * If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same
228
+ * order as passed to `registerTokens`.
229
+ *
230
+ * Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are
231
+ * the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo`
232
+ * instead.
233
+ */
234
+ function getPoolTokens(bytes32 poolId)
235
+ external
236
+ view
237
+ returns (
238
+ address[] memory tokens,
239
+ uint256[] memory balances,
240
+ uint256 lastChangeBlock
241
+ );
242
+
243
+ /**
244
+ * @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will
245
+ * trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized
246
+ * Pool shares.
247
+ *
248
+ * If the caller is not `sender`, it must be an authorized relayer for them.
249
+ *
250
+ * The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount
251
+ * to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces
252
+ * these maximums.
253
+ *
254
+ * If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable
255
+ * this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the
256
+ * WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent
257
+ * back to the caller (not the sender, which is important for relayers).
258
+ *
259
+ * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
260
+ * interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be
261
+ * sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final
262
+ * `assets` array might not be sorted. Pools with no registered tokens cannot be joined.
263
+ *
264
+ * If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only
265
+ * be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be
266
+ * withdrawn from Internal Balance: attempting to do so will trigger a revert.
267
+ *
268
+ * This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement
269
+ * their own custom logic. This typically requires additional information from the user (such as the expected number
270
+ * of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed
271
+ * directly to the Pool's contract, as is `recipient`.
272
+ *
273
+ * Emits a `PoolBalanceChanged` event.
274
+ */
275
+ function joinPool(
276
+ bytes32 poolId,
277
+ address sender,
278
+ address recipient,
279
+ JoinPoolRequest calldata request
280
+ ) external payable;
281
+
282
+ enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
283
+ enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT, MANAGEMENT_FEE_TOKENS_OUT }
284
+
285
+ struct JoinPoolRequest {
286
+ IAsset[] assets;
287
+ uint256[] maxAmountsIn;
288
+ bytes userData;
289
+ bool fromInternalBalance;
290
+ }
291
+
292
+ /**
293
+ * @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will
294
+ * trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized
295
+ * Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see
296
+ * `getPoolTokenInfo`).
297
+ *
298
+ * If the caller is not `sender`, it must be an authorized relayer for them.
299
+ *
300
+ * The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum
301
+ * token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault:
302
+ * it just enforces these minimums.
303
+ *
304
+ * If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To
305
+ * enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead
306
+ * of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit.
307
+ *
308
+ * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
309
+ * interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must
310
+ * be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the
311
+ * final `assets` array might not be sorted. Pools with no registered tokens cannot be exited.
312
+ *
313
+ * If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise,
314
+ * an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to
315
+ * do so will trigger a revert.
316
+ *
317
+ * `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the
318
+ * `tokens` array. This array must match the Pool's registered tokens.
319
+ *
320
+ * This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement
321
+ * their own custom logic. This typically requires additional information from the user (such as the expected number
322
+ * of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and
323
+ * passed directly to the Pool's contract.
324
+ *
325
+ * Emits a `PoolBalanceChanged` event.
326
+ */
327
+ function exitPool(
328
+ bytes32 poolId,
329
+ address sender,
330
+ address payable recipient,
331
+ ExitPoolRequest calldata request
332
+ ) external;
333
+
334
+ struct ExitPoolRequest {
335
+ IAsset[] assets;
336
+ uint256[] minAmountsOut;
337
+ bytes userData;
338
+ bool toInternalBalance;
339
+ }
340
+
341
+ /**
342
+ * @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively.
343
+ */
344
+ event PoolBalanceChanged(
345
+ bytes32 indexed poolId,
346
+ address indexed liquidityProvider,
347
+ address[] tokens,
348
+ int256[] deltas,
349
+ uint256[] protocolFeeAmounts
350
+ );
351
+
352
+ enum PoolBalanceChangeKind { JOIN, EXIT }
353
+
354
+ // Swaps
355
+ //
356
+ // Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
357
+ // they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be
358
+ // aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote.
359
+ //
360
+ // The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence.
361
+ // In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'),
362
+ // and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out').
363
+ // More complex swaps, such as one token in to multiple tokens out can be achieved by batching together
364
+ // individual swaps.
365
+ //
366
+ // There are two swap kinds:
367
+ // - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the
368
+ // `onSwap` hook) the amount of tokens out (to send to the recipient).
369
+ // - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines
370
+ // (via the `onSwap` hook) the amount of tokens in (to receive from the sender).
371
+ //
372
+ // Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with
373
+ // the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated
374
+ // tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended
375
+ // swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at
376
+ // the final intended token.
377
+ //
378
+ // In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal
379
+ // Balance) after all individual swaps have been completed, and the net token balance change computed. This makes
380
+ // certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost
381
+ // much less gas than they would otherwise.
382
+ //
383
+ // It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple
384
+ // Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only
385
+ // updating the Pool's internal accounting).
386
+ //
387
+ // To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token
388
+ // involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the
389
+ // minimum amount of tokens to receive (by passing a negative value) is specified.
390
+ //
391
+ // Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after
392
+ // this point in time (e.g. if the transaction failed to be included in a block promptly).
393
+ //
394
+ // If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do
395
+ // the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be
396
+ // passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the
397
+ // same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers).
398
+ //
399
+ // Finally, Internal Balance can be used when either sending or receiving tokens.
400
+
401
+ enum SwapKind { GIVEN_IN, GIVEN_OUT }
402
+
403
+ /**
404
+ * @dev Performs a swap with a single Pool.
405
+ *
406
+ * If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens
407
+ * taken from the Pool, which must be greater than or equal to `limit`.
408
+ *
409
+ * If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens
410
+ * sent to the Pool, which must be less than or equal to `limit`.
411
+ *
412
+ * Internal Balance usage and the recipient are determined by the `funds` struct.
413
+ *
414
+ * Emits a `Swap` event.
415
+ */
416
+ function swap(
417
+ SingleSwap calldata singleSwap,
418
+ FundManagement calldata funds,
419
+ uint256 limit,
420
+ uint256 deadline
421
+ ) external payable returns (uint256);
422
+
423
+ /**
424
+ * @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on
425
+ * the `kind` value.
426
+ *
427
+ * `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address).
428
+ * Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault.
429
+ *
430
+ * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
431
+ * used to extend swap behavior.
432
+ */
433
+ struct SingleSwap {
434
+ bytes32 poolId;
435
+ SwapKind kind;
436
+ IAsset assetIn;
437
+ IAsset assetOut;
438
+ uint256 amount;
439
+ bytes userData;
440
+ }
441
+
442
+ /**
443
+ * @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either
444
+ * the amount of tokens sent to or received from the Pool, depending on the `kind` value.
445
+ *
446
+ * Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the
447
+ * Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at
448
+ * the same index in the `assets` array.
449
+ *
450
+ * Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a
451
+ * Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or
452
+ * `amountOut` depending on the swap kind.
453
+ *
454
+ * Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out
455
+ * of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal
456
+ * the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`.
457
+ *
458
+ * The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses,
459
+ * or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and
460
+ * out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to
461
+ * or unwrapped from WETH by the Vault.
462
+ *
463
+ * Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies
464
+ * the minimum or maximum amount of each token the vault is allowed to transfer.
465
+ *
466
+ * `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the
467
+ * equivalent `swap` call.
468
+ *
469
+ * Emits `Swap` events.
470
+ */
471
+ function batchSwap(
472
+ SwapKind kind,
473
+ BatchSwapStep[] calldata swaps,
474
+ IAsset[] calldata assets,
475
+ FundManagement calldata funds,
476
+ int256[] calldata limits,
477
+ uint256 deadline
478
+ ) external payable returns (int256[] memory);
479
+
480
+ /**
481
+ * @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the
482
+ * `assets` array passed to that function, and ETH assets are converted to WETH.
483
+ *
484
+ * If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out
485
+ * from the previous swap, depending on the swap kind.
486
+ *
487
+ * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
488
+ * used to extend swap behavior.
489
+ */
490
+ struct BatchSwapStep {
491
+ bytes32 poolId;
492
+ uint256 assetInIndex;
493
+ uint256 assetOutIndex;
494
+ uint256 amount;
495
+ bytes userData;
496
+ }
497
+
498
+ /**
499
+ * @dev Emitted for each individual swap performed by `swap` or `batchSwap`.
500
+ */
501
+ event Swap(
502
+ bytes32 indexed poolId,
503
+ address indexed tokenIn,
504
+ address indexed tokenOut,
505
+ uint256 amountIn,
506
+ uint256 amountOut
507
+ );
508
+
509
+ /**
510
+ * @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the
511
+ * `recipient` account.
512
+ *
513
+ * If the caller is not `sender`, it must be an authorized relayer for them.
514
+ *
515
+ * If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20
516
+ * transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender`
517
+ * must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of
518
+ * `joinPool`.
519
+ *
520
+ * If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of
521
+ * transferred. This matches the behavior of `exitPool`.
522
+ *
523
+ * Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a
524
+ * revert.
525
+ */
526
+ struct FundManagement {
527
+ address sender;
528
+ bool fromInternalBalance;
529
+ address payable recipient;
530
+ bool toInternalBalance;
531
+ }
532
+
533
+ /**
534
+ * @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be
535
+ * simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result.
536
+ *
537
+ * Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH)
538
+ * the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it
539
+ * receives are the same that an equivalent `batchSwap` call would receive.
540
+ *
541
+ * Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct.
542
+ * This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens,
543
+ * approve them for the Vault, or even know a user's address.
544
+ *
545
+ * Note that this function is not 'view' (due to implementation details): the client code must explicitly execute
546
+ * eth_call instead of eth_sendTransaction.
547
+ */
548
+ function queryBatchSwap(
549
+ SwapKind kind,
550
+ BatchSwapStep[] calldata swaps,
551
+ IAsset[] calldata assets,
552
+ FundManagement calldata funds
553
+ ) external returns (int256[] memory assetDeltas);
554
+
555
+ function getProtocolFeesCollector() external view returns(address);
556
+
557
+ /**
558
+ * @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
559
+ * and then reverting unless the tokens plus a proportional protocol fee have been returned.
560
+ *
561
+ * The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
562
+ * for each token contract. `tokens` must be sorted in ascending order.
563
+ *
564
+ * The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
565
+ * `receiveFlashLoan` call.
566
+ *
567
+ * Emits `FlashLoan` events.
568
+ */
569
+ function flashLoan(
570
+ address recipient,
571
+ address[] memory tokens,
572
+ uint256[] memory amounts,
573
+ bytes memory userData
574
+ ) external;
575
+
576
+ /**
577
+ * @dev Emitted for each individual flash loan performed by `flashLoan`.
578
+ */
579
+ event FlashLoan(address indexed recipient, address indexed token, uint256 amount, uint256 feeAmount);
580
+ }