@enzymefinance/testutils 4.0.0 → 4.0.1

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