Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yu23ki14 committed Jan 1, 2025
1 parent 23666ba commit d69b4fd
Show file tree
Hide file tree
Showing 19 changed files with 873 additions and 319 deletions.
211 changes: 211 additions & 0 deletions pkgs/contract/.openzeppelin/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,217 @@
]
}
}
},
"7ec8e5faeca7102ee9b0280f21320bd396150d8b38307dab9e3571a43d52ab07": {
"address": "0x5f791DE36ec558127F58AB334808D6274F35EE70",
"txHash": "0xf8f8d6414eb409b0842584d04b93852d15784f0bde0502ab3023f2ac906e377e",
"layout": {
"solcVersion": "0.8.24",
"storage": [
{
"label": "TOKEN_SUPPLY",
"offset": 0,
"slot": "0",
"type": "t_uint256",
"contract": "FractionToken",
"src": "contracts/fractiontoken/FractionToken.sol:17"
},
{
"label": "tokenRecipients",
"offset": 0,
"slot": "1",
"type": "t_mapping(t_uint256,t_array(t_address)dyn_storage)",
"contract": "FractionToken",
"src": "contracts/fractiontoken/FractionToken.sol:19"
},
{
"label": "hatsContract",
"offset": 0,
"slot": "2",
"type": "t_contract(IHats)8259",
"contract": "FractionToken",
"src": "contracts/fractiontoken/FractionToken.sol:21"
}
],
"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_mapping(t_uint256,t_uint256)": {
"label": "mapping(uint256 => uint256)",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(ERC1155Storage)100_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(ERC1155SupplyStorage)383_storage": {
"label": "struct ERC1155SupplyUpgradeable.ERC1155SupplyStorage",
"members": [
{
"label": "_totalSupply",
"type": "t_mapping(t_uint256,t_uint256)",
"offset": 0,
"slot": "0"
},
{
"label": "_totalSupplyAll",
"type": "t_uint256",
"offset": 0,
"slot": "1"
}
],
"numberOfBytes": "64"
},
"t_struct(InitializableStorage)7_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)8259": {
"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.ERC1155Supply": [
{
"contract": "ERC1155SupplyUpgradeable",
"label": "_totalSupply",
"type": "t_mapping(t_uint256,t_uint256)",
"src": "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol:25",
"offset": 0,
"slot": "0"
},
{
"contract": "ERC1155SupplyUpgradeable",
"label": "_totalSupplyAll",
"type": "t_uint256",
"src": "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol:26",
"offset": 0,
"slot": "1"
}
],
"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"
}
]
}
}
}
}
}
4 changes: 3 additions & 1 deletion pkgs/contract/contracts/fractiontoken/FractionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ pragma solidity ^0.8.24;

import { ERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import { ERC1155SupplyUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol";
import { MulticallUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.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,
ERC1155SupplyUpgradeable,
MulticallUpgradeable,
IFractionToken
{
uint256 public TOKEN_SUPPLY;
Expand Down Expand Up @@ -39,7 +41,7 @@ contract FractionToken is
);

require(
_hasHatAuthority(hatId),
msg.sender == account || _hasHatAuthority(hatId),
"This msg.sender does not have the authority"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ pragma solidity ^0.8.24;

import { ERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import { ERC1155SupplyUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol";
import { MulticallUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import { IHats } from "../../hats/src/Interfaces/IHats.sol";

contract FractionToken_Mock_v2 is ERC1155Upgradeable, ERC1155SupplyUpgradeable {
contract FractionToken_Mock_v2 is
ERC1155Upgradeable,
ERC1155SupplyUpgradeable,
MulticallUpgradeable
{
uint256 public TOKEN_SUPPLY;

mapping(uint256 => address[]) private tokenRecipients;
Expand Down
62 changes: 44 additions & 18 deletions pkgs/contract/test/FractionToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { expect } from "chai";
import { viem } from "hardhat";
import { decodeEventLog, PublicClient, WalletClient, zeroAddress } from "viem";
import {
decodeEventLog,
encodeFunctionData,
PublicClient,
WalletClient,
zeroAddress,
} from "viem";
import {
deployFractionToken,
FractionToken,
Expand All @@ -16,9 +22,9 @@ describe("FractionToken", () => {
let address2: WalletClient;
let address3: WalletClient;
let address4: WalletClient;
let address5: WalletClient;

let hatId: bigint;
let topHatId: bigint;

let publicClient: PublicClient;

Expand All @@ -35,7 +41,8 @@ describe("FractionToken", () => {
);
FractionToken = _FractionToken;

[address1, address2, address3, address4] = await viem.getWalletClients();
[address1, address2, address3, address4, address5] =
await viem.getWalletClients();

publicClient = await viem.getPublicClient();

Expand All @@ -45,22 +52,10 @@ describe("FractionToken", () => {
"https://test.com/tophat.png",
]);

let receipt1 = await publicClient.waitForTransactionReceipt({
await publicClient.waitForTransactionReceipt({
hash: tx1,
});

for (const log of receipt1.logs) {
try {
const decodedLog = decodeEventLog({
abi: Hats.abi,
data: log.data,
topics: log.topics,
});
if (decodedLog.eventName === "HatCreated")
topHatId = decodedLog.args.id;
} catch (error) {}
}

let tx2 = await Hats.write.createHat([
BigInt(
"0x0000000100000000000000000000000000000000000000000000000000000000"
Expand Down Expand Up @@ -88,9 +83,10 @@ describe("FractionToken", () => {
} catch (error) {}
}

// address2,address3にHatをmint
// address2,address3, address5にHatをmint
await Hats.write.mintHat([hatId, address2.account?.address!]);
await Hats.write.mintHat([hatId, address3.account?.address!]);
await Hats.write.mintHat([hatId, address5.account?.address!]);
});

it("should mint, transfer and burn tokens", async () => {
Expand Down Expand Up @@ -197,7 +193,7 @@ describe("FractionToken", () => {
// 権限のない人はtokenをmintできない
await FractionToken.write
.mintInitialSupply([hatId, address2.account?.address!, 0n], {
account: address2.account!,
account: address3.account!,
})
.catch((error: any) => {
expect(error.message).to.include(
Expand Down Expand Up @@ -247,6 +243,36 @@ describe("FractionToken", () => {
});
});

it("should success initial supply and transfer with multicall", async () => {
const tokenId = await FractionToken.read.getTokenId([
hatId,
address5.account?.address!,
]);
const mintInitialSupplyCalldata = encodeFunctionData({
abi: FractionToken.abi,
functionName: "mintInitialSupply",
args: [hatId, address5.account?.address!, 0n],
});
const transferCalldata = encodeFunctionData({
abi: FractionToken.abi,
functionName: "safeTransferFrom",
args: [
address5.account?.address!,
address1.account?.address!,
tokenId,
1000n,
"0x",
],
});

await FractionToken.write.multicall(
[[mintInitialSupplyCalldata, transferCalldata]],
{
account: address5.account!,
}
);
});

/**
* 以降は、Upgradeのテストコードになる。
* Upgrade後に再度機能をテストする。
Expand Down
Loading

0 comments on commit d69b4fd

Please sign in to comment.