Skip to content

Commit

Permalink
feat: use merkle distributor with deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 committed Sep 20, 2024
1 parent 465c254 commit f6c7571
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
1 change: 0 additions & 1 deletion data/test.root.json

This file was deleted.

1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fs_permissions = [
{ access = "read", path = "./out" },
{ access = "read", path = "./data" },
{ access = "read", path = "./script/upgrades/dependencies.json" },
{ access = "read", path = "./script/upgrades/MINIDROP/data/" },
]
via_ir = true

Expand Down
1 change: 1 addition & 0 deletions lib/merkle-distributor
Submodule merkle-distributor added at 25a79e
4 changes: 4 additions & 0 deletions script/upgrades/MINIDROP/data/alfajores.root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cUSDRoot": "0x92dfd30b2fb698891a63455cdc438dfc30e43c43251f642f39225ada6227c09d",
"mentoRoot": "0x92dfd30b2fb698891a63455cdc438dfc30e43c43251f642f39225ada6227c09e"
}
4 changes: 4 additions & 0 deletions script/upgrades/MINIDROP/data/celo.root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cUSDRoot": "0x92dfd30b2fb698891a63455cdc438dfc30e43c43251f642f39225ada6227c09e",
"mentoRoot": "0x92dfd30b2fb698891a63455cdc438dfc30e43c43251f642f39225ada6227c09e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,56 @@ contract MINIDROP_CreateMerkleDistributor is Script {
IRegistry registry = IRegistry(0x000000000000000000000000000000000000ce10);
address cUSD = registry.getAddressForStringOrDie("StableToken");
address MENTO = IGovernanceFactory(contracts.deployed("GovernanceFactory")).mentoToken();
bytes32 merkleRootCUSD = readMerkleRoot();
bytes32 merkleRootMENTO = readMerkleRoot();

// 91 days after the current block timestamp roughly 3 months
uint256 endTime = block.timestamp + 91 days;

bytes32 merkleRootCUSD = readMerkleRoot(".cUSDRoot");
bytes32 merkleRootMENTO = readMerkleRoot(".mentoRoot");

address cUSDDistributor;
address mentoDistributor;

vm.startBroadcast(vm.envUint("MENTO_DEPLOYER_PK"));

{
cUSDDistributor = deployMerkleDistributor("MerkleDistributor.sol", cUSD, merkleRootCUSD);
cUSDDistributor = deployMerkleDistributor(
"out/MerkleDistributorWithDeadline.sol/MerkleDistributorWithDeadline.json",
cUSD,
merkleRootCUSD,
endTime
);
console.log("MerkleDistributor for cUSD deployed at:", cUSDDistributor);
mentoDistributor = deployMerkleDistributor("MerkleDistributor.sol", MENTO, merkleRootMENTO);
mentoDistributor = deployMerkleDistributor(
"out/MerkleDistributorWithDeadline.sol/MerkleDistributorWithDeadline.json",
MENTO,
merkleRootMENTO,
endTime
);
console.log("MerkleDistributor for MENTO deployed at:", mentoDistributor);
}

vm.stopBroadcast();
}

function deployMerkleDistributor(string memory path, address token, bytes32 merkleRoot) private returns (address) {
bytes memory bytecode = abi.encodePacked(vm.getCode(path), abi.encode(token, merkleRoot));
function deployMerkleDistributor(
string memory path,
address token,
bytes32 merkleRoot,
uint256 endTime
) private returns (address) {
bytes memory bytecode = abi.encodePacked(vm.getCode(path), abi.encode(token, merkleRoot, endTime));
address deployedAddress;
assembly {
deployedAddress := create(0, add(bytecode, 0x20), mload(bytecode))
}
return deployedAddress;
}

function readMerkleRoot() internal view returns (bytes32) {
function readMerkleRoot(string memory token) internal view returns (bytes32) {
string memory network = ChainLib.rpcToken(); // celo | alfajores
string memory root = vm.projectRoot();
string memory path = string(abi.encodePacked(root, "/data/test.root.json"));
string memory path = string(abi.encodePacked(root, "/script/upgrades/MINIDROP/data/", network, ".root.json"));
string memory json = vm.readFile(path);
return stdJson.readBytes32(json, ".root");
return stdJson.readBytes32(json, token);
}
}
2 changes: 1 addition & 1 deletion script/upgrades/MINIDROP/deploy/import.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pragma solidity 0.8.17;
// File needed to compile 0.8.17 contract from merkle-distributor without causing
// problems with different solidity versions.

import { MerkleDistributor } from "merkle-distributor/MerkleDistributor.sol";
import { MerkleDistributorWithDeadline } from "merkle-distributor/MerkleDistributorWithDeadline.sol";

0 comments on commit f6c7571

Please sign in to comment.