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

Subgraph #375

Merged
merged 22 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
99 changes: 79 additions & 20 deletions contracts/src/scripts/DeployLiquity2.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import "../CollateralRegistry.sol";
import "../MockInterestRouter.sol";
import "../test/TestContracts/PriceFeedTestnet.sol";
import {WETHTester} from "../test/TestContracts/WETHTester.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import "forge-std/console.sol";

contract DeployLiquity2Script is Script, StdCheats {
bytes32 SALT;
Expand Down Expand Up @@ -82,10 +84,12 @@ contract DeployLiquity2Script is Script, StdCheats {
}

struct DemoTroveParams {
uint256 coll;
uint256 debt;
uint256 collIndex;
uint256 owner;
uint256 ownerIndex;
uint256 coll;
uint256 debt;
uint256 annualInterestRate;
}

function run() external {
Expand All @@ -102,9 +106,10 @@ contract DeployLiquity2Script is Script, StdCheats {
vm.startBroadcast(privateKey);
}

TroveManagerParams[] memory troveManagerParamsArray = new TroveManagerParams[](1);
TroveManagerParams[] memory troveManagerParamsArray = new TroveManagerParams[](2);

troveManagerParamsArray[0] = TroveManagerParams(150e16, 110e16, 110e16, 5e16, 10e16);
troveManagerParamsArray[0] = TroveManagerParams(150e16, 110e16, 110e16, 5e16, 10e16); // WETH
troveManagerParamsArray[1] = TroveManagerParams(150e16, 110e16, 110e16, 5e16, 10e16); // stETH

// used for gas compensation and as collateral of the first branch
IWETH WETH = new WETHTester(
Expand All @@ -113,7 +118,6 @@ contract DeployLiquity2Script is Script, StdCheats {
);
(LiquityContractsTestnet[] memory contractsArray,,,,) =
_deployAndConnectContracts(troveManagerParamsArray, WETH);
LiquityContractsTestnet memory contracts = contractsArray[0];
vm.stopBroadcast();

if (vm.envOr("OPEN_DEMO_TROVES", false)) {
Expand All @@ -129,35 +133,71 @@ contract DeployLiquity2Script is Script, StdCheats {
demoAccounts[6] = 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e;
demoAccounts[7] = 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356;

DemoTroveParams[] memory demoTroves = new DemoTroveParams[](4);
demoTroves[0] = DemoTroveParams({owner: demoAccounts[0], ownerIndex: 0, coll: 25e18, debt: 2800e18});
demoTroves[1] = DemoTroveParams({owner: demoAccounts[1], ownerIndex: 0, coll: 37e18, debt: 2400e18});
demoTroves[2] = DemoTroveParams({owner: demoAccounts[2], ownerIndex: 0, coll: 30e18, debt: 4000e18});
demoTroves[3] = DemoTroveParams({owner: demoAccounts[3], ownerIndex: 0, coll: 65e18, debt: 6000e18});
DemoTroveParams[] memory demoTroves = new DemoTroveParams[](16);

demoTroves[0] = DemoTroveParams(0, demoAccounts[0], 0, 25e18, 2800e18, 5.0e16);
demoTroves[1] = DemoTroveParams(0, demoAccounts[1], 0, 37e18, 2400e18, 4.7e16);
demoTroves[2] = DemoTroveParams(0, demoAccounts[2], 0, 30e18, 4000e18, 3.3e16);
demoTroves[3] = DemoTroveParams(0, demoAccounts[3], 0, 65e18, 6000e18, 4.3e16);

demoTroves[4] = DemoTroveParams(0, demoAccounts[4], 0, 19e18, 2280e18, 5.0e16);
demoTroves[5] = DemoTroveParams(0, demoAccounts[5], 0, 48.37e18, 4400e18, 4.7e16);
demoTroves[6] = DemoTroveParams(0, demoAccounts[6], 0, 33.92e18, 5500e18, 3.8e16);
demoTroves[7] = DemoTroveParams(0, demoAccounts[7], 0, 47.2e18, 6000e18, 4.3e16);

tapFaucet(demoAccounts, contracts);
openDemoTroves(demoTroves, contracts);
demoTroves[8] = DemoTroveParams(1, demoAccounts[0], 0, 21e18, 2000e18, 3.3e16);
demoTroves[9] = DemoTroveParams(1, demoAccounts[1], 1, 16e18, 2000e18, 4.1e16);
demoTroves[10] = DemoTroveParams(1, demoAccounts[2], 1, 18e18, 2300e18, 3.8e16);
demoTroves[11] = DemoTroveParams(1, demoAccounts[3], 1, 22e18, 2200e18, 4.3e16);

demoTroves[12] = DemoTroveParams(1, demoAccounts[4], 1, 85e18, 12000e18, 7.0e16);
demoTroves[13] = DemoTroveParams(1, demoAccounts[5], 1, 87e18, 4000e18, 4.4e16);
demoTroves[14] = DemoTroveParams(1, demoAccounts[6], 1, 61e18, 11000e18, 3.3e16);
demoTroves[15] = DemoTroveParams(1, demoAccounts[7], 1, 84e18, 14800e18, 4.4e16);

for (uint256 i = 0; i < contractsArray.length; i++) {
tapFaucet(demoAccounts, contractsArray[i]);
}

openDemoTroves(demoTroves, contractsArray);
}
}

function tapFaucet(uint256[] memory accounts, LiquityContractsTestnet memory contracts) internal {
for (uint256 i = 0; i < accounts.length; i++) {
ERC20Faucet token = ERC20Faucet(address(contracts.collToken));

vm.startBroadcast(accounts[i]);
ERC20Faucet(address(contracts.collToken)).tap();
token.tap();
vm.stopBroadcast();

console.log(
"%s.tap() => %s (balance: %s)",
token.symbol(),
vm.addr(accounts[i]),
string.concat(formatAmount(token.balanceOf(vm.addr(accounts[i])), 18, 2), " ", token.symbol())
);
}
}

function openDemoTroves(DemoTroveParams[] memory troves, LiquityContractsTestnet memory contracts) internal {
for (uint256 i = 0; i < troves.length; i++) {
DemoTroveParams memory trove = troves[i];
function openDemoTroves(DemoTroveParams[] memory demoTroves, LiquityContractsTestnet[] memory contractsArray)
internal
{
for (uint256 i = 0; i < demoTroves.length; i++) {
DemoTroveParams memory trove = demoTroves[i];
LiquityContractsTestnet memory contracts = contractsArray[trove.collIndex];

vm.startBroadcast(trove.owner);

// Approve collToken to BorrowerOperations
IERC20(contracts.collToken).approve(
address(contracts.borrowerOperations), trove.coll + ETH_GAS_COMPENSATION
);
IERC20 collToken = IERC20(contracts.collToken);
IERC20 wethToken = IERC20(contracts.addressesRegistry.WETH());

if (collToken == wethToken) {
wethToken.approve(address(contracts.borrowerOperations), trove.coll + ETH_GAS_COMPENSATION);
} else {
wethToken.approve(address(contracts.borrowerOperations), ETH_GAS_COMPENSATION);
collToken.approve(address(contracts.borrowerOperations), trove.coll);
}

IBorrowerOperations(contracts.borrowerOperations).openTrove(
vm.addr(trove.owner), // _owner
Expand Down Expand Up @@ -360,4 +400,23 @@ contract DeployLiquity2Script is Script, StdCheats {
address(contracts.activePool)
);
}

function formatAmount(uint256 amount, uint256 decimals, uint256 digits) internal pure returns (string memory) {
if (digits > decimals) {
digits = decimals;
}

uint256 scaled = amount / (10 ** (decimals - digits));
string memory whole = Strings.toString(scaled / (10 ** digits));

if (digits == 0) {
return whole;
}

string memory fractional = Strings.toString(scaled % (10 ** digits));
for (uint256 i = bytes(fractional).length; i < digits; i++) {
fractional = string.concat("0", fractional);
}
return string.concat(whole, ".", fractional);
}
}
7 changes: 4 additions & 3 deletions contracts/utils/deploy-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ Deploying Liquity contracts with the following settings:
delete process.env.CI;
}

// deploy
const deploymentOutput = await $`forge ${forgeArgs}`;
if (options.debug) {
console.log(deploymentOutput.text());
$.verbose = true;
}

// deploy
await $`forge ${forgeArgs}`;

const deployedContracts = await getDeployedContracts(
`broadcast/DeployLiquity2.s.sol/${options.chainId}/run-latest.json`,
);
Expand Down
Loading
Loading