Skip to content

Commit dca1e8c

Browse files
authored
Merge pull request #414 from hackdays-io/feature/thankscomment
Add message data in thanks token mint and add index the data with goldsky
2 parents 7d2f424 + 1f95062 commit dca1e8c

File tree

20 files changed

+303
-128
lines changed

20 files changed

+303
-128
lines changed

pkgs/contract/contracts/thankstoken/IThanksToken.sol

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ interface IThanksToken is IERC20 {
1818
* @param to The address to mint tokens to
1919
* @param amount The amount of tokens to mint
2020
* @param relatedRoles Array of roles related to the sender
21+
* @param data Additional data with no specified format
2122
* @return success Whether the operation was successful
2223
*/
2324
function mint(
2425
address to,
2526
uint256 amount,
26-
RelatedRole[] memory relatedRoles
27+
RelatedRole[] memory relatedRoles,
28+
bytes memory data
2729
) external returns (bool);
2830

2931
/**
3032
* @notice Mints new tokens to multiple recipients
3133
* @param to Array of addresses to mint tokens to
3234
* @param amounts Array of amounts of tokens to mint
3335
* @param relatedRoles Array of roles related to the sender
36+
* @param data Additional data with no specified format
3437
* @return success Whether the operation was successful
3538
*/
3639
function batchMint(
3740
address[] memory to,
3841
uint256[] memory amounts,
39-
RelatedRole[] memory relatedRoles
42+
RelatedRole[] memory relatedRoles,
43+
bytes memory data
4044
) external returns (bool);
4145

4246
/**
@@ -81,5 +85,10 @@ interface IThanksToken is IERC20 {
8185
* @param to The recipient of the minted tokens
8286
* @param amount The amount of tokens minted
8387
*/
84-
event TokenMinted(address indexed from, address indexed to, uint256 amount);
88+
event TokenMinted(
89+
address indexed from,
90+
address indexed to,
91+
uint256 amount,
92+
bytes data
93+
);
8594
}

pkgs/contract/contracts/thankstoken/ThanksToken.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ contract ThanksToken is Clone, ERC20("", ""), IThanksToken {
108108
function mint(
109109
address to,
110110
uint256 amount,
111-
RelatedRole[] memory relatedRoles
111+
RelatedRole[] memory relatedRoles,
112+
bytes memory data
112113
) public override returns (bool) {
113114
require(to != msg.sender, "Cannot mint to yourself");
114115
require(amount > 0, "Amount must be greater than 0");
@@ -131,15 +132,16 @@ contract ThanksToken is Clone, ERC20("", ""), IThanksToken {
131132
_isParticipant[to] = true;
132133
}
133134

134-
emit TokenMinted(msg.sender, to, amount);
135+
emit TokenMinted(msg.sender, to, amount, data);
135136

136137
return true;
137138
}
138139

139140
function batchMint(
140141
address[] memory to,
141142
uint256[] memory amounts,
142-
RelatedRole[] memory relatedRoles
143+
RelatedRole[] memory relatedRoles,
144+
bytes memory data
143145
) public override returns (bool) {
144146
require(to.length == amounts.length, "Arrays length mismatch");
145147

@@ -165,7 +167,7 @@ contract ThanksToken is Clone, ERC20("", ""), IThanksToken {
165167
_isParticipant[to[i]] = true;
166168
}
167169

168-
emit TokenMinted(msg.sender, to[i], amounts[i]);
170+
emit TokenMinted(msg.sender, to[i], amounts[i], data);
169171
}
170172

171173
if (!_isParticipant[msg.sender]) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { ethers, network } from "hardhat";
2+
import type { Address } from "viem";
3+
import {
4+
deployThanksToken,
5+
deployThanksTokenFactory,
6+
} from "../../helpers/deploy/ThanksToken";
7+
8+
const deploy = async () => {
9+
console.log(
10+
"##################################### [Create2 Deploy START] #####################################",
11+
);
12+
13+
const [deployerSigner] = await ethers.getSigners();
14+
const deployerAddress = await deployerSigner.getAddress();
15+
16+
console.log("Deploying ThanksToken...");
17+
const { ThanksToken } = await deployThanksToken();
18+
const thanksTokenAddress = ThanksToken.address;
19+
20+
console.log("Deploying ThanksTokenFactory...");
21+
22+
const {
23+
ThanksTokenFactory,
24+
ThanksTokenFactoryImplAddress,
25+
ThanksTokenFactoryInitData,
26+
} = await deployThanksTokenFactory({
27+
initialOwner: deployerAddress as Address,
28+
implementation: thanksTokenAddress,
29+
hatsAddress: process.env.HATS_ADDRESS as Address,
30+
});
31+
const thanksTokenFactoryAddress = ThanksTokenFactory.address;
32+
33+
// Set bigbang address to thanks token factory
34+
const ThanksTokenFactoryContract = await ethers.getContractAt(
35+
"ThanksTokenFactory",
36+
thanksTokenFactoryAddress,
37+
);
38+
await ThanksTokenFactoryContract.setBigBang(
39+
"0xfB4FA9Dbb82a36566154A038e5f3865fbAC92422",
40+
);
41+
42+
console.log("Successfully deployed contracts!🎉");
43+
console.log("Verify contract with these commands...\n");
44+
45+
console.log(
46+
"ThanksToken:\n",
47+
`pnpm contract hardhat verify ${thanksTokenAddress} --network ${network.name}\n`,
48+
);
49+
console.log(
50+
"ThanksTokenFactory:\n",
51+
`pnpm contract hardhat verify ${ThanksTokenFactoryImplAddress} --network ${network.name} &&`,
52+
`pnpm contract hardhat verify ${thanksTokenFactoryAddress} ${ThanksTokenFactoryImplAddress} ${ThanksTokenFactoryInitData} --network ${network.name}\n`,
53+
);
54+
55+
console.log(
56+
"\n##################################### [Create2 Deploy END] #####################################",
57+
);
58+
};
59+
60+
deploy();

pkgs/contract/test/IntegrationTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ describe("IntegrationTest", () => {
436436
wearer: address1.account?.address!,
437437
},
438438
],
439+
"0x",
439440
],
440441
{ account: address1.account },
441442
);

