Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/138 #150

Merged
merged 7 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkgs/contract/contracts/bigbang/BigBang.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract BigBang is ERC2771Context {
event Executed(
address indexed owner,
uint256 indexed topHatId,
uint256 indexed hatterHatId,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hats protocol の hatId の取得が大変そうだったため、 hatterHatIdtopHatId とともに event で emit してみましたが、大丈夫でしょうか?

address hatsTimeFrameModule,
address splitCreator
);
Expand Down Expand Up @@ -118,7 +119,7 @@ contract BigBang is ERC2771Context {
keccak256(abi.encodePacked(topHatId))
);

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

return topHatId;
}
Expand Down
7 changes: 6 additions & 1 deletion pkgs/contract/contracts/splitscreator/ISplitsCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ interface ISplitsCreator {
address[] wearers;
}

event SplitsCreated(address split);
event SplitsCreated(
address split,
address[] shareHolders,
uint256[] allocations,
uint256 totalAllocation
Comment on lines +15 to +17
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

役割や着用時間の重み計算後の値は、後で取得したり計算するのが大変そうだったため、event に追加してみたのですが、大丈夫でしょうか?

);

function create(SplitsInfo[] memory _splitInfos) external returns (address);
}
35 changes: 13 additions & 22 deletions pkgs/contract/contracts/splitscreator/SplitsCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ contract SplitsCreator is ISplitsCreator, Clone {
);
address[] memory recepients = FRACTION_TOKEN()
.getTokenRecipients(tokenId);
numOfShareHolders += recepients.length + 1;
numOfShareHolders += recepients.length;
}
}

address[] memory shareHolders = new address[](numOfShareHolders);
address[] memory warers = new address[](numOfShareHolders);
uint256[] memory hatIdsOfShareHolders = new uint256[](
numOfShareHolders
);
address[] memory wearers = new address[](numOfShareHolders);
uint256[] memory hatIdsOfShareHolders = new uint256[](numOfShareHolders);
uint256[] memory roleMultipliersOfShareHolders = new uint256[](
numOfShareHolders
);
Expand All @@ -66,36 +64,24 @@ contract SplitsCreator is ISplitsCreator, Clone {

for (uint i = 0; i < _splitsInfo.length; i++) {
SplitsInfo memory _splitInfo = _splitsInfo[i];
uint256 roleMultiplier = _splitInfo.multiplierTop /
_splitInfo.multiplierBottom;
for (uint si = 0; si < _splitInfo.wearers.length; si++) {
uint256 tokenId = FRACTION_TOKEN().getTokenId(
_splitInfo.hatId,
_splitInfo.wearers[si]
);
uint256 roleMultiplier = _splitInfo.multiplierTop /
_splitInfo.multiplierBottom;
uint256 hatsTimeFrameMultiplier = _getHatsTimeFrameMultiplier(
_splitInfo.wearers[si],
_splitInfo.hatId
);

// ロール保持者に対する分配の計算
shareHolders[shareHolderIndex] = _splitInfo.wearers[si];
warers[shareHolderIndex] = _splitInfo.wearers[si];
hatIdsOfShareHolders[shareHolderIndex] = _splitInfo.hatId;
roleMultipliersOfShareHolders[
shareHolderIndex
] = roleMultiplier;
hatsTimeFrameMultipliersOfShareHolders[
shareHolderIndex
] = hatsTimeFrameMultiplier;
shareHolderIndex++;

// FractionTokenのホルダーに対する分配の計算
address[] memory recipients = FRACTION_TOKEN()
.getTokenRecipients(tokenId);
for (uint j = 0; j < recipients.length; j++) {
shareHolders[shareHolderIndex] = recipients[j];
warers[shareHolderIndex] = _splitInfo.wearers[si];
wearers[shareHolderIndex] = _splitInfo.wearers[si];
hatIdsOfShareHolders[shareHolderIndex] = _splitInfo.hatId;
roleMultipliersOfShareHolders[
shareHolderIndex
Expand All @@ -109,7 +95,7 @@ contract SplitsCreator is ISplitsCreator, Clone {
}

uint256[] memory balanceOfShareHolders = FRACTION_TOKEN()
.balanceOfBatch(shareHolders, warers, hatIdsOfShareHolders);
.balanceOfBatch(shareHolders, wearers, hatIdsOfShareHolders);

uint256 totalAllocation = 0;
uint256[] memory allocations = new uint256[](shareHolderIndex);
Expand All @@ -135,7 +121,12 @@ contract SplitsCreator is ISplitsCreator, Clone {
_generateSalt(_splitsInfo)
);

emit SplitsCreated(split);
emit SplitsCreated(
split,
shareHolders,
allocations,
totalAllocation
);

return split;
}
Expand Down
12 changes: 6 additions & 6 deletions pkgs/contract/gas-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
··············|··········|··············|·············|·············|···············|··············
| Deployments · · % of limit · │
·························|··············|·············|·············|···············|··············
| BigBang · - · - · 1089851 · 3.6 % · - │
| BigBang · - · - · 1092017 · 3.6 % · - │
·························|··············|·············|·············|···············|··············
| FractionToken · - · - · 2573797 · 8.6 % · - │
| FractionToken · 2573785 · 2573797 · 2573795 · 8.6 % · - │
·························|··············|·············|·············|···············|··············
| Hats · - · - · 7032431 · 23.4 % · - │
·························|··············|·············|·············|···············|··············
| HatsModule · - · - · 754132 · 2.5 % · - │
·························|··············|·············|·············|···············|··············
| HatsModuleFactory · - · - · 1101122 · 3.7 % · - │
| HatsModuleFactory · 1101110 · 1101122 · 1101120 · 3.7 % · - │
·························|··············|·············|·············|···············|··············
| HatsTimeFrameModule · - · - · 1115811 · 3.7 % · - │
·························|··············|·············|·············|···············|··············
| PullSplitFactory · 4535815 · 4535827 · 4535824 · 15.1 % · - │
| PullSplitFactory · - · - · 4535827 · 15.1 % · - │
·························|··············|·············|·············|···············|··············
| PushSplitFactory · 4483101 · 4483113 · 4483110 · 14.9 % · - │
| PushSplitFactory · - · - · 4483113 · 14.9 % · - │
·························|··············|·············|·············|···············|··············
| SplitsCreator · - · - · 1515444 · 5.1 % · - │
| SplitsCreator · - · - · 1487532 · 5 % · - │
·························|··············|·············|·············|···············|··············
| SplitsCreatorFactory · - · - · 526836 · 1.8 % · - │
·························|··············|·············|·············|···············|··············
Expand Down
15 changes: 15 additions & 0 deletions pkgs/contract/helpers/util/sqrt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function sqrt(y: bigint): bigint {
if (y > 3n) {
let z: bigint = y;
let x: bigint = y / 2n + 1n;
while (x < z) {
z = x;
x = (y / x + x) / 2n;
}
return z;
} else if (y !== 0n) {
return 1n;
} else {
return 0n;
}
}
4 changes: 3 additions & 1 deletion pkgs/contract/test/BigBang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ describe("BigBang", () => {
topics: log.topics,
});
if (decodedLog.eventName == "Executed") {
expect(decodedLog.args.owner).to.be.equal(address1.account?.address!);
expect(decodedLog.args.owner.toLowerCase()).to.be.equal(
address1.account?.address!
);
}
} catch (error) {}
}
Expand Down
Loading
Loading