Skip to content

Commit

Permalink
feat: update merklDeploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
nlecoufl committed Nov 20, 2024
1 parent 2336c92 commit 5f69c90
Showing 1 changed file with 71 additions and 25 deletions.
96 changes: 71 additions & 25 deletions deploy/foundry/merklDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import { BaseScript } from "../utils/Base.s.sol";
import { MockToken } from "../../contracts/mock/MockToken.sol";

// NOTE: Before running this script on a new chain, make sure to create the AngleLabs multisig and update the sdk with the new address
// Can be executed with (using zero address as default will fetch addresses from the sdk registry):
// forge script deploy/foundry/merklDeploy.s.sol \
// --rpc-url $RPC_URL \
// -vvvv
// Can be also be executed with (using zero address as default with addresses from the sdk registry):
// forge script deploy/foundry/merklDeploy.s.sol \
// --sig "run(address,address)" \
// "0x0000000000000000000000000000000000000000" "0x0000000000000000000000000000000000000000" \
// --rpc-url $RPC_URL \
// -vvvv
contract MainDeployScript is Script, BaseScript, JsonReader {
uint256 private DEPLOYER_PRIVATE_KEY;
uint256 private MERKL_DEPLOYER_PRIVATE_KEY;
Expand All @@ -37,23 +47,59 @@ contract MainDeployScript is Script, BaseScript, JsonReader {
address implementation;
}

// NOTE: This function is used to automatically set the ANGLE_LABS and DISPUTE_TOKEN addresses from the sdk registry
function run() external {
// Setup
DEPLOYER_PRIVATE_KEY = vm.envUint("DEPLOYER_PRIVATE_KEY");
MERKL_DEPLOYER_PRIVATE_KEY = vm.envUint("MERKL_DEPLOYER_PRIVATE_KEY");
console.log("Chain ID:", block.chainid);

try this.readAddress(block.chainid, "EUR.AgToken") returns (address eura) {
DISPUTE_TOKEN = eura;
} catch {
DISPUTE_TOKEN = address(0);
}

try this.readAddress(block.chainid, "AngleLabs") returns (address angleLabs) {
ANGLE_LABS = angleLabs;
try this.readAddress(block.chainid, "AngleLabs") returns (address _angleLabs) {
ANGLE_LABS = _angleLabs;
} catch {
ANGLE_LABS = GUARDIAN_ADDRESS;
}

_run(ANGLE_LABS, DISPUTE_TOKEN);
}

// NOTE: This function is used to manually set the ANGLE_LABS and DISPUTE_TOKEN addresses.
// If angleLabs or disputeToken are set to the zero address, the script will try to fetch the addresses from the sdk registry
function run(address angleLabs, address disputeToken) external {
// Setup
if (disputeToken != address(0)) {
DISPUTE_TOKEN = disputeToken;
} else {
try this.readAddress(block.chainid, "EUR.AgToken") returns (address eura) {
DISPUTE_TOKEN = eura;
} catch {
DISPUTE_TOKEN = address(0);
}
}

if (angleLabs != address(0)) {
ANGLE_LABS = angleLabs;
} else {
try this.readAddress(block.chainid, "AngleLabs") returns (address _angleLabs) {
ANGLE_LABS = _angleLabs;
} catch {
ANGLE_LABS = GUARDIAN_ADDRESS;
}
}

_run(ANGLE_LABS, DISPUTE_TOKEN);
}

function _run(address angleLabs, address disputeToken) internal {
ANGLE_LABS = angleLabs;
DISPUTE_TOKEN = disputeToken;

DEPLOYER_PRIVATE_KEY = vm.envUint("DEPLOYER_PRIVATE_KEY");
MERKL_DEPLOYER_PRIVATE_KEY = vm.envUint("MERKL_DEPLOYER_PRIVATE_KEY");

console.log("Chain ID:", block.chainid);
console.log("ANGLE_LABS:", ANGLE_LABS);

// Compute addresses from private keys
Expand All @@ -62,7 +108,7 @@ contract MainDeployScript is Script, BaseScript, JsonReader {
MERKL_DEPLOYER_ADDRESS = vm.addr(MERKL_DEPLOYER_PRIVATE_KEY);
console.log("DEPLOYER_ADDRESS:", DEPLOYER_ADDRESS);
console.log("MERKL_DEPLOYER_ADDRESS:", MERKL_DEPLOYER_ADDRESS);
console.log("DISPUTE TOKEN (EURA):", DISPUTE_TOKEN);
console.log("DISPUTE TOKEN:", DISPUTE_TOKEN);

// 1. Deploy using DEPLOYER_PRIVATE_KEY
vm.startBroadcast(DEPLOYER_PRIVATE_KEY);
Expand All @@ -86,7 +132,7 @@ contract MainDeployScript is Script, BaseScript, JsonReader {

vm.stopBroadcast();

// 3. Set params and deploy Disputer using DEPLOYER_PRIVATE_KEY
// 3. Set params and deploy Disputer using DEPLOYER_PRIVATE_KEY (make sure that the deployer is the GUARDIAN_ADDRESS)
vm.startBroadcast(DEPLOYER_PRIVATE_KEY);

// Set params and transfer ownership
Expand All @@ -103,11 +149,6 @@ contract MainDeployScript is Script, BaseScript, JsonReader {
CoreBorrow(coreBorrow.proxy).removeGovernor(DEPLOYER_ADDRESS);
}

console.log(CoreBorrow(coreBorrow.proxy).getRoleMemberCount(CoreBorrow(coreBorrow.proxy).GOVERNOR_ROLE()));
console.log(CoreBorrow(coreBorrow.proxy).getRoleMemberCount(CoreBorrow(coreBorrow.proxy).GUARDIAN_ROLE()));
console.log(CoreBorrow(coreBorrow.proxy).hasRole(CoreBorrow(coreBorrow.proxy).GOVERNOR_ROLE(), ANGLE_LABS));
console.log(CoreBorrow(coreBorrow.proxy).hasRole(CoreBorrow(coreBorrow.proxy).GUARDIAN_ROLE(), ANGLE_LABS));

vm.stopBroadcast();

// Print summary
Expand All @@ -130,7 +171,6 @@ contract MainDeployScript is Script, BaseScript, JsonReader {
console.log("AglaMerkl:");
console.log(" - Address:", aglaMerkl);
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DEPLOY FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -224,28 +264,31 @@ contract MainDeployScript is Script, BaseScript, JsonReader {
whitelist[2] = 0xF4c94b2FdC2efA4ad4b831f312E7eF74890705DA;

// Create initialization bytecode
bytes memory bytecode = abi.encodePacked(
type(Disputer).creationCode,
abi.encode(DEPLOYER_ADDRESS, whitelist, Distributor(distributor))
);
bytes
memory bytecode = hex"60806040523480156200001157600080fd5b506040516200137738038062001377833981016040819052620000349162000322565b6200003f33620001b3565b600180546001600160a01b0319166001600160a01b0383169081179091556040805163c748d26160e01b8152905163c748d261916004808201926020929091908290030181865afa15801562000099573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000bf91906200041f565b60405163095ea7b360e01b81526001600160a01b0383811660048301526000196024830152919091169063095ea7b3906044016020604051808303816000875af115801562000112573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000138919062000446565b50815160005b818110156200019d576001600260008684815181106200016257620001626200046a565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790556001016200013e565b50620001a98462000203565b5050505062000480565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6200020d62000286565b6001600160a01b038116620002785760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b6200028381620001b3565b50565b6000546001600160a01b03163314620002e25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016200026f565b565b6001600160a01b03811681146200028357600080fd5b80516200030781620002e4565b919050565b634e487b7160e01b600052604160045260246000fd5b6000806000606084860312156200033857600080fd5b83516200034581620002e4565b602085810151919450906001600160401b03808211156200036557600080fd5b818701915087601f8301126200037a57600080fd5b8151818111156200038f576200038f6200030c565b8060051b604051601f19603f83011681018181108582111715620003b757620003b76200030c565b60405291825284820192508381018501918a831115620003d657600080fd5b938501935b82851015620003ff57620003ef85620002fa565b84529385019392850192620003db565b8097505050505050506200041660408501620002fa565b90509250925092565b6000602082840312156200043257600080fd5b81516200043f81620002e4565b9392505050565b6000602082840312156200045957600080fd5b815180151581146200043f57600080fd5b634e487b7160e01b600052603260045260246000fd5b610ee780620004906000396000f3fe608060405234801561001057600080fd5b50600436106100c95760003560e01c80639b19251a11610081578063ca85e5d01161005b578063ca85e5d0146101bb578063e43252d7146101ce578063f2fde38b146101e157600080fd5b80639b19251a14610155578063bfe1092814610188578063c1075329146101a857600080fd5b806375619ab5116100b257806375619ab5146100eb5780638ab1d681146100fe5780638da5cb5b1461011157600080fd5b80631c20fadd146100ce578063715018a6146100e3575b600080fd5b6100e16100dc366004610c1d565b6101f4565b005b6100e161029b565b6100e16100f9366004610c5e565b6102af565b6100e161010c366004610c5e565b61055e565b60005473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b610178610163366004610c5e565b60026020526000908152604090205460ff1681565b604051901515815260200161014c565b60015461012b9073ffffffffffffffffffffffffffffffffffffffff1681565b6100e16101b6366004610c82565b6105b2565b6100e16101c9366004610cdd565b610659565b6100e16101dc366004610c5e565b6109f2565b6100e16101ef366004610c5e565b610a49565b6101fc610b05565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301526024820183905284169063a9059cbb906044016020604051808303816000875af1158015610271573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102959190610dac565b50505050565b6102a3610b05565b6102ad6000610b86565b565b6102b7610b05565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c748d2616040518163ffffffff1660e01b8152600401602060405180830381865afa158015610324573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103489190610dce565b6001546040517f095ea7b300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff91821660048201526000602482015291169063095ea7b3906044016020604051808303816000875af11580156103c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103e49190610dac565b50600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117909155604080517fc748d261000000000000000000000000000000000000000000000000000000008152905163c748d261916004808201926020929091908290030181865afa15801561047c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a09190610dce565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6024830152919091169063095ea7b3906044016020604051808303816000875af1158015610536573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055a9190610dac565b5050565b610566610b05565b73ffffffffffffffffffffffffffffffffffffffff16600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055565b6105ba610b05565b60008273ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d8060008114610614576040519150601f19603f3d011682016040523d82523d6000602084013e610619565b606091505b5050905080610654576040517f27fcd9d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050565b3360009081526002602052604090205460ff166106a2576040517f584a793800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600154604080517fc748d261000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163c748d2619160048083019260209291908290030181865afa158015610712573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107369190610dce565b90506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166309454ba36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107cb9190610deb565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290915060009073ffffffffffffffffffffffffffffffffffffffff8416906370a0823190602401602060405180830381865afa15801561083b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085f9190610deb565b9050818110156109645773ffffffffffffffffffffffffffffffffffffffff83166323b872dd33306108918587610e04565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b16815273ffffffffffffffffffffffffffffffffffffffff938416600482015292909116602483015260448201526064016020604051808303816000875af115801561090a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061092e9190610dac565b610964576040517fb1eb39bb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001546040517f2a25dd4100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690632a25dd41906109ba908790600401610e44565b600060405180830381600087803b1580156109d457600080fd5b505af11580156109e8573d6000803e3d6000fd5b5050505050505050565b6109fa610b05565b73ffffffffffffffffffffffffffffffffffffffff16600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b610a51610b05565b73ffffffffffffffffffffffffffffffffffffffff8116610af9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b610b0281610b86565b50565b60005473ffffffffffffffffffffffffffffffffffffffff1633146102ad576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610af0565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b73ffffffffffffffffffffffffffffffffffffffff81168114610b0257600080fd5b600080600060608486031215610c3257600080fd5b8335610c3d81610bfb565b92506020840135610c4d81610bfb565b929592945050506040919091013590565b600060208284031215610c7057600080fd5b8135610c7b81610bfb565b9392505050565b60008060408385031215610c9557600080fd5b8235610ca081610bfb565b946020939093013593505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600060208284031215610cef57600080fd5b813567ffffffffffffffff80821115610d0757600080fd5b818401915084601f830112610d1b57600080fd5b813581811115610d2d57610d2d610cae565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908382118183101715610d7357610d73610cae565b81604052828152876020848701011115610d8c57600080fd5b826020860160208301376000928101602001929092525095945050505050565b600060208284031215610dbe57600080fd5b81518015158114610c7b57600080fd5b600060208284031215610de057600080fd5b8151610c7b81610bfb565b600060208284031215610dfd57600080fd5b5051919050565b81810381811115610e3e577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b60006020808352835180602085015260005b81811015610e7257858101830151858201604001528201610e56565b5060006040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f830116850101925050509291505056fea26469706673582212202c48aee5de4959ef518786fa36afffd4b4a0c2f4af9e25741d18037fdf60170b64736f6c63430008180033000000000000000000000000a9ddd91249dfdd450e81e1c56ab60e1a6265170100000000000000000000000000000000000000000000000000000000000000600000000000000000000000003ef3d8ba38ebe18db133cec108f4d14ce00dd9ae0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000ea05f9001fbdea6d4280879f283ff9d0b282060e0000000000000000000000000dd2ea40a3561c309c03b96108e78d06e8a1a99b000000000000000000000000f4c94b2fdc2efa4ad4b831f312e7ef74890705da";
// bytes memory bytecode = abi.encodePacked(
// type(Disputer).creationCode,
// abi.encode(GUARDIAN_ADDRESS, whitelist, distributor)
// ); // weird - not equivalent to the above bytecode

// Use a deterministic salt
bytes32 salt = vm.envBytes32("DEPLOY_SALT");

// Deploy using the specified CREATE2 deployer
address createX = 0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed;
(bool success, bytes memory returnData) = createX.call(
abi.encodeWithSignature("deployCreate2(bytes32,bytes)", salt, bytecode)
);
bytes memory callData = abi.encodeWithSignature("deployCreate2(bytes32,bytes)", salt, bytecode);

(bool success, bytes memory returnData) = createX.call(callData);

require(success, "CREATE2 deployment failed");
address disputer = address(uint160(uint256(bytes32(returnData))));

console.log("Disputer:", disputer);

// Transfer ownership to AngleLabs
Disputer(disputer).transferOwnership(ANGLE_LABS);
console.log("Transferred Disputer ownership to AngleLabs:", ANGLE_LABS);

console.log("Disputer:", disputer);
return address(disputer);
}

Expand Down Expand Up @@ -307,8 +350,11 @@ contract MainDeployScript is Script, BaseScript, JsonReader {
console.log("Setting dispute period to 1");
distributor.setDisputePeriod(1);

// Set dispute amount to 100 EURA (18 decimals)
console.log("Setting dispute amount to 100 EURA (18 decimals)");
distributor.setDisputeAmount(100 * 10 ** 18);
// Set dispute amount to 100 tokens (18 decimals)
string memory symbol = MockToken(disputeToken).symbol();
uint8 decimals = MockToken(disputeToken).decimals();
console.log("Setting dispute amount to 100", symbol);
console.log("Token decimals:", decimals);
distributor.setDisputeAmount(100 * 10 ** decimals);
}
}

0 comments on commit 5f69c90

Please sign in to comment.