@enzymefinance/testutils 4.0.0 → 4.0.3

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.
Files changed (92) hide show
  1. package/dist/index.d.ts +1566 -0
  2. package/dist/index.js +3375 -0
  3. package/dist/index.mjs +3375 -0
  4. package/package.json +74 -11
  5. package/CHANGELOG.md +0 -84
  6. package/dist/declarations/src/assertions.d.ts +0 -4
  7. package/dist/declarations/src/deployment.d.ts +0 -188
  8. package/dist/declarations/src/gasRelayer.d.ts +0 -56
  9. package/dist/declarations/src/helpers.d.ts +0 -16
  10. package/dist/declarations/src/index.d.ts +0 -6
  11. package/dist/declarations/src/scaffolding/assets.d.ts +0 -10
  12. package/dist/declarations/src/scaffolding/chainlink.d.ts +0 -3
  13. package/dist/declarations/src/scaffolding/common.d.ts +0 -7
  14. package/dist/declarations/src/scaffolding/core.d.ts +0 -16
  15. package/dist/declarations/src/scaffolding/extensions/common.d.ts +0 -11
  16. package/dist/declarations/src/scaffolding/extensions/external-positions/aave-debt.d.ts +0 -51
  17. package/dist/declarations/src/scaffolding/extensions/external-positions/actions.d.ts +0 -36
  18. package/dist/declarations/src/scaffolding/extensions/external-positions/compound.d.ts +0 -56
  19. package/dist/declarations/src/scaffolding/extensions/external-positions/index.d.ts +0 -5
  20. package/dist/declarations/src/scaffolding/extensions/external-positions/mocks.d.ts +0 -56
  21. package/dist/declarations/src/scaffolding/extensions/external-positions/uniswap-v3-liquidity.d.ts +0 -100
  22. package/dist/declarations/src/scaffolding/extensions/fees.d.ts +0 -12
  23. package/dist/declarations/src/scaffolding/extensions/index.d.ts +0 -5
  24. package/dist/declarations/src/scaffolding/extensions/integrations/aave.d.ts +0 -20
  25. package/dist/declarations/src/scaffolding/extensions/integrations/compound.d.ts +0 -56
  26. package/dist/declarations/src/scaffolding/extensions/integrations/curve.d.ts +0 -106
  27. package/dist/declarations/src/scaffolding/extensions/integrations/idle.d.ts +0 -28
  28. package/dist/declarations/src/scaffolding/extensions/integrations/index.d.ts +0 -14
  29. package/dist/declarations/src/scaffolding/extensions/integrations/mock.d.ts +0 -32
  30. package/dist/declarations/src/scaffolding/extensions/integrations/olympusV2.d.ts +0 -17
  31. package/dist/declarations/src/scaffolding/extensions/integrations/paraSwapV5.d.ts +0 -23
  32. package/dist/declarations/src/scaffolding/extensions/integrations/poolTogetherV4.d.ts +0 -29
  33. package/dist/declarations/src/scaffolding/extensions/integrations/synthetix.d.ts +0 -28
  34. package/dist/declarations/src/scaffolding/extensions/integrations/trackedAssets.d.ts +0 -15
  35. package/dist/declarations/src/scaffolding/extensions/integrations/uniswapV2.d.ts +0 -46
  36. package/dist/declarations/src/scaffolding/extensions/integrations/uniswapV3.d.ts +0 -15
  37. package/dist/declarations/src/scaffolding/extensions/integrations/yearn.d.ts +0 -22
  38. package/dist/declarations/src/scaffolding/extensions/integrations/zeroExV2.d.ts +0 -12
  39. package/dist/declarations/src/scaffolding/extensions/policies.d.ts +0 -17
  40. package/dist/declarations/src/scaffolding/index.d.ts +0 -8
  41. package/dist/declarations/src/scaffolding/setup.d.ts +0 -77
  42. package/dist/declarations/src/scaffolding/shares.d.ts +0 -35
  43. package/dist/declarations/src/scaffolding/vaultCalls.d.ts +0 -32
  44. package/dist/declarations/src/whales.d.ts +0 -49
  45. package/dist/enzymefinance-testutils.browser.cjs.js +0 -4158
  46. package/dist/enzymefinance-testutils.browser.esm.js +0 -4028
  47. package/dist/enzymefinance-testutils.cjs.d.ts +0 -1
  48. package/dist/enzymefinance-testutils.cjs.dev.js +0 -4158
  49. package/dist/enzymefinance-testutils.cjs.js +0 -7
  50. package/dist/enzymefinance-testutils.cjs.prod.js +0 -4158
  51. package/dist/enzymefinance-testutils.esm.js +0 -4028
  52. package/src/assertions.ts +0 -23
  53. package/src/deployment.ts +0 -280
  54. package/src/gasRelayer.ts +0 -95
  55. package/src/helpers.ts +0 -39
  56. package/src/index.ts +0 -6
  57. package/src/scaffolding/assets.ts +0 -37
  58. package/src/scaffolding/chainlink.ts +0 -8
  59. package/src/scaffolding/common.ts +0 -11
  60. package/src/scaffolding/core.ts +0 -103
  61. package/src/scaffolding/extensions/common.ts +0 -30
  62. package/src/scaffolding/extensions/external-positions/aave-debt.ts +0 -179
  63. package/src/scaffolding/extensions/external-positions/actions.ts +0 -108
  64. package/src/scaffolding/extensions/external-positions/compound.ts +0 -190
  65. package/src/scaffolding/extensions/external-positions/index.ts +0 -5
  66. package/src/scaffolding/extensions/external-positions/mocks.ts +0 -191
  67. package/src/scaffolding/extensions/external-positions/uniswap-v3-liquidity.ts +0 -284
  68. package/src/scaffolding/extensions/fees.ts +0 -70
  69. package/src/scaffolding/extensions/index.ts +0 -5
  70. package/src/scaffolding/extensions/integrations/aave.ts +0 -78
  71. package/src/scaffolding/extensions/integrations/compound.ts +0 -255
  72. package/src/scaffolding/extensions/integrations/curve.ts +0 -354
  73. package/src/scaffolding/extensions/integrations/idle.ts +0 -104
  74. package/src/scaffolding/extensions/integrations/index.ts +0 -14
  75. package/src/scaffolding/extensions/integrations/mock.ts +0 -116
  76. package/src/scaffolding/extensions/integrations/olympusV2.ts +0 -71
  77. package/src/scaffolding/extensions/integrations/paraSwapV5.ts +0 -73
  78. package/src/scaffolding/extensions/integrations/poolTogetherV4.ts +0 -117
  79. package/src/scaffolding/extensions/integrations/synthetix.ts +0 -111
  80. package/src/scaffolding/extensions/integrations/trackedAssets.ts +0 -48
  81. package/src/scaffolding/extensions/integrations/uniswapV2.ts +0 -175
  82. package/src/scaffolding/extensions/integrations/uniswapV3.ts +0 -55
  83. package/src/scaffolding/extensions/integrations/yearn.ts +0 -79
  84. package/src/scaffolding/extensions/integrations/zeroExV2.ts +0 -47
  85. package/src/scaffolding/extensions/policies.ts +0 -112
  86. package/src/scaffolding/index.ts +0 -8
  87. package/src/scaffolding/setup.ts +0 -243
  88. package/src/scaffolding/shares.ts +0 -80
  89. package/src/scaffolding/vaultCalls.ts +0 -105
  90. package/src/types.d.ts +0 -2
  91. package/src/whales.ts +0 -82
  92. package/tsconfig.json +0 -5
