@enzymefinance/testutils 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,215 @@
|
|
1
|
+
import { AddressLike } from '@enzymefinance/ethers';
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
3
|
+
import {
|
4
|
+
approveAssetsSelector,
|
5
|
+
callOnIntegrationArgs,
|
6
|
+
claimRewardsAndReinvestSelector,
|
7
|
+
claimRewardsAndSwapSelector,
|
8
|
+
claimRewardsSelector,
|
9
|
+
ComptrollerLib,
|
10
|
+
IdleAdapter,
|
11
|
+
idleApproveAssetsArgs,
|
12
|
+
idleClaimRewardsAndReinvestArgs,
|
13
|
+
idleClaimRewardsAndSwapArgs,
|
14
|
+
idleClaimRewardsArgs,
|
15
|
+
idleLendArgs,
|
16
|
+
idleRedeemArgs,
|
17
|
+
IntegrationManager,
|
18
|
+
IntegrationManagerActionId,
|
19
|
+
lendSelector,
|
20
|
+
redeemSelector,
|
21
|
+
StandardToken,
|
22
|
+
} from '@enzymefinance/protocol';
|
23
|
+
import { BigNumber, BigNumberish } from 'ethers';
|
24
|
+
|
25
|
+
export async function idleApproveAssets({
|
26
|
+
comptrollerProxy,
|
27
|
+
integrationManager,
|
28
|
+
fundOwner,
|
29
|
+
idleAdapter,
|
30
|
+
idleToken,
|
31
|
+
assets,
|
32
|
+
amounts,
|
33
|
+
}: {
|
34
|
+
comptrollerProxy: ComptrollerLib;
|
35
|
+
integrationManager: IntegrationManager;
|
36
|
+
fundOwner: SignerWithAddress;
|
37
|
+
idleAdapter: IdleAdapter;
|
38
|
+
idleToken: StandardToken;
|
39
|
+
assets: AddressLike[];
|
40
|
+
amounts: BigNumberish[];
|
41
|
+
}) {
|
42
|
+
const callArgs = callOnIntegrationArgs({
|
43
|
+
adapter: idleAdapter,
|
44
|
+
selector: approveAssetsSelector,
|
45
|
+
encodedCallArgs: idleApproveAssetsArgs({
|
46
|
+
idleToken,
|
47
|
+
assets,
|
48
|
+
amounts,
|
49
|
+
}),
|
50
|
+
});
|
51
|
+
|
52
|
+
return comptrollerProxy
|
53
|
+
.connect(fundOwner)
|
54
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
55
|
+
}
|
56
|
+
|
57
|
+
export async function idleClaimRewards({
|
58
|
+
comptrollerProxy,
|
59
|
+
integrationManager,
|
60
|
+
fundOwner,
|
61
|
+
idleAdapter,
|
62
|
+
idleToken,
|
63
|
+
}: {
|
64
|
+
comptrollerProxy: ComptrollerLib;
|
65
|
+
integrationManager: IntegrationManager;
|
66
|
+
fundOwner: SignerWithAddress;
|
67
|
+
idleAdapter: IdleAdapter;
|
68
|
+
idleToken: StandardToken;
|
69
|
+
}) {
|
70
|
+
const callArgs = callOnIntegrationArgs({
|
71
|
+
adapter: idleAdapter,
|
72
|
+
selector: claimRewardsSelector,
|
73
|
+
encodedCallArgs: idleClaimRewardsArgs({
|
74
|
+
vaultProxy: await comptrollerProxy.getVaultProxy(),
|
75
|
+
idleToken,
|
76
|
+
}),
|
77
|
+
});
|
78
|
+
|
79
|
+
return comptrollerProxy
|
80
|
+
.connect(fundOwner)
|
81
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
82
|
+
}
|
83
|
+
|
84
|
+
export async function idleClaimRewardsAndReinvest({
|
85
|
+
comptrollerProxy,
|
86
|
+
integrationManager,
|
87
|
+
fundOwner,
|
88
|
+
idleAdapter,
|
89
|
+
idleToken,
|
90
|
+
minIncomingIdleTokenAmount = BigNumber.from(1),
|
91
|
+
useFullBalances,
|
92
|
+
}: {
|
93
|
+
comptrollerProxy: ComptrollerLib;
|
94
|
+
integrationManager: IntegrationManager;
|
95
|
+
fundOwner: SignerWithAddress;
|
96
|
+
idleAdapter: IdleAdapter;
|
97
|
+
idleToken: StandardToken;
|
98
|
+
minIncomingIdleTokenAmount?: BigNumberish;
|
99
|
+
useFullBalances: boolean;
|
100
|
+
}) {
|
101
|
+
const callArgs = callOnIntegrationArgs({
|
102
|
+
adapter: idleAdapter,
|
103
|
+
selector: claimRewardsAndReinvestSelector,
|
104
|
+
encodedCallArgs: idleClaimRewardsAndReinvestArgs({
|
105
|
+
vaultProxy: await comptrollerProxy.getVaultProxy(),
|
106
|
+
idleToken,
|
107
|
+
minIncomingIdleTokenAmount,
|
108
|
+
useFullBalances,
|
109
|
+
}),
|
110
|
+
});
|
111
|
+
|
112
|
+
return comptrollerProxy
|
113
|
+
.connect(fundOwner)
|
114
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
115
|
+
}
|
116
|
+
|
117
|
+
export async function idleClaimRewardsAndSwap({
|
118
|
+
comptrollerProxy,
|
119
|
+
integrationManager,
|
120
|
+
fundOwner,
|
121
|
+
idleAdapter,
|
122
|
+
idleToken,
|
123
|
+
incomingAsset,
|
124
|
+
minIncomingAssetAmount = BigNumber.from(1),
|
125
|
+
useFullBalances,
|
126
|
+
}: {
|
127
|
+
comptrollerProxy: ComptrollerLib;
|
128
|
+
integrationManager: IntegrationManager;
|
129
|
+
fundOwner: SignerWithAddress;
|
130
|
+
idleAdapter: IdleAdapter;
|
131
|
+
idleToken: StandardToken;
|
132
|
+
incomingAsset: AddressLike;
|
133
|
+
minIncomingAssetAmount?: BigNumberish;
|
134
|
+
useFullBalances: boolean;
|
135
|
+
}) {
|
136
|
+
const callArgs = callOnIntegrationArgs({
|
137
|
+
adapter: idleAdapter,
|
138
|
+
selector: claimRewardsAndSwapSelector,
|
139
|
+
encodedCallArgs: idleClaimRewardsAndSwapArgs({
|
140
|
+
vaultProxy: await comptrollerProxy.getVaultProxy(),
|
141
|
+
idleToken,
|
142
|
+
incomingAsset,
|
143
|
+
minIncomingAssetAmount,
|
144
|
+
useFullBalances,
|
145
|
+
}),
|
146
|
+
});
|
147
|
+
|
148
|
+
return comptrollerProxy
|
149
|
+
.connect(fundOwner)
|
150
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
151
|
+
}
|
152
|
+
|
153
|
+
export async function idleLend({
|
154
|
+
comptrollerProxy,
|
155
|
+
integrationManager,
|
156
|
+
fundOwner,
|
157
|
+
idleAdapter,
|
158
|
+
idleToken,
|
159
|
+
outgoingUnderlyingAmount,
|
160
|
+
minIncomingIdleTokenAmount = BigNumber.from(1),
|
161
|
+
}: {
|
162
|
+
comptrollerProxy: ComptrollerLib;
|
163
|
+
integrationManager: IntegrationManager;
|
164
|
+
fundOwner: SignerWithAddress;
|
165
|
+
idleAdapter: IdleAdapter;
|
166
|
+
idleToken: StandardToken;
|
167
|
+
outgoingUnderlyingAmount: BigNumberish;
|
168
|
+
minIncomingIdleTokenAmount?: BigNumberish;
|
169
|
+
}) {
|
170
|
+
const callArgs = callOnIntegrationArgs({
|
171
|
+
adapter: idleAdapter,
|
172
|
+
selector: lendSelector,
|
173
|
+
encodedCallArgs: idleLendArgs({
|
174
|
+
idleToken,
|
175
|
+
outgoingUnderlyingAmount,
|
176
|
+
minIncomingIdleTokenAmount,
|
177
|
+
}),
|
178
|
+
});
|
179
|
+
|
180
|
+
return comptrollerProxy
|
181
|
+
.connect(fundOwner)
|
182
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
183
|
+
}
|
184
|
+
|
185
|
+
export async function idleRedeem({
|
186
|
+
comptrollerProxy,
|
187
|
+
integrationManager,
|
188
|
+
fundOwner,
|
189
|
+
idleAdapter,
|
190
|
+
idleToken,
|
191
|
+
outgoingIdleTokenAmount,
|
192
|
+
minIncomingUnderlyingAmount = BigNumber.from(1),
|
193
|
+
}: {
|
194
|
+
comptrollerProxy: ComptrollerLib;
|
195
|
+
integrationManager: IntegrationManager;
|
196
|
+
fundOwner: SignerWithAddress;
|
197
|
+
idleAdapter: IdleAdapter;
|
198
|
+
idleToken: StandardToken;
|
199
|
+
outgoingIdleTokenAmount: BigNumberish;
|
200
|
+
minIncomingUnderlyingAmount?: BigNumberish;
|
201
|
+
}) {
|
202
|
+
const callArgs = callOnIntegrationArgs({
|
203
|
+
adapter: idleAdapter,
|
204
|
+
selector: redeemSelector,
|
205
|
+
encodedCallArgs: idleRedeemArgs({
|
206
|
+
idleToken,
|
207
|
+
outgoingIdleTokenAmount,
|
208
|
+
minIncomingUnderlyingAmount,
|
209
|
+
}),
|
210
|
+
});
|
211
|
+
|
212
|
+
return comptrollerProxy
|
213
|
+
.connect(fundOwner)
|
214
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
215
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export * from './aave';
|
2
|
+
export * from './alpha';
|
3
|
+
export * from './compound';
|
4
|
+
export * from './curve';
|
5
|
+
export * from './idle';
|
6
|
+
export * from './kyber';
|
7
|
+
export * from './mock';
|
8
|
+
export * from './paraSwapV4';
|
9
|
+
export * from './synthetix';
|
10
|
+
export * from './trackedAssets';
|
11
|
+
export * from './uniswapV2';
|
12
|
+
export * from './uniswapV3';
|
13
|
+
export * from './yearn';
|
14
|
+
export * from './zeroExV2';
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { AddressLike, Call, Contract, contract } from '@enzymefinance/ethers';
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
3
|
+
import {
|
4
|
+
StandardToken,
|
5
|
+
ComptrollerLib,
|
6
|
+
IntegrationManager,
|
7
|
+
KyberAdapter,
|
8
|
+
VaultLib,
|
9
|
+
callOnIntegrationArgs,
|
10
|
+
takeOrderSelector,
|
11
|
+
kyberTakeOrderArgs,
|
12
|
+
IntegrationManagerActionId,
|
13
|
+
} from '@enzymefinance/protocol';
|
14
|
+
import { BigNumber, BigNumberish, utils } from 'ethers';
|
15
|
+
|
16
|
+
// prettier-ignore
|
17
|
+
export interface KyberNetworkProxy extends Contract<KyberNetworkProxy> {
|
18
|
+
getExpectedRate: Call<(src: AddressLike, dest: AddressLike, srcQty: BigNumberish) => { expectedRate: BigNumber, worstRate: BigNumber }, KyberNetworkProxy>
|
19
|
+
}
|
20
|
+
|
21
|
+
export const KyberNetworkProxy = contract<KyberNetworkProxy>()`
|
22
|
+
function getExpectedRate(address src, address dest, uint256 srcQty) view returns (uint256 expectedRate, uint256 worstRate)
|
23
|
+
`;
|
24
|
+
|
25
|
+
export async function kyberTakeOrder({
|
26
|
+
comptrollerProxy,
|
27
|
+
vaultProxy,
|
28
|
+
integrationManager,
|
29
|
+
fundOwner,
|
30
|
+
kyberAdapter,
|
31
|
+
outgoingAsset,
|
32
|
+
outgoingAssetAmount = utils.parseEther('1'),
|
33
|
+
incomingAsset,
|
34
|
+
minIncomingAssetAmount = utils.parseEther('1'),
|
35
|
+
seedFund = false,
|
36
|
+
}: {
|
37
|
+
comptrollerProxy: ComptrollerLib;
|
38
|
+
vaultProxy: VaultLib;
|
39
|
+
integrationManager: IntegrationManager;
|
40
|
+
fundOwner: SignerWithAddress;
|
41
|
+
kyberAdapter: KyberAdapter;
|
42
|
+
outgoingAsset: StandardToken;
|
43
|
+
outgoingAssetAmount?: BigNumberish;
|
44
|
+
incomingAsset: StandardToken;
|
45
|
+
minIncomingAssetAmount?: BigNumberish;
|
46
|
+
seedFund?: boolean;
|
47
|
+
}) {
|
48
|
+
if (seedFund) {
|
49
|
+
// Seed the VaultProxy with enough outgoingAsset for the tx
|
50
|
+
await outgoingAsset.transfer(vaultProxy, outgoingAssetAmount);
|
51
|
+
}
|
52
|
+
|
53
|
+
const takeOrderArgs = kyberTakeOrderArgs({
|
54
|
+
incomingAsset: incomingAsset,
|
55
|
+
minIncomingAssetAmount: minIncomingAssetAmount,
|
56
|
+
outgoingAsset: outgoingAsset,
|
57
|
+
outgoingAssetAmount: outgoingAssetAmount,
|
58
|
+
});
|
59
|
+
|
60
|
+
const callArgs = callOnIntegrationArgs({
|
61
|
+
adapter: kyberAdapter,
|
62
|
+
selector: takeOrderSelector,
|
63
|
+
encodedCallArgs: takeOrderArgs,
|
64
|
+
});
|
65
|
+
|
66
|
+
return comptrollerProxy
|
67
|
+
.connect(fundOwner)
|
68
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
69
|
+
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import { AddressLike } from '@enzymefinance/ethers';
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
3
|
+
import {
|
4
|
+
ComptrollerLib,
|
5
|
+
IntegrationManager,
|
6
|
+
VaultLib,
|
7
|
+
MockGenericAdapter,
|
8
|
+
StandardToken,
|
9
|
+
sighash,
|
10
|
+
callOnIntegrationArgs,
|
11
|
+
encodeArgs,
|
12
|
+
IntegrationManagerActionId,
|
13
|
+
} from '@enzymefinance/protocol';
|
14
|
+
import { BigNumberish, BytesLike, utils } from 'ethers';
|
15
|
+
|
16
|
+
export const mockGenericRemoveOnlySelector = sighash(
|
17
|
+
utils.FunctionFragment.fromString('removeOnly(address,bytes,bytes)'),
|
18
|
+
);
|
19
|
+
|
20
|
+
export const mockGenericSwapASelector = sighash(utils.FunctionFragment.fromString('swapA(address,bytes,bytes)'));
|
21
|
+
|
22
|
+
export const mockGenericSwapBSelector = sighash(utils.FunctionFragment.fromString('swapB(address,bytes,bytes)'));
|
23
|
+
|
24
|
+
export const mockGenericSwapDirectFromVaultSelector = sighash(
|
25
|
+
utils.FunctionFragment.fromString('swapDirectFromVault(address,bytes,bytes)'),
|
26
|
+
);
|
27
|
+
|
28
|
+
export const mockGenericSwapViaApprovalSelector = sighash(
|
29
|
+
utils.FunctionFragment.fromString('swapViaApproval(address,bytes,bytes)'),
|
30
|
+
);
|
31
|
+
|
32
|
+
export function mockGenericSwapArgs({
|
33
|
+
spendAssets = [],
|
34
|
+
actualSpendAssetAmounts = [],
|
35
|
+
maxSpendAssetAmounts = actualSpendAssetAmounts,
|
36
|
+
incomingAssets = [],
|
37
|
+
actualIncomingAssetAmounts = [],
|
38
|
+
minIncomingAssetAmounts = actualIncomingAssetAmounts,
|
39
|
+
}: {
|
40
|
+
spendAssets?: AddressLike[];
|
41
|
+
maxSpendAssetAmounts?: BigNumberish[];
|
42
|
+
actualSpendAssetAmounts?: BigNumberish[];
|
43
|
+
incomingAssets?: AddressLike[];
|
44
|
+
minIncomingAssetAmounts?: BigNumberish[];
|
45
|
+
actualIncomingAssetAmounts?: BigNumberish[];
|
46
|
+
}) {
|
47
|
+
return encodeArgs(
|
48
|
+
['address[]', 'uint256[]', 'uint256[]', 'address[]', 'uint256[]', 'uint256[]'],
|
49
|
+
[
|
50
|
+
spendAssets,
|
51
|
+
maxSpendAssetAmounts,
|
52
|
+
actualSpendAssetAmounts,
|
53
|
+
incomingAssets,
|
54
|
+
minIncomingAssetAmounts,
|
55
|
+
actualIncomingAssetAmounts,
|
56
|
+
],
|
57
|
+
);
|
58
|
+
}
|
59
|
+
|
60
|
+
export async function mockGenericSwap({
|
61
|
+
comptrollerProxy,
|
62
|
+
vaultProxy,
|
63
|
+
integrationManager,
|
64
|
+
fundOwner,
|
65
|
+
mockGenericAdapter,
|
66
|
+
selector = mockGenericSwapASelector,
|
67
|
+
spendAssets = [],
|
68
|
+
actualSpendAssetAmounts = [],
|
69
|
+
maxSpendAssetAmounts = actualSpendAssetAmounts,
|
70
|
+
incomingAssets = [],
|
71
|
+
actualIncomingAssetAmounts = [],
|
72
|
+
minIncomingAssetAmounts = actualIncomingAssetAmounts,
|
73
|
+
seedFund = false,
|
74
|
+
}: {
|
75
|
+
comptrollerProxy: ComptrollerLib;
|
76
|
+
vaultProxy: VaultLib;
|
77
|
+
integrationManager: IntegrationManager;
|
78
|
+
fundOwner: SignerWithAddress;
|
79
|
+
mockGenericAdapter: MockGenericAdapter;
|
80
|
+
selector?: BytesLike;
|
81
|
+
spendAssets?: StandardToken[];
|
82
|
+
maxSpendAssetAmounts?: BigNumberish[];
|
83
|
+
actualSpendAssetAmounts?: BigNumberish[];
|
84
|
+
incomingAssets?: StandardToken[];
|
85
|
+
minIncomingAssetAmounts?: BigNumberish[];
|
86
|
+
actualIncomingAssetAmounts?: BigNumberish[];
|
87
|
+
seedFund?: boolean;
|
88
|
+
}) {
|
89
|
+
// Seed the VaultProxy with enough spendAssets for the tx
|
90
|
+
if (seedFund) {
|
91
|
+
for (const key in spendAssets) {
|
92
|
+
await spendAssets[key].transfer(vaultProxy, maxSpendAssetAmounts[key]);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
const swapArgs = mockGenericSwapArgs({
|
97
|
+
spendAssets,
|
98
|
+
maxSpendAssetAmounts,
|
99
|
+
actualSpendAssetAmounts,
|
100
|
+
incomingAssets,
|
101
|
+
minIncomingAssetAmounts,
|
102
|
+
actualIncomingAssetAmounts,
|
103
|
+
});
|
104
|
+
|
105
|
+
const callArgs = callOnIntegrationArgs({
|
106
|
+
adapter: mockGenericAdapter,
|
107
|
+
selector,
|
108
|
+
encodedCallArgs: swapArgs,
|
109
|
+
});
|
110
|
+
|
111
|
+
const swapTx = comptrollerProxy
|
112
|
+
.connect(fundOwner)
|
113
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
114
|
+
|
115
|
+
await expect(swapTx).resolves.toBeReceipt();
|
116
|
+
|
117
|
+
return swapTx;
|
118
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { AddressLike } from '@enzymefinance/ethers';
|
2
|
+
import { SignerWithAddress } from '@enzymefinance/hardhat';
|
3
|
+
import {
|
4
|
+
callOnIntegrationArgs,
|
5
|
+
ComptrollerLib,
|
6
|
+
IntegrationManager,
|
7
|
+
IntegrationManagerActionId,
|
8
|
+
ParaSwapV4Adapter,
|
9
|
+
ParaSwapV4Path,
|
10
|
+
paraSwapV4TakeOrderArgs,
|
11
|
+
StandardToken,
|
12
|
+
takeOrderSelector,
|
13
|
+
} from '@enzymefinance/protocol';
|
14
|
+
import { BigNumberish, utils } from 'ethers';
|
15
|
+
|
16
|
+
// ParaSwapV4Path
|
17
|
+
export function paraSwapV4GenerateDummyPaths({ toTokens }: { toTokens: AddressLike[] }) {
|
18
|
+
return toTokens.map((toToken) => {
|
19
|
+
return {
|
20
|
+
to: toToken,
|
21
|
+
totalNetworkFee: 0, // Not supported in our protocol
|
22
|
+
routes: [], // Can ignore this param in the dummy
|
23
|
+
};
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
export async function paraSwapV4TakeOrder({
|
28
|
+
comptrollerProxy,
|
29
|
+
integrationManager,
|
30
|
+
fundOwner,
|
31
|
+
paraSwapV4Adapter,
|
32
|
+
outgoingAsset,
|
33
|
+
outgoingAssetAmount = utils.parseEther('1'),
|
34
|
+
minIncomingAssetAmount = 1,
|
35
|
+
expectedIncomingAssetAmount = minIncomingAssetAmount,
|
36
|
+
paths,
|
37
|
+
}: {
|
38
|
+
comptrollerProxy: ComptrollerLib;
|
39
|
+
integrationManager: IntegrationManager;
|
40
|
+
fundOwner: SignerWithAddress;
|
41
|
+
paraSwapV4Adapter: ParaSwapV4Adapter;
|
42
|
+
outgoingAsset: StandardToken;
|
43
|
+
outgoingAssetAmount?: BigNumberish;
|
44
|
+
minIncomingAssetAmount?: BigNumberish;
|
45
|
+
expectedIncomingAssetAmount?: BigNumberish;
|
46
|
+
paths: ParaSwapV4Path[];
|
47
|
+
}) {
|
48
|
+
const takeOrderArgs = paraSwapV4TakeOrderArgs({
|
49
|
+
minIncomingAssetAmount,
|
50
|
+
expectedIncomingAssetAmount,
|
51
|
+
outgoingAsset,
|
52
|
+
outgoingAssetAmount,
|
53
|
+
paths,
|
54
|
+
});
|
55
|
+
|
56
|
+
const callArgs = callOnIntegrationArgs({
|
57
|
+
adapter: paraSwapV4Adapter,
|
58
|
+
selector: takeOrderSelector,
|
59
|
+
encodedCallArgs: takeOrderArgs,
|
60
|
+
});
|
61
|
+
|
62
|
+
return comptrollerProxy
|
63
|
+
.connect(fundOwner)
|
64
|
+
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
65
|
+
}
|