Skip to content

Commit 03c93c0

Browse files
committed
Fix withdrawals
1 parent d76db85 commit 03c93c0

File tree

6 files changed

+78
-61
lines changed

6 files changed

+78
-61
lines changed

hardhat.base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { HardhatUserConfig } from "hardhat/types";
99
// Hardhat tasks
1010
import "./tasks/advance-epoch";
1111
import "./tasks/advance-week-and-drawdown-receivable";
12-
import "./tasks/withdraw-flc-and-close-pool";
13-
import "./tasks/withdraw-from-tranches";
12+
import "./tasks/log-incomes";
13+
import "./tasks/withdraw-and-close-pool";
1414

1515
const EMPTY_URL = "empty url";
1616
const EMPTY_PRIVATE_KEY = "0x0000000000000000000000000000000000000000000000000000000000000000";

tasks/advance-epoch.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
55
task("advanceEpoch", "Advances time in the local blockchain based on options")
66
.addParam(
77
"poolConfigAddr",
8-
"The address of the Pool Config whose epoch you wish to advance to next",
8+
"The PoolConfig contract address of the pool in question",
99
)
1010
.setAction(async (taskArgs: { poolConfigAddr: string }, hre: HardhatRuntimeEnvironment) => {
1111
console.log("Advancing to next epoch");
@@ -33,6 +33,8 @@ 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 + 1]);
36+
await hre.network.provider.send("evm_setNextBlockTimestamp", [timestampToAdvance + 60]);
37+
await hre.network.provider.send("evm_mine");
38+
await hre.network.provider.send("evm_mine");
3739
await hre.network.provider.send("evm_mine");
3840
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ task(
1212
)
1313
.addParam(
1414
"poolConfigAddr",
15-
"The address of the Pool Config whose epoch you wish to advance to next",
15+
"The PoolConfig contract address of the pool in question",
1616
)
1717
.setAction(async (taskArgs: { poolConfigAddr: string }, hre: HardhatRuntimeEnvironment) => {
1818
const { borrowerActive } = await getAccountSigners(hre.ethers);

tasks/log-incomes.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { task } from "hardhat/config";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
3+
import { getAccountSigners } from "./utils";
4+
5+
task(
6+
"logIncomes",
7+
"Submit withdrawal and redemption requests and prepare pool for closing",
8+
)
9+
.addParam(
10+
"poolConfigAddr",
11+
"The PoolConfig contract address of the pool in question",
12+
)
13+
.setAction(async (taskArgs: { poolConfigAddr: string }, hre: HardhatRuntimeEnvironment) => {
14+
const { poolOwnerTreasury, evaluationAgent, juniorLender, seniorLender, treasury } =
15+
await getAccountSigners(hre.ethers);
16+
17+
const PoolConfig = await hre.ethers.getContractFactory("PoolConfig");
18+
const poolConfigContract = PoolConfig.attach(taskArgs.poolConfigAddr);
19+
20+
const poolFeeManagerAddr = await poolConfigContract.poolFeeManager();
21+
const PoolFeeManager = await hre.ethers.getContractFactory("PoolFeeManager");
22+
const poolFeeManagerContract = PoolFeeManager.attach(poolFeeManagerAddr);
23+
24+
console.log('Accrued Incomes', await poolFeeManagerContract.getAccruedIncomes());
25+
console.log('protocolIncomeWithdrawn', await poolFeeManagerContract.protocolIncomeWithdrawn());
26+
console.log('poolOwnerIncomeWithdrawn', await poolFeeManagerContract.poolOwnerIncomeWithdrawn());
27+
console.log('eaIncomeWithdrawn', await poolFeeManagerContract.eaIncomeWithdrawn());
28+
});

tasks/withdraw-flc-and-close-pool.ts renamed to tasks/withdraw-and-close-pool.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ async function withdrawFromFLC(
1818
}
1919
}
2020

21+
async function withdrawFromTranche(
22+
hre: HardhatRuntimeEnvironment,
23+
trancheVaultContractAddr: string,
24+
redemptionRequester: SignerWithAddress,
25+
): Promise<void> {
26+
const TrancheVault = await hre.ethers.getContractFactory("TrancheVault");
27+
const trancheVaultContract = TrancheVault.attach(trancheVaultContractAddr);
28+
const tx = await trancheVaultContract
29+
.connect(redemptionRequester)
30+
.withdrawAfterPoolClosure();
31+
await tx.wait();
32+
}
33+
2134
task(
22-
"withdrawFLCAndClosePool",
35+
"withdrawAndClosePool",
2336
"Submit withdrawal and redemption requests and prepare pool for closing",
2437
)
2538
.addParam(
2639
"poolConfigAddr",
27-
"The address of the Pool Config whose epoch you wish to advance to next",
40+
"The PoolConfig contract address of the pool in question",
2841
)
2942
.setAction(async (taskArgs: { poolConfigAddr: string }, hre: HardhatRuntimeEnvironment) => {
3043
console.log("Preparing pool for closing");
@@ -34,6 +47,8 @@ task(
3447
poolOwnerTreasury,
3548
evaluationAgent,
3649
borrowerActive,
50+
juniorLender,
51+
seniorLender
3752
} = await getAccountSigners(hre.ethers);
3853

3954
const PoolConfig = await hre.ethers.getContractFactory("PoolConfig");
@@ -46,9 +61,6 @@ task(
4661
const affiliateFirstLossCoverContract = FirstLossCover.attach(
4762
flcContracts[CONSTANTS.ADMIN_LOSS_COVER_INDEX],
4863
);
49-
50-
await poolConfigContract.connect(poolOwner).setPoolOwnerRewardsAndLiquidity(0, 0);
51-
await poolConfigContract.connect(poolOwner).setEARewardsAndLiquidity(0, 0);
5264

5365
console.log("Closing pool");
5466
const Pool = await hre.ethers.getContractFactory("Pool");
@@ -60,4 +72,30 @@ task(
6072
await withdrawFromFLC(affiliateFirstLossCoverContract, evaluationAgent);
6173
await withdrawFromFLC(affiliateFirstLossCoverContract, treasury);
6274
await withdrawFromFLC(affiliateFirstLossCoverContract, poolOwnerTreasury);
75+
76+
console.log("Withdrawing from pool tranches");
77+
const juniorTranche = await poolConfigContract.juniorTranche();
78+
const seniorTranche = await poolConfigContract.seniorTranche();
79+
80+
// Debug logs
81+
// const TrancheVault = await hre.ethers.getContractFactory("TrancheVault");
82+
// const juniorTrancheContract = TrancheVault.attach(juniorTranche);
83+
// const seniorTrancheContract = TrancheVault.attach(seniorTranche);
84+
// console.log(await juniorTrancheContract.withdrawableAssets(juniorLender.address));
85+
// console.log(await juniorTrancheContract.withdrawableAssets(poolOwnerTreasury.address));
86+
// console.log(await juniorTrancheContract.withdrawableAssets(evaluationAgent.address));
87+
// console.log(await juniorTrancheContract.withdrawableAssets(seniorLender.address));
88+
// console.log(await juniorTrancheContract.withdrawableAssets(treasury.address));
89+
// console.log(await seniorTrancheContract.withdrawableAssets(juniorLender.address));
90+
// console.log(await seniorTrancheContract.withdrawableAssets(poolOwnerTreasury.address));
91+
// console.log(await seniorTrancheContract.withdrawableAssets(evaluationAgent.address));
92+
// console.log(await seniorTrancheContract.withdrawableAssets(seniorLender.address));
93+
// console.log(await seniorTrancheContract.withdrawableAssets(treasury.address));
94+
95+
// Redeem from tranches
96+
await withdrawFromTranche(hre, juniorTranche, juniorLender);
97+
await withdrawFromTranche(hre, juniorTranche, poolOwnerTreasury);
98+
await withdrawFromTranche(hre, juniorTranche, evaluationAgent);
99+
await withdrawFromTranche(hre, seniorTranche, seniorLender);
100+
await withdrawFromTranche(hre, seniorTranche, poolOwnerTreasury);
63101
});

tasks/withdraw-from-tranches.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)