Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {Script} from "forge-std-1.16.1/src/Script.sol";
import {DiaWords} from "../src/concrete/DiaWords.sol";
import {IMetaBoardV1_2} from "rain-metadata-0.1.0/src/interface/unstable/IMetaBoardV1_2.sol";
import {LibDescribedByMeta} from "rain-metadata-0.1.0/src/lib/LibDescribedByMeta.sol";
import {LibRainDeploy} from "rain-deploy-0.1.2/src/lib/LibRainDeploy.sol";
import {LibDiaWordsDeploy} from "../src/lib/deploy/LibDiaWordsDeploy.sol";

/// @dev Deterministic MetaBoard address deployed via Zoltu factory.
/// https://github.com/rainlanguage/rain.metadata
Expand All @@ -18,7 +20,18 @@ contract Deploy is Script {
IMetaBoardV1_2 metaboard = IMetaBoardV1_2(METABOARD_ADDRESS);

vm.startBroadcast(deployerPrivateKey);
DiaWords subParser = new DiaWords();

address deployed = LibRainDeploy.deployZoltu(type(DiaWords).creationCode);
if (deployed != LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_ADDRESS) {
revert LibRainDeploy.UnexpectedDeployedAddress(LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_ADDRESS, deployed);
}
if (deployed.codehash != LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_CODEHASH) {
revert LibRainDeploy.UnexpectedDeployedCodeHash(
LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_CODEHASH, deployed.codehash
);
}

DiaWords subParser = DiaWords(deployed);
LibDescribedByMeta.emitForDescribedAddress(metaboard, subParser, subParserDescribedByMeta);

vm.stopBroadcast();
Expand Down
23 changes: 23 additions & 0 deletions src/lib/deploy/LibDiaWordsDeploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

import {LibRainDeploy} from "rain-deploy-0.1.2/src/lib/LibRainDeploy.sol";

/// @title LibDiaWordsDeploy
/// @notice Deterministic DiaWords deployment record for Zoltu CREATE2 deploys.
library LibDiaWordsDeploy {
/// @dev Zoltu-derived deployment address for the current DiaWords creation code.
address constant DIA_WORDS_DEPLOYED_ADDRESS = 0x64288bBA6FC86506f0aF001545eBCF23544B8389;

/// @dev Runtime codehash for `DIA_WORDS_DEPLOYED_ADDRESS`.
bytes32 constant DIA_WORDS_DEPLOYED_CODEHASH = 0xf0b030be8140c85d41825a53dfc0c27ba42cf4959e34b8322963d191fb36b493;

/// @notice Predicts the Zoltu CREATE2 address for the given creation code.
function zoltuAddress(bytes memory initCode) internal pure returns (address predicted) {
bytes32 initCodeHash = keccak256(initCode);
bytes32 digest =
keccak256(abi.encodePacked(bytes1(0xff), LibRainDeploy.ZOLTU_FACTORY, bytes32(0), initCodeHash));
predicted = address(uint160(uint256(digest)));
}
}
31 changes: 31 additions & 0 deletions test/src/lib/deploy/LibDiaWordsDeploy.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity =0.8.25;

import {Test} from "forge-std-1.16.1/src/Test.sol";
import {DiaWords} from "src/concrete/DiaWords.sol";
import {LibRainDeploy} from "rain-deploy-0.1.2/src/lib/LibRainDeploy.sol";
import {LibDiaWordsDeploy} from "src/lib/deploy/LibDiaWordsDeploy.sol";

contract LibDiaWordsDeployTest is Test {
function setUp() external {
LibRainDeploy.etchZoltuFactory(vm);
}

function testPinnedAddressMatchesZoltuDerivation() external pure {
assertEq(
LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_ADDRESS, LibDiaWordsDeploy.zoltuAddress(type(DiaWords).creationCode)
);
}

function testPinnedCodehashMatchesRuntimeBytecode() external {
LibRainDeploy.deployZoltu(type(DiaWords).creationCode);
assertEq(LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_ADDRESS.codehash, LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_CODEHASH);
}

function testZoltuDeployMatchesPinnedRecord() external {
address deployed = LibRainDeploy.deployZoltu(type(DiaWords).creationCode);
assertEq(deployed, LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_ADDRESS);
assertEq(deployed.codehash, LibDiaWordsDeploy.DIA_WORDS_DEPLOYED_CODEHASH);
}
}
Loading