Skip to content
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
15 changes: 12 additions & 3 deletions pkgs/contract/contracts/thankstoken/IThanksToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ interface IThanksToken is IERC20 {
* @param to The address to mint tokens to
* @param amount The amount of tokens to mint
* @param relatedRoles Array of roles related to the sender
* @param data Additional data with no specified format
* @return success Whether the operation was successful
*/
function mint(
address to,
uint256 amount,
RelatedRole[] memory relatedRoles
RelatedRole[] memory relatedRoles,
bytes memory data
) external returns (bool);

/**
* @notice Mints new tokens to multiple recipients
* @param to Array of addresses to mint tokens to
* @param amounts Array of amounts of tokens to mint
* @param relatedRoles Array of roles related to the sender
* @param data Additional data with no specified format
* @return success Whether the operation was successful
*/
function batchMint(
address[] memory to,
uint256[] memory amounts,
RelatedRole[] memory relatedRoles
RelatedRole[] memory relatedRoles,
bytes memory data
) external returns (bool);

/**
Expand Down Expand Up @@ -81,5 +85,10 @@ interface IThanksToken is IERC20 {
* @param to The recipient of the minted tokens
* @param amount The amount of tokens minted
*/
event TokenMinted(address indexed from, address indexed to, uint256 amount);
event TokenMinted(
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
}
10 changes: 6 additions & 4 deletions pkgs/contract/contracts/thankstoken/ThanksToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ contract ThanksToken is Clone, ERC20("", ""), IThanksToken {
function mint(
address to,
uint256 amount,
RelatedRole[] memory relatedRoles
RelatedRole[] memory relatedRoles,
bytes memory data
) public override returns (bool) {
require(to != msg.sender, "Cannot mint to yourself");
require(amount > 0, "Amount must be greater than 0");
Expand All @@ -131,15 +132,16 @@ contract ThanksToken is Clone, ERC20("", ""), IThanksToken {
_isParticipant[to] = true;
}

emit TokenMinted(msg.sender, to, amount);
emit TokenMinted(msg.sender, to, amount, data);

return true;
}

function batchMint(
address[] memory to,
uint256[] memory amounts,
RelatedRole[] memory relatedRoles
RelatedRole[] memory relatedRoles,
bytes memory data
) public override returns (bool) {
require(to.length == amounts.length, "Arrays length mismatch");

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

emit TokenMinted(msg.sender, to[i], amounts[i]);
emit TokenMinted(msg.sender, to[i], amounts[i], data);
}

if (!_isParticipant[msg.sender]) {
Expand Down
60 changes: 60 additions & 0 deletions pkgs/contract/scripts/deploy/thankstoken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ethers, network } from "hardhat";
import type { Address } from "viem";
import {
deployThanksToken,
deployThanksTokenFactory,
} from "../../helpers/deploy/ThanksToken";

const deploy = async () => {
console.log(
"##################################### [Create2 Deploy START] #####################################",
);

const [deployerSigner] = await ethers.getSigners();
const deployerAddress = await deployerSigner.getAddress();

console.log("Deploying ThanksToken...");
const { ThanksToken } = await deployThanksToken();
const thanksTokenAddress = ThanksToken.address;

console.log("Deploying ThanksTokenFactory...");

const {
ThanksTokenFactory,
ThanksTokenFactoryImplAddress,
ThanksTokenFactoryInitData,
} = await deployThanksTokenFactory({
initialOwner: deployerAddress as Address,
implementation: thanksTokenAddress,
hatsAddress: process.env.HATS_ADDRESS as Address,
});
const thanksTokenFactoryAddress = ThanksTokenFactory.address;

// Set bigbang address to thanks token factory
const ThanksTokenFactoryContract = await ethers.getContractAt(
"ThanksTokenFactory",
thanksTokenFactoryAddress,
);
await ThanksTokenFactoryContract.setBigBang(
"0xfB4FA9Dbb82a36566154A038e5f3865fbAC92422",
);

console.log("Successfully deployed contracts!🎉");
console.log("Verify contract with these commands...\n");

console.log(
"ThanksToken:\n",
`pnpm contract hardhat verify ${thanksTokenAddress} --network ${network.name}\n`,
);
console.log(
"ThanksTokenFactory:\n",
`pnpm contract hardhat verify ${ThanksTokenFactoryImplAddress} --network ${network.name} &&`,
`pnpm contract hardhat verify ${thanksTokenFactoryAddress} ${ThanksTokenFactoryImplAddress} ${ThanksTokenFactoryInitData} --network ${network.name}\n`,
);

console.log(
"\n##################################### [Create2 Deploy END] #####################################",
);
};

deploy();
1 change: 1 addition & 0 deletions pkgs/contract/test/IntegrationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ describe("IntegrationTest", () => {
wearer: address1.account?.address!,
},
],
"0x",
],
{ account: address1.account },
);
Expand Down
4 changes: 2 additions & 2 deletions pkgs/contract/test/SplitsCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ describe("CreateSplit with thanks token weight", () => {
expect(Number(mintableAmount1)).to.be.greaterThan(0);

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

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

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

Expand Down
12 changes: 6 additions & 6 deletions pkgs/contract/test/ThanksToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ describe("ThanksToken", () => {
expect(Number(mintableAmount)).to.be.equal(600000000000000000000);

await DeployedThanksToken.write.mint(
[address2Validated, mintableAmount / 2n, relatedRoles],
[address2Validated, mintableAmount / 2n, relatedRoles, "0x"],
{
account: address1.account,
},
Expand Down Expand Up @@ -542,7 +542,7 @@ describe("ThanksToken", () => {

try {
await DeployedThanksToken.write.mint(
[address2Validated, amountToMint, relatedRoles],
[address2Validated, amountToMint, relatedRoles, "0x"],
{ account: address1.account },
);
} catch (error: any) {
Expand Down Expand Up @@ -678,7 +678,7 @@ describe("ThanksToken", () => {

try {
await DeployedThanksToken.write.mint(
[address1Validated, 1n, relatedRoles],
[address1Validated, 1n, relatedRoles, "0x"],
{ account: address1.account },
);
// If we get here, the mint succeeded when it should have failed
Expand All @@ -697,7 +697,7 @@ describe("ThanksToken", () => {
];
try {
await DeployedThanksToken.write.mint(
[address2Validated, 1000000n, relatedRoles],
[address2Validated, 1000000n, relatedRoles, "0x"],
{ account: address1.account },
);
// If we get here, the mint succeeded when it should have failed
Expand Down Expand Up @@ -735,7 +735,7 @@ describe("ThanksToken", () => {

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

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

await DeployedThanksToken.write.mint(
[address2Validated, mintableAmount2, relatedRoles],
[address2Validated, mintableAmount2, relatedRoles, "0x"],
{ account: address1.account },
);

Expand Down
16 changes: 16 additions & 0 deletions pkgs/frontend/abi/thankstoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ export const THANKS_TOKEN_ABI = [
name: "amount",
type: "uint256",
},
{
indexed: false,
internalType: "bytes",
name: "data",
type: "bytes",
},
],
name: "TokenMinted",
type: "event",
Expand Down Expand Up @@ -353,6 +359,11 @@ export const THANKS_TOKEN_ABI = [
name: "relatedRoles",
type: "tuple[]",
},
{
internalType: "bytes",
name: "data",
type: "bytes",
},
],
name: "batchMint",
outputs: [
Expand Down Expand Up @@ -433,6 +444,11 @@ export const THANKS_TOKEN_ABI = [
name: "relatedRoles",
type: "tuple[]",
},
{
internalType: "bytes",
name: "data",
type: "bytes",
},
],
name: "mint",
outputs: [
Expand Down
27 changes: 26 additions & 1 deletion pkgs/frontend/app/components/assistcredit/AmountSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Box, Flex, HStack, Stack, Text, VStack } from "@chakra-ui/react";
import {
Box,
Flex,
HStack,
Stack,
Text,
Textarea,
VStack,
} from "@chakra-ui/react";
import { Slider, useSlider } from "@chakra-ui/react/slider";
import type { NameData } from "namestone-sdk";
import { useEffect, useState } from "react";
Expand All @@ -24,6 +32,8 @@ const getNearestEmoji = (amount: number): number => {
interface AmountSelectorProps {
amount: number;
setAmount: (amount: number) => void;
data?: string;
setData?: (data: string) => void;
onNext: () => void;
isLoading: boolean;
me?: NameData;
Expand All @@ -36,6 +46,8 @@ interface AmountSelectorProps {
const AmountSelector = ({
amount,
setAmount,
data,
setData,
onNext,
isLoading,
me,
Expand Down Expand Up @@ -166,6 +178,19 @@ const AmountSelector = ({
</Text>
</Box>
</HStack>

{setData && (
<Field mb={4} width="100%">
<Textarea
backgroundColor="white"
rows={2}
maxLength={150}
placeholder="メッセージを追加 (任意)"
value={data}
onChange={(e) => setData(e.target.value)}
/>
</Field>
)}
<BasicButton
colorScheme="yellow"
loading={isLoading}
Expand Down
Loading
Loading