Skip to content

Commit

Permalink
fix(ct): make executors permissioned
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jan 16, 2023
1 parent 1c6b379 commit 60d7adc
Show file tree
Hide file tree
Showing 18 changed files with 357 additions and 434 deletions.
8 changes: 8 additions & 0 deletions .changeset/old-badgers-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@chugsplash/contracts': patch
'@chugsplash/core': patch
'@chugsplash/executor': patch
'@chugsplash/plugins': patch
---

Make executors permissioned
5 changes: 2 additions & 3 deletions packages/contracts/contracts/ChugSplashBootLoader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ contract ChugSplashBootLoader is Initializable {
* using ChugSplash!
*
* @param _owner Address of the owner of the ChugSplash contracts.
* @param _executorBondAmount Executor bond amount in ETH.
* @param _executionLockTime Amount of time for an executor to completely execute a
* bundle after claiming it.
* @param _ownerBondAmount Amount that must be deposited in this contract in order to
Expand All @@ -54,7 +53,6 @@ contract ChugSplashBootLoader is Initializable {
*/
function initialize(
address _owner,
uint256 _executorBondAmount,
uint256 _executionLockTime,
uint256 _ownerBondAmount,
uint256 _executorPaymentPercentage,
Expand Down Expand Up @@ -84,10 +82,11 @@ contract ChugSplashBootLoader is Initializable {
registryImplementation = new ChugSplashRegistry{ salt: _salt }(
address(proxyUpdater),
_ownerBondAmount,
_executorBondAmount,
_executionLockTime,
_executorPaymentPercentage,
_managerImplementation
);

registryImplementation.initialize(_owner, new address[](0));
}
}
185 changes: 52 additions & 133 deletions packages/contracts/contracts/ChugSplashManager.sol

Large diffs are not rendered by default.

79 changes: 69 additions & 10 deletions packages/contracts/contracts/ChugSplashRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pragma solidity ^0.8.9;
import { ChugSplashManager } from "./ChugSplashManager.sol";
import { ChugSplashManagerProxy } from "./ChugSplashManagerProxy.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {
OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Proxy } from "./libraries/Proxy.sol";

/**
Expand All @@ -13,7 +16,7 @@ import { Proxy } from "./libraries/Proxy.sol";
* find and index these deployments. Deployment names are unique and are reserved on a
* first-come, first-served basis.
*/
contract ChugSplashRegistry is Initializable {
contract ChugSplashRegistry is Initializable, OwnableUpgradeable {
/**
* @notice Emitted whenever a new project is registered.
*
Expand Down Expand Up @@ -74,6 +77,20 @@ contract ChugSplashRegistry is Initializable {
*/
event ProxyTypeAdded(bytes32 proxyType, address adapter);

/**
* @notice Emitted when an executor is added.
*
* @param executor Address of the added executor.
*/
event ExecutorAdded(address indexed executor);

/**
* @notice Emitted when an executor is removed.
*
* @param executor Address of the removed executor.
*/
event ExecutorRemoved(address indexed executor);

/**
* @notice Mapping of project names to ChugSplashManager contracts.
*/
Expand All @@ -89,6 +106,11 @@ contract ChugSplashRegistry is Initializable {
*/
mapping(bytes32 => address) public adapters;

/**
* @notice Addresses that can execute bundles.
*/
mapping(address => bool) public executors;

/**
* @notice Address of the ProxyUpdater.
*/
Expand All @@ -99,11 +121,6 @@ contract ChugSplashRegistry is Initializable {
*/
uint256 public immutable ownerBondAmount;

/**
* @notice Amount that an executor must send to the ChugSplashManager to claim a bundle.
*/
uint256 public immutable executorBondAmount;

/**
* @notice Amount of time for an executor to completely execute a bundle after claiming it.
*/
Expand All @@ -124,8 +141,6 @@ contract ChugSplashRegistry is Initializable {
* @param _proxyUpdater Address of the ProxyUpdater.
* @param _ownerBondAmount Amount that must be deposited in the ChugSplashManager in
* order to execute a bundle.
* @param _executorBondAmount Amount that an executor must send to the ChugSplashManager
* to claim a bundle.
* @param _executionLockTime Amount of time for an executor to completely execute a
* bundle after claiming it.
* @param _executorPaymentPercentage Amount that an executor will earn from completing a bundle,
Expand All @@ -135,19 +150,30 @@ contract ChugSplashRegistry is Initializable {
constructor(
address _proxyUpdater,
uint256 _ownerBondAmount,
uint256 _executorBondAmount,
uint256 _executionLockTime,
uint256 _executorPaymentPercentage,
address _managerImplementation
) {
proxyUpdater = _proxyUpdater;
ownerBondAmount = _ownerBondAmount;
executorBondAmount = _executorBondAmount;
executionLockTime = _executionLockTime;
executorPaymentPercentage = _executorPaymentPercentage;
managerImplementation = _managerImplementation;
}

/**
* @param _owner Initial owner of this contract.
* @param _executors Array of executors to add.
*/
function initialize(address _owner, address[] memory _executors) public initializer {
__Ownable_init();
_transferOwnership(_owner);

for (uint i = 0; i < _executors.length; i++) {
_setExecutor(_executors[i], true);
}
}

/**
* @notice Registers a new project.
*
Expand Down Expand Up @@ -228,4 +254,37 @@ contract ChugSplashRegistry is Initializable {

emit ProxyTypeAdded(_proxyType, _adapter);
}

/**
* @notice Add an executor, which can execute bundles on behalf of users. Only callable by the
* owner of this contract.
*
* @param _executor Address of the executor to add.
*/
function addExecutor(address _executor) public onlyOwner {
require(executors[_executor] == false, "ChugSplashRegistry: executor already added");
_setExecutor(_executor, true);
emit ExecutorAdded(_executor);
}

/**
* @notice Remove an executor. Only callable by the owner of this contract.
*
* @param _executor Address of the executor to remove.
*/
function removeExecutor(address _executor) public onlyOwner {
require(executors[_executor] == true, "ChugSplashRegistry: executor already removed");
_setExecutor(_executor, false);
emit ExecutorRemoved(_executor);
}

/**
* @notice Internal function that adds or removes an executor.
*
* @param _executor Address of the executor to add or remove.
* @param _isExecutor Boolean indicating if the executor is being added or removed.
*/
function _setExecutor(address _executor, bool _isExecutor) internal {
executors[_executor] = _isExecutor;
}
}
7 changes: 4 additions & 3 deletions packages/contracts/contracts/ProxyInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ contract ProxyInitializer is Initializable {
* new owner specified in the constructor.
*
* @param _implementation The proxy's implementation address.
* @param _data Data to delegatecall the new implementation with.
*/
function initialize(address _implementation) external initializer {
// Set the proxy's implementation contract.
proxy.upgradeTo(_implementation);
function initialize(address _implementation, bytes memory _data) external initializer {
// Set the proxy's implementation contract and delegatecall it with the supplied data.
proxy.upgradeToAndCall(_implementation, _data);

// Transfer ownership of the proxy to the new owner.
proxy.changeAdmin(newOwner);
Expand Down
7 changes: 2 additions & 5 deletions packages/contracts/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

export const OWNER_MULTISIG_ADDRESS =
'0xF2a21e4E9F22AAfD7e8Bf47578a550b4102732a9'
export const EXECUTOR = '0x42761facf5e6091fca0e38f450adfb1e22bd8c3c'

export const CHUGSPLASH_SALT = '0x' + '11'.repeat(32)

Expand Down Expand Up @@ -48,7 +49,6 @@ const chugsplashManagerConstructorArgTypes =
export const DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS =
'0x4e59b44847b379578588920ca78fbf26c0b4956c'
export const OWNER_BOND_AMOUNT = ethers.utils.parseEther('0.001')
export const EXECUTOR_BOND_AMOUNT = ethers.utils.parseEther('0.01')
export const EXECUTION_LOCK_TIME = 15 * 60
export const EXECUTOR_PAYMENT_PERCENTAGE = 20

Expand Down Expand Up @@ -125,7 +125,6 @@ const chugsplashManagerConstructorArgValues = [
'Root Manager',
OWNER_MULTISIG_ADDRESS,
PROXY_UPDATER_ADDRESS,
EXECUTOR_BOND_AMOUNT,
EXECUTION_LOCK_TIME,
OWNER_BOND_AMOUNT,
EXECUTOR_PAYMENT_PERCENTAGE,
Expand Down Expand Up @@ -154,11 +153,10 @@ export const CHUGSPLASH_REGISTRY_ADDRESS = ethers.utils.getCreate2Address(
[
ChugSplashRegistryArtifact.bytecode,
ethers.utils.defaultAbiCoder.encode(
['address', 'uint256', 'uint256', 'uint256', 'uint256', 'address'],
['address', 'uint256', 'uint256', 'uint256', 'address'],
[
PROXY_UPDATER_ADDRESS,
OWNER_BOND_AMOUNT,
EXECUTOR_BOND_AMOUNT,
EXECUTION_LOCK_TIME,
EXECUTOR_PAYMENT_PERCENTAGE,
CHUGSPLASH_MANAGER_ADDRESS,
Expand All @@ -178,7 +176,6 @@ export const CHUGSPLASH_CONSTRUCTOR_ARGS = {}
CHUGSPLASH_CONSTRUCTOR_ARGS[chugsplashRegistrySourceName] = [
PROXY_UPDATER_ADDRESS,
OWNER_BOND_AMOUNT,
EXECUTOR_BOND_AMOUNT,
EXECUTION_LOCK_TIME,
EXECUTOR_PAYMENT_PERCENTAGE,
CHUGSPLASH_MANAGER_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/ifaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const DefaultAdapterArtifact = require('../artifacts/contracts/adapters/D
export const ProxyArtifact = require('../artifacts/contracts/libraries/Proxy.sol/Proxy.json')
export const ProxyInitializerArtifact = require('../artifacts/contracts/ProxyInitializer.sol/ProxyInitializer.json')

export const buildInfo = require('../artifacts/build-info/6523e78f87a5803afa0b08ab43b0b969.json')
export const buildInfo = require('../artifacts/build-info/af0bd9270cded1139bee6d9130cd340f.json')

export const ChugSplashRegistryABI = ChugSplashRegistryArtifact.abi
export const ChugSplashBootLoaderABI = ChugSplashBootLoaderArtifact.abi
Expand Down
Loading

0 comments on commit 60d7adc

Please sign in to comment.