@enzymefinance/testutils 4.0.0 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1566 -0
- package/dist/index.js +3375 -0
- package/dist/index.mjs +3375 -0
- package/package.json +74 -11
- package/CHANGELOG.md +0 -84
- package/dist/declarations/src/assertions.d.ts +0 -4
- package/dist/declarations/src/deployment.d.ts +0 -188
- package/dist/declarations/src/gasRelayer.d.ts +0 -56
- package/dist/declarations/src/helpers.d.ts +0 -16
- package/dist/declarations/src/index.d.ts +0 -6
- package/dist/declarations/src/scaffolding/assets.d.ts +0 -10
- package/dist/declarations/src/scaffolding/chainlink.d.ts +0 -3
- package/dist/declarations/src/scaffolding/common.d.ts +0 -7
- package/dist/declarations/src/scaffolding/core.d.ts +0 -16
- package/dist/declarations/src/scaffolding/extensions/common.d.ts +0 -11
- package/dist/declarations/src/scaffolding/extensions/external-positions/aave-debt.d.ts +0 -51
- package/dist/declarations/src/scaffolding/extensions/external-positions/actions.d.ts +0 -36
- package/dist/declarations/src/scaffolding/extensions/external-positions/compound.d.ts +0 -56
- package/dist/declarations/src/scaffolding/extensions/external-positions/index.d.ts +0 -5
- package/dist/declarations/src/scaffolding/extensions/external-positions/mocks.d.ts +0 -56
- package/dist/declarations/src/scaffolding/extensions/external-positions/uniswap-v3-liquidity.d.ts +0 -100
- package/dist/declarations/src/scaffolding/extensions/fees.d.ts +0 -12
- package/dist/declarations/src/scaffolding/extensions/index.d.ts +0 -5
- package/dist/declarations/src/scaffolding/extensions/integrations/aave.d.ts +0 -20
- package/dist/declarations/src/scaffolding/extensions/integrations/compound.d.ts +0 -56
- package/dist/declarations/src/scaffolding/extensions/integrations/curve.d.ts +0 -106
- package/dist/declarations/src/scaffolding/extensions/integrations/idle.d.ts +0 -28
- package/dist/declarations/src/scaffolding/extensions/integrations/index.d.ts +0 -14
- package/dist/declarations/src/scaffolding/extensions/integrations/mock.d.ts +0 -32
- package/dist/declarations/src/scaffolding/extensions/integrations/olympusV2.d.ts +0 -17
- package/dist/declarations/src/scaffolding/extensions/integrations/paraSwapV5.d.ts +0 -23
- package/dist/declarations/src/scaffolding/extensions/integrations/poolTogetherV4.d.ts +0 -29
- package/dist/declarations/src/scaffolding/extensions/integrations/synthetix.d.ts +0 -28
- package/dist/declarations/src/scaffolding/extensions/integrations/trackedAssets.d.ts +0 -15
- package/dist/declarations/src/scaffolding/extensions/integrations/uniswapV2.d.ts +0 -46
- package/dist/declarations/src/scaffolding/extensions/integrations/uniswapV3.d.ts +0 -15
- package/dist/declarations/src/scaffolding/extensions/integrations/yearn.d.ts +0 -22
- package/dist/declarations/src/scaffolding/extensions/integrations/zeroExV2.d.ts +0 -12
- package/dist/declarations/src/scaffolding/extensions/policies.d.ts +0 -17
- package/dist/declarations/src/scaffolding/index.d.ts +0 -8
- package/dist/declarations/src/scaffolding/setup.d.ts +0 -77
- package/dist/declarations/src/scaffolding/shares.d.ts +0 -35
- package/dist/declarations/src/scaffolding/vaultCalls.d.ts +0 -32
- package/dist/declarations/src/whales.d.ts +0 -49
- package/dist/enzymefinance-testutils.browser.cjs.js +0 -4158
- package/dist/enzymefinance-testutils.browser.esm.js +0 -4028
- package/dist/enzymefinance-testutils.cjs.d.ts +0 -1
- package/dist/enzymefinance-testutils.cjs.dev.js +0 -4158
- package/dist/enzymefinance-testutils.cjs.js +0 -7
- package/dist/enzymefinance-testutils.cjs.prod.js +0 -4158
- package/dist/enzymefinance-testutils.esm.js +0 -4028
- package/src/assertions.ts +0 -23
- package/src/deployment.ts +0 -280
- package/src/gasRelayer.ts +0 -95
- package/src/helpers.ts +0 -39
- package/src/index.ts +0 -6
- package/src/scaffolding/assets.ts +0 -37
- package/src/scaffolding/chainlink.ts +0 -8
- package/src/scaffolding/common.ts +0 -11
- package/src/scaffolding/core.ts +0 -103
- package/src/scaffolding/extensions/common.ts +0 -30
- package/src/scaffolding/extensions/external-positions/aave-debt.ts +0 -179
- package/src/scaffolding/extensions/external-positions/actions.ts +0 -108
- package/src/scaffolding/extensions/external-positions/compound.ts +0 -190
- package/src/scaffolding/extensions/external-positions/index.ts +0 -5
- package/src/scaffolding/extensions/external-positions/mocks.ts +0 -191
- package/src/scaffolding/extensions/external-positions/uniswap-v3-liquidity.ts +0 -284
- package/src/scaffolding/extensions/fees.ts +0 -70
- package/src/scaffolding/extensions/index.ts +0 -5
- package/src/scaffolding/extensions/integrations/aave.ts +0 -78
- package/src/scaffolding/extensions/integrations/compound.ts +0 -255
- package/src/scaffolding/extensions/integrations/curve.ts +0 -354
- package/src/scaffolding/extensions/integrations/idle.ts +0 -104
- package/src/scaffolding/extensions/integrations/index.ts +0 -14
- package/src/scaffolding/extensions/integrations/mock.ts +0 -116
- package/src/scaffolding/extensions/integrations/olympusV2.ts +0 -71
- package/src/scaffolding/extensions/integrations/paraSwapV5.ts +0 -73
- package/src/scaffolding/extensions/integrations/poolTogetherV4.ts +0 -117
- package/src/scaffolding/extensions/integrations/synthetix.ts +0 -111
- package/src/scaffolding/extensions/integrations/trackedAssets.ts +0 -48
- package/src/scaffolding/extensions/integrations/uniswapV2.ts +0 -175
- package/src/scaffolding/extensions/integrations/uniswapV3.ts +0 -55
- package/src/scaffolding/extensions/integrations/yearn.ts +0 -79
- package/src/scaffolding/extensions/integrations/zeroExV2.ts +0 -47
- package/src/scaffolding/extensions/policies.ts +0 -112
- package/src/scaffolding/index.ts +0 -8
- package/src/scaffolding/setup.ts +0 -243
- package/src/scaffolding/shares.ts +0 -80
- package/src/scaffolding/vaultCalls.ts +0 -105
- package/src/types.d.ts +0 -2
- package/src/whales.ts +0 -82
- package/tsconfig.json +0 -5
@@ -1,284 +0,0 @@
|
|
1
|
-
import type { AddressLike, Call, Contract } from '@enzymefinance/ethers';
|
2
|
-
import { contract, extractEvent, resolveAddress } from '@enzymefinance/ethers';
|
3
|
-
import type { SignerWithAddress } from '@enzymefinance/hardhat';
|
4
|
-
import type { ComptrollerLib, ExternalPositionManager } from '@enzymefinance/protocol';
|
5
|
-
import {
|
6
|
-
callOnExternalPositionArgs,
|
7
|
-
ExternalPositionManagerActionId,
|
8
|
-
ExternalPositionType,
|
9
|
-
UniswapV3LiquidityPositionActionId,
|
10
|
-
uniswapV3LiquidityPositionAddLiquidityArgs,
|
11
|
-
uniswapV3LiquidityPositionCollectArgs,
|
12
|
-
UniswapV3LiquidityPositionLib,
|
13
|
-
uniswapV3LiquidityPositionMintArgs,
|
14
|
-
uniswapV3LiquidityPositionPurgeArgs,
|
15
|
-
uniswapV3LiquidityPositionRemoveLiquidityArgs,
|
16
|
-
} from '@enzymefinance/protocol';
|
17
|
-
import type { BigNumber, BigNumberish, BytesLike } from 'ethers';
|
18
|
-
|
19
|
-
import { createExternalPosition } from './actions';
|
20
|
-
|
21
|
-
export enum UniswapV3FeeAmount {
|
22
|
-
LOW = 500,
|
23
|
-
MEDIUM = 3000,
|
24
|
-
HIGH = 10000,
|
25
|
-
}
|
26
|
-
|
27
|
-
export const uniswapV3LiquidityPositionGetMinTick = (tickSpacing: number) =>
|
28
|
-
Math.ceil(-887272 / tickSpacing) * tickSpacing;
|
29
|
-
export const uniswapV3LiquidityPositionGetMaxTick = (tickSpacing: number) =>
|
30
|
-
Math.floor(887272 / tickSpacing) * tickSpacing;
|
31
|
-
|
32
|
-
export interface IUniswapV3NonFungibleTokenManager extends Contract<IUniswapV3NonFungibleTokenManager> {
|
33
|
-
positions: Call<
|
34
|
-
(tokenId: BigNumberish) => {
|
35
|
-
nonce: BigNumber;
|
36
|
-
operator: string;
|
37
|
-
token0: string;
|
38
|
-
token1: string;
|
39
|
-
fee: BigNumber;
|
40
|
-
tickLower: BigNumber;
|
41
|
-
tickUpper: BigNumber;
|
42
|
-
liquidity: BigNumber;
|
43
|
-
feeGrowthInside0LastX128: BigNumber;
|
44
|
-
feeGrowthInside1LastX128: BigNumber;
|
45
|
-
tokensOwed0: BigNumber;
|
46
|
-
tokensOwed1: BigNumber;
|
47
|
-
},
|
48
|
-
Contract<any>
|
49
|
-
>;
|
50
|
-
}
|
51
|
-
|
52
|
-
export const IUniswapV3NonFungibleTokenManager = contract<IUniswapV3NonFungibleTokenManager>()`
|
53
|
-
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)
|
54
|
-
`;
|
55
|
-
|
56
|
-
export async function createUniswapV3LiquidityPosition({
|
57
|
-
signer,
|
58
|
-
comptrollerProxy,
|
59
|
-
externalPositionManager,
|
60
|
-
callOnExternalPositionData = '0x',
|
61
|
-
}: {
|
62
|
-
signer: SignerWithAddress;
|
63
|
-
comptrollerProxy: ComptrollerLib;
|
64
|
-
externalPositionManager: ExternalPositionManager;
|
65
|
-
callOnExternalPositionData?: BytesLike;
|
66
|
-
}) {
|
67
|
-
const { externalPositionProxy: externalPositionProxyContract, receipt } = await createExternalPosition({
|
68
|
-
callOnExternalPositionData,
|
69
|
-
comptrollerProxy,
|
70
|
-
externalPositionManager,
|
71
|
-
externalPositionTypeId: ExternalPositionType.UniswapV3LiquidityPosition,
|
72
|
-
signer,
|
73
|
-
});
|
74
|
-
|
75
|
-
return { externalPositionProxyAddress: externalPositionProxyContract.address, receipt };
|
76
|
-
}
|
77
|
-
|
78
|
-
export async function uniswapV3LiquidityPositionAddLiquidity({
|
79
|
-
signer,
|
80
|
-
comptrollerProxy,
|
81
|
-
externalPositionManager,
|
82
|
-
externalPositionProxy,
|
83
|
-
nftId,
|
84
|
-
amount0Desired,
|
85
|
-
amount1Desired,
|
86
|
-
amount0Min = 0,
|
87
|
-
amount1Min = 0,
|
88
|
-
}: {
|
89
|
-
signer: SignerWithAddress;
|
90
|
-
comptrollerProxy: ComptrollerLib;
|
91
|
-
externalPositionManager: ExternalPositionManager;
|
92
|
-
externalPositionProxy: AddressLike;
|
93
|
-
nftId: BigNumberish;
|
94
|
-
amount0Desired: BigNumberish;
|
95
|
-
amount1Desired: BigNumberish;
|
96
|
-
amount0Min?: BigNumberish;
|
97
|
-
amount1Min?: BigNumberish;
|
98
|
-
}) {
|
99
|
-
const actionArgs = uniswapV3LiquidityPositionAddLiquidityArgs({
|
100
|
-
amount0Desired,
|
101
|
-
amount0Min,
|
102
|
-
amount1Desired,
|
103
|
-
amount1Min,
|
104
|
-
nftId,
|
105
|
-
});
|
106
|
-
|
107
|
-
const callArgs = callOnExternalPositionArgs({
|
108
|
-
actionArgs,
|
109
|
-
actionId: UniswapV3LiquidityPositionActionId.AddLiquidity,
|
110
|
-
externalPositionProxy,
|
111
|
-
});
|
112
|
-
|
113
|
-
return comptrollerProxy
|
114
|
-
.connect(signer)
|
115
|
-
.callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CallOnExternalPosition, callArgs);
|
116
|
-
}
|
117
|
-
|
118
|
-
export async function uniswapV3LiquidityPositionCollect({
|
119
|
-
signer,
|
120
|
-
comptrollerProxy,
|
121
|
-
externalPositionManager,
|
122
|
-
externalPositionProxy,
|
123
|
-
nftId,
|
124
|
-
}: {
|
125
|
-
signer: SignerWithAddress;
|
126
|
-
comptrollerProxy: ComptrollerLib;
|
127
|
-
externalPositionManager: ExternalPositionManager;
|
128
|
-
externalPositionProxy: AddressLike;
|
129
|
-
nftId: BigNumberish;
|
130
|
-
}) {
|
131
|
-
const actionArgs = uniswapV3LiquidityPositionCollectArgs({
|
132
|
-
nftId,
|
133
|
-
});
|
134
|
-
|
135
|
-
const callArgs = callOnExternalPositionArgs({
|
136
|
-
actionArgs,
|
137
|
-
actionId: UniswapV3LiquidityPositionActionId.Collect,
|
138
|
-
externalPositionProxy,
|
139
|
-
});
|
140
|
-
|
141
|
-
return comptrollerProxy
|
142
|
-
.connect(signer)
|
143
|
-
.callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CallOnExternalPosition, callArgs);
|
144
|
-
}
|
145
|
-
|
146
|
-
export async function uniswapV3LiquidityPositionMint({
|
147
|
-
signer,
|
148
|
-
comptrollerProxy,
|
149
|
-
externalPositionManager,
|
150
|
-
externalPositionProxy,
|
151
|
-
token0,
|
152
|
-
token1,
|
153
|
-
fee,
|
154
|
-
tickLower,
|
155
|
-
tickUpper,
|
156
|
-
amount0Desired,
|
157
|
-
amount1Desired,
|
158
|
-
amount0Min = 0,
|
159
|
-
amount1Min = 0,
|
160
|
-
}: {
|
161
|
-
signer: SignerWithAddress;
|
162
|
-
comptrollerProxy: ComptrollerLib;
|
163
|
-
externalPositionManager: ExternalPositionManager;
|
164
|
-
externalPositionProxy: AddressLike;
|
165
|
-
token0: AddressLike;
|
166
|
-
token1: AddressLike;
|
167
|
-
fee: BigNumberish;
|
168
|
-
tickLower: BigNumberish;
|
169
|
-
tickUpper: BigNumberish;
|
170
|
-
amount0Desired: BigNumberish;
|
171
|
-
amount1Desired: BigNumberish;
|
172
|
-
amount0Min?: BigNumberish;
|
173
|
-
amount1Min?: BigNumberish;
|
174
|
-
}) {
|
175
|
-
const actionArgs = uniswapV3LiquidityPositionMintArgs({
|
176
|
-
amount0Desired,
|
177
|
-
amount0Min,
|
178
|
-
amount1Desired,
|
179
|
-
amount1Min,
|
180
|
-
fee,
|
181
|
-
tickLower,
|
182
|
-
tickUpper,
|
183
|
-
token0,
|
184
|
-
token1,
|
185
|
-
});
|
186
|
-
|
187
|
-
const callArgs = callOnExternalPositionArgs({
|
188
|
-
actionArgs,
|
189
|
-
actionId: UniswapV3LiquidityPositionActionId.Mint,
|
190
|
-
externalPositionProxy,
|
191
|
-
});
|
192
|
-
|
193
|
-
const receipt = await comptrollerProxy
|
194
|
-
.connect(signer)
|
195
|
-
.callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CallOnExternalPosition, callArgs);
|
196
|
-
|
197
|
-
const externalPosition = new UniswapV3LiquidityPositionLib(externalPositionProxy, provider);
|
198
|
-
const nftId = extractEvent(receipt, externalPosition.abi.getEvent('NFTPositionAdded'))[0].args.tokenId;
|
199
|
-
|
200
|
-
return { nftId, receipt };
|
201
|
-
}
|
202
|
-
|
203
|
-
export async function uniswapV3LiquidityPositionPurge({
|
204
|
-
signer,
|
205
|
-
comptrollerProxy,
|
206
|
-
externalPositionManager,
|
207
|
-
externalPositionProxy,
|
208
|
-
nftId,
|
209
|
-
liquidity,
|
210
|
-
amount0Min = 0,
|
211
|
-
amount1Min = 0,
|
212
|
-
}: {
|
213
|
-
signer: SignerWithAddress;
|
214
|
-
comptrollerProxy: ComptrollerLib;
|
215
|
-
externalPositionManager: ExternalPositionManager;
|
216
|
-
externalPositionProxy: AddressLike;
|
217
|
-
nftId: BigNumberish;
|
218
|
-
liquidity: BigNumberish;
|
219
|
-
amount0Min?: BigNumberish;
|
220
|
-
amount1Min?: BigNumberish;
|
221
|
-
}) {
|
222
|
-
const actionArgs = uniswapV3LiquidityPositionPurgeArgs({
|
223
|
-
amount0Min,
|
224
|
-
amount1Min,
|
225
|
-
liquidity,
|
226
|
-
nftId,
|
227
|
-
});
|
228
|
-
|
229
|
-
const callArgs = callOnExternalPositionArgs({
|
230
|
-
actionArgs,
|
231
|
-
actionId: UniswapV3LiquidityPositionActionId.Purge,
|
232
|
-
externalPositionProxy,
|
233
|
-
});
|
234
|
-
|
235
|
-
return comptrollerProxy
|
236
|
-
.connect(signer)
|
237
|
-
.callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CallOnExternalPosition, callArgs);
|
238
|
-
}
|
239
|
-
|
240
|
-
export async function uniswapV3LiquidityPositionRemoveLiquidity({
|
241
|
-
signer,
|
242
|
-
comptrollerProxy,
|
243
|
-
externalPositionManager,
|
244
|
-
externalPositionProxy,
|
245
|
-
nftId,
|
246
|
-
liquidity,
|
247
|
-
amount0Min = 0,
|
248
|
-
amount1Min = 0,
|
249
|
-
}: {
|
250
|
-
signer: SignerWithAddress;
|
251
|
-
comptrollerProxy: ComptrollerLib;
|
252
|
-
externalPositionManager: ExternalPositionManager;
|
253
|
-
externalPositionProxy: AddressLike;
|
254
|
-
nftId: BigNumberish;
|
255
|
-
liquidity: BigNumberish;
|
256
|
-
amount0Min?: BigNumberish;
|
257
|
-
amount1Min?: BigNumberish;
|
258
|
-
}) {
|
259
|
-
const actionArgs = uniswapV3LiquidityPositionRemoveLiquidityArgs({
|
260
|
-
amount0Min,
|
261
|
-
amount1Min,
|
262
|
-
liquidity,
|
263
|
-
nftId,
|
264
|
-
});
|
265
|
-
|
266
|
-
const callArgs = callOnExternalPositionArgs({
|
267
|
-
actionArgs,
|
268
|
-
actionId: UniswapV3LiquidityPositionActionId.RemoveLiquidity,
|
269
|
-
externalPositionProxy,
|
270
|
-
});
|
271
|
-
|
272
|
-
return comptrollerProxy
|
273
|
-
.connect(signer)
|
274
|
-
.callOnExtension(externalPositionManager, ExternalPositionManagerActionId.CallOnExternalPosition, callArgs);
|
275
|
-
}
|
276
|
-
|
277
|
-
export function uniswapV3OrderTokenPair({ tokenA, tokenB }: { tokenA: AddressLike; tokenB: AddressLike }) {
|
278
|
-
const tokenAAddress = resolveAddress(tokenA);
|
279
|
-
const tokenBAddress = resolveAddress(tokenB);
|
280
|
-
|
281
|
-
return tokenAAddress < tokenBAddress
|
282
|
-
? { token0: tokenAAddress, token1: tokenBAddress }
|
283
|
-
: { token0: tokenBAddress, token1: tokenAAddress };
|
284
|
-
}
|
@@ -1,70 +0,0 @@
|
|
1
|
-
import type { SignerWithAddress } from '@enzymefinance/hardhat';
|
2
|
-
import { FeeHook, feeManagerConfigArgs, FeeSettlementType, IFee } from '@enzymefinance/protocol';
|
3
|
-
import { constants, utils } from 'ethers';
|
4
|
-
|
5
|
-
export async function generateFeeManagerConfigWithMockFees({ deployer }: { deployer: SignerWithAddress }) {
|
6
|
-
const fees = await generateMockFees({
|
7
|
-
deployer,
|
8
|
-
});
|
9
|
-
|
10
|
-
const feeManagerSettingsData = [utils.randomBytes(10), '0x', utils.randomBytes(2)];
|
11
|
-
|
12
|
-
return feeManagerConfigArgs({
|
13
|
-
fees: Object.values(fees),
|
14
|
-
settings: feeManagerSettingsData,
|
15
|
-
});
|
16
|
-
}
|
17
|
-
|
18
|
-
export async function generateMockFees({ deployer }: { deployer: SignerWithAddress }) {
|
19
|
-
// Create mock fees
|
20
|
-
const mockContinuousFeeSettleOnly = await IFee.mock(deployer);
|
21
|
-
const mockContinuousFeeWithGavAndUpdates = await IFee.mock(deployer);
|
22
|
-
const mockPostBuySharesFee = await IFee.mock(deployer);
|
23
|
-
|
24
|
-
// Initialize mock fee return values
|
25
|
-
await Promise.all([
|
26
|
-
// Continuous fee the mimics ManagementFee
|
27
|
-
mockContinuousFeeSettleOnly.getRecipientForFund.returns(constants.AddressZero),
|
28
|
-
mockContinuousFeeSettleOnly.settle.returns(FeeSettlementType.None, constants.AddressZero, 0),
|
29
|
-
mockContinuousFeeSettleOnly.payout.returns(false),
|
30
|
-
mockContinuousFeeSettleOnly.addFundSettings.returns(undefined),
|
31
|
-
mockContinuousFeeSettleOnly.activateForFund.returns(undefined),
|
32
|
-
mockContinuousFeeSettleOnly.update.returns(undefined),
|
33
|
-
mockContinuousFeeSettleOnly.settlesOnHook.returns(false, false),
|
34
|
-
mockContinuousFeeSettleOnly.settlesOnHook.given(FeeHook.Continuous).returns(true, false),
|
35
|
-
mockContinuousFeeSettleOnly.settlesOnHook.given(FeeHook.PreBuyShares).returns(true, false),
|
36
|
-
mockContinuousFeeSettleOnly.settlesOnHook.given(FeeHook.PreRedeemShares).returns(true, false),
|
37
|
-
mockContinuousFeeSettleOnly.updatesOnHook.returns(false, false),
|
38
|
-
// Continuous fee the mimics PerformanceFee
|
39
|
-
mockContinuousFeeWithGavAndUpdates.getRecipientForFund.returns(constants.AddressZero),
|
40
|
-
mockContinuousFeeWithGavAndUpdates.settle.returns(FeeSettlementType.None, constants.AddressZero, 0),
|
41
|
-
mockContinuousFeeWithGavAndUpdates.payout.returns(false),
|
42
|
-
mockContinuousFeeWithGavAndUpdates.addFundSettings.returns(undefined),
|
43
|
-
mockContinuousFeeWithGavAndUpdates.activateForFund.returns(undefined),
|
44
|
-
mockContinuousFeeWithGavAndUpdates.update.returns(undefined),
|
45
|
-
mockContinuousFeeWithGavAndUpdates.settlesOnHook.returns(false, false),
|
46
|
-
mockContinuousFeeWithGavAndUpdates.settlesOnHook.given(FeeHook.Continuous).returns(true, true),
|
47
|
-
mockContinuousFeeWithGavAndUpdates.settlesOnHook.given(FeeHook.PreBuyShares).returns(true, true),
|
48
|
-
mockContinuousFeeWithGavAndUpdates.settlesOnHook.given(FeeHook.PreRedeemShares).returns(true, true),
|
49
|
-
mockContinuousFeeWithGavAndUpdates.updatesOnHook.returns(false, false),
|
50
|
-
mockContinuousFeeWithGavAndUpdates.updatesOnHook.given(FeeHook.Continuous).returns(true, true),
|
51
|
-
mockContinuousFeeWithGavAndUpdates.updatesOnHook.given(FeeHook.PostBuyShares).returns(true, true),
|
52
|
-
mockContinuousFeeWithGavAndUpdates.updatesOnHook.given(FeeHook.PreRedeemShares).returns(true, true),
|
53
|
-
// PostBuyShares fee
|
54
|
-
mockPostBuySharesFee.getRecipientForFund.returns(constants.AddressZero),
|
55
|
-
mockPostBuySharesFee.settle.returns(FeeSettlementType.None, constants.AddressZero, 0),
|
56
|
-
mockPostBuySharesFee.payout.returns(false),
|
57
|
-
mockPostBuySharesFee.addFundSettings.returns(undefined),
|
58
|
-
mockPostBuySharesFee.activateForFund.returns(undefined),
|
59
|
-
mockPostBuySharesFee.update.returns(undefined),
|
60
|
-
mockPostBuySharesFee.settlesOnHook.returns(false, false),
|
61
|
-
mockPostBuySharesFee.settlesOnHook.given(FeeHook.PostBuyShares).returns(true, false),
|
62
|
-
mockPostBuySharesFee.updatesOnHook.returns(false, false),
|
63
|
-
]);
|
64
|
-
|
65
|
-
return {
|
66
|
-
mockContinuousFeeSettleOnly,
|
67
|
-
mockContinuousFeeWithGavAndUpdates,
|
68
|
-
mockPostBuySharesFee,
|
69
|
-
};
|
70
|
-
}
|
@@ -1,78 +0,0 @@
|
|
1
|
-
import type { SignerWithAddress } from '@enzymefinance/hardhat';
|
2
|
-
import type { AaveAdapter, ComptrollerLib, IntegrationManager, StandardToken } from '@enzymefinance/protocol';
|
3
|
-
import {
|
4
|
-
aaveLendArgs,
|
5
|
-
aaveRedeemArgs,
|
6
|
-
callOnIntegrationArgs,
|
7
|
-
IntegrationManagerActionId,
|
8
|
-
lendSelector,
|
9
|
-
redeemSelector,
|
10
|
-
} from '@enzymefinance/protocol';
|
11
|
-
import type { BigNumberish } from 'ethers';
|
12
|
-
import { utils } from 'ethers';
|
13
|
-
|
14
|
-
export async function aaveLend({
|
15
|
-
comptrollerProxy,
|
16
|
-
integrationManager,
|
17
|
-
fundOwner,
|
18
|
-
aaveAdapter,
|
19
|
-
aToken,
|
20
|
-
amount = utils.parseEther('1'),
|
21
|
-
}: {
|
22
|
-
comptrollerProxy: ComptrollerLib;
|
23
|
-
integrationManager: IntegrationManager;
|
24
|
-
fundOwner: SignerWithAddress;
|
25
|
-
aaveAdapter: AaveAdapter;
|
26
|
-
aToken: StandardToken;
|
27
|
-
amount?: BigNumberish;
|
28
|
-
}) {
|
29
|
-
const lendArgs = aaveLendArgs({
|
30
|
-
aToken,
|
31
|
-
amount,
|
32
|
-
});
|
33
|
-
|
34
|
-
const callArgs = callOnIntegrationArgs({
|
35
|
-
adapter: aaveAdapter,
|
36
|
-
encodedCallArgs: lendArgs,
|
37
|
-
selector: lendSelector,
|
38
|
-
});
|
39
|
-
|
40
|
-
const lendTx = comptrollerProxy
|
41
|
-
.connect(fundOwner)
|
42
|
-
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
43
|
-
|
44
|
-
return lendTx;
|
45
|
-
}
|
46
|
-
|
47
|
-
export async function aaveRedeem({
|
48
|
-
comptrollerProxy,
|
49
|
-
integrationManager,
|
50
|
-
fundOwner,
|
51
|
-
aaveAdapter,
|
52
|
-
aToken,
|
53
|
-
amount = utils.parseEther('1'),
|
54
|
-
}: {
|
55
|
-
comptrollerProxy: ComptrollerLib;
|
56
|
-
integrationManager: IntegrationManager;
|
57
|
-
fundOwner: SignerWithAddress;
|
58
|
-
aaveAdapter: AaveAdapter;
|
59
|
-
aToken: StandardToken;
|
60
|
-
amount?: BigNumberish;
|
61
|
-
}) {
|
62
|
-
const redeemArgs = aaveRedeemArgs({
|
63
|
-
aToken,
|
64
|
-
amount,
|
65
|
-
});
|
66
|
-
|
67
|
-
const callArgs = callOnIntegrationArgs({
|
68
|
-
adapter: aaveAdapter,
|
69
|
-
encodedCallArgs: redeemArgs,
|
70
|
-
selector: redeemSelector,
|
71
|
-
});
|
72
|
-
|
73
|
-
const redeemTx = comptrollerProxy
|
74
|
-
.connect(fundOwner)
|
75
|
-
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
76
|
-
|
77
|
-
return redeemTx;
|
78
|
-
}
|
@@ -1,255 +0,0 @@
|
|
1
|
-
import type { AddressLike, Contract, Send } from '@enzymefinance/ethers';
|
2
|
-
import { contract, resolveAddress } from '@enzymefinance/ethers';
|
3
|
-
import type { SignerWithAddress } from '@enzymefinance/hardhat';
|
4
|
-
import type {
|
5
|
-
CompoundAdapter,
|
6
|
-
CompoundPriceFeed,
|
7
|
-
ComptrollerLib,
|
8
|
-
ICERC20,
|
9
|
-
IntegrationManager,
|
10
|
-
VaultLib,
|
11
|
-
} from '@enzymefinance/protocol';
|
12
|
-
import {
|
13
|
-
callOnIntegrationArgs,
|
14
|
-
claimRewardsSelector,
|
15
|
-
compoundArgs,
|
16
|
-
compoundClaimRewardsArgs,
|
17
|
-
IntegrationManagerActionId,
|
18
|
-
lendSelector,
|
19
|
-
redeemSelector,
|
20
|
-
StandardToken,
|
21
|
-
} from '@enzymefinance/protocol';
|
22
|
-
import type { BigNumberish } from 'ethers';
|
23
|
-
import { BigNumber, utils } from 'ethers';
|
24
|
-
|
25
|
-
import { getAssetBalances } from '../../common';
|
26
|
-
|
27
|
-
export interface ICompoundComptroller extends Contract<ICompoundComptroller> {
|
28
|
-
claimComp: Send<(_account: AddressLike) => void>;
|
29
|
-
}
|
30
|
-
|
31
|
-
export const ICompoundComptroller = contract<ICompoundComptroller>()`
|
32
|
-
function claimComp(address)
|
33
|
-
`;
|
34
|
-
|
35
|
-
export async function assertCompoundLend({
|
36
|
-
tokenWhale,
|
37
|
-
comptrollerProxy,
|
38
|
-
vaultProxy,
|
39
|
-
integrationManager,
|
40
|
-
fundOwner,
|
41
|
-
compoundAdapter,
|
42
|
-
tokenAmount = utils.parseEther('1'),
|
43
|
-
cToken,
|
44
|
-
compoundPriceFeed,
|
45
|
-
}: {
|
46
|
-
tokenWhale: SignerWithAddress;
|
47
|
-
comptrollerProxy: ComptrollerLib;
|
48
|
-
vaultProxy: VaultLib;
|
49
|
-
integrationManager: IntegrationManager;
|
50
|
-
fundOwner: SignerWithAddress;
|
51
|
-
compoundAdapter: CompoundAdapter;
|
52
|
-
tokenAmount?: BigNumber;
|
53
|
-
cToken: ICERC20;
|
54
|
-
compoundPriceFeed: CompoundPriceFeed;
|
55
|
-
}) {
|
56
|
-
const token = new StandardToken(await compoundPriceFeed.getTokenFromCToken.args(cToken).call(), tokenWhale);
|
57
|
-
await token.connect(tokenWhale).transfer(vaultProxy, tokenAmount);
|
58
|
-
const rateBefore = await cToken.exchangeRateStored.call();
|
59
|
-
|
60
|
-
// Exchange rate stored can have a small deviation from exchangeRateStored
|
61
|
-
const minIncomingCTokenAmount = tokenAmount
|
62
|
-
.mul(utils.parseEther('1'))
|
63
|
-
.div(rateBefore)
|
64
|
-
.mul(BigNumber.from('999'))
|
65
|
-
.div(BigNumber.from('1000'));
|
66
|
-
|
67
|
-
const [preTxIncomingAssetBalance, preTxOutgoingAssetBalance] = await getAssetBalances({
|
68
|
-
account: vaultProxy,
|
69
|
-
assets: [cToken as any, token],
|
70
|
-
});
|
71
|
-
|
72
|
-
const lendReceipt = await compoundLend({
|
73
|
-
cToken,
|
74
|
-
cTokenAmount: minIncomingCTokenAmount,
|
75
|
-
compoundAdapter,
|
76
|
-
comptrollerProxy,
|
77
|
-
fundOwner,
|
78
|
-
integrationManager,
|
79
|
-
tokenAmount,
|
80
|
-
});
|
81
|
-
|
82
|
-
// Get exchange rate after tx (the rate is updated right after)
|
83
|
-
const rate = await cToken.exchangeRateStored();
|
84
|
-
const [postTxIncomingAssetBalance, postTxOutgoingAssetBalance] = await getAssetBalances({
|
85
|
-
account: vaultProxy,
|
86
|
-
assets: [cToken as any, token],
|
87
|
-
});
|
88
|
-
|
89
|
-
const expectedCTokenAmount = tokenAmount.mul(utils.parseEther('1')).div(rate);
|
90
|
-
expect(postTxIncomingAssetBalance).toEqBigNumber(preTxIncomingAssetBalance.add(expectedCTokenAmount));
|
91
|
-
expect(postTxOutgoingAssetBalance).toEqBigNumber(preTxOutgoingAssetBalance.sub(tokenAmount));
|
92
|
-
|
93
|
-
return lendReceipt;
|
94
|
-
}
|
95
|
-
|
96
|
-
export async function assertCompoundRedeem({
|
97
|
-
comptrollerProxy,
|
98
|
-
vaultProxy,
|
99
|
-
integrationManager,
|
100
|
-
fundOwner,
|
101
|
-
compoundAdapter,
|
102
|
-
cToken,
|
103
|
-
compoundPriceFeed,
|
104
|
-
}: {
|
105
|
-
comptrollerProxy: ComptrollerLib;
|
106
|
-
vaultProxy: VaultLib;
|
107
|
-
integrationManager: IntegrationManager;
|
108
|
-
fundOwner: SignerWithAddress;
|
109
|
-
compoundAdapter: CompoundAdapter;
|
110
|
-
cToken: ICERC20;
|
111
|
-
compoundPriceFeed: CompoundPriceFeed;
|
112
|
-
}) {
|
113
|
-
const cTokenAmount = utils.parseUnits('1', await cToken.decimals());
|
114
|
-
await cToken.transfer(vaultProxy, cTokenAmount);
|
115
|
-
|
116
|
-
const token = new StandardToken(await compoundPriceFeed.getTokenFromCToken.args(cToken).call(), provider);
|
117
|
-
const [preTxIncomingAssetBalance, preTxOutgoingAssetBalance] = await getAssetBalances({
|
118
|
-
account: vaultProxy,
|
119
|
-
assets: [token, cToken as any],
|
120
|
-
});
|
121
|
-
|
122
|
-
const rateBefore = await cToken.exchangeRateStored();
|
123
|
-
const minIncomingTokenAmount = cTokenAmount.mul(rateBefore).div(utils.parseEther('1'));
|
124
|
-
|
125
|
-
const redeemReceipt = await compoundRedeem({
|
126
|
-
cToken,
|
127
|
-
cTokenAmount,
|
128
|
-
compoundAdapter,
|
129
|
-
comptrollerProxy,
|
130
|
-
fundOwner,
|
131
|
-
integrationManager,
|
132
|
-
tokenAmount: minIncomingTokenAmount,
|
133
|
-
vaultProxy,
|
134
|
-
});
|
135
|
-
|
136
|
-
const [postTxIncomingAssetBalance, postTxOutgoingAssetBalance] = await getAssetBalances({
|
137
|
-
account: vaultProxy,
|
138
|
-
assets: [token, cToken as any],
|
139
|
-
});
|
140
|
-
|
141
|
-
// Get exchange rate after tx (the rate is updated right after)
|
142
|
-
const rate = await cToken.exchangeRateStored();
|
143
|
-
const expectedTokenAmount = cTokenAmount.mul(rate).div(utils.parseEther('1'));
|
144
|
-
|
145
|
-
expect(postTxIncomingAssetBalance).toEqBigNumber(preTxIncomingAssetBalance.add(expectedTokenAmount));
|
146
|
-
expect(postTxOutgoingAssetBalance).toEqBigNumber(preTxOutgoingAssetBalance.sub(cTokenAmount));
|
147
|
-
|
148
|
-
return redeemReceipt;
|
149
|
-
}
|
150
|
-
|
151
|
-
export async function compoundClaim({
|
152
|
-
comptrollerProxy,
|
153
|
-
integrationManager,
|
154
|
-
fundOwner,
|
155
|
-
compoundAdapter,
|
156
|
-
compoundComptroller,
|
157
|
-
cTokens,
|
158
|
-
}: {
|
159
|
-
comptrollerProxy: ComptrollerLib;
|
160
|
-
integrationManager: IntegrationManager;
|
161
|
-
fundOwner: SignerWithAddress;
|
162
|
-
compoundAdapter: CompoundAdapter;
|
163
|
-
compoundComptroller: AddressLike;
|
164
|
-
cTokens: AddressLike[];
|
165
|
-
}) {
|
166
|
-
const claimArgs = compoundClaimRewardsArgs({
|
167
|
-
cTokens,
|
168
|
-
compoundComptroller,
|
169
|
-
});
|
170
|
-
|
171
|
-
const callArgs = callOnIntegrationArgs({
|
172
|
-
adapter: compoundAdapter,
|
173
|
-
encodedCallArgs: claimArgs,
|
174
|
-
selector: claimRewardsSelector,
|
175
|
-
});
|
176
|
-
|
177
|
-
const claimRewardsTx = comptrollerProxy
|
178
|
-
.connect(fundOwner)
|
179
|
-
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
180
|
-
|
181
|
-
return claimRewardsTx;
|
182
|
-
}
|
183
|
-
|
184
|
-
export async function compoundLend({
|
185
|
-
comptrollerProxy,
|
186
|
-
integrationManager,
|
187
|
-
fundOwner,
|
188
|
-
compoundAdapter,
|
189
|
-
cToken,
|
190
|
-
tokenAmount = utils.parseEther('1'),
|
191
|
-
cTokenAmount = utils.parseEther('1'),
|
192
|
-
}: {
|
193
|
-
comptrollerProxy: ComptrollerLib;
|
194
|
-
integrationManager: IntegrationManager;
|
195
|
-
fundOwner: SignerWithAddress;
|
196
|
-
compoundAdapter: CompoundAdapter;
|
197
|
-
cToken: AddressLike;
|
198
|
-
tokenAmount?: BigNumberish;
|
199
|
-
cTokenAmount?: BigNumberish;
|
200
|
-
}) {
|
201
|
-
const lendArgs = compoundArgs({
|
202
|
-
cToken,
|
203
|
-
minIncomingAssetAmount: cTokenAmount,
|
204
|
-
outgoingAssetAmount: tokenAmount,
|
205
|
-
});
|
206
|
-
|
207
|
-
const callArgs = callOnIntegrationArgs({
|
208
|
-
adapter: compoundAdapter,
|
209
|
-
encodedCallArgs: lendArgs,
|
210
|
-
selector: lendSelector,
|
211
|
-
});
|
212
|
-
|
213
|
-
const lendTx = comptrollerProxy
|
214
|
-
.connect(fundOwner)
|
215
|
-
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
216
|
-
|
217
|
-
return lendTx;
|
218
|
-
}
|
219
|
-
|
220
|
-
export async function compoundRedeem({
|
221
|
-
comptrollerProxy,
|
222
|
-
integrationManager,
|
223
|
-
fundOwner,
|
224
|
-
compoundAdapter,
|
225
|
-
cToken,
|
226
|
-
tokenAmount = utils.parseEther('1'),
|
227
|
-
cTokenAmount = utils.parseEther('1'),
|
228
|
-
}: {
|
229
|
-
comptrollerProxy: ComptrollerLib;
|
230
|
-
vaultProxy: VaultLib;
|
231
|
-
integrationManager: IntegrationManager;
|
232
|
-
fundOwner: SignerWithAddress;
|
233
|
-
compoundAdapter: CompoundAdapter;
|
234
|
-
cToken: AddressLike;
|
235
|
-
tokenAmount?: BigNumberish;
|
236
|
-
cTokenAmount?: BigNumberish;
|
237
|
-
}) {
|
238
|
-
const redeemArgs = compoundArgs({
|
239
|
-
cToken: resolveAddress(cToken),
|
240
|
-
minIncomingAssetAmount: tokenAmount,
|
241
|
-
outgoingAssetAmount: cTokenAmount,
|
242
|
-
});
|
243
|
-
|
244
|
-
const callArgs = callOnIntegrationArgs({
|
245
|
-
adapter: compoundAdapter,
|
246
|
-
encodedCallArgs: redeemArgs,
|
247
|
-
selector: redeemSelector,
|
248
|
-
});
|
249
|
-
|
250
|
-
const redeemTx = comptrollerProxy
|
251
|
-
.connect(fundOwner)
|
252
|
-
.callOnExtension(integrationManager, IntegrationManagerActionId.CallOnIntegration, callArgs);
|
253
|
-
|
254
|
-
return redeemTx;
|
255
|
-
}
|