@molteee/arena-tools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/arena.js +5 -0
- package/dist/client.d.ts +52 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +48 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/accept.d.ts +2 -0
- package/dist/commands/accept.d.ts.map +1 -0
- package/dist/commands/accept.js +41 -0
- package/dist/commands/accept.js.map +1 -0
- package/dist/commands/auction.d.ts +7 -0
- package/dist/commands/auction.d.ts.map +1 -0
- package/dist/commands/auction.js +79 -0
- package/dist/commands/auction.js.map +1 -0
- package/dist/commands/challenge.d.ts +2 -0
- package/dist/commands/challenge.d.ts.map +1 -0
- package/dist/commands/challenge.js +44 -0
- package/dist/commands/challenge.js.map +1 -0
- package/dist/commands/claim-timeout.d.ts +2 -0
- package/dist/commands/claim-timeout.d.ts.map +1 -0
- package/dist/commands/claim-timeout.js +34 -0
- package/dist/commands/claim-timeout.js.map +1 -0
- package/dist/commands/find-opponents.d.ts +2 -0
- package/dist/commands/find-opponents.d.ts.map +1 -0
- package/dist/commands/find-opponents.js +50 -0
- package/dist/commands/find-opponents.js.map +1 -0
- package/dist/commands/get-game.d.ts +2 -0
- package/dist/commands/get-game.d.ts.map +1 -0
- package/dist/commands/get-game.js +96 -0
- package/dist/commands/get-game.js.map +1 -0
- package/dist/commands/get-match.d.ts +2 -0
- package/dist/commands/get-match.d.ts.map +1 -0
- package/dist/commands/get-match.js +37 -0
- package/dist/commands/get-match.js.map +1 -0
- package/dist/commands/history.d.ts +2 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +33 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/join-tournament.d.ts +2 -0
- package/dist/commands/join-tournament.d.ts.map +1 -0
- package/dist/commands/join-tournament.js +37 -0
- package/dist/commands/join-tournament.js.map +1 -0
- package/dist/commands/market-status.d.ts +2 -0
- package/dist/commands/market-status.d.ts.map +1 -0
- package/dist/commands/market-status.js +39 -0
- package/dist/commands/market-status.js.map +1 -0
- package/dist/commands/market.d.ts +9 -0
- package/dist/commands/market.d.ts.map +1 -0
- package/dist/commands/market.js +87 -0
- package/dist/commands/market.js.map +1 -0
- package/dist/commands/poker.d.ts +9 -0
- package/dist/commands/poker.d.ts.map +1 -0
- package/dist/commands/poker.js +120 -0
- package/dist/commands/poker.js.map +1 -0
- package/dist/commands/register.d.ts +5 -0
- package/dist/commands/register.d.ts.map +1 -0
- package/dist/commands/register.js +39 -0
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/rps.d.ts +7 -0
- package/dist/commands/rps.d.ts.map +1 -0
- package/dist/commands/rps.js +135 -0
- package/dist/commands/rps.js.map +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +58 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/tournaments.d.ts +3 -0
- package/dist/commands/tournaments.d.ts.map +1 -0
- package/dist/commands/tournaments.js +77 -0
- package/dist/commands/tournaments.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +50 -0
- package/dist/config.js.map +1 -0
- package/dist/contracts.d.ts +764 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +518 -0
- package/dist/contracts.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +245 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/commit-reveal.d.ts +22 -0
- package/dist/utils/commit-reveal.d.ts.map +1 -0
- package/dist/utils/commit-reveal.js +56 -0
- package/dist/utils/commit-reveal.js.map +1 -0
- package/dist/utils/output.d.ts +9 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +30 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/tx.d.ts +14 -0
- package/dist/utils/tx.d.ts.map +1 -0
- package/dist/utils/tx.js +35 -0
- package/dist/utils/tx.js.map +1 -0
- package/package.json +34 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @molteee/arena-tools — CLI for the Molteee Gaming Arena on Monad testnet.
|
|
3
|
+
// All commands output JSON to stdout. Exit code 0 = success, 1 = error.
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { wrapCommand } from "./utils/output.js";
|
|
6
|
+
// ─── Read commands ──────────────────────────────────────────────────────────
|
|
7
|
+
import { statusCommand } from "./commands/status.js";
|
|
8
|
+
import { findOpponentsCommand } from "./commands/find-opponents.js";
|
|
9
|
+
import { historyCommand } from "./commands/history.js";
|
|
10
|
+
import { getMatchCommand } from "./commands/get-match.js";
|
|
11
|
+
import { getGameCommand } from "./commands/get-game.js";
|
|
12
|
+
import { marketStatusCommand } from "./commands/market-status.js";
|
|
13
|
+
import { tournamentsCommand, tournamentStatusCommand, } from "./commands/tournaments.js";
|
|
14
|
+
// ─── Write commands ─────────────────────────────────────────────────────────
|
|
15
|
+
import { registerCommand } from "./commands/register.js";
|
|
16
|
+
import { challengeCommand } from "./commands/challenge.js";
|
|
17
|
+
import { acceptCommand } from "./commands/accept.js";
|
|
18
|
+
import { rpsCreateCommand, rpsCommitCommand, rpsRevealCommand, } from "./commands/rps.js";
|
|
19
|
+
import { pokerCreateCommand, pokerCommitCommand, pokerActionCommand, pokerRevealCommand, } from "./commands/poker.js";
|
|
20
|
+
import { auctionCreateCommand, auctionCommitCommand, auctionRevealCommand, } from "./commands/auction.js";
|
|
21
|
+
import { claimTimeoutCommand } from "./commands/claim-timeout.js";
|
|
22
|
+
import { createMarketCommand, betCommand, resolveMarketCommand, redeemCommand, } from "./commands/market.js";
|
|
23
|
+
import { joinTournamentCommand } from "./commands/join-tournament.js";
|
|
24
|
+
const program = new Command();
|
|
25
|
+
program
|
|
26
|
+
.name("arena-tools")
|
|
27
|
+
.description("CLI for the Molteee Gaming Arena on Monad testnet. All output is JSON.")
|
|
28
|
+
.version("0.1.0");
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
30
|
+
// READ-ONLY COMMANDS (no PRIVATE_KEY needed)
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
32
|
+
program
|
|
33
|
+
.command("status")
|
|
34
|
+
.description("Get wallet balance, registration status, and ELO ratings")
|
|
35
|
+
.requiredOption("--address <address>", "Wallet address to check")
|
|
36
|
+
.action(wrapCommand(async (opts) => {
|
|
37
|
+
await statusCommand(opts.address);
|
|
38
|
+
}));
|
|
39
|
+
program
|
|
40
|
+
.command("find-opponents")
|
|
41
|
+
.description("List open agents for a game type")
|
|
42
|
+
.argument("<game_type>", "Game type: rps, poker, or auction")
|
|
43
|
+
.action(wrapCommand(async (gameType) => {
|
|
44
|
+
await findOpponentsCommand(gameType);
|
|
45
|
+
}));
|
|
46
|
+
program
|
|
47
|
+
.command("history")
|
|
48
|
+
.description("Get match history for an address")
|
|
49
|
+
.requiredOption("--address <address>", "Wallet address")
|
|
50
|
+
.action(wrapCommand(async (opts) => {
|
|
51
|
+
await historyCommand(opts.address);
|
|
52
|
+
}));
|
|
53
|
+
program
|
|
54
|
+
.command("get-match")
|
|
55
|
+
.description("Get details of a specific match")
|
|
56
|
+
.argument("<match_id>", "Match ID")
|
|
57
|
+
.action(wrapCommand(async (matchId) => {
|
|
58
|
+
await getMatchCommand(matchId);
|
|
59
|
+
}));
|
|
60
|
+
program
|
|
61
|
+
.command("get-game")
|
|
62
|
+
.description("Get game state for RPS, Poker, or Auction")
|
|
63
|
+
.argument("<game_type>", "Game type: rps, poker, or auction")
|
|
64
|
+
.argument("<game_id>", "Game ID")
|
|
65
|
+
.action(wrapCommand(async (gameType, gameId) => {
|
|
66
|
+
await getGameCommand(gameType, gameId);
|
|
67
|
+
}));
|
|
68
|
+
program
|
|
69
|
+
.command("market-status")
|
|
70
|
+
.description("Get prediction market prices and state")
|
|
71
|
+
.argument("<market_id>", "Market ID")
|
|
72
|
+
.action(wrapCommand(async (marketId) => {
|
|
73
|
+
await marketStatusCommand(marketId);
|
|
74
|
+
}));
|
|
75
|
+
program
|
|
76
|
+
.command("tournaments")
|
|
77
|
+
.description("List all tournaments")
|
|
78
|
+
.action(wrapCommand(async () => {
|
|
79
|
+
await tournamentsCommand();
|
|
80
|
+
}));
|
|
81
|
+
program
|
|
82
|
+
.command("tournament-status")
|
|
83
|
+
.description("Get tournament details and participants")
|
|
84
|
+
.argument("<tournament_id>", "Tournament ID")
|
|
85
|
+
.action(wrapCommand(async (tournamentId) => {
|
|
86
|
+
await tournamentStatusCommand(tournamentId);
|
|
87
|
+
}));
|
|
88
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
89
|
+
// WRITE COMMANDS (require PRIVATE_KEY env var)
|
|
90
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
91
|
+
program
|
|
92
|
+
.command("register")
|
|
93
|
+
.description("Register on the AgentRegistry for game types")
|
|
94
|
+
.argument("<game_types>", "Comma-separated: rps,poker,auction")
|
|
95
|
+
.option("--min-wager <amount>", "Min wager in MON", "0.001")
|
|
96
|
+
.option("--max-wager <amount>", "Max wager in MON", "1.0")
|
|
97
|
+
.action(wrapCommand(async (gameTypes, opts) => {
|
|
98
|
+
await registerCommand(gameTypes, opts);
|
|
99
|
+
}));
|
|
100
|
+
program
|
|
101
|
+
.command("challenge")
|
|
102
|
+
.description("Create an escrow match against an opponent")
|
|
103
|
+
.argument("<address>", "Opponent address")
|
|
104
|
+
.argument("<wager>", "Wager amount in MON")
|
|
105
|
+
.argument("<game_type>", "Game type: rps, poker, or auction")
|
|
106
|
+
.action(wrapCommand(async (address, wager, gameType) => {
|
|
107
|
+
await challengeCommand(address, wager, gameType);
|
|
108
|
+
}));
|
|
109
|
+
program
|
|
110
|
+
.command("accept")
|
|
111
|
+
.description("Accept an escrow match (auto-matches wager)")
|
|
112
|
+
.argument("<match_id>", "Match ID to accept")
|
|
113
|
+
.action(wrapCommand(async (matchId) => {
|
|
114
|
+
await acceptCommand(matchId);
|
|
115
|
+
}));
|
|
116
|
+
// ─── RPS Commands ────────────────────────────────────────────────────────────
|
|
117
|
+
program
|
|
118
|
+
.command("rps-create")
|
|
119
|
+
.description("Create a new RPS game for a match")
|
|
120
|
+
.argument("<match_id>", "Escrow match ID")
|
|
121
|
+
.argument("[rounds]", "Number of rounds (must be odd)", "1")
|
|
122
|
+
.action(wrapCommand(async (matchId, rounds) => {
|
|
123
|
+
await rpsCreateCommand(matchId, rounds);
|
|
124
|
+
}));
|
|
125
|
+
program
|
|
126
|
+
.command("rps-commit")
|
|
127
|
+
.description("Commit a move (salt handled automatically)")
|
|
128
|
+
.argument("<game_id>", "RPS game ID")
|
|
129
|
+
.argument("<move>", "Move: rock, paper, or scissors")
|
|
130
|
+
.action(wrapCommand(async (gameId, move) => {
|
|
131
|
+
await rpsCommitCommand(gameId, move);
|
|
132
|
+
}));
|
|
133
|
+
program
|
|
134
|
+
.command("rps-reveal")
|
|
135
|
+
.description("Reveal your committed move")
|
|
136
|
+
.argument("<game_id>", "RPS game ID")
|
|
137
|
+
.action(wrapCommand(async (gameId) => {
|
|
138
|
+
await rpsRevealCommand(gameId);
|
|
139
|
+
}));
|
|
140
|
+
// ─── Poker Commands ──────────────────────────────────────────────────────────
|
|
141
|
+
program
|
|
142
|
+
.command("poker-create")
|
|
143
|
+
.description("Create a new Poker game for a match")
|
|
144
|
+
.argument("<match_id>", "Escrow match ID")
|
|
145
|
+
.action(wrapCommand(async (matchId) => {
|
|
146
|
+
await pokerCreateCommand(matchId);
|
|
147
|
+
}));
|
|
148
|
+
program
|
|
149
|
+
.command("poker-commit")
|
|
150
|
+
.description("Commit a hand value (1-100)")
|
|
151
|
+
.argument("<game_id>", "Poker game ID")
|
|
152
|
+
.argument("<hand_value>", "Hand value: 1-100")
|
|
153
|
+
.action(wrapCommand(async (gameId, handValue) => {
|
|
154
|
+
await pokerCommitCommand(gameId, handValue);
|
|
155
|
+
}));
|
|
156
|
+
program
|
|
157
|
+
.command("poker-action")
|
|
158
|
+
.description("Take a betting action")
|
|
159
|
+
.argument("<game_id>", "Poker game ID")
|
|
160
|
+
.argument("<action>", "Action: check, bet, raise, call, or fold")
|
|
161
|
+
.argument("[amount]", "Amount in MON (for bet/raise)")
|
|
162
|
+
.action(wrapCommand(async (gameId, action, amount) => {
|
|
163
|
+
await pokerActionCommand(gameId, action, amount);
|
|
164
|
+
}));
|
|
165
|
+
program
|
|
166
|
+
.command("poker-reveal")
|
|
167
|
+
.description("Reveal your committed hand")
|
|
168
|
+
.argument("<game_id>", "Poker game ID")
|
|
169
|
+
.action(wrapCommand(async (gameId) => {
|
|
170
|
+
await pokerRevealCommand(gameId);
|
|
171
|
+
}));
|
|
172
|
+
// ─── Auction Commands ────────────────────────────────────────────────────────
|
|
173
|
+
program
|
|
174
|
+
.command("auction-create")
|
|
175
|
+
.description("Create a new Auction game for a match")
|
|
176
|
+
.argument("<match_id>", "Escrow match ID")
|
|
177
|
+
.action(wrapCommand(async (matchId) => {
|
|
178
|
+
await auctionCreateCommand(matchId);
|
|
179
|
+
}));
|
|
180
|
+
program
|
|
181
|
+
.command("auction-commit")
|
|
182
|
+
.description("Commit a bid amount")
|
|
183
|
+
.argument("<game_id>", "Auction game ID")
|
|
184
|
+
.argument("<bid>", "Bid amount in MON")
|
|
185
|
+
.action(wrapCommand(async (gameId, bid) => {
|
|
186
|
+
await auctionCommitCommand(gameId, bid);
|
|
187
|
+
}));
|
|
188
|
+
program
|
|
189
|
+
.command("auction-reveal")
|
|
190
|
+
.description("Reveal your committed bid")
|
|
191
|
+
.argument("<game_id>", "Auction game ID")
|
|
192
|
+
.action(wrapCommand(async (gameId) => {
|
|
193
|
+
await auctionRevealCommand(gameId);
|
|
194
|
+
}));
|
|
195
|
+
// ─── Shared Game Commands ────────────────────────────────────────────────────
|
|
196
|
+
program
|
|
197
|
+
.command("claim-timeout")
|
|
198
|
+
.description("Claim a timeout win when opponent doesn't act within 5 min")
|
|
199
|
+
.argument("<game_type>", "Game type: rps, poker, or auction")
|
|
200
|
+
.argument("<game_id>", "Game ID")
|
|
201
|
+
.action(wrapCommand(async (gameType, gameId) => {
|
|
202
|
+
await claimTimeoutCommand(gameType, gameId);
|
|
203
|
+
}));
|
|
204
|
+
// ─── Market Commands ─────────────────────────────────────────────────────────
|
|
205
|
+
program
|
|
206
|
+
.command("create-market")
|
|
207
|
+
.description("Create a prediction market for a match")
|
|
208
|
+
.argument("<match_id>", "Match ID")
|
|
209
|
+
.argument("<seed>", "Seed liquidity in MON")
|
|
210
|
+
.action(wrapCommand(async (matchId, seed) => {
|
|
211
|
+
await createMarketCommand(matchId, seed);
|
|
212
|
+
}));
|
|
213
|
+
program
|
|
214
|
+
.command("bet")
|
|
215
|
+
.description("Buy YES or NO tokens on a prediction market")
|
|
216
|
+
.argument("<market_id>", "Market ID")
|
|
217
|
+
.argument("<side>", "Side: yes or no")
|
|
218
|
+
.argument("<amount>", "Amount in MON")
|
|
219
|
+
.action(wrapCommand(async (marketId, side, amount) => {
|
|
220
|
+
await betCommand(marketId, side, amount);
|
|
221
|
+
}));
|
|
222
|
+
program
|
|
223
|
+
.command("resolve-market")
|
|
224
|
+
.description("Resolve a prediction market after match settles")
|
|
225
|
+
.argument("<market_id>", "Market ID")
|
|
226
|
+
.action(wrapCommand(async (marketId) => {
|
|
227
|
+
await resolveMarketCommand(marketId);
|
|
228
|
+
}));
|
|
229
|
+
program
|
|
230
|
+
.command("redeem")
|
|
231
|
+
.description("Redeem winning prediction market tokens")
|
|
232
|
+
.argument("<market_id>", "Market ID")
|
|
233
|
+
.action(wrapCommand(async (marketId) => {
|
|
234
|
+
await redeemCommand(marketId);
|
|
235
|
+
}));
|
|
236
|
+
// ─── Tournament Commands ─────────────────────────────────────────────────────
|
|
237
|
+
program
|
|
238
|
+
.command("join-tournament")
|
|
239
|
+
.description("Register for a tournament (auto-pays entry fee)")
|
|
240
|
+
.argument("<tournament_id>", "Tournament ID")
|
|
241
|
+
.action(wrapCommand(async (tournamentId) => {
|
|
242
|
+
await joinTournamentCommand(tournamentId);
|
|
243
|
+
}));
|
|
244
|
+
program.parse();
|
|
245
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,4EAA4E;AAC5E,wEAAwE;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,+EAA+E;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EACL,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAEnC,+EAA+E;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CA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/** Save a salt for later reveal */
|
|
5
|
+
export declare function saveSalt(key: string, salt: Hex, value: string, gameType: string): void;
|
|
6
|
+
/** Load a saved salt and remove it from storage */
|
|
7
|
+
export declare function loadSalt(key: string): {
|
|
8
|
+
salt: Hex;
|
|
9
|
+
value: string;
|
|
10
|
+
gameType: string;
|
|
11
|
+
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* Generate commit hash for RPS moves or Poker hands.
|
|
14
|
+
* Matches Solidity: keccak256(abi.encodePacked(uint8(value), bytes32(salt)))
|
|
15
|
+
*/
|
|
16
|
+
export declare function commitHash(value: number, salt: Hex): Hex;
|
|
17
|
+
/**
|
|
18
|
+
* Generate commit hash for Auction bids.
|
|
19
|
+
* Matches Solidity: keccak256(abi.encodePacked(uint256(bid), bytes32(salt)))
|
|
20
|
+
*/
|
|
21
|
+
export declare function commitBidHash(bid: bigint, salt: Hex): Hex;
|
|
22
|
+
//# sourceMappingURL=commit-reveal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-reveal.d.ts","sourceRoot":"","sources":["../../src/utils/commit-reveal.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAczD,uDAAuD;AACvD,wBAAgB,YAAY,IAAI,GAAG,CAElC;AAED,mCAAmC;AACnC,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,IAAI,CAUN;AAED,mDAAmD;AACnD,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,GACV;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CASvD;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,CAExD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,CAEzD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Commit-reveal hash generation and salt management.
|
|
2
|
+
// Handles salt storage so agents never deal with raw cryptography.
|
|
3
|
+
import { keccak256, encodePacked } from "viem";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import os from "os";
|
|
7
|
+
import crypto from "crypto";
|
|
8
|
+
// Salt storage directory
|
|
9
|
+
const SALT_DIR = path.join(os.homedir(), ".arena-tools");
|
|
10
|
+
const SALT_FILE = path.join(SALT_DIR, "salts.json");
|
|
11
|
+
// ─── Salt Management ─────────────────────────────────────────────────────────
|
|
12
|
+
/** Generate a cryptographically secure 32-byte salt */
|
|
13
|
+
export function generateSalt() {
|
|
14
|
+
return `0x${crypto.randomBytes(32).toString("hex")}`;
|
|
15
|
+
}
|
|
16
|
+
/** Save a salt for later reveal */
|
|
17
|
+
export function saveSalt(key, salt, value, gameType) {
|
|
18
|
+
if (!fs.existsSync(SALT_DIR)) {
|
|
19
|
+
fs.mkdirSync(SALT_DIR, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
let store = {};
|
|
22
|
+
if (fs.existsSync(SALT_FILE)) {
|
|
23
|
+
store = JSON.parse(fs.readFileSync(SALT_FILE, "utf-8"));
|
|
24
|
+
}
|
|
25
|
+
store[key] = { salt, value, gameType };
|
|
26
|
+
fs.writeFileSync(SALT_FILE, JSON.stringify(store, null, 2));
|
|
27
|
+
}
|
|
28
|
+
/** Load a saved salt and remove it from storage */
|
|
29
|
+
export function loadSalt(key) {
|
|
30
|
+
if (!fs.existsSync(SALT_FILE))
|
|
31
|
+
return null;
|
|
32
|
+
const store = JSON.parse(fs.readFileSync(SALT_FILE, "utf-8"));
|
|
33
|
+
const entry = store[key];
|
|
34
|
+
if (!entry)
|
|
35
|
+
return null;
|
|
36
|
+
// Remove after loading (single-use)
|
|
37
|
+
delete store[key];
|
|
38
|
+
fs.writeFileSync(SALT_FILE, JSON.stringify(store, null, 2));
|
|
39
|
+
return entry;
|
|
40
|
+
}
|
|
41
|
+
// ─── Hash Generation ─────────────────────────────────────────────────────────
|
|
42
|
+
/**
|
|
43
|
+
* Generate commit hash for RPS moves or Poker hands.
|
|
44
|
+
* Matches Solidity: keccak256(abi.encodePacked(uint8(value), bytes32(salt)))
|
|
45
|
+
*/
|
|
46
|
+
export function commitHash(value, salt) {
|
|
47
|
+
return keccak256(encodePacked(["uint8", "bytes32"], [value, salt]));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generate commit hash for Auction bids.
|
|
51
|
+
* Matches Solidity: keccak256(abi.encodePacked(uint256(bid), bytes32(salt)))
|
|
52
|
+
*/
|
|
53
|
+
export function commitBidHash(bid, salt) {
|
|
54
|
+
return keccak256(encodePacked(["uint256", "bytes32"], [bid, salt]));
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=commit-reveal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-reveal.js","sourceRoot":"","sources":["../../src/utils/commit-reveal.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,mEAAmE;AACnE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAY,MAAM,MAAM,CAAC;AACzD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,yBAAyB;AACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC,CAAC;AACzD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AAIpD,gFAAgF;AAEhF,uDAAuD;AACvD,M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,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAAS;IACjD,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,IAAS;IAClD,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Print a success response and exit */
|
|
2
|
+
export declare function ok(data: unknown): never;
|
|
3
|
+
/** Print an error response and exit */
|
|
4
|
+
export declare function fail(error: string, code?: string): never;
|
|
5
|
+
/** Print a streaming event (JSONL — one JSON object per line) */
|
|
6
|
+
export declare function event(data: Record<string, unknown>): void;
|
|
7
|
+
/** Wrap an async command handler with error catching */
|
|
8
|
+
export declare function wrapCommand<T extends (...args: any[]) => Promise<void>>(fn: T): T;
|
|
9
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":"AAEA,wCAAwC;AACxC,wBAAgB,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAGvC;AAED,uCAAuC;AACvC,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAGxD;AAED,iEAAiE;AACjE,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAEzD;AAED,wDAAwD;AAExD,wBAAgB,WAAW,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,EACrE,EAAE,EAAE,CAAC,GACJ,CAAC,CAWH"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// JSON output helpers — all commands use these for consistent stdout format.
|
|
2
|
+
/** Print a success response and exit */
|
|
3
|
+
export function ok(data) {
|
|
4
|
+
console.log(JSON.stringify({ ok: true, data }, null, 2));
|
|
5
|
+
process.exit(0);
|
|
6
|
+
}
|
|
7
|
+
/** Print an error response and exit */
|
|
8
|
+
export function fail(error, code) {
|
|
9
|
+
console.error(JSON.stringify({ ok: false, error, code }, null, 2));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
/** Print a streaming event (JSONL — one JSON object per line) */
|
|
13
|
+
export function event(data) {
|
|
14
|
+
console.log(JSON.stringify(data));
|
|
15
|
+
}
|
|
16
|
+
/** Wrap an async command handler with error catching */
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
export function wrapCommand(fn) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
return (async (...args) => {
|
|
21
|
+
try {
|
|
22
|
+
await fn(...args);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
26
|
+
fail(message, "UNEXPECTED_ERROR");
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,wCAAwC;AACxC,MAAM,UAAU,EAAE,CAAC,IAAa;IAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,IAAI,CAAC,KAAa,EAAE,IAAa;IAC/C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,KAAK,CAAC,IAA6B;IACjD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,wDAAwD;AACxD,8DAA8D;AAC9D,MAAM,UAAU,WAAW,CACzB,EAAK;IAEL,8DAA8D;IAC9D,OAAO,CAAC,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC/B,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACpB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,OAAO,GACX,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACnD,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAM,CAAC;AACV,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Send a write transaction with gas estimation.
|
|
4
|
+
* Returns the transaction hash and receipt.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sendTx(params: {
|
|
7
|
+
to: `0x${string}`;
|
|
8
|
+
data: Hex;
|
|
9
|
+
value?: bigint;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
hash: Hex;
|
|
12
|
+
gasUsed: bigint;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=tx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/utils/tx.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAGhC;;;GAGG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE;IACnC,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAiC1C"}
|
package/dist/utils/tx.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getPublicClient, getWalletClient } from "../client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Send a write transaction with gas estimation.
|
|
4
|
+
* Returns the transaction hash and receipt.
|
|
5
|
+
*/
|
|
6
|
+
export async function sendTx(params) {
|
|
7
|
+
const publicClient = getPublicClient();
|
|
8
|
+
const walletClient = getWalletClient();
|
|
9
|
+
const account = walletClient.account;
|
|
10
|
+
// Estimate gas with 1.5x buffer (Monad needs more than Ethereum)
|
|
11
|
+
const gasEstimate = await publicClient.estimateGas({
|
|
12
|
+
account: account.address,
|
|
13
|
+
to: params.to,
|
|
14
|
+
data: params.data,
|
|
15
|
+
value: params.value ?? 0n,
|
|
16
|
+
});
|
|
17
|
+
const gas = (gasEstimate * 3n) / 2n;
|
|
18
|
+
// Send transaction
|
|
19
|
+
const hash = await walletClient.sendTransaction({
|
|
20
|
+
to: params.to,
|
|
21
|
+
data: params.data,
|
|
22
|
+
value: params.value ?? 0n,
|
|
23
|
+
gas,
|
|
24
|
+
});
|
|
25
|
+
// Wait for confirmation
|
|
26
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
27
|
+
hash,
|
|
28
|
+
timeout: 60_000,
|
|
29
|
+
});
|
|
30
|
+
if (receipt.status === "reverted") {
|
|
31
|
+
throw new Error(`Transaction reverted: ${hash}`);
|
|
32
|
+
}
|
|
33
|
+
return { hash, gasUsed: receipt.gasUsed };
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=tx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx.js","sourceRoot":"","sources":["../../src/utils/tx.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEhE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAI5B;IACC,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;IAErC,iEAAiE;IACjE,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC;QACjD,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;KAC1B,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,CAAC,WAAW,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IAEpC,mBAAmB;IACnB,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC;QAC9C,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;QACzB,GAAG;KACJ,CAAC,CAAC;IAEH,wBAAwB;IACxB,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,yBAAyB,CAAC;QAC3D,IAAI;QACJ,OAAO,EAAE,MAAM;KAChB,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;AAC5C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molteee/arena-tools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for interacting with the Molteee Gaming Arena on Monad testnet",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"arena-tools": "./bin/arena.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsx src/index.ts",
|
|
13
|
+
"start": "node dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["monad", "gaming", "arena", "rps", "poker", "auction", "agent", "cli"],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"commander": "^13.1.0",
|
|
19
|
+
"dotenv": "^16.4.7",
|
|
20
|
+
"viem": "^2.45.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.0.0",
|
|
24
|
+
"tsx": "^4.19.0",
|
|
25
|
+
"typescript": "^5.7.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"bin"
|
|
33
|
+
]
|
|
34
|
+
}
|