Skip to content

Commit d76db85

Browse files
committed
Update and fix E2E tests
1 parent 2d232e6 commit d76db85

File tree

6 files changed

+71
-147
lines changed

6 files changed

+71
-147
lines changed

hardhat.base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { HardhatUserConfig } from "hardhat/types";
99
// Hardhat tasks
1010
import "./tasks/advance-epoch";
1111
import "./tasks/advance-week-and-drawdown-receivable";
12-
import "./tasks/prepare-tranches-flc-for-withdrawal";
12+
import "./tasks/withdraw-flc-and-close-pool";
1313
import "./tasks/withdraw-from-tranches";
1414

1515
const EMPTY_URL = "empty url";

scripts/deploy-local-test-pools.ts

Lines changed: 44 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BigNumber as BN } from "ethers";
44
import { ethers } from "hardhat";
55
import moment from "moment";
66

7+
import { getAccountSigners } from "../tasks/utils";
78
import {
89
CreditContractName,
910
CreditManagerContractName,
@@ -14,60 +15,15 @@ import {
1415
import { CONSTANTS, LocalPoolName } from "../test/constants";
1516
import { overrideFirstLossCoverConfig, toToken } from "../test/TestUtils";
1617
import {
17-
Calendar,
18-
CreditDueManager,
1918
CreditLine,
2019
CreditLineManager,
21-
EpochManager,
2220
FirstLossCover,
23-
HumaConfig,
2421
MockToken,
25-
Pool,
26-
PoolConfig,
27-
PoolFeeManager,
28-
PoolSafe,
29-
Receivable,
3022
ReceivableBackedCreditLine,
31-
RiskAdjustedTranchesPolicy,
32-
TrancheVault,
23+
ReceivableBackedCreditLineManager,
3324
} from "../typechain-types";
3425
import { advanceChainTime } from "./utils";
3526

36-
let defaultDeployer: SignerWithAddress,
37-
protocolOwner: SignerWithAddress,
38-
treasury: SignerWithAddress,
39-
sentinelServiceAccount: SignerWithAddress;
40-
let poolOwner: SignerWithAddress,
41-
poolOwnerTreasury: SignerWithAddress,
42-
evaluationAgent: SignerWithAddress,
43-
poolOperator: SignerWithAddress;
44-
let juniorLender: SignerWithAddress,
45-
seniorLender: SignerWithAddress,
46-
lenderRedemptionActive: SignerWithAddress,
47-
borrowerActive: SignerWithAddress,
48-
borrowerApproved: SignerWithAddress,
49-
borrowerNoAutopay: SignerWithAddress,
50-
borrowerAutopayReady: SignerWithAddress,
51-
borrowerLate: SignerWithAddress,
52-
borrowerDefault: SignerWithAddress;
53-
54-
let humaConfigContract: HumaConfig, mockTokenContract: MockToken;
55-
let poolConfigContract: PoolConfig,
56-
poolFeeManagerContract: PoolFeeManager,
57-
poolSafeContract: PoolSafe,
58-
calendarContract: Calendar,
59-
borrowerFirstLossCoverContract: FirstLossCover,
60-
adminFirstLossCoverContract: FirstLossCover,
61-
tranchesPolicyContract: RiskAdjustedTranchesPolicy,
62-
poolContract: Pool,
63-
epochManagerContract: EpochManager,
64-
seniorTrancheVaultContract: TrancheVault,
65-
juniorTrancheVaultContract: TrancheVault,
66-
creditContract: CreditLine | ReceivableBackedCreditLine,
67-
creditDueManagerContract: CreditDueManager,
68-
creditManagerContract: CreditLineManager,
69-
receivableContract: Receivable;
70-
7127
const poolsToDeploy: {
7228
creditContract: CreditContractName;
7329
manager: CreditManagerContractName;
@@ -86,7 +42,12 @@ const poolsToDeploy: {
8642
// Add more pools as needed
8743
];
8844

89-
async function depositFirstLossCover(coverContract: FirstLossCover, account: SignerWithAddress) {
45+
async function depositFirstLossCover(
46+
coverContract: FirstLossCover,
47+
mockTokenContract: MockToken,
48+
poolOwner: SignerWithAddress,
49+
account: SignerWithAddress,
50+
) {
9051
await coverContract.connect(poolOwner).addCoverProvider(account.address);
9152
await mockTokenContract
9253
.connect(account)
@@ -110,7 +71,7 @@ async function deployPool(
11071
console.log(`Pool name: ${poolName}`);
11172
}
11273
console.log(`Starting block timestamp: ${await time.latest()}`);
113-
[
74+
const {
11475
defaultDeployer,
11576
protocolOwner,
11677
treasury,
@@ -123,22 +84,17 @@ async function deployPool(
12384
seniorLender,
12485
lenderRedemptionActive,
12586
borrowerActive,
126-
borrowerApproved,
127-
borrowerNoAutopay,
128-
borrowerAutopayReady,
129-
borrowerLate,
130-
borrowerDefault,
131-
] = await ethers.getSigners();
87+
} = await getAccountSigners(ethers);
13288

13389
console.log("Deploying and setting up protocol contracts");
134-
[humaConfigContract, mockTokenContract] = await deployProtocolContracts(
90+
const [humaConfigContract, mockTokenContract] = await deployProtocolContracts(
13591
protocolOwner,
13692
treasury,
13793
sentinelServiceAccount,
13894
poolOwner,
13995
);
14096

141-
[
97+
const [
14298
poolConfigContract,
14399
poolFeeManagerContract,
144100
poolSafeContract,
@@ -150,9 +106,9 @@ async function deployPool(
150106
epochManagerContract,
151107
seniorTrancheVaultContract,
152108
juniorTrancheVaultContract,
153-
creditContract as unknown,
109+
creditContract,
154110
creditDueManagerContract,
155-
creditManagerContract as unknown,
111+
creditManagerContract,
156112
receivableContract,
157113
] = await deployAndSetupPoolContracts(
158114
humaConfigContract,
@@ -170,7 +126,12 @@ async function deployPool(
170126
);
171127

172128
// Deposit first loss cover
173-
await depositFirstLossCover(borrowerFirstLossCoverContract, borrowerActive);
129+
await depositFirstLossCover(
130+
borrowerFirstLossCoverContract,
131+
mockTokenContract,
132+
poolOwner,
133+
borrowerActive,
134+
);
174135

175136
// Set first loss cover liquidity cap
176137
const totalAssetsBorrowerFLC = await borrowerFirstLossCoverContract.totalAssets();
@@ -208,15 +169,17 @@ async function deployPool(
208169

209170
if (poolName === LocalPoolName.CreditLine) {
210171
console.log("Drawing down from CreditLine");
211-
await creditManagerContract.connect(evaluationAgent).approveBorrower(
212-
borrowerActive.address,
213-
toToken(100_000),
214-
5, // numOfPeriods
215-
1217, // yieldInBps
216-
toToken(0),
217-
0,
218-
true,
219-
);
172+
await (creditManagerContract as CreditLineManager)
173+
.connect(evaluationAgent)
174+
.approveBorrower(
175+
borrowerActive.address,
176+
toToken(100_000),
177+
5, // numOfPeriods
178+
1217, // yieldInBps
179+
toToken(0),
180+
0,
181+
true,
182+
);
220183
const borrowAmount = toToken(100_000);
221184

222185
// Drawing down credit line
@@ -244,16 +207,18 @@ async function deployPool(
244207
lateFeeBps,
245208
});
246209

247-
console.log("Drawing down from CreditLine");
248-
await creditManagerContract.connect(evaluationAgent).approveBorrower(
249-
borrowerActive.address,
250-
toToken(100_000),
251-
5, // numOfPeriods
252-
1217, // yieldInBps
253-
toToken(0),
254-
0,
255-
true,
256-
);
210+
console.log("Drawing down from ReceivableBackedCreditLine");
211+
await (creditManagerContract as ReceivableBackedCreditLineManager)
212+
.connect(evaluationAgent)
213+
.approveBorrower(
214+
borrowerActive.address,
215+
toToken(100_000),
216+
5, // numOfPeriods
217+
1217, // yieldInBps
218+
toToken(0),
219+
0,
220+
true,
221+
);
257222
const borrowAmount = toToken(100_000);
258223

259224
const currentBlockTimestamp = await time.latest();
@@ -285,8 +250,8 @@ async function deployPool(
285250
console.log(`Borrower: ${borrowerActive.address}`);
286251
console.log(`Sentinel Service: ${sentinelServiceAccount.address}`);
287252
console.log(`Pool owner: ${poolOwner.address}`);
288-
289253
console.log("-------------------------------------");
254+
290255
console.log("Addresses:");
291256
console.log(`Pool: ${poolContract.address}`);
292257
console.log(`Epoch manager: ${epochManagerContract.address}`);
@@ -303,7 +268,6 @@ async function deployPool(
303268
if (poolName === LocalPoolName.ReceivableBackedCreditLine) {
304269
console.log(`Receivable: ${receivableContract.address}`);
305270
}
306-
307271
console.log("=====================================");
308272
}
309273

tasks/advance-epoch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ task("advanceEpoch", "Advances time in the local blockchain based on options")
3333
console.log(`Advancing blockchain to ${timestampToAdvance}`);
3434

3535
// Simulate the passage of time by advancing the time on the Hardhat Network
36-
await hre.network.provider.send("evm_setNextBlockTimestamp", [timestampToAdvance]);
36+
await hre.network.provider.send("evm_setNextBlockTimestamp", [timestampToAdvance + 1]);
3737
await hre.network.provider.send("evm_mine");
3838
});

tasks/advance-week-and-drawdown-receivable.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { time } from "@nomicfoundation/hardhat-network-helpers";
2-
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
32
import { BigNumber } from "ethers";
43
import { task } from "hardhat/config";
54
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
65
import moment from "moment";
76
import { CONSTANTS } from "../test/constants";
7+
import { getAccountSigners } from "./utils";
88

99
task(
1010
"advanceWeekAndDrawdownReceivable",
@@ -15,9 +15,7 @@ task(
1515
"The address of the Pool Config whose epoch you wish to advance to next",
1616
)
1717
.setAction(async (taskArgs: { poolConfigAddr: string }, hre: HardhatRuntimeEnvironment) => {
18-
let borrowerActive: SignerWithAddress;
19-
20-
[, , , , , , , , , , , , borrowerActive] = await hre.ethers.getSigners();
18+
const { borrowerActive } = await getAccountSigners(hre.ethers);
2119

2220
const PoolConfig = await hre.ethers.getContractFactory("PoolConfig");
2321
const poolConfigContract = PoolConfig.attach(taskArgs.poolConfigAddr);

tasks/prepare-tranches-flc-for-withdrawal.ts renamed to tasks/withdraw-flc-and-close-pool.ts

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@ import { task } from "hardhat/config";
33
import { HardhatRuntimeEnvironment } from "hardhat/types";
44
import { CONSTANTS } from "../test/constants";
55
import { FirstLossCover } from "../typechain-types";
6-
7-
async function submitRedemptionRequestToTranche(
8-
hre: HardhatRuntimeEnvironment,
9-
trancheVaultContractAddr: string,
10-
redemptionRequester: SignerWithAddress,
11-
): Promise<void> {
12-
const TrancheVault = await hre.ethers.getContractFactory("TrancheVault");
13-
const trancheVaultContract = TrancheVault.attach(trancheVaultContractAddr);
14-
const redemptionShares = await trancheVaultContract.balanceOf(redemptionRequester.address);
15-
if (redemptionShares.gt(0)) {
16-
const addRedemptionRequestTx = await trancheVaultContract
17-
.connect(redemptionRequester)
18-
.addRedemptionRequest(redemptionShares);
19-
await addRedemptionRequestTx.wait();
20-
}
21-
}
6+
import { getAccountSigners } from "./utils";
227

238
async function withdrawFromFLC(
249
flcContract: FirstLossCover,
@@ -34,73 +19,45 @@ async function withdrawFromFLC(
3419
}
3520

3621
task(
37-
"prepareTranchesFlcForWithdrawal",
22+
"withdrawFLCAndClosePool",
3823
"Submit withdrawal and redemption requests and prepare pool for closing",
3924
)
4025
.addParam(
4126
"poolConfigAddr",
4227
"The address of the Pool Config whose epoch you wish to advance to next",
4328
)
4429
.setAction(async (taskArgs: { poolConfigAddr: string }, hre: HardhatRuntimeEnvironment) => {
45-
let poolOwner: SignerWithAddress,
46-
poolOwnerTreasury: SignerWithAddress,
47-
evaluationAgent: SignerWithAddress,
48-
juniorLender: SignerWithAddress,
49-
seniorLender: SignerWithAddress,
50-
borrowerActive: SignerWithAddress,
51-
treasury: SignerWithAddress;
52-
5330
console.log("Preparing pool for closing");
54-
[
55-
,
56-
,
31+
const {
5732
treasury,
58-
,
59-
,
6033
poolOwner,
6134
poolOwnerTreasury,
6235
evaluationAgent,
63-
,
64-
juniorLender,
65-
seniorLender,
66-
,
6736
borrowerActive,
68-
] = await hre.ethers.getSigners();
37+
} = await getAccountSigners(hre.ethers);
6938

7039
const PoolConfig = await hre.ethers.getContractFactory("PoolConfig");
7140
const poolConfigContract = PoolConfig.attach(taskArgs.poolConfigAddr);
72-
73-
console.log("Submitting redemption requests to tranches");
74-
const juniorTranche = await poolConfigContract.juniorTranche();
75-
const seniorTranche = await poolConfigContract.seniorTranche();
76-
77-
await poolConfigContract.connect(poolOwner).setPoolOwnerRewardsAndLiquidity(0, 0);
78-
await poolConfigContract.connect(poolOwner).setEARewardsAndLiquidity(0, 0);
79-
80-
// Submit redemption requests
81-
await submitRedemptionRequestToTranche(hre, juniorTranche, juniorLender);
82-
await submitRedemptionRequestToTranche(hre, juniorTranche, poolOwnerTreasury);
83-
await submitRedemptionRequestToTranche(hre, juniorTranche, evaluationAgent);
84-
await submitRedemptionRequestToTranche(hre, seniorTranche, seniorLender);
85-
86-
console.log("Setting FLC to ready for withdraw");
8741
const FirstLossCover = await hre.ethers.getContractFactory("FirstLossCover");
8842
const flcContracts = await poolConfigContract.getFirstLossCovers();
8943
const borrowerFirstLossCoverContract = FirstLossCover.attach(
9044
flcContracts[CONSTANTS.BORROWER_LOSS_COVER_INDEX],
91-
);
45+
);
9246
const affiliateFirstLossCoverContract = FirstLossCover.attach(
9347
flcContracts[CONSTANTS.ADMIN_LOSS_COVER_INDEX],
9448
);
95-
96-
// Set FLC ready to withdraw
49+
50+
await poolConfigContract.connect(poolOwner).setPoolOwnerRewardsAndLiquidity(0, 0);
51+
await poolConfigContract.connect(poolOwner).setEARewardsAndLiquidity(0, 0);
52+
53+
console.log("Closing pool");
9754
const Pool = await hre.ethers.getContractFactory("Pool");
9855
const poolContract = Pool.attach(await poolConfigContract.pool());
9956
await poolContract.connect(poolOwner).closePool();
10057

10158
await console.log("Withdrawing from FLC");
10259
await withdrawFromFLC(borrowerFirstLossCoverContract, borrowerActive);
103-
await withdrawFromFLC(affiliateFirstLossCoverContract, poolOwnerTreasury);
10460
await withdrawFromFLC(affiliateFirstLossCoverContract, evaluationAgent);
10561
await withdrawFromFLC(affiliateFirstLossCoverContract, treasury);
62+
await withdrawFromFLC(affiliateFirstLossCoverContract, poolOwnerTreasury);
10663
});

0 commit comments

Comments
 (0)