Skip to content

Commit

Permalink
Merge pull request #162 from hackdays-io/issue/142
Browse files Browse the repository at this point in the history
Issue/142
  • Loading branch information
yu23ki14 authored Nov 22, 2024
2 parents b990ddf + dcb5b82 commit f140fa4
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 48 deletions.
1 change: 1 addition & 0 deletions contracts/fractiontoken/FractionToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

48 changes: 41 additions & 7 deletions pkgs/contract/contracts/bigbang/BigBang.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { IHatsModuleFactory } from "./IHatsModuleFactory.sol";
import { ISplitsCreatorFactory } from "../splitscreator/ISplitsCreatorFactory.sol";
import { HatsTimeFrameModule } from "../timeframe/HatsTimeFrameModule.sol";
import "./../ERC2771ContextUpgradeable.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract BigBang is ERC2771ContextUpgradeable {
contract BigBang is ERC2771ContextUpgradeable, OwnableUpgradeable {
IHats public Hats;

IHatsModuleFactory public HatsModuleFactory;
Expand All @@ -16,9 +17,9 @@ contract BigBang is ERC2771ContextUpgradeable {

address public HatsTimeFrameModule_IMPL;

address public splitFactoryV2;
address public SplitsFactoryV2;

address public fractionToken;
address public FractionToken;

event Executed(
address indexed owner,
Expand Down Expand Up @@ -47,13 +48,14 @@ contract BigBang is ERC2771ContextUpgradeable {
address _splitFactoryV2,
address _fractionToken
) initializer public {
__Ownable_init(_msgSender());
__ERC2771Context_init(address(_trustedForwarder));
Hats = IHats(_hatsAddress);
HatsModuleFactory = IHatsModuleFactory(_hatsModuleFactory);
HatsTimeFrameModule_IMPL = _hatsTimeFrameModule_IMPL;
SplitsCreatorFactory = ISplitsCreatorFactory(_splitsCreatorFactory);
splitFactoryV2 = _splitFactoryV2;
fractionToken = _fractionToken;
SplitsFactoryV2 = _splitFactoryV2;
FractionToken = _fractionToken;
}

/**
Expand Down Expand Up @@ -114,14 +116,46 @@ contract BigBang is ERC2771ContextUpgradeable {
.createSplitCreatorDeterministic(
topHatId,
_trustedForwarder,
splitFactoryV2,
SplitsFactoryV2,
hatsTimeFrameModule,
fractionToken,
FractionToken,
keccak256(abi.encodePacked(topHatId))
);

emit Executed(_owner, topHatId, hatterHatId, hatsTimeFrameModule, splitCreator);

return topHatId;
}

function setHats(address _hats) external onlyOwner {
Hats = IHats(_hats);
}

function setHatsModuleFactory(address _hatsModuleFactory) external onlyOwner {
HatsModuleFactory = IHatsModuleFactory(_hatsModuleFactory);
}

function setSplitsCreatorFactory(address _splitsCreatorFactory) external onlyOwner {
SplitsCreatorFactory = ISplitsCreatorFactory(_splitsCreatorFactory);
}

function setHatsTimeFrameModuleImpl(address _hatsTimeFrameModuleImpl) external onlyOwner {
HatsTimeFrameModule_IMPL = _hatsTimeFrameModuleImpl;
}

function setSplitsFactoryV2(address _splitsFactoryV2) external onlyOwner {
SplitsFactoryV2 = _splitsFactoryV2;
}

function setFractionToken(address _fractionToken) external onlyOwner {
FractionToken = _fractionToken;
}

function _msgSender() internal view override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (address sender) {
return super._msgSender();
}

function _msgData() internal view override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (bytes calldata) {
return super._msgData();
}
}
54 changes: 44 additions & 10 deletions pkgs/contract/contracts/bigbang/mock/BigBang_Mock_v2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
pragma solidity ^0.8.24;

import { IHats } from "../../hats/src/Interfaces/IHats.sol";
import { IHatsModuleFactory } from "./../IHatsModuleFactory.sol";
import { IHatsModuleFactory } from "../IHatsModuleFactory.sol";
import { ISplitsCreatorFactory } from "../../splitscreator/ISplitsCreatorFactory.sol";
import { HatsTimeFrameModule } from "../../timeframe/HatsTimeFrameModule.sol";
import "./../../ERC2771ContextUpgradeable.sol";
import "../../ERC2771ContextUpgradeable.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/**
* Upgradableになっている確認するための検証用BigBangコントラクト
*/
contract BigBang_Mock_v2 is ERC2771ContextUpgradeable {
contract BigBang_Mock_v2 is ERC2771ContextUpgradeable, OwnableUpgradeable {
IHats public Hats;

IHatsModuleFactory public HatsModuleFactory;
Expand All @@ -19,9 +20,9 @@ contract BigBang_Mock_v2 is ERC2771ContextUpgradeable {

address public HatsTimeFrameModule_IMPL;

address public splitFactoryV2;
address public SplitsFactoryV2;

address public fractionToken;
address public FractionToken;

event Executed(
address indexed owner,
Expand All @@ -31,7 +32,7 @@ contract BigBang_Mock_v2 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 All @@ -50,13 +51,14 @@ contract BigBang_Mock_v2 is ERC2771ContextUpgradeable {
address _splitFactoryV2,
address _fractionToken
) initializer public {
__Ownable_init(_msgSender());
__ERC2771Context_init(address(_trustedForwarder));
Hats = IHats(_hatsAddress);
HatsModuleFactory = IHatsModuleFactory(_hatsModuleFactory);
HatsTimeFrameModule_IMPL = _hatsTimeFrameModule_IMPL;
SplitsCreatorFactory = ISplitsCreatorFactory(_splitsCreatorFactory);
splitFactoryV2 = _splitFactoryV2;
fractionToken = _fractionToken;
SplitsFactoryV2 = _splitFactoryV2;
FractionToken = _fractionToken;
}

/**
Expand Down Expand Up @@ -117,9 +119,9 @@ contract BigBang_Mock_v2 is ERC2771ContextUpgradeable {
.createSplitCreatorDeterministic(
topHatId,
_trustedForwarder,
splitFactoryV2,
SplitsFactoryV2,
hatsTimeFrameModule,
fractionToken,
FractionToken,
keccak256(abi.encodePacked(topHatId))
);

Expand All @@ -128,6 +130,38 @@ contract BigBang_Mock_v2 is ERC2771ContextUpgradeable {
return topHatId;
}

function setHats(address _hats) external onlyOwner {
Hats = IHats(_hats);
}

function setHatsModuleFactory(address _hatsModuleFactory) external onlyOwner {
HatsModuleFactory = IHatsModuleFactory(_hatsModuleFactory);
}

function setSplitsCreatorFactory(address _splitsCreatorFactory) external onlyOwner {
SplitsCreatorFactory = ISplitsCreatorFactory(_splitsCreatorFactory);
}

function setHatsTimeFrameModuleImpl(address _hatsTimeFrameModuleImpl) external onlyOwner {
HatsTimeFrameModule_IMPL = _hatsTimeFrameModuleImpl;
}

function setSplitsFactoryV2(address _splitsFactoryV2) external onlyOwner {
SplitsFactoryV2 = _splitsFactoryV2;
}

function setFractionToken(address _fractionToken) external onlyOwner {
FractionToken = _fractionToken;
}

function _msgSender() internal view override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (address sender) {
return super._msgSender();
}

function _msgData() internal view override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (bytes calldata) {
return super._msgData();
}

/**
* 検証用に追加した関数
*/
Expand Down
31 changes: 5 additions & 26 deletions pkgs/contract/contracts/fractiontoken/FractionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable {
TOKEN_SUPPLY = _tokenSupply;
}

function mintInitialSupply(
uint256 hatId,
address account
) public {
function mintInitialSupply(uint256 hatId, address account) public {
require(
_hasHatRole(account, hatId),
"This account does not have the role"
Expand All @@ -47,23 +44,17 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable {

_mint(account, tokenId, TOKEN_SUPPLY, "");

if (!_containsRecipient(tokenId, account)) {
tokenRecipients[tokenId].push(account);
}
tokenRecipients[tokenId].push(account);
}

function mint(
uint256 hatId,
address account,
uint256 amount
) public {
function mint(uint256 hatId, address account, uint256 amount) public {
uint256 tokenId = getTokenId(hatId, account);

require(
tokenRecipients[tokenId].length > 0,
"This account has not received the initial supply"
);

require(
_msgSender() == tokenRecipients[tokenId][0],
"Only the first recipient can additionally mint"
Expand Down Expand Up @@ -152,9 +143,7 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable {
return balance > 0;
}

function _hasHatAuthority(
uint256 hatId
) private view returns (bool) {
function _hasHatAuthority(uint256 hatId) private view returns (bool) {
uint32 hatLevel = hatsContract.getHatLevel(hatId);

uint256 parentHatId = hatsContract.getAdminAtLevel(hatId, hatLevel - 1);
Expand Down Expand Up @@ -220,14 +209,4 @@ contract FractionToken is ERC1155Upgradeable, ERC2771ContextUpgradeable {
{
return super._msgData();
}

function _contextSuffixLength()
internal
view
virtual
override(ContextUpgradeable)
returns (uint256)
{
return super._contextSuffixLength();
}
}
Loading

0 comments on commit f140fa4

Please sign in to comment.