Skip to content

Commit

Permalink
feat: store addresses separately
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed May 15, 2024
1 parent 724ac44 commit 2087967
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
2 changes: 2 additions & 0 deletions contracts/v0.2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
cache
out
deployments/*/31337
addresses/localhost/*
migration/local/*/migration.lock
migration/localhost/*/migration.lock
typechain-types/
dist/
9 changes: 6 additions & 3 deletions contracts/v0.2/script/Feed.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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));
}
}

Expand Down
8 changes: 6 additions & 2 deletions contracts/v0.2/script/FeedRouter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down
16 changes: 12 additions & 4 deletions contracts/v0.2/script/SubmissionProxy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -44,6 +47,7 @@ contract DeploySubmissionProxy is Script {

if (deploy) {
submissionProxy = deploySubmissionProxy();
config.storeAddress("SubmissionProxy", address(submissionProxy));
} else if (useExisting) {
submissionProxy = useExistingSubmissionProxy(json);
} else {
Expand Down Expand Up @@ -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));
}
Expand All @@ -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)");
}
Expand Down
28 changes: 28 additions & 0 deletions contracts/v0.2/script/Utils.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 *;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2087967

Please sign in to comment.