Skip to content

Commit

Permalink
feat: add setters to deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
nlecoufl committed Nov 18, 2024
1 parent 37ad4bd commit ce8b427
Showing 1 changed file with 89 additions and 27 deletions.
116 changes: 89 additions & 27 deletions deploy/foundry/merklDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ import { ICore } from "../../contracts/interfaces/ICore.sol";
import { BaseScript } from "../utils/Base.s.sol";
import { MockToken } from "../../contracts/mock/MockToken.sol";

contract MainDeployScript is Script, BaseScript {
contract MainDeployScript is Script, BaseScript, JsonReader {
uint256 private DEPLOYER_PRIVATE_KEY;
uint256 private MERKL_DEPLOYER_PRIVATE_KEY;

// Constants and storage
address public KEEPER = 0x435046800Fb9149eE65159721A92cB7d50a7534b;
address public GUARDIAN_ADDRESS = 0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701;
address public ANGLE_LABS;
address public DEPLOYER_ADDRESS;
address public MERKL_DEPLOYER_ADDRESS;
address public EURA;
address public DISPUTE_TOKEN;

JsonReader public reader;

Expand All @@ -39,16 +40,19 @@ contract MainDeployScript is Script, BaseScript {
// Setup
DEPLOYER_PRIVATE_KEY = vm.envUint("DEPLOYER_PRIVATE_KEY");
MERKL_DEPLOYER_PRIVATE_KEY = vm.envUint("MERKL_DEPLOYER_PRIVATE_KEY");
reader = new JsonReader();
console.log("Chain ID:", block.chainid);

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

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

// Compute addresses from private keys
Expand All @@ -57,7 +61,7 @@ contract MainDeployScript is Script, BaseScript {
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("EURA:", EURA);
console.log("DISPUTE TOKEN (EURA):", DISPUTE_TOKEN);

// 1. Deploy using DEPLOYER_PRIVATE_KEY
vm.startBroadcast(DEPLOYER_PRIVATE_KEY);
Expand All @@ -66,6 +70,8 @@ contract MainDeployScript is Script, BaseScript {
address proxyAdmin = deployProxyAdmin();
// Deploy CoreBorrow
DeploymentAddresses memory coreBorrow = deployCoreBorrow(proxyAdmin);
// Deploy AglaMerkl
address aglaMerkl = deployAglaMerkl();

vm.stopBroadcast();

Expand All @@ -79,17 +85,27 @@ contract MainDeployScript is Script, BaseScript {

vm.stopBroadcast();

// 3. Deploy using DEPLOYER_PRIVATE_KEY
// 3. Set params and deploy Disputer using DEPLOYER_PRIVATE_KEY
vm.startBroadcast(DEPLOYER_PRIVATE_KEY);

// Set params and transfer ownership
setDistributionCreatorParams(address(creator.proxy), aglaMerkl, KEEPER);
setDistributorParams(address(distributor.proxy), DISPUTE_TOKEN, KEEPER);

// Deploy Disputer
// First, set dispute token if EURA is set
if (EURA != address(0)) Distributor(distributor.proxy).setDisputeToken(IERC20(EURA));
// Then deploy Disputer
address disputer = deployDisputer(distributor.proxy);

// Deploy AglaMerkl
address aglaMerkl = deployAglaMerkl();
// Revoke GOVENOR from DEPLOYER_ADDRESS if deployer is GUARDIAN_ADDRESS, else revoke both roles by calling removeGovernor
if (DEPLOYER_ADDRESS == GUARDIAN_ADDRESS) {
CoreBorrow(coreBorrow.proxy).revokeRole(CoreBorrow(coreBorrow.proxy).GOVERNOR_ROLE(), DEPLOYER_ADDRESS);
} else {
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();

Expand All @@ -112,20 +128,15 @@ contract MainDeployScript is Script, BaseScript {
}
console.log("AglaMerkl:");
console.log(" - Address:", aglaMerkl);

console.log("\n=== Additional Setup Required ===");
console.log("On DistributionCreator:");
console.log("- setRewardTokenMinAmounts()");
console.log("- setFeeRecipient() -> angleLabs");
console.log("- setMessage()");
console.log("\nOn Distributor:");
console.log("- toggleTrusted() -> keeper bot updating");
console.log("- setDisputeToken()");
console.log("- setDisputePeriod()");
console.log("- setDisputeAmount()");
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DEPLOY FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function deployProxyAdmin() public returns (address) {
console.log("\n=== Deploying ProxyAdmin ===");

// Deploy ProxyAdmin
ProxyAdmin proxyAdmin = new ProxyAdmin();
console.log("ProxyAdmin:", address(proxyAdmin));
Expand Down Expand Up @@ -211,8 +222,6 @@ contract MainDeployScript is Script, BaseScript {
whitelist[1] = 0x0dd2Ea40A3561C309C03B96108e78d06E8A1a99B;
whitelist[2] = 0xF4c94b2FdC2efA4ad4b831f312E7eF74890705DA;

// Disputer disputer = new Disputer(DEPLOYER_ADDRESS, whitelist, Distributor(distributor));

// Create initialization bytecode
bytes memory bytecode = abi.encodePacked(
type(Disputer).creationCode,
Expand All @@ -231,6 +240,10 @@ contract MainDeployScript is Script, BaseScript {
require(success, "CREATE2 deployment failed");
address disputer = address(uint160(uint256(bytes32(returnData))));

// 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 All @@ -247,4 +260,53 @@ contract MainDeployScript is Script, BaseScript {
console.log("AglaMerkl Token:", address(token));
return address(token);
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SETTERS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function setDistributionCreatorParams(address _distributionCreator, address aglaMerkl, address keeper) public {
console.log("\n=== Setting DistributionCreator params ===");

DistributionCreator distributionCreator = DistributionCreator(_distributionCreator);

// Set min amount to 1 for reward tokens
uint256[] memory minAmounts = new uint256[](1);
address[] memory tokens = new address[](1);
minAmounts[0] = 1;
tokens[0] = aglaMerkl;
console.log("Setting reward token min amounts to 1 for:", aglaMerkl);
distributionCreator.setRewardTokenMinAmounts(tokens, minAmounts);

// Set keeper as fee recipient
console.log("Setting keeper as fee recipient:", keeper);
distributionCreator.setFeeRecipient(keeper);

// Set message
console.log("Setting message");
distributionCreator.setMessage(
" 1. Merkl is experimental software provided as is, use it at your own discretion. There may notably be delays in the onchain Merkle root updates and there may be flaws in the script (or engine) or in the infrastructure used to update results onchain. In that regard, everyone can permissionlessly dispute the rewards which are posted onchain, and when creating a distribution, you are responsible for checking the results and eventually dispute them. 2. If you are specifying an invalid pool address or a pool from an AMM that is not marked as supported, your rewards will not be taken into account and you will not be able to recover them. 3. If you do not blacklist liquidity position managers or smart contract addresses holding LP tokens that are not natively supported by the Merkl system, or if you don't specify the addresses of the liquidity position managers that are not automatically handled by the system, then the script will not be able to take the specifities of these addresses into account, and it will reward them like a normal externally owned account would be. If these are smart contracts that do not support external rewards, then rewards that should be accruing to it will be lost. 4. If rewards sent through Merkl remain unclaimed for a period of more than 1 year after the end of the distribution (because they are meant for instance for smart contract addresses that cannot claim or deal with them), then we reserve the right to recover these rewards. 5. Fees apply to incentives deposited on Merkl, unless the pools incentivized contain a whitelisted token (e.g an Angle Protocol stablecoin). 6. By interacting with the Merkl smart contract to deposit an incentive for a pool, you are exposed to smart contract risk and to the offchain mechanism used to compute reward distribution. 7. If the rewards you are sending are too small in value, or if you are sending rewards using a token that is not approved for it, your rewards will not be handled by the script, and they may be lost. 8. If you mistakenly send too much rewards compared with what you wanted to send, you will not be able to call them back. You will also not be able to prematurely end a reward distribution once created. 9. The engine handling reward distribution for a pool may not look at all the swaps occurring on the pool during the time for which you are incentivizing, but just at a subset of it to gain in efficiency. Overall, if you distribute incentives using Merkl, it means that you are aware of how the engine works, of the approximations it makes and of the behaviors it may trigger (e.g. just in time liquidity). 10. Rewards corresponding to incentives distributed through Merkl do not compound block by block, but are regularly made available (through a Merkle root update) at a frequency which depends on the chain. "
);
}

function setDistributorParams(address _distributor, address disputeToken, address keeper) public {
console.log("\n=== Setting Distributor params ===");
Distributor distributor = Distributor(_distributor);

// Toggle trusted status for keeper
console.log("Toggling trusted status for keeper:", keeper);
distributor.toggleTrusted(keeper);

// Set dispute token (DISPUTE_TOKEN if available, skip otherwise)
console.log("Setting dispute token:", disputeToken);
if (disputeToken != address(0)) distributor.setDisputeToken(IERC20(disputeToken));

// Set dispute period
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);
}
}

0 comments on commit ce8b427

Please sign in to comment.