Skip to content

Commit

Permalink
wip: issue147
Browse files Browse the repository at this point in the history
  • Loading branch information
aowheel committed Dec 9, 2024
1 parent dc8f002 commit eabbe01
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
31 changes: 27 additions & 4 deletions pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -126,7 +149,7 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable {
function _msgSender()
internal
view
override(ERC2771ContextUpgradeable)
override(ERC2771ContextUpgradeable, ContextUpgradeable)
returns (address sender)
{
return super._msgSender();
Expand All @@ -135,7 +158,7 @@ contract SplitsCreatorFactory is ERC2771ContextUpgradeable {
function _msgData()
internal
view
override(ERC2771ContextUpgradeable)
override(ERC2771ContextUpgradeable, ContextUpgradeable)
returns (bytes calldata)
{
return super._msgData();
Expand Down
6 changes: 6 additions & 0 deletions pkgs/contract/test/BigBang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down Expand Up @@ -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!,
Expand Down
2 changes: 2 additions & 0 deletions pkgs/contract/test/IntegrationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down
52 changes: 43 additions & 9 deletions pkgs/contract/test/SplitsCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -116,6 +120,9 @@ describe("SplitsCreator Factory", () => {
"HatsTimeFrameModule",
hatsTimeFrameModuleAddress
);

[address1, relayer] = await viem.getWalletClients();
publicClient = await viem.getPublicClient();
});

it("Should deploy SplitsCreatorFactory", async () => {
Expand All @@ -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([
Expand All @@ -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);

Expand Down

0 comments on commit eabbe01

Please sign in to comment.