Skip to content

Commit

Permalink
DeployLiquity2: fix openDemoTroves()
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Apr 13, 2024
1 parent 86d0477 commit 33283b9
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions contracts/src/scripts/DeployLiquity2.s.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;

import "forge-std/console.sol";
import {Script} from "forge-std/Script.sol";
import {StdCheats} from "forge-std/StdCheats.sol";
import "../deployment.sol";
import {Accounts} from "../test/TestContracts/Accounts.sol";
import {ERC20Faucet} from "../test/TestContracts/ERC20Faucet.sol";

contract DeployLiquity2Script is Script, StdCheats {
struct TroveParams {
uint256 coll;
uint256 debt;
uint256 owner;
uint256 ownerIndex;
}

function run() external {
Expand All @@ -30,54 +34,50 @@ contract DeployLiquity2Script is Script, StdCheats {
}

function openDemoTroves(IERC20 WETH, IBorrowerOperations borrowerOperations) internal {
address[10] memory accounts = createAccounts(WETH, borrowerOperations);

uint256 eth = 1e18;
uint256 bold = 1e18;
// Anvil accounts
// TODO: pass accounts from env
uint256[8] memory accounts = [
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80,
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d,
0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a,
0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6,
0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a,
0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba,
0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e,
0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
];

TroveParams[8] memory troves = [
TroveParams(20 * eth, 1800 * bold),
TroveParams(32 * eth, 2800 * bold),
TroveParams(30 * eth, 4000 * bold),
TroveParams(65 * eth, 6000 * bold),
TroveParams(50 * eth, 5000 * bold),
TroveParams(37 * eth, 2400 * bold),
TroveParams(37 * eth, 2800 * bold),
TroveParams(36 * eth, 2222 * bold)
TroveParams({owner: accounts[0], ownerIndex: 0, coll: 20e18, debt: 1800e18}),
TroveParams({owner: accounts[1], ownerIndex: 0, coll: 32e18, debt: 2800e18}),
TroveParams({owner: accounts[2], ownerIndex: 0, coll: 30e18, debt: 4000e18}),
TroveParams({owner: accounts[3], ownerIndex: 0, coll: 65e18, debt: 6000e18}),
TroveParams({owner: accounts[4], ownerIndex: 0, coll: 50e18, debt: 5000e18}),
TroveParams({owner: accounts[5], ownerIndex: 0, coll: 37e18, debt: 2400e18}),
TroveParams({owner: accounts[6], ownerIndex: 0, coll: 37e18, debt: 2800e18}),
TroveParams({owner: accounts[7], ownerIndex: 0, coll: 36e18, debt: 2222e18})
];

for (uint256 i = 0; i < troves.length; i++) {
vm.startPrank(accounts[i]);
vm.startBroadcast(troves[i].owner);

borrowerOperations.openTrove(
accounts[i], // _owner
1, // _ownerIndex
1e18, // _maxFeePercentage
troves[i].coll, // _ETHAmount
troves[i].debt, // _boldAmount
0, // _upperHint
0, // _lowerHint
0.05e18 // _annualInterestRate
);

vm.stopPrank();
}
}

function createAccounts(IERC20 WETH, IBorrowerOperations borrowerOperations)
internal
returns (address[10] memory accountsList)
{
Accounts accounts = new Accounts();

for (uint256 i = 0; i < accounts.getAccountsCount(); i++) {
accountsList[i] = vm.addr(uint256(accounts.accountsPks(i)));
deal(address(WETH), accountsList[i], 1000e18);
ERC20Faucet(address(WETH)).tap();

// Approve infinite WETH to BorrowerOperations
vm.startPrank(accountsList[i]);
WETH.approve(address(borrowerOperations), type(uint256).max);
vm.stopPrank();

borrowerOperations.openTrove(
vm.addr(troves[i].owner), // _owner
troves[i].ownerIndex, // _ownerIndex
1e18, // _maxFeePercentage (100%)
troves[i].coll, // _ETHAmount
troves[i].debt, // _boldAmount
0, // _upperHint
0, // _lowerHint
0.05e18 // _annualInterestRate
);

vm.stopBroadcast();
}
}
}

0 comments on commit 33283b9

Please sign in to comment.