Skip to content

Commit

Permalink
feat: add Sourcify support to deploy-cli
Browse files Browse the repository at this point in the history
Also refactor the deployment script and our test harnesses to share a
single deployment function.
  • Loading branch information
danielattilasimon committed Apr 9, 2024
1 parent 66da622 commit e4c1183
Show file tree
Hide file tree
Showing 8 changed files with 4,835 additions and 262 deletions.
1,526 changes: 1,526 additions & 0 deletions contracts/broadcast/DeployLiquity2.s.sol/1337/run-1712649204.json

Large diffs are not rendered by default.

1,526 changes: 1,526 additions & 0 deletions contracts/broadcast/DeployLiquity2.s.sol/1337/run-1712649405.json

Large diffs are not rendered by default.

1,526 changes: 1,526 additions & 0 deletions contracts/broadcast/DeployLiquity2.s.sol/1337/run-latest.json

Large diffs are not rendered by default.

157 changes: 0 additions & 157 deletions contracts/scripts/DeployLiquity2.s.sol

This file was deleted.

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 e4c1183

Please sign in to comment.