pkgs/contract/test/SplitsCreator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ describe("CreateSplit with thanks token weight", () => {
19381938
expect(Number(mintableAmount1)).to.be.greaterThan(0);
19391939

19401940
await ThanksToken.write.mint(
1941-
[address2.account?.address!, mintableAmount1 / 2n, relatedRoles1],
1941+
[address2.account?.address!, mintableAmount1 / 2n, relatedRoles1, "0x"],
19421942
{ account: address1.account },
19431943
);
19441944

@@ -1951,7 +1951,7 @@ describe("CreateSplit with thanks token weight", () => {
19511951
expect(Number(mintableAmount2)).to.be.greaterThan(0);
19521952

19531953
await ThanksToken.write.mint(
1954-
[address3.account?.address!, mintableAmount2 / 2n, relatedRoles2],
1954+
[address3.account?.address!, mintableAmount2 / 2n, relatedRoles2, "0x"],
19551955
{ account: address2.account },
19561956
);
19571957

pkgs/contract/test/ThanksToken.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ describe("ThanksToken", () => {
397397
expect(Number(mintableAmount)).to.be.equal(600000000000000000000);
398398

399399
await DeployedThanksToken.write.mint(
400-
[address2Validated, mintableAmount / 2n, relatedRoles],
400+
[address2Validated, mintableAmount / 2n, relatedRoles, "0x"],
401401
{
402402
account: address1.account,
403403
},
@@ -542,7 +542,7 @@ describe("ThanksToken", () => {
542542

543543
try {
544544
await DeployedThanksToken.write.mint(
545-
[address2Validated, amountToMint, relatedRoles],
545+
[address2Validated, amountToMint, relatedRoles, "0x"],
546546
{ account: address1.account },
547547
);
548548
} catch (error: any) {
@@ -678,7 +678,7 @@ describe("ThanksToken", () => {
678678

679679
try {
680680
await DeployedThanksToken.write.mint(
681-
[address1Validated, 1n, relatedRoles],
681+
[address1Validated, 1n, relatedRoles, "0x"],
682682
{ account: address1.account },
683683
);
684684
// If we get here, the mint succeeded when it should have failed
@@ -697,7 +697,7 @@ describe("ThanksToken", () => {
697697
];
698698
try {
699699
await DeployedThanksToken.write.mint(
700-
[address2Validated, 1000000n, relatedRoles],
700+
[address2Validated, 1000000n, relatedRoles, "0x"],
701701
{ account: address1.account },
702702
);
703703
// If we get here, the mint succeeded when it should have failed
@@ -735,7 +735,7 @@ describe("ThanksToken", () => {
735735

736736
// Mint from address1 to address3, who is a new participant
737737
await DeployedThanksToken.write.mint(
738-
[address3Validated, mintableAmount, relatedRoles],
738+
[address3Validated, mintableAmount, relatedRoles, "0x"],
739739
{ account: address1.account },
740740
);
741741

@@ -757,7 +757,7 @@ describe("ThanksToken", () => {
757757
expect(mintableAmount2 > 0n).to.be.true;
758758

759759
await DeployedThanksToken.write.mint(
760-
[address2Validated, mintableAmount2, relatedRoles],
760+
[address2Validated, mintableAmount2, relatedRoles, "0x"],
761761
{ account: address1.account },
762762
);
763763

pkgs/frontend/abi/thankstoken.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ export const THANKS_TOKEN_ABI = [
131131
name: "amount",
132132
type: "uint256",
133133
},
134+
{
135+
indexed: false,
136+
internalType: "bytes",
137+
name: "data",
138+
type: "bytes",
139+
},
134140
],
135141
name: "TokenMinted",
136142
type: "event",
@@ -353,6 +359,11 @@ export const THANKS_TOKEN_ABI = [
353359
name: "relatedRoles",
354360
type: "tuple[]",
355361
},
362+
{
363+
internalType: "bytes",
364+
name: "data",
365+
type: "bytes",
366+
},
356367
],
357368
name: "batchMint",
358369
outputs: [
@@ -433,6 +444,11 @@ export const THANKS_TOKEN_ABI = [
433444
name: "relatedRoles",
434445
type: "tuple[]",
435446
},
447+
{
448+
internalType: "bytes",
449+
name: "data",
450+
type: "bytes",
451+
},
436452
],
437453
name: "mint",
438454
outputs: [

pkgs/frontend/app/components/assistcredit/AmountSelector.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Box, Flex, HStack, Stack, Text, VStack } from "@chakra-ui/react";
1+
import {
2+
Box,
3+
Flex,
4+
HStack,
5+
Stack,
6+
Text,
7+
Textarea,
8+
VStack,
9+
} from "@chakra-ui/react";
210
import { Slider, useSlider } from "@chakra-ui/react/slider";
311
import type { NameData } from "namestone-sdk";
412
import { useEffect, useState } from "react";
@@ -24,6 +32,8 @@ const getNearestEmoji = (amount: number): number => {
2432
interface AmountSelectorProps {
2533
amount: number;
2634
setAmount: (amount: number) => void;
35+
data?: string;
36+
setData?: (data: string) => void;
2737
onNext: () => void;
2838
isLoading: boolean;
2939
me?: NameData;
@@ -36,6 +46,8 @@ interface AmountSelectorProps {
3646
const AmountSelector = ({
3747
amount,
3848
setAmount,
49+
data,
50+
setData,
3951
onNext,
4052
isLoading,
4153
me,
@@ -166,6 +178,19 @@ const AmountSelector = ({
166178
</Text>
167179
</Box>
168180
</HStack>
181+
182+
{setData && (
183+
<Field mb={4} width="100%">
184+
<Textarea
185+
backgroundColor="white"
186+
rows={2}
187+
maxLength={150}
188+
placeholder="メッセージを追加 (任意)"
189+
value={data}
190+
onChange={(e) => setData(e.target.value)}
191+
/>
192+
</Field>
193+
)}
169194
<BasicButton
170195
colorScheme="yellow"
171196
loading={isLoading}

0 commit comments

Comments
 (0)