From cdcfb0249b66456e9bfc544944fee283b63627da Mon Sep 17 00:00:00 2001 From: yawn <69970183+yawn-c111@users.noreply.github.com> Date: Thu, 3 Oct 2024 20:32:18 +0900 Subject: [PATCH] feat: add createHat command into commands/hats.ts --- pkgs/cli/src/commands/hats.ts | 39 +++++++++++++++++++++++++++- pkgs/cli/src/modules/hatsProtocol.ts | 24 +++++++---------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/pkgs/cli/src/commands/hats.ts b/pkgs/cli/src/commands/hats.ts index 3a46acd..583ee1f 100644 --- a/pkgs/cli/src/commands/hats.ts +++ b/pkgs/cli/src/commands/hats.ts @@ -3,10 +3,12 @@ import { getTreeInfo, getWearerInfo, getWearersInfo, + createHat, mintHat, } from "../modules/hatsProtocol"; import { getAccount } from "../services/wallet"; import { publicClient, rootProgram, walletClient } from ".."; +import { Address } from "viem"; export const hatsCommands = new Command(); @@ -67,13 +69,48 @@ hatsCommands console.log(wearer); }); +/** + * ロールを作成 + */ +hatsCommands + .command("createHat") + .description("Create Hat") + .requiredOption("-hid", "--hatId ", "Hat ID") + .requiredOption("-img", "--imageUri ", "Image URI") + .option("-det", "--details
", "Details") + .option("-max", "--maxSupply ", "Max Supply") + .option("-el", "--eligibility ", "Eligibility Address") + .option("-tgl", "--toggle ", "Toggle") + .option("-mut", "--mutable ", "Mutable") + .action( + async ({ + hatId, + details, + maxSupply, + eligibility, + toggle, + mutable, + imageURI, + }) => { + await createHat({ + parentHatId: BigInt(hatId), + details, + maxSupply, + eligibility: eligibility as Address, + toggle: toggle as Address, + mutable: mutable, + imageURI, + }); + } + ); + /** * ロールを付与 */ hatsCommands .command("mintHat") .description("Mint Hat") - .requiredOption("--hatId ", "Hat ID") + .requiredOption("-hid", "--hatId ", "Hat ID") .requiredOption("--wearer ", "Wearer address") .action(async ({ hatId, wearer }) => { await mintHat({ hatId, wearer }); diff --git a/pkgs/cli/src/modules/hatsProtocol.ts b/pkgs/cli/src/modules/hatsProtocol.ts index 25a1d0c..8428332 100644 --- a/pkgs/cli/src/modules/hatsProtocol.ts +++ b/pkgs/cli/src/modules/hatsProtocol.ts @@ -1,5 +1,5 @@ import { HatsSubgraphClient } from "@hatsprotocol/sdk-v1-subgraph"; -import { Address, PublicClient, WalletClient } from "viem"; +import { Address } from "viem"; import { base, optimism, sepolia } from "viem/chains"; import { hatsContractBaseConfig, @@ -110,19 +110,15 @@ export const getWearerInfo = async (walletAddress: string, chainId: number) => { /** * 新規Hat作成 */ -export const createHat = async ( - publicClient: PublicClient, - walletClient: WalletClient, - args: { - parentHatId: bigint; - details?: string; - maxSupply?: number; - eligibility?: Address; - toggle?: Address; - mutable?: boolean; - imageURI: string; - } -) => { +export const createHat = async (args: { + parentHatId: bigint; + details?: string; + maxSupply?: number; + eligibility?: Address; + toggle?: Address; + mutable?: boolean; + imageURI: string; +}) => { const { request } = await publicClient.simulateContract({ ...hatsContractBaseConfig, account: walletClient.account,