Skip to content

Commit

Permalink
add subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
yu23ki14 committed Dec 19, 2024
1 parent d69fe50 commit fbd5835
Show file tree
Hide file tree
Showing 11 changed files with 1,868 additions and 134 deletions.
171 changes: 171 additions & 0 deletions pkgs/contract/.openzeppelin/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,177 @@
]
}
}
},
"bc99c04f0dfb4992ed165e54e943343e226f7658165be2a79475a81a43158d28": {
"address": "0xE9087c88980D08c5C20C92792b7CfbfE8606E67A",
"txHash": "0x57b6be25d318764f5d965c683b83cb7e7ecda118c8ee28e7c9d2b5ec48dc4353",
"layout": {
"solcVersion": "0.8.24",
"storage": [
{
"label": "TOKEN_SUPPLY",
"offset": 0,
"slot": "0",
"type": "t_uint256",
"contract": "FractionToken",
"src": "contracts/fractiontoken/FractionToken.sol:10"
},
{
"label": "tokenRecipients",
"offset": 0,
"slot": "1",
"type": "t_mapping(t_uint256,t_array(t_address)dyn_storage)",
"contract": "FractionToken",
"src": "contracts/fractiontoken/FractionToken.sol:12"
},
{
"label": "hatsContract",
"offset": 0,
"slot": "2",
"type": "t_contract(IHats)7761",
"contract": "FractionToken",
"src": "contracts/fractiontoken/FractionToken.sol:14"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_mapping(t_address,t_bool)": {
"label": "mapping(address => bool)",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_mapping(t_address,t_bool))": {
"label": "mapping(address => mapping(address => bool))",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_uint256)": {
"label": "mapping(address => uint256)",
"numberOfBytes": "32"
},
"t_mapping(t_uint256,t_mapping(t_address,t_uint256))": {
"label": "mapping(uint256 => mapping(address => uint256))",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(ERC1155Storage)166_storage": {
"label": "struct ERC1155Upgradeable.ERC1155Storage",
"members": [
{
"label": "_balances",
"type": "t_mapping(t_uint256,t_mapping(t_address,t_uint256))",
"offset": 0,
"slot": "0"
},
{
"label": "_operatorApprovals",
"type": "t_mapping(t_address,t_mapping(t_address,t_bool))",
"offset": 0,
"slot": "1"
},
{
"label": "_uri",
"type": "t_string_storage",
"offset": 0,
"slot": "2"
}
],
"numberOfBytes": "96"
},
"t_struct(InitializableStorage)73_storage": {
"label": "struct Initializable.InitializableStorage",
"members": [
{
"label": "_initialized",
"type": "t_uint64",
"offset": 0,
"slot": "0"
},
{
"label": "_initializing",
"type": "t_bool",
"offset": 8,
"slot": "0"
}
],
"numberOfBytes": "32"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint64": {
"label": "uint64",
"numberOfBytes": "8"
},
"t_array(t_address)dyn_storage": {
"label": "address[]",
"numberOfBytes": "32"
},
"t_contract(IHats)7761": {
"label": "contract IHats",
"numberOfBytes": "20"
},
"t_mapping(t_uint256,t_array(t_address)dyn_storage)": {
"label": "mapping(uint256 => address[])",
"numberOfBytes": "32"
}
},
"namespaces": {
"erc7201:openzeppelin.storage.ERC1155": [
{
"contract": "ERC1155Upgradeable",
"label": "_balances",
"type": "t_mapping(t_uint256,t_mapping(t_address,t_uint256))",
"src": "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol:27",
"offset": 0,
"slot": "0"
},
{
"contract": "ERC1155Upgradeable",
"label": "_operatorApprovals",
"type": "t_mapping(t_address,t_mapping(t_address,t_bool))",
"src": "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol:29",
"offset": 0,
"slot": "1"
},
{
"contract": "ERC1155Upgradeable",
"label": "_uri",
"type": "t_string_storage",
"src": "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol:32",
"offset": 0,
"slot": "2"
}
],
"erc7201:openzeppelin.storage.Initializable": [
{
"contract": "Initializable",
"label": "_initialized",
"type": "t_uint64",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69",
"offset": 0,
"slot": "0"
},
{
"contract": "Initializable",
"label": "_initializing",
"type": "t_bool",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73",
"offset": 8,
"slot": "0"
}
]
}
}
}
}
}
19 changes: 14 additions & 5 deletions pkgs/contract/contracts/fractiontoken/FractionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ pragma solidity ^0.8.24;

import { ERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import { IHats } from "../hats/src/Interfaces/IHats.sol";
import { IFractionToken } from "./IFractionToken.sol";
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

contract FractionToken is ERC1155Upgradeable {
contract FractionToken is ERC1155Upgradeable, IFractionToken {
uint256 public TOKEN_SUPPLY;

mapping(uint256 => address[]) private tokenRecipients;
Expand All @@ -21,7 +23,11 @@ contract FractionToken is ERC1155Upgradeable {
TOKEN_SUPPLY = _tokenSupply;
}

function mintInitialSupply(uint256 hatId, address account) public {
function mintInitialSupply(
uint256 hatId,
address account,
uint256 amount
) public {
require(
_hasHatRole(account, hatId),
"This account does not have the role"
Expand All @@ -39,9 +45,12 @@ contract FractionToken is ERC1155Upgradeable {
"This account has already received"
);

_mint(account, tokenId, TOKEN_SUPPLY, "");
uint256 initialAmount = amount > 0 ? amount : TOKEN_SUPPLY;
_mint(account, tokenId, initialAmount, "");

tokenRecipients[tokenId].push(account);

emit InitialMint(account, hatId, tokenId);
}

function mint(uint256 hatId, address account, uint256 amount) public {
Expand Down Expand Up @@ -82,7 +91,7 @@ contract FractionToken is ERC1155Upgradeable {
uint256 tokenId,
uint256 amount,
bytes memory data
) public override {
) public override(ERC1155Upgradeable, IERC1155) {
super.safeTransferFrom(from, to, tokenId, amount, data);

if (!_containsRecipient(tokenId, to)) {
Expand All @@ -96,7 +105,7 @@ contract FractionToken is ERC1155Upgradeable {
uint256[] memory tokenIds,
uint256[] memory amounts,
bytes memory data
) public override {
) public override(ERC1155Upgradeable, IERC1155) {
super.safeBatchTransferFrom(from, to, tokenIds, amounts, data);

for (uint256 i = 0; i < tokenIds.length; i++) {
Expand Down
70 changes: 38 additions & 32 deletions pkgs/contract/contracts/fractiontoken/IFractionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,45 @@ pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

interface IFractionToken is IERC1155 {
function mintInitialSupply(
string memory hatId,
address account,
uint256 amount
) external;

function burn(
address from,
event InitialMint(
address indexed wearer,
uint256 indexed hatId,
uint256 indexed tokenId
);

function mintInitialSupply(
uint256 hatId,
address account,
uint256 amount
) external;

function mint(uint256 hatId, address account, uint256 amount) external;

function burn(
address from,
address wearer,
uint256 hatId,
uint256 value
) external;

function getTokenRecipients(
uint256 tokenId
) external view returns (address[] memory);

function getAllTokenIds() external view returns (uint256[] memory);

function getTokenId(
uint256 hatId,
address account
) external view returns (uint256);

function balanceOf(
address account,
address warer,
uint256 hatId
) external view returns (uint256);

function balanceOfBatch(
address[] memory accounts,
address[] memory warers,
uint256[] memory hatIds
) external view returns (uint256[] memory);
) external;

function getTokenRecipients(
uint256 tokenId
) external view returns (address[] memory);

function getTokenId(
uint256 hatId,
address account
) external view returns (uint256);

function balanceOf(
address account,
address warer,
uint256 hatId
) external view returns (uint256);

function balanceOfBatch(
address[] memory accounts,
address[] memory warers,
uint256[] memory hatIds
) external view returns (uint256[] memory);
}
4 changes: 2 additions & 2 deletions pkgs/contract/helpers/upgrade/fractionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const upgradeFractionToken = async (
params?: any[]
) => {
// 新しいコントラクトのファクトリーを取得
const FractionToken_Mock_v2 = await ethers.getContractFactory(contractName);
const FractionToken = await ethers.getContractFactory(contractName);

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

const address = _FractionToken.target;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"getContractAddress": "npx hardhat getContractAddress",
"registerSubdomain": "npx hardhat registerSubdomain",
"createSplit": "npx hardhat run scripts/createSplit.ts",
"upgrade:FractionToken": "npx hardhat run scripts/upgrade/FractionToken.ts",
"upgrade:FractionToken": "npx hardhat run scripts/upgrade/fractionToken.ts",
"upgrade:BigBang": "npx hardhat run scripts/upgrade/BigBang.ts",
"bigbang": "npx hardhat bigbang",
"getWoreTime": "npx hardhat getWoreTime",
Expand Down
2 changes: 1 addition & 1 deletion pkgs/contract/scripts/upgrade/fractionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const upgrade = async () => {
// FractionTokenコントラクトをアップグレードする
const newFractionToken = await upgradeFractionToken(
FractionToken,
"FractionToken_Mock_v2" // ここにアップグレード後のFractionTokenのコントラクト名を指定する。
"FractionToken" // ここにアップグレード後のFractionTokenのコントラクト名を指定する。
);

console.log("upgrded address:", newFractionToken.address);
Expand Down
10 changes: 5 additions & 5 deletions pkgs/contract/test/FractionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ describe("FractionToken", () => {
it("should mint, transfer and burn tokens", async () => {
// address1がaddress2,address3にtokenをmint
await FractionToken.write.mintInitialSupply(
[hatId, address2.account?.address!],
[hatId, address2.account?.address!, 0n],
{ account: address1.account! }
);
await FractionToken.write.mintInitialSupply(
[hatId, address3.account?.address!],
[hatId, address3.account?.address!, 0n],
{ account: address1.account! }
);

Expand Down Expand Up @@ -187,7 +187,7 @@ describe("FractionToken", () => {
it("should fail to mint a token", async () => {
// roleのない人にtokenはmintできない
await FractionToken.write
.mintInitialSupply([hatId, address4.account?.address!], {
.mintInitialSupply([hatId, address4.account?.address!, 0n], {
account: address1.account!,
})
.catch((error: any) => {
Expand All @@ -196,7 +196,7 @@ describe("FractionToken", () => {

// 権限のない人はtokenをmintできない
await FractionToken.write
.mintInitialSupply([hatId, address2.account?.address!], {
.mintInitialSupply([hatId, address2.account?.address!, 0n], {
account: address2.account!,
})
.catch((error: any) => {
Expand All @@ -207,7 +207,7 @@ describe("FractionToken", () => {

// tokenは二度mintできない
await FractionToken.write
.mintInitialSupply([hatId, address2.account?.address!])
.mintInitialSupply([hatId, address2.account?.address!, 0n])
.catch((error: any) => {
expect(error.message).to.include("This account has already received");
});
Expand Down
Loading

0 comments on commit fbd5835

Please sign in to comment.