Skip to content

Commit

Permalink
chore: grant roles
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Oct 5, 2024
1 parent eda1182 commit c9e2dc6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
20 changes: 20 additions & 0 deletions contracts/0.4.24/template/LidoTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,12 @@ contract LidoTemplate is IsContract {
function createSimpleDVTApp(
uint16[3] _initialSemanticVersion,
address _impl,
address _stakingRouter,
bytes _contentURI
) external onlyOwner {
APMRegistry lidoRegistry = deployState.lidoRegistry;
Kernel dao = deployState.dao;
ACL acl = deployState.acl;

apmRepos.simpleDVT = lidoRegistry.newRepoWithVersion(
SIMPLE_DVT_APP_NAME,
Expand All @@ -376,6 +378,24 @@ contract LidoTemplate is IsContract {

bytes32 appId = _getAppId(SIMPLE_DVT_APP_NAME, deployState.lidoRegistryEnsNode);
dao.setApp(dao.APP_BASES_NAMESPACE(), appId, _impl);


bytes32 stakingRouterRole = deployState.operators.STAKING_ROUTER_ROLE();
address app = address(apmRepos.simpleDVT);

// grant perm for staking router
// https://github.com/lidofinance/lido-dao/blob/291ea9e191f62692f0a17d6af77b66de0abe0a53/scripts/simpledvt/02-clone-nor.js#L220
acl.createPermission(_stakingRouter, app,deployState.operators.STAKING_ROUTER_ROLE(),this);
acl.grantPermission(deployState.agent, app, stakingRouterRole);
_transferPermissionFromTemplate(acl, app, deployState.voting, stakingRouterRole);

// grant perm for agent to manage signing keys and set node operator limit
// https://github.com/lidofinance/lido-dao/blob/291ea9e191f62692f0a17d6af77b66de0abe0a53/scripts/simpledvt/02-clone-nor.js#L228
acl.createPermission(deployState.agent, app, deployState.operators.MANAGE_SIGNING_KEYS(), deployState.voting);
acl.createPermission(deployState.agent, app, deployState.operators.SET_NODE_OPERATOR_LIMIT_ROLE(), deployState.voting);

// TODO: grant perms to easy track factories ?
// https://github.com/lidofinance/lido-dao/blob/291ea9e191f62692f0a17d6af77b66de0abe0a53/scripts/simpledvt/02-clone-nor.js#L257
}

function issueTokens(
Expand Down
54 changes: 43 additions & 11 deletions scripts/scratch/steps/0095-deploy-simple-dvt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { expect } from "chai";
import { ZeroAddress } from "ethers";
import { ethers } from "hardhat";

import { Kernel, LidoTemplate, NodeOperatorsRegistry } from "typechain-types";
import { AppProxyUpgradeable, Kernel, LidoTemplate, NodeOperatorsRegistry } from "typechain-types";

import { findEvents, getContractPath, loadContract, makeTx, setValueInState, updateObjectInState } from "lib";
import { cy, log, yl } from "lib/log";
Expand Down Expand Up @@ -54,11 +53,6 @@ async function deployEmptyAppProxy(deployer: string, appName: string) {
});

log.success(`Deployed ${yl(appName)} proxy at ${cy(proxyAddress)}`);

const appProxyUpgradeable = await ethers.getContractAt("AppProxyUpgradeable", proxyAddress);
expect(await appProxyUpgradeable.kernel()).to.equal(kernelAddress);
expect(await appProxyUpgradeable.appId()).to.equal(appId);
expect(await appProxyUpgradeable.implementation()).to.equal(ZeroAddress);
}

async function deploySimpleDvt(deployer: string) {
Expand All @@ -69,15 +63,20 @@ async function deploySimpleDvt(deployer: string) {
return;
}

const norImplAddress = state[Sk.appNodeOperatorsRegistry].implementation.address;
const lidoLocatorAddress = state[Sk.lidoLocator].proxy.address;
const norImplAddress = state[Sk.appNodeOperatorsRegistry].implementation.address;

const template = await loadContract<LidoTemplate>("LidoTemplate", state[Sk.lidoTemplate].address);

// Set the simple DVT app implementation address to the Node Operators Registry implementation address
const receipt = await makeTx(template, "createSimpleDVTApp", [[1, 0, 0], norImplAddress, NULL_CONTENT_URI], {
from: deployer,
});
const receipt = await makeTx(
template,
"createSimpleDVTApp",
[[1, 0, 0], norImplAddress, state[Sk.stakingRouter].proxy.address, NULL_CONTENT_URI],
{
from: deployer,
},
);

setValueInState(Sk.createSimpleDVTAppTx, receipt.hash);

Expand All @@ -94,6 +93,37 @@ async function deploySimpleDvt(deployer: string) {
];

await makeTx(proxy, "initialize", simpleDvtInitOptions, { from: deployer });

updateObjectInState(Sk.appSimpleDvt, {
...state[Sk.appSimpleDvt],
implementation: {
address: norImplAddress,
contract: await getContractPath("NodeOperatorsRegistry"),
constructorArgs: [],
},
});
}

async function validateSimpleDvt(deployer: string) {
const state = readNetworkState({ deployer });

const proxyAddress = state[Sk.appSimpleDvt].proxy.address;
const kernelAddress = state[Sk.aragonKernel].proxy.address;
const appId = state[Sk.appSimpleDvt].aragonApp.id;

const appProxyUpgradeable = await loadContract<AppProxyUpgradeable>("AppProxyUpgradeable", proxyAddress);
expect(await appProxyUpgradeable.kernel()).to.equal(kernelAddress);
expect(await appProxyUpgradeable.appId()).to.equal(appId);
expect(await appProxyUpgradeable.implementation()).to.equal(
state[Sk.appNodeOperatorsRegistry].implementation.address,
);

const app = await loadContract<NodeOperatorsRegistry>("NodeOperatorsRegistry", proxyAddress);

expect(await app.appId()).to.equal(appId);
expect(await app.kernel()).to.equal(kernelAddress);
expect(await app.hasInitialized()).to.be.true;
expect(await app.getLocator()).to.equal(state[Sk.lidoLocator].proxy.address);
}

export async function main() {
Expand All @@ -102,4 +132,6 @@ export async function main() {
await deployEmptyAppProxy(deployer, SIMPLE_DVT_APP_NAME);

await deploySimpleDvt(deployer);

await validateSimpleDvt(deployer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function main() {
const lidoAddress = state[Sk.appLido].proxy.address;
const legacyOracleAddress = state[Sk.appOracle].proxy.address;
const nodeOperatorsRegistryAddress = state[Sk.appNodeOperatorsRegistry].proxy.address;
const nodeOperatorsRegistryParams = state["nodeOperatorsRegistry"].deployParameters;
const nodeOperatorsRegistryParams = state[Sk.nodeOperatorsRegistry].deployParameters;
const validatorsExitBusOracleParams = state[Sk.validatorsExitBusOracle].deployParameters;
const accountingOracleParams = state[Sk.accountingOracle].deployParameters;
const stakingRouterAddress = state[Sk.stakingRouter].proxy.address;
Expand Down

0 comments on commit c9e2dc6

Please sign in to comment.