Skip to content

Commit

Permalink
Network configuration (#143)
Browse files Browse the repository at this point in the history
* Update deployment

* Merge

* Update README

* Deploy base-sepolia too
  • Loading branch information
aviggiano authored Jul 18, 2024
1 parent 9f75543 commit bb5b95a
Show file tree
Hide file tree
Showing 28 changed files with 11,182 additions and 2,019 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Supported pair:
Target networks:

- Ethereum mainnet
- [Base](./deployments/8453.json)
- [Base](./deployments/base-production.json)

## Audits

Expand Down Expand Up @@ -224,44 +224,42 @@ for i in {0..5}; do halmos --loop $i; done

## Deployment


### Environment Setup

Ensure your `.env` file in the root directory of your project contains the following variables:

```
```bash
API_KEY_ALCHEMY=<Your Alchemy API Key>
API_KEY_ETHERSCAN=<Your Etherscan API Key>
DEPLOYER_ADDRESS=<Deployer's Ethereum Address>
DEPLOYER_ACCOUNT=<Name of the Deployer's Account in Foundry>
OWNER=<Owner's Address>
FEE_RECIPIENT=<Fee Recipient's Address>
CHAIN_NAME=<Network Name>
NETWORK_CONFIGURATION=<Network Configuration>
RPC_URL=<Network Name>
```

### Account Management

The `DEPLOYER_ACCOUNT` is a reference to the name of an account managed by Foundry's `cast wallet` feature. To import an external wallet using a private key, use the following command:
The `DEPLOYER_ACCOUNT` is a reference to the name of an account managed by Foundry's `cast wallet` feature. To create and import a new deployer wallet using a private key, use the following command:

```bash
cast wallet import <Your Private Key>
cast wallet import DEPLOYER_ACCOUNT_NAME --private-key $(cast wallet new | grep Private | awk -F 'Private key: ' '{print $2}')
```

### Network Configuration

Ensure that the `CHAIN_NAME` and `RPC_URL` are set according to the network you are deploying to. You can see the available networks in `script/Networks.sol`.
You can set relevant `NetworkParams` to `address(0)` if you are deploying with mock contracts or require specific network parameters.


## Deployment
Ensure that the `NETWORK_CONFIGURATION` is set according to the network options you are deploying to. For example, you can create a configuration `base-mocks` and another `base-production` without mocks. Also, ensure that `RPC_URL` is set according to the network you are deploying to. In the previous case, both would be equal to `base` as in your `foundry.toml`. You can see the available network configuration in `script/Networks.sol`.

You can set relevant `NetworkParams` to `address(0)` if you are deploying with mock contracts or require specific network parameters.

```bash
source .env
forge script script/Deploy.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sender $DEPLOYER_ADDRESS --account $DEPLOYER_ACCOUNT --ffi --verify
forge script script/Deploy.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sender $DEPLOYER_ADDRESS --account $DEPLOYER_ACCOUNT --ffi --verify -vvvvv
```

If it does not work, try removing `--verify`

### Deployment checklist

1. Deploy
Expand All @@ -273,5 +271,5 @@ forge script script/Deploy.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sende

```bash
source .env.sepolia
forge script script/Upgrade.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sender $DEPLOYER_ADDRESS --account $DEPLOYER_ACCOUNT --ffi --verify
forge script script/Upgrade.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sender $DEPLOYER_ADDRESS --account $DEPLOYER_ACCOUNT --ffi --verify -vvvvv
```
1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721323890.json

Large diffs are not rendered by default.

1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721324044.json

Large diffs are not rendered by default.

1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721324140.json

Large diffs are not rendered by default.

1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721324255.json

Large diffs are not rendered by default.

1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721324325.json

Large diffs are not rendered by default.

1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721324628.json

Large diffs are not rendered by default.

710 changes: 710 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1721324707.json

Large diffs are not rendered by default.

1,390 changes: 454 additions & 936 deletions broadcast/Deploy.s.sol/8453/run-latest.json

Large diffs are not rendered by default.

352 changes: 352 additions & 0 deletions broadcast/Deploy.s.sol/84532/run-1721326198.json

Large diffs are not rendered by default.

306 changes: 153 additions & 153 deletions broadcast/Deploy.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

987 changes: 987 additions & 0 deletions broadcast/Upgrade.s.sol/84532/run-1721244775.json

Large diffs are not rendered by default.

987 changes: 987 additions & 0 deletions broadcast/Upgrade.s.sol/84532/run-1721244953.json

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions broadcast/Upgrade.s.sol/84532/run-1721245022.json

Large diffs are not rendered by default.

914 changes: 57 additions & 857 deletions broadcast/Upgrade.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions deployments/base-mocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"chainId": "8453",
"commit": "bb8eb5d",
"deployments": {
"PriceFeed": "0x2e9Ab61c2AeCfcB9519F884FE93d7e395BE3CB47",
"Size-implementation": "0xd04193B1EBd88E9A84572E232e9f25973930A446",
"Size-proxy": "0x0D6a734011103A249C3c1727BD209B382d803cb3"
},
"networkConfiguration": "base-mocks",
"parameters": {
"feeRecipient": "0x38199bdd622237cbe8e0f85edf597ec2790c4a78",
"owner": "0x38199bdd622237cbe8e0f85edf597ec2790c4a78",
"sequencerUptimeFeed": "0x0000000000000000000000000000000000000000",
"usdc": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"usdcAggregator": "0x0000000000000000000000000000000000000000",
"usdcHeartbeat": "0",
"variablePool": "0xfe28e26d5027a28ed95b0836cd796846b4ef2312",
"weth": "0x4200000000000000000000000000000000000006",
"wethAggregator": "0x0000000000000000000000000000000000000000",
"wethHeartbeat": "0"
}
}
4 changes: 2 additions & 2 deletions deployments/8453.json → deployments/base-production.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commit": "echo -n 'commit-' && git rev-parse HEAD",
"commit": "d1ed03741036715cb5a0d5bac31e7e621ac82674",
"deployments": {
"PriceFeed": "0xd6938E55cc5f4B553948Cc153d360E8a8FA0de72",
"Size-implementation": "0xCd6CA4ac60C932937EE209aB8B7Af2941708724A",
"Size-proxy": "0xC2a429681CAd7C1ce36442fbf7A4a68B11eFF940"
},
"networkName": "base",
"chainId": "8453",
"parameters": {
"feeRecipient": "0x12328ea44ab6d7b18aa9cc030714763734b625db",
"owner": "0x462b545e8bbb6f9e5860928748bfe9ecc712c3a7",
Expand Down
15 changes: 8 additions & 7 deletions deployments/84532.json → deployments/base-sepolia.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"commit": "e92524b67942d5df4ff4d7157a2bb9ab414e0241",
"chainId": "84532",
"commit": "af254f5",
"deployments": {
"PriceFeed": "0x97B848F22Eed0278a32b1F471aAe2EcfD87038Ec",
"Size-implementation": "0xFB0b2996061d2b297c21BF8e5f324Ce013Ea8C19",
"Size-proxy": "0xc2C923bBfD83d3B3a8888F80a9Aab193eE5449b6"
"PriceFeed": "0x56A5CD8bADd94E5d46e3cc028393Bdb4A91b66eD",
"Size-implementation": "0xb2b90c9E5A9C95fe2d1014785F18ed7216Ab5936",
"Size-proxy": "0x3AE40a5126b3E37dfcB172bbF485b1E2A6DBD882"
},
"networkName": "base-sepolia",
"networkConfiguration": "base-sepolia",
"parameters": {
"feeRecipient": "0xf7164d2fc05350c75387fa6c0cc4f97634ca9451",
"owner": "0xf7164d2fc05350c75387fa6c0cc4f97634ca9451",
"sequencerUptimeFeed": "0x0000000000000000000000000000000000000000",
"usdc": "0x036cbd53842c5426634e7929541ec2318f3dcf7e",
"usdcAggregator": "0xd30e2101a97dcbaebcbc04f14c3f624e67a35165",
"usdcHeartbeat": 95040,
"usdcHeartbeat": "95040",
"variablePool": "0x07ea79f68b2b3df564d0a34f8e19d9b1e339814b",
"weth": "0x4200000000000000000000000000000000000006",
"wethAggregator": "0x4adc67696ba383f43dd60a9e78f2c97fbbfc7cb1",
"wethHeartbeat": 1320
"wethHeartbeat": "1320"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Size-implementation": "0x6D4F2F365f0a091103809890E43D77dC908Fd260",
"Size-proxy": "0x12FE37B7730a55153E6da7b6c0E5aC93450BA231"
},
"networkName": "sepolia-mocks",
"chainId": "11155111",
"parameters": {
"feeRecipient": "0xf0c7f57f5f889d546f032e50fba953bd7c026350",
"owner": "0xf0c7f57f5f889d546f032e50fba953bd7c026350",
Expand Down
18 changes: 8 additions & 10 deletions script/BaseScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract contract BaseScript is Script {
error InvalidPrivateKey(string privateKey);

string constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
string constant TEST_CHAIN_NAME = "anvil";
string constant TEST_NETWORK_CONFIGURATION = "anvil";

string root;
string path;
Expand All @@ -41,12 +41,11 @@ abstract contract BaseScript is Script {
vm.stopBroadcast();
}

function exportDeployments(string memory networkName) internal {
function exportDeployments(string memory networkConfiguration) internal {
// fetch already existing contracts
root = vm.projectRoot();
path = string.concat(root, "/deployments/");
string memory chainIdStr = vm.toString(block.chainid);
path = string.concat(path, string.concat(chainIdStr, ".json"));
path = string.concat(path, string.concat(networkConfiguration, ".json"));

string memory finalObject;
string memory deploymentsObject;
Expand All @@ -60,22 +59,21 @@ abstract contract BaseScript is Script {
finalObject = vm.serializeString(".", "deployments", deploymentsObject);
finalObject = vm.serializeString(".", "parameters", parametersObject);

finalObject = vm.serializeString(".", "networkName", networkName);
finalObject = vm.serializeString(".", "networkConfiguration", networkConfiguration);

string memory commit = getCommitHash();
finalObject = vm.serializeString(".", "commit", commit);
finalObject = vm.serializeString(".", "commit", getCommitHash());
finalObject = vm.serializeString(".", "chainId", vm.toString(block.chainid));

vm.writeJson(finalObject, path);
}

function importDeployments()
function importDeployments(string memory networkConfiguration)
internal
returns (ISize size, IPriceFeed priceFeed, IPool variablePool, USDC usdc, WETH weth, address owner)
{
root = vm.projectRoot();
path = string.concat(root, "/deployments/");
string memory chainIdStr = vm.toString(block.chainid);
path = string.concat(path, string.concat(chainIdStr, ".json"));
path = string.concat(path, string.concat(networkConfiguration, ".json"));

string memory json = vm.readFile(path);

Expand Down
36 changes: 17 additions & 19 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Size} from "@src/Size.sol";

import {BaseScript, Deployment, Parameter} from "@script/BaseScript.sol";
import {Deploy} from "@script/Deploy.sol";
import {NetworkParams, Networks} from "@script/Networks.sol";
import {NetworkConfiguration, Networks} from "@script/Networks.sol";

contract DeployScript is BaseScript, Networks, Deploy {
bool mockContracts;
Expand All @@ -17,44 +17,42 @@ contract DeployScript is BaseScript, Networks, Deploy {
address feeRecipient;
address wethAggregator;
address usdcAggregator;
string chainName;
string networkConfiguration;

function setUp() public {}

modifier parseEnv() {
deployer = vm.envOr("DEPLOYER_ADDRESS", vm.addr(vm.deriveKey(TEST_MNEMONIC, 0)));
owner = vm.envOr("OWNER", address(0));
feeRecipient = vm.envOr("FEE_RECIPIENT", address(0));
chainName = vm.envOr("CHAIN_NAME", TEST_CHAIN_NAME);
networkConfiguration = vm.envOr("NETWORK_CONFIGURATION", TEST_NETWORK_CONFIGURATION);
_;
}

function run() public parseEnv broadcast returns (Deployment[] memory, Parameter[] memory) {
console.log("[Size v1] deploying...");

console.log("[Size v1] chain: ", chainName);
console.log("[Size v1] deployer: ", deployer);
console.log("[Size v1] owner: ", owner);
console.log("[Size v1] feeRecipient:", feeRecipient);
console.log("[Size v1] networkConfiguration", networkConfiguration);
console.log("[Size v1] deployer", deployer);
console.log("[Size v1] owner", owner);
console.log("[Size v1] feeRecipient", feeRecipient);

NetworkParams memory networkParams = params(chainName);
NetworkConfiguration memory params = params(networkConfiguration);

setupProduction(owner, feeRecipient, networkParams);
setupProduction(owner, feeRecipient, params);

deployments.push(Deployment({name: "Size-implementation", addr: address(implementation)}));
deployments.push(Deployment({name: "Size-proxy", addr: address(proxy)}));
deployments.push(Deployment({name: "PriceFeed", addr: address(priceFeed)}));
parameters.push(Parameter({key: "owner", value: Strings.toHexString(owner)}));
parameters.push(Parameter({key: "feeRecipient", value: Strings.toHexString(feeRecipient)}));
parameters.push(Parameter({key: "usdc", value: Strings.toHexString(address(networkParams.usdc))}));
parameters.push(Parameter({key: "weth", value: Strings.toHexString(address(networkParams.weth))}));
parameters.push(Parameter({key: "wethAggregator", value: Strings.toHexString(networkParams.wethAggregator)}));
parameters.push(Parameter({key: "usdcAggregator", value: Strings.toHexString(networkParams.usdcAggregator)}));
parameters.push(Parameter({key: "wethHeartbeat", value: Strings.toString(networkParams.wethHeartbeat)}));
parameters.push(Parameter({key: "usdcHeartbeat", value: Strings.toString(networkParams.usdcHeartbeat)}));
parameters.push(
Parameter({key: "sequencerUptimeFeed", value: Strings.toHexString(networkParams.sequencerUptimeFeed)})
);
parameters.push(Parameter({key: "usdc", value: Strings.toHexString(address(params.usdc))}));
parameters.push(Parameter({key: "weth", value: Strings.toHexString(address(params.weth))}));
parameters.push(Parameter({key: "wethAggregator", value: Strings.toHexString(params.wethAggregator)}));
parameters.push(Parameter({key: "usdcAggregator", value: Strings.toHexString(params.usdcAggregator)}));
parameters.push(Parameter({key: "wethHeartbeat", value: Strings.toString(params.wethHeartbeat)}));
parameters.push(Parameter({key: "usdcHeartbeat", value: Strings.toString(params.usdcHeartbeat)}));
parameters.push(Parameter({key: "sequencerUptimeFeed", value: Strings.toHexString(params.sequencerUptimeFeed)}));
parameters.push(Parameter({key: "variablePool", value: Strings.toHexString(address(variablePool))}));

console.log("[Size v1] deployed\n");
Expand All @@ -66,7 +64,7 @@ contract DeployScript is BaseScript, Networks, Deploy {
console.log("[Size v1] Parameter: ", parameters[i].key, "\t", parameters[i].value);
}

exportDeployments(chainName);
exportDeployments(networkConfiguration);

console.log("[Size v1] done");

Expand Down
6 changes: 4 additions & 2 deletions script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {PriceFeedMock} from "@test/mocks/PriceFeedMock.sol";

import {Size} from "@src/Size.sol";

import {NetworkParams} from "@script/Networks.sol";
import {NetworkConfiguration} from "@script/Networks.sol";
import {
Initialize,
InitializeDataParams,
Expand Down Expand Up @@ -78,7 +78,9 @@ abstract contract Deploy {
PriceFeedMock(address(priceFeed)).setPrice(1337e18);
}

function setupProduction(address _owner, address _feeRecipient, NetworkParams memory _networkParams) internal {
function setupProduction(address _owner, address _feeRecipient, NetworkConfiguration memory _networkParams)
internal
{
variablePool = IPool(_networkParams.variablePool);

if (_networkParams.wethAggregator == address(0) && _networkParams.usdcAggregator == address(0)) {
Expand Down
29 changes: 20 additions & 9 deletions script/Networks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.23;

import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

struct NetworkParams {
struct NetworkConfiguration {
address weth;
address usdc;
address variablePool;
Expand All @@ -17,9 +17,9 @@ struct NetworkParams {
abstract contract Networks {
error InvalidChain(string chain);

function params(string memory chain) public pure returns (NetworkParams memory) {
function params(string memory chain) public pure returns (NetworkConfiguration memory) {
if (Strings.equal(chain, "sepolia")) {
return NetworkParams({
return NetworkConfiguration({
weth: 0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14,
usdc: 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8,
variablePool: 0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951,
Expand All @@ -30,7 +30,7 @@ abstract contract Networks {
usdcHeartbeat: type(uint256).max
});
} else if (Strings.equal(chain, "sepolia-mocks")) {
return NetworkParams({
return NetworkConfiguration({
weth: 0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14,
usdc: 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8,
variablePool: address(0),
Expand All @@ -41,7 +41,7 @@ abstract contract Networks {
usdcHeartbeat: 0
});
} else if (Strings.equal(chain, "base-sepolia")) {
return NetworkParams({
return NetworkConfiguration({
weth: 0x4200000000000000000000000000000000000006,
usdc: 0x036CbD53842c5426634e7929541eC2318f3dCF7e,
variablePool: 0x07eA79F68B2B3df564D0A34F8e19D9B1e339814b,
Expand All @@ -51,8 +51,8 @@ abstract contract Networks {
wethHeartbeat: 1200 * 1.1e18 / 1e18,
usdcHeartbeat: 86400 * 1.1e18 / 1e18
});
} else if (Strings.equal(chain, "mainnet")) {
return NetworkParams({
} else if (Strings.equal(chain, "mainnet-production")) {
return NetworkConfiguration({
weth: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
usdc: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
variablePool: 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2,
Expand All @@ -62,8 +62,8 @@ abstract contract Networks {
wethHeartbeat: 3600 * 1.1e18 / 1e18,
usdcHeartbeat: 86400 * 1.1e18 / 1e18
});
} else if (Strings.equal(chain, "base")) {
return NetworkParams({
} else if (Strings.equal(chain, "base-production")) {
return NetworkConfiguration({
weth: 0x4200000000000000000000000000000000000006,
usdc: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
variablePool: 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5,
Expand All @@ -73,6 +73,17 @@ abstract contract Networks {
wethHeartbeat: 1200 * 1.1e18 / 1e18,
usdcHeartbeat: 86400 * 1.1e18 / 1e18
});
} else if (Strings.equal(chain, "base-mocks")) {
return NetworkConfiguration({
weth: 0x4200000000000000000000000000000000000006,
usdc: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
variablePool: address(0),
wethAggregator: address(0),
usdcAggregator: address(0),
sequencerUptimeFeed: address(0),
wethHeartbeat: 0,
usdcHeartbeat: 0
});
} else {
revert InvalidChain(chain);
}
Expand Down
2 changes: 1 addition & 1 deletion script/PoolMock.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {console2 as console} from "forge-std/console2.sol";
contract PoolMockScript is BaseTest, BaseScript {
function run() external broadcast {
console.log("PoolMock...");
(,, variablePool,, weth,) = importDeployments();
(,, variablePool,, weth,) = importDeployments("sepolia-mocks");

PoolMock(address(variablePool)).setLiquidityIndex(address(weth), WadRayMath.RAY);
}
Expand Down
Loading

0 comments on commit bb5b95a

Please sign in to comment.