Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a deployment script for app development purposes #83

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ require("@nomicfoundation/hardhat-foundry");
require("@nomicfoundation/hardhat-toolbox");
require("@nomiclabs/hardhat-truffle5");

const accounts = require("./hardhatAccountsList2k.js");
const accountsList = accounts.accountsList;
function accounts() {
const { accountsList } = require("./hardhatAccountsList2k.js");
const balanceStr = process.env.ACCOUNTS_BALANCE?.trim();
return balanceStr
? accountsList.map((account) => ({
...account,
balance: String(BigInt(balanceStr) * 10n ** 18n),
}))
: accountsList;
}

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
Expand All @@ -22,7 +30,7 @@ module.exports = {
},
networks: {
hardhat: {
accounts: accountsList,
accounts: accounts(),
gas: 10000000,
blockGasLimit: 15000000,
gasPrice: 20000000000,
Expand Down
2 changes: 1 addition & 1 deletion contracts/hardhatAccountsList2k.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _1e36Str = "1000000000000000000000000000000000000"
const _1e36Str = String(10n ** 36n)

const accountsList =

Expand Down
75 changes: 75 additions & 0 deletions contracts/utils/deploymentDev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const hre = require("hardhat");
const { deployLiquityCoreHardhat, connectCoreContracts } = require("./deploymentHelpers.js");

// Deploy Liquity contracts for development purposes
async function main() {
const contracts = await deployLiquityCoreHardhat();
await connectCoreContracts(contracts);

const accounts = await hre.ethers.getSigners();

// list of [debt, coll] tuples
const trovesParams = [
[1_800n, 20n],
[2_800n, 32n],
[4_000n, 30n],
[6_000n, 65n],
[5_000n, 50n],
[2_400n, 37n],
];

// open troves
await Promise.all(trovesParams.map(async ([debt, coll], index) => {
const account = await accounts[index].getAddress();
return contracts.borrowerOperations.openTrove(
String(100n * 10n ** 16n), // 100%
String(debt * 10n ** 18n),
account,
account,
String(5n * 10n ** 16n), // 5%
{
from: account,
value: String(coll * 10n ** 18n),
},
);
}));

let namesWidth = 0;
const contractsLog = [];
for (const contract of Object.values(contracts)) {
const { contractName } = contract.constructor;
contractsLog.push([contractName, contract.address]);
namesWidth = Math.max(namesWidth, contractName.length);
}

console.log("");
console.log("Core contracts deployed.");
console.log("");
console.log(
contractsLog
.map(([name, address]) => `${name.padEnd(namesWidth)} ${address}`)
.join("\n"),
);
console.log("");

console.log("Frontend vars (put this in frontend/*.env):");
console.log("");
console.log(
contractsLog
.map(([name, address]) => envVarContract(name, address))
.join("\n"),
);
console.log("");
}

function envVarContract(name, address) {
const envVarEnd = name.replace(/[A-Z]/g, (s) => "_" + s);
return `NEXT_PUBLIC_CONTRACT${envVarEnd.toUpperCase()}=${address}`;
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading