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

Switch RepoDriver to Gelato #352

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/chainlink"]
path = lib/chainlink
url = https://github.com/smartcontractkit/chainlink
[submodule "lib/LayerZero-v2"]
path = lib/LayerZero-v2
url = https://github.com/LayerZero-Labs/LayerZero-v2
[submodule "lib/gelato-automate"]
path = lib/gelato-automate
url = https://github.com/gelatodigital/automate
1 change: 0 additions & 1 deletion lib/chainlink
Submodule chainlink deleted from 594387
1 change: 1 addition & 0 deletions lib/gelato-automate
Submodule gelato-automate added at ae1cac
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/
chainlink/=lib/chainlink/contracts/src/v0.8/
layer-zero-v2/=lib/LayerZero-v2/
gelato-automate/=lib/gelato-automate/contracts/
42 changes: 22 additions & 20 deletions src/DripsDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Drips} from "./Drips.sol";
import {ImmutableSplitsDriver} from "./ImmutableSplitsDriver.sol";
import {Managed, ManagedProxy} from "./Managed.sol";
import {NFTDriver} from "./NFTDriver.sol";
import {OperatorInterface, RepoDriver} from "./RepoDriver.sol";
import {RepoDriver} from "./RepoDriver.sol";
import {Ownable2Step} from "openzeppelin-contracts/access/Ownable2Step.sol";
import {Address} from "openzeppelin-contracts/utils/Address.sol";

Expand Down Expand Up @@ -102,19 +102,28 @@ abstract contract ProxyDeployerModule is BaseModule {
bytes32 public immutable proxySalt = "proxy";
address public proxyAdmin;
address public logic;
bytes public proxyDelegateCalldata;

function proxy() public view returns (address) {
return Create3Factory.getDeployed(proxySalt);
}

function proxyArgs() public view returns (bytes memory) {
return abi.encode(logic, proxyAdmin);
return abi.encode(logic, proxyAdmin, proxyDelegateCalldata);
}

function logicArgs() public view virtual returns (bytes memory);

// slither-disable-next-line reentrancy-benign
function _deployProxy(address proxyAdmin_, bytes memory logicCreationCode) internal {
_deployProxy(proxyAdmin_, logicCreationCode, "");
}

// slither-disable-next-line reentrancy-benign
function _deployProxy(
address proxyAdmin_,
bytes memory logicCreationCode,
bytes memory proxyDelegateCalldata_
) internal {
// Deploy logic
address logic_;
bytes memory logicInitCode = abi.encodePacked(logicCreationCode, logicArgs());
Expand All @@ -126,6 +135,7 @@ abstract contract ProxyDeployerModule is BaseModule {
logic = logic_;
// Deploy proxy
proxyAdmin = proxyAdmin_;
proxyDelegateCalldata = proxyDelegateCalldata_;
// slither-disable-next-line too-many-digits
bytes memory proxyInitCode = abi.encodePacked(type(ManagedProxy).creationCode, proxyArgs());
Create3Factory.deploy(0, proxySalt, proxyInitCode);
Expand Down Expand Up @@ -283,35 +293,27 @@ contract ImmutableSplitsDriverModule is DriverModule(2) {
}

contract RepoDriverModule is CallerDependentModule, DriverModule(3) {
OperatorInterface public immutable operator;
bytes32 public immutable jobId;
uint96 public immutable defaultFee;
string public ipfsCid;

function args() public view override returns (bytes memory) {
return abi.encode(dripsDeployer, proxyAdmin, operator, jobId, defaultFee);
return abi.encode(dripsDeployer, proxyAdmin, ipfsCid);
}

constructor(
DripsDeployer dripsDeployer_,
address proxyAdmin_,
OperatorInterface operator_,
bytes32 jobId_,
uint96 defaultFee_
) BaseModule(dripsDeployer_, "RepoDriver") {
operator = operator_;
jobId = jobId_;
defaultFee = defaultFee_;
constructor(DripsDeployer dripsDeployer_, address proxyAdmin_, string memory ipfsCid_)
BaseModule(dripsDeployer_, "RepoDriver")
{
ipfsCid = ipfsCid_;
bytes memory data = abi.encodeCall(RepoDriver.updateGelatoTask, (ipfsCid_));
// slither-disable-next-line too-many-digits
_deployProxy(proxyAdmin_, type(RepoDriver).creationCode);
repoDriver().initializeAnyApiOperator(operator, jobId, defaultFee);
_deployProxy(proxyAdmin_, type(RepoDriver).creationCode, data);
}

function logicArgs() public view override returns (bytes memory) {
return abi.encode(_dripsModule().drips(), _callerModule().caller(), driverId);
}

function repoDriver() public view returns (RepoDriver) {
return RepoDriver(proxy());
return RepoDriver(payable(proxy()));
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/Managed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.20;
import {UUPSUpgradeable} from "openzeppelin-contracts/proxy/utils/UUPSUpgradeable.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol";
import {Address} from "openzeppelin-contracts/utils/Address.sol";
import {StorageSlot} from "openzeppelin-contracts/utils/StorageSlot.sol";

using EnumerableSet for EnumerableSet.AddressSet;
Expand Down Expand Up @@ -55,6 +56,15 @@ abstract contract Managed is UUPSUpgradeable {
_;
}

/// @notice Throws if called by any caller other than the admin.
/// May be called by anybody if delegated to from a constructor.
modifier onlyAdminOrConstructor() {
if (Address.isContract(address(this))) {
require(admin() == msg.sender, "Caller not the admin");
}
_;
}

/// @notice Throws if called by any caller other than the admin or a pauser.
modifier onlyAdminOrPauser() {
require(admin() == msg.sender || isPauser(msg.sender), "Caller not the admin or a pauser");
Expand Down Expand Up @@ -201,7 +211,12 @@ abstract contract Managed is UUPSUpgradeable {

/// @notice A generic proxy for contracts implementing `Managed`.
contract ManagedProxy is ERC1967Proxy {
constructor(Managed logic, address admin) ERC1967Proxy(address(logic), new bytes(0)) {
/// @param logic The initial implementation address of the proxy.
/// @param admin The initial admin of the proxy.
/// @param data If non-empty, used as calldata to delegate to `logic`.
constructor(Managed logic, address admin, bytes memory data)
ERC1967Proxy(address(logic), data)
{
_changeAdmin(admin);
}
}
Loading
Loading