Skip to content

Commit

Permalink
Merge pull request #127 from hackdays-io/issue/104
Browse files Browse the repository at this point in the history
Issue/104
  • Loading branch information
yu23ki14 authored Oct 3, 2024
2 parents dc9f483 + 83497c6 commit 2647982
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 149 deletions.
217 changes: 217 additions & 0 deletions pkgs/cli/src/abi/hatsTimeFrameModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
export const HATS_TIME_FRAME_MODULE_ABI = [
{
inputs: [
{
internalType: "address",
name: "_trustedForwarder",
type: "address",
},
{
internalType: "string",
name: "_version",
type: "string",
},
],
stateMutability: "nonpayable",
type: "constructor",
},
{
inputs: [],
name: "InvalidInitialization",
type: "error",
},
{
inputs: [],
name: "NotInitializing",
type: "error",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "version",
type: "uint64",
},
],
name: "Initialized",
type: "event",
},
{
inputs: [],
name: "HATS",
outputs: [
{
internalType: "contract IHats",
name: "",
type: "address",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [],
name: "IMPLEMENTATION",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "wearer",
type: "address",
},
{
internalType: "uint256",
name: "hatId",
type: "uint256",
},
],
name: "getWearingElapsedTime",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "wearer",
type: "address",
},
{
internalType: "uint256",
name: "hatId",
type: "uint256",
},
],
name: "getWoreTime",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "hatId",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "forwarder",
type: "address",
},
],
name: "isTrustedForwarder",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "uint256",
name: "hatId",
type: "uint256",
},
{
internalType: "address",
name: "wearer",
type: "address",
},
],
name: "mintHat",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "bytes",
name: "_initData",
type: "bytes",
},
],
name: "setUp",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "trustedForwarder",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "version",
outputs: [
{
internalType: "string",
name: "",
type: "string",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "version_",
outputs: [
{
internalType: "string",
name: "",
type: "string",
},
],
stateMutability: "view",
type: "function",
},
] as const;
70 changes: 0 additions & 70 deletions pkgs/cli/src/commands/function.ts

This file was deleted.

23 changes: 20 additions & 3 deletions pkgs/cli/src/commands/hats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
getTreeInfo,
getWearerInfo,
getWearersInfo,
mintHat,
} from "../modules/hatsProtocol";
import { getAccount } from "../services/wallet";
import { publicClient, rootProgram, walletClient } from "..";

export const hatsCommands = new Command();

Expand All @@ -29,7 +32,7 @@ hatsCommands
.option("-id, --treeId <treeId>", "Tree ID")
.action(async (options) => {
// ツリー情報を全て取得する。
const tree = await getTreeInfo(Number(options.treeId));
const tree = await getTreeInfo(Number(options.treeId), options.chainId);

console.log(tree);
});
Expand All @@ -43,7 +46,7 @@ hatsCommands
.option("-id, --hatId <hatId>", "Hat ID")
.action(async (options) => {
// ツリー情報を全て取得する。
const wearers = await getWearersInfo(options.hatId);
const wearers = await getWearersInfo(options.hatId, options.chainId);

console.log(wearers);
});
Expand All @@ -57,7 +60,21 @@ hatsCommands
.option("-addr, --address <address>", "Wallet Address")
.action(async (options) => {
// 特定のウォレットアドレスに紐づく情報を全て取得する。
const wearer = await getWearerInfo(options.address);
const address =
options.address || getAccount(rootProgram.opts().profile).address;
const wearer = await getWearerInfo(address, rootProgram.opts().chain);

console.log(wearer);
});

/**
* ロールを付与
*/
hatsCommands
.command("mintHat")
.description("Mint Hat")
.requiredOption("--hatId <hatId>", "Hat ID")
.requiredOption("--wearer <wearer>", "Wearer address")
.action(async ({ hatId, wearer }) => {
await mintHat({ hatId, wearer });
});
16 changes: 6 additions & 10 deletions pkgs/cli/src/commands/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Command } from "commander";
import { getEthAddress, sendEth } from "../modules/viem";
import { sendEth } from "../modules/viem";
import { listProfiles, saveProfile, deleteProfile } from "../services/wallet";
import { walletClient } from "..";

export const walletCommands = new Command();

const { TOBAN_PRIVATE_KEY } = process.env;

walletCommands
.name("wallet")
.description("This is a CLI function for toban project")
Expand Down Expand Up @@ -50,11 +49,8 @@ walletCommands
walletCommands
.command("sendEth")
.description("Send ETH")
.action(async () => {
console.log("Start send ETH");
const address1 = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";

await sendEth(TOBAN_PRIVATE_KEY as `0x${string}`, address1);

console.log("End send ETH");
.requiredOption("--receiver <receiver>", "Receiver address")
.requiredOption("--amount <amount>", "Amount")
.action(async ({ receiver, amount }) => {
await sendEth(walletClient, receiver, amount);
});
15 changes: 15 additions & 0 deletions pkgs/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Address } from "viem";
import { HATS_ABI } from "./abi/hats";
import { HATS_TIME_FRAME_MODULE_ABI } from "./abi/hatsTimeFrameModule";

export const skipPreActionCommands = ["wallet>add", "wallet>list"];

export const hatsContractBaseConfig = {
address: "0x3bc1A0Ad72417f2d411118085256fC53CBdDd137" as Address,
abi: HATS_ABI,
};

export const hatsTimeFrameContractBaseConfig = {
address: "0xd4a66507ea8c8382fa8474ed6cae4163676a434a" as Address,
abi: HATS_TIME_FRAME_MODULE_ABI,
};
Loading

0 comments on commit 2647982

Please sign in to comment.