Skip to content

Commit

Permalink
feat: add splits command
Browse files Browse the repository at this point in the history
  • Loading branch information
yawn-c111 committed Oct 3, 2024
1 parent 57f4131 commit 1c351ce
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
108 changes: 108 additions & 0 deletions pkgs/cli/src/abi/splits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
export const SPLITS_ABI = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "split",
type: "address",
},
],
name: "SplitsCreated",
type: "event",
},
{
inputs: [],
name: "FRACTION_TOKEN",
outputs: [
{
internalType: "contract IFractionToken",
name: "",
type: "address",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [],
name: "HATS_TIME_FRAME_MODULE",
outputs: [
{
internalType: "contract IHatsTimeFrameModule",
name: "",
type: "address",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [],
name: "SPLIT_FACTORY_V2",
outputs: [
{
internalType: "contract ISplitFactoryV2",
name: "",
type: "address",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [],
name: "TRUSTED_FORWARDER",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "pure",
type: "function",
},
{
inputs: [
{
components: [
{
internalType: "uint256",
name: "hatId",
type: "uint256",
},
{
internalType: "uint256",
name: "multiplierBottom",
type: "uint256",
},
{
internalType: "uint256",
name: "multiplierTop",
type: "uint256",
},
{
internalType: "address[]",
name: "wearers",
type: "address[]",
},
],
internalType: "struct ISplitsCreator.SplitsInfo[]",
name: "_splitsInfo",
type: "tuple[]",
},
],
name: "create",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "nonpayable",
type: "function",
},
] as const;
61 changes: 61 additions & 0 deletions pkgs/cli/src/commands/splits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Command } from "commander";
import { create } from "../modules/splits";
import { getAccount } from "../services/wallet";
import { rootProgram } from "..";
import { Address } from "viem";

export const splitsCommands = new Command();

// ###############################################################
// CLI init setup
// ###############################################################

splitsCommands
.name("splits")
.description("This is a CLI splits for toban project")
.version("1.0.0");

// ###############################################################
// command setUp
// ###############################################################

/**
* スプリットを作成
*/
splitsCommands
.command("create")
.description("Create Splits")
.requiredOption(
"-splits",
"--splitsAddress <splitsAddress>",
"Splits Address"
)
.requiredOption("-hid --hatId <hatId>", "Hat ID")
.requiredOption(
"-mb --multiplierBottom <multiplierBottom>",
"Multiplier Bottom"
)
.requiredOption("-mt --multiplierTop <multiplierTop>", "Multiplier Top")
.requiredOption("-w --wearers <wearers>", "Wearers")
.action(
async ({
splitsAddress,
hatId,
multiplierBottom,
multiplierTop,
wearer,
}) => {
const hash = await create(splitsAddress, [
{
hatId: hatId,
multiplierBottom: multiplierBottom,
multiplierTop: multiplierTop,
wearers: [
"0x777ee5eeed30c3712bee6c83260d786857d9c556" as Address,
// "0xEef377Bdf67A227a744e386231fB3f264C158CDF",
],
},
]);
console.log("Transaction sent. Hash:", hash);
}
);
2 changes: 2 additions & 0 deletions pkgs/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Command } from "commander";
import { hatsCommands } from "./commands/hats";
import { walletCommands } from "./commands/wallet";
import { splitsCommands } from "./commands/splits";
import { PublicClient, WalletClient } from "viem";
import { getPublicClient } from "./modules/viem";
import { getWalletClient } from "./services/wallet";
Expand Down Expand Up @@ -33,5 +34,6 @@ rootProgram
rootProgram.addCommand(bigbangCommands);
rootProgram.addCommand(hatsCommands);
rootProgram.addCommand(walletCommands);
rootProgram.addCommand(splitsCommands);

rootProgram.parse(process.argv);
31 changes: 31 additions & 0 deletions pkgs/cli/src/modules/splits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HatsSubgraphClient } from "@hatsprotocol/sdk-v1-subgraph";
import { Address } from "viem";
import { base, optimism, sepolia } from "viem/chains";
import {
hatsContractBaseConfig,
hatsTimeFrameContractBaseConfig,
} from "../config";
import { publicClient, walletClient } from "..";
import { SPLITS_ABI } from "../abi/splits";

type SplitsInfo = {
hatId: bigint;
multiplierBottom: bigint;
multiplierTop: bigint;
wearers: Address[];
};

/**
* Splitsを作成
*/
export const create = async (splitsAddress: Address, args: SplitsInfo[]) => {
const { request } = await publicClient.simulateContract({
address: "0x39cB5bb4D84a37d1d9D0Abb0c9a6C5F5DE501aba" as Address,
abi: SPLITS_ABI,
account: walletClient.account,
functionName: "create",
args: [args],
});
const hash = await walletClient.writeContract(request);
return hash;
};

0 comments on commit 1c351ce

Please sign in to comment.