package/dist/index.mjs ADDED
@@ -0,0 +1,3375 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/accounts.ts
22
+ import { resolveAddress } from "@enzymefinance/ethers";
23
+
24
+ // src/helpers.ts
25
+ import { SelfDestructEthPayer } from "@enzymefinance/protocol";
26
+ import { BigNumber, utils } from "ethers";
27
+ import { MerkleTree } from "merkletreejs";
28
+ async function calcMlnValueAndBurnAmountForSharesBuyback({
29
+ valueInterpreter,
30
+ mln,
31
+ denominationAsset,
32
+ sharesSupply,
33
+ gav,
34
+ buybackSharesAmount
35
+ }) {
36
+ const grossShareValue = BigNumber.from(gav).mul(utils.parseEther("1")).div(sharesSupply);
37
+ const denominationAssetValueOfBuyback = grossShareValue.mul(buybackSharesAmount).div(utils.parseEther("1"));
38
+ const mlnValueOfBuyback = await valueInterpreter.calcCanonicalAssetValue.args(denominationAsset, denominationAssetValueOfBuyback, mln).call();
39
+ const mlnAmountToBurn = mlnValueOfBuyback.div(2);
40
+ return { mlnAmountToBurn, mlnValue: mlnValueOfBuyback };
41
+ }
42
+ function generateMerkleTreeForContractProof({
43
+ itemArrays,
44
+ itemTypes
45
+ }) {
46
+ const leaves = itemArrays.map((itemArray) => utils.solidityKeccak256(itemTypes, itemArray));
47
+ const tree = new MerkleTree(leaves, utils.keccak256, { sort: true });
48
+ const root = tree.getHexRoot();
49
+ return { leaves, root, tree };
50
+ }
51
+ async function sendEthBySelfDestruct({
52
+ signer,
53
+ recipient,
54
+ amount = utils.parseEther("1")
55
+ }) {
56
+ const selfDestructEthPayer = await SelfDestructEthPayer.deploy(signer);
57
+ await selfDestructEthPayer.destructTo.args(recipient).value(amount).send();
58
+ }
59
+ async function transactionTimestamp(receipt) {
60
+ const block = await provider.getBlock(receipt.blockNumber);
61
+ return block.timestamp;
62
+ }
63
+
64
+ // src/accounts.ts
65
+ async function impersonateContractSigner({
66
+ contractAddress,
67
+ ethSeeder,
68
+ provider: provider2
69
+ }) {
70
+ await sendEthBySelfDestruct({ recipient: contractAddress, signer: ethSeeder });
71
+ return impersonateSigner({
72
+ provider: provider2,
73
+ signerAddress: contractAddress
74
+ });
75
+ }
76
+ async function impersonateSigner({
77
+ signerAddress,
78
+ provider: provider2
79
+ }) {
80
+ await provider2.send("hardhat_impersonateAccount", [signerAddress]);
81
+ return provider2.getSignerWithAddress(resolveAddress(signerAddress));
82
+ }
83
+
84
+ // src/assertions.ts
85
+ import { extractEvent } from "@enzymefinance/ethers";
86
+ function assertEvent(receipt, event, match) {
87
+ var _a;
88
+ const events = extractEvent(receipt, event);
89
+ expect(events.length).toBe(1);
90
+ expect(receipt).toHaveEmittedWith(event, match);
91
+ const args = (_a = events.shift()) == null ? void 0 : _a.args;
92
+ return args;
93
+ }
94
+ function assertNoEvent(receipt, event) {
95
+ const events = extractEvent(receipt, event);
96
+ expect(events.length).toBe(0);
97
+ }
98
+
99
+ // src/deployment.ts
100
+ import {
101
+ AaveAdapter,
102
+ AaveDebtPositionLib,
103
+ AaveDebtPositionParser,
104
+ AavePriceFeed,
105
+ AddressListRegistry,
106
+ AllowedAdapterIncomingAssetsPolicy,
107
+ AllowedAdaptersPolicy,
108
+ AllowedAssetsForRedemptionPolicy,
109
+ AllowedDepositRecipientsPolicy,
110
+ AllowedExternalPositionTypesPolicy,
111
+ AllowedSharesTransferRecipientsPolicy,
112
+ CompoundAdapter,
113
+ CompoundDebtPositionLib,
114
+ CompoundDebtPositionParser,
115
+ CompoundPriceFeed,
116
+ ComptrollerLib,
117
+ ConvexCurveLpStakingAdapter,
118
+ ConvexCurveLpStakingWrapperFactory,
119
+ ConvexCurveLpStakingWrapperPriceFeed,
120
+ ConvexVotingPositionLib,
121
+ ConvexVotingPositionParser,
122
+ CumulativeSlippageTolerancePolicy,
123
+ CurveExchangeAdapter,
124
+ CurveLiquidityAdapter,
125
+ CurvePriceFeed,
126
+ DepositWrapper,
127
+ Dispatcher,
128
+ EntranceRateBurnFee,
129
+ EntranceRateDirectFee,
130
+ ExitRateBurnFee,
131
+ ExitRateDirectFee,
132
+ ExternalPositionFactory,
133
+ ExternalPositionManager,
134
+ FeeManager,
135
+ FundDeployer,
136
+ FundValueCalculator,
137
+ FundValueCalculatorRouter,
138
+ FundValueCalculatorUsdWrapper,
139
+ FuseAdapter,
140
+ FusePriceFeed,
141
+ GasRelayPaymasterFactory,
142
+ GlobalConfigLib,
143
+ IdleAdapter,
144
+ IdlePriceFeed,
145
+ IntegrationManager,
146
+ LidoStethPriceFeed,
147
+ LiquityDebtPositionLib,
148
+ LiquityDebtPositionParser,
149
+ ManagementFee,
150
+ ManualValueOracleFactory,
151
+ MapleLiquidityPositionLib,
152
+ MapleLiquidityPositionParser,
153
+ MinAssetBalancesPostRedemptionPolicy,
154
+ MinMaxInvestmentPolicy,
155
+ OlympusV2Adapter,
156
+ OnlyRemoveDustExternalPositionPolicy,
157
+ OnlyUntrackDustOrPricelessAssetsPolicy,
158
+ ParaSwapV5Adapter,
159
+ PerformanceFee,
160
+ PolicyManager,
161
+ PoolTogetherV4Adapter,
162
+ PoolTogetherV4PriceFeed,
163
+ ProtocolFeeReserveLib,
164
+ ProtocolFeeTracker,
165
+ RevertingPriceFeed,
166
+ SharesSplitterFactory,
167
+ SynthetixAdapter,
168
+ UintListRegistry,
169
+ UniswapV2ExchangeAdapter,
170
+ UniswapV2LiquidityAdapter,
171
+ UniswapV2PoolPriceFeed,
172
+ UniswapV3Adapter,
173
+ UnpermissionedActionsWrapper,
174
+ UsdEthSimulatedAggregator,
175
+ ValueInterpreter,
176
+ VaultLib,
177
+ YearnVaultV2Adapter,
178
+ YearnVaultV2PriceFeed,
179
+ ZeroExV2Adapter
180
+ } from "@enzymefinance/protocol";
181
+ async function getNamedSigner(name) {
182
+ const accounts = await hre.getNamedAccounts();
183
+ if (!accounts[name]) {
184
+ throw new Error(`Missing account with name ${name}`);
185
+ }
186
+ return provider.getSignerWithAddress(accounts[name]);
187
+ }
188
+ async function getUnnamedSigners() {
189
+ const accounts = await hre.getUnnamedAccounts();
190
+ return Promise.all(accounts.map((account) => provider.getSignerWithAddress(account)));
191
+ }
192
+ async function deployProtocolFixture() {
193
+ const fixture = await hre.deployments.fixture();
194
+ const deployer = await getNamedSigner("deployer");
195
+ const accounts = await getUnnamedSigners();
196
+ const config = fixture.Config.linkedData;
197
+ const deployment = {
198
+ aaveAdapter: new AaveAdapter(fixture.AaveAdapter.address, deployer),
199
+ aaveDebtPositionLib: new AaveDebtPositionLib(fixture.AaveDebtPositionLib.address, deployer),
200
+ aaveDebtPositionParser: new AaveDebtPositionParser(fixture.AaveDebtPositionParser.address, deployer),
201
+ aavePriceFeed: new AavePriceFeed(fixture.AavePriceFeed.address, deployer),
202
+ addressListRegistry: new AddressListRegistry(fixture.AddressListRegistry.address, deployer),
203
+ allowedAdapterIncomingAssetsPolicy: new AllowedAdapterIncomingAssetsPolicy(fixture.AllowedAdapterIncomingAssetsPolicy.address, deployer),
204
+ allowedAdaptersPolicy: new AllowedAdaptersPolicy(fixture.AllowedAdaptersPolicy.address, deployer),
205
+ allowedAssetsForRedemptionPolicy: new AllowedAssetsForRedemptionPolicy(fixture.AllowedAssetsForRedemptionPolicy.address, deployer),
206
+ allowedDepositRecipientsPolicy: new AllowedDepositRecipientsPolicy(fixture.AllowedDepositRecipientsPolicy.address, deployer),
207
+ allowedExternalPositionTypesPolicy: new AllowedExternalPositionTypesPolicy(fixture.AllowedExternalPositionTypesPolicy.address, deployer),
208
+ allowedSharesTransferRecipientsPolicy: new AllowedSharesTransferRecipientsPolicy(fixture.AllowedSharesTransferRecipientsPolicy.address, deployer),
209
+ compoundAdapter: new CompoundAdapter(fixture.CompoundAdapter.address, deployer),
210
+ compoundDebtPositionLib: new CompoundDebtPositionLib(fixture.CompoundDebtPositionLib.address, deployer),
211
+ compoundDebtPositionParser: new CompoundDebtPositionParser(fixture.CompoundDebtPositionParser.address, deployer),
212
+ compoundPriceFeed: new CompoundPriceFeed(fixture.CompoundPriceFeed.address, deployer),
213
+ comptrollerLib: new ComptrollerLib(fixture.ComptrollerLib.address, deployer),
214
+ convexCurveLpStakingAdapter: new ConvexCurveLpStakingAdapter(fixture.ConvexCurveLpStakingAdapter.address, deployer),
215
+ convexCurveLpStakingWrapperFactory: new ConvexCurveLpStakingWrapperFactory(fixture.ConvexCurveLpStakingWrapperFactory.address, deployer),
216
+ convexCurveLpStakingWrapperPriceFeed: new ConvexCurveLpStakingWrapperPriceFeed(fixture.ConvexCurveLpStakingWrapperPriceFeed.address, deployer),
217
+ convexVotingPositionLib: new ConvexVotingPositionLib(fixture.ConvexVotingPositionLib.address, deployer),
218
+ convexVotingPositionParser: new ConvexVotingPositionParser(fixture.ConvexVotingPositionParser.address, deployer),
219
+ cumulativeSlippageTolerancePolicy: new CumulativeSlippageTolerancePolicy(fixture.CumulativeSlippageTolerancePolicy.address, deployer),
220
+ curveExchangeAdapter: new CurveExchangeAdapter(fixture.CurveExchangeAdapter.address, deployer),
221
+ curveLiquidityAdapter: new CurveLiquidityAdapter(fixture.CurveLiquidityAdapter.address, deployer),
222
+ curvePriceFeed: new CurvePriceFeed(fixture.CurvePriceFeed.address, deployer),
223
+ depositWrapper: new DepositWrapper(fixture.DepositWrapper.address, deployer),
224
+ dispatcher: new Dispatcher(fixture.Dispatcher.address, deployer),
225
+ entranceRateBurnFee: new EntranceRateBurnFee(fixture.EntranceRateBurnFee.address, deployer),
226
+ entranceRateDirectFee: new EntranceRateDirectFee(fixture.EntranceRateDirectFee.address, deployer),
227
+ exitRateBurnFee: new ExitRateBurnFee(fixture.ExitRateBurnFee.address, deployer),
228
+ exitRateDirectFee: new ExitRateDirectFee(fixture.ExitRateDirectFee.address, deployer),
229
+ externalPositionFactory: new ExternalPositionFactory(fixture.ExternalPositionFactory.address, deployer),
230
+ externalPositionManager: new ExternalPositionManager(fixture.ExternalPositionManager.address, deployer),
231
+ feeManager: new FeeManager(fixture.FeeManager.address, deployer),
232
+ fundDeployer: new FundDeployer(fixture.FundDeployer.address, deployer),
233
+ fundValueCalculator: new FundValueCalculator(fixture.FundValueCalculator.address, deployer),
234
+ fundValueCalculatorRouter: new FundValueCalculatorRouter(fixture.FundValueCalculatorRouter.address, deployer),
235
+ fundValueCalculatorUsdWrapper: new FundValueCalculatorUsdWrapper(fixture.FundValueCalculatorUsdWrapper.address, deployer),
236
+ fuseAdapter: new FuseAdapter(fixture.FuseAdapter.address, deployer),
237
+ fusePriceFeed: new FusePriceFeed(fixture.FusePriceFeed.address, deployer),
238
+ gasRelayPaymasterFactory: new GasRelayPaymasterFactory(fixture.GasRelayPaymasterFactory.address, deployer),
239
+ globalConfigLib: new GlobalConfigLib(fixture.GlobalConfigLib.address, deployer),
240
+ globalConfigProxy: new GlobalConfigLib(fixture.GlobalConfigProxy.address, deployer),
241
+ idleAdapter: new IdleAdapter(fixture.IdleAdapter.address, deployer),
242
+ idlePriceFeed: new IdlePriceFeed(fixture.IdlePriceFeed.address, deployer),
243
+ integrationManager: new IntegrationManager(fixture.IntegrationManager.address, deployer),
244
+ lidoStethPriceFeed: new LidoStethPriceFeed(fixture.LidoStethPriceFeed.address, deployer),
245
+ liquityDebtPositionLib: new LiquityDebtPositionLib(fixture.LiquityDebtPositionLib.address, deployer),
246
+ liquityDebtPositionParser: new LiquityDebtPositionParser(fixture.LiquityDebtPositionParser.address, deployer),
247
+ managementFee: new ManagementFee(fixture.ManagementFee.address, deployer),
248
+ manualValueOracleFactory: new ManualValueOracleFactory(fixture.ManualValueOracleFactory.address, deployer),
249
+ mapleLiquidityPositionLib: new MapleLiquidityPositionLib(fixture.MapleLiquidityPositionLib.address, deployer),
250
+ mapleLiquidityPositionParser: new MapleLiquidityPositionParser(fixture.MapleLiquidityPositionParser.address, deployer),
251
+ minAssetBalancesPostRedemptionPolicy: new MinAssetBalancesPostRedemptionPolicy(fixture.MinAssetBalancesPostRedemptionPolicy.address, deployer),
252
+ minMaxInvestmentPolicy: new MinMaxInvestmentPolicy(fixture.MinMaxInvestmentPolicy.address, deployer),
253
+ olympusV2Adapter: new OlympusV2Adapter(fixture.OlympusV2Adapter.address, deployer),
254
+ onlyRemoveDustExternalPositionPolicy: new OnlyRemoveDustExternalPositionPolicy(fixture.OnlyRemoveDustExternalPositionPolicy.address, deployer),
255
+ onlyUntrackDustOrPricelessAssetsPolicy: new OnlyUntrackDustOrPricelessAssetsPolicy(fixture.OnlyUntrackDustOrPricelessAssetsPolicy.address, deployer),
256
+ paraSwapV5Adapter: new ParaSwapV5Adapter(fixture.ParaSwapV5Adapter.address, deployer),
257
+ performanceFee: new PerformanceFee(fixture.PerformanceFee.address, deployer),
258
+ policyManager: new PolicyManager(fixture.PolicyManager.address, deployer),
259
+ poolTogetherV4Adapter: new PoolTogetherV4Adapter(fixture.PoolTogetherV4Adapter.address, deployer),
260
+ poolTogetherV4PriceFeed: new PoolTogetherV4PriceFeed(fixture.PoolTogetherV4PriceFeed.address, deployer),
261
+ protocolFeeReserveLib: new ProtocolFeeReserveLib(fixture.ProtocolFeeReserveLib.address, deployer),
262
+ protocolFeeReserveProxy: new ProtocolFeeReserveLib(fixture.ProtocolFeeReserveProxy.address, deployer),
263
+ protocolFeeTracker: new ProtocolFeeTracker(fixture.ProtocolFeeTracker.address, deployer),
264
+ revertingPriceFeed: new RevertingPriceFeed(fixture.RevertingPriceFeed.address, deployer),
265
+ sharesSplitterFactory: new SharesSplitterFactory(fixture.SharesSplitterFactory.address, deployer),
266
+ synthetixAdapter: new SynthetixAdapter(fixture.SynthetixAdapter.address, deployer),
267
+ uintListRegistry: new UintListRegistry(fixture.UintListRegistry.address, deployer),
268
+ uniswapV2ExchangeAdapter: new UniswapV2ExchangeAdapter(fixture.UniswapV2ExchangeAdapter.address, deployer),
269
+ uniswapV2LiquidityAdapter: new UniswapV2LiquidityAdapter(fixture.UniswapV2LiquidityAdapter.address, deployer),
270
+ uniswapV2PoolPriceFeed: new UniswapV2PoolPriceFeed(fixture.UniswapV2PoolPriceFeed.address, deployer),
271
+ uniswapV3Adapter: new UniswapV3Adapter(fixture.UniswapV3Adapter.address, deployer),
272
+ unpermissionedActionsWrapper: new UnpermissionedActionsWrapper(fixture.UnpermissionedActionsWrapper.address, deployer),
273
+ usdEthSimulatedAggregator: new UsdEthSimulatedAggregator(fixture.UsdEthSimulatedAggregator.address, deployer),
274
+ valueInterpreter: new ValueInterpreter(fixture.ValueInterpreter.address, deployer),
275
+ vaultLib: new VaultLib(fixture.VaultLib.address, deployer),
276
+ yearnVaultV2Adapter: new YearnVaultV2Adapter(fixture.YearnVaultV2Adapter.address, deployer),
277
+ yearnVaultV2PriceFeed: new YearnVaultV2PriceFeed(fixture.YearnVaultV2PriceFeed.address, deployer),
278
+ zeroExV2Adapter: new ZeroExV2Adapter(fixture.ZeroExV2Adapter.address, deployer)
279
+ };
280
+ return {
281
+ accounts,
282
+ config,
283
+ deployer,
284
+ deployment
285
+ };
286
+ }
287
+
288
+ // src/gasRelayer.ts
289
+ import { createSignedRelayRequest, IGsnRelayHub, isTypedDataSigner } from "@enzymefinance/protocol";
290
+ import { BigNumber as BigNumber2, utils as utils2 } from "ethers";
291
+ async function relayTransaction(options) {
292
+ const signer = options.sendFunction.contract.signer;
293
+ if (!(signer && isTypedDataSigner(signer))) {
294
+ throw new Error("Missing or invalid signer");
295
+ }
296
+ const { relayData, relayRequest, signedRelayRequest } = await createSignedRelayRequest(options);
297
+ const defaultGasLimit = 1245e4;
298
+ const defaultMaxAcceptance = BigNumber2.from(15e4);
299
+ const mergedRelayRequest = {
300
+ relayData,
301
+ request: relayRequest
302
+ };
303
+ const relayHub = new IGsnRelayHub(options.relayHub, provider.getSigner(options.relayWorker));
304
+ return relayHub.relayCall.args(defaultMaxAcceptance, mergedRelayRequest, signedRelayRequest, "0x", defaultGasLimit).gas(defaultGasLimit, relayData.gasPrice).send();
305
+ }
306
+ var relayed = utils2.EventFragment.fromString("TransactionRelayed(address indexed relayManager, address indexed relayWorker, address indexed from, address to, address paymaster, bytes4 selector, uint8 status, uint256 charge)");
307
+ var rejected = utils2.EventFragment.fromString("TransactionRejectedByPaymaster(address indexed relayManager, address indexed paymaster, address indexed from, address to, address relayWorker, bytes4 selector, uint256 innerGasUsed, bytes reason)");
308
+ function assertDidRelay(receipt) {
309
+ return assertEvent(receipt, relayed, {
310
+ charge: expect.anything(),
311
+ from: expect.any(String),
312
+ paymaster: expect.any(String),
313
+ relayManager: expect.any(String),
314
+ relayWorker: expect.any(String),
315
+ selector: expect.any(String),
316
+ status: expect.anything(),
317
+ to: expect.any(String)
318
+ });
319
+ }
320
+ function assertDidRelaySuccessfully(receipt) {
321
+ const result = assertDidRelay(receipt);
322
+ expect(result.status).toEqBigNumber(0);
323
+ }
324
+ function assertDidRelayWithError(receipt) {
325
+ const result = assertDidRelay(receipt);
326
+ expect(result.status).toEqBigNumber(1);
327
+ }
328
+ function assertDidRelayWithCharge(receipt, amount, tolerance) {
329
+ const result = assertDidRelay(receipt);
330
+ expect(result.charge).toBeAroundBigNumber(amount, tolerance);
331
+ }
332
+ function assertPaymasterDidReject(receipt) {
333
+ return assertEvent(receipt, rejected, {
334
+ from: expect.any(String),
335
+ innerGasUsed: expect.anything(),
336
+ paymaster: expect.any(String),
337
+ reason: expect.any(String),
338
+ relayManager: expect.any(String),
339
+ relayWorker: expect.any(String),
340
+ selector: expect.any(String),
341
+ to: expect.any(String)
342
+ });
343
+ }
344
+ function assertPaymasterDidRejectForReason(receipt, reason) {
345
+ const params = assertPaymasterDidReject(receipt);
346
+ expect(utils2.toUtf8String(`0x${params.reason.substr(138)}`)).toMatch(reason);
347
+ }
348
+
349
+ // src/scaffolding/extensions/integrations/trackedAssets.ts
350
+ import {
351
+ addTrackedAssetsToVaultArgs,
352
+ IntegrationManagerActionId,
353
+ removeTrackedAssetsFromVaultArgs
354
+ } from "@enzymefinance/protocol";
355
+ function addTrackedAssetsToVault({
356
+ signer,
357
+ comptrollerProxy,
358
+ integrationManager,
359
+ assets
360
+ }) {
361
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId.AddTrackedAssetsToVault, addTrackedAssetsToVaultArgs({ assets }));
362
+ }
363
+ function removeTrackedAssetsFromVault({
364
+ signer,
365
+ comptrollerProxy,
366
+ integrationManager,
367
+ assets
368
+ }) {
369
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId.RemoveTrackedAssetsFromVault, removeTrackedAssetsFromVaultArgs({ assets }));
370
+ }
371
+
372
+ // src/scaffolding/assets.ts
373
+ async function addNewAssetsToFund({
374
+ signer,
375
+ comptrollerProxy,
376
+ integrationManager,
377
+ assets,
378
+ amounts = new Array(assets.length).fill(1)
379
+ }) {
380
+ const receipt = addTrackedAssetsToVault({
381
+ assets,
382
+ comptrollerProxy,
383
+ integrationManager,
384
+ signer
385
+ });
386
+ const vaultProxy = await comptrollerProxy.getVaultProxy();
387
+ for (const i in assets) {
388
+ if (amounts[i] > 0) {
389
+ await assets[i].transfer(vaultProxy, amounts[i]);
390
+ }
391
+ }
392
+ return receipt;
393
+ }
394
+
395
+ // src/scaffolding/chainlink.ts
396
+ async function updateChainlinkAggregator(aggregator, price) {
397
+ const answer = price != null ? price : await aggregator.latestAnswer();
398
+ const block = await aggregator.provider.getBlock("latest");
399
+ await aggregator.setLatestAnswer(answer, block.timestamp);
400
+ }
401
+
402
+ // src/scaffolding/common.ts
403
+ import { StandardToken } from "@enzymefinance/protocol";
404
+ import { utils as utils3 } from "ethers";
405
+ async function getAssetBalances({ account, assets }) {
406
+ return Promise.all(assets.map((asset) => new StandardToken(asset, provider).balanceOf(account)));
407
+ }
408
+ async function getAssetUnit(asset) {
409
+ return utils3.parseUnits("1", await asset.decimals());
410
+ }
411
+
412
+ // src/scaffolding/core.ts
413
+ import {
414
+ ComptrollerLib as ComptrollerLib2,
415
+ ExternalPositionManager as ExternalPositionManager2,
416
+ FeeManager as FeeManager2,
417
+ FundDeployer as FundDeployer2,
418
+ IntegrationManager as IntegrationManager2,
419
+ PolicyManager as PolicyManager2,
420
+ ProtocolFeeTracker as ProtocolFeeTracker2,
421
+ VaultLib as VaultLib2
422
+ } from "@enzymefinance/protocol";
423
+ async function createFundDeployer({
424
+ deployer,
425
+ externalPositionManager,
426
+ dispatcher,
427
+ gasRelayPaymasterFactory,
428
+ valueInterpreter,
429
+ vaultLib,
430
+ setOnDispatcher = true,
431
+ setReleaseLive = true
432
+ }) {
433
+ const mlnToken = await vaultLib.getMlnToken();
434
+ const wethToken = await vaultLib.getWethToken();
435
+ const protocolFeeReserve = await vaultLib.getProtocolFeeReserve();
436
+ const nextFundDeployer = await FundDeployer2.deploy(deployer, dispatcher, gasRelayPaymasterFactory);
437
+ const nextPolicyManager = await PolicyManager2.deploy(deployer, nextFundDeployer, gasRelayPaymasterFactory);
438
+ const nextExternalPositionManager = await ExternalPositionManager2.deploy(deployer, nextFundDeployer, await externalPositionManager.getExternalPositionFactory(), nextPolicyManager);
439
+ const nextFeeManager = await FeeManager2.deploy(deployer, nextFundDeployer);
440
+ const nextIntegrationManager = await IntegrationManager2.deploy(deployer, nextFundDeployer, nextPolicyManager, valueInterpreter);
441
+ const nextComptrollerLib = await ComptrollerLib2.deploy(deployer, dispatcher, protocolFeeReserve, nextFundDeployer, valueInterpreter, nextExternalPositionManager, nextFeeManager, nextIntegrationManager, nextPolicyManager, gasRelayPaymasterFactory, mlnToken, wethToken);
442
+ await nextFundDeployer.setComptrollerLib(nextComptrollerLib);
443
+ const nextProtocolFeeTracker = await ProtocolFeeTracker2.deploy(deployer, nextFundDeployer);
444
+ await nextFundDeployer.setProtocolFeeTracker(nextProtocolFeeTracker);
445
+ const nextVaultLib = await VaultLib2.deploy(deployer, externalPositionManager, await vaultLib.getGasRelayPaymasterFactory(), await vaultLib.getProtocolFeeReserve(), nextProtocolFeeTracker, await vaultLib.getMlnToken(), await vaultLib.getMlnBurner(), await vaultLib.getWethToken(), await vaultLib.getPositionsLimit());
446
+ await nextFundDeployer.setVaultLib(nextVaultLib);
447
+ if (setReleaseLive) {
448
+ await nextFundDeployer.setReleaseLive();
449
+ }
450
+ if (setOnDispatcher) {
451
+ await dispatcher.setCurrentFundDeployer(nextFundDeployer);
452
+ }
453
+ return nextFundDeployer;
454
+ }
455
+
456
+ // src/scaffolding/extensions/common.ts
457
+ async function callOnExtension({
458
+ comptrollerProxy,
459
+ extension,
460
+ actionId,
461
+ callArgs = "0x",
462
+ signer
463
+ }) {
464
+ let callOnExtensionTx;
465
+ if (signer) {
466
+ callOnExtensionTx = comptrollerProxy.connect(signer).callOnExtension(extension, actionId, callArgs);
467
+ } else {
468
+ callOnExtensionTx = comptrollerProxy.callOnExtension(extension, actionId, callArgs);
469
+ }
470
+ await expect(callOnExtensionTx).resolves.toBeReceipt();
471
+ return callOnExtensionTx;
472
+ }
473
+
474
+ // src/scaffolding/extensions/external-positions/aave-debt.ts
475
+ import {
476
+ AaveDebtPositionActionId,
477
+ aaveDebtPositionAddCollateralArgs,
478
+ aaveDebtPositionBorrowArgs,
479
+ aaveDebtPositionClaimRewardsArgs,
480
+ aaveDebtPositionRemoveCollateralArgs,
481
+ aaveDebtPositionRepayBorrowArgs,
482
+ ExternalPositionType
483
+ } from "@enzymefinance/protocol";
484
+
485
+ // src/scaffolding/extensions/external-positions/actions.ts
486
+ import { extractEvent as extractEvent2 } from "@enzymefinance/ethers";
487
+ import {
488
+ callOnExternalPositionArgs,
489
+ encodeArgs,
490
+ ExternalPositionManagerActionId,
491
+ externalPositionReactivateArgs,
492
+ externalPositionRemoveArgs,
493
+ IExternalPositionProxy
494
+ } from "@enzymefinance/protocol";
495
+ async function callOnExternalPosition({
496
+ signer,
497
+ comptrollerProxy,
498
+ externalPositionManager,
499
+ externalPositionProxy,
500
+ actionId,
501
+ actionArgs
502
+ }) {
503
+ const callArgs = callOnExternalPositionArgs({
504
+ actionArgs,
505
+ actionId,
506
+ externalPositionProxy
507
+ });
508
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CallOnExternalPosition, callArgs);
509
+ }
510
+ async function createExternalPosition({
511
+ signer,
512
+ comptrollerProxy,
513
+ externalPositionManager,
514
+ externalPositionTypeId,
515
+ initializationData = "0x",
516
+ callOnExternalPositionData = "0x"
517
+ }) {
518
+ const receipt = await comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CreateExternalPosition, encodeArgs(["uint256", "bytes", "bytes"], [externalPositionTypeId, initializationData, callOnExternalPositionData]));
519
+ const event = extractEvent2(receipt, externalPositionManager.abi.getEvent("ExternalPositionDeployedForFund"));
520
+ const externalPositionProxy = new IExternalPositionProxy(event[0].args.externalPosition, signer);
521
+ return { externalPositionProxy, receipt };
522
+ }
523
+ async function reactivateExternalPosition({
524
+ signer,
525
+ comptrollerProxy,
526
+ externalPositionManager,
527
+ externalPositionProxy
528
+ }) {
529
+ const callArgs = externalPositionReactivateArgs({ externalPositionProxy });
530
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId.ReactivateExternalPosition, callArgs);
531
+ }
532
+ async function removeExternalPosition({
533
+ signer,
534
+ comptrollerProxy,
535
+ externalPositionManager,
536
+ externalPositionProxy
537
+ }) {
538
+ const callArgs = externalPositionRemoveArgs({ externalPositionProxy });
539
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId.RemoveExternalPosition, callArgs);
540
+ }
541
+
542
+ // src/scaffolding/extensions/external-positions/aave-debt.ts
543
+ async function aaveDebtPositionAddCollateral({
544
+ comptrollerProxy,
545
+ externalPositionManager,
546
+ signer,
547
+ aTokens,
548
+ amounts,
549
+ externalPositionProxy
550
+ }) {
551
+ const actionArgs = aaveDebtPositionAddCollateralArgs({
552
+ aTokens,
553
+ amounts
554
+ });
555
+ return callOnExternalPosition({
556
+ actionArgs,
557
+ actionId: AaveDebtPositionActionId.AddCollateralAssets,
558
+ comptrollerProxy,
559
+ externalPositionManager,
560
+ externalPositionProxy,
561
+ signer
562
+ });
563
+ }
564
+ async function aaveDebtPositionBorrow({
565
+ comptrollerProxy,
566
+ externalPositionManager,
567
+ signer,
568
+ tokens,
569
+ amounts,
570
+ externalPositionProxy
571
+ }) {
572
+ const actionArgs = aaveDebtPositionBorrowArgs({
573
+ amounts,
574
+ tokens
575
+ });
576
+ return callOnExternalPosition({
577
+ actionArgs,
578
+ actionId: AaveDebtPositionActionId.BorrowAsset,
579
+ comptrollerProxy,
580
+ externalPositionManager,
581
+ externalPositionProxy,
582
+ signer
583
+ });
584
+ }
585
+ async function aaveDebtPositionClaimRewards({
586
+ comptrollerProxy,
587
+ externalPositionManager,
588
+ signer,
589
+ assets,
590
+ externalPositionProxy
591
+ }) {
592
+ const actionArgs = aaveDebtPositionClaimRewardsArgs({
593
+ assets
594
+ });
595
+ return callOnExternalPosition({
596
+ actionArgs,
597
+ actionId: AaveDebtPositionActionId.ClaimRewards,
598
+ comptrollerProxy,
599
+ externalPositionManager,
600
+ externalPositionProxy,
601
+ signer
602
+ });
603
+ }
604
+ async function aaveDebtPositionRemoveCollateral({
605
+ comptrollerProxy,
606
+ externalPositionManager,
607
+ signer,
608
+ aTokens,
609
+ amounts,
610
+ externalPositionProxy
611
+ }) {
612
+ const actionArgs = aaveDebtPositionRemoveCollateralArgs({
613
+ aTokens,
614
+ amounts
615
+ });
616
+ return callOnExternalPosition({
617
+ actionArgs,
618
+ actionId: AaveDebtPositionActionId.RemoveCollateralAssets,
619
+ comptrollerProxy,
620
+ externalPositionManager,
621
+ externalPositionProxy,
622
+ signer
623
+ });
624
+ }
625
+ async function aaveDebtPositionRepayBorrow({
626
+ comptrollerProxy,
627
+ externalPositionManager,
628
+ signer,
629
+ tokens,
630
+ amounts,
631
+ externalPositionProxy
632
+ }) {
633
+ const actionArgs = aaveDebtPositionRepayBorrowArgs({
634
+ amounts,
635
+ tokens
636
+ });
637
+ return callOnExternalPosition({
638
+ actionArgs,
639
+ actionId: AaveDebtPositionActionId.RepayBorrowedAssets,
640
+ comptrollerProxy,
641
+ externalPositionManager,
642
+ externalPositionProxy,
643
+ signer
644
+ });
645
+ }
646
+ async function createAaveDebtPosition({
647
+ signer,
648
+ comptrollerProxy,
649
+ externalPositionManager
650
+ }) {
651
+ return createExternalPosition({
652
+ comptrollerProxy,
653
+ externalPositionManager,
654
+ externalPositionTypeId: ExternalPositionType.AaveDebtPosition,
655
+ signer
656
+ });
657
+ }
658
+
659
+ // src/scaffolding/extensions/external-positions/compound.ts
660
+ import {
661
+ CompoundDebtPositionActionId,
662
+ compoundExternalPositionActionArgs,
663
+ encodeArgs as encodeArgs2,
664
+ ExternalPositionType as ExternalPositionType2
665
+ } from "@enzymefinance/protocol";
666
+ async function compoundDebtPositionAddCollateral({
667
+ comptrollerProxy,
668
+ externalPositionManager,
669
+ fundOwner,
670
+ assets,
671
+ amounts,
672
+ externalPositionProxy,
673
+ cTokens
674
+ }) {
675
+ const actionArgs = compoundExternalPositionActionArgs({
676
+ amounts,
677
+ assets,
678
+ data: encodeArgs2(["address[]"], [cTokens])
679
+ });
680
+ return callOnExternalPosition({
681
+ actionArgs,
682
+ actionId: CompoundDebtPositionActionId.AddCollateralAssets,
683
+ comptrollerProxy,
684
+ externalPositionManager,
685
+ externalPositionProxy,
686
+ signer: fundOwner
687
+ });
688
+ }
689
+ async function compoundDebtPositionBorrow({
690
+ comptrollerProxy,
691
+ externalPositionManager,
692
+ fundOwner,
693
+ externalPositionProxy,
694
+ assets,
695
+ amounts,
696
+ cTokens
697
+ }) {
698
+ const actionArgs = compoundExternalPositionActionArgs({
699
+ amounts,
700
+ assets,
701
+ data: encodeArgs2(["address[]"], [cTokens])
702
+ });
703
+ return callOnExternalPosition({
704
+ actionArgs,
705
+ actionId: CompoundDebtPositionActionId.BorrowAsset,
706
+ comptrollerProxy,
707
+ externalPositionManager,
708
+ externalPositionProxy,
709
+ signer: fundOwner
710
+ });
711
+ }
712
+ async function compoundDebtPositionClaimComp({
713
+ comptrollerProxy,
714
+ externalPositionManager,
715
+ fundOwner,
716
+ externalPositionProxy
717
+ }) {
718
+ const actionArgs = compoundExternalPositionActionArgs({
719
+ amounts: [],
720
+ assets: [],
721
+ data: "0x"
722
+ });
723
+ return callOnExternalPosition({
724
+ actionArgs,
725
+ actionId: CompoundDebtPositionActionId.ClaimComp,
726
+ comptrollerProxy,
727
+ externalPositionManager,
728
+ externalPositionProxy,
729
+ signer: fundOwner
730
+ });
731
+ }
732
+ async function compoundDebtPositionRemoveCollateral({
733
+ comptrollerProxy,
734
+ externalPositionManager,
735
+ fundOwner,
736
+ assets,
737
+ amounts,
738
+ externalPositionProxy,
739
+ cTokens
740
+ }) {
741
+ const actionArgs = compoundExternalPositionActionArgs({
742
+ amounts,
743
+ assets,
744
+ data: encodeArgs2(["address[]"], [cTokens])
745
+ });
746
+ return callOnExternalPosition({
747
+ actionArgs,
748
+ actionId: CompoundDebtPositionActionId.RemoveCollateralAssets,
749
+ comptrollerProxy,
750
+ externalPositionManager,
751
+ externalPositionProxy,
752
+ signer: fundOwner
753
+ });
754
+ }
755
+ async function compoundDebtPositionRepayBorrow({
756
+ comptrollerProxy,
757
+ externalPositionManager,
758
+ fundOwner,
759
+ assets,
760
+ amounts,
761
+ externalPositionProxy,
762
+ cTokens
763
+ }) {
764
+ const actionArgs = compoundExternalPositionActionArgs({
765
+ amounts,
766
+ assets,
767
+ data: encodeArgs2(["address[]"], [cTokens])
768
+ });
769
+ return callOnExternalPosition({
770
+ actionArgs,
771
+ actionId: CompoundDebtPositionActionId.RepayBorrowedAssets,
772
+ comptrollerProxy,
773
+ externalPositionManager,
774
+ externalPositionProxy,
775
+ signer: fundOwner
776
+ });
777
+ }
778
+ async function createCompoundDebtPosition({
779
+ signer,
780
+ comptrollerProxy,
781
+ externalPositionManager
782
+ }) {
783
+ return createExternalPosition({
784
+ comptrollerProxy,
785
+ externalPositionManager,
786
+ externalPositionTypeId: ExternalPositionType2.CompoundDebtPosition,
787
+ signer
788
+ });
789
+ }
790
+
791
+ // src/scaffolding/extensions/external-positions/convex-voting.ts
792
+ import {
793
+ ConvexVotingPositionActionId,
794
+ convexVotingPositionClaimRewardsArgs,
795
+ convexVotingPositionDelegateArgs,
796
+ convexVotingPositionLockArgs,
797
+ ExternalPositionType as ExternalPositionType3
798
+ } from "@enzymefinance/protocol";
799
+ import { BigNumber as BigNumber3 } from "ethers";
800
+ function createConvexVotingPosition({
801
+ signer,
802
+ comptrollerProxy,
803
+ externalPositionManager
804
+ }) {
805
+ return createExternalPosition({
806
+ comptrollerProxy,
807
+ externalPositionManager,
808
+ externalPositionTypeId: ExternalPositionType3.ConvexVotingPosition,
809
+ signer
810
+ });
811
+ }
812
+ function convexVotingPositionClaimRewards({
813
+ comptrollerProxy,
814
+ externalPositionManager,
815
+ signer,
816
+ externalPositionProxy,
817
+ claimLockerRewards,
818
+ extraRewardTokens,
819
+ votiumClaims,
820
+ unstakeCvxCrv,
821
+ allTokensToTransfer
822
+ }) {
823
+ const actionArgs = convexVotingPositionClaimRewardsArgs({
824
+ allTokensToTransfer,
825
+ claimLockerRewards,
826
+ extraRewardTokens,
827
+ unstakeCvxCrv,
828
+ votiumClaims
829
+ });
830
+ return callOnExternalPosition({
831
+ actionArgs,
832
+ actionId: ConvexVotingPositionActionId.ClaimRewards,
833
+ comptrollerProxy,
834
+ externalPositionManager,
835
+ externalPositionProxy,
836
+ signer
837
+ });
838
+ }
839
+ function convexVotingPositionDelegate({
840
+ comptrollerProxy,
841
+ externalPositionManager,
842
+ signer,
843
+ externalPositionProxy,
844
+ delegatee
845
+ }) {
846
+ const actionArgs = convexVotingPositionDelegateArgs({
847
+ delegatee
848
+ });
849
+ return callOnExternalPosition({
850
+ actionArgs,
851
+ actionId: ConvexVotingPositionActionId.Delegate,
852
+ comptrollerProxy,
853
+ externalPositionManager,
854
+ externalPositionProxy,
855
+ signer
856
+ });
857
+ }
858
+ function convexVotingPositionLock({
859
+ comptrollerProxy,
860
+ externalPositionManager,
861
+ signer,
862
+ externalPositionProxy,
863
+ amount,
864
+ spendRatio = BigNumber3.from(0)
865
+ }) {
866
+ const actionArgs = convexVotingPositionLockArgs({
867
+ amount,
868
+ spendRatio
869
+ });
870
+ return callOnExternalPosition({
871
+ actionArgs,
872
+ actionId: ConvexVotingPositionActionId.Lock,
873
+ comptrollerProxy,
874
+ externalPositionManager,
875
+ externalPositionProxy,
876
+ signer
877
+ });
878
+ }
879
+ function convexVotingPositionRelock({
880
+ comptrollerProxy,
881
+ externalPositionManager,
882
+ signer,
883
+ externalPositionProxy
884
+ }) {
885
+ return callOnExternalPosition({
886
+ actionArgs: "0x",
887
+ actionId: ConvexVotingPositionActionId.Relock,
888
+ comptrollerProxy,
889
+ externalPositionManager,
890
+ externalPositionProxy,
891
+ signer
892
+ });
893
+ }
894
+ function convexVotingPositionWithdraw({
895
+ comptrollerProxy,
896
+ externalPositionManager,
897
+ signer,
898
+ externalPositionProxy
899
+ }) {
900
+ return callOnExternalPosition({
901
+ actionArgs: "0x",
902
+ actionId: ConvexVotingPositionActionId.Withdraw,
903
+ comptrollerProxy,
904
+ externalPositionManager,
905
+ externalPositionProxy,
906
+ signer
907
+ });
908
+ }
909
+
910
+ // src/scaffolding/extensions/external-positions/liquity-debt.ts
911
+ import { contract } from "@enzymefinance/ethers";
912
+ import {
913
+ ExternalPositionType as ExternalPositionType4,
914
+ LiquityDebtPositionActionId,
915
+ liquityDebtPositionAddCollateralArgs,
916
+ liquityDebtPositionBorrowArgs,
917
+ liquityDebtPositionOpenTroveArgs,
918
+ liquityDebtPositionRemoveCollateralArgs,
919
+ liquityDebtPositionRepayBorrowArgs
920
+ } from "@enzymefinance/protocol";
921
+ import { BigNumber as BigNumber4, utils as utils4 } from "ethers";
922
+ var ILiquityTroveManager = contract()`
923
+ function getBorrowingFee(uint256) external returns (uint256)
924
+ `;
925
+ var ILiquityHintHelper = contract()`
926
+ function getApproxHint(uint256, uint256, uint256) external returns (address, uint256, uint256)
927
+ `;
928
+ var ILiquitySortedTroves = contract()`
929
+ function findInsertPosition(uint256, address, address) external view returns (address, address)
930
+ `;
931
+ async function createLiquityDebtPosition({
932
+ signer,
933
+ comptrollerProxy,
934
+ externalPositionManager
935
+ }) {
936
+ return createExternalPosition({
937
+ comptrollerProxy,
938
+ externalPositionManager,
939
+ externalPositionTypeId: ExternalPositionType4.LiquityDebtPosition,
940
+ signer
941
+ });
942
+ }
943
+ async function liquityCalcHints({
944
+ collateralAmount,
945
+ debtAmount,
946
+ numTrials = BigNumber4.from("100"),
947
+ liquitySortedTroves,
948
+ liquityHintHelper,
949
+ inputRandomSeed = BigNumber4.from("4")
950
+ }) {
951
+ const nicr = collateralAmount.mul(utils4.parseEther("100")).div(debtAmount);
952
+ const approxHint = await liquityHintHelper.getApproxHint.args(nicr, numTrials, inputRandomSeed).call();
953
+ const [upperHint, lowerHint] = await liquitySortedTroves.findInsertPosition.args(nicr, approxHint[0], approxHint[0]).call();
954
+ return { lowerHint, upperHint };
955
+ }
956
+ async function liquityDebtPositionAddCollateral({
957
+ comptrollerProxy,
958
+ externalPositionManager,
959
+ signer,
960
+ collateralAmount,
961
+ upperHint,
962
+ lowerHint,
963
+ externalPositionProxy
964
+ }) {
965
+ const actionArgs = liquityDebtPositionAddCollateralArgs({
966
+ collateralAmount,
967
+ lowerHint,
968
+ upperHint
969
+ });
970
+ return callOnExternalPosition({
971
+ actionArgs,
972
+ actionId: LiquityDebtPositionActionId.AddCollateral,
973
+ comptrollerProxy,
974
+ externalPositionManager,
975
+ externalPositionProxy,
976
+ signer
977
+ });
978
+ }
979
+ async function liquityDebtPositionBorrow({
980
+ comptrollerProxy,
981
+ externalPositionManager,
982
+ signer,
983
+ maxFeePercentage,
984
+ lusdAmount,
985
+ upperHint,
986
+ lowerHint,
987
+ externalPositionProxy
988
+ }) {
989
+ const actionArgs = liquityDebtPositionBorrowArgs({
990
+ lowerHint,
991
+ lusdAmount,
992
+ maxFeePercentage,
993
+ upperHint
994
+ });
995
+ return callOnExternalPosition({
996
+ actionArgs,
997
+ actionId: LiquityDebtPositionActionId.Borrow,
998
+ comptrollerProxy,
999
+ externalPositionManager,
1000
+ externalPositionProxy,
1001
+ signer
1002
+ });
1003
+ }
1004
+ async function liquityDebtPositionCloseTrove({
1005
+ comptrollerProxy,
1006
+ externalPositionManager,
1007
+ signer,
1008
+ externalPositionProxy
1009
+ }) {
1010
+ const actionArgs = "0x";
1011
+ return callOnExternalPosition({
1012
+ actionArgs,
1013
+ actionId: LiquityDebtPositionActionId.CloseTrove,
1014
+ comptrollerProxy,
1015
+ externalPositionManager,
1016
+ externalPositionProxy,
1017
+ signer
1018
+ });
1019
+ }
1020
+ async function liquityDebtPositionOpenTrove({
1021
+ comptrollerProxy,
1022
+ externalPositionManager,
1023
+ signer,
1024
+ maxFeePercentage,
1025
+ collateralAmount,
1026
+ lusdAmount,
1027
+ upperHint,
1028
+ lowerHint,
1029
+ externalPositionProxy
1030
+ }) {
1031
+ const actionArgs = liquityDebtPositionOpenTroveArgs({
1032
+ collateralAmount,
1033
+ lowerHint,
1034
+ lusdAmount,
1035
+ maxFeePercentage,
1036
+ upperHint
1037
+ });
1038
+ return callOnExternalPosition({
1039
+ actionArgs,
1040
+ actionId: LiquityDebtPositionActionId.OpenTrove,
1041
+ comptrollerProxy,
1042
+ externalPositionManager,
1043
+ externalPositionProxy,
1044
+ signer
1045
+ });
1046
+ }
1047
+ async function liquityDebtPositionRemoveCollateral({
1048
+ comptrollerProxy,
1049
+ externalPositionManager,
1050
+ signer,
1051
+ collateralAmount,
1052
+ upperHint,
1053
+ lowerHint,
1054
+ externalPositionProxy
1055
+ }) {
1056
+ const actionArgs = liquityDebtPositionRemoveCollateralArgs({
1057
+ collateralAmount,
1058
+ lowerHint,
1059
+ upperHint
1060
+ });
1061
+ return callOnExternalPosition({
1062
+ actionArgs,
1063
+ actionId: LiquityDebtPositionActionId.RemoveCollateral,
1064
+ comptrollerProxy,
1065
+ externalPositionManager,
1066
+ externalPositionProxy,
1067
+ signer
1068
+ });
1069
+ }
1070
+ async function liquityDebtPositionRepay({
1071
+ comptrollerProxy,
1072
+ externalPositionManager,
1073
+ signer,
1074
+ lusdAmount,
1075
+ upperHint,
1076
+ lowerHint,
1077
+ externalPositionProxy
1078
+ }) {
1079
+ const actionArgs = liquityDebtPositionRepayBorrowArgs({
1080
+ lowerHint,
1081
+ lusdAmount,
1082
+ upperHint
1083
+ });
1084
+ return callOnExternalPosition({
1085
+ actionArgs,
1086
+ actionId: LiquityDebtPositionActionId.Repay,
1087
+ comptrollerProxy,
1088
+ externalPositionManager,
1089
+ externalPositionProxy,
1090
+ signer
1091
+ });
1092
+ }
1093
+
1094
+ // src/scaffolding/extensions/external-positions/maple-liquidity.ts
1095
+ import {
1096
+ ExternalPositionType as ExternalPositionType5,
1097
+ MapleLiquidityPositionActionId,
1098
+ mapleLiquidityPositionClaimInterestArgs,
1099
+ mapleLiquidityPositionClaimRewardsArgs,
1100
+ mapleLiquidityPositionIntendToRedeemArgs,
1101
+ mapleLiquidityPositionLendAndStakeArgs,
1102
+ mapleLiquidityPositionLendArgs,
1103
+ mapleLiquidityPositionRedeemArgs,
1104
+ mapleLiquidityPositionStakeArgs,
1105
+ mapleLiquidityPositionUnstakeAndRedeemArgs,
1106
+ mapleLiquidityPositionUnstakeArgs
1107
+ } from "@enzymefinance/protocol";
1108
+ async function createMapleLiquidityPosition({
1109
+ signer,
1110
+ comptrollerProxy,
1111
+ externalPositionManager
1112
+ }) {
1113
+ return createExternalPosition({
1114
+ comptrollerProxy,
1115
+ externalPositionManager,
1116
+ externalPositionTypeId: ExternalPositionType5.MapleLiquidityPosition,
1117
+ signer
1118
+ });
1119
+ }
1120
+ async function mapleLiquidityPositionClaimInterest({
1121
+ comptrollerProxy,
1122
+ externalPositionManager,
1123
+ signer,
1124
+ pool,
1125
+ externalPositionProxy
1126
+ }) {
1127
+ const actionArgs = mapleLiquidityPositionClaimInterestArgs({
1128
+ pool
1129
+ });
1130
+ return callOnExternalPosition({
1131
+ actionArgs,
1132
+ actionId: MapleLiquidityPositionActionId.ClaimInterest,
1133
+ comptrollerProxy,
1134
+ externalPositionManager,
1135
+ externalPositionProxy,
1136
+ signer
1137
+ });
1138
+ }
1139
+ async function mapleLiquidityPositionClaimRewards({
1140
+ comptrollerProxy,
1141
+ externalPositionManager,
1142
+ signer,
1143
+ rewardsContract,
1144
+ externalPositionProxy
1145
+ }) {
1146
+ const actionArgs = mapleLiquidityPositionClaimRewardsArgs({
1147
+ rewardsContract
1148
+ });
1149
+ return callOnExternalPosition({
1150
+ actionArgs,
1151
+ actionId: MapleLiquidityPositionActionId.ClaimRewards,
1152
+ comptrollerProxy,
1153
+ externalPositionManager,
1154
+ externalPositionProxy,
1155
+ signer
1156
+ });
1157
+ }
1158
+ async function mapleLiquidityPositionIntendToRedeem({
1159
+ comptrollerProxy,
1160
+ externalPositionManager,
1161
+ signer,
1162
+ pool,
1163
+ externalPositionProxy
1164
+ }) {
1165
+ const actionArgs = mapleLiquidityPositionIntendToRedeemArgs({
1166
+ pool
1167
+ });
1168
+ return callOnExternalPosition({
1169
+ actionArgs,
1170
+ actionId: MapleLiquidityPositionActionId.IntendToRedeem,
1171
+ comptrollerProxy,
1172
+ externalPositionManager,
1173
+ externalPositionProxy,
1174
+ signer
1175
+ });
1176
+ }
1177
+ async function mapleLiquidityPositionLend({
1178
+ comptrollerProxy,
1179
+ externalPositionManager,
1180
+ signer,
1181
+ liquidityAssetAmount,
1182
+ pool,
1183
+ externalPositionProxy
1184
+ }) {
1185
+ const actionArgs = mapleLiquidityPositionLendArgs({
1186
+ liquidityAssetAmount,
1187
+ pool
1188
+ });
1189
+ return callOnExternalPosition({
1190
+ actionArgs,
1191
+ actionId: MapleLiquidityPositionActionId.Lend,
1192
+ comptrollerProxy,
1193
+ externalPositionManager,
1194
+ externalPositionProxy,
1195
+ signer
1196
+ });
1197
+ }
1198
+ async function mapleLiquidityPositionLendAndStake({
1199
+ comptrollerProxy,
1200
+ externalPositionManager,
1201
+ signer,
1202
+ liquidityAssetAmount,
1203
+ pool,
1204
+ rewardsContract,
1205
+ externalPositionProxy
1206
+ }) {
1207
+ const actionArgs = mapleLiquidityPositionLendAndStakeArgs({
1208
+ liquidityAssetAmount,
1209
+ pool,
1210
+ rewardsContract
1211
+ });
1212
+ return callOnExternalPosition({
1213
+ actionArgs,
1214
+ actionId: MapleLiquidityPositionActionId.LendAndStake,
1215
+ comptrollerProxy,
1216
+ externalPositionManager,
1217
+ externalPositionProxy,
1218
+ signer
1219
+ });
1220
+ }
1221
+ async function mapleLiquidityPositionRedeem({
1222
+ comptrollerProxy,
1223
+ externalPositionManager,
1224
+ signer,
1225
+ liquidityAssetAmount,
1226
+ pool,
1227
+ externalPositionProxy
1228
+ }) {
1229
+ const actionArgs = mapleLiquidityPositionRedeemArgs({
1230
+ liquidityAssetAmount,
1231
+ pool
1232
+ });
1233
+ return callOnExternalPosition({
1234
+ actionArgs,
1235
+ actionId: MapleLiquidityPositionActionId.Redeem,
1236
+ comptrollerProxy,
1237
+ externalPositionManager,
1238
+ externalPositionProxy,
1239
+ signer
1240
+ });
1241
+ }
1242
+ async function mapleLiquidityPositionStake({
1243
+ comptrollerProxy,
1244
+ externalPositionManager,
1245
+ signer,
1246
+ poolTokenAmount,
1247
+ pool,
1248
+ rewardsContract,
1249
+ externalPositionProxy
1250
+ }) {
1251
+ const actionArgs = mapleLiquidityPositionStakeArgs({
1252
+ pool,
1253
+ poolTokenAmount,
1254
+ rewardsContract
1255
+ });
1256
+ return callOnExternalPosition({
1257
+ actionArgs,
1258
+ actionId: MapleLiquidityPositionActionId.Stake,
1259
+ comptrollerProxy,
1260
+ externalPositionManager,
1261
+ externalPositionProxy,
1262
+ signer
1263
+ });
1264
+ }
1265
+ async function mapleLiquidityPositionUnstake({
1266
+ comptrollerProxy,
1267
+ externalPositionManager,
1268
+ signer,
1269
+ poolTokenAmount,
1270
+ rewardsContract,
1271
+ externalPositionProxy
1272
+ }) {
1273
+ const actionArgs = mapleLiquidityPositionUnstakeArgs({
1274
+ poolTokenAmount,
1275
+ rewardsContract
1276
+ });
1277
+ return callOnExternalPosition({
1278
+ actionArgs,
1279
+ actionId: MapleLiquidityPositionActionId.Unstake,
1280
+ comptrollerProxy,
1281
+ externalPositionManager,
1282
+ externalPositionProxy,
1283
+ signer
1284
+ });
1285
+ }
1286
+ async function mapleLiquidityPositionUnstakeAndRedeem({
1287
+ comptrollerProxy,
1288
+ externalPositionManager,
1289
+ signer,
1290
+ pool,
1291
+ poolTokenAmount,
1292
+ rewardsContract,
1293
+ externalPositionProxy
1294
+ }) {
1295
+ const actionArgs = mapleLiquidityPositionUnstakeAndRedeemArgs({
1296
+ pool,
1297
+ poolTokenAmount,
1298
+ rewardsContract
1299
+ });
1300
+ return callOnExternalPosition({
1301
+ actionArgs,
1302
+ actionId: MapleLiquidityPositionActionId.UnstakeAndRedeem,
1303
+ comptrollerProxy,
1304
+ externalPositionManager,
1305
+ externalPositionProxy,
1306
+ signer
1307
+ });
1308
+ }
1309
+
1310
+ // src/scaffolding/extensions/external-positions/mocks.ts
1311
+ import {
1312
+ mockGenericExternalPositionActionArgs,
1313
+ MockGenericExternalPositionActionId,
1314
+ MockGenericExternalPositionLib,
1315
+ MockGenericExternalPositionParser,
1316
+ VaultLib as VaultLib3
1317
+ } from "@enzymefinance/protocol";
1318
+ async function createMockExternalPosition({
1319
+ comptrollerProxy,
1320
+ externalPositionManager,
1321
+ externalPositionFactory,
1322
+ defaultActionAssetsToTransfer,
1323
+ defaultActionAmountsToTransfer,
1324
+ defaultActionAssetsToReceive,
1325
+ fundOwner,
1326
+ deployer
1327
+ }) {
1328
+ const vaultProxy = new VaultLib3(await comptrollerProxy.getVaultProxy(), deployer);
1329
+ const typeId = await externalPositionFactory.getPositionTypeCounter();
1330
+ await externalPositionFactory.addNewPositionTypes(["TEST"]);
1331
+ const mockGenericExternalPositionLib = await MockGenericExternalPositionLib.deploy(deployer);
1332
+ const mockExternalPositionParser = await MockGenericExternalPositionParser.deploy(deployer);
1333
+ mockExternalPositionParser.setAssetsForAction(0, defaultActionAssetsToTransfer, defaultActionAmountsToTransfer, defaultActionAssetsToReceive);
1334
+ await externalPositionManager.updateExternalPositionTypesInfo([typeId], [mockGenericExternalPositionLib], [mockExternalPositionParser]);
1335
+ const receipt = await createExternalPosition({
1336
+ comptrollerProxy,
1337
+ externalPositionManager,
1338
+ externalPositionTypeId: typeId,
1339
+ signer: fundOwner
1340
+ });
1341
+ const externalPositionProxy = (await vaultProxy.getActiveExternalPositions())[0];
1342
+ return {
1343
+ externalPositionProxy,
1344
+ mockExternalPositionParser,
1345
+ mockGenericExternalPositionLib,
1346
+ receipt,
1347
+ typeId
1348
+ };
1349
+ }
1350
+ async function mockExternalPositionAddDebtAssets({
1351
+ signer,
1352
+ comptrollerProxy,
1353
+ externalPositionManager,
1354
+ externalPositionProxy,
1355
+ assets,
1356
+ amounts
1357
+ }) {
1358
+ const actionArgs = mockGenericExternalPositionActionArgs({
1359
+ amounts,
1360
+ assets
1361
+ });
1362
+ return callOnExternalPosition({
1363
+ actionArgs,
1364
+ actionId: MockGenericExternalPositionActionId.AddDebtAssets,
1365
+ comptrollerProxy,
1366
+ externalPositionManager,
1367
+ externalPositionProxy,
1368
+ signer
1369
+ });
1370
+ }
1371
+ async function mockExternalPositionAddManagedAssets({
1372
+ signer,
1373
+ comptrollerProxy,
1374
+ externalPositionManager,
1375
+ externalPositionProxy,
1376
+ assets,
1377
+ amounts
1378
+ }) {
1379
+ const actionArgs = mockGenericExternalPositionActionArgs({
1380
+ amounts,
1381
+ assets
1382
+ });
1383
+ return callOnExternalPosition({
1384
+ actionArgs,
1385
+ actionId: MockGenericExternalPositionActionId.AddManagedAssets,
1386
+ comptrollerProxy,
1387
+ externalPositionManager,
1388
+ externalPositionProxy,
1389
+ signer
1390
+ });
1391
+ }
1392
+ async function mockExternalPositionRemoveDebtAssets({
1393
+ signer,
1394
+ comptrollerProxy,
1395
+ externalPositionManager,
1396
+ externalPositionProxy,
1397
+ assets,
1398
+ amounts
1399
+ }) {
1400
+ const actionArgs = mockGenericExternalPositionActionArgs({
1401
+ amounts,
1402
+ assets
1403
+ });
1404
+ return callOnExternalPosition({
1405
+ actionArgs,
1406
+ actionId: MockGenericExternalPositionActionId.RemoveDebtAssets,
1407
+ comptrollerProxy,
1408
+ externalPositionManager,
1409
+ externalPositionProxy,
1410
+ signer
1411
+ });
1412
+ }
1413
+ async function mockExternalPositionRemoveManagedAssets({
1414
+ signer,
1415
+ comptrollerProxy,
1416
+ externalPositionManager,
1417
+ externalPositionProxy,
1418
+ assets,
1419
+ amounts
1420
+ }) {
1421
+ const actionArgs = mockGenericExternalPositionActionArgs({
1422
+ amounts,
1423
+ assets
1424
+ });
1425
+ return callOnExternalPosition({
1426
+ actionArgs,
1427
+ actionId: MockGenericExternalPositionActionId.RemoveManagedAssets,
1428
+ comptrollerProxy,
1429
+ externalPositionManager,
1430
+ externalPositionProxy,
1431
+ signer
1432
+ });
1433
+ }
1434
+
1435
+ // src/scaffolding/extensions/external-positions/the-graph-delegation.ts
1436
+ import {
1437
+ ExternalPositionType as ExternalPositionType6,
1438
+ TheGraphDelegationPositionActionId,
1439
+ theGraphDelegationPositionDelegateArgs,
1440
+ theGraphDelegationPositionUndelegateArgs,
1441
+ theGraphDelegationPositionWithdrawArgs
1442
+ } from "@enzymefinance/protocol";
1443
+ async function theGraphDelegationPositionDelegate({
1444
+ comptrollerProxy,
1445
+ externalPositionManager,
1446
+ signer,
1447
+ indexer,
1448
+ tokens,
1449
+ externalPositionProxy
1450
+ }) {
1451
+ const actionArgs = theGraphDelegationPositionDelegateArgs({
1452
+ indexer,
1453
+ tokens
1454
+ });
1455
+ return callOnExternalPosition({
1456
+ actionArgs,
1457
+ actionId: TheGraphDelegationPositionActionId.Delegate,
1458
+ comptrollerProxy,
1459
+ externalPositionManager,
1460
+ externalPositionProxy,
1461
+ signer
1462
+ });
1463
+ }
1464
+ async function theGraphDelegationPositionUndelegate({
1465
+ comptrollerProxy,
1466
+ externalPositionManager,
1467
+ signer,
1468
+ indexer,
1469
+ shares,
1470
+ externalPositionProxy
1471
+ }) {
1472
+ const actionArgs = theGraphDelegationPositionUndelegateArgs({
1473
+ indexer,
1474
+ shares
1475
+ });
1476
+ return callOnExternalPosition({
1477
+ actionArgs,
1478
+ actionId: TheGraphDelegationPositionActionId.Undelegate,
1479
+ comptrollerProxy,
1480
+ externalPositionManager,
1481
+ externalPositionProxy,
1482
+ signer
1483
+ });
1484
+ }
1485
+ async function theGraphDelegationPositionWithdraw({
1486
+ comptrollerProxy,
1487
+ externalPositionManager,
1488
+ signer,
1489
+ indexer,
1490
+ nextIndexer,
1491
+ externalPositionProxy
1492
+ }) {
1493
+ const actionArgs = theGraphDelegationPositionWithdrawArgs({
1494
+ indexer,
1495
+ nextIndexer
1496
+ });
1497
+ return callOnExternalPosition({
1498
+ actionArgs,
1499
+ actionId: TheGraphDelegationPositionActionId.Withdraw,
1500
+ comptrollerProxy,
1501
+ externalPositionManager,
1502
+ externalPositionProxy,
1503
+ signer
1504
+ });
1505
+ }
1506
+ async function createTheGraphDelegationPosition({
1507
+ signer,
1508
+ comptrollerProxy,
1509
+ externalPositionManager
1510
+ }) {
1511
+ return createExternalPosition({
1512
+ comptrollerProxy,
1513
+ externalPositionManager,
1514
+ externalPositionTypeId: ExternalPositionType6.TheGraphDelegationPosition,
1515
+ signer
1516
+ });
1517
+ }
1518
+
1519
+ // src/scaffolding/extensions/external-positions/uniswap-v3-liquidity.ts
1520
+ import { contract as contract2, extractEvent as extractEvent3, resolveAddress as resolveAddress2 } from "@enzymefinance/ethers";
1521
+ import {
1522
+ callOnExternalPositionArgs as callOnExternalPositionArgs2,
1523
+ ExternalPositionManagerActionId as ExternalPositionManagerActionId2,
1524
+ ExternalPositionType as ExternalPositionType7,
1525
+ UniswapV3LiquidityPositionActionId,
1526
+ uniswapV3LiquidityPositionAddLiquidityArgs,
1527
+ uniswapV3LiquidityPositionCollectArgs,
1528
+ UniswapV3LiquidityPositionLib,
1529
+ uniswapV3LiquidityPositionMintArgs,
1530
+ uniswapV3LiquidityPositionPurgeArgs,
1531
+ uniswapV3LiquidityPositionRemoveLiquidityArgs
1532
+ } from "@enzymefinance/protocol";
1533
+ var UniswapV3FeeAmount = /* @__PURE__ */ ((UniswapV3FeeAmount2) => {
1534
+ UniswapV3FeeAmount2[UniswapV3FeeAmount2["LOW"] = 500] = "LOW";
1535
+ UniswapV3FeeAmount2[UniswapV3FeeAmount2["MEDIUM"] = 3e3] = "MEDIUM";
1536
+ UniswapV3FeeAmount2[UniswapV3FeeAmount2["HIGH"] = 1e4] = "HIGH";
1537
+ return UniswapV3FeeAmount2;
1538
+ })(UniswapV3FeeAmount || {});
1539
+ var uniswapV3LiquidityPositionGetMinTick = (tickSpacing) => Math.ceil(-887272 / tickSpacing) * tickSpacing;
1540
+ var uniswapV3LiquidityPositionGetMaxTick = (tickSpacing) => Math.floor(887272 / tickSpacing) * tickSpacing;
1541
+ var IUniswapV3NonFungibleTokenManager = contract2()`
1542
+ function positions(uint256 tokenId) view returns (uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1)
1543
+ `;
1544
+ async function createUniswapV3LiquidityPosition({
1545
+ signer,
1546
+ comptrollerProxy,
1547
+ externalPositionManager,
1548
+ callOnExternalPositionData = "0x"
1549
+ }) {
1550
+ const { externalPositionProxy: externalPositionProxyContract, receipt } = await createExternalPosition({
1551
+ callOnExternalPositionData,
1552
+ comptrollerProxy,
1553
+ externalPositionManager,
1554
+ externalPositionTypeId: ExternalPositionType7.UniswapV3LiquidityPosition,
1555
+ signer
1556
+ });
1557
+ return { externalPositionProxyAddress: externalPositionProxyContract.address, receipt };
1558
+ }
1559
+ async function uniswapV3LiquidityPositionAddLiquidity({
1560
+ signer,
1561
+ comptrollerProxy,
1562
+ externalPositionManager,
1563
+ externalPositionProxy,
1564
+ nftId,
1565
+ amount0Desired,
1566
+ amount1Desired,
1567
+ amount0Min = 0,
1568
+ amount1Min = 0
1569
+ }) {
1570
+ const actionArgs = uniswapV3LiquidityPositionAddLiquidityArgs({
1571
+ amount0Desired,
1572
+ amount0Min,
1573
+ amount1Desired,
1574
+ amount1Min,
1575
+ nftId
1576
+ });
1577
+ const callArgs = callOnExternalPositionArgs2({
1578
+ actionArgs,
1579
+ actionId: UniswapV3LiquidityPositionActionId.AddLiquidity,
1580
+ externalPositionProxy
1581
+ });
1582
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId2.CallOnExternalPosition, callArgs);
1583
+ }
1584
+ async function uniswapV3LiquidityPositionCollect({
1585
+ signer,
1586
+ comptrollerProxy,
1587
+ externalPositionManager,
1588
+ externalPositionProxy,
1589
+ nftId
1590
+ }) {
1591
+ const actionArgs = uniswapV3LiquidityPositionCollectArgs({
1592
+ nftId
1593
+ });
1594
+ const callArgs = callOnExternalPositionArgs2({
1595
+ actionArgs,
1596
+ actionId: UniswapV3LiquidityPositionActionId.Collect,
1597
+ externalPositionProxy
1598
+ });
1599
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId2.CallOnExternalPosition, callArgs);
1600
+ }
1601
+ async function uniswapV3LiquidityPositionMint({
1602
+ signer,
1603
+ comptrollerProxy,
1604
+ externalPositionManager,
1605
+ externalPositionProxy,
1606
+ token0,
1607
+ token1,
1608
+ fee,
1609
+ tickLower,
1610
+ tickUpper,
1611
+ amount0Desired,
1612
+ amount1Desired,
1613
+ amount0Min = 0,
1614
+ amount1Min = 0
1615
+ }) {
1616
+ const actionArgs = uniswapV3LiquidityPositionMintArgs({
1617
+ amount0Desired,
1618
+ amount0Min,
1619
+ amount1Desired,
1620
+ amount1Min,
1621
+ fee,
1622
+ tickLower,
1623
+ tickUpper,
1624
+ token0,
1625
+ token1
1626
+ });
1627
+ const callArgs = callOnExternalPositionArgs2({
1628
+ actionArgs,
1629
+ actionId: UniswapV3LiquidityPositionActionId.Mint,
1630
+ externalPositionProxy
1631
+ });
1632
+ const receipt = await comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId2.CallOnExternalPosition, callArgs);
1633
+ const externalPosition = new UniswapV3LiquidityPositionLib(externalPositionProxy, provider);
1634
+ const nftId = extractEvent3(receipt, externalPosition.abi.getEvent("NFTPositionAdded"))[0].args.tokenId;
1635
+ return { nftId, receipt };
1636
+ }
1637
+ async function uniswapV3LiquidityPositionPurge({
1638
+ signer,
1639
+ comptrollerProxy,
1640
+ externalPositionManager,
1641
+ externalPositionProxy,
1642
+ nftId,
1643
+ liquidity,
1644
+ amount0Min = 0,
1645
+ amount1Min = 0
1646
+ }) {
1647
+ const actionArgs = uniswapV3LiquidityPositionPurgeArgs({
1648
+ amount0Min,
1649
+ amount1Min,
1650
+ liquidity,
1651
+ nftId
1652
+ });
1653
+ const callArgs = callOnExternalPositionArgs2({
1654
+ actionArgs,
1655
+ actionId: UniswapV3LiquidityPositionActionId.Purge,
1656
+ externalPositionProxy
1657
+ });
1658
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId2.CallOnExternalPosition, callArgs);
1659
+ }
1660
+ async function uniswapV3LiquidityPositionRemoveLiquidity({
1661
+ signer,
1662
+ comptrollerProxy,
1663
+ externalPositionManager,
1664
+ externalPositionProxy,
1665
+ nftId,
1666
+ liquidity,
1667
+ amount0Min = 0,
1668
+ amount1Min = 0
1669
+ }) {
1670
+ const actionArgs = uniswapV3LiquidityPositionRemoveLiquidityArgs({
1671
+ amount0Min,
1672
+ amount1Min,
1673
+ liquidity,
1674
+ nftId
1675
+ });
1676
+ const callArgs = callOnExternalPositionArgs2({
1677
+ actionArgs,
1678
+ actionId: UniswapV3LiquidityPositionActionId.RemoveLiquidity,
1679
+ externalPositionProxy
1680
+ });
1681
+ return comptrollerProxy.connect(signer).callOnExtension(externalPositionManager, ExternalPositionManagerActionId2.CallOnExternalPosition, callArgs);
1682
+ }
1683
+ function uniswapV3OrderTokenPair({ tokenA, tokenB }) {
1684
+ const tokenAAddress = resolveAddress2(tokenA);
1685
+ const tokenBAddress = resolveAddress2(tokenB);
1686
+ return tokenAAddress < tokenBAddress ? { token0: tokenAAddress, token1: tokenBAddress } : { token0: tokenBAddress, token1: tokenAAddress };
1687
+ }
1688
+
1689
+ // src/scaffolding/extensions/fees.ts
1690
+ import { FeeHook, feeManagerConfigArgs, FeeSettlementType, IFee } from "@enzymefinance/protocol";
1691
+ import { constants, utils as utils5 } from "ethers";
1692
+ async function generateFeeManagerConfigWithMockFees({ deployer }) {
1693
+ const fees = await generateMockFees({
1694
+ deployer
1695
+ });
1696
+ const feeManagerSettingsData = [utils5.randomBytes(10), "0x", utils5.randomBytes(2)];
1697
+ return feeManagerConfigArgs({
1698
+ fees: Object.values(fees),
1699
+ settings: feeManagerSettingsData
1700
+ });
1701
+ }
1702
+ async function generateMockFees({ deployer }) {
1703
+ const mockContinuousFeeSettleOnly = await IFee.mock(deployer);
1704
+ const mockContinuousFeeWithGavAndUpdates = await IFee.mock(deployer);
1705
+ const mockPostBuySharesFee = await IFee.mock(deployer);
1706
+ await Promise.all([
1707
+ mockContinuousFeeSettleOnly.getRecipientForFund.returns(constants.AddressZero),
1708
+ mockContinuousFeeSettleOnly.settle.returns(FeeSettlementType.None, constants.AddressZero, 0),
1709
+ mockContinuousFeeSettleOnly.payout.returns(false),
1710
+ mockContinuousFeeSettleOnly.addFundSettings.returns(void 0),
1711
+ mockContinuousFeeSettleOnly.activateForFund.returns(void 0),
1712
+ mockContinuousFeeSettleOnly.update.returns(void 0),
1713
+ mockContinuousFeeSettleOnly.settlesOnHook.returns(false, false),
1714
+ mockContinuousFeeSettleOnly.settlesOnHook.given(FeeHook.Continuous).returns(true, false),
1715
+ mockContinuousFeeSettleOnly.settlesOnHook.given(FeeHook.PreBuyShares).returns(true, false),
1716
+ mockContinuousFeeSettleOnly.settlesOnHook.given(FeeHook.PreRedeemShares).returns(true, false),
1717
+ mockContinuousFeeSettleOnly.updatesOnHook.returns(false, false),
1718
+ mockContinuousFeeWithGavAndUpdates.getRecipientForFund.returns(constants.AddressZero),
1719
+ mockContinuousFeeWithGavAndUpdates.settle.returns(FeeSettlementType.None, constants.AddressZero, 0),
1720
+ mockContinuousFeeWithGavAndUpdates.payout.returns(false),
1721
+ mockContinuousFeeWithGavAndUpdates.addFundSettings.returns(void 0),
1722
+ mockContinuousFeeWithGavAndUpdates.activateForFund.returns(void 0),
1723
+ mockContinuousFeeWithGavAndUpdates.update.returns(void 0),
1724
+ mockContinuousFeeWithGavAndUpdates.settlesOnHook.returns(false, false),
1725
+ mockContinuousFeeWithGavAndUpdates.settlesOnHook.given(FeeHook.Continuous).returns(true, true),
1726
+ mockContinuousFeeWithGavAndUpdates.settlesOnHook.given(FeeHook.PreBuyShares).returns(true, true),
1727
+ mockContinuousFeeWithGavAndUpdates.settlesOnHook.given(FeeHook.PreRedeemShares).returns(true, true),
1728
+ mockContinuousFeeWithGavAndUpdates.updatesOnHook.returns(false, false),
1729
+ mockContinuousFeeWithGavAndUpdates.updatesOnHook.given(FeeHook.Continuous).returns(true, true),
1730
+ mockContinuousFeeWithGavAndUpdates.updatesOnHook.given(FeeHook.PostBuyShares).returns(true, true),
1731
+ mockContinuousFeeWithGavAndUpdates.updatesOnHook.given(FeeHook.PreRedeemShares).returns(true, true),
1732
+ mockPostBuySharesFee.getRecipientForFund.returns(constants.AddressZero),
1733
+ mockPostBuySharesFee.settle.returns(FeeSettlementType.None, constants.AddressZero, 0),
1734
+ mockPostBuySharesFee.payout.returns(false),
1735
+ mockPostBuySharesFee.addFundSettings.returns(void 0),
1736
+ mockPostBuySharesFee.activateForFund.returns(void 0),
1737
+ mockPostBuySharesFee.update.returns(void 0),
1738
+ mockPostBuySharesFee.settlesOnHook.returns(false, false),
1739
+ mockPostBuySharesFee.settlesOnHook.given(FeeHook.PostBuyShares).returns(true, false),
1740
+ mockPostBuySharesFee.updatesOnHook.returns(false, false)
1741
+ ]);
1742
+ return {
1743
+ mockContinuousFeeSettleOnly,
1744
+ mockContinuousFeeWithGavAndUpdates,
1745
+ mockPostBuySharesFee
1746
+ };
1747
+ }
1748
+
1749
+ // src/scaffolding/extensions/integrations/aave.ts
1750
+ import {
1751
+ aaveLendArgs,
1752
+ aaveRedeemArgs,
1753
+ callOnIntegrationArgs,
1754
+ IntegrationManagerActionId as IntegrationManagerActionId2,
1755
+ lendSelector,
1756
+ redeemSelector
1757
+ } from "@enzymefinance/protocol";
1758
+ import { utils as utils6 } from "ethers";
1759
+ async function aaveLend({
1760
+ comptrollerProxy,
1761
+ integrationManager,
1762
+ fundOwner,
1763
+ aaveAdapter,
1764
+ aToken,
1765
+ amount = utils6.parseEther("1")
1766
+ }) {
1767
+ const lendArgs = aaveLendArgs({
1768
+ aToken,
1769
+ amount
1770
+ });
1771
+ const callArgs = callOnIntegrationArgs({
1772
+ adapter: aaveAdapter,
1773
+ encodedCallArgs: lendArgs,
1774
+ selector: lendSelector
1775
+ });
1776
+ const lendTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId2.CallOnIntegration, callArgs);
1777
+ return lendTx;
1778
+ }
1779
+ async function aaveRedeem({
1780
+ comptrollerProxy,
1781
+ integrationManager,
1782
+ fundOwner,
1783
+ aaveAdapter,
1784
+ aToken,
1785
+ amount = utils6.parseEther("1")
1786
+ }) {
1787
+ const redeemArgs = aaveRedeemArgs({
1788
+ aToken,
1789
+ amount
1790
+ });
1791
+ const callArgs = callOnIntegrationArgs({
1792
+ adapter: aaveAdapter,
1793
+ encodedCallArgs: redeemArgs,
1794
+ selector: redeemSelector
1795
+ });
1796
+ const redeemTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId2.CallOnIntegration, callArgs);
1797
+ return redeemTx;
1798
+ }
1799
+
1800
+ // src/scaffolding/extensions/integrations/compound.ts
1801
+ import { contract as contract3, resolveAddress as resolveAddress3 } from "@enzymefinance/ethers";
1802
+ import {
1803
+ callOnIntegrationArgs as callOnIntegrationArgs2,
1804
+ claimRewardsSelector,
1805
+ compoundArgs,
1806
+ compoundClaimRewardsArgs,
1807
+ IntegrationManagerActionId as IntegrationManagerActionId3,
1808
+ lendSelector as lendSelector2,
1809
+ redeemSelector as redeemSelector2,
1810
+ StandardToken as StandardToken2
1811
+ } from "@enzymefinance/protocol";
1812
+ import { BigNumber as BigNumber5, utils as utils7 } from "ethers";
1813
+ var ICompoundComptroller = contract3()`
1814
+ function claimComp(address)
1815
+ `;
1816
+ async function assertCompoundLend({
1817
+ tokenWhale,
1818
+ comptrollerProxy,
1819
+ vaultProxy,
1820
+ integrationManager,
1821
+ fundOwner,
1822
+ compoundAdapter,
1823
+ tokenAmount = utils7.parseEther("1"),
1824
+ cToken,
1825
+ compoundPriceFeed
1826
+ }) {
1827
+ const token = new StandardToken2(await compoundPriceFeed.getTokenFromCToken.args(cToken).call(), tokenWhale);
1828
+ await token.connect(tokenWhale).transfer(vaultProxy, tokenAmount);
1829
+ const rateBefore = await cToken.exchangeRateStored.call();
1830
+ const minIncomingCTokenAmount = tokenAmount.mul(utils7.parseEther("1")).div(rateBefore).mul(BigNumber5.from("999")).div(BigNumber5.from("1000"));
1831
+ const [preTxIncomingAssetBalance, preTxOutgoingAssetBalance] = await getAssetBalances({
1832
+ account: vaultProxy,
1833
+ assets: [cToken, token]
1834
+ });
1835
+ const lendReceipt = await compoundLend({
1836
+ cToken,
1837
+ cTokenAmount: minIncomingCTokenAmount,
1838
+ compoundAdapter,
1839
+ comptrollerProxy,
1840
+ fundOwner,
1841
+ integrationManager,
1842
+ tokenAmount
1843
+ });
1844
+ const rate = await cToken.exchangeRateStored();
1845
+ const [postTxIncomingAssetBalance, postTxOutgoingAssetBalance] = await getAssetBalances({
1846
+ account: vaultProxy,
1847
+ assets: [cToken, token]
1848
+ });
1849
+ const expectedCTokenAmount = tokenAmount.mul(utils7.parseEther("1")).div(rate);
1850
+ expect(postTxIncomingAssetBalance).toEqBigNumber(preTxIncomingAssetBalance.add(expectedCTokenAmount));
1851
+ expect(postTxOutgoingAssetBalance).toEqBigNumber(preTxOutgoingAssetBalance.sub(tokenAmount));
1852
+ return lendReceipt;
1853
+ }
1854
+ async function assertCompoundRedeem({
1855
+ comptrollerProxy,
1856
+ vaultProxy,
1857
+ integrationManager,
1858
+ fundOwner,
1859
+ compoundAdapter,
1860
+ cToken,
1861
+ compoundPriceFeed
1862
+ }) {
1863
+ const cTokenAmount = utils7.parseUnits("1", await cToken.decimals());
1864
+ await cToken.transfer(vaultProxy, cTokenAmount);
1865
+ const token = new StandardToken2(await compoundPriceFeed.getTokenFromCToken.args(cToken).call(), provider);
1866
+ const [preTxIncomingAssetBalance, preTxOutgoingAssetBalance] = await getAssetBalances({
1867
+ account: vaultProxy,
1868
+ assets: [token, cToken]
1869
+ });
1870
+ const rateBefore = await cToken.exchangeRateStored();
1871
+ const minIncomingTokenAmount = cTokenAmount.mul(rateBefore).div(utils7.parseEther("1"));
1872
+ const redeemReceipt = await compoundRedeem({
1873
+ cToken,
1874
+ cTokenAmount,
1875
+ compoundAdapter,
1876
+ comptrollerProxy,
1877
+ fundOwner,
1878
+ integrationManager,
1879
+ tokenAmount: minIncomingTokenAmount,
1880
+ vaultProxy
1881
+ });
1882
+ const [postTxIncomingAssetBalance, postTxOutgoingAssetBalance] = await getAssetBalances({
1883
+ account: vaultProxy,
1884
+ assets: [token, cToken]
1885
+ });
1886
+ const rate = await cToken.exchangeRateStored();
1887
+ const expectedTokenAmount = cTokenAmount.mul(rate).div(utils7.parseEther("1"));
1888
+ expect(postTxIncomingAssetBalance).toEqBigNumber(preTxIncomingAssetBalance.add(expectedTokenAmount));
1889
+ expect(postTxOutgoingAssetBalance).toEqBigNumber(preTxOutgoingAssetBalance.sub(cTokenAmount));
1890
+ return redeemReceipt;
1891
+ }
1892
+ async function compoundClaim({
1893
+ comptrollerProxy,
1894
+ integrationManager,
1895
+ fundOwner,
1896
+ compoundAdapter,
1897
+ compoundComptroller,
1898
+ cTokens
1899
+ }) {
1900
+ const claimArgs = compoundClaimRewardsArgs({
1901
+ cTokens,
1902
+ compoundComptroller
1903
+ });
1904
+ const callArgs = callOnIntegrationArgs2({
1905
+ adapter: compoundAdapter,
1906
+ encodedCallArgs: claimArgs,
1907
+ selector: claimRewardsSelector
1908
+ });
1909
+ const claimRewardsTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId3.CallOnIntegration, callArgs);
1910
+ return claimRewardsTx;
1911
+ }
1912
+ async function compoundLend({
1913
+ comptrollerProxy,
1914
+ integrationManager,
1915
+ fundOwner,
1916
+ compoundAdapter,
1917
+ cToken,
1918
+ tokenAmount = utils7.parseEther("1"),
1919
+ cTokenAmount = utils7.parseEther("1")
1920
+ }) {
1921
+ const lendArgs = compoundArgs({
1922
+ cToken,
1923
+ minIncomingAssetAmount: cTokenAmount,
1924
+ outgoingAssetAmount: tokenAmount
1925
+ });
1926
+ const callArgs = callOnIntegrationArgs2({
1927
+ adapter: compoundAdapter,
1928
+ encodedCallArgs: lendArgs,
1929
+ selector: lendSelector2
1930
+ });
1931
+ const lendTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId3.CallOnIntegration, callArgs);
1932
+ return lendTx;
1933
+ }
1934
+ async function compoundRedeem({
1935
+ comptrollerProxy,
1936
+ integrationManager,
1937
+ fundOwner,
1938
+ compoundAdapter,
1939
+ cToken,
1940
+ tokenAmount = utils7.parseEther("1"),
1941
+ cTokenAmount = utils7.parseEther("1")
1942
+ }) {
1943
+ const redeemArgs = compoundArgs({
1944
+ cToken: resolveAddress3(cToken),
1945
+ minIncomingAssetAmount: tokenAmount,
1946
+ outgoingAssetAmount: cTokenAmount
1947
+ });
1948
+ const callArgs = callOnIntegrationArgs2({
1949
+ adapter: compoundAdapter,
1950
+ encodedCallArgs: redeemArgs,
1951
+ selector: redeemSelector2
1952
+ });
1953
+ const redeemTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId3.CallOnIntegration, callArgs);
1954
+ return redeemTx;
1955
+ }
1956
+
1957
+ // src/scaffolding/extensions/integrations/curve.ts
1958
+ import { contract as contract4 } from "@enzymefinance/ethers";
1959
+ import {
1960
+ callOnIntegrationArgs as callOnIntegrationArgs3,
1961
+ claimRewardsSelector as claimRewardsSelector2,
1962
+ curveClaimRewardsArgs,
1963
+ curveLendAndStakeArgs,
1964
+ curveLendArgs,
1965
+ curveRedeemArgs,
1966
+ curveStakeArgs,
1967
+ curveTakeOrderArgs,
1968
+ curveUnstakeAndRedeemArgs,
1969
+ curveUnstakeArgs,
1970
+ IntegrationManagerActionId as IntegrationManagerActionId4,
1971
+ lendAndStakeSelector,
1972
+ lendSelector as lendSelector3,
1973
+ redeemSelector as redeemSelector3,
1974
+ stakeSelector,
1975
+ takeOrderSelector,
1976
+ unstakeAndRedeemSelector,
1977
+ unstakeSelector
1978
+ } from "@enzymefinance/protocol";
1979
+ import { BigNumber as BigNumber6, utils as utils8 } from "ethers";
1980
+ var CurveLiquidityGaugeV2 = contract4()`
1981
+ function claim_rewards(address)
1982
+ function integrate_fraction(address) view returns (uint256)
1983
+ `;
1984
+ var CurveRegistry = contract4()`
1985
+ function get_coins(address) view returns (address[8])
1986
+ function get_lp_token(address) view returns (address)
1987
+ `;
1988
+ var CurveSwaps = contract4()`
1989
+ function get_best_rate(address _from, address to, uint256 amount) view returns (address bestPool, uint256 amountReceived)
1990
+ `;
1991
+ var CurveMinter = contract4()`
1992
+ function mint_for(address,address)
1993
+ `;
1994
+ async function curveTakeOrder({
1995
+ comptrollerProxy,
1996
+ integrationManager,
1997
+ fundOwner,
1998
+ curveExchangeAdapter,
1999
+ pool,
2000
+ outgoingAsset,
2001
+ outgoingAssetAmount = utils8.parseEther("1"),
2002
+ incomingAsset,
2003
+ minIncomingAssetAmount = utils8.parseEther("1")
2004
+ }) {
2005
+ const takeOrderArgs = curveTakeOrderArgs({
2006
+ incomingAsset,
2007
+ minIncomingAssetAmount,
2008
+ outgoingAsset,
2009
+ outgoingAssetAmount,
2010
+ pool
2011
+ });
2012
+ const callArgs = callOnIntegrationArgs3({
2013
+ adapter: curveExchangeAdapter,
2014
+ encodedCallArgs: takeOrderArgs,
2015
+ selector: takeOrderSelector
2016
+ });
2017
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2018
+ }
2019
+ function curveClaimRewards({
2020
+ comptrollerProxy,
2021
+ integrationManager,
2022
+ fundOwner,
2023
+ curveLiquidityAdapter,
2024
+ stakingToken
2025
+ }) {
2026
+ const callArgs = callOnIntegrationArgs3({
2027
+ adapter: curveLiquidityAdapter,
2028
+ encodedCallArgs: curveClaimRewardsArgs({ stakingToken }),
2029
+ selector: claimRewardsSelector2
2030
+ });
2031
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2032
+ }
2033
+ async function curveLend({
2034
+ comptrollerProxy,
2035
+ integrationManager,
2036
+ signer,
2037
+ curveLiquidityAdapter,
2038
+ pool,
2039
+ orderedOutgoingAssetAmounts,
2040
+ minIncomingLpTokenAmount = BigNumber6.from(1),
2041
+ useUnderlyings
2042
+ }) {
2043
+ const callArgs = callOnIntegrationArgs3({
2044
+ adapter: curveLiquidityAdapter,
2045
+ encodedCallArgs: curveLendArgs({
2046
+ minIncomingLpTokenAmount,
2047
+ orderedOutgoingAssetAmounts,
2048
+ pool,
2049
+ useUnderlyings
2050
+ }),
2051
+ selector: lendSelector3
2052
+ });
2053
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2054
+ }
2055
+ async function curveLendAndStake({
2056
+ comptrollerProxy,
2057
+ integrationManager,
2058
+ signer,
2059
+ curveLiquidityAdapter,
2060
+ pool,
2061
+ orderedOutgoingAssetAmounts,
2062
+ incomingStakingToken,
2063
+ minIncomingStakingTokenAmount = BigNumber6.from(1),
2064
+ useUnderlyings
2065
+ }) {
2066
+ const callArgs = callOnIntegrationArgs3({
2067
+ adapter: curveLiquidityAdapter,
2068
+ encodedCallArgs: curveLendAndStakeArgs({
2069
+ incomingStakingToken,
2070
+ minIncomingStakingTokenAmount,
2071
+ orderedOutgoingAssetAmounts,
2072
+ pool,
2073
+ useUnderlyings
2074
+ }),
2075
+ selector: lendAndStakeSelector
2076
+ });
2077
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2078
+ }
2079
+ async function curveRedeem({
2080
+ comptrollerProxy,
2081
+ integrationManager,
2082
+ signer,
2083
+ curveLiquidityAdapter,
2084
+ pool,
2085
+ outgoingLpTokenAmount,
2086
+ useUnderlyings,
2087
+ redeemType,
2088
+ incomingAssetData
2089
+ }) {
2090
+ const callArgs = callOnIntegrationArgs3({
2091
+ adapter: curveLiquidityAdapter,
2092
+ encodedCallArgs: curveRedeemArgs({
2093
+ incomingAssetData,
2094
+ outgoingLpTokenAmount,
2095
+ pool,
2096
+ redeemType,
2097
+ useUnderlyings
2098
+ }),
2099
+ selector: redeemSelector3
2100
+ });
2101
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2102
+ }
2103
+ async function curveStake({
2104
+ comptrollerProxy,
2105
+ integrationManager,
2106
+ signer,
2107
+ curveLiquidityAdapter,
2108
+ pool,
2109
+ incomingStakingToken,
2110
+ amount
2111
+ }) {
2112
+ const callArgs = callOnIntegrationArgs3({
2113
+ adapter: curveLiquidityAdapter,
2114
+ encodedCallArgs: curveStakeArgs({
2115
+ amount,
2116
+ incomingStakingToken,
2117
+ pool
2118
+ }),
2119
+ selector: stakeSelector
2120
+ });
2121
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2122
+ }
2123
+ async function curveUnstake({
2124
+ comptrollerProxy,
2125
+ integrationManager,
2126
+ signer,
2127
+ curveLiquidityAdapter,
2128
+ pool,
2129
+ outgoingStakingToken,
2130
+ amount
2131
+ }) {
2132
+ const callArgs = callOnIntegrationArgs3({
2133
+ adapter: curveLiquidityAdapter,
2134
+ encodedCallArgs: curveUnstakeArgs({
2135
+ amount,
2136
+ outgoingStakingToken,
2137
+ pool
2138
+ }),
2139
+ selector: unstakeSelector
2140
+ });
2141
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2142
+ }
2143
+ async function curveUnstakeAndRedeem({
2144
+ comptrollerProxy,
2145
+ integrationManager,
2146
+ signer,
2147
+ curveLiquidityAdapter,
2148
+ pool,
2149
+ outgoingStakingToken,
2150
+ outgoingStakingTokenAmount,
2151
+ useUnderlyings,
2152
+ redeemType,
2153
+ incomingAssetData
2154
+ }) {
2155
+ const callArgs = callOnIntegrationArgs3({
2156
+ adapter: curveLiquidityAdapter,
2157
+ encodedCallArgs: curveUnstakeAndRedeemArgs({
2158
+ incomingAssetData,
2159
+ outgoingStakingToken,
2160
+ outgoingStakingTokenAmount,
2161
+ pool,
2162
+ redeemType,
2163
+ useUnderlyings
2164
+ }),
2165
+ selector: unstakeAndRedeemSelector
2166
+ });
2167
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId4.CallOnIntegration, callArgs);
2168
+ }
2169
+
2170
+ // src/scaffolding/extensions/integrations/idle.ts
2171
+ import {
2172
+ callOnIntegrationArgs as callOnIntegrationArgs4,
2173
+ claimRewardsSelector as claimRewardsSelector3,
2174
+ idleClaimRewardsArgs,
2175
+ idleLendArgs,
2176
+ idleRedeemArgs,
2177
+ IntegrationManagerActionId as IntegrationManagerActionId5,
2178
+ lendSelector as lendSelector4,
2179
+ redeemSelector as redeemSelector4
2180
+ } from "@enzymefinance/protocol";
2181
+ import { BigNumber as BigNumber7 } from "ethers";
2182
+ async function idleClaimRewards({
2183
+ comptrollerProxy,
2184
+ integrationManager,
2185
+ fundOwner,
2186
+ idleAdapter,
2187
+ idleToken
2188
+ }) {
2189
+ const callArgs = callOnIntegrationArgs4({
2190
+ adapter: idleAdapter,
2191
+ encodedCallArgs: idleClaimRewardsArgs({
2192
+ idleToken
2193
+ }),
2194
+ selector: claimRewardsSelector3
2195
+ });
2196
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId5.CallOnIntegration, callArgs);
2197
+ }
2198
+ async function idleLend({
2199
+ comptrollerProxy,
2200
+ integrationManager,
2201
+ fundOwner,
2202
+ idleAdapter,
2203
+ idleToken,
2204
+ outgoingUnderlyingAmount,
2205
+ minIncomingIdleTokenAmount = BigNumber7.from(1)
2206
+ }) {
2207
+ const callArgs = callOnIntegrationArgs4({
2208
+ adapter: idleAdapter,
2209
+ encodedCallArgs: idleLendArgs({
2210
+ idleToken,
2211
+ minIncomingIdleTokenAmount,
2212
+ outgoingUnderlyingAmount
2213
+ }),
2214
+ selector: lendSelector4
2215
+ });
2216
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId5.CallOnIntegration, callArgs);
2217
+ }
2218
+ async function idleRedeem({
2219
+ comptrollerProxy,
2220
+ integrationManager,
2221
+ fundOwner,
2222
+ idleAdapter,
2223
+ idleToken,
2224
+ outgoingIdleTokenAmount,
2225
+ minIncomingUnderlyingAmount = BigNumber7.from(1)
2226
+ }) {
2227
+ const callArgs = callOnIntegrationArgs4({
2228
+ adapter: idleAdapter,
2229
+ encodedCallArgs: idleRedeemArgs({
2230
+ idleToken,
2231
+ minIncomingUnderlyingAmount,
2232
+ outgoingIdleTokenAmount
2233
+ }),
2234
+ selector: redeemSelector4
2235
+ });
2236
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId5.CallOnIntegration, callArgs);
2237
+ }
2238
+
2239
+ // src/scaffolding/extensions/integrations/mock.ts
2240
+ import { callOnIntegrationArgs as callOnIntegrationArgs5, encodeArgs as encodeArgs3, IntegrationManagerActionId as IntegrationManagerActionId6, sighash } from "@enzymefinance/protocol";
2241
+ import { utils as utils9 } from "ethers";
2242
+ var mockGenericRemoveOnlySelector = sighash(utils9.FunctionFragment.fromString("removeOnly(address,bytes,bytes)"));
2243
+ var mockGenericSwapASelector = sighash(utils9.FunctionFragment.fromString("swapA(address,bytes,bytes)"));
2244
+ var mockGenericSwapBSelector = sighash(utils9.FunctionFragment.fromString("swapB(address,bytes,bytes)"));
2245
+ var mockGenericSwapDirectFromVaultSelector = sighash(utils9.FunctionFragment.fromString("swapDirectFromVault(address,bytes,bytes)"));
2246
+ var mockGenericSwapViaApprovalSelector = sighash(utils9.FunctionFragment.fromString("swapViaApproval(address,bytes,bytes)"));
2247
+ function mockGenericSwapArgs({
2248
+ spendAssets = [],
2249
+ actualSpendAssetAmounts = [],
2250
+ maxSpendAssetAmounts = actualSpendAssetAmounts,
2251
+ incomingAssets = [],
2252
+ actualIncomingAssetAmounts = [],
2253
+ minIncomingAssetAmounts = actualIncomingAssetAmounts
2254
+ }) {
2255
+ return encodeArgs3(["address[]", "uint256[]", "uint256[]", "address[]", "uint256[]", "uint256[]"], [
2256
+ spendAssets,
2257
+ maxSpendAssetAmounts,
2258
+ actualSpendAssetAmounts,
2259
+ incomingAssets,
2260
+ minIncomingAssetAmounts,
2261
+ actualIncomingAssetAmounts
2262
+ ]);
2263
+ }
2264
+ async function mockGenericSwap({
2265
+ comptrollerProxy,
2266
+ vaultProxy,
2267
+ integrationManager,
2268
+ fundOwner,
2269
+ mockGenericAdapter,
2270
+ selector = mockGenericSwapASelector,
2271
+ spendAssets = [],
2272
+ actualSpendAssetAmounts = [],
2273
+ maxSpendAssetAmounts = actualSpendAssetAmounts,
2274
+ incomingAssets = [],
2275
+ actualIncomingAssetAmounts = [],
2276
+ minIncomingAssetAmounts = actualIncomingAssetAmounts,
2277
+ seedFund = false
2278
+ }) {
2279
+ if (seedFund) {
2280
+ for (const key in spendAssets) {
2281
+ await spendAssets[key].transfer(vaultProxy, maxSpendAssetAmounts[key]);
2282
+ }
2283
+ }
2284
+ const swapArgs = mockGenericSwapArgs({
2285
+ actualIncomingAssetAmounts,
2286
+ actualSpendAssetAmounts,
2287
+ incomingAssets,
2288
+ maxSpendAssetAmounts,
2289
+ minIncomingAssetAmounts,
2290
+ spendAssets
2291
+ });
2292
+ const callArgs = callOnIntegrationArgs5({
2293
+ adapter: mockGenericAdapter,
2294
+ encodedCallArgs: swapArgs,
2295
+ selector
2296
+ });
2297
+ const swapTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId6.CallOnIntegration, callArgs);
2298
+ await expect(swapTx).resolves.toBeReceipt();
2299
+ return swapTx;
2300
+ }
2301
+
2302
+ // src/scaffolding/extensions/integrations/olympusV2.ts
2303
+ import {
2304
+ callOnIntegrationArgs as callOnIntegrationArgs6,
2305
+ IntegrationManagerActionId as IntegrationManagerActionId7,
2306
+ olympusV2StakeArgs,
2307
+ olympusV2UnstakeArgs,
2308
+ stakeSelector as stakeSelector2,
2309
+ unstakeSelector as unstakeSelector2
2310
+ } from "@enzymefinance/protocol";
2311
+ async function olympusV2Stake({
2312
+ comptrollerProxy,
2313
+ integrationManager,
2314
+ signer,
2315
+ olympusV2Adapter,
2316
+ amount
2317
+ }) {
2318
+ const stakeArgs = olympusV2StakeArgs({
2319
+ amount
2320
+ });
2321
+ const callArgs = callOnIntegrationArgs6({
2322
+ adapter: olympusV2Adapter,
2323
+ encodedCallArgs: stakeArgs,
2324
+ selector: stakeSelector2
2325
+ });
2326
+ const stakeTx = comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId7.CallOnIntegration, callArgs);
2327
+ return stakeTx;
2328
+ }
2329
+ async function olympusV2Unstake({
2330
+ comptrollerProxy,
2331
+ integrationManager,
2332
+ signer,
2333
+ olympusV2Adapter,
2334
+ amount
2335
+ }) {
2336
+ const unstakeArgs = olympusV2UnstakeArgs({
2337
+ amount
2338
+ });
2339
+ const callArgs = callOnIntegrationArgs6({
2340
+ adapter: olympusV2Adapter,
2341
+ encodedCallArgs: unstakeArgs,
2342
+ selector: unstakeSelector2
2343
+ });
2344
+ const unstakeTx = comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId7.CallOnIntegration, callArgs);
2345
+ return unstakeTx;
2346
+ }
2347
+
2348
+ // src/scaffolding/extensions/integrations/paraSwapV5.ts
2349
+ import {
2350
+ callOnIntegrationArgs as callOnIntegrationArgs7,
2351
+ IntegrationManagerActionId as IntegrationManagerActionId8,
2352
+ paraSwapV5TakeOrderArgs,
2353
+ takeOrderSelector as takeOrderSelector2
2354
+ } from "@enzymefinance/protocol";
2355
+ import { utils as utils10 } from "ethers";
2356
+ function paraSwapV5GenerateDummyPaths({ toTokens }) {
2357
+ return toTokens.map((toToken) => {
2358
+ return {
2359
+ adapters: [],
2360
+ to: toToken,
2361
+ totalNetworkFee: 0
2362
+ };
2363
+ });
2364
+ }
2365
+ async function paraSwapV5TakeOrder({
2366
+ comptrollerProxy,
2367
+ integrationManager,
2368
+ fundOwner,
2369
+ paraSwapV5Adapter,
2370
+ outgoingAsset,
2371
+ outgoingAssetAmount,
2372
+ minIncomingAssetAmount = 1,
2373
+ expectedIncomingAssetAmount = minIncomingAssetAmount,
2374
+ uuid = utils10.randomBytes(16),
2375
+ paths
2376
+ }) {
2377
+ const takeOrderArgs = paraSwapV5TakeOrderArgs({
2378
+ expectedIncomingAssetAmount,
2379
+ minIncomingAssetAmount,
2380
+ outgoingAsset,
2381
+ outgoingAssetAmount,
2382
+ paths,
2383
+ uuid
2384
+ });
2385
+ const callArgs = callOnIntegrationArgs7({
2386
+ adapter: paraSwapV5Adapter,
2387
+ encodedCallArgs: takeOrderArgs,
2388
+ selector: takeOrderSelector2
2389
+ });
2390
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId8.CallOnIntegration, callArgs);
2391
+ }
2392
+
2393
+ // src/scaffolding/extensions/integrations/poolTogetherV4.ts
2394
+ import {
2395
+ callOnIntegrationArgs as callOnIntegrationArgs8,
2396
+ claimRewardsSelector as claimRewardsSelector4,
2397
+ IntegrationManagerActionId as IntegrationManagerActionId9,
2398
+ lendSelector as lendSelector5,
2399
+ poolTogetherV4ClaimRewardsArgs,
2400
+ poolTogetherV4LendArgs,
2401
+ poolTogetherV4RedeemArgs,
2402
+ redeemSelector as redeemSelector5
2403
+ } from "@enzymefinance/protocol";
2404
+ import { utils as utils11 } from "ethers";
2405
+ async function poolTogetherV4Lend({
2406
+ comptrollerProxy,
2407
+ integrationManager,
2408
+ fundOwner,
2409
+ poolTogetherV4Adapter,
2410
+ ptToken,
2411
+ amount = utils11.parseEther("1")
2412
+ }) {
2413
+ const lendArgs = poolTogetherV4LendArgs({
2414
+ amount,
2415
+ ptToken
2416
+ });
2417
+ const callArgs = callOnIntegrationArgs8({
2418
+ adapter: poolTogetherV4Adapter,
2419
+ encodedCallArgs: lendArgs,
2420
+ selector: lendSelector5
2421
+ });
2422
+ const lendTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId9.CallOnIntegration, callArgs);
2423
+ return lendTx;
2424
+ }
2425
+ async function poolTogetherV4Redeem({
2426
+ comptrollerProxy,
2427
+ integrationManager,
2428
+ fundOwner,
2429
+ poolTogetherV4Adapter,
2430
+ ptToken,
2431
+ amount = utils11.parseEther("1")
2432
+ }) {
2433
+ const redeemArgs = poolTogetherV4RedeemArgs({
2434
+ amount,
2435
+ ptToken
2436
+ });
2437
+ const callArgs = callOnIntegrationArgs8({
2438
+ adapter: poolTogetherV4Adapter,
2439
+ encodedCallArgs: redeemArgs,
2440
+ selector: redeemSelector5
2441
+ });
2442
+ const redeemTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId9.CallOnIntegration, callArgs);
2443
+ return redeemTx;
2444
+ }
2445
+ async function poolTogetherV4ClaimRewards({
2446
+ comptrollerProxy,
2447
+ integrationManager,
2448
+ fundOwner,
2449
+ poolTogetherV4Adapter,
2450
+ prizeDistributor,
2451
+ drawIds,
2452
+ winningPicks
2453
+ }) {
2454
+ const claimRewardsArgs = poolTogetherV4ClaimRewardsArgs({
2455
+ drawIds,
2456
+ prizeDistributor,
2457
+ winningPicks
2458
+ });
2459
+ const callArgs = callOnIntegrationArgs8({
2460
+ adapter: poolTogetherV4Adapter,
2461
+ encodedCallArgs: claimRewardsArgs,
2462
+ selector: claimRewardsSelector4
2463
+ });
2464
+ const claimTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId9.CallOnIntegration, callArgs);
2465
+ return claimTx;
2466
+ }
2467
+
2468
+ // src/scaffolding/extensions/integrations/synthetix.ts
2469
+ import {
2470
+ callOnIntegrationArgs as callOnIntegrationArgs9,
2471
+ encodeArgs as encodeArgs4,
2472
+ IntegrationManagerActionId as IntegrationManagerActionId10,
2473
+ redeemSelector as redeemSelector6,
2474
+ synthetixAssignExchangeDelegateSelector,
2475
+ synthetixRedeemArgs,
2476
+ synthetixTakeOrderArgs,
2477
+ takeOrderSelector as takeOrderSelector3
2478
+ } from "@enzymefinance/protocol";
2479
+ import { utils as utils12 } from "ethers";
2480
+ async function synthetixAssignExchangeDelegate({
2481
+ comptrollerProxy,
2482
+ synthetixDelegateApprovals,
2483
+ fundOwner,
2484
+ delegate
2485
+ }) {
2486
+ await comptrollerProxy.connect(fundOwner).vaultCallOnContract(synthetixDelegateApprovals, synthetixAssignExchangeDelegateSelector, encodeArgs4(["address"], [delegate]));
2487
+ }
2488
+ async function synthetixRedeem({
2489
+ comptrollerProxy,
2490
+ integrationManager,
2491
+ signer,
2492
+ synthetixAdapter,
2493
+ synths
2494
+ }) {
2495
+ const redeemArgs = synthetixRedeemArgs({
2496
+ synths
2497
+ });
2498
+ const callArgs = callOnIntegrationArgs9({
2499
+ adapter: synthetixAdapter,
2500
+ encodedCallArgs: redeemArgs,
2501
+ selector: redeemSelector6
2502
+ });
2503
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId10.CallOnIntegration, callArgs);
2504
+ }
2505
+ async function synthetixTakeOrder({
2506
+ comptrollerProxy,
2507
+ vaultProxy,
2508
+ integrationManager,
2509
+ fundOwner,
2510
+ synthetixAdapter,
2511
+ outgoingAsset,
2512
+ outgoingAssetAmount = utils12.parseEther("1"),
2513
+ minIncomingSusdAmount = utils12.parseEther("1"),
2514
+ seedFund = false
2515
+ }) {
2516
+ if (seedFund) {
2517
+ await outgoingAsset.transfer(vaultProxy, outgoingAssetAmount);
2518
+ }
2519
+ const takeOrderArgs = synthetixTakeOrderArgs({
2520
+ minIncomingSusdAmount,
2521
+ outgoingAsset,
2522
+ outgoingAssetAmount
2523
+ });
2524
+ const callArgs = await callOnIntegrationArgs9({
2525
+ adapter: synthetixAdapter,
2526
+ encodedCallArgs: takeOrderArgs,
2527
+ selector: takeOrderSelector3
2528
+ });
2529
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId10.CallOnIntegration, callArgs);
2530
+ }
2531
+
2532
+ // src/scaffolding/extensions/integrations/uniswapV2.ts
2533
+ import { contract as contract5 } from "@enzymefinance/ethers";
2534
+ import {
2535
+ callOnIntegrationArgs as callOnIntegrationArgs10,
2536
+ IntegrationManagerActionId as IntegrationManagerActionId11,
2537
+ lendSelector as lendSelector6,
2538
+ redeemSelector as redeemSelector7,
2539
+ takeOrderSelector as takeOrderSelector4,
2540
+ uniswapV2LendArgs,
2541
+ uniswapV2RedeemArgs,
2542
+ uniswapV2TakeOrderArgs
2543
+ } from "@enzymefinance/protocol";
2544
+ var UniswapV2Factory = contract5()`
2545
+ function createPair(address,address) returns (address)
2546
+ function getPair(address,address) view returns (address)
2547
+ `;
2548
+ async function uniswapV2Lend({
2549
+ comptrollerProxy,
2550
+ vaultProxy,
2551
+ integrationManager,
2552
+ fundOwner,
2553
+ uniswapV2LiquidityAdapter,
2554
+ tokenA,
2555
+ tokenB,
2556
+ amountADesired,
2557
+ amountBDesired,
2558
+ amountAMin,
2559
+ amountBMin,
2560
+ minPoolTokenAmount,
2561
+ seedFund = false
2562
+ }) {
2563
+ if (seedFund) {
2564
+ await tokenA.transfer(vaultProxy, amountADesired);
2565
+ await tokenB.transfer(vaultProxy, amountBDesired);
2566
+ }
2567
+ const lendArgs = uniswapV2LendArgs({
2568
+ amountADesired,
2569
+ amountAMin,
2570
+ amountBDesired,
2571
+ amountBMin,
2572
+ minPoolTokenAmount,
2573
+ tokenA,
2574
+ tokenB
2575
+ });
2576
+ const callArgs = callOnIntegrationArgs10({
2577
+ adapter: uniswapV2LiquidityAdapter,
2578
+ encodedCallArgs: lendArgs,
2579
+ selector: lendSelector6
2580
+ });
2581
+ const lendTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId11.CallOnIntegration, callArgs);
2582
+ await expect(lendTx).resolves.toBeReceipt();
2583
+ return lendTx;
2584
+ }
2585
+ async function uniswapV2Redeem({
2586
+ comptrollerProxy,
2587
+ integrationManager,
2588
+ fundOwner,
2589
+ uniswapV2LiquidityAdapter,
2590
+ poolTokenAmount,
2591
+ tokenA,
2592
+ tokenB,
2593
+ amountAMin,
2594
+ amountBMin
2595
+ }) {
2596
+ const redeemArgs = uniswapV2RedeemArgs({
2597
+ amountAMin,
2598
+ amountBMin,
2599
+ poolTokenAmount,
2600
+ tokenA,
2601
+ tokenB
2602
+ });
2603
+ const callArgs = callOnIntegrationArgs10({
2604
+ adapter: uniswapV2LiquidityAdapter,
2605
+ encodedCallArgs: redeemArgs,
2606
+ selector: redeemSelector7
2607
+ });
2608
+ const redeemTx = comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId11.CallOnIntegration, callArgs);
2609
+ await expect(redeemTx).resolves.toBeReceipt();
2610
+ return redeemTx;
2611
+ }
2612
+ async function uniswapV2TakeOrder({
2613
+ comptrollerProxy,
2614
+ vaultProxy,
2615
+ integrationManager,
2616
+ fundOwner,
2617
+ uniswapV2ExchangeAdapter,
2618
+ path,
2619
+ outgoingAssetAmount,
2620
+ minIncomingAssetAmount,
2621
+ seedFund = false
2622
+ }) {
2623
+ if (seedFund) {
2624
+ await path[0].transfer(vaultProxy, outgoingAssetAmount);
2625
+ }
2626
+ const takeOrderArgs = uniswapV2TakeOrderArgs({
2627
+ minIncomingAssetAmount,
2628
+ outgoingAssetAmount,
2629
+ path
2630
+ });
2631
+ const callArgs = callOnIntegrationArgs10({
2632
+ adapter: uniswapV2ExchangeAdapter,
2633
+ encodedCallArgs: takeOrderArgs,
2634
+ selector: takeOrderSelector4
2635
+ });
2636
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId11.CallOnIntegration, callArgs);
2637
+ }
2638
+
2639
+ // src/scaffolding/extensions/integrations/uniswapV3.ts
2640
+ import {
2641
+ callOnIntegrationArgs as callOnIntegrationArgs11,
2642
+ IntegrationManagerActionId as IntegrationManagerActionId12,
2643
+ takeOrderSelector as takeOrderSelector5,
2644
+ uniswapV3TakeOrderArgs
2645
+ } from "@enzymefinance/protocol";
2646
+ async function uniswapV3TakeOrder({
2647
+ comptrollerProxy,
2648
+ integrationManager,
2649
+ fundOwner,
2650
+ uniswapV3Adapter,
2651
+ pathAddresses,
2652
+ pathFees,
2653
+ outgoingAssetAmount,
2654
+ minIncomingAssetAmount = 1,
2655
+ seedFund = false
2656
+ }) {
2657
+ if (seedFund) {
2658
+ const vaultProxy = await comptrollerProxy.getVaultProxy();
2659
+ await pathAddresses[0].transfer(vaultProxy, outgoingAssetAmount);
2660
+ }
2661
+ const takeOrderArgs = uniswapV3TakeOrderArgs({
2662
+ minIncomingAssetAmount,
2663
+ outgoingAssetAmount,
2664
+ pathAddresses,
2665
+ pathFees
2666
+ });
2667
+ const callArgs = callOnIntegrationArgs11({
2668
+ adapter: uniswapV3Adapter,
2669
+ encodedCallArgs: takeOrderArgs,
2670
+ selector: takeOrderSelector5
2671
+ });
2672
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId12.CallOnIntegration, callArgs);
2673
+ }
2674
+
2675
+ // src/scaffolding/extensions/integrations/yearn.ts
2676
+ import {
2677
+ callOnIntegrationArgs as callOnIntegrationArgs12,
2678
+ IntegrationManagerActionId as IntegrationManagerActionId13,
2679
+ lendSelector as lendSelector7,
2680
+ redeemSelector as redeemSelector8,
2681
+ yearnVaultV2LendArgs,
2682
+ yearnVaultV2RedeemArgs
2683
+ } from "@enzymefinance/protocol";
2684
+ import { BigNumber as BigNumber8 } from "ethers";
2685
+ async function yearnVaultV2Lend({
2686
+ signer,
2687
+ comptrollerProxy,
2688
+ integrationManager,
2689
+ yearnVaultV2Adapter,
2690
+ yVault,
2691
+ outgoingUnderlyingAmount,
2692
+ minIncomingYVaultSharesAmount = BigNumber8.from(1)
2693
+ }) {
2694
+ const callArgs = callOnIntegrationArgs12({
2695
+ adapter: yearnVaultV2Adapter,
2696
+ encodedCallArgs: yearnVaultV2LendArgs({
2697
+ minIncomingYVaultSharesAmount,
2698
+ outgoingUnderlyingAmount,
2699
+ yVault
2700
+ }),
2701
+ selector: lendSelector7
2702
+ });
2703
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId13.CallOnIntegration, callArgs);
2704
+ }
2705
+ async function yearnVaultV2Redeem({
2706
+ signer,
2707
+ comptrollerProxy,
2708
+ integrationManager,
2709
+ yearnVaultV2Adapter,
2710
+ yVault,
2711
+ maxOutgoingYVaultSharesAmount,
2712
+ minIncomingUnderlyingAmount = BigNumber8.from(1),
2713
+ slippageToleranceBps = 1
2714
+ }) {
2715
+ const callArgs = callOnIntegrationArgs12({
2716
+ adapter: yearnVaultV2Adapter,
2717
+ encodedCallArgs: yearnVaultV2RedeemArgs({
2718
+ maxOutgoingYVaultSharesAmount,
2719
+ minIncomingUnderlyingAmount,
2720
+ slippageToleranceBps,
2721
+ yVault
2722
+ }),
2723
+ selector: redeemSelector8
2724
+ });
2725
+ return comptrollerProxy.connect(signer).callOnExtension(integrationManager, IntegrationManagerActionId13.CallOnIntegration, callArgs);
2726
+ }
2727
+
2728
+ // src/scaffolding/extensions/integrations/zeroExV2.ts
2729
+ import {
2730
+ callOnIntegrationArgs as callOnIntegrationArgs13,
2731
+ IntegrationManagerActionId as IntegrationManagerActionId14,
2732
+ takeOrderSelector as takeOrderSelector6,
2733
+ zeroExV2TakeOrderArgs
2734
+ } from "@enzymefinance/protocol";
2735
+ async function zeroExV2TakeOrder({
2736
+ comptrollerProxy,
2737
+ integrationManager,
2738
+ fundOwner,
2739
+ zeroExV2Adapter,
2740
+ signedOrder,
2741
+ takerAssetFillAmount
2742
+ }) {
2743
+ const takeOrderArgs = zeroExV2TakeOrderArgs({
2744
+ signedOrder,
2745
+ takerAssetFillAmount
2746
+ });
2747
+ const callArgs = callOnIntegrationArgs13({
2748
+ adapter: zeroExV2Adapter,
2749
+ encodedCallArgs: takeOrderArgs,
2750
+ selector: takeOrderSelector6
2751
+ });
2752
+ return comptrollerProxy.connect(fundOwner).callOnExtension(integrationManager, IntegrationManagerActionId14.CallOnIntegration, callArgs);
2753
+ }
2754
+
2755
+ // src/scaffolding/extensions/policies.ts
2756
+ import { IPolicy, PolicyHook, policyManagerConfigArgs } from "@enzymefinance/protocol";
2757
+ import { constants as constants2, utils as utils13 } from "ethers";
2758
+ async function generatePolicyManagerConfigWithMockPolicies({ deployer }) {
2759
+ const policies = Object.values(await generateMockPolicies({
2760
+ deployer
2761
+ }));
2762
+ const policiesSettingsData = [...new Array(policies.length - 1).fill(constants2.HashZero), utils13.randomBytes(10)];
2763
+ return policyManagerConfigArgs({
2764
+ policies,
2765
+ settings: policiesSettingsData
2766
+ });
2767
+ }
2768
+ async function generateMockPolicies({ deployer }) {
2769
+ const mockAddTrackedAssetsPolicy = await IPolicy.mock(deployer);
2770
+ const mockCreateExternalPositionPolicy = await IPolicy.mock(deployer);
2771
+ const mockPostBuySharesPolicy = await IPolicy.mock(deployer);
2772
+ const mockPostCallOnExternalPositionPolicy = await IPolicy.mock(deployer);
2773
+ const mockPostCoIPolicy = await IPolicy.mock(deployer);
2774
+ const mockRedeemSharesForSpecificAssetsPolicy = await IPolicy.mock(deployer);
2775
+ const mockPreTransferSharesPolicy = await IPolicy.mock(deployer);
2776
+ const mockRemoveExternalPositionPolicy = await IPolicy.mock(deployer);
2777
+ await Promise.all([
2778
+ mockAddTrackedAssetsPolicy.identifier.returns(`MOCK_ADD_TRACKED_ASSETS`),
2779
+ mockAddTrackedAssetsPolicy.addFundSettings.returns(void 0),
2780
+ mockAddTrackedAssetsPolicy.activateForFund.returns(void 0),
2781
+ mockAddTrackedAssetsPolicy.canDisable.returns(false),
2782
+ mockAddTrackedAssetsPolicy.validateRule.returns(true),
2783
+ mockAddTrackedAssetsPolicy.implementedHooks.returns([PolicyHook.AddTrackedAssets]),
2784
+ mockAddTrackedAssetsPolicy.updateFundSettings.returns(void 0),
2785
+ mockCreateExternalPositionPolicy.identifier.returns(`MOCK_CREATE_EXTERNAL_POSITION`),
2786
+ mockCreateExternalPositionPolicy.addFundSettings.returns(void 0),
2787
+ mockCreateExternalPositionPolicy.activateForFund.returns(void 0),
2788
+ mockCreateExternalPositionPolicy.canDisable.returns(false),
2789
+ mockCreateExternalPositionPolicy.validateRule.returns(true),
2790
+ mockCreateExternalPositionPolicy.implementedHooks.returns([PolicyHook.CreateExternalPosition]),
2791
+ mockCreateExternalPositionPolicy.updateFundSettings.returns(void 0),
2792
+ mockPostBuySharesPolicy.identifier.returns(`MOCK_POST_BUY_SHARES`),
2793
+ mockPostBuySharesPolicy.addFundSettings.returns(void 0),
2794
+ mockPostBuySharesPolicy.activateForFund.returns(void 0),
2795
+ mockPostBuySharesPolicy.canDisable.returns(false),
2796
+ mockPostBuySharesPolicy.validateRule.returns(true),
2797
+ mockPostBuySharesPolicy.implementedHooks.returns([PolicyHook.PostBuyShares]),
2798
+ mockPostBuySharesPolicy.updateFundSettings.returns(void 0),
2799
+ mockPostCallOnExternalPositionPolicy.identifier.returns(`MOCK_POST_CALL_ON_EXTERNAL_POSITION`),
2800
+ mockPostCallOnExternalPositionPolicy.addFundSettings.returns(void 0),
2801
+ mockPostCallOnExternalPositionPolicy.activateForFund.returns(void 0),
2802
+ mockPostCallOnExternalPositionPolicy.canDisable.returns(false),
2803
+ mockPostCallOnExternalPositionPolicy.validateRule.returns(true),
2804
+ mockPostCallOnExternalPositionPolicy.implementedHooks.returns([PolicyHook.PostCallOnExternalPosition]),
2805
+ mockPostCallOnExternalPositionPolicy.updateFundSettings.returns(void 0),
2806
+ mockPostCoIPolicy.identifier.returns(`MOCK_POST_CALL_ON_INTEGRATION`),
2807
+ mockPostCoIPolicy.addFundSettings.returns(void 0),
2808
+ mockPostCoIPolicy.activateForFund.returns(void 0),
2809
+ mockPostCoIPolicy.canDisable.returns(false),
2810
+ mockPostCoIPolicy.validateRule.returns(true),
2811
+ mockPostCoIPolicy.implementedHooks.returns([PolicyHook.PostCallOnIntegration]),
2812
+ mockPostCoIPolicy.updateFundSettings.returns(void 0),
2813
+ mockPreTransferSharesPolicy.identifier.returns(`MOCK_PRE_TRANSFER_SHARES`),
2814
+ mockPreTransferSharesPolicy.addFundSettings.returns(void 0),
2815
+ mockPreTransferSharesPolicy.activateForFund.returns(void 0),
2816
+ mockPreTransferSharesPolicy.canDisable.returns(false),
2817
+ mockPreTransferSharesPolicy.validateRule.returns(true),
2818
+ mockPreTransferSharesPolicy.implementedHooks.returns([PolicyHook.PreTransferShares]),
2819
+ mockPreTransferSharesPolicy.updateFundSettings.returns(void 0),
2820
+ mockRedeemSharesForSpecificAssetsPolicy.identifier.returns(`MOCK_REDEEM_SHARES_FOR_SPECIFIC_ASSETS`),
2821
+ mockRedeemSharesForSpecificAssetsPolicy.addFundSettings.returns(void 0),
2822
+ mockRedeemSharesForSpecificAssetsPolicy.activateForFund.returns(void 0),
2823
+ mockRedeemSharesForSpecificAssetsPolicy.canDisable.returns(false),
2824
+ mockRedeemSharesForSpecificAssetsPolicy.validateRule.returns(true),
2825
+ mockRedeemSharesForSpecificAssetsPolicy.implementedHooks.returns([PolicyHook.RedeemSharesForSpecificAssets]),
2826
+ mockRedeemSharesForSpecificAssetsPolicy.updateFundSettings.returns(void 0),
2827
+ mockRemoveExternalPositionPolicy.identifier.returns(`MOCK_REMOVE_EXTERNAL_POSITION`),
2828
+ mockRemoveExternalPositionPolicy.addFundSettings.returns(void 0),
2829
+ mockRemoveExternalPositionPolicy.activateForFund.returns(void 0),
2830
+ mockRemoveExternalPositionPolicy.canDisable.returns(false),
2831
+ mockRemoveExternalPositionPolicy.validateRule.returns(true),
2832
+ mockRemoveExternalPositionPolicy.implementedHooks.returns([PolicyHook.RedeemSharesForSpecificAssets]),
2833
+ mockRemoveExternalPositionPolicy.updateFundSettings.returns(void 0)
2834
+ ]);
2835
+ return {
2836
+ mockAddTrackedAssetsPolicy,
2837
+ mockCreateExternalPositionPolicy,
2838
+ mockPostBuySharesPolicy,
2839
+ mockPostCallOnExternalPositionPolicy,
2840
+ mockPostCoIPolicy,
2841
+ mockPreTransferSharesPolicy,
2842
+ mockRedeemSharesForSpecificAssetsPolicy,
2843
+ mockRemoveExternalPositionPolicy
2844
+ };
2845
+ }
2846
+
2847
+ // src/scaffolding/external-interfaces.ts
2848
+ import { contract as contract6 } from "@enzymefinance/ethers";
2849
+ var IConvexBaseRewardPool = contract6()`
2850
+ function stakeFor(address, uint256) returns (bool)
2851
+ `;
2852
+ var IConvexCrvDepositor = contract6()`
2853
+ function deposit(uint256, bool)
2854
+ `;
2855
+ var IConvexCvxLocker = contract6()`
2856
+ function balanceOf(address) view returns (uint256)
2857
+ function checkpointEpoch()
2858
+ function getReward(address, bool)
2859
+ function lockedBalanceOf(address) view returns (uint256)
2860
+ `;
2861
+ var IConvexVlCvxExtraRewardDistribution = contract6()`
2862
+ function claimableRewards(address, address) view returns (uint256)
2863
+ function addReward(address, uint256)
2864
+ `;
2865
+ var ISnapshotDelegateRegistry = contract6()`
2866
+ function delegation(address, bytes32) view returns (address)
2867
+ `;
2868
+ var IVotiumMultiMerkleStash = contract6()`
2869
+ function owner() view returns (address)
2870
+ function updateMerkleRoot(address, bytes32)
2871
+ `;
2872
+
2873
+ // src/scaffolding/persistent/manual-value-oracle.ts
2874
+ import { ManualValueOracleLib } from "@enzymefinance/protocol";
2875
+ async function deployManualValueOracle({
2876
+ signer,
2877
+ manualValueOracleFactory,
2878
+ owner,
2879
+ updater,
2880
+ description = ""
2881
+ }) {
2882
+ const receipt = await manualValueOracleFactory.connect(signer).deploy(owner, updater, description);
2883
+ const proxyDeployedArgs = assertEvent(receipt, "ProxyDeployed", {
2884
+ caller: signer,
2885
+ proxy: expect.any(String)
2886
+ });
2887
+ const proxy = new ManualValueOracleLib(proxyDeployedArgs.proxy, provider);
2888
+ return { proxy, receipt };
2889
+ }
2890
+
2891
+ // src/scaffolding/persistent/shares-splitter.ts
2892
+ import { SharesSplitterLib } from "@enzymefinance/protocol";
2893
+ async function deploySharesSplitter({
2894
+ signer,
2895
+ sharesSplitterFactory,
2896
+ splitUsers,
2897
+ splitPercentages
2898
+ }) {
2899
+ const receipt = await sharesSplitterFactory.connect(signer).deploy(splitUsers, splitPercentages);
2900
+ const proxyDeployedArgs = assertEvent(receipt, "ProxyDeployed", {
2901
+ caller: signer,
2902
+ proxy: expect.any(String)
2903
+ });
2904
+ const sharesSplitterProxy = new SharesSplitterLib(proxyDeployedArgs.proxy, provider);
2905
+ return { receipt, sharesSplitterProxy };
2906
+ }
2907
+
2908
+ // src/scaffolding/setup.ts
2909
+ import { randomAddress } from "@enzymefinance/ethers";
2910
+ import {
2911
+ ComptrollerLib as ComptrollerLib3,
2912
+ ComptrollerProxy,
2913
+ encodeFunctionData,
2914
+ GasRelayPaymasterLib,
2915
+ VaultLib as VaultLib4,
2916
+ VaultProxy
2917
+ } from "@enzymefinance/protocol";
2918
+ import { BigNumber as BigNumber9, utils as utils15 } from "ethers";
2919
+
2920
+ // src/scaffolding/shares.ts
2921
+ import { constants as constants3, utils as utils14 } from "ethers";
2922
+ async function buyShares(options) {
2923
+ return (await buySharesFunction(options)).send();
2924
+ }
2925
+ async function buySharesFunction({
2926
+ comptrollerProxy,
2927
+ denominationAsset,
2928
+ buyer,
2929
+ investmentAmount,
2930
+ minSharesQuantity = 1,
2931
+ seedBuyer = false
2932
+ }) {
2933
+ if (investmentAmount == null) {
2934
+ investmentAmount = utils14.parseUnits("1", await denominationAsset.decimals());
2935
+ }
2936
+ if (seedBuyer) {
2937
+ await denominationAsset.transfer(buyer, investmentAmount);
2938
+ }
2939
+ await denominationAsset.connect(buyer).approve(comptrollerProxy, investmentAmount);
2940
+ return comptrollerProxy.connect(buyer).buyShares.args(investmentAmount, minSharesQuantity).ref;
2941
+ }
2942
+ async function redeemSharesForSpecificAssets({
2943
+ comptrollerProxy,
2944
+ signer,
2945
+ recipient = signer,
2946
+ quantity = constants3.MaxUint256,
2947
+ payoutAssets,
2948
+ payoutAssetPercentages
2949
+ }) {
2950
+ return comptrollerProxy.connect(signer).redeemSharesForSpecificAssets(recipient, quantity, payoutAssets, payoutAssetPercentages);
2951
+ }
2952
+ async function redeemSharesInKind({
2953
+ comptrollerProxy,
2954
+ signer,
2955
+ recipient = signer,
2956
+ quantity = constants3.MaxUint256,
2957
+ additionalAssets = [],
2958
+ assetsToSkip = []
2959
+ }) {
2960
+ return comptrollerProxy.connect(signer).redeemSharesInKind(recipient, quantity, additionalAssets, assetsToSkip);
2961
+ }
2962
+
2963
+ // src/scaffolding/setup.ts
2964
+ async function createComptrollerProxy({
2965
+ signer,
2966
+ comptrollerLib,
2967
+ denominationAsset,
2968
+ sharesActionTimelock = 0
2969
+ }) {
2970
+ const constructData = encodeFunctionData(comptrollerLib.init.fragment, [denominationAsset, sharesActionTimelock]);
2971
+ const comptrollerProxyContract = await ComptrollerProxy.deploy(signer, constructData, comptrollerLib);
2972
+ return {
2973
+ comptrollerProxy: new ComptrollerLib3(comptrollerProxyContract, signer),
2974
+ receipt: comptrollerProxyContract.deployment
2975
+ };
2976
+ }
2977
+ async function createMigrationRequest({
2978
+ signer,
2979
+ fundDeployer,
2980
+ vaultProxy,
2981
+ denominationAsset,
2982
+ sharesActionTimelock = 0,
2983
+ feeManagerConfigData = "0x",
2984
+ policyManagerConfigData = "0x",
2985
+ bypassPrevReleaseFailure = false
2986
+ }) {
2987
+ const receipt = await fundDeployer.connect(signer).createMigrationRequest(vaultProxy, denominationAsset, sharesActionTimelock, feeManagerConfigData, policyManagerConfigData, bypassPrevReleaseFailure);
2988
+ const comptrollerDeployedArgs = assertEvent(receipt, "ComptrollerProxyDeployed", {
2989
+ comptrollerProxy: expect.any(String),
2990
+ creator: signer,
2991
+ denominationAsset,
2992
+ sharesActionTimelock: BigNumber9.from(sharesActionTimelock)
2993
+ });
2994
+ return {
2995
+ comptrollerProxy: new ComptrollerLib3(comptrollerDeployedArgs.comptrollerProxy, signer),
2996
+ receipt
2997
+ };
2998
+ }
2999
+ async function createNewFund({
3000
+ signer,
3001
+ fundDeployer,
3002
+ denominationAsset,
3003
+ sharesActionTimelock = 0,
3004
+ fundOwner = randomAddress(),
3005
+ fundName = "My Fund",
3006
+ fundSymbol = "",
3007
+ feeManagerConfig = "0x",
3008
+ policyManagerConfig = "0x",
3009
+ investment
3010
+ }) {
3011
+ const receipt = await fundDeployer.connect(signer).createNewFund(fundOwner, fundName, fundSymbol, denominationAsset, sharesActionTimelock, feeManagerConfig, policyManagerConfig);
3012
+ const comptrollerDeployedArgs = assertEvent(receipt, "ComptrollerProxyDeployed", {
3013
+ comptrollerProxy: expect.any(String),
3014
+ creator: signer,
3015
+ denominationAsset,
3016
+ sharesActionTimelock: BigNumber9.from(sharesActionTimelock)
3017
+ });
3018
+ const comptrollerProxy = new ComptrollerLib3(comptrollerDeployedArgs.comptrollerProxy, signer);
3019
+ const newFundDeployedArgs = assertEvent(receipt, "NewFundCreated", {
3020
+ comptrollerProxy,
3021
+ creator: signer,
3022
+ vaultProxy: expect.any(String)
3023
+ });
3024
+ const vaultProxy = new VaultLib4(newFundDeployedArgs.vaultProxy, signer);
3025
+ if (investment != null) {
3026
+ await buyShares(__spreadValues({
3027
+ comptrollerProxy,
3028
+ denominationAsset
3029
+ }, investment));
3030
+ }
3031
+ return {
3032
+ comptrollerProxy,
3033
+ receipt,
3034
+ vaultProxy
3035
+ };
3036
+ }
3037
+ async function createReconfigurationRequest({
3038
+ signer,
3039
+ fundDeployer,
3040
+ vaultProxy,
3041
+ denominationAsset,
3042
+ sharesActionTimelock = 0,
3043
+ feeManagerConfigData = "0x",
3044
+ policyManagerConfigData = "0x"
3045
+ }) {
3046
+ const receipt = await fundDeployer.connect(signer).createReconfigurationRequest(vaultProxy, denominationAsset, sharesActionTimelock, feeManagerConfigData, policyManagerConfigData);
3047
+ const comptrollerDeployedArgs = assertEvent(receipt, "ComptrollerProxyDeployed", {
3048
+ comptrollerProxy: expect.any(String),
3049
+ creator: signer,
3050
+ denominationAsset,
3051
+ sharesActionTimelock: BigNumber9.from(sharesActionTimelock)
3052
+ });
3053
+ return {
3054
+ comptrollerProxy: new ComptrollerLib3(comptrollerDeployedArgs.comptrollerProxy, signer),
3055
+ receipt
3056
+ };
3057
+ }
3058
+ async function createVaultProxy({
3059
+ signer,
3060
+ vaultLib,
3061
+ fundOwner,
3062
+ fundAccessor,
3063
+ fundName = "My Fund"
3064
+ }) {
3065
+ const constructData = encodeFunctionData(vaultLib.init.fragment, [fundOwner, fundAccessor, fundName]);
3066
+ const vaultProxyContract = await VaultProxy.deploy(signer, constructData, vaultLib);
3067
+ return new VaultLib4(vaultProxyContract, fundAccessor);
3068
+ }
3069
+ async function setupGasRelayerPaymaster({
3070
+ signer,
3071
+ vaultProxy,
3072
+ fundAccessor,
3073
+ weth,
3074
+ startingBalance = utils15.parseUnits("10", 18)
3075
+ }) {
3076
+ await weth.transfer(vaultProxy, startingBalance);
3077
+ const comptrollerProxy = new ComptrollerLib3(fundAccessor, signer);
3078
+ const receipt = await comptrollerProxy.deployGasRelayPaymaster();
3079
+ const eventArgs = assertEvent(receipt, "GasRelayPaymasterSet", {
3080
+ gasRelayPaymaster: expect.any(String)
3081
+ });
3082
+ return new GasRelayPaymasterLib(eventArgs.gasRelayPaymaster, signer);
3083
+ }
3084
+
3085
+ // src/scaffolding/vaultCalls.ts
3086
+ import {
3087
+ addressListRegistryCreateListSelector,
3088
+ curveMinterMintManySelector,
3089
+ curveMinterMintSelector,
3090
+ curveMinterToggleApproveMintSelector,
3091
+ encodeArgs as encodeArgs5,
3092
+ sighash as sighash2
3093
+ } from "@enzymefinance/protocol";
3094
+ import { constants as constants4, utils as utils16 } from "ethers";
3095
+ async function vaultCallCreateNewList({
3096
+ addressListRegistry,
3097
+ comptrollerProxy,
3098
+ items,
3099
+ owner,
3100
+ signer,
3101
+ updateType
3102
+ }) {
3103
+ await comptrollerProxy.connect(signer).vaultCallOnContract(addressListRegistry.address, addressListRegistryCreateListSelector, encodeArgs5(["address", "uint8", "address[]"], [owner, updateType, items]));
3104
+ const listCount = await addressListRegistry.getListCount();
3105
+ return listCount.sub(1);
3106
+ }
3107
+ function vaultCallCurveMinterMint({
3108
+ comptrollerProxy,
3109
+ minter,
3110
+ gauge
3111
+ }) {
3112
+ return comptrollerProxy.vaultCallOnContract(minter, curveMinterMintSelector, encodeArgs5(["address"], [gauge]));
3113
+ }
3114
+ function vaultCallCurveMinterMintMany({
3115
+ comptrollerProxy,
3116
+ minter,
3117
+ gauges
3118
+ }) {
3119
+ const gaugesFormatted = new Array(8).fill(constants4.AddressZero);
3120
+ for (const i in gauges) {
3121
+ gaugesFormatted[i] = gauges[i];
3122
+ }
3123
+ return comptrollerProxy.vaultCallOnContract(minter, curveMinterMintManySelector, encodeArgs5(["address[8]"], [gaugesFormatted]));
3124
+ }
3125
+ function vaultCallCurveMinterToggleApproveMint({
3126
+ comptrollerProxy,
3127
+ minter,
3128
+ account
3129
+ }) {
3130
+ return comptrollerProxy.vaultCallOnContract(minter, curveMinterToggleApproveMintSelector, encodeArgs5(["address"], [account]));
3131
+ }
3132
+ function vaultCallStartAssetBypassTimelock({
3133
+ comptrollerProxy,
3134
+ contract: contract7,
3135
+ asset
3136
+ }) {
3137
+ return comptrollerProxy.vaultCallOnContract(contract7, sighash2(utils16.FunctionFragment.fromString("startAssetBypassTimelock(address)")), encodeArgs5(["address"], [asset]));
3138
+ }
3139
+
3140
+ // src/whales.ts
3141
+ import { resolveAddress as resolveAddress4 } from "@enzymefinance/ethers";
3142
+ var whales = {
3143
+ bat: "0x12274c71304bc0e6b38a56b94d2949b118feb838",
3144
+ bnb: "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
3145
+ bnt: "0x7d1ed1601a12a172269436fa95fe156650603c1d",
3146
+ busd: "0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503",
3147
+ comp: "0x0f50d31b3eaefd65236dd3736b863cffa4c63c4e",
3148
+ crv: "0xf89501b77b2fa6329f94f5a05fe84cebb5c8b1a0",
3149
+ dai: "0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503",
3150
+ grt: "0xf977814e90da44bfa03b6295a0616a897441acec",
3151
+ knc: "0x09d51654bd9efbfcb56da3491989cc1444095fff",
3152
+ ldo: "0x3dba737ccc50a32a1764b493285dd51c8af6c278",
3153
+ link: "0xbe6977e08d4479c0a6777539ae0e8fa27be4e9d6",
3154
+ lusd: "0x24cbbef882a77c5aaa9abd6558e68b4c648453c5",
3155
+ mana: "0xefb94ac00f1cee8a89d5c3f49faa799da6f03024",
3156
+ mln: "0xd8f8a53945bcfbbc19da162aa405e662ef71c40d",
3157
+ ohm: "0x2cfcbd233268c302996c767347eb45bec36fb08d",
3158
+ rep: "0xc6a043b07d33b6f30d8cb501026c391cfd25abe1",
3159
+ ren: "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
3160
+ susd: "0xa5f7a39e55d7878bc5bd754ee5d6bd7a7662355b",
3161
+ sohm: "0x3d5c83351c872fdf07da498c84ca3275222f284c",
3162
+ uni: "0x47173b170c64d16393a52e6c480b3ad8c302ba1e",
3163
+ usdc: "0xae2d4617c862309a3d75a0ffb358c7a5009c673f",
3164
+ usdt: "0x5041ed759dd4afc3a72b8192c143f72f4724081a",
3165
+ weth: "0xe08A8b19e5722a201EaF20A6BC595eF655397bd5",
3166
+ zrx: "0x206376e8940e42538781cd94ef024df3c1e0fd43",
3167
+ ausdc: "0x3DdfA8eC3052539b6C9549F12cEA2C295cfF5296",
3168
+ ausdt: "0x7d6149ad9a573a6e2ca6ebf7d4897c1b766841b4",
3169
+ ccomp: "0xd74f186194ab9219fafac5c2fe4b3270169666db",
3170
+ cdai: "0x22fa8cc33a42320385cbd3690ed60a021891cb32",
3171
+ ceth: "0x8aceab8167c80cb8b3de7fa6228b889bb1130ee8",
3172
+ cuni: "0x39d8014b4f40d2cbc441137011d32023f4f1fd87",
3173
+ cusdc: "0xb3bd459e0598dde1fe84b1d0a1430be175b5d5be",
3174
+ fdai7: "0xa993d62492f41703f6185881eae755b0966ea5b0",
3175
+ feth7: "0x05f284897641661fee9f1c1413a4f599a43a746f",
3176
+ fdai8: "0xd6bf9d9079139dbb3a4fdb84b07efc75ea77838f",
3177
+ ftribe8: "0xdb5ac83c137321da29a59a7592232bc4ed461730",
3178
+ ptUsdc: "0x8904ffc6aa039db5941de11309a42372f3f7d2fd",
3179
+ seth: "0xc34a7c65aa08cb36744bda8eeec7b8e9891e147c",
3180
+ sxag: "0x40d68c490bf7262ec40048099aec23535f734be2",
3181
+ sxau: "0x92eb453b7b5b8d41edb44e2c8b8b53eb70a482c7",
3182
+ cvx: "0x0aca67fa70b142a3b9bf2ed89a81b40ff85dacdc",
3183
+ lidoSteth: "0x06920c9fc643de77b99cb7670a944ad31eaaa260",
3184
+ ust: "0x738cf6903e6c4e699d1c2dd9ab8b67fcdb3121ea",
3185
+ stecrv: "0x56c915758ad3f76fd287fff7563ee313142fb663"
3186
+ };
3187
+ async function unlockWhale(token) {
3188
+ const address = resolveAddress4(whales[token]);
3189
+ await provider.send("hardhat_impersonateAccount", [address]);
3190
+ return provider.getSignerWithAddress(address);
3191
+ }
3192
+ async function unlockAllWhales() {
3193
+ const keys = Object.keys(whales);
3194
+ const signers = await Promise.all(keys.map(async (token) => unlockWhale(token)));
3195
+ const initial = {};
3196
+ return keys.reduce((carry, key, index) => {
3197
+ return __spreadProps(__spreadValues({}, carry), { [key]: signers[index] });
3198
+ }, initial);
3199
+ }
3200
+ async function unlockWhales(...tokens) {
3201
+ const signers = await Promise.all(tokens.map(async (token) => unlockWhale(token)));
3202
+ const initial = {};
3203
+ return tokens.reduce((carry, key, index) => {
3204
+ return __spreadProps(__spreadValues({}, carry), { [key]: signers[index] });
3205
+ }, initial);
3206
+ }
3207
+ export {
3208
+ CurveLiquidityGaugeV2,
3209
+ CurveMinter,
3210
+ CurveRegistry,
3211
+ CurveSwaps,
3212
+ ICompoundComptroller,
3213
+ IConvexBaseRewardPool,
3214
+ IConvexCrvDepositor,
3215
+ IConvexCvxLocker,
3216
+ IConvexVlCvxExtraRewardDistribution,
3217
+ ILiquityHintHelper,
3218
+ ILiquitySortedTroves,
3219
+ ILiquityTroveManager,
3220
+ ISnapshotDelegateRegistry,
3221
+ IUniswapV3NonFungibleTokenManager,
3222
+ IVotiumMultiMerkleStash,
3223
+ UniswapV2Factory,
3224
+ UniswapV3FeeAmount,
3225
+ aaveDebtPositionAddCollateral,
3226
+ aaveDebtPositionBorrow,
3227
+ aaveDebtPositionClaimRewards,
3228
+ aaveDebtPositionRemoveCollateral,
3229
+ aaveDebtPositionRepayBorrow,
3230
+ aaveLend,
3231
+ aaveRedeem,
3232
+ addNewAssetsToFund,
3233
+ addTrackedAssetsToVault,
3234
+ assertCompoundLend,
3235
+ assertCompoundRedeem,
3236
+ assertDidRelay,
3237
+ assertDidRelaySuccessfully,
3238
+ assertDidRelayWithCharge,
3239
+ assertDidRelayWithError,
3240
+ assertEvent,
3241
+ assertNoEvent,
3242
+ assertPaymasterDidReject,
3243
+ assertPaymasterDidRejectForReason,
3244
+ buyShares,
3245
+ buySharesFunction,
3246
+ calcMlnValueAndBurnAmountForSharesBuyback,
3247
+ callOnExtension,
3248
+ callOnExternalPosition,
3249
+ compoundClaim,
3250
+ compoundDebtPositionAddCollateral,
3251
+ compoundDebtPositionBorrow,
3252
+ compoundDebtPositionClaimComp,
3253
+ compoundDebtPositionRemoveCollateral,
3254
+ compoundDebtPositionRepayBorrow,
3255
+ compoundLend,
3256
+ compoundRedeem,
3257
+ convexVotingPositionClaimRewards,
3258
+ convexVotingPositionDelegate,
3259
+ convexVotingPositionLock,
3260
+ convexVotingPositionRelock,
3261
+ convexVotingPositionWithdraw,
3262
+ createAaveDebtPosition,
3263
+ createCompoundDebtPosition,
3264
+ createComptrollerProxy,
3265
+ createConvexVotingPosition,
3266
+ createExternalPosition,
3267
+ createFundDeployer,
3268
+ createLiquityDebtPosition,
3269
+ createMapleLiquidityPosition,
3270
+ createMigrationRequest,
3271
+ createMockExternalPosition,
3272
+ createNewFund,
3273
+ createReconfigurationRequest,
3274
+ createTheGraphDelegationPosition,
3275
+ createUniswapV3LiquidityPosition,
3276
+ createVaultProxy,
3277
+ curveClaimRewards,
3278
+ curveLend,
3279
+ curveLendAndStake,
3280
+ curveRedeem,
3281
+ curveStake,
3282
+ curveTakeOrder,
3283
+ curveUnstake,
3284
+ curveUnstakeAndRedeem,
3285
+ deployManualValueOracle,
3286
+ deployProtocolFixture,
3287
+ deploySharesSplitter,
3288
+ generateFeeManagerConfigWithMockFees,
3289
+ generateMerkleTreeForContractProof,
3290
+ generateMockFees,
3291
+ generateMockPolicies,
3292
+ generatePolicyManagerConfigWithMockPolicies,
3293
+ getAssetBalances,
3294
+ getAssetUnit,
3295
+ getNamedSigner,
3296
+ getUnnamedSigners,
3297
+ idleClaimRewards,
3298
+ idleLend,
3299
+ idleRedeem,
3300
+ impersonateContractSigner,
3301
+ impersonateSigner,
3302
+ liquityCalcHints,
3303
+ liquityDebtPositionAddCollateral,
3304
+ liquityDebtPositionBorrow,
3305
+ liquityDebtPositionCloseTrove,
3306
+ liquityDebtPositionOpenTrove,
3307
+ liquityDebtPositionRemoveCollateral,
3308
+ liquityDebtPositionRepay,
3309
+ mapleLiquidityPositionClaimInterest,
3310
+ mapleLiquidityPositionClaimRewards,
3311
+ mapleLiquidityPositionIntendToRedeem,
3312
+ mapleLiquidityPositionLend,
3313
+ mapleLiquidityPositionLendAndStake,
3314
+ mapleLiquidityPositionRedeem,
3315
+ mapleLiquidityPositionStake,
3316
+ mapleLiquidityPositionUnstake,
3317
+ mapleLiquidityPositionUnstakeAndRedeem,
3318
+ mockExternalPositionAddDebtAssets,
3319
+ mockExternalPositionAddManagedAssets,
3320
+ mockExternalPositionRemoveDebtAssets,
3321
+ mockExternalPositionRemoveManagedAssets,
3322
+ mockGenericRemoveOnlySelector,
3323
+ mockGenericSwap,
3324
+ mockGenericSwapASelector,
3325
+ mockGenericSwapArgs,
3326
+ mockGenericSwapBSelector,
3327
+ mockGenericSwapDirectFromVaultSelector,
3328
+ mockGenericSwapViaApprovalSelector,
3329
+ olympusV2Stake,
3330
+ olympusV2Unstake,
3331
+ paraSwapV5GenerateDummyPaths,
3332
+ paraSwapV5TakeOrder,
3333
+ poolTogetherV4ClaimRewards,
3334
+ poolTogetherV4Lend,
3335
+ poolTogetherV4Redeem,
3336
+ reactivateExternalPosition,
3337
+ redeemSharesForSpecificAssets,
3338
+ redeemSharesInKind,
3339
+ relayTransaction,
3340
+ removeExternalPosition,
3341
+ removeTrackedAssetsFromVault,
3342
+ sendEthBySelfDestruct,
3343
+ setupGasRelayerPaymaster,
3344
+ synthetixAssignExchangeDelegate,
3345
+ synthetixRedeem,
3346
+ synthetixTakeOrder,
3347
+ theGraphDelegationPositionDelegate,
3348
+ theGraphDelegationPositionUndelegate,
3349
+ theGraphDelegationPositionWithdraw,
3350
+ transactionTimestamp,
3351
+ uniswapV2Lend,
3352
+ uniswapV2Redeem,
3353
+ uniswapV2TakeOrder,
3354
+ uniswapV3LiquidityPositionAddLiquidity,
3355
+ uniswapV3LiquidityPositionCollect,
3356
+ uniswapV3LiquidityPositionGetMaxTick,
3357
+ uniswapV3LiquidityPositionGetMinTick,
3358
+ uniswapV3LiquidityPositionMint,
3359
+ uniswapV3LiquidityPositionPurge,
3360
+ uniswapV3LiquidityPositionRemoveLiquidity,
3361
+ uniswapV3OrderTokenPair,
3362
+ uniswapV3TakeOrder,
3363
+ unlockAllWhales,
3364
+ unlockWhale,
3365
+ unlockWhales,
3366
+ updateChainlinkAggregator,
3367
+ vaultCallCreateNewList,
3368
+ vaultCallCurveMinterMint,
3369
+ vaultCallCurveMinterMintMany,
3370
+ vaultCallCurveMinterToggleApproveMint,
3371
+ vaultCallStartAssetBypassTimelock,
3372
+ yearnVaultV2Lend,
3373
+ yearnVaultV2Redeem,
3374
+ zeroExV2TakeOrder
3375
+ };