Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VEN-2797] Helper Contract to Batch ACM Commands #90

Open
wants to merge 63 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ea03dc5
feat: added contract for configuring permissions
web3rover Sep 11, 2024
3336a8e
feat: updating deployment files
Sep 11, 2024
f0eecfc
fix: added oracle permissions
web3rover Sep 12, 2024
3a9d364
Merge branch 'feat/ven-2797' of github.com:VenusProtocol/governance-c…
web3rover Sep 12, 2024
59673a8
fix: xvs and xvs bridge permissions
web3rover Sep 12, 2024
75acc1f
fix: added permissions for xvs vault and store
web3rover Sep 12, 2024
fe1358a
fix: added permissions for comptrollers, vtokens and pool registry
web3rover Sep 12, 2024
53bc61a
fix: added all other permissions
web3rover Sep 12, 2024
f8d2e80
fix: updated addresses
web3rover Sep 12, 2024
57d1c6c
fix: remove duplicate check
web3rover Sep 13, 2024
bd3772d
fix: fixed lock
web3rover Sep 13, 2024
6e0d9c9
fix: update yarn.lock
web3rover Sep 16, 2024
4dea831
fix: fix yarn
web3rover Sep 16, 2024
fdd7deb
fix: revert yarn
web3rover Sep 16, 2024
e5321d6
fix: revert yarn lock
web3rover Sep 16, 2024
ac52151
fix: revert yarn
web3rover Sep 16, 2024
21bd7b2
Merge branch 'develop' into feat/ven-2797
web3rover Sep 16, 2024
ea209e0
fix: updated yarn.lock
web3rover Sep 16, 2024
6fd1556
fix: use array instead of mapping
web3rover Sep 16, 2024
4a7ea00
fix: check for empty array
web3rover Sep 16, 2024
a6dee6b
fix: optimise length read
web3rover Sep 16, 2024
0cde6c2
fix: change enum to bool
web3rover Sep 16, 2024
ae4119c
fix: added events to netspec
web3rover Sep 16, 2024
3cd18ac
fix: remove if check for grant and revoke
web3rover Sep 16, 2024
b32a685
fix: added revoke commands
web3rover Sep 17, 2024
45f1642
fix: moved oracle permissions to funcs
web3rover Sep 18, 2024
3281343
fix: created reusable funcs for permissions
web3rover Sep 18, 2024
24d9771
fix: moved all grant permissions to funcs
web3rover Sep 18, 2024
da6f9f0
fix: revoke permissions funcs
web3rover Sep 18, 2024
5b6d4a7
fix: moved revoke permissions to funcs
web3rover Sep 19, 2024
ddc4ec1
fix: use loop to prevent duplicate code
web3rover Sep 19, 2024
90aebf0
fix: contract optimisations
web3rover Sep 19, 2024
2c339b1
fix: fixed permissions for reward distirbutor
web3rover Sep 19, 2024
1fa91eb
fix: removed params subobject
web3rover Sep 20, 2024
1a99762
fix: use flatMap
web3rover Sep 20, 2024
5e3182e
fix: change contract location
web3rover Sep 20, 2024
92ad829
fix: fix prime permissions
web3rover Sep 24, 2024
70077fb
fix: acm-02
web3rover Sep 27, 2024
2f8b6be
fix: acm-03
web3rover Sep 27, 2024
4bc0cdc
fix: global-01
web3rover Sep 27, 2024
93280bf
fix: fixed typo
web3rover Sep 27, 2024
1390a81
fix: use ensureNonzeroAddress
web3rover Sep 27, 2024
b9070b0
fix: acm-02
web3rover Sep 29, 2024
7ee75af
fix: revert global-01
web3rover Sep 29, 2024
4f28586
fix: deployed on sepolia
web3rover Oct 3, 2024
1af0888
feat: updating deployment files
Oct 3, 2024
82fa696
fix: deployed on arbitrumsepolia
web3rover Oct 3, 2024
9868d25
Merge branch 'feat/ven-2797' of github.com:VenusProtocol/governance-c…
web3rover Oct 3, 2024
d168a99
feat: updating deployment files
Oct 3, 2024
80becae
fix: fixed permissions
web3rover Oct 4, 2024
ef49603
fix: deployed to opbnbtestnet
web3rover Oct 4, 2024
dae464b
feat: updating deployment files
Oct 4, 2024
2d0167b
fix: revoke XVSVaultTreasury permissions
web3rover Oct 9, 2024
bd7c481
fix: revoke XVSBridgeAdmin permissions
web3rover Oct 9, 2024
83081f4
fix: fixed reward distributor permission
web3rover Oct 9, 2024
8114441
fix: fixed pool registry permissions
web3rover Oct 9, 2024
c5631f8
fix: fixed reward distributor revoke permissions
web3rover Oct 9, 2024
7e7f72d
fix: added redstone oracle revoke permissions
web3rover Oct 9, 2024
da1ad82
fix: revoke reward distributor permissions for opbnbtestnet
web3rover Oct 9, 2024
391c5e1
fix: fixed omnichain executor permissions
web3rover Oct 9, 2024
92aa2e0
fix: fixed permissions
web3rover Oct 10, 2024
a4472c3
fix: fixed permissions
web3rover Oct 10, 2024
5003c20
Merge branch 'develop' into feat/ven-2797
GitGuru7 Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions contracts/Utils/ACMCommandsAggregator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.25;

