From eabbe01627557db82a520a36842d4b3fbe10b88a Mon Sep 17 00:00:00 2001 From: aowheel Date: Mon, 9 Dec 2024 20:28:13 +0900 Subject: [PATCH] wip: issue147 --- .../splitscreator/SplitsCreatorFactory.sol | 31 +++++++++-- pkgs/contract/test/BigBang.ts | 6 +++ pkgs/contract/test/IntegrationTest.ts | 2 + pkgs/contract/test/SplitsCreator.ts | 52 +++++++++++++++---- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol b/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol index cd246f0..42caed9 100644 --- a/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol +++ b/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol @@ -5,9 +5,13 @@ pragma solidity ^0.8.24; import { LibClone } from "solady/src/utils/LibClone.sol"; import { SplitsCreator } from "./SplitsCreator.sol"; import { ISplitsCreator } from "./ISplitsCreator.sol"; -import { ERC2771ContextUpgradeable } from "./../ERC2771ContextUpgradeable.sol"; +import { ERC2771ContextUpgradeable, ContextUpgradeable } from "./../ERC2771ContextUpgradeable.sol"; +import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -contract SplitsCreatorFactory is ERC2771ContextUpgradeable { +contract SplitsCreatorFactory is + ERC2771ContextUpgradeable, + OwnableUpgradeable +{ event SplitCreatorCreated( address indexed creator, address indexed splitCreator, @@ -19,12 +23,15 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable { ); address public SPLITS_CREATOR_IMPLEMENTATION; + + address public BIG_BANG; function initialize( address _trustedForwarderAddress, address _splitsCreatorImplementation ) public initializer { __ERC2771Context_init(_trustedForwarderAddress); + __Ownable_init(_msgSender()); SPLITS_CREATOR_IMPLEMENTATION = _splitsCreatorImplementation; } @@ -37,6 +44,10 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable { address _fractionToken, bytes32 _salt ) external returns (address splitCreator) { + if (_msgSender() != BIG_BANG) { + revert("SplitsCreatorFactory: Only BigBang can call this function"); + } + splitCreator = LibClone.cloneDeterministic( SPLITS_CREATOR_IMPLEMENTATION, abi.encode( @@ -100,6 +111,18 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable { ); } + function setImplementation( + address _implementation + ) external onlyOwner { + SPLITS_CREATOR_IMPLEMENTATION = _implementation; + } + + function setBigBang( + address _bigBang + ) external onlyOwner { + BIG_BANG = _bigBang; + } + function _getSalt( uint256 _topHatId, address _trustedForwarder, @@ -126,7 +149,7 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable { function _msgSender() internal view - override(ERC2771ContextUpgradeable) + override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (address sender) { return super._msgSender(); @@ -135,7 +158,7 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable { function _msgData() internal view - override(ERC2771ContextUpgradeable) + override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (bytes calldata) { return super._msgData(); diff --git a/pkgs/contract/test/BigBang.ts b/pkgs/contract/test/BigBang.ts index dc30b5d..e9922df 100644 --- a/pkgs/contract/test/BigBang.ts +++ b/pkgs/contract/test/BigBang.ts @@ -105,6 +105,9 @@ describe("BigBang", () => { }); it("should execute bigbang", async () => { + // SplitsCreatorFactoryにBigBangアドレスをセット + SplitsCreatorFactory.write.setBigBang([BigBang.address]); + const txHash = await BigBang.write.bigbang( [ address1.account?.address!, @@ -321,6 +324,9 @@ describe("BigBang", () => { ["", 10000n, Hats.address, zeroAddress] ); + // SplitsCreatorFactoryにBigBangアドレスをセット + SplitsCreatorFactory.write.setBigBang([newBigBang.address]); + const txHash = await newBigBang.write.bigbang( [ address1.account?.address!, diff --git a/pkgs/contract/test/IntegrationTest.ts b/pkgs/contract/test/IntegrationTest.ts index 0aeae14..47339d4 100644 --- a/pkgs/contract/test/IntegrationTest.ts +++ b/pkgs/contract/test/IntegrationTest.ts @@ -124,6 +124,8 @@ describe("IntegrationTest", () => { }); it("should execute bigbang", async () => { + SplitsCreatorFactory.write.setBigBang([BigBang.address]); + const txHash = await BigBang.write.bigbang( [ deployer.account?.address!, diff --git a/pkgs/contract/test/SplitsCreator.ts b/pkgs/contract/test/SplitsCreator.ts index 710f74d..e17076d 100644 --- a/pkgs/contract/test/SplitsCreator.ts +++ b/pkgs/contract/test/SplitsCreator.ts @@ -33,6 +33,7 @@ import { SplitsWarehouse, } from "../helpers/deploy/Splits"; import { sqrt } from "../helpers/util/sqrt"; +import { BigBang, deployBigBang } from "../helpers/deploy/BigBang"; describe("SplitsCreator Factory", () => { let Hats: Hats; @@ -46,8 +47,11 @@ describe("SplitsCreator Factory", () => { let SplitsCreator_IMPL: SplitsCreator; let SplitsCreator: SplitsCreator; let FractionToken: FractionToken; + let BigBang: BigBang; let address1: WalletClient; + let relayer: WalletClient; + let publicClient: PublicClient; let topHatId: bigint; @@ -116,6 +120,9 @@ describe("SplitsCreator Factory", () => { "HatsTimeFrameModule", hatsTimeFrameModuleAddress ); + + [address1, relayer] = await viem.getWalletClients(); + publicClient = await viem.getPublicClient(); }); it("Should deploy SplitsCreatorFactory", async () => { @@ -138,6 +145,30 @@ describe("SplitsCreator Factory", () => { ).to.be.a("string"); }); + it("should deploy BigBang", async () => { + const { BigBang: _BigBang } = await deployBigBang({ + trustedForwarder: zeroAddress, + hatsContractAddress: Hats.address, + hatsModuleFacotryAddress: HatsModuleFactory.address, + hatsTimeFrameModule_impl: HatsTimeFrameModule_IMPL.address, + splitsCreatorFactoryAddress: SplitsCreatorFactory.address, + splitsFactoryV2Address: PullSplitsFactory.address, + fractionTokenAddress: FractionToken.address, + }); + + expect(_BigBang.address).to.not.be.undefined; + + BigBang = _BigBang; + + expect((await BigBang.read.owner()).toLowerCase()).to.equal( + address1.account?.address + ); + + // SplitsCreatorFactoryにBigBangアドレスをセット + SplitsCreatorFactory.write.setBigBang([BigBang.address]); + console.log("BigBang address", BigBang.address); + }); + it("Should deploy SplitsCreator", async () => { const predictedAddress = await SplitsCreatorFactory.read.predictDeterministicAddress([ @@ -150,15 +181,18 @@ describe("SplitsCreator Factory", () => { keccak256("0x1234"), ]); - await SplitsCreatorFactory.write.createSplitCreatorDeterministic([ - topHatId, - address1.account?.address!, - Hats.address, - PullSplitsFactory.address, - HatsTimeFrameModule.address, - FractionToken.address, - keccak256("0x1234"), - ]); + await SplitsCreatorFactory.write.createSplitCreatorDeterministic( + [ + topHatId, + address1.account?.address!, + Hats.address, + PullSplitsFactory.address, + HatsTimeFrameModule.address, + FractionToken.address, + keccak256("0x1234"), + ], + { account: BigBang.address } + ); SplitsCreator = await viem.getContractAt("SplitsCreator", predictedAddress);