-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
527 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,6 @@ on: | |
|
||
jobs: | ||
test-foundry: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.