Skip to content

Commit

Permalink
Add a deployment script for app development purposes (#83)
Browse files Browse the repository at this point in the history
- Hardhat: add ACCOUNTS_BALANCE to change the default accounts ETH balance.
- Hardhat: add a script to deploy contracts for app development purposes.
  • Loading branch information
bpierre authored Mar 19, 2024
1 parent ae8c58f commit 71e23f8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
14 changes: 11 additions & 3 deletions contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ require("@nomicfoundation/hardhat-toolbox");
require("@nomiclabs/hardhat-truffle5");
require("solidity-coverage");

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 @@ -23,7 +31,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);
});

0 comments on commit 71e23f8

Please sign in to comment.