-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from xWerk/feat/upgradeable-payment-module
- Loading branch information
Showing
23 changed files
with
464 additions
and
185 deletions.
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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Directories | ||
cache/ | ||
out/ | ||
out-optimized/ | ||
node_modules | ||
|
||
# Coverage | ||
|
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,3 @@ | ||
[submodule "lib/openzeppelin-foundry-upgrades"] | ||
path = lib/openzeppelin-foundry-upgrades | ||
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades |
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
Submodule openzeppelin-foundry-upgrades
added at
16e0ae
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
{ | ||
"scripts": { | ||
"build": "forge build", | ||
"lint": "bun run lint:sol && bun run prettier:check", | ||
"lint:sol": "forge fmt --check && bun solhint \"{precompiles,script,src,test}/**/*.sol\"", | ||
"prettier:check": "prettier --check --plugin=prettier-plugin-solidity \"**/*.{json,md,svg,yml}\"", | ||
"prettier:write": "prettier --write --plugin=prettier-plugin-solidity \"**/*.{json,md,svg,yml,sol}\"" | ||
}, | ||
"devDependencies": { | ||
"forge-std": "github:foundry-rs/forge-std#v1.9.4", | ||
"prettier": "^3.3.3", | ||
"prettier-plugin-solidity": "^1.4.1", | ||
"solhint": "^5.0.3" | ||
}, | ||
"dependencies": { | ||
"@openzeppelin/contracts": "^5.1.0", | ||
"@prb/math": "^4.1.0", | ||
"@sablier/v2-core": "^1.2.0", | ||
"@thirdweb-dev/contracts": "^3.15.0" | ||
} | ||
"scripts": { | ||
"build": "forge build", | ||
"lint": "bun run lint:sol && bun run prettier:check", | ||
"lint:sol": "forge fmt --check && bun solhint \"{precompiles,script,src,test}/**/*.sol\"", | ||
"prettier:check": "prettier --check --plugin=prettier-plugin-solidity \"**/*.{json,md,svg,yml}\"", | ||
"prettier:write": "prettier --write --plugin=prettier-plugin-solidity \"**/*.{json,md,svg,yml,sol}\"" | ||
}, | ||
"devDependencies": { | ||
"forge-std": "github:foundry-rs/forge-std#v1.9.4", | ||
"prettier": "^3.3.3", | ||
"prettier-plugin-solidity": "^1.4.1", | ||
"solhint": "^5.0.3" | ||
}, | ||
"dependencies": { | ||
"@openzeppelin/contracts": "^5.1.0", | ||
"@openzeppelin/contracts-upgradeable": "^5.1.0", | ||
"@prb/math": "^4.1.0", | ||
"@sablier/v2-core": "^1.2.0", | ||
"@thirdweb-dev/contracts": "^3.15.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.26; | ||
|
||
import { BaseScript } from "./Base.s.sol"; | ||
import { PaymentModule } from "./../src/modules/payment-module/PaymentModule.sol"; | ||
import { StationRegistry } from "./../src/StationRegistry.sol"; | ||
import { ModuleKeeper } from "./../src/ModuleKeeper.sol"; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { Options } from "./../lib/openzeppelin-foundry-upgrades/src/Options.sol"; | ||
import { Core } from "./../lib/openzeppelin-foundry-upgrades/src/internal/Core.sol"; | ||
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol"; | ||
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol"; | ||
import { IEntryPoint } from "@thirdweb/contracts/prebuilts/account/interface/IEntrypoint.sol"; | ||
import { ud } from "@prb/math/src/UD60x18.sol"; | ||
|
||
/// @notice Deploys at deterministic addresses across chains the core contracts of the Werk Protocol | ||
/// @dev Reverts if any contract has already been deployed | ||
contract DeployDeterministicCore is BaseScript { | ||
/// @dev By using a salt, Forge will deploy the contract via a deterministic CREATE2 factory | ||
/// https://book.getfoundry.sh/tutorials/create2-tutorial?highlight=deter#deterministic-deployment-using-create2 | ||
function run( | ||
string memory create2Salt, | ||
ISablierV2LockupLinear sablierLockupLinear, | ||
ISablierV2LockupTranched sablierLockupTranched, | ||
address initialOwner, | ||
address brokerAccount, | ||
IEntryPoint entrypoint | ||
) | ||
public | ||
virtual | ||
broadcast | ||
returns (ModuleKeeper moduleKeeper, StationRegistry stationRegistry, PaymentModule paymentModule) | ||
{ | ||
bytes32 salt = bytes32(abi.encodePacked(create2Salt)); | ||
|
||
// Deterministically deploy the {ModuleKeeper} contract | ||
moduleKeeper = new ModuleKeeper{ salt: salt }(initialOwner); | ||
|
||
// Deterministically deploy the {StationRegistry} contract | ||
stationRegistry = new StationRegistry{ salt: salt }(initialOwner, entrypoint, moduleKeeper); | ||
|
||
// Deterministically deploy the {PaymentModule} module | ||
paymentModule = PaymentModule( | ||
deployDetermisticUUPSProxy( | ||
salt, | ||
abi.encode(sablierLockupLinear, sablierLockupTranched), | ||
"PaymentModule.sol", | ||
abi.encodeCall(PaymentModule.initialize, (initialOwner, brokerAccount, ud(0))) | ||
) | ||
); | ||
|
||
// Add the {PaymentModule} module to the allowlist of the {ModuleKeeper} | ||
moduleKeeper.addToAllowlist(address(paymentModule)); | ||
} | ||
|
||
/// @dev Deploys a UUPS proxy at deterministic addresses across chains based on a provided salt | ||
/// @param salt Salt to use for deterministic deployment | ||
/// @param contractName The name of the implementation contract | ||
/// @param initializerData The ABI encoded call to be made to the initialize method | ||
function deployDetermisticUUPSProxy( | ||
bytes32 salt, | ||
bytes memory constructorData, | ||
string memory contractName, | ||
bytes memory initializerData | ||
) | ||
internal | ||
returns (address) | ||
{ | ||
Options memory opts; | ||
opts.constructorData = constructorData; | ||
|
||
address impl = Core.deployImplementation(contractName, opts); | ||
|
||
return address(new ERC1967Proxy{ salt: salt }(impl, initializerData)); | ||
} | ||
} |
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,64 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.26; | ||
|
||
import { BaseScript } from "./Base.s.sol"; | ||
import { PaymentModule } from "./../src/modules/payment-module/PaymentModule.sol"; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { Options } from "./../lib/openzeppelin-foundry-upgrades/src/Options.sol"; | ||
import { Core } from "./../lib/openzeppelin-foundry-upgrades/src/internal/Core.sol"; | ||
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol"; | ||
import { ISablierV2LockupTranched } from "@sablier/v2-core/src/interfaces/ISablierV2LockupTranched.sol"; | ||
import { ud } from "@prb/math/src/UD60x18.sol"; | ||
|
||
/// @notice Deploys at deterministic addresses across chains an instance of {PaymentModule} | ||
/// @dev Reverts if any contract has already been deployed | ||
contract DeployDeterministicPaymentModule is BaseScript { | ||
/// @dev By using a salt, Forge will deploy the contract via a deterministic CREATE2 factory | ||
/// https://book.getfoundry.sh/tutorials/create2-tutorial?highlight=deter#deterministic-deployment-using-create2 | ||
function run( | ||
string memory create2Salt, | ||
ISablierV2LockupLinear sablierLockupLinear, | ||
ISablierV2LockupTranched sablierLockupTranched, | ||
address initialOwner, | ||
address brokerAccount | ||
) | ||
public | ||
virtual | ||
broadcast | ||
returns (PaymentModule paymentModule) | ||
{ | ||
bytes32 salt = bytes32(abi.encodePacked(create2Salt)); | ||
|
||
// Deterministically deploy the {PaymentModule} module | ||
paymentModule = PaymentModule( | ||
deployDetermisticUUPSProxy( | ||
salt, | ||
abi.encode(sablierLockupLinear, sablierLockupTranched), | ||
"PaymentModule.sol", | ||
abi.encodeCall(PaymentModule.initialize, (initialOwner, brokerAccount, ud(0))) | ||
) | ||
); | ||
} | ||
|
||
/// @dev Deploys a UUPS proxy at deterministic addresses across chains based on a provided salt | ||
/// @param salt Salt to use for deterministic deployment | ||
/// @param contractName The name of the implementation contract | ||
/// @param initializerData The ABI encoded call to be made to the initialize method | ||
function deployDetermisticUUPSProxy( | ||
bytes32 salt, | ||
bytes memory constructorData, | ||
string memory contractName, | ||
bytes memory initializerData | ||
) | ||
internal | ||
returns (address) | ||
{ | ||
Options memory opts; | ||
opts.constructorData = constructorData; | ||
|
||
address impl = Core.deployImplementation(contractName, opts); | ||
|
||
return address(new ERC1967Proxy{ salt: salt }(impl, initializerData)); | ||
} | ||
} |
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.