-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: OwnerProxy #116
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3001dde
feat: ownerproxy impl
maximebrugel 0eca3a8
test: add updateFees/AddOperator script and tests
maximebrugel 9f64b8b
test: AddOperator script test
maximebrugel 5ed3b60
add dsproxy fork ref
maximebrugel f8141b6
build: add OwnerProxy to json
maximebrugel cd225ab
script: Deploy OwnerProxy
maximebrugel 2d501d1
fix: PR fixes
maximebrugel 679ab40
feat: deploy/add operator script
maximebrugel a16d873
fix: typo "cant"
maximebrugel d505e74
fix: PR fixes
maximebrugel b1554e4
Merge branch 'master' into owner-proxy
maximebrugel 7f53352
scripts: Deploy scripts and generate calldata
maximebrugel 3da01cb
fix: wrong address.json attribute
maximebrugel c63cad1
fix: finalize calldata owneproxy
maximebrugel 19c67c6
fix: OwnerProxy as admin
maximebrugel 4d78cd9
deploy OperatorScripts
maximebrugel bb5285d
scripts: generate calldata add/deploy FlatOperator
maximebrugel 9e6c20a
remove addresses
maximebrugel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
contracts/interfaces/external/ITransparentUpgradeableProxy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.