Skip to content

Commit

Permalink
verify disburse
Browse files Browse the repository at this point in the history
  • Loading branch information
PlayJok3r committed Dec 31, 2024
1 parent 861d3f5 commit 45094a2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 119 deletions.
2 changes: 1 addition & 1 deletion deployment/deployUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const sendTransaction = async function (
logMessage?,
) {
// const gasPrice = await hre.ethers.provider.getGasPrice()
// await sleep(5000);
await sleep(5000);
logMessage = !logMessage ? methodName : logMessage;
const method = contractInstance[methodName];
console.log(`${contractName}:${logMessage} Start!`);
Expand Down
26 changes: 26 additions & 0 deletions deployment/scroll-temp/hardhat-deployed-contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"MockToken": "0x4730Ba92780b6783Ce97bD5f7AaD75337d6D180A",
"Calendar": "0x0562e6287dd69E76771E046f7E24ADC608c837b6",
"HumaConfig": "0x1691090fb0cFd3bd9b59128b57490eA882A09573",
"HumaConfigTimelock": "0x5B7841b94a3C7246662ef514745b034A6ceaAB15",
"PoolFeeManagerImpl": "0xf5F9297c74e464933e42F4a989e81D931fb20f83",
"PoolSafeImpl": "0x98f41d57C06b302AFf999f3F58f4ae7a3F884590",
"FirstLossCoverImpl": "0x87FD98F3eB172B5183F7527060DDbe8a8D17B924",
"RiskAdjustedTranchesPolicyImpl": "0x58AAF1f9cB10F335111A2129273056bbED251B61",
"FixedSeniorYieldTranchesPolicyImpl": "0x2Ff4108A5aA022F3b1b30aA0186454Db6A5F89fA",
"PoolImpl": "0x0550c0CC3135E271707c2fbfe63cA9Aa8c40d3c5",
"EpochManagerImpl": "0x8A76f41F360fE94920c9a3209Ae499496D733fcf",
"CreditLineImpl": "0x900DB77BB9c061051A4EB8A8Bdd8F02f1ee17EB6",
"ReceivableBackedCreditLineImpl": "0xd5643Da11EFb2DAC2523668AE41d4cBB4C005fb9",
"ReceivableFactoringCreditImpl": "0xA15e0D4Dd6010DAc65e3994DE8D97C548326eaF9",
"CreditDueManagerImpl": "0x11c5a1D28bBe81C22803f29fb7591AF4914ddc56",
"CreditLineManagerImpl": "0xF2AC6AD2d673A4c4aEc163FC5eAf989707edE9B0",
"ReceivableBackedCreditLineManagerImpl": "0xdE0e6b245E5Edec1c18AAC6cA48AD540e2703eb6",
"ReceivableFactoringCreditManagerImpl": "0x79D1aC58F10F724B6aB67708A411c50ED4DA281d",
"ReceivableImpl": "0x0a76a396fc138f211d01D2d5844d4b469ae37B69",
"LibTimelockController": "0x78f95653fD62a5CFc15E3c25B2212BC13d85f195",
"PoolFactoryImpl": "0x2Ec9952194f3fc4131f343c94971360fCEf12018",
"PoolFactory": "0xA8a5928Ee04BA928275ed1D1E7C7b89934dfE324",
"PoolConfigImpl": "0x0da01955AB786a948A6F34317c3beE47c804ad4F",
"TrancheVaultImpl": "0x2010529d1F2Ea01646828dAA4d1a82BD2716DaFE"
}
50 changes: 24 additions & 26 deletions deployment/scroll-temp/scroll-deployed-contracts.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
{
"MockToken": "0x4730Ba92780b6783Ce97bD5f7AaD75337d6D180A",
"Calendar": "0x0562e6287dd69E76771E046f7E24ADC608c837b6",
"HumaConfig": "0x1691090fb0cFd3bd9b59128b57490eA882A09573",
"HumaConfigTimelock": "0x5B7841b94a3C7246662ef514745b034A6ceaAB15",
"PoolFeeManagerImpl": "0xf5F9297c74e464933e42F4a989e81D931fb20f83",
"PoolSafeImpl": "0x98f41d57C06b302AFf999f3F58f4ae7a3F884590",
"FirstLossCoverImpl": "0x87FD98F3eB172B5183F7527060DDbe8a8D17B924",
"RiskAdjustedTranchesPolicyImpl": "0x58AAF1f9cB10F335111A2129273056bbED251B61",
"FixedSeniorYieldTranchesPolicyImpl": "0x74D9E676e86FF8547FD0F02fea3710d3B3E618E3",
"PoolImpl": "0x2dEce900ffAcfD89ea70bE911b703848568fD39d",
"EpochManagerImpl": "0x52C9B8D35717f16B5F45cb6Cf03E9f72c236603D",
"CreditLineImpl": "0x900DB77BB9c061051A4EB8A8Bdd8F02f1ee17EB6",
"ReceivableBackedCreditLineImpl": "0x0D2E679baaE452091DEfE0e711195FB5Fa9f59Ef",
"ReceivableFactoringCreditImpl": "0xA15e0D4Dd6010DAc65e3994DE8D97C548326eaF9",
"CreditDueManagerImpl": "0x11c5a1D28bBe81C22803f29fb7591AF4914ddc56",
"CreditLineManagerImpl": "0xF2AC6AD2d673A4c4aEc163FC5eAf989707edE9B0",
"ReceivableBackedCreditLineManagerImpl": "0x8817e6226CdEecD8c920ad18B5cE118408308ecE",
"ReceivableFactoringCreditManagerImpl": "0x79D1aC58F10F724B6aB67708A411c50ED4DA281d",
"ReceivableImpl": "0x0a76a396fc138f211d01D2d5844d4b469ae37B69",
"LibTimelockController": "0x78f95653fD62a5CFc15E3c25B2212BC13d85f195",
"PoolFactoryImpl": "0x97745a975a7596b2F62fa0ed1A7302ADAc9433f4",
"PoolFactory": "0xCB8F2bBa5a1f1d9aCB8e78f03d30F84beAA442cb",
"PoolConfigImpl": "0x0da01955AB786a948A6F34317c3beE47c804ad4F",
"TrancheVaultImpl": "0xE717B1c838B243eD95A6e50Fe9459145AAa5F55c"
}
{"MockToken":"0x4730Ba92780b6783Ce97bD5f7AaD75337d6D180A",
"Calendar":"0x0562e6287dd69E76771E046f7E24ADC608c837b6",
"HumaConfig":"0x1691090fb0cFd3bd9b59128b57490eA882A09573",
"HumaConfigTimelock":"0x5B7841b94a3C7246662ef514745b034A6ceaAB15",
"PoolFeeManagerImpl":"0xf5F9297c74e464933e42F4a989e81D931fb20f83",
"PoolSafeImpl":"0x98f41d57C06b302AFf999f3F58f4ae7a3F884590",
"FirstLossCoverImpl":"0x87FD98F3eB172B5183F7527060DDbe8a8D17B924",
"RiskAdjustedTranchesPolicyImpl":"0x58AAF1f9cB10F335111A2129273056bbED251B61",
"FixedSeniorYieldTranchesPolicyImpl":"0x2Ff4108A5aA022F3b1b30aA0186454Db6A5F89fA",
"PoolImpl":"0x0550c0CC3135E271707c2fbfe63cA9Aa8c40d3c5",
"EpochManagerImpl":"0x8A76f41F360fE94920c9a3209Ae499496D733fcf",
"CreditLineImpl":"0x900DB77BB9c061051A4EB8A8Bdd8F02f1ee17EB6",
"ReceivableBackedCreditLineImpl":"0xd5643Da11EFb2DAC2523668AE41d4cBB4C005fb9",
"ReceivableFactoringCreditImpl":"0xA15e0D4Dd6010DAc65e3994DE8D97C548326eaF9",
"CreditDueManagerImpl":"0x11c5a1D28bBe81C22803f29fb7591AF4914ddc56",
"CreditLineManagerImpl":"0xF2AC6AD2d673A4c4aEc163FC5eAf989707edE9B0",
"ReceivableBackedCreditLineManagerImpl":"0xdE0e6b245E5Edec1c18AAC6cA48AD540e2703eb6",
"ReceivableFactoringCreditManagerImpl":"0x79D1aC58F10F724B6aB67708A411c50ED4DA281d",
"ReceivableImpl":"0x0a76a396fc138f211d01D2d5844d4b469ae37B69",
"LibTimelockController":"0x78f95653fD62a5CFc15E3c25B2212BC13d85f195",
"PoolFactoryImpl":"0x2Ec9952194f3fc4131f343c94971360fCEf12018",
"PoolFactory":"0xA8a5928Ee04BA928275ed1D1E7C7b89934dfE324",
"PoolConfigImpl":"0x0da01955AB786a948A6F34317c3beE47c804ad4F",
"TrancheVaultImpl":"0x2010529d1F2Ea01646828dAA4d1a82BD2716DaFE"}
26 changes: 8 additions & 18 deletions deployment/scroll/20241230-migrate-stroage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import { expect } from "chai";
import fs from "fs";
import hre, { network } from "hardhat";
import { sendTransaction } from "../deployUtils";
// import { deployContracts } from "./[temp]deploy-recovery-protocol-factory";
// import { initContracts as initPoolFactory } from "./init-protocol-factory";
import { getDeployedContracts, sendTransaction } from "../deployUtils";

let deployer;
let networkName;
Expand All @@ -24,24 +22,16 @@ async function main() {

console.log("deployer address: " + deployer.address);

// deployedContracts = await getDeployedContracts(networkName);
// console.log(deployedContracts);

// let ethAmount = ethers.BigNumber.from("1000000000000000000000");

// await hre.network.provider.send("hardhat_setBalance", [
// deployer.address,
// ethAmount.toHexString(),
// ]);
deployedContracts = await getDeployedContracts(networkName);
console.log(deployedContracts);

// await deployContracts();
// await initPoolFactory();
// await sleep(5000);
// await createPool();
// await setPool();
// await addOwnership();
// await addTimeLock();
// await migrateStorage();
await createPool();
await setPool();
await addOwnership();
await addTimeLock();
await migrateStorage();
}

async function migrateStorage() {
Expand Down
30 changes: 19 additions & 11 deletions deployment/scroll/20241230-upgrade-6mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ async function main() {
// ethAmount.toHexString(),
// ]);

// await upgradeReceivableBackedCreditLine();
// await getUSDC(deployer.address);
// await approveUSDC(deployer);
// await replacePoolOwnerTreasury();
await upgradeReceivableBackedCreditLine();
// await makePayment();
await checkCreditRecord();
// await checkCreditRecord();

// await deployContracts();
// await initPoolFactory();
Expand Down Expand Up @@ -91,20 +88,31 @@ async function approveUSDC(account: Signer) {
}

async function makePayment() {
const poolOwnerTreasury = await impersonateAccount(
"0x73285f0013F76366e0442180C5Ae3A67Da2ab4fC",
);
await getUSDC(poolOwnerTreasury.address);
await approveUSDC(poolOwnerTreasury);

const poolConfig = await getPoolConfig(1);
const contractAddress = await poolConfig.callStatic["credit"]();
console.log(`Credit address: ${contractAddress}`);
const Contract = await hre.ethers.getContractAt("ReceivableBackedCreditLine", contractAddress);
// const ContractWithSigner = Contract.connect(borrower);
await sendTransaction(
"ReceivableBackedCreditLine",
Contract,
"makePaymentOnBehalfOfWithReceivable",
["0x08534d9b632a7A35d7af4aAe5d487A15FC247691", RECEIVABLE_ID, 95_615_000_000],
const ContractWithSigner = Contract.connect(poolOwnerTreasury);
await ContractWithSigner.makePaymentOnBehalfOfWithReceivable(
borrower,
RECEIVABLE_ID,
95_615_000_000,
);
// await sendTransaction(
// "ReceivableBackedCreditLine",
// ContractWithSigner,
// "makePaymentOnBehalfOfWithReceivable",
// ["0x08534d9b632a7A35d7af4aAe5d487A15FC247691", RECEIVABLE_ID, 95_615_000_000],
// );
// await sendTransaction(
// "ReceivableBackedCreditLine",
// ContractWithSigner,
// "makePaymentWithReceivable",
// [borrower.address, RECEIVABLE_ID, 780_000_000_000],
// );
Expand Down
19 changes: 0 additions & 19 deletions deployment/scroll/20241230-upgrade-back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,7 @@ async function main() {
deployedContracts = await getDeployedContracts(networkName);
console.log(deployedContracts);

// let ethAmount = ethers.BigNumber.from("1000000000000000000000");

// await hre.network.provider.send("hardhat_setBalance", [
// deployer.address,
// ethAmount.toHexString(),
// ]);

await upgradeProxies();
// await deployContracts();
// await initPoolFactory();
// await createPool();
// await setPool();
// await addOwnership();
// await migrateStorage();
}

async function impersonateAccount(account: string) {
Expand Down Expand Up @@ -65,12 +52,6 @@ async function getPoolConfig(poolId: number) {
}

async function upgradeProxies() {
// await hre.network.provider.request({
// method: "hardhat_impersonateAccount",
// params: ["0xf52130518d74d14573A59d10a26f6b89A263214e"],
// });

// const ledger = await new LedgerSigner(hre.ethers.provider, "hid", "m/44'/60'/0'/0");
const poolConfig = await getPoolConfig(1);
const humaConfig = await hre.ethers.getContractAt("HumaConfig", await poolConfig.humaConfig());
console.log(await humaConfig.owner());
Expand Down
102 changes: 58 additions & 44 deletions deployment/scroll/20241230-verification.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
/* eslint-disable no-undef */
import { impersonateAccount } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { Signer } from "ethers";
import hre, { network } from "hardhat";
import { getDeployedContracts, sendTransaction } from "../deployUtils";
let deployer;
let networkName;
let deployedContracts;
let borrower;
const RECEIVABLE_ID = 44;
const RECEIVABLE_ID = 43;
const USDC_ADDRESS = "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4";
const USDC_MAP_SLOT = "0x9";

async function main() {
await network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl:
"https://scroll-mainnet.g.alchemy.com/v2/N5soMVjdW0CxGKbbllHGyxbaOrrpu7th",
// blockNumber: 33667900,
},
},
],
});
networkName = network.name;
console.log("networkName : ", networkName);
const accounts = await hre.ethers.getSigners();
Expand All @@ -31,43 +44,32 @@ async function main() {
// ethAmount.toHexString(),
// ]);
const borrowerAddress = "0x08534d9b632a7A35d7af4aAe5d487A15FC247691";
// borrower = await impersonateAccount(borrowerAddress);

borrower = await hre.ethers.getImpersonatedSigner(borrowerAddress);
await borrower.sendTransaction({
to: deployer.address,
value: hre.ethers.utils.parseEther("0.01"),
});
borrower = await impersonateAccount(borrowerAddress);

// const IERC20 = "@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20";
// const usdc = await hre.ethers.getContractAt(IERC20, USDC_ADDRESS);
// const usdcWithSigner = await usdc.connect(await hre.ethers.getSigner(borrowerAddress));
// await usdcWithSigner.approve(deployer.address, hre.ethers.constants.MaxUint256);

// await getUSDC();
// await createReceivable();
// await getReceivableId();
// await replaceEA();
// await approveReceivable();
// await replacePoolOwnerTreasury();
// await transferReceivable();

// await getUSDC(deployer.address);
// await approveUSDC(deployer);
// await approveUSDCforBorrower(borrower.address);
// await makePayment();
await getUSDC(deployer.address);
await makePayment();
// await checkCreditRecord();

// await processYield();
// await setBlockTimeStamp();
// await closeEpoch();
await processYield();
await setBlockTimeStamp();
await closeEpoch();
await checkRedemptionSummary();
}

async function disburseLiquidity() {
const poolConfig = await getPoolConfig(1);
const contractAddress = await poolConfig.callStatic["credit"]();
const Contract = await hre.ethers.getContractAt("ReceivableBackedCreditLine", contractAddress);
await Contract.disburseLiquidity();
}

// await deployContracts();
// await initPoolFactory();
// await createPool();
// await setPool();
// await addOwnership();
// await migrateStorage();
async function checkRedemptionSummary() {
for (const tranche of ["juniorTranche", "seniorTranche"]) {
const poolConfig = await getPoolConfig(1);
const contractAddress = await poolConfig.callStatic[tranche]();
const Contract = await hre.ethers.getContractAt("TrancheVault", contractAddress);
console.log(`${tranche} redemption summary: `, await Contract.epochRedemptionSummary(7));
}
}

async function impersonateAccount(account: string) {
Expand Down Expand Up @@ -183,15 +185,17 @@ async function replaceEA() {
}

async function approveReceivable() {
const ea = await impersonateAccount("0x1D0952Dbe8351477125A31Da857E8b148f04372D");
const poolConfig = await getPoolConfig(1);
const Contract = await hre.ethers.getContractAt(
"ReceivableBackedCreditLineManager",
poolConfig.callStatic["creditManager"](),
);
await sendTransaction("ReceivableBackedCreditLineManager", Contract, "approveReceivable", [
borrower.address,
RECEIVABLE_ID,
]);
await Contract.connect(ea).approveReceivable(borrower.address, RECEIVABLE_ID);
// await sendTransaction("ReceivableBackedCreditLineManager", Contract, "approveReceivable", [
// borrower.address,
// RECEIVABLE_ID,
// ]);
}

async function getReceivableId() {
Expand All @@ -210,20 +214,30 @@ async function replacePoolOwnerTreasury() {
}

async function makePayment() {
const poolOwnerTreasury = await impersonateAccount(
"0x73285f0013F76366e0442180C5Ae3A67Da2ab4fC",
);
await getUSDC(poolOwnerTreasury.address);
await approveUSDC(poolOwnerTreasury);
const poolConfig = await getPoolConfig(1);
const contractAddress = await poolConfig.callStatic["credit"]();
console.log(`Credit address: ${contractAddress}`);
const Contract = await hre.ethers.getContractAt("ReceivableBackedCreditLine", contractAddress);
const ContractWithSigner = Contract.connect(borrower);
await sendTransaction(
"ReceivableBackedCreditLine",
Contract,
"makePaymentOnBehalfOfWithReceivable",
[borrower.address, RECEIVABLE_ID, 788_283_000_000],
const ContractWithSigner = Contract.connect(poolOwnerTreasury);
await ContractWithSigner.makePaymentOnBehalfOfWithReceivable(
borrower.address,
RECEIVABLE_ID,
785_138_000_000,
);
// await sendTransaction(
// "ReceivableBackedCreditLine",
// ContractWithSigner,
// "makePaymentOnBehalfOfWithReceivable",
// [borrower.address, RECEIVABLE_ID, 785_138_000_000],
// );
// await sendTransaction(
// "ReceivableBackedCreditLine",
// ContractWithSigner,
// "makePaymentWithReceivable",
// [borrower.address, RECEIVABLE_ID, 780_000_000_000],
// );
Expand Down
3 changes: 3 additions & 0 deletions hardhat.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const config: HardhatUserConfig = {
mnemonic: process.env.LOCALHOST_MNEMONIC_PHRASE,
}
: undefined,
forking: {
url: "https://scroll-mainnet.g.alchemy.com/v2/N5soMVjdW0CxGKbbllHGyxbaOrrpu7th",
},
},
localhost: {
url: "http://localhost:8545",
Expand Down

0 comments on commit 45094a2

Please sign in to comment.