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

SplitsCreatorFactoryの機能実装 #209

Merged
merged 5 commits into from
Dec 16, 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
23 changes: 21 additions & 2 deletions pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ pragma solidity ^0.8.24;
import { LibClone } from "solady/src/utils/LibClone.sol";
import { SplitsCreator } from "./SplitsCreator.sol";
import { ISplitsCreator } from "./ISplitsCreator.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract SplitsCreatorFactory is Initializable {
contract SplitsCreatorFactory is OwnableUpgradeable {
event SplitCreatorCreated(
address indexed creator,
address indexed splitCreator,
Expand All @@ -18,10 +18,13 @@ contract SplitsCreatorFactory is Initializable {
);

address public SPLITS_CREATOR_IMPLEMENTATION;

address public BIG_BANG;

function initialize(
address _splitsCreatorImplementation
) public initializer {
__Ownable_init(_msgSender());
SPLITS_CREATOR_IMPLEMENTATION = _splitsCreatorImplementation;
}

Expand All @@ -33,6 +36,10 @@ contract SplitsCreatorFactory is Initializable {
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 @@ -90,6 +97,18 @@ contract SplitsCreatorFactory is Initializable {
);
}

function setImplementation(
address _implementation
) external onlyOwner {
SPLITS_CREATOR_IMPLEMENTATION = _implementation;
}

function setBigBang(
address _bigBang
) external onlyOwner {
BIG_BANG = _bigBang;
}

function _getSalt(
uint256 _topHatId,
address _hats,
Expand Down
139 changes: 139 additions & 0 deletions pkgs/contract/contracts/splitscreator/mock/SplitsCreator_Mock_v2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import { LibClone } from "solady/src/utils/LibClone.sol";
import { SplitsCreator } from "../SplitsCreator.sol";
import { ISplitsCreator } from "../ISplitsCreator.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract SplitsCreatorFactory_Mock_v2 is OwnableUpgradeable {
event SplitCreatorCreated(
address indexed creator,
address indexed splitCreator,
uint256 topHatId,
address splitFactoryV2,
address hatsTimeFrameModule,
address fractionToken
);

address public SPLITS_CREATOR_IMPLEMENTATION;

address public BIG_BANG;

function initialize(
address _splitsCreatorImplementation
) public initializer {
__Ownable_init(_msgSender());
SPLITS_CREATOR_IMPLEMENTATION = _splitsCreatorImplementation;
}

function createSplitCreatorDeterministic(
uint256 _topHatId,
address _hats,
address _splitFactoryV2,
address _hatsTimeFrameModule,
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(
_hats,
_splitFactoryV2,
_hatsTimeFrameModule,
_fractionToken
),
_getSalt(
_topHatId,
_hats,
_splitFactoryV2,
_hatsTimeFrameModule,
_fractionToken,
_salt
)
);

emit SplitCreatorCreated(
msg.sender,
splitCreator,
_topHatId,
_splitFactoryV2,
_hatsTimeFrameModule,
_fractionToken
);
}

function predictDeterministicAddress(
uint256 _topHatId,
address _hats,
address _splitFactoryV2,
address _hatsTimeFrameModule,
address _fractionToken,
bytes32 _salt
) external view returns (address) {
return
LibClone.predictDeterministicAddress(
SPLITS_CREATOR_IMPLEMENTATION,
abi.encode(
_hats,
_splitFactoryV2,
_hatsTimeFrameModule,
_fractionToken
),
_getSalt(
_topHatId,
_hats,
_splitFactoryV2,
_hatsTimeFrameModule,
_fractionToken,
_salt
),
address(this)
);
}

function setImplementation(
address _implementation
) external onlyOwner {
SPLITS_CREATOR_IMPLEMENTATION = _implementation;
}

function setBigBang(
address _bigBang
) external onlyOwner {
BIG_BANG = _bigBang;
}

function _getSalt(
uint256 _topHatId,
address _hats,
address _splitFactoryV2,
address _hatsTimeFrameModule,
address _fractionToken,
bytes32 _salt
) internal pure returns (bytes32) {
return
keccak256(
abi.encodePacked(
_topHatId,
_hats,
_splitFactoryV2,
_hatsTimeFrameModule,
_fractionToken,
_salt
)
);
}

/**
* 検証用に追加した関数
*/
function testUpgradeFunction() external pure returns (string memory) {
return "testUpgradeFunction";
}
}
35 changes: 35 additions & 0 deletions pkgs/contract/helpers/upgrade/splitsCreatorFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ethers, upgrades, viem } from "hardhat";
import { Address } from "viem";

/**
* SplitsCreatorFactory Contractをアップグレードするメソッド
* @param contractAddress アップグレード対象のコントラクトアドレス
* @param contractName アップグレード後のコントラクト名
* @param params アップグレード時に必要なパラメータ
* @returns
*/
export async function upgradeSplitsCreatorFacotry(
contractAddress: string ,
contractName: string,
params: any[]
) {
// 新しいコントラクトのファクトリーを取得
const SplitsCreator_Mock_v2 = await ethers.getContractFactory(contractName);

// アップグレードを実行
const _SplitsCreatorFactory = await upgrades.upgradeProxy(
contractAddress,
SplitsCreator_Mock_v2
);

// 新しいアドレスを取得
const address = _SplitsCreatorFactory.target;

// create a new instance of the contract
const newSplitsCreatorFactory = await viem.getContractAt(
contractName,
address as Address
);

return newSplitsCreatorFactory;
}
6 changes: 6 additions & 0 deletions pkgs/contract/test/BigBang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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 @@ -316,6 +319,9 @@ describe("BigBang", () => {
"BigBang_Mock_v2"
);

// 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 @@ -122,6 +122,8 @@ describe("IntegrationTest", () => {
});

it("should execute bigbang", async () => {
SplitsCreatorFactory.write.setBigBang([BigBang.address]);

const txHash = await BigBang.write.bigbang(
[
deployer.account?.address!,
Expand Down
Loading
Loading