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

feat: OwnerProxy #116

Merged
merged 18 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"Timelock": "0x1734A5eAB695d9B7C678adaa9a479DBB88897660",
"NestedAssetBatcher": "0xae5fAB55C6AA6Bba24eef3fb98c48a0B616b163d",
"scripts": {
"DeployAddOperators": "0xd87c56d1698E52F6e3363b9ffD09b0AfD46DDA8E"
"OperatorScripts": ""
},
"config": {
"maxHoldingsCount": 12,
Expand Down
37 changes: 0 additions & 37 deletions contracts/governance/scripts/AddOperator.sol

This file was deleted.

61 changes: 0 additions & 61 deletions contracts/governance/scripts/DeployAddOperators.sol

This file was deleted.

107 changes: 107 additions & 0 deletions contracts/governance/scripts/OperatorScripts.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.11;

import "../../interfaces/INestedFactory.sol";
import "../../interfaces/IOperatorResolver.sol";
import "../../abstracts/MixinOperatorResolver.sol";
import "../../interfaces/external/ITransparentUpgradeableProxy.sol";

contract OperatorScripts {
struct tupleOperator {
bytes32 name;
bytes4 selector;
}

address public immutable nestedFactory;
address public immutable resolver;

constructor(address _nestedFactory, address _resolver) {
require(_nestedFactory != address(0), "AO-SCRIPT: INVALID_FACTORY_ADDR");
require(_resolver != address(0), "AO-SCRIPT: INVALID_RESOLVER_ADDR");
nestedFactory = _nestedFactory;
resolver = _resolver;
}

/// @notice Call NestedFactory and OperatorResolver to add an operator.
/// @param operator The operator to add
/// @param name The operator bytes32 name
function addOperator(IOperatorResolver.Operator memory operator, bytes32 name) external {
require(operator.implementation != address(0), "AO-SCRIPT: INVALID_IMPL_ADDRESS");

// Init arrays with length 1 (only one operator to import)
bytes32[] memory names = new bytes32[](1);
IOperatorResolver.Operator[] memory operatorsToImport = new IOperatorResolver.Operator[](1);
MixinOperatorResolver[] memory destinations = new MixinOperatorResolver[](1);

names[0] = name;
operatorsToImport[0] = operator;
destinations[0] = MixinOperatorResolver(nestedFactory);

IOperatorResolver(resolver).importOperators(names, operatorsToImport, destinations);

ITransparentUpgradeableProxy(nestedFactory).upgradeToAndCall(
ITransparentUpgradeableProxy(nestedFactory).implementation(),
abi.encodeWithSelector(INestedFactory.addOperator.selector, name)
);
}

/// @notice Deploy and add operators
/// @dev One address and multiple selectors/names
/// @param bytecode Operator implementation bytecode
/// @param operators Array of tuples => bytes32/bytes4 (name and selector)
function deployAddOperators(bytes memory bytecode, tupleOperator[] memory operators) external {
uint256 operatorLength = operators.length;
require(operatorLength != 0, "DAO-SCRIPT: INVALID_OPERATOR_LEN");
require(bytecode.length != 0, "DAO-SCRIPT: BYTECODE_ZERO");

address deployedAddress;
assembly {
deployedAddress := create(0, add(bytecode, 0x20), mload(bytecode))
}
require(deployedAddress != address(0), "DAO-SCRIPT: FAILED_DEPLOY");

// Init arrays
bytes32[] memory names = new bytes32[](operatorLength);
IOperatorResolver.Operator[] memory operatorsToImport = new IOperatorResolver.Operator[](operatorLength);

for (uint256 i; i < operatorLength; i++) {
names[i] = operators[i].name;
operatorsToImport[i] = IOperatorResolver.Operator(deployedAddress, operators[i].selector);
}

// Only the NestedFactory as destination
MixinOperatorResolver[] memory destinations = new MixinOperatorResolver[](1);
destinations[0] = MixinOperatorResolver(nestedFactory);

// Start importing operators
IOperatorResolver(resolver).importOperators(names, operatorsToImport, destinations);

// Add all the operators to the factory
for (uint256 i; i < operatorLength; i++) {
ITransparentUpgradeableProxy(nestedFactory).upgradeToAndCall(
ITransparentUpgradeableProxy(nestedFactory).implementation(),
abi.encodeWithSelector(INestedFactory.addOperator.selector, operators[i].name)
);
}
}

/// @notice Call NestedFactory and OperatorResolver to remove an operator.
/// @param name The operator bytes32 name
function removeOperator(bytes32 name) external {
ITransparentUpgradeableProxy(nestedFactory).upgradeToAndCall(
ITransparentUpgradeableProxy(nestedFactory).implementation(),
abi.encodeWithSelector(INestedFactory.removeOperator.selector, name)
);

// Init arrays with length 1 (only one operator to remove)
bytes32[] memory names = new bytes32[](1);
IOperatorResolver.Operator[] memory operatorsToImport = new IOperatorResolver.Operator[](1);
MixinOperatorResolver[] memory destinations = new MixinOperatorResolver[](1);

names[0] = name;
operatorsToImport[0] = IOperatorResolver.Operator({ implementation: address(0), selector: bytes4(0) });
destinations[0] = MixinOperatorResolver(nestedFactory);

IOperatorResolver(resolver).importOperators(names, operatorsToImport, destinations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importOperators It does not look like we're removing an operator here. Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing something here, I'll take a look at NestedFactory's removeOperator method before finishing the review

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think the OperatorResolver should have had a removeOperators method, but this works too.

}
}
32 changes: 0 additions & 32 deletions contracts/governance/scripts/RemoveOperator.sol

This file was deleted.

14 changes: 11 additions & 3 deletions contracts/governance/scripts/UpdateFees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.11;

import "../../interfaces/INestedFactory.sol";
import "../../interfaces/external/ITransparentUpgradeableProxy.sol";

contract UpdateFees {
/// @notice Update atomically the entryFees and exitFees
Expand All @@ -10,11 +11,18 @@ contract UpdateFees {
/// @param exitFees The exit fees
/// @dev Called using delegatecall by the NestedFactory owner
function updateFees(
INestedFactory nestedFactory,
ITransparentUpgradeableProxy nestedFactory,
uint256 entryFees,
uint256 exitFees
) external {
nestedFactory.setEntryFees(entryFees);
nestedFactory.setExitFees(exitFees);
nestedFactory.upgradeToAndCall(
nestedFactory.implementation(),
abi.encodeWithSelector(INestedFactory.setEntryFees.selector, entryFees)
);

nestedFactory.upgradeToAndCall(
nestedFactory.implementation(),
abi.encodeWithSelector(INestedFactory.setExitFees.selector, exitFees)
);
}
}
14 changes: 14 additions & 0 deletions contracts/interfaces/external/ITransparentUpgradeableProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.11;

interface ITransparentUpgradeableProxy {
function admin() external returns (address);

function implementation() external returns (address);

function changeAdmin(address newAdmin) external;

function upgradeTo(address newImplementation) external;

function upgradeToAndCall(address newImplementation, bytes calldata data) external payable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ const delay = async (ms: number) => new Promise(res => setTimeout(res, ms));

async function main(): Promise<void> {
console.log("Deploy DeployAddOperators : ");

const nestedFactoryAddr = "";
const operatorResolverAddr = "";

// Get Factories
const scriptDeployAddOperatorsFactory = await ethers.getContractFactory("DeployAddOperators");
const scriptDeployAddOperators = await scriptDeployAddOperatorsFactory.deploy();
await scriptDeployAddOperators.deployed();
const operatorScriptsFactory = await ethers.getContractFactory("OperatorScripts");
const operatorScripts = await operatorScriptsFactory.deploy(nestedFactoryAddr, operatorResolverAddr);
await operatorScripts.deployed();

console.log("DeployAddOperators Deployed : ", scriptDeployAddOperators.address);
console.log("OperatorScripts Deployed : ", operatorScripts.address);

await delay(60000);

await hre.run("verify:verify", {
address: scriptDeployAddOperators.address,
address: operatorScripts.address,
constructorArguments: [],
});
}
Expand Down
10 changes: 4 additions & 6 deletions scripts/operators/ParaswapOperator/generateCalldata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const context = JSON.parse(JSON.stringify(addresses));
async function main(): Promise<void> {
// Factories
const paraswapOperatorFactory = await ethers.getContractFactory("ParaswapOperator");
const scriptDeployAddOperatorsFactory = await ethers.getContractFactory("DeployAddOperators");
const operatorScriptsFactory = await ethers.getContractFactory("OperatorScripts");
const ownerProxyFactory = await ethers.getContractFactory("OwnerProxy");

// Addresses
const nestedFactoryAddr = context[chainId].NestedFactoryProxy;
const tokenTransferProxy = "0x216B4B4Ba9F3e719726886d34a177484278Bfcae";
const augustusSwapper = "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57";
const tokenTransferProxy = "";
const augustusSwapper = "";

// Concat deploy bytecode + args
const deployCalldata = abiCoder.encode(
Expand All @@ -23,8 +22,7 @@ async function main(): Promise<void> {
);

// Generate DeployAddOperators script calldata
const calldata = scriptDeployAddOperatorsFactory.interface.encodeFunctionData("deployAddOperators", [
nestedFactoryAddr,
const calldata = operatorScriptsFactory.interface.encodeFunctionData("deployAddOperators", [
deployCalldata,
[
{
Expand Down
4 changes: 2 additions & 2 deletions scripts/operators/ParaswapOperator/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ async function main(): Promise<void> {
// Factories
const paraswapOperatorAddr = "";

const tokenTransferProxy = "0x216B4B4Ba9F3e719726886d34a177484278Bfcae";
const augustusSwapper = "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57";
const tokenTransferProxy = "";
const augustusSwapper = "";

await hre.run("verify:verify", {
address: paraswapOperatorAddr,
Expand Down
Loading