-
Notifications
You must be signed in to change notification settings - Fork 3
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 #209 from hackdays-io/feature/splitscreator-ownable
SplitsCreatorFactoryの機能実装
- Loading branch information
Showing
6 changed files
with
261 additions
and
20 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
139 changes: 139 additions & 0 deletions
139
pkgs/contract/contracts/splitscreator/mock/SplitsCreator_Mock_v2.sol
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,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"; | ||
} | ||
} |
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,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; | ||
} |
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
Oops, something went wrong.