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

feat: add deployment json #48

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cache_path = "cache"
optimizer = true
optimizer_runs = 1_000
block_gas_limit = 30_000_000
fs_permissions = [{ access = "write", path = "./out" }]

[fmt]
line_length = 80
Expand Down
10 changes: 10 additions & 0 deletions script/DeployBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { CSFeeOracle } from "../src/CSFeeOracle.sol";

import { ILidoLocator } from "../src/interfaces/ILidoLocator.sol";

import { JsonObj, Json } from "./utils/Json.sol";

abstract contract DeployBase is Script {
// TODO: some contracts of the module probably should be deployed behind a proxy
uint256 immutable CHAIN_ID;
Expand Down Expand Up @@ -127,6 +129,14 @@ abstract contract DeployBase is Script {
consensusVersion: 1,
lastProcessingRefSlot: _refSlotFromEpoch(INITIALIZATION_EPOCH)
});

JsonObj memory deployJson = Json.newObj();
deployJson.set("CSModule", address(csm));
deployJson.set("CSAccounting", address(accounting));
deployJson.set("CSFeeOracle", address(oracle));
deployJson.set("CSFeeDistributor", address(feeDistributor));
deployJson.set("HashConsensus", address(hashConsensus));
vm.writeJson(deployJson.str, "./out/deploy.json");
vgorkavenko marked this conversation as resolved.
Show resolved Hide resolved
}

vm.stopBroadcast();
Expand Down
41 changes: 41 additions & 0 deletions script/utils/Json.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;

import { Vm } from "forge-std/Vm.sol";

struct JsonObj {
string ref;
string str;
}

// @see https://github.com/nomoixyz/vulcan/blob/main/src/_internal/Json.sol
library Json {
Vm internal constant vm =
Vm(address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))));

function newObj() internal returns (JsonObj memory obj) {
obj.ref = string(abi.encodePacked(address(this), _incrementId()));
obj.str = "";
}

function set(
JsonObj memory obj,
string memory key,
address value
) internal {
obj.str = vm.serializeAddress(obj.ref, key, value);
}

function _incrementId() private returns (uint256 count) {
bytes32 slot = keccak256("json.id.counter");

assembly {
count := sload(slot)
sstore(slot, add(count, 1))
}
}
}

using Json for JsonObj global;
Loading