From fd1640fed93475d1db973aa1d18d0e0396c7296c Mon Sep 17 00:00:00 2001 From: yu23ki14 Date: Thu, 26 Dec 2024 17:04:06 +0900 Subject: [PATCH] small --- pkgs/contract/.openzeppelin/sepolia.json | 211 ++++++++++++++++++ pkgs/contract/test/SplitsCreator.ts | 49 +++- pkgs/frontend/abi/splits.ts | 7 +- .../app/routes/$treeId_.splitter.new.tsx | 65 +++--- 4 files changed, 283 insertions(+), 49 deletions(-) diff --git a/pkgs/contract/.openzeppelin/sepolia.json b/pkgs/contract/.openzeppelin/sepolia.json index c3e7018..deb586b 100644 --- a/pkgs/contract/.openzeppelin/sepolia.json +++ b/pkgs/contract/.openzeppelin/sepolia.json @@ -1357,6 +1357,217 @@ ] } } + }, + "dd12bf6e75fb0acd68de953a2d3bb52bb98ef7fc45c7771ef4b96e40a51ea298": { + "address": "0x30Ee73482782dA4300C60B1DcD30b429a9C5f1eA", + "txHash": "0xb0055890b9abcbb62d1763d3fdf5d97615985dd3e6759714092a954c9840cd10", + "layout": { + "solcVersion": "0.8.24", + "storage": [ + { + "label": "TOKEN_SUPPLY", + "offset": 0, + "slot": "0", + "type": "t_uint256", + "contract": "FractionToken", + "src": "contracts/fractiontoken/FractionToken.sol:15" + }, + { + "label": "tokenRecipients", + "offset": 0, + "slot": "1", + "type": "t_mapping(t_uint256,t_array(t_address)dyn_storage)", + "contract": "FractionToken", + "src": "contracts/fractiontoken/FractionToken.sol:17" + }, + { + "label": "hatsContract", + "offset": 0, + "slot": "2", + "type": "t_contract(IHats)17350", + "contract": "FractionToken", + "src": "contracts/fractiontoken/FractionToken.sol:19" + } + ], + "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)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(ERC1155SupplyStorage)449_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)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)17350": { + "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" + } + ] + } + } } } } diff --git a/pkgs/contract/test/SplitsCreator.ts b/pkgs/contract/test/SplitsCreator.ts index ad856d9..a01e166 100644 --- a/pkgs/contract/test/SplitsCreator.ts +++ b/pkgs/contract/test/SplitsCreator.ts @@ -234,7 +234,7 @@ describe("CreateSplit", () => { let address1WoreTime: bigint; let address2WoreTime: bigint; let address3WoreTime: bigint; - let address1_additional_woreTime: number = 500000; + let address1_additional_woreTime: number = 2592000; let publicClient: PublicClient; @@ -311,7 +311,9 @@ describe("CreateSplit", () => { SplitsCreatorFactory = _SplitsCreatorFactory; - SplitsCreatorFactory.write.setBigBang([bigBangAddress.account?.address!]); + await SplitsCreatorFactory.write.setBigBang([ + bigBangAddress.account?.address!, + ]); let txHash = await SplitsCreatorFactory.write.createSplitCreatorDeterministic( @@ -494,13 +496,25 @@ describe("CreateSplit", () => { account: address1.account!, } ); + await FractionToken.write.safeTransferFrom( + [ + address1.account?.address!, + address3.account?.address!, + tokenId, + 1000n, + "0x", + ], + { + account: address1.account!, + } + ); const address1Balance = await FractionToken.read.balanceOf([ address1.account?.address!, address1.account?.address!, hat1_id, ]); - expect(address1Balance).to.equal(7000n); + expect(address1Balance).to.equal(6000n); // address2のbalance const address2Balance = await FractionToken.read.balanceOf([ @@ -571,7 +585,7 @@ describe("CreateSplit", () => { } } - expect(shareHolders.length).to.equal(4); + expect(shareHolders.length).to.equal(5); const address1Time = endWoreTime - address1WoreTime; const address2Time = endWoreTime - address2WoreTime; @@ -586,7 +600,13 @@ describe("CreateSplit", () => { address1.account?.address!, hat1_id, ]); - expect(address1Balance).to.equal(7000n); + expect(address1Balance).to.equal(6000n); + + const address3_address1Balance = await FractionToken.read.balanceOf([ + address3.account?.address!, + address1.account?.address!, + hat1_id, + ]); const address4Balance = await FractionToken.read.balanceOf([ address4.account?.address!, @@ -608,7 +628,7 @@ describe("CreateSplit", () => { ]); expect(address3Balance).to.equal(10000n); - expect(allocations.length).to.equal(4); + expect(allocations.length).to.equal(5); expect(allocations[0]).to.equal( ((address1Balance * 1000000n) / 20000n) * 1n * sqrtAddress1Time ); @@ -616,9 +636,12 @@ describe("CreateSplit", () => { ((address4Balance * 1000000n) / 20000n) * 1n * sqrtAddress1Time ); expect(allocations[2]).to.equal( - ((address2Balance * 1000000n) / 20000n) * 1n * sqrtAddress2Time + ((address3_address1Balance * 1000000n) / 20000n) * 1n * sqrtAddress1Time ); expect(allocations[3]).to.equal( + ((address2Balance * 1000000n) / 20000n) * 1n * sqrtAddress2Time + ); + expect(allocations[4]).to.equal( ((address3Balance * 1000000n) / 10000n) * 2n * sqrtAddress3Time ); @@ -777,11 +800,12 @@ describe("CreateSplit", () => { allocation3, ]; - expect(shareHolders.length).to.equal(4); + expect(shareHolders.length).to.equal(5); const expectedShareHolders = [ address1.account?.address!, address4.account?.address!, + address3.account?.address!, address2.account?.address!, address3.account?.address!, ]; @@ -799,12 +823,15 @@ describe("CreateSplit", () => { expect(shareHolders[3].toLowerCase()).to.equal( expectedShareHolders[3].toLowerCase() ); + expect(shareHolders[4].toLowerCase()).to.equal( + expectedShareHolders[4].toLowerCase() + ); - expect(allocations.length).to.equal(4); + expect(allocations.length).to.equal(5); expect(allocations[0]).to.equal(expectedAllocations[0]); expect(allocations[1]).to.equal(expectedAllocations[1]); - expect(allocations[2]).to.equal(expectedAllocations[2]); - expect(allocations[3]).to.equal(expectedAllocations[3]); + expect(allocations[3]).to.equal(expectedAllocations[2]); + expect(allocations[4]).to.equal(expectedAllocations[3]); }); }); diff --git a/pkgs/frontend/abi/splits.ts b/pkgs/frontend/abi/splits.ts index e36ca26..7a16c02 100644 --- a/pkgs/frontend/abi/splits.ts +++ b/pkgs/frontend/abi/splits.ts @@ -162,9 +162,14 @@ export const SPLITS_CREATOR_ABI = [ }, { internalType: "uint256[]", - name: "percentages", + name: "allocations", type: "uint256[]", }, + { + internalType: "uint256", + name: "totalAllocation", + type: "uint256", + }, ], stateMutability: "view", type: "function", diff --git a/pkgs/frontend/app/routes/$treeId_.splitter.new.tsx b/pkgs/frontend/app/routes/$treeId_.splitter.new.tsx index 8268b0d..a2bd49b 100644 --- a/pkgs/frontend/app/routes/$treeId_.splitter.new.tsx +++ b/pkgs/frontend/app/routes/$treeId_.splitter.new.tsx @@ -60,8 +60,6 @@ const RoleItem: FC = ({ const [wearersAddress, setWearersAddress] = useState([]); - const [multiplier, setMultiplier] = useState(1); - useEffect(() => { const fetch = async () => { const res = await getWearersInfo({ hatId: field.hatId }); @@ -73,34 +71,6 @@ const RoleItem: FC = ({ const { names } = useNamesByAddresses(wearersAddress); - // const handleUpdateMultiplier = (e: ChangeEvent) => { - // if (e.target.value.endsWith(".")) return; - // const float = Number(e.target.value); - // if (Number.isInteger(float)) { - // update(fieldIndex, { - // ...field, - // multiplierTop: BigInt(float), - // multiplierBottom: BigInt(1), - // }); - // return; - // } - - // const str = float.toString(); - // const decimalPlaces = str.includes(".") ? str.split(".")[1].length : 0; - - // const bottom = Math.pow(10, decimalPlaces); - // const top = Math.round(float * bottom); - - // const gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b)); - // const divisor = gcd(top, bottom); - - // update(fieldIndex, { - // ...field, - // multiplierTop: BigInt(top / divisor), - // multiplierBottom: BigInt(bottom / divisor), - // }); - // }; - const handleOnCheck = (address: Address) => { if (!address) return; const array = field.wearers.includes(address) @@ -112,6 +82,14 @@ const RoleItem: FC = ({ }); }; + const handleUpdateMultiplier = (e: ChangeEvent) => { + const value = Number(e.target.value); + update(fieldIndex, { + ...field, + multiplier: value, + }); + }; + return ( @@ -132,8 +110,8 @@ const RoleItem: FC = ({ 分配係数 setMultiplier(Number(e.target.value))} + value={field.multiplier} + onChange={handleUpdateMultiplier} placeholder="例: 1, 1.5 10" textAlign="center" w="80px" @@ -235,7 +213,7 @@ const SplitterNew: FC = () => { ); }, [hats]); - const { isLoading, createSplits, previewSplits } = useSplitsCreator(treeId!); + const { createSplits, previewSplits } = useSplitsCreator(treeId!); const { control, getValues } = useForm(); const { fields, insert, update } = useFieldArray({ @@ -266,10 +244,17 @@ const SplitterNew: FC = () => { const handlePreview = async () => { const data = getValues(); + const params = data.roles.map((role) => ({ hatId: BigInt(role.hatId), - multiplierBottom: BigInt(1), - multiplierTop: BigInt(1), + multiplierBottom: role.multiplier + ? BigInt(String(role.multiplier).split(".")[1].length * 10) + : BigInt(1), + multiplierTop: role.multiplier + ? BigInt( + role.multiplier * String(role.multiplier).split(".")[1].length * 10 + ) + : BigInt(1), wearers: role.wearers, })); const res = await previewSplits(params); @@ -289,8 +274,14 @@ const SplitterNew: FC = () => { const data = getValues(); const params = data.roles.map((role) => ({ hatId: BigInt(role.hatId), - multiplierBottom: BigInt(1), - multiplierTop: BigInt(1), + multiplierBottom: role.multiplier + ? BigInt(String(role.multiplier).split(".")[1].length * 10) + : BigInt(1), + multiplierTop: role.multiplier + ? BigInt( + role.multiplier * String(role.multiplier).split(".")[1].length * 10 + ) + : BigInt(1), wearers: role.wearers, })); const txHash = await createSplits({