From 208796730a80754b58a967380ca7b1d670bc404d Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 16 May 2024 00:57:32 +0900 Subject: [PATCH] feat: store addresses separately --- contracts/v0.2/.gitignore | 2 ++ contracts/v0.2/script/Feed.s.sol | 9 ++++--- contracts/v0.2/script/FeedRouter.s.sol | 8 ++++-- contracts/v0.2/script/SubmissionProxy.s.sol | 16 +++++++++--- contracts/v0.2/script/Utils.s.sol | 28 +++++++++++++++++++++ 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/contracts/v0.2/.gitignore b/contracts/v0.2/.gitignore index 4abdeee9b..56cf63551 100644 --- a/contracts/v0.2/.gitignore +++ b/contracts/v0.2/.gitignore @@ -2,6 +2,8 @@ cache out deployments/*/31337 +addresses/localhost/* migration/local/*/migration.lock +migration/localhost/*/migration.lock typechain-types/ dist/ \ No newline at end of file diff --git a/contracts/v0.2/script/Feed.s.sol b/contracts/v0.2/script/Feed.s.sol index 10851e9f1..2f5835758 100644 --- a/contracts/v0.2/script/Feed.s.sol +++ b/contracts/v0.2/script/Feed.s.sol @@ -12,12 +12,13 @@ contract DeployFeed is Script { using stdJson for string; using strings for *; uint8 constant DECIMALS = 8; + UtilsScript config; - - function setUp() public {} + function setUp() public { + config = new UtilsScript(); + } function run() public { - UtilsScript config = new UtilsScript(); string memory dirPath = string.concat("/migration/", config.chainName(), "/Feed"); string[] memory migrationFiles = config.loadMigration(dirPath); @@ -56,6 +57,8 @@ contract DeployFeed is Script { console.log("(Feed Deployed)", feedNames[j], address(feed)); FeedProxy feedProxy = new FeedProxy(address(feed)); console.log("(FeedProxy Deployed)", feedNames[j], address(feedProxy)); + + config.storeFeedAddress(feedNames[j], address(feed), address(feedProxy)); } } diff --git a/contracts/v0.2/script/FeedRouter.s.sol b/contracts/v0.2/script/FeedRouter.s.sol index eb602a16b..7937eb7b2 100644 --- a/contracts/v0.2/script/FeedRouter.s.sol +++ b/contracts/v0.2/script/FeedRouter.s.sol @@ -10,10 +10,13 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; contract DeployFeedRouter is Script { using stdJson for string; using strings for *; + UtilsScript config; - function setUp() public {} + function setUp() public { + config = new UtilsScript(); + } function run() public { - UtilsScript config = new UtilsScript(); + string memory dirPath = string.concat("/migration/", config.chainName(), "/FeedRouter"); string[] memory migrationFiles = config.loadMigration(dirPath); @@ -59,6 +62,7 @@ contract DeployFeedRouter is Script { if (deploy) { console.log("Deploying FeedRouter"); feedRouter = new FeedRouter(); + config.storeAddress("FeedRouter", address(feedRouter)); console.log("(FeedRouter Deployed)", address(feedRouter)); }else if (useExisting) { bytes memory feedRouterAddressRaw = json.parseRaw(".address"); diff --git a/contracts/v0.2/script/SubmissionProxy.s.sol b/contracts/v0.2/script/SubmissionProxy.s.sol index 1f269db02..68f1c157c 100644 --- a/contracts/v0.2/script/SubmissionProxy.s.sol +++ b/contracts/v0.2/script/SubmissionProxy.s.sol @@ -13,12 +13,15 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; contract DeploySubmissionProxy is Script { using stdJson for string; using strings for *; - uint8 constant DECIMALS = 8; - function setUp() public {} + uint8 constant DECIMALS = 8; + UtilsScript config; + function setUp() public { + config = new UtilsScript(); + } function run() public { - UtilsScript config = new UtilsScript(); + string memory dirPath = string.concat("/migration/", config.chainName(), "/SubmissionProxy"); string[] memory migrationFiles = config.loadMigration(dirPath); @@ -44,6 +47,7 @@ contract DeploySubmissionProxy is Script { if (deploy) { submissionProxy = deploySubmissionProxy(); + config.storeAddress("SubmissionProxy", address(submissionProxy)); } else if (useExisting) { submissionProxy = useExistingSubmissionProxy(json); } else { @@ -205,9 +209,12 @@ contract DeploySubmissionProxy is Script { Feed feed = new Feed(DECIMALS, feedNames[j], address(submissionProxy)); console.log("(Feed Deployed)", feedNames[j], address(feed)); FeedProxy feedProxy = new FeedProxy(address(feed)); - proxyAddresses[j] = address(feedProxy); console.log("(FeedProxy Deployed)", feedNames[j], address(feedProxy)); + + config.storeFeedAddress(feedNames[j], address(feed), address(feedProxy)); + feedHashes[j] = string2bytes32Hash(feedNames[j]); + proxyAddresses[j] = address(feedProxy); feedAddresses[j] = address(feed); console.log("(Feed Prepared for updateFeed)", feedNames[j], address(feed)); } @@ -220,6 +227,7 @@ contract DeploySubmissionProxy is Script { FeedRouter feedRouter = new FeedRouter(); console.log("(FeedRouter Deployed)", address(feedRouter)); + config.storeAddress("FeedRouter", address(feedRouter)); feedRouter.updateProxyBulk(feedNames, proxyAddresses); console.log("(Proxies Updated)"); } diff --git a/contracts/v0.2/script/Utils.s.sol b/contracts/v0.2/script/Utils.s.sol index bfcdf6649..531b0221b 100644 --- a/contracts/v0.2/script/Utils.s.sol +++ b/contracts/v0.2/script/Utils.s.sol @@ -3,8 +3,11 @@ pragma solidity ^0.8.20; import {Script, stdJson, VmSafe, console} from "forge-std/Script.sol"; import {strings} from "solidity-stringutils/strings.sol"; +import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; contract UtilsScript is Script { + using Strings for uint256; + using Strings for address; using stdJson for string; using strings for *; @@ -121,6 +124,31 @@ contract UtilsScript is Script { vm.writeLine(path, parts[parts.length - 1]); } + function storeAddress(string memory contractName, address _address) public { + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/addresses/", chainName()); + if(!vm.isDir(path)) { + vm.createDir(path, true); + } + + string memory filePath = string.concat(path, "/", string.concat(contractName, ".json")); + string memory json = string.concat("{ \"address\": \"", _address.toHexString(), "\" }"); + + vm.writeJson(json, filePath); + } + + function storeFeedAddress(string memory feedName, address feedAddress, address feedProxyAddress) public { + string memory feedContractName = string.concat("Feed_", feedName, "_", timestampString()); + string memory feedProxyContractName = string.concat("FeedProxy_", feedName, "_", timestampString()); + + storeAddress(feedContractName, feedAddress); + storeAddress(feedProxyContractName, feedProxyAddress); + } + + function timestampString() public returns (string memory) { + return (vm.unixTime() / 1000).toString(); + } + function readJson(string memory filePath, string memory key) public view returns (bytes memory) { string memory json = vm.readFile(filePath); return json.parseRaw(key);