import { IAccessControlManagerV8 } from "../Governance/IAccessControlManagerV8.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";

/**
* @title ACMCommandsAggregator
* @author Venus
* @notice This contract is a helper to aggregate multiple grant and revoke permissions in batches and execute them in one go.
*/
contract ACMCommandsAggregator {
/*
* @notice Struct to store permission details
*/
struct Permission {
/*
* @notice Address of the contract
*/
address contractAddress;
/*
* @notice Function signature
*/
string functionSig;
/*
* @notice Address of the account
*/
address account;
}

/**
* @notice Access control manager contract
*/
IAccessControlManagerV8 public immutable ACM;

/*
* @notice 2D array to store grant permissions in batches
*/
Permission[][] public grantPermissions;

/*
* @notice 2D array to store revoke permissions in batches
*/
Permission[][] public revokePermissions;

/*
* @notice Event emitted when grant permissions are added
*/
event GrantPermissionsAdded(uint256 index);

/*
* @notice Event emitted when revoke permissions are added
*/
event RevokePermissionsAdded(uint256 index);

/*
* @notice Event emitted when grant permissions are executed
*/
event GrantPermissionsExecuted(uint256 index);

/*
* @notice Event emitted when revoke permissions are executed
*/
event RevokePermissionsExecuted(uint256 index);

/*
* @notice Error to be thrown when permissions are empty
*/
error EmptyPermissions();

/*
* @notice Constructor to set the access control manager
* @param _acm Address of the access control manager
*/
constructor(IAccessControlManagerV8 _acm) {
ensureNonzeroAddress(address(_acm));
ACM = _acm;
}

/*
* @notice Function to add grant permissions
* @param _permissions Array of permissions
* @custom:event Emits GrantPermissionsAdded event
*/
function addGrantPermissions(Permission[] memory _permissions) external {
if (_permissions.length == 0) {
revert EmptyPermissions();
}

uint256 index = grantPermissions.length;
grantPermissions.push();

for (uint256 i; i < _permissions.length; ++i) {
grantPermissions[index].push(
Permission(_permissions[i].contractAddress, _permissions[i].functionSig, _permissions[i].account)
);
}

emit GrantPermissionsAdded(index);
}

/*
* @notice Function to add revoke permissions
* @param _permissions Array of permissions
* @custom:event Emits RevokePermissionsAdded event
*/
function addRevokePermissions(Permission[] memory _permissions) external {
if (_permissions.length == 0) {
revert EmptyPermissions();
}

uint256 index = revokePermissions.length;
revokePermissions.push();

for (uint256 i; i < _permissions.length; ++i) {
revokePermissions[index].push(
Permission(_permissions[i].contractAddress, _permissions[i].functionSig, _permissions[i].account)
);
}

emit RevokePermissionsAdded(index);
}

/*
* @notice Function to execute grant permissions
* @param index Index of the permissions array
* @custom:event Emits GrantPermissionsExecuted event
*/
function executeGrantPermissions(uint256 index) external {
uint256 length = grantPermissions[index].length;
for (uint256 i; i < length; ++i) {
Permission memory permission = grantPermissions[index][i];
ACM.giveCallPermission(permission.contractAddress, permission.functionSig, permission.account);
}

emit GrantPermissionsExecuted(index);
}

/*
* @notice Function to execute revoke permissions
* @param index Index of the permissions array
* @custom:event Emits RevokePermissionsExecuted event
*/
function executeRevokePermissions(uint256 index) external {
uint256 length = revokePermissions[index].length;
for (uint256 i; i < length; ++i) {
Permission memory permission = revokePermissions[index][i];
ACM.revokeCallPermission(permission.contractAddress, permission.functionSig, permission.account);
}

emit RevokePermissionsExecuted(index);
}
}
23 changes: 23 additions & 0 deletions deploy/007-acm-commands-aggregator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const acm = await ethers.getContract("AccessControlManager");

await deploy("ACMCommandsAggregator", {
contract: "ACMCommandsAggregator",
from: deployer,
args: [acm.address],
log: true,
autoMine: true,
});
};

func.tags = ["ACMCommandsAggregator"];

export default func;
Loading
Loading