@enzymefinance/testutils 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/declarations/src/assertions.d.ts +4 -0
- package/dist/declarations/src/deployment.d.ts +81 -0
- package/dist/declarations/src/helpers.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +5 -0
- package/dist/declarations/src/scaffolding/assets.d.ts +12 -0
- package/dist/declarations/src/scaffolding/chainlink.d.ts +3 -0
- package/dist/declarations/src/scaffolding/common.d.ts +6 -0
- package/dist/declarations/src/scaffolding/core.d.ts +19 -0
- package/dist/declarations/src/scaffolding/extensions/common.d.ts +11 -0
- package/dist/declarations/src/scaffolding/extensions/fees.d.ts +14 -0
- package/dist/declarations/src/scaffolding/extensions/index.d.ts +4 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/aave.d.ts +19 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/alpha.d.ts +36 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/compound.d.ts +27 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/curve.d.ts +331 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/idle.d.ts +57 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/index.d.ts +14 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/kyber.d.ts +23 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/mock.d.ts +32 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/paraSwapV4.d.ts +22 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/synthetix.d.ts +25 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/trackedAssets.d.ts +17 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/uniswapV2.d.ts +46 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/uniswapV3.d.ts +15 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/yearn.d.ts +22 -0
- package/dist/declarations/src/scaffolding/extensions/integrations/zeroExV2.d.ts +12 -0
- package/dist/declarations/src/scaffolding/extensions/policies.d.ts +15 -0
- package/dist/declarations/src/scaffolding/index.d.ts +9 -0
- package/dist/declarations/src/scaffolding/peripheral/index.d.ts +1 -0
- package/dist/declarations/src/scaffolding/peripheral/sharesRequestors.d.ts +19 -0
- package/dist/declarations/src/scaffolding/setup.d.ts +46 -0
- package/dist/declarations/src/scaffolding/shares.d.ts +30 -0
- package/dist/declarations/src/scaffolding/vaultCalls.d.ts +17 -0
- package/dist/declarations/src/whales.d.ts +43 -0
- package/dist/enzymefinance-testutils.browser.cjs.js +3160 -0
- package/dist/enzymefinance-testutils.browser.esm.js +3045 -0
- package/dist/enzymefinance-testutils.cjs.d.ts +1 -0
- package/dist/enzymefinance-testutils.cjs.dev.js +3160 -0
- package/dist/enzymefinance-testutils.cjs.js +7 -0
- package/dist/enzymefinance-testutils.cjs.prod.js +3160 -0
- package/dist/enzymefinance-testutils.esm.js +3045 -0
- package/package.json +18 -0
- package/src/assertions.ts +20 -0
- package/src/deployment.ts +169 -0
- package/src/helpers.ts +6 -0
- package/src/index.ts +5 -0
- package/src/scaffolding/assets.ts +39 -0
- package/src/scaffolding/chainlink.ts +8 -0
- package/src/scaffolding/common.ts +6 -0
- package/src/scaffolding/core.ts +77 -0
- package/src/scaffolding/extensions/common.ts +30 -0
- package/src/scaffolding/extensions/fees.ts +87 -0
- package/src/scaffolding/extensions/index.ts +4 -0
- package/src/scaffolding/extensions/integrations/aave.ts +80 -0
- package/src/scaffolding/extensions/integrations/alpha.ts +119 -0
- package/src/scaffolding/extensions/integrations/compound.ts +97 -0
- package/src/scaffolding/extensions/integrations/curve.ts +1207 -0
- package/src/scaffolding/extensions/integrations/idle.ts +215 -0
- package/src/scaffolding/extensions/integrations/index.ts +14 -0
- package/src/scaffolding/extensions/integrations/kyber.ts +69 -0
- package/src/scaffolding/extensions/integrations/mock.ts +118 -0
- package/src/scaffolding/extensions/integrations/paraSwapV4.ts +65 -0
- package/src/scaffolding/extensions/integrations/synthetix.ts +97 -0
- package/src/scaffolding/extensions/integrations/trackedAssets.ts +66 -0
- package/src/scaffolding/extensions/integrations/uniswapV2.ts +171 -0
- package/src/scaffolding/extensions/integrations/uniswapV3.ts +56 -0
- package/src/scaffolding/extensions/integrations/yearn.ts +81 -0
- package/src/scaffolding/extensions/integrations/zeroExV2.ts +45 -0
- package/src/scaffolding/extensions/policies.ts +85 -0
- package/src/scaffolding/index.ts +9 -0
- package/src/scaffolding/peripheral/index.ts +1 -0
- package/src/scaffolding/peripheral/sharesRequestors.ts +53 -0
- package/src/scaffolding/setup.ts +135 -0
- package/src/scaffolding/shares.ts +63 -0
- package/src/scaffolding/vaultCalls.ts +58 -0
- package/src/types.d.ts +1 -0
- package/src/whales.ts +63 -0
- package/tsconfig.json +4 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
|
2
|
+
import {
|
|
3
|
+
ComptrollerLib,
|
|
4
|
+
IntegrationManager,
|
|
5
|
+
ZeroExV2Adapter,
|
|
6
|
+
VaultLib,
|
|
7
|
+
SignedZeroExV2Order,
|
|
8
|
+
callOnIntegrationArgs,
|
|
9
|
+
takeOrderSelector,
|
|
10
|
+
zeroExV2TakeOrderArgs,
|
|
11
|
+
IntegrationManagerActionId,
|
|
12
|
+
} from '@enzymefinance/protocol';
|
|
13
|
+
import { BigNumberish } from 'ethers';
|
|
14
|
+
|
|
15
|
+
export async function zeroExV2TakeOrder({
|
|
16
|
+
comptrollerProxy,
|
|
17
|
+
integrationManager,
|
|
18
|
+
fundOwner,
|
|
19
|
+
zeroExV2Adapter,
|
|
20
|
+
signedOrder,
|
|
21
|
+
takerAssetFillAmount,
|
|
22
|
+
}: {
|
|
23
|
+
comptrollerProxy: ComptrollerLib;
|
|
24
|
+
vaultProxy: VaultLib;
|
|
25
|
+
integrationManager: IntegrationManager;
|
|
26
|
+
fundOwner: SignerWithAddress;
|
|
27
|
+
zeroExV2Adapter: ZeroExV2Adapter;
|
|
28
|
+
signedOrder: SignedZeroExV2Order;
|
|
29
|
+
takerAssetFillAmount: BigNumberish;
|
|
30
|
+
}) {
|
|
31
|
+
const takeOrderArgs = zeroExV2TakeOrderArgs({
|
|
32
|
+
signedOrder,
|
|
33
|
+
takerAssetFillAmount,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const callArgs = callOnIntegrationArgs({
|
|
37
|
+
adapter: zeroExV2Adapter,
|
|
38
|
+
selector: takeOrderSelector,
|
|
39
|
+
encodedCallArgs: takeOrderArgs,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return comptrollerProxy
|
|
43
|
+
.connect(fundOwner)
|
|
44
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
|
45
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IPolicy, PolicyHook, PolicyManager, policyManagerConfigArgs } from '@enzymefinance/protocol';
|
|
2
|
+
import { constants, Signer, utils } from 'ethers';
|
|
3
|
+
|
|
4
|
+
// Policy Manager
|
|
5
|
+
|
|
6
|
+
export async function generatePolicyManagerConfigWithMockPolicies({
|
|
7
|
+
deployer,
|
|
8
|
+
policyManager,
|
|
9
|
+
}: {
|
|
10
|
+
deployer: Signer;
|
|
11
|
+
policyManager: PolicyManager;
|
|
12
|
+
}) {
|
|
13
|
+
const policies = await generateRegisteredMockPolicies({
|
|
14
|
+
deployer,
|
|
15
|
+
policyManager,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const policiesSettingsData = [utils.randomBytes(10), constants.HashZero, constants.HashZero, utils.randomBytes(2)];
|
|
19
|
+
|
|
20
|
+
return policyManagerConfigArgs({
|
|
21
|
+
policies: Object.values(policies),
|
|
22
|
+
settings: policiesSettingsData,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function generateRegisteredMockPolicies({
|
|
27
|
+
deployer,
|
|
28
|
+
policyManager,
|
|
29
|
+
}: {
|
|
30
|
+
deployer: Signer;
|
|
31
|
+
policyManager: PolicyManager;
|
|
32
|
+
}) {
|
|
33
|
+
// Create mock policies
|
|
34
|
+
const mockPreBuySharesPolicy = await IPolicy.mock(deployer);
|
|
35
|
+
const mockPostBuySharesPolicy = await IPolicy.mock(deployer);
|
|
36
|
+
const mockPreCoIPolicy = await IPolicy.mock(deployer);
|
|
37
|
+
const mockPostCoIPolicy = await IPolicy.mock(deployer);
|
|
38
|
+
|
|
39
|
+
// Initialize mock policy return values
|
|
40
|
+
await Promise.all([
|
|
41
|
+
// PreBuyShares
|
|
42
|
+
mockPreBuySharesPolicy.identifier.returns(`MOCK_PRE_BUY_SHARES`),
|
|
43
|
+
mockPreBuySharesPolicy.addFundSettings.returns(undefined),
|
|
44
|
+
mockPreBuySharesPolicy.activateForFund.returns(undefined),
|
|
45
|
+
mockPreBuySharesPolicy.validateRule.returns(true),
|
|
46
|
+
mockPreBuySharesPolicy.implementedHooks.returns([PolicyHook.PreBuyShares]),
|
|
47
|
+
mockPreBuySharesPolicy.updateFundSettings.returns(undefined),
|
|
48
|
+
// PostBuyShares
|
|
49
|
+
mockPostBuySharesPolicy.identifier.returns(`MOCK_POST_BUY_SHARES`),
|
|
50
|
+
mockPostBuySharesPolicy.addFundSettings.returns(undefined),
|
|
51
|
+
mockPostBuySharesPolicy.activateForFund.returns(undefined),
|
|
52
|
+
mockPostBuySharesPolicy.validateRule.returns(true),
|
|
53
|
+
mockPostBuySharesPolicy.implementedHooks.returns([PolicyHook.PostBuyShares]),
|
|
54
|
+
mockPostBuySharesPolicy.updateFundSettings.returns(undefined),
|
|
55
|
+
// PreCallOnIntegration
|
|
56
|
+
mockPreCoIPolicy.identifier.returns(`MOCK_PRE_CALL_ON_INTEGRATION`),
|
|
57
|
+
mockPreCoIPolicy.addFundSettings.returns(undefined),
|
|
58
|
+
mockPreCoIPolicy.activateForFund.returns(undefined),
|
|
59
|
+
mockPreCoIPolicy.validateRule.returns(true),
|
|
60
|
+
mockPreCoIPolicy.implementedHooks.returns([PolicyHook.PreCallOnIntegration]),
|
|
61
|
+
mockPreCoIPolicy.updateFundSettings.returns(undefined),
|
|
62
|
+
// PostCallOnIntegration
|
|
63
|
+
mockPostCoIPolicy.identifier.returns(`MOCK_POST_CALL_ON_INTEGRATION`),
|
|
64
|
+
mockPostCoIPolicy.addFundSettings.returns(undefined),
|
|
65
|
+
mockPostCoIPolicy.activateForFund.returns(undefined),
|
|
66
|
+
mockPostCoIPolicy.validateRule.returns(true),
|
|
67
|
+
mockPostCoIPolicy.implementedHooks.returns([PolicyHook.PostCallOnIntegration]),
|
|
68
|
+
mockPostCoIPolicy.updateFundSettings.returns(undefined),
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
// Register all mock policies
|
|
72
|
+
await policyManager.registerPolicies([
|
|
73
|
+
mockPreBuySharesPolicy,
|
|
74
|
+
mockPostBuySharesPolicy,
|
|
75
|
+
mockPreCoIPolicy,
|
|
76
|
+
mockPostCoIPolicy,
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
mockPreBuySharesPolicy,
|
|
81
|
+
mockPostBuySharesPolicy,
|
|
82
|
+
mockPreCoIPolicy,
|
|
83
|
+
mockPostCoIPolicy,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sharesRequestors';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AddressLike } from '@enzymefinance/ethers';
|
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
|
3
|
+
import {
|
|
4
|
+
AuthUserExecutedSharesRequestorFactory,
|
|
5
|
+
AuthUserExecutedSharesRequestorLib,
|
|
6
|
+
StandardToken,
|
|
7
|
+
} from '@enzymefinance/protocol';
|
|
8
|
+
import { BigNumberish, utils } from 'ethers';
|
|
9
|
+
import { assertEvent } from '../../assertions';
|
|
10
|
+
|
|
11
|
+
export async function createAuthUserExecutedSharesRequestorProxy({
|
|
12
|
+
signer,
|
|
13
|
+
authUserExecutedSharesRequestorFactory,
|
|
14
|
+
comptrollerProxy,
|
|
15
|
+
}: {
|
|
16
|
+
signer: SignerWithAddress;
|
|
17
|
+
authUserExecutedSharesRequestorFactory: AuthUserExecutedSharesRequestorFactory;
|
|
18
|
+
comptrollerProxy: AddressLike;
|
|
19
|
+
}) {
|
|
20
|
+
const receipt = await authUserExecutedSharesRequestorFactory
|
|
21
|
+
.connect(signer)
|
|
22
|
+
.deploySharesRequestorProxy(comptrollerProxy);
|
|
23
|
+
|
|
24
|
+
const sharesRequestorProxyDeployedArgs = assertEvent(receipt, 'SharesRequestorProxyDeployed', {
|
|
25
|
+
comptrollerProxy,
|
|
26
|
+
sharesRequestorProxy: expect.any(String) as string,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
authUserExecutedSharesRequestorProxy: new AuthUserExecutedSharesRequestorLib(
|
|
31
|
+
sharesRequestorProxyDeployedArgs.sharesRequestorProxy,
|
|
32
|
+
signer,
|
|
33
|
+
),
|
|
34
|
+
receipt,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function createAuthUserExecutedSharesRequest({
|
|
39
|
+
buyer,
|
|
40
|
+
authUserExecutedSharesRequestorProxy,
|
|
41
|
+
denominationAsset,
|
|
42
|
+
investmentAmount = utils.parseEther('1'),
|
|
43
|
+
minSharesQuantity = investmentAmount,
|
|
44
|
+
}: {
|
|
45
|
+
buyer: SignerWithAddress;
|
|
46
|
+
authUserExecutedSharesRequestorProxy: AuthUserExecutedSharesRequestorLib;
|
|
47
|
+
denominationAsset: StandardToken;
|
|
48
|
+
investmentAmount?: BigNumberish;
|
|
49
|
+
minSharesQuantity?: BigNumberish;
|
|
50
|
+
}) {
|
|
51
|
+
await denominationAsset.connect(buyer).approve(authUserExecutedSharesRequestorProxy, investmentAmount);
|
|
52
|
+
return authUserExecutedSharesRequestorProxy.connect(buyer).createRequest(investmentAmount, minSharesQuantity);
|
|
53
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AddressLike, randomAddress } from '@enzymefinance/ethers';
|
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
|
3
|
+
import { ComptrollerLib, ComptrollerProxy, encodeFunctionData, FundDeployer, VaultLib } from '@enzymefinance/protocol';
|
|
4
|
+
import { BigNumber, BigNumberish, BytesLike, utils } from 'ethers';
|
|
5
|
+
import { assertEvent } from '../assertions';
|
|
6
|
+
import { buyShares, BuySharesParams, DenominationAssetInterface } from './shares';
|
|
7
|
+
|
|
8
|
+
export type InitialInvestmentParams = Omit<BuySharesParams, 'comptrollerProxy' | 'denominationAsset'>;
|
|
9
|
+
|
|
10
|
+
export interface CreateMigratedFundConfigParams {
|
|
11
|
+
signer: SignerWithAddress;
|
|
12
|
+
fundDeployer: FundDeployer;
|
|
13
|
+
denominationAsset: DenominationAssetInterface;
|
|
14
|
+
sharesActionTimelock?: BigNumberish;
|
|
15
|
+
feeManagerConfigData?: BytesLike;
|
|
16
|
+
policyManagerConfigData?: BytesLike;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CreateNewFundParams {
|
|
20
|
+
signer: SignerWithAddress;
|
|
21
|
+
fundDeployer: FundDeployer;
|
|
22
|
+
denominationAsset: DenominationAssetInterface;
|
|
23
|
+
sharesActionTimelock?: BigNumberish;
|
|
24
|
+
fundOwner?: AddressLike;
|
|
25
|
+
fundName?: string;
|
|
26
|
+
feeManagerConfig?: BytesLike;
|
|
27
|
+
policyManagerConfig?: BytesLike;
|
|
28
|
+
investment?: InitialInvestmentParams;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function createComptrollerProxy({
|
|
32
|
+
signer,
|
|
33
|
+
comptrollerLib,
|
|
34
|
+
denominationAsset,
|
|
35
|
+
sharesActionTimelock = 0,
|
|
36
|
+
}: {
|
|
37
|
+
signer: SignerWithAddress;
|
|
38
|
+
comptrollerLib: ComptrollerLib;
|
|
39
|
+
denominationAsset: AddressLike;
|
|
40
|
+
sharesActionTimelock?: BigNumberish;
|
|
41
|
+
}) {
|
|
42
|
+
const constructData = encodeFunctionData(comptrollerLib.init.fragment, [denominationAsset, sharesActionTimelock]);
|
|
43
|
+
|
|
44
|
+
const comptrollerProxyContract = await ComptrollerProxy.deploy(signer, constructData, comptrollerLib);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
comptrollerProxy: new ComptrollerLib(comptrollerProxyContract, signer),
|
|
48
|
+
receipt: comptrollerProxyContract.deployment!,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function createMigratedFundConfig({
|
|
53
|
+
signer,
|
|
54
|
+
fundDeployer,
|
|
55
|
+
denominationAsset,
|
|
56
|
+
sharesActionTimelock = 0,
|
|
57
|
+
feeManagerConfigData = '0x',
|
|
58
|
+
policyManagerConfigData = '0x',
|
|
59
|
+
}: CreateMigratedFundConfigParams) {
|
|
60
|
+
const receipt = await fundDeployer
|
|
61
|
+
.connect(signer)
|
|
62
|
+
.createMigratedFundConfig(denominationAsset, sharesActionTimelock, feeManagerConfigData, policyManagerConfigData);
|
|
63
|
+
|
|
64
|
+
const comptrollerDeployedArgs = assertEvent(receipt, 'ComptrollerProxyDeployed', {
|
|
65
|
+
creator: signer,
|
|
66
|
+
comptrollerProxy: expect.any(String) as string,
|
|
67
|
+
denominationAsset,
|
|
68
|
+
sharesActionTimelock: BigNumber.from(sharesActionTimelock),
|
|
69
|
+
feeManagerConfigData: utils.hexlify(feeManagerConfigData),
|
|
70
|
+
policyManagerConfigData: utils.hexlify(policyManagerConfigData),
|
|
71
|
+
forMigration: true,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
receipt,
|
|
76
|
+
comptrollerProxy: new ComptrollerLib(comptrollerDeployedArgs.comptrollerProxy, signer),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// TODO: should we pass in the fundOwner as a signer also so we can connect comptroller proxy and vault proxy to that acct instead?
|
|
81
|
+
export async function createNewFund({
|
|
82
|
+
signer,
|
|
83
|
+
fundDeployer,
|
|
84
|
+
denominationAsset,
|
|
85
|
+
sharesActionTimelock = 0,
|
|
86
|
+
fundOwner = randomAddress(),
|
|
87
|
+
fundName = 'My Fund',
|
|
88
|
+
feeManagerConfig = '0x',
|
|
89
|
+
policyManagerConfig = '0x',
|
|
90
|
+
investment,
|
|
91
|
+
}: CreateNewFundParams) {
|
|
92
|
+
const receipt = await fundDeployer
|
|
93
|
+
.connect(signer)
|
|
94
|
+
.createNewFund(fundOwner, fundName, denominationAsset, sharesActionTimelock, feeManagerConfig, policyManagerConfig);
|
|
95
|
+
|
|
96
|
+
const comptrollerDeployedArgs = assertEvent(receipt, 'ComptrollerProxyDeployed', {
|
|
97
|
+
creator: signer,
|
|
98
|
+
comptrollerProxy: expect.any(String) as string,
|
|
99
|
+
denominationAsset,
|
|
100
|
+
sharesActionTimelock: BigNumber.from(sharesActionTimelock),
|
|
101
|
+
feeManagerConfigData: utils.hexlify(feeManagerConfig),
|
|
102
|
+
policyManagerConfigData: utils.hexlify(policyManagerConfig),
|
|
103
|
+
forMigration: false,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const comptrollerProxy = new ComptrollerLib(comptrollerDeployedArgs.comptrollerProxy, signer);
|
|
107
|
+
|
|
108
|
+
const newFundDeployedArgs = assertEvent(receipt, 'NewFundCreated', {
|
|
109
|
+
creator: signer,
|
|
110
|
+
comptrollerProxy,
|
|
111
|
+
vaultProxy: expect.any(String) as string,
|
|
112
|
+
fundOwner,
|
|
113
|
+
fundName,
|
|
114
|
+
denominationAsset,
|
|
115
|
+
sharesActionTimelock: BigNumber.from(sharesActionTimelock),
|
|
116
|
+
feeManagerConfigData: utils.hexlify(feeManagerConfig),
|
|
117
|
+
policyManagerConfigData: utils.hexlify(policyManagerConfig),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const vaultProxy = new VaultLib(newFundDeployedArgs.vaultProxy, signer);
|
|
121
|
+
|
|
122
|
+
if (investment != null) {
|
|
123
|
+
await buyShares({
|
|
124
|
+
comptrollerProxy,
|
|
125
|
+
denominationAsset,
|
|
126
|
+
...investment,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
comptrollerProxy,
|
|
132
|
+
receipt,
|
|
133
|
+
vaultProxy,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AddressLike, Contract, Send } from '@enzymefinance/ethers';
|
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
|
3
|
+
import { ComptrollerLib } from '@enzymefinance/protocol';
|
|
4
|
+
import { BigNumber, BigNumberish, constants, utils } from 'ethers';
|
|
5
|
+
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
export interface DenominationAssetInterface extends Contract<any> {
|
|
8
|
+
approve: Send<(spender: AddressLike, amount: BigNumberish) => boolean, any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BuySharesParams {
|
|
12
|
+
comptrollerProxy: ComptrollerLib;
|
|
13
|
+
signer: SignerWithAddress;
|
|
14
|
+
buyers: AddressLike[];
|
|
15
|
+
denominationAsset: DenominationAssetInterface;
|
|
16
|
+
investmentAmounts?: BigNumberish[];
|
|
17
|
+
minSharesAmounts?: BigNumberish[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface RedeemSharesParams {
|
|
21
|
+
comptrollerProxy: ComptrollerLib;
|
|
22
|
+
signer: SignerWithAddress;
|
|
23
|
+
quantity?: BigNumberish;
|
|
24
|
+
additionalAssets?: AddressLike[];
|
|
25
|
+
assetsToSkip?: AddressLike[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function buyShares({
|
|
29
|
+
comptrollerProxy,
|
|
30
|
+
signer,
|
|
31
|
+
buyers,
|
|
32
|
+
denominationAsset,
|
|
33
|
+
investmentAmounts = new Array(buyers.length).fill(utils.parseEther('1')),
|
|
34
|
+
minSharesAmounts = investmentAmounts,
|
|
35
|
+
}: BuySharesParams) {
|
|
36
|
+
const totalInvestmentAmount = investmentAmounts.reduce(
|
|
37
|
+
(total: BigNumber, amount) => total.add(amount),
|
|
38
|
+
constants.Zero,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const callerDenominationAsset = denominationAsset.connect(signer);
|
|
42
|
+
await callerDenominationAsset.approve(comptrollerProxy, totalInvestmentAmount);
|
|
43
|
+
|
|
44
|
+
const callerComptrollerProxy = comptrollerProxy.connect(signer);
|
|
45
|
+
return callerComptrollerProxy.buyShares(buyers, investmentAmounts, minSharesAmounts);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function redeemShares({
|
|
49
|
+
comptrollerProxy,
|
|
50
|
+
signer,
|
|
51
|
+
quantity,
|
|
52
|
+
additionalAssets = [],
|
|
53
|
+
assetsToSkip = [],
|
|
54
|
+
}: RedeemSharesParams) {
|
|
55
|
+
if (quantity == undefined) {
|
|
56
|
+
if (additionalAssets.length > 0 || assetsToSkip.length > 0) {
|
|
57
|
+
throw 'Must specify shares quantity if specifying additional assets or assets to skip';
|
|
58
|
+
}
|
|
59
|
+
return comptrollerProxy.connect(signer).redeemShares();
|
|
60
|
+
} else {
|
|
61
|
+
return comptrollerProxy.connect(signer).redeemSharesDetailed(quantity, additionalAssets, assetsToSkip);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AddressLike } from '@enzymefinance/ethers';
|
|
2
|
+
import {
|
|
3
|
+
ComptrollerLib,
|
|
4
|
+
curveMinterMintManySelector,
|
|
5
|
+
curveMinterMintSelector,
|
|
6
|
+
curveMinterToggleApproveMintSelector,
|
|
7
|
+
encodeArgs,
|
|
8
|
+
} from '@enzymefinance/protocol';
|
|
9
|
+
import { constants } from 'ethers';
|
|
10
|
+
|
|
11
|
+
export function vaultCallCurveMinterMint({
|
|
12
|
+
comptrollerProxy,
|
|
13
|
+
minter,
|
|
14
|
+
gauge,
|
|
15
|
+
}: {
|
|
16
|
+
comptrollerProxy: ComptrollerLib;
|
|
17
|
+
minter: AddressLike;
|
|
18
|
+
gauge: AddressLike;
|
|
19
|
+
}) {
|
|
20
|
+
return comptrollerProxy.vaultCallOnContract(minter, curveMinterMintSelector, encodeArgs(['address'], [gauge]));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function vaultCallCurveMinterMintMany({
|
|
24
|
+
comptrollerProxy,
|
|
25
|
+
minter,
|
|
26
|
+
gauges,
|
|
27
|
+
}: {
|
|
28
|
+
comptrollerProxy: ComptrollerLib;
|
|
29
|
+
minter: AddressLike;
|
|
30
|
+
gauges: AddressLike[];
|
|
31
|
+
}) {
|
|
32
|
+
const gaugesFormatted = new Array(8).fill(constants.AddressZero);
|
|
33
|
+
for (const i in gauges) {
|
|
34
|
+
gaugesFormatted[i] = gauges[i];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return comptrollerProxy.vaultCallOnContract(
|
|
38
|
+
minter,
|
|
39
|
+
curveMinterMintManySelector,
|
|
40
|
+
encodeArgs(['address[8]'], [gaugesFormatted]),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function vaultCallCurveMinterToggleApproveMint({
|
|
45
|
+
comptrollerProxy,
|
|
46
|
+
minter,
|
|
47
|
+
account,
|
|
48
|
+
}: {
|
|
49
|
+
comptrollerProxy: ComptrollerLib;
|
|
50
|
+
minter: AddressLike;
|
|
51
|
+
account: AddressLike;
|
|
52
|
+
}) {
|
|
53
|
+
return comptrollerProxy.vaultCallOnContract(
|
|
54
|
+
minter,
|
|
55
|
+
curveMinterToggleApproveMintSelector,
|
|
56
|
+
encodeArgs(['address'], [account]),
|
|
57
|
+
);
|
|
58
|
+
}
|