Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Apr 9, 2024
2 parents 6a6d449 + f260960 commit 8ce4bf0
Show file tree
Hide file tree
Showing 8 changed files with 527 additions and 100 deletions.
37 changes: 34 additions & 3 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ on:

jobs:
test-foundry:
strategy:
fail-fast: true

name: Foundry tests
runs-on: ubuntu-latest
steps:
Expand All @@ -48,6 +45,40 @@ jobs:
forge test -vvv
id: test

deploy:
name: Deploy contracts to Liquity v2 Testnet
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install pnpm
uses: pnpm/[email protected]
with:
version: 8

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
cache: 'pnpm'
cache-dependency-path: 'contracts/pnpm-lock.yaml'

- name: Install dependencies
run: pnpm install

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run deployment tool
run: ./deploy liquity-testnet --verify
env:
DEPLOYER: ${{ secrets.DEPLOYER }}

console-logs:
name: Check we didn’t forget to remove console imports
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ out/
# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/*/1337/
/broadcast/**/dry-run/

# Docs
Expand Down
8 changes: 8 additions & 0 deletions contracts/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S npx tsx

require("./utils/deploy-cli").main().catch(({ message }) => {
console.error("");
console.error(` Error: ${message}`);
console.error("");
process.exit(1);
});
4 changes: 3 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"hardhat-gas-reporter": "^1.0.8",
"solidity-coverage": "^0.8.8",
"ts-node": ">=8.0.0",
"tsx": "^4.7.1",
"typechain": "^8.1.0",
"typescript": ">=4.5.0"
"typescript": ">=4.5.0",
"zx": "^7.2.3"
}
}
115 changes: 115 additions & 0 deletions contracts/src/deployment.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

import "./ActivePool.sol";
import "./BoldToken.sol";
import "./BorrowerOperations.sol";
import "./CollSurplusPool.sol";
import "./DefaultPool.sol";
import "./GasPool.sol";
import "./HintHelpers.sol";
import "./MultiTroveGetter.sol";
import "./SortedTroves.sol";
import "./StabilityPool.sol";
import "./TroveManager.sol";
import "./MockInterestRouter.sol";
import "./test/TestContracts/PriceFeedTestnet.sol";

struct LiquityContracts {
IActivePool activePool;
IBorrowerOperations borrowerOperations;
ICollSurplusPool collSurplusPool;
IDefaultPool defaultPool;
ISortedTroves sortedTroves;
IStabilityPool stabilityPool;
ITroveManager troveManager;
IBoldToken boldToken;
IPriceFeedTestnet priceFeed;
GasPool gasPool;
IInterestRouter interestRouter;
IERC20 WETH;
}

function _deployAndConnectContracts() returns (LiquityContracts memory contracts) {
contracts.WETH = new ERC20("Wrapped ETH", "WETH");

// TODO: optimize deployment order & constructor args & connector functions

// Deploy all contracts
contracts.activePool = new ActivePool(address(contracts.WETH));
contracts.borrowerOperations = new BorrowerOperations(address(contracts.WETH));
contracts.collSurplusPool = new CollSurplusPool(address(contracts.WETH));
contracts.defaultPool = new DefaultPool(address(contracts.WETH));
contracts.gasPool = new GasPool();
contracts.priceFeed = new PriceFeedTestnet();
contracts.sortedTroves = new SortedTroves();
contracts.stabilityPool = new StabilityPool(address(contracts.WETH));
contracts.troveManager = new TroveManager();
contracts.interestRouter = new MockInterestRouter();

contracts.boldToken = new BoldToken(
address(contracts.troveManager),
address(contracts.stabilityPool),
address(contracts.borrowerOperations),
address(contracts.activePool)
);

// Connect contracts
contracts.sortedTroves.setParams(
type(uint256).max, address(contracts.troveManager), address(contracts.borrowerOperations)
);

// set contracts in the Trove Manager
contracts.troveManager.setAddresses(
address(contracts.borrowerOperations),
address(contracts.activePool),
address(contracts.defaultPool),
address(contracts.stabilityPool),
address(contracts.gasPool),
address(contracts.collSurplusPool),
address(contracts.priceFeed),
address(contracts.boldToken),
address(contracts.sortedTroves)
);

// set contracts in BorrowerOperations
contracts.borrowerOperations.setAddresses(
address(contracts.troveManager),
address(contracts.activePool),
address(contracts.defaultPool),
address(contracts.stabilityPool),
address(contracts.gasPool),
address(contracts.collSurplusPool),
address(contracts.priceFeed),
address(contracts.sortedTroves),
address(contracts.boldToken)
);

// set contracts in the Pools
contracts.stabilityPool.setAddresses(
address(contracts.borrowerOperations),
address(contracts.troveManager),
address(contracts.activePool),
address(contracts.boldToken),
address(contracts.sortedTroves),
address(contracts.priceFeed)
);

contracts.activePool.setAddresses(
address(contracts.borrowerOperations),
address(contracts.troveManager),
address(contracts.stabilityPool),
address(contracts.defaultPool),
address(contracts.boldToken),
address(contracts.interestRouter)
);

contracts.defaultPool.setAddresses(address(contracts.troveManager), address(contracts.activePool));

contracts.collSurplusPool.setAddresses(
address(contracts.borrowerOperations), address(contracts.troveManager), address(contracts.activePool)
);
}
83 changes: 83 additions & 0 deletions contracts/src/scripts/DeployLiquity2.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;

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

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

function run() external {
if (vm.envBytes("DEPLOYER").length == 20) {
// address
vm.startBroadcast(vm.envAddress("DEPLOYER"));
} else {
// private key
vm.startBroadcast(vm.envUint("DEPLOYER"));
}

LiquityContracts memory contracts = _deployAndConnectContracts();
vm.stopBroadcast();

if (vm.envOr("OPEN_DEMO_TROVES", false)) {
openDemoTroves(contracts.WETH, contracts.borrowerOperations);
}
}

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

uint256 eth = 1e18;
uint256 bold = 1e18;

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)
];

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

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);

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

0 comments on commit 8ce4bf0

Please sign in to comment.