diff --git a/pkgs/contract/contracts/bigbang/BigBang.sol b/pkgs/contract/contracts/bigbang/BigBang.sol index 84c1caa..5387270 100644 --- a/pkgs/contract/contracts/bigbang/BigBang.sol +++ b/pkgs/contract/contracts/bigbang/BigBang.sol @@ -28,7 +28,7 @@ contract BigBang is ERC2771ContextUpgradeable { address splitCreator ); - /* + /** * @dev Constructor to initialize the trusted forwarder. * @param _trustedForwarder Address of the trusted forwarder contract. * @param _hatsAddress Address of the hats protocol V1 contract. diff --git a/pkgs/contract/contracts/fractiontoken/FractionToken.sol b/pkgs/contract/contracts/fractiontoken/FractionToken.sol index c41fa68..b81bcaf 100644 --- a/pkgs/contract/contracts/fractiontoken/FractionToken.sol +++ b/pkgs/contract/contracts/fractiontoken/FractionToken.sol @@ -1,12 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; +import { ERC1155Upgradeable, ContextUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; import { IHats } from "../hats/src/Interfaces/IHats.sol"; -import "./../ERC2771ContextUpgradeable.sol"; +import { ERC2771ContextUpgradeable } from "./../ERC2771ContextUpgradeable.sol"; -contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable{ +contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable { uint256 public TOKEN_SUPPLY; mapping(uint256 => address[]) private tokenRecipients; @@ -18,7 +17,7 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable{ uint256 _tokenSupply, address _hatsAddress, address _trustedForwarderAddress - ) initializer public { + ) public initializer { __ERC1155_init(_uri); __ERC2771Context_init(address(_trustedForwarderAddress)); hatsContract = IHats(_hatsAddress); @@ -47,7 +46,10 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable{ ) public { uint256 tokenId = getTokenId(hatId, wearer); - require(_msgSender() == from || _containsRecipient(tokenId, _msgSender()), "not authorized"); + require( + _msgSender() == from || _containsRecipient(tokenId, _msgSender()), + "not authorized" + ); _burn(from, tokenId, value); } @@ -123,7 +125,9 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable{ ) public view returns (uint256) { uint256 tokenId = getTokenId(hatId, wearer); - if (_hasHatRole(account, hatId) && !_containsRecipient(tokenId, account)) { + if ( + _hasHatRole(account, hatId) && !_containsRecipient(tokenId, account) + ) { return TOKEN_SUPPLY; } diff --git a/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol b/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol index 8e26dc4..c0662e1 100644 --- a/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol +++ b/pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol @@ -5,10 +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 { ERC2771ContextUpgradeable } from "./../ERC2771ContextUpgradeable.sol"; -import "hardhat/console.sol"; - -contract SplitsCreatorFactory { +contract SplitsCreatorFactory is ERC2771ContextUpgradeable { event SplitCreatorCreated( address indexed creator, address indexed splitCreator, @@ -19,9 +18,13 @@ contract SplitsCreatorFactory { address fractionToken ); - address public immutable SPLITS_CREATOR_IMPLEMENTATION; + address public SPLITS_CREATOR_IMPLEMENTATION; - constructor(address _splitsCreatorImplementation) { + function initialize( + address _trustedForwarderAddress, + address _splitsCreatorImplementation + ) public initializer { + __ERC2771Context_init(_trustedForwarderAddress); SPLITS_CREATOR_IMPLEMENTATION = _splitsCreatorImplementation; } @@ -52,7 +55,7 @@ contract SplitsCreatorFactory { ); emit SplitCreatorCreated( - msg.sender, + _msgSender(), splitCreator, _topHatId, _trustedForwarder, @@ -111,4 +114,22 @@ contract SplitsCreatorFactory { ) ); } + + function _msgSender() + internal + view + override(ERC2771ContextUpgradeable) + returns (address sender) + { + return super._msgSender(); + } + + function _msgData() + internal + view + override(ERC2771ContextUpgradeable) + returns (bytes calldata) + { + return super._msgData(); + } } diff --git a/pkgs/contract/gas-report.txt b/pkgs/contract/gas-report.txt deleted file mode 100644 index be3d880..0000000 --- a/pkgs/contract/gas-report.txt +++ /dev/null @@ -1,31 +0,0 @@ -·------------------------|----------------------------|-------------|-----------------------------· -| Solc version: 0.8.24 · Optimizer enabled: false · Runs: 200 · Block limit: 30000000 gas │ -·························|····························|·············|······························ -| Methods │ -··············|··········|··············|·············|·············|···············|·············· -| Contract · Method · Min · Max · Avg · # calls · usd (avg) │ -··············|··········|··············|·············|·············|···············|·············· -| Deployments · · % of limit · │ -·························|··············|·············|·············|···············|·············· -| BigBang · - · - · 1248128 · 4.2 % · - │ -·························|··············|·············|·············|···············|·············· -| FractionToken · - · - · 2859199 · 9.5 % · - │ -·························|··············|·············|·············|···············|·············· -| Hats · - · - · 7032431 · 23.4 % · - │ -·························|··············|·············|·············|···············|·············· -| HatsModule · - · - · 754132 · 2.5 % · - │ -·························|··············|·············|·············|···············|·············· -| HatsModuleFactory · - · - · 1101122 · 3.7 % · - │ -·························|··············|·············|·············|···············|·············· -| HatsTimeFrameModule · - · - · 1287099 · 4.3 % · - │ -·························|··············|·············|·············|···············|·············· -| PullSplitFactory · - · - · 4535827 · 15.1 % · - │ -·························|··············|·············|·············|···············|·············· -| PushSplitFactory · - · - · 4483113 · 14.9 % · - │ -·························|··············|·············|·············|···············|·············· -| SplitsCreator · - · - · 1487532 · 5 % · - │ -·························|··············|·············|·············|···············|·············· -| SplitsCreatorFactory · - · - · 526836 · 1.8 % · - │ -·························|··············|·············|·············|···············|·············· -| SplitsWarehouse · - · - · 3934655 · 13.1 % · - │ -·------------------------|--------------|-------------|-------------|---------------|-------------· \ No newline at end of file diff --git a/pkgs/contract/hardhat.config.ts b/pkgs/contract/hardhat.config.ts index acbdd47..7340b21 100644 --- a/pkgs/contract/hardhat.config.ts +++ b/pkgs/contract/hardhat.config.ts @@ -67,11 +67,7 @@ const config: HardhatUserConfig = { }, gasReporter: { enabled: true, - // currency: "JPY", currency: "USD", - outputFile: "gas-report.txt", // 結果をファイルに保存 - noColors: true, // ファイル出力用に色を無効化 - // gasPrice: 20, token: "ETH", coinmarketcap: COINMARKETCAP_API_KEY, gasPriceApi: diff --git a/pkgs/contract/helpers/deploy/Splits.ts b/pkgs/contract/helpers/deploy/Splits.ts index 586ddbc..43c564e 100644 --- a/pkgs/contract/helpers/deploy/Splits.ts +++ b/pkgs/contract/helpers/deploy/Splits.ts @@ -1,4 +1,4 @@ -import { viem } from "hardhat"; +import { ethers, upgrades, viem } from "hardhat"; import { Address } from "viem"; export type SplitsWarehouse = Awaited< @@ -43,11 +43,29 @@ export const deploySplitsProtocol = async () => { }; export const deploySplitsCreatorFactory = async ( + forwarderAddress: Address, splitsCreatorImpl: Address ) => { - const SplitsCreatorFactory = await viem.deployContract( + const splitsCreatorFactory = await ethers.getContractFactory("SplitsCreatorFactory"); + + const _SplitsCreatorFactory = await upgrades.deployProxy( + splitsCreatorFactory, + [ + forwarderAddress, + splitsCreatorImpl + ], + { + initializer: "initialize", + } + ); + + await _SplitsCreatorFactory.waitForDeployment(); + const address = await _SplitsCreatorFactory.getAddress(); + + // create a new instance of the contract + const SplitsCreatorFactory = await viem.getContractAt( "SplitsCreatorFactory", - [splitsCreatorImpl] + address as Address ); return { SplitsCreatorFactory }; diff --git a/pkgs/contract/test/BigBang.ts b/pkgs/contract/test/BigBang.ts index 1c87685..70bc677 100644 --- a/pkgs/contract/test/BigBang.ts +++ b/pkgs/contract/test/BigBang.ts @@ -75,7 +75,7 @@ describe("BigBang", () => { SplitsCreator_IMPL = _SplitsCreator; const { SplitsCreatorFactory: _SplitsCreatorFactory } = - await deploySplitsCreatorFactory(SplitsCreator_IMPL.address); + await deploySplitsCreatorFactory(zeroAddress, SplitsCreator_IMPL.address); SplitsCreatorFactory = _SplitsCreatorFactory; diff --git a/pkgs/contract/test/IntegrationTest.ts b/pkgs/contract/test/IntegrationTest.ts index b758274..8ac61bf 100644 --- a/pkgs/contract/test/IntegrationTest.ts +++ b/pkgs/contract/test/IntegrationTest.ts @@ -98,7 +98,7 @@ describe("IntegrationTest", () => { SplitsCreator_IMPL = _SplitsCreator; const { SplitsCreatorFactory: _SplitsCreatorFactory } = - await deploySplitsCreatorFactory(SplitsCreator_IMPL.address); + await deploySplitsCreatorFactory(zeroAddress, SplitsCreator_IMPL.address); SplitsCreatorFactory = _SplitsCreatorFactory; diff --git a/pkgs/contract/test/SplitsCreator.ts b/pkgs/contract/test/SplitsCreator.ts index 99141ac..a57b014 100644 --- a/pkgs/contract/test/SplitsCreator.ts +++ b/pkgs/contract/test/SplitsCreator.ts @@ -120,7 +120,7 @@ describe("SplitsCreator Factory", () => { it("Should deploy SplitsCreatorFactory", async () => { const { SplitsCreatorFactory: _SplitsCreatorFactory } = - await deploySplitsCreatorFactory(SplitsCreator_IMPL.address); + await deploySplitsCreatorFactory(zeroAddress, SplitsCreator_IMPL.address); SplitsCreatorFactory = _SplitsCreatorFactory; @@ -266,7 +266,7 @@ describe("CreateSplit", () => { ); const { SplitsCreatorFactory: _SplitsCreatorFactory } = - await deploySplitsCreatorFactory(SplitsCreator_IMPL.address); + await deploySplitsCreatorFactory(zeroAddress, SplitsCreator_IMPL.address); SplitsCreatorFactory = _SplitsCreatorFactory;