Skip to content

Commit

Permalink
Merge pull request #130 from hackdays-io/issue/103
Browse files Browse the repository at this point in the history
Feat: add createHat command into commands/hats.ts
  • Loading branch information
yu23ki14 authored Oct 3, 2024
2 parents d415959 + cdcfb02 commit 57f4131
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
39 changes: 38 additions & 1 deletion pkgs/cli/src/commands/hats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -67,13 +69,48 @@ hatsCommands
console.log(wearer);
});

/**
* ロールを作成
*/
hatsCommands
.command("createHat")
.description("Create Hat")
.requiredOption("-hid", "--hatId <hatId>", "Hat ID")
.requiredOption("-img", "--imageUri <imageURI>", "Image URI")
.option("-det", "--details <details>", "Details")
.option("-max", "--maxSupply <maxSupply>", "Max Supply")
.option("-el", "--eligibility <eligibility>", "Eligibility Address")
.option("-tgl", "--toggle <toggle>", "Toggle")
.option("-mut", "--mutable <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 <hatId>", "Hat ID")
.requiredOption("-hid", "--hatId <hatId>", "Hat ID")
.requiredOption("--wearer <wearer>", "Wearer address")
.action(async ({ hatId, wearer }) => {
await mintHat({ hatId, wearer });
Expand Down
24 changes: 10 additions & 14 deletions pkgs/cli/src/modules/hatsProtocol.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 57f4131

Please sign in to comment.