Skip to content

Commit

Permalink
Merge pull request #160 from hackdays-io/issue/149
Browse files Browse the repository at this point in the history
SplitsCreatorFactoryをUpgradeableに
  • Loading branch information
yu23ki14 authored Oct 28, 2024
2 parents 9702c43 + b391b27 commit 9ed0ec6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 56 deletions.
2 changes: 1 addition & 1 deletion pkgs/contract/contracts/bigbang/BigBang.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions pkgs/contract/contracts/fractiontoken/FractionToken.sol
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
33 changes: 27 additions & 6 deletions pkgs/contract/contracts/splitscreator/SplitsCreatorFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -52,7 +55,7 @@ contract SplitsCreatorFactory {
);

emit SplitCreatorCreated(
msg.sender,
_msgSender(),
splitCreator,
_topHatId,
_trustedForwarder,
Expand Down Expand Up @@ -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();
}
}
31 changes: 0 additions & 31 deletions pkgs/contract/gas-report.txt

This file was deleted.

4 changes: 0 additions & 4 deletions pkgs/contract/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 21 additions & 3 deletions pkgs/contract/helpers/deploy/Splits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { viem } from "hardhat";
import { ethers, upgrades, viem } from "hardhat";
import { Address } from "viem";

export type SplitsWarehouse = Awaited<
Expand Down Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion pkgs/contract/test/BigBang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/contract/test/IntegrationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions pkgs/contract/test/SplitsCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -266,7 +266,7 @@ describe("CreateSplit", () => {
);

const { SplitsCreatorFactory: _SplitsCreatorFactory } =
await deploySplitsCreatorFactory(SplitsCreator_IMPL.address);
await deploySplitsCreatorFactory(zeroAddress, SplitsCreator_IMPL.address);

SplitsCreatorFactory = _SplitsCreatorFactory;

Expand Down

0 comments on commit 9ed0ec6

Please sign in to comment.