Skip to content

Commit

Permalink
chore: increased dispatch window
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikelle committed May 3, 2024
1 parent f1cbbed commit e418905
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 63 deletions.
113 changes: 89 additions & 24 deletions contracts/scripts/DeployScripts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ import "../contracts/BlockTracker.sol";

// Deploy scripts should inherit this contract if they deploy using create2 deterministic addrs.
contract Create2Deployer {
address constant _CREATE2_PROXY = 0x4e59b44847b379578588920cA78FbF26c0B4956C;
address constant _EXPECTED_DEPLOYER = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
address constant _CREATE2_PROXY =
0x4e59b44847b379578588920cA78FbF26c0B4956C;
address constant _EXPECTED_DEPLOYER =
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;

function _checkCreate2Deployed() internal view {
require(isContractDeployed(_CREATE2_PROXY), "Create2 proxy needs to be deployed. See https://github.com/primevprotocol/deterministic-deployment-proxy");
require(
isContractDeployed(_CREATE2_PROXY),
"Create2 proxy needs to be deployed. See https://github.com/primevprotocol/deterministic-deployment-proxy"
);
}

function _checkDeployer() internal view {
if (msg.sender != _EXPECTED_DEPLOYER) {
console.log("Warning: deployer is not expected address of 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266. Contracts addresses will not match documentation");
console.log(
"Warning: deployer is not expected address of 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266. Contracts addresses will not match documentation"
);
}
}

Expand All @@ -45,9 +52,11 @@ contract DeployScript is Script, Create2Deployer {

// Replace these with your contract's constructor parameters
uint256 minStake = 1 ether;
address feeRecipient = address(0x68bC10674b265f266b4b1F079Fa06eF4045c3ab9);
address feeRecipient = address(
0x68bC10674b265f266b4b1F079Fa06eF4045c3ab9
);
uint16 feePercent = 2;
uint64 commitmentDispatchWindow = 250;
uint64 commitmentDispatchWindow = 500;

uint256 blocksPerWindow = 10;
// Forge deploy with salt uses create2 proxy from https://github.com/primevprotocol/deterministic-deployment-proxy
Expand All @@ -56,26 +65,66 @@ contract DeployScript is Script, Create2Deployer {
BlockTracker blockTracker = new BlockTracker{salt: salt}(msg.sender);
console.log("BlockTracker deployed to:", address(blockTracker));

BidderRegistry bidderRegistry = new BidderRegistry{salt: salt}(minStake, feeRecipient, feePercent, msg.sender, address(blockTracker));
BidderRegistry bidderRegistry = new BidderRegistry{salt: salt}(
minStake,
feeRecipient,
feePercent,
msg.sender,
address(blockTracker)
);
console.log("BidderRegistry deployed to:", address(bidderRegistry));

ProviderRegistry providerRegistry = new ProviderRegistry{salt: salt}(minStake, feeRecipient, feePercent, msg.sender);
ProviderRegistry providerRegistry = new ProviderRegistry{salt: salt}(
minStake,
feeRecipient,
feePercent,
msg.sender
);
console.log("ProviderRegistry deployed to:", address(providerRegistry));

PreConfCommitmentStore preConfCommitmentStore = new PreConfCommitmentStore{salt: salt}(address(providerRegistry), address(bidderRegistry), feeRecipient, msg.sender, address(blockTracker), commitmentDispatchWindow);
console.log("PreConfCommitmentStore deployed to:", address(preConfCommitmentStore));
PreConfCommitmentStore preConfCommitmentStore = new PreConfCommitmentStore{
salt: salt
}(
address(providerRegistry),
address(bidderRegistry),
feeRecipient,
msg.sender,
address(blockTracker),
commitmentDispatchWindow
);
console.log(
"PreConfCommitmentStore deployed to:",
address(preConfCommitmentStore)
);

providerRegistry.setPreconfirmationsContract(address(preConfCommitmentStore));
console.log("ProviderRegistry updated with PreConfCommitmentStore address:", address(preConfCommitmentStore));
providerRegistry.setPreconfirmationsContract(
address(preConfCommitmentStore)
);
console.log(
"ProviderRegistry updated with PreConfCommitmentStore address:",
address(preConfCommitmentStore)
);

bidderRegistry.setPreconfirmationsContract(address(preConfCommitmentStore));
console.log("BidderRegistry updated with PreConfCommitmentStore address:", address(preConfCommitmentStore));
bidderRegistry.setPreconfirmationsContract(
address(preConfCommitmentStore)
);
console.log(
"BidderRegistry updated with PreConfCommitmentStore address:",
address(preConfCommitmentStore)
);

Oracle oracle = new Oracle{salt: salt}(address(preConfCommitmentStore), address(blockTracker), msg.sender);
Oracle oracle = new Oracle{salt: salt}(
address(preConfCommitmentStore),
address(blockTracker),
msg.sender
);
console.log("Oracle deployed to:", address(oracle));

preConfCommitmentStore.updateOracle(address(oracle));
console.log("PreConfCommitmentStore updated with Oracle address:", address(oracle));
console.log(
"PreConfCommitmentStore updated with Oracle address:",
address(oracle)
);

vm.stopBroadcast();
}
Expand All @@ -84,12 +133,16 @@ contract DeployScript is Script, Create2Deployer {
// Deploys whitelist contract and adds HypERC20 to whitelist
contract DeployWhitelist is Script, Create2Deployer {
function run() external {

console.log("Warning: DeployWhitelist is deprecated and only for backwards compatibility with hyperlane");
console.log(
"Warning: DeployWhitelist is deprecated and only for backwards compatibility with hyperlane"
);

address expectedWhiteListAddr = 0x57508f0B0f3426758F1f3D63ad4935a7c9383620;
if (isContractDeployed(expectedWhiteListAddr)) {
console.log("Whitelist already deployed to:", expectedWhiteListAddr);
console.log(
"Whitelist already deployed to:",
expectedWhiteListAddr
);
return;
}

Expand All @@ -99,7 +152,10 @@ contract DeployWhitelist is Script, Create2Deployer {
_checkDeployer();

address hypERC20Addr = vm.envAddress("HYP_ERC20_ADDR");
require(hypERC20Addr != address(0), "Address to whitelist not provided");
require(
hypERC20Addr != address(0),
"Address to whitelist not provided"
);

// Forge deploy with salt uses create2 proxy from https://github.com/primevprotocol/deterministic-deployment-proxy
bytes32 salt = 0x8989000000000000000000000000000000000000000000000000000000000000;
Expand All @@ -108,7 +164,10 @@ contract DeployWhitelist is Script, Create2Deployer {
console.log("Whitelist deployed to:", address(whitelist));

whitelist.addToWhitelist(address(hypERC20Addr));
console.log("Whitelist updated with hypERC20 address:", address(hypERC20Addr));
console.log(
"Whitelist updated with hypERC20 address:",
address(hypERC20Addr)
);

vm.stopBroadcast();
}
Expand All @@ -119,16 +178,22 @@ contract DeployValidatorRegistry is Script {
function run() external {
vm.startBroadcast();

// 7000 blocks @ 200ms per block = 23.3 min. This allows two L1 epochs (finalization time) + settlement buffer,
// 7000 blocks @ 200ms per block = 23.3 min. This allows two L1 epochs (finalization time) + settlement buffer,
// to pass between validator unstake initiation and withdrawal.
uint256 unstakePeriodBlocks = 7000;

// Can later be upgraded with https://docs.openzeppelin.com/upgrades-plugins/1.x/api-foundry-upgrades#Upgrades-upgradeProxy-address-string-bytes-
address proxy = Upgrades.deployUUPSProxy(
"ValidatorRegistry.sol",
abi.encodeCall(ValidatorRegistry.initialize, (3 ether, unstakePeriodBlocks, msg.sender))
abi.encodeCall(
ValidatorRegistry.initialize,
(3 ether, unstakePeriodBlocks, msg.sender)
)
);
console.log(
"ValidatorRegistry UUPS proxy deployed to:",
address(proxy)
);
console.log("ValidatorRegistry UUPS proxy deployed to:", address(proxy));

ValidatorRegistry validatorRegistry = ValidatorRegistry(proxy);
console.log("ValidatorRegistry owner:", validatorRegistry.owner());
Expand Down
39 changes: 0 additions & 39 deletions contracts/test/PreConfirmationConfTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,45 +135,6 @@ contract TestPreConfCommitmentStore is Test {


function test_StoreCommitmentFailureDueToTimestampValidation() public {
// bytes32 bidHash = preConfCommitmentStore.getBidHash(
// _testCommitmentAliceBob.txnHash,
// _testCommitmentAliceBob.bid,
// _testCommitmentAliceBob.blockNumber,
// _testCommitmentAliceBob.decayStartTimestamp,
// _testCommitmentAliceBob.decayEndTimestamp
// );
// (address bidder, uint256 bidderPk) = makeAddrAndKey("alice");
// // Wallet memory kartik = vm.createWallet('test wallet');
// (uint8 v,bytes32 r, bytes32 s) = vm.sign(bidderPk, bidHash);
// bytes memory signature = abi.encodePacked(r, s, v);

// vm.deal(bidder, 200000 ether);
// vm.prank(bidder);
// bidderRegistry.depositForSpecificWindow{value: 2 ether}(2);

// (bytes32 digest, address recoveredAddress) = preConfCommitmentStore.verifyBid(
// _testCommitmentAliceBob.bid,
// _testCommitmentAliceBob.blockNumber,
// _testCommitmentAliceBob.decayStartTimestamp,
// _testCommitmentAliceBob.decayEndTimestamp,
// _testCommitmentAliceBob.txnHash,
// signature);

// assertEq(bidder, recoveredAddress);
// assertEq(digest, bidHash);
// vm.warp(1000);
// vm.expectRevert("Invalid dispatch timestamp, block.timestamp - dispatchTimestamp < commitment_dispatch_window");
// preConfCommitmentStore.storeCommitment(
// _testCommitmentAliceBob.bid,
// _testCommitmentAliceBob.blockNumber,
// _testCommitmentAliceBob.txnHash,
// _testCommitmentAliceBob.decayStartTimestamp,
// _testCommitmentAliceBob.decayEndTimestamp,
// signature,
// _testCommitmentAliceBob.commitmentSignature,
// _testCommitmentAliceBob.dispatchTimestamp
// );
// Step 1: Prepare the commitment information and signature
bytes32 commitmentDigest = keccak256(
abi.encodePacked("commitment data")
);
Expand Down

0 comments on commit e418905

Please sign in to comment.