Skip to content

Commit

Permalink
Create a new deployment mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSandwich committed Oct 9, 2024
1 parent 3aeccb7 commit 637f1bb
Show file tree
Hide file tree
Showing 20 changed files with 971 additions and 422 deletions.
47 changes: 14 additions & 33 deletions deployments/filecoin-test.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
{
"Chain": "filecoin",
"Deployment time": "2024-08-12T22:50:45Z",
"Commit hash": "0b04137dff43f83789f4d10169d9a4d78e323332",
"Wallet": "0xEF4B994f97092fD22B8a880c47F053910788471b",
"Safe singleton factory": "0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7",
"CREATE3 factory": "0xe9BE461efaB6f9079741da3b180249F81e66A461",
"DripsDeployer salt": "DripsDeployerTest1",
"DripsDeployer": "0xCD29c13A0f40C6E1a1783f1b0B69D72529CE183F",
"Drips": "0x29252acF5a3dA105CB3aC245B7758F6e50281ba7",
"Drips cycle seconds": "604800 [6.048e5]",
"Drips logic": "0x1ADE6713A488A8AE1DA66b452aCb3DD1821aeB7D",
"Drips admin": "0xEF4B994f97092fD22B8a880c47F053910788471b",
"Caller": "0x6171a47dDc84AF3e138D6d84c5b5D1bFD35615a3",
"AddressDriver": "0xE13A4f3671ee451F81Df3aa1AEb6653e4c33D5e0",
"AddressDriver ID": "0",
"AddressDriver logic": "0x3288D4C292080643E9041602cf0960bfe8fB44F0",
"AddressDriver admin": "0xEF4B994f97092fD22B8a880c47F053910788471b",
"NFTDriver": "0xE03d510d927816f3482C3C0204F14203403c0ee2",
"NFTDriver ID": "1",
"NFTDriver logic": "0xe349116Ab1F17819b080d519B51914DD1D5b6057",
"NFTDriver admin": "0xEF4B994f97092fD22B8a880c47F053910788471b",
"ImmutableSplitsDriver": "0xf07bF47a4a118792f5392560C27EE6530Ca36cA3",
"ImmutableSplitsDriver ID": "2",
"ImmutableSplitsDriver logic": "0x01Ca3Edd523913A7402F682eD1f758C2Ee47e72f",
"ImmutableSplitsDriver admin": "0xEF4B994f97092fD22B8a880c47F053910788471b",
"RepoDriver": "0x249e35aC49ccC4B1F0688Bc4c0bFA866a1b1E3fE",
"RepoDriver ID": "3",
"Gelato Automate": "0x83444851B04Af09e3F2dA745F1AC5F580bB775C6",
"RepoDriver IPFS CID": "",
"RepoDriver max requests per block": "0",
"RepoDriver max requests per 31 days": "0",
"RepoDriver logic": "0xB47AFebbf18Bb7126289eF068097E559E0cC76e4",
"RepoDriver admin": "0xEF4B994f97092fD22B8a880c47F053910788471b"
"AddressDriver": "0xEFcd912a5a67C3a7Cc70a2Fb9aa17781bf1cE68F",
"Caller": "0x7f2457421718A541B9Ee01E2F77F8BA749055F3b",
"Deployer": "0xEF4B994f97092fD22B8a880c47F053910788471b",
"Drips": "0x0B71C2a08d27E86d3841A6772332DEde0bc8DCa5",
"Drips cycle seconds": 86400,
"DripsDeployer": "0x79f3e7Aa55D39bBD42de31677B715B2e4D6e8ab0",
"GiversRegistry": "0x1F83E99813941a9bd701342560BFFaC794D707d1",
"ImmutableSplitsDriver": "0x990806c7EFC1C26be162a46F821ca281618F28AA",
"LZBridgedGovernor": "0x6bC5C5D7dA80dC1c30677852ce9AA01df368E76f",
"NFTDriver": "0x1397579E87AB255C8474907183B074947eBa7338",
"NativeTokenUnwrapper": "0x8A388BE3fb93C28b66365DCbf3eAc344690BD1C4",
"RepoDriver": "0xf3aE6ADDeEE195e91380F5F9Ce73698460BAdf79",
"RepoDriver tasks owner": "0x6D3A0fAE4FBa0f543b9e3280E85F4e4f59ba3D54",
"Salt": "test5"
}
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ evm_version = 'shanghai'
optimizer_runs = 7_700
verbosity = 1
fuzz_runs = 5
script = 'scripts'
fs_permissions = [{ access = "read-write", path = "./"}]
[fmt]
line_length = 100
[fuzz]
Expand Down
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions script/FilecoinDeploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {console, Script} from "forge-std/Script.sol";

import {addressDriverModuleData} from "script/modules/AddressDriver.sol";
import {
axelarBridgedGovernorModule,
axelarBridgedGovernorModuleData,
IAxelarGMPGateway
} from "script/modules/AxelarBridgedGovernor.sol";
import {callerModuleData} from "script/modules/Caller.sol";
import {dripsModuleData} from "script/modules/Drips.sol";
import {giversRegistryModuleData, IWrappedNativeToken} from "script/modules/GiversRegistry.sol";
import {immutableSplitsDriverModuleData} from "script/modules/ImmutableSplitsDriver.sol";
import {nativeTokenUnwrapperModuleData} from "script/modules/NativeTokenUnwrapper.sol";
import {nftDriverModuleData} from "script/modules/NFTDriver.sol";
import {IAutomate, repoDriverModuleData} from "script/modules/RepoDriver.sol";
import {deployCreate3Factory, ICreate3Factory} from "script/utils/Create3Factory.sol";
import {writeDeploymentJson} from "script/utils/DeploymentJson.sol";
import {
deployModulesDeployer, ModulesDeployer, ModuleData
} from "script/utils/ModulesDeployer.sol";

/// @dev As of 09.10.2024 Foundry badly estimates Filecoin gas usage.
/// To avoid the out of gas errors, pass `--gas-estimate-multiplier 80000` to `forge script`.
contract FilecoinDeploy is Script {
function run() public {
require(block.chainid == 314, "Must be run on Filecoin");
string memory salt = vm.envString("SALT");

vm.startBroadcast();
ICreate3Factory create3Factory = deployCreate3Factory();
ModulesDeployer modulesDeployer =
deployModulesDeployer(create3Factory, bytes32(bytes(salt)), msg.sender);

ModuleData[] memory modules = new ModuleData[](1);
modules[0] = axelarBridgedGovernorModuleData({
modulesDeployer: modulesDeployer,
// Taken from https://docs.axelar.dev/dev/reference/mainnet-contract-addresses/
gateway: IAxelarGMPGateway(0xe432150cce91c13a887f7D836923d5597adD8E31),
ownerChain: "Ethereum",
// Radworks governance on Ethereum controlling the bridge.
owner: 0x8dA8f82d2BbDd896822de723F55D6EdF416130ba
});
modulesDeployer.deployModules(modules);

address admin =
address(axelarBridgedGovernorModule(modulesDeployer).axelarBridgedGovernor());

modules = new ModuleData[](2);
modules[0] = callerModuleData(modulesDeployer);
modules[1] =
dripsModuleData({modulesDeployer: modulesDeployer, admin: admin, cycleSecs: 1 days});
modulesDeployer.deployModules(modules);

modules = new ModuleData[](2);
modules[0] = addressDriverModuleData(modulesDeployer, admin);
modules[1] = nftDriverModuleData(modulesDeployer, admin);
modulesDeployer.deployModules(modules);

modules = new ModuleData[](2);
modules[0] = immutableSplitsDriverModuleData(modulesDeployer, admin);
modules[1] = repoDriverModuleData({
modulesDeployer: modulesDeployer,
admin: admin,
// Taken from https://docs.gelato.network/web3-services/web3-functions/contract-addresses
gelatoAutomate: IAutomate(0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0),
// Deployed from https://github.com/drips-network/contracts-gelato-web3-function
ipfsCid: "QmeP5ETCt7bZLMtQeFRmJNm5mhYaGgM3GNvExQ4PP12whD",
// Calculated to saturate the Gelato free tier giving 200K GU.
// Assumes that each requests costs up to 11 GU (5 seconds of CPU + 1 transaction).
// The penalty-free throughput is 1 request per 3 minutes.
maxRequestsPerBlock: 80,
maxRequestsPer31Days: 18000
});
modulesDeployer.deployModules(modules);

// Take from https://docs.filecoin.io/smart-contracts/advanced/wrapped-fil
IWrappedNativeToken wfil = IWrappedNativeToken(0x60E1773636CF5E4A227d9AC24F20fEca034ee25A);
modules = new ModuleData[](2);
modules[0] = giversRegistryModuleData(modulesDeployer, admin, wfil);
modules[1] = nativeTokenUnwrapperModuleData(modulesDeployer, wfil);
modulesDeployer.deployModules(modules);

vm.stopBroadcast();

writeDeploymentJson(vm, modulesDeployer, salt);
}
}
53 changes: 53 additions & 0 deletions script/modules/AddressDriver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {create3ManagedProxy} from "script/utils/Create3Helpers.sol";
import {callerModule} from "script/modules/Caller.sol";
import {Drips, dripsModule, DripsModule} from "script/modules/Drips.sol";
import {
isModuleDeployed,
ModulesDeployer,
getModule,
Module,
ModuleData
} from "script/utils/ModulesDeployer.sol";
import {AddressDriver} from "src/AddressDriver.sol";

bytes32 constant ADDRESS_DRIVER_MODULE_SALT = "AddressDriverModule";

function isAddressDriverModuleDeployed(ModulesDeployer modulesDeployer) view returns (bool yes) {
return isModuleDeployed(modulesDeployer, ADDRESS_DRIVER_MODULE_SALT);
}

function addressDriverModule(ModulesDeployer modulesDeployer) view returns (AddressDriverModule) {
return AddressDriverModule(getModule(modulesDeployer, ADDRESS_DRIVER_MODULE_SALT));
}

function addressDriverModuleData(ModulesDeployer modulesDeployer, address admin)
pure
returns (ModuleData memory)
{
bytes memory args = abi.encode(modulesDeployer, admin);
return ModuleData({
salt: ADDRESS_DRIVER_MODULE_SALT,
initCode: abi.encodePacked(type(AddressDriverModule).creationCode, args),
value: 0
});
}

contract AddressDriverModule is Module {
AddressDriver public immutable addressDriver;

constructor(ModulesDeployer modulesDeployer, address admin)
Module(modulesDeployer, ADDRESS_DRIVER_MODULE_SALT)
{
DripsModule dripsModule_ = dripsModule(modulesDeployer);
Drips drips = dripsModule_.drips();
address forwarder = address(callerModule(modulesDeployer).caller());
uint32 driverId = 0;
AddressDriver logic = new AddressDriver(drips, forwarder, driverId);
address proxy = create3ManagedProxy(modulesDeployer, "AddressDriver", logic, admin, "");
addressDriver = AddressDriver(proxy);
dripsModule_.claimDriverId(ADDRESS_DRIVER_MODULE_SALT, driverId, proxy);
}
}
58 changes: 58 additions & 0 deletions script/modules/AxelarBridgedGovernor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {create3GovernorProxy} from "script/utils/Create3Helpers.sol";
import {
isModuleDeployed,
ModulesDeployer,
getModule,
Module,
ModuleData
} from "script/utils/ModulesDeployer.sol";
import {AxelarBridgedGovernor, IAxelarGMPGateway} from "src/BridgedGovernor.sol";

bytes32 constant AXELAR_BRIDGED_GOVERNOR_MODULE_SALT = "AxelarBridgedGovernorModule";

function isAxelarBridgedGovernorModuleDeployed(ModulesDeployer modulesDeployer)
view
returns (bool yes)
{
return isModuleDeployed(modulesDeployer, AXELAR_BRIDGED_GOVERNOR_MODULE_SALT);
}

function axelarBridgedGovernorModule(ModulesDeployer modulesDeployer)
view
returns (AxelarBridgedGovernorModule)
{
return
AxelarBridgedGovernorModule(getModule(modulesDeployer, AXELAR_BRIDGED_GOVERNOR_MODULE_SALT));
}

function axelarBridgedGovernorModuleData(
ModulesDeployer modulesDeployer,
IAxelarGMPGateway gateway,
string memory ownerChain,
address owner
) pure returns (ModuleData memory) {
bytes memory args = abi.encode(modulesDeployer, gateway, ownerChain, owner);
return ModuleData({
salt: AXELAR_BRIDGED_GOVERNOR_MODULE_SALT,
initCode: abi.encodePacked(type(AxelarBridgedGovernorModule).creationCode, args),
value: 0
});
}

contract AxelarBridgedGovernorModule is Module {
AxelarBridgedGovernor public immutable axelarBridgedGovernor;

constructor(
ModulesDeployer modulesDeployer,
IAxelarGMPGateway gateway,
string memory ownerChain,
address owner
) Module(modulesDeployer, AXELAR_BRIDGED_GOVERNOR_MODULE_SALT) {
AxelarBridgedGovernor logic = new AxelarBridgedGovernor(gateway, ownerChain, owner);
address proxy = create3GovernorProxy(modulesDeployer, "AxelarBridgedGovernor", logic);
axelarBridgedGovernor = AxelarBridgedGovernor(payable(proxy));
}
}
40 changes: 40 additions & 0 deletions script/modules/Caller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {create3} from "script/utils/Create3Helpers.sol";
import {
isModuleDeployed,
ModulesDeployer,
getModule,
Module,
ModuleData
} from "script/utils/ModulesDeployer.sol";
import {Caller} from "src/Caller.sol";

bytes32 constant CALLER_MODULE_SALT = "CallerModule";

function isCallerModuleDeployed(ModulesDeployer modulesDeployer) view returns (bool yes) {
return isModuleDeployed(modulesDeployer, CALLER_MODULE_SALT);
}

function callerModule(ModulesDeployer modulesDeployer) view returns (CallerModule) {
return CallerModule(getModule(modulesDeployer, CALLER_MODULE_SALT));
}

function callerModuleData(ModulesDeployer modulesDeployer) pure returns (ModuleData memory) {
bytes memory args = abi.encode(modulesDeployer);
return ModuleData({
salt: CALLER_MODULE_SALT,
initCode: abi.encodePacked(type(CallerModule).creationCode, args),
value: 0
});
}

contract CallerModule is Module {
Caller public immutable caller;

constructor(ModulesDeployer modulesDeployer) Module(modulesDeployer, CALLER_MODULE_SALT) {
// slither-disable-next-line too-many-digits
caller = Caller(create3(modulesDeployer, "Caller", type(Caller).creationCode, ""));
}
}
57 changes: 57 additions & 0 deletions script/modules/Drips.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.20;

import {create3ManagedProxy} from "script/utils/Create3Helpers.sol";
import {
isModuleDeployed,
ModulesDeployer,
getModule,
Module,
ModuleData
} from "script/utils/ModulesDeployer.sol";
import {Drips} from "src/Drips.sol";

bytes32 constant DRIPS_MODULE_SALT = "DripsModule";

function isDripsModuleDeployed(ModulesDeployer modulesDeployer) view returns (bool yes) {
return isModuleDeployed(modulesDeployer, DRIPS_MODULE_SALT);
}

function dripsModule(ModulesDeployer modulesDeployer) view returns (DripsModule) {
return DripsModule(getModule(modulesDeployer, DRIPS_MODULE_SALT));
}

function dripsModuleData(ModulesDeployer modulesDeployer, address admin, uint32 cycleSecs)
pure
returns (ModuleData memory)
{
bytes memory args = abi.encode(modulesDeployer, admin, cycleSecs);
return ModuleData({
salt: DRIPS_MODULE_SALT,
initCode: abi.encodePacked(type(DripsModule).creationCode, args),
value: 0
});
}

contract DripsModule is Module {
Drips public immutable drips;

constructor(ModulesDeployer modulesDeployer, address admin, uint32 cycleSecs)
Module(modulesDeployer, DRIPS_MODULE_SALT)
{
Drips logic = new Drips(cycleSecs);
address proxy = create3ManagedProxy(modulesDeployer, "Drips", logic, admin, "");
drips = Drips(proxy);
for (uint256 i = 0; i < 100; i++) {
// slither-disable-next-line calls-loop,unused-return
drips.registerDriver(address(this));
}
}

function claimDriverId(bytes32 senderSalt, uint32 driverId, address driver)
public
onlyModule(senderSalt)
{
drips.updateDriverAddress(driverId, driver);
}
}
Loading

0 comments on commit 637f1bb

Please sign in to comment.