Skip to content

Commit

Permalink
conflict handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PlayJok3r committed Jun 2, 2024
2 parents 36f4ecf + e390998 commit 357da6d
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 15 deletions.
36 changes: 21 additions & 15 deletions deployment/deployUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BigNumber as BN, ethers } from "ethers";
import fs from "fs";
const DEPLOYED_PATH = "./deployment/";

const MAX_FEE_PER_GAS = 2_000_000_000;
const MAX_FEE_PER_GAS = 1_000_000;
const MAX_PRIORITY_FEE_PER_GAS = 0;

const getContractAddressFile = async function (fileType = "deployed", network) {
Expand Down Expand Up @@ -112,12 +112,13 @@ export const sendTransaction = async function (
const method = contractInstance[methodName];
console.log(`${contractName}:${logMessage} Start!`);
console.log(`paramaters: ${parameters}`);
await checkReceiptOk(
await method(...parameters, {
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}),
);
// await checkReceiptOk(
// await method(...parameters, {
// maxFeePerGas: MAX_FEE_PER_GAS,
// maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
// }),
// );
await checkReceiptOk(await method(...parameters));
console.log(`${contractName}:${logMessage} End!`);
};

Expand Down Expand Up @@ -153,16 +154,21 @@ export async function deploy(
// const gasPrice = web3.utils.toHex('33000000000')

let contract;
// if (contractParameters) {
// contract = await Contract.deploy(...contractParameters, {
// maxFeePerGas: MAX_FEE_PER_GAS,
// maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
// });
// } else {
// contract = await Contract.deploy({
// maxFeePerGas: MAX_FEE_PER_GAS,
// maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
// });
// }
if (contractParameters) {
contract = await Contract.deploy(...contractParameters, {
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
});
contract = await Contract.deploy(...contractParameters);
} else {
contract = await Contract.deploy({
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
});
contract = await Contract.deploy();
}
console.log(`${keyName} TransactionHash: ${contract.deployTransaction.hash}`);
await contract.deployed();
Expand Down
26 changes: 26 additions & 0 deletions deployment/scrollSepolia-deployed-contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"MockToken": "0x50dc34a634F3E29CfBad79E9cECD2759a6bA8Eae",
"Calendar": "0xb94879541CAF746bFe1b066421E7D64C94fC9738",
"HumaConfig": "0xa0A16038D714F687679732dCb34e1d4051218Dc5",
"HumaConfigTimelock": "0x503EA0E2d1180b74F3A6105F43C481d18C2e426d",
"PoolConfigImpl": "0x41c82e7bA2Cea9b14B4CCd88d96739a1f1890384",
"PoolFeeManagerImpl": "0xEDa33b3b92Af44D5D1Be70Fb77527e74CbE933f7",
"PoolSafeImpl": "0xCc0a468E93e8D2eEA311c7e9135BB78207DB7EF9",
"FirstLossCoverImpl": "0xDDf423278bBe8A5Fc0E608d68A577f05024a8Ed4",
"RiskAdjustedTranchesPolicyImpl": "0xF1982c34E7256e02852e7dE664247aE04B0c71f2",
"FixedSeniorYieldTranchesPolicyImpl": "0xBB867612c4428798F0Be599671530ED96B104D8a",
"PoolImpl": "0x458594604Fbc36DE8016843D50e54688A639655B",
"EpochManagerImpl": "0x03e84C522b834Bb8cF84A5B64b4d0824e492Fc68",
"TrancheVaultImpl": "0x3DA2A11433eABBB1E661478BdBd03510F9D4b83b",
"CreditLineImpl": "0xbaFF4a403AA31819B1bD23A254EaEd3d8cC87a41",
"ReceivableBackedCreditLineImpl": "0x479f92d5F875f9Ced1C8C95cB8dcE6b7F6Ce9c92",
"ReceivableFactoringCreditImpl": "0x9BF2A12eB9276314F26A7E575cdb99D041D06DF3",
"CreditDueManagerImpl": "0x3e4c08aE5fD8d535033942B5fB7D761C271762e3",
"CreditLineManagerImpl": "0xD19d0C1EAC63f1E1e41FE86F83C08774CA324155",
"ReceivableBackedCreditLineManagerImpl": "0xd61F3595Da5563826875dcB239dD06b348f93702",
"ReceivableFactoringCreditManagerImpl": "0xdf243D02f5a6611F1D5988Dd8376FB1269dDac89",
"ReceivableImpl": "0xBA7525621EF5803FE0B0217F3Efb1889b9ca0686",
"LibTimelockController": "0x0204CfeAE8B6e409a1695CfDeD4c3D6B403a213e",
"PoolFactoryImpl": "0xb5d43a18c4c459DD705cc0924771D238514D1C5b",
"PoolFactory": "0x88278d0370C8B13919F67c67f9a0067095Cf5447"
}
87 changes: 87 additions & 0 deletions deployment/scrollSepolia/deploy-protocol-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import hre, { network } from "hardhat";
import { deploy } from "../deployUtils.ts";

const HUMA_OWNER_ADDRESS = "0x60891b087E81Ee2a61B7606f68019ec112c539B9";
let deployer;
let networkName;

async function deployImplementationContracts() {
const contracts = [
"PoolConfig",
"PoolFeeManager",
"PoolSafe",
"FirstLossCover",
"RiskAdjustedTranchesPolicy",
"FixedSeniorYieldTranchesPolicy",
"Pool",
"EpochManager",
"TrancheVault",
"CreditLine",
"ReceivableBackedCreditLine",
"ReceivableFactoringCredit",
"CreditDueManager",
"CreditLineManager",
"ReceivableBackedCreditLineManager",
"ReceivableFactoringCreditManager",
"Receivable",
];

for (var contractName of contracts) {
console.log(contractName);
await deploy(networkName, contractName, `${contractName}Impl`);
}
}

async function deployFactory(humaConfigAddress) {
const libTimelockController = await deploy(
networkName,
"LibTimelockController",
"LibTimelockController",
);
const poolFactoryImpl = await deploy(networkName, "PoolFactory", "PoolFactoryImpl", [], {
libraries: { LibTimelockController: libTimelockController.address },
});
console.log(humaConfigAddress);
const fragment = await poolFactoryImpl.interface.getFunction("initialize(address)");
const calldata = await poolFactoryImpl.interface.encodeFunctionData(fragment, [
humaConfigAddress,
]);
await deploy(networkName, "ERC1967Proxy", "PoolFactory", [poolFactoryImpl.address, calldata]);
}

async function deployProtocolContracts() {
await deploy(networkName, "Calendar", "Calendar");
const humaConfig = await deploy(networkName, "HumaConfig", "HumaConfig");
await deploy(networkName, "TimelockController", "HumaConfigTimelock", [
0,
[HUMA_OWNER_ADDRESS],
[deployer.address],
deployer.address,
]);

return humaConfig.address;
}

async function deployContracts() {
// const networkName = (await hre.ethers.provider.getNetworkName()).name;
networkName = network.name;
console.log("networkName : ", networkName);
const accounts = await hre.ethers.getSigners();
if (accounts.length == 0) {
throw new Error("Accounts not set!");
}
[deployer] = await accounts;
console.log("deployer address: " + deployer.address);

await deploy(networkName, "MockToken", "MockToken");
const humaConfigAddress = await deployProtocolContracts();
await deployImplementationContracts();
await deployFactory(humaConfigAddress);
}

deployContracts()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
148 changes: 148 additions & 0 deletions deployment/scrollSepolia/init-protocol-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import hre, { network } from "hardhat";
import {
getDeployedContracts,
getInitilizedContract,
sendTransaction,
updateInitializedContract,
} from "../deployUtils.ts";

let networkName;
let deployer;
let deployedContracts;
const HUMA_TREASURY_ACCOUNT = "0x60891b087E81Ee2a61B7606f68019ec112c539B9";
const SENTINEL_ACCOUNT = "0x3C64b8A1431F2227E4aAD3aF15a7667b752A4537";
const contracts = [
"PoolConfig",
"PoolFeeManager",
"PoolSafe",
"FirstLossCover",
"RiskAdjustedTranchesPolicy",
"FixedSeniorYieldTranchesPolicy",
"Pool",
"EpochManager",
"TrancheVault",
"CreditLine",
"ReceivableBackedCreditLine",
"ReceivableFactoringCredit",
"CreditDueManager",
"CreditLineManager",
"ReceivableBackedCreditLineManager",
"ReceivableFactoringCreditManager",
"Receivable",
];

async function transferOwnershipToTL(contractName, contractKey, timeLockKey) {
if (!deployedContracts[timeLockKey]) {
throw new Error(`${timeLockKey} not deployed yet!`);
}

if (!deployedContracts[contractKey]) {
throw new Error(`${contractKey} not deployed yet!`);
}

const TimeLockController = await hre.ethers.getContractFactory("TimelockController");
const timeLockController = TimeLockController.attach(deployedContracts[timeLockKey]);

const Contract = await hre.ethers.getContractFactory(contractName);
const contract = Contract.attach(deployedContracts[contractKey]);

await sendTransaction(contractKey, contract, "transferOwnership", [
timeLockController.address,
]);

const adminRole = await timeLockController.TIMELOCK_ADMIN_ROLE();
await sendTransaction(contractKey, timeLockController, "renounceRole", [
adminRole,
deployer.address,
]);
}

async function initHumaConfig() {
const initilized = await getInitilizedContract("HumaConfig", networkName);
if (initilized) {
console.log("HumaConfig is already initialized!");
return;
}

if (!deployedContracts["HumaConfig"]) {
throw new Error("HumaConfig not deployed yet!");
}

if (!deployedContracts["MockToken"]) {
throw new Error("MockToken not deployed yet!");
}

const HumaConfig = await hre.ethers.getContractFactory("HumaConfig");
const humaConfig = HumaConfig.attach(deployedContracts["HumaConfig"]);

await sendTransaction("HumaConfig", humaConfig, "setHumaTreasury", [HUMA_TREASURY_ACCOUNT]);
await sendTransaction("HumaConfig", humaConfig, "setSentinelServiceAccount", [
SENTINEL_ACCOUNT,
]);
await sendTransaction("HumaConfig", humaConfig, "setLiquidityAsset", [
deployedContracts["MockToken"],
true,
]);
// await transferOwnershipToTL("HumaConfig", "HumaConfig", "HumaConfigTimelock")

await updateInitializedContract("HumaConfig", networkName);
}

async function initPoolFactory() {
const initilized = await getInitilizedContract("PoolFactory", networkName);
if (initilized) {
console.log("PoolFactory is already initialized!");
return;
}

if (!deployedContracts["PoolFactory"]) {
throw new Error("PoolFactory not deployed yet!");
}

for (var contractName of contracts) {
if (!deployedContracts[`${contractName}Impl`]) {
throw new Error(contractName + " not deployed yet!");
}
}

const PoolFactory = await hre.ethers.getContractFactory("PoolFactory", {
libraries: { LibTimelockController: deployedContracts["LibTimelockController"] },
});
const poolFactory = PoolFactory.attach(deployedContracts["PoolFactory"]);

await sendTransaction("PoolFactory", poolFactory, "addDeployer", [deployer.address]);
await sendTransaction("PoolFactory", poolFactory, "setCalendarAddress", [
deployedContracts["Calendar"],
]);
for (contractName of contracts) {
await sendTransaction("PoolFactory", poolFactory, `set${contractName}ImplAddress`, [
deployedContracts[`${contractName}Impl`],
]);
}

// await transferOwnershipToTL("HumaConfig", "HumaConfig", "HumaConfigTimelock")

await updateInitializedContract("PoolFactory", networkName);
}

async function initContracts() {
// const networkName = (await hre.ethers.provider.getNetworkName()).name;
networkName = network.name;
console.log("networkName : ", networkName);
const accounts = await hre.ethers.getSigners();
[deployer] = await accounts;
console.log("deployer address: " + deployer.address);
// console.log("ea address: " + eaService.address);

deployedContracts = await getDeployedContracts(networkName);
console.log(deployedContracts);
await initHumaConfig();
await initPoolFactory();
}

initContracts()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
14 changes: 14 additions & 0 deletions hardhat.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const config: HardhatUserConfig = {
accounts: [deployer],
chainId: 80002,
},
scrollSepolia: {
url: "https://sepolia-rpc.scroll.io",
accounts: [deployer],
chainId: 534351,
},
},
solidity: {
compilers: [
Expand All @@ -74,6 +79,7 @@ const config: HardhatUserConfig = {
celo: process.env.CELOSCAN_API_KEY || "",
baseSepolia: process.env.BASESCAN_API_KEY || "",
amoy: process.env.ETHERSCAN_API_KEY || "",
scrollSepolia: process.env.SCROLLSCAN_API_KEY || "",
},
customChains: [
{
Expand Down Expand Up @@ -108,6 +114,14 @@ const config: HardhatUserConfig = {
browserURL: "https://amoy.polygonscan.com/",
},
},
{
network: "scrollSepolia",
chainId: 534351,
urls: {
apiURL: "https://api-sepolia.scrollscan.com/api",
browserURL: "https://sepolia.scrollscan.dev/",
},
},
],
},
contractSizer: {
Expand Down

0 comments on commit 357da6d

Please sign in to comment.