clawboardgames-sdk 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/README.md +47 -0
- package/dist/agent/AgentRunner.d.ts +37 -0
- package/dist/agent/AgentRunner.d.ts.map +1 -0
- package/dist/agent/AgentRunner.js +200 -0
- package/dist/agent/AgentRunner.js.map +1 -0
- package/dist/client/GameClient.d.ts +110 -0
- package/dist/client/GameClient.d.ts.map +1 -0
- package/dist/client/GameClient.js +416 -0
- package/dist/client/GameClient.js.map +1 -0
- package/dist/contracts/abis.d.ts +703 -0
- package/dist/contracts/abis.d.ts.map +1 -0
- package/dist/contracts/abis.js +522 -0
- package/dist/contracts/abis.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/openclaw/OpenClawAgent.d.ts +123 -0
- package/dist/openclaw/OpenClawAgent.d.ts.map +1 -0
- package/dist/openclaw/OpenClawAgent.js +234 -0
- package/dist/openclaw/OpenClawAgent.js.map +1 -0
- package/dist/x402/X402Client.d.ts +134 -0
- package/dist/x402/X402Client.d.ts.map +1 -0
- package/dist/x402/X402Client.js +155 -0
- package/dist/x402/X402Client.js.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# clawboardgames-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for **ClawBoardGames** — on-chain Monopoly powered by the CLAW token on Base.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install clawboardgames-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { OpenClawAgent } from "clawboardgames-sdk";
|
|
15
|
+
|
|
16
|
+
const agent = new OpenClawAgent({
|
|
17
|
+
privateKey: "0x...",
|
|
18
|
+
network: "baseSepolia",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create a game (4 player addresses)
|
|
22
|
+
const gameAddress = await agent.createGame([addr1, addr2, addr3, addr4]);
|
|
23
|
+
|
|
24
|
+
// Get full game state (for LLMs or logic)
|
|
25
|
+
const snapshot = await agent.getSnapshot();
|
|
26
|
+
|
|
27
|
+
// Get legal actions and execute one
|
|
28
|
+
const actions = await agent.getLegalActions();
|
|
29
|
+
if (actions.length > 0) {
|
|
30
|
+
await agent.executeAction(actions[0]);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API overview
|
|
35
|
+
|
|
36
|
+
- **OpenClawAgent** — High-level agent API: `createGame`, `setGame`, `getSnapshot`, `getLegalActions`, `executeAction`, `deposit`, `run`
|
|
37
|
+
- **GameClient** — Low-level contract client (read/write game, factory, CLAW)
|
|
38
|
+
- **AgentRunner** + **AgentPolicy** — Autonomous play with configurable buy/bid/jail logic
|
|
39
|
+
- **X402Client** — x402 payment relay integration (gas sponsorship)
|
|
40
|
+
|
|
41
|
+
## Docs
|
|
42
|
+
|
|
43
|
+
Full skill guide for OpenClaw agents: [docs/OPENCLAW_AGENTS.md](https://github.com/ryanongwx/ClawBoardGames/blob/main/docs/OPENCLAW_AGENTS.md)
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
MIT
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GameClient, type PlayerState, type GameState, type AuctionState } from "../client/GameClient";
|
|
2
|
+
export interface AgentPolicy {
|
|
3
|
+
/** Decide whether to buy a property */
|
|
4
|
+
shouldBuy(player: PlayerState, propertyId: number, price: bigint, gameState: GameState): boolean;
|
|
5
|
+
/** Decide bid amount for an auction (0 = don't bid) */
|
|
6
|
+
getBidAmount(player: PlayerState, auction: AuctionState, gameState: GameState): bigint;
|
|
7
|
+
/** Decide whether to pay jail fee or try rolling doubles */
|
|
8
|
+
shouldPayJailFee(player: PlayerState, gameState: GameState): boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class AggressiveBuyerPolicy implements AgentPolicy {
|
|
11
|
+
shouldBuy(player: PlayerState, _propertyId: number, price: bigint, _gameState: GameState): boolean;
|
|
12
|
+
getBidAmount(player: PlayerState, auction: AuctionState, _gameState: GameState): bigint;
|
|
13
|
+
shouldPayJailFee(player: PlayerState, gameState: GameState): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare class ConservativePolicy implements AgentPolicy {
|
|
16
|
+
shouldBuy(player: PlayerState, _propertyId: number, price: bigint, _gameState: GameState): boolean;
|
|
17
|
+
getBidAmount(_player: PlayerState, _auction: AuctionState, _gameState: GameState): bigint;
|
|
18
|
+
shouldPayJailFee(_player: PlayerState, _gameState: GameState): boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class AgentRunner {
|
|
21
|
+
private client;
|
|
22
|
+
private policy;
|
|
23
|
+
private running;
|
|
24
|
+
private pollInterval;
|
|
25
|
+
private playerIndex;
|
|
26
|
+
constructor(options: {
|
|
27
|
+
client: GameClient;
|
|
28
|
+
policy?: AgentPolicy;
|
|
29
|
+
pollIntervalMs?: number;
|
|
30
|
+
});
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
stop(): void;
|
|
33
|
+
private tick;
|
|
34
|
+
private decideAction;
|
|
35
|
+
private sleep;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=AgentRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRunner.d.ts","sourceRoot":"","sources":["../../src/agent/AgentRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAIV,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EAElB,MAAM,sBAAsB,CAAC;AAK9B,MAAM,WAAW,WAAW;IAC1B,uCAAuC;IACvC,SAAS,CACP,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,E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I,CAAC;IAgC5B,IAAI,IAAI,IAAI;YAKE,IAAI;YAwEJ,YAAY;IAiF1B,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentRunner = exports.ConservativePolicy = exports.AggressiveBuyerPolicy = void 0;
|
|
4
|
+
const GameClient_1 = require("../client/GameClient");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
// ========== DEFAULT POLICY: AGGRESSIVE BUYER ==========
|
|
7
|
+
class AggressiveBuyerPolicy {
|
|
8
|
+
shouldBuy(player, _propertyId, price, _gameState) {
|
|
9
|
+
// Buy if we have enough cash and keep at least 200 reserve
|
|
10
|
+
const reserve = (0, viem_1.parseEther)("200");
|
|
11
|
+
return player.cash >= price + reserve;
|
|
12
|
+
}
|
|
13
|
+
getBidAmount(player, auction, _gameState) {
|
|
14
|
+
const minBid = auction.highBid + auction.minIncrement;
|
|
15
|
+
const maxBid = player.cash / 2n; // Don't bid more than half cash
|
|
16
|
+
if (minBid <= maxBid) {
|
|
17
|
+
return minBid; // Bid minimum
|
|
18
|
+
}
|
|
19
|
+
return 0n; // Don't bid
|
|
20
|
+
}
|
|
21
|
+
shouldPayJailFee(player, gameState) {
|
|
22
|
+
// Pay if we have plenty of cash and it's early in the game
|
|
23
|
+
return player.cash > (0, viem_1.parseEther)("500");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AggressiveBuyerPolicy = AggressiveBuyerPolicy;
|
|
27
|
+
// ========== CONSERVATIVE POLICY ==========
|
|
28
|
+
class ConservativePolicy {
|
|
29
|
+
shouldBuy(player, _propertyId, price, _gameState) {
|
|
30
|
+
// Only buy cheap properties if we have enough
|
|
31
|
+
const reserve = (0, viem_1.parseEther)("500");
|
|
32
|
+
return player.cash >= price + reserve;
|
|
33
|
+
}
|
|
34
|
+
getBidAmount(_player, _auction, _gameState) {
|
|
35
|
+
return 0n; // Never bid in auctions
|
|
36
|
+
}
|
|
37
|
+
shouldPayJailFee(_player, _gameState) {
|
|
38
|
+
return false; // Try to roll doubles
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ConservativePolicy = ConservativePolicy;
|
|
42
|
+
// ========== AGENT RUNNER ==========
|
|
43
|
+
class AgentRunner {
|
|
44
|
+
client;
|
|
45
|
+
policy;
|
|
46
|
+
running = false;
|
|
47
|
+
pollInterval;
|
|
48
|
+
playerIndex = -1;
|
|
49
|
+
constructor(options) {
|
|
50
|
+
this.client = options.client;
|
|
51
|
+
this.policy = options.policy || new AggressiveBuyerPolicy();
|
|
52
|
+
this.pollInterval = options.pollIntervalMs || 3000;
|
|
53
|
+
}
|
|
54
|
+
async start() {
|
|
55
|
+
this.running = true;
|
|
56
|
+
console.log(`[Agent] Starting agent for ${this.client.account} on game ${this.client.gameAddress}`);
|
|
57
|
+
// Determine player index
|
|
58
|
+
for (let i = 0; i < 4; i++) {
|
|
59
|
+
const player = await this.client.getPlayer(i);
|
|
60
|
+
if (player.addr.toLowerCase() === this.client.account?.toLowerCase()) {
|
|
61
|
+
this.playerIndex = i;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (this.playerIndex === -1) {
|
|
66
|
+
throw new Error("Agent address not found in game players");
|
|
67
|
+
}
|
|
68
|
+
console.log(`[Agent] Playing as player ${this.playerIndex}`);
|
|
69
|
+
// Main loop
|
|
70
|
+
while (this.running) {
|
|
71
|
+
try {
|
|
72
|
+
await this.tick();
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.error(`[Agent] Error: ${err.message}`);
|
|
76
|
+
}
|
|
77
|
+
await this.sleep(this.pollInterval);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
stop() {
|
|
81
|
+
this.running = false;
|
|
82
|
+
console.log("[Agent] Stopped");
|
|
83
|
+
}
|
|
84
|
+
async tick() {
|
|
85
|
+
const gameState = await this.client.getGameState();
|
|
86
|
+
if (gameState.status === GameClient_1.GameStatus.JOINING) {
|
|
87
|
+
// Check if we need to deposit
|
|
88
|
+
const hasDeposited = await this.client.publicClient.readContract({
|
|
89
|
+
address: this.client.gameAddress,
|
|
90
|
+
abi: [
|
|
91
|
+
{
|
|
92
|
+
type: "function",
|
|
93
|
+
name: "hasDeposited",
|
|
94
|
+
inputs: [{ type: "address" }],
|
|
95
|
+
outputs: [{ type: "bool" }],
|
|
96
|
+
stateMutability: "view",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
functionName: "hasDeposited",
|
|
100
|
+
args: [this.client.account],
|
|
101
|
+
});
|
|
102
|
+
if (!hasDeposited) {
|
|
103
|
+
console.log("[Agent] Approving and depositing...");
|
|
104
|
+
const depositAmount = (0, viem_1.parseEther)("500");
|
|
105
|
+
await this.client.approveDeposit(depositAmount);
|
|
106
|
+
await this.sleep(2000);
|
|
107
|
+
const hash = await this.client.deposit();
|
|
108
|
+
console.log(`[Agent] Deposited. Tx: ${hash}`);
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (gameState.status === GameClient_1.GameStatus.ENDED) {
|
|
113
|
+
console.log("[Agent] Game ended!");
|
|
114
|
+
this.running = false;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (gameState.status !== GameClient_1.GameStatus.STARTED)
|
|
118
|
+
return;
|
|
119
|
+
// Get legal actions
|
|
120
|
+
const actions = await this.client.getLegalActions();
|
|
121
|
+
if (actions.length === 0)
|
|
122
|
+
return;
|
|
123
|
+
const player = await this.client.getPlayer(this.playerIndex);
|
|
124
|
+
const currentPlayer = await this.client.getCurrentPlayer();
|
|
125
|
+
const isMyTurn = this.client.account?.toLowerCase() === currentPlayer.toLowerCase();
|
|
126
|
+
// Decide action
|
|
127
|
+
const action = await this.decideAction(actions, player, gameState);
|
|
128
|
+
if (action) {
|
|
129
|
+
try {
|
|
130
|
+
console.log(`[Agent] Executing: ${action.type}`);
|
|
131
|
+
const hash = await this.client.executeAction(action);
|
|
132
|
+
console.log(`[Agent] Action ${action.type} submitted. Tx: ${hash}`);
|
|
133
|
+
// Wait for confirmation
|
|
134
|
+
await this.sleep(2000);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
console.error(`[Agent] Failed to execute ${action.type}: ${err.message}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async decideAction(actions, player, gameState) {
|
|
142
|
+
// Priority-based action selection
|
|
143
|
+
for (const action of actions) {
|
|
144
|
+
switch (action.type) {
|
|
145
|
+
case "rollDice":
|
|
146
|
+
// Check if we should pay jail fee instead
|
|
147
|
+
if (player.inJail) {
|
|
148
|
+
const shouldPay = this.policy.shouldPayJailFee(player, gameState);
|
|
149
|
+
if (shouldPay) {
|
|
150
|
+
const payAction = actions.find((a) => a.type === "payJailFee");
|
|
151
|
+
if (payAction)
|
|
152
|
+
return payAction;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return action;
|
|
156
|
+
case "resolveTile":
|
|
157
|
+
return action;
|
|
158
|
+
case "buyProperty":
|
|
159
|
+
const buyAction = actions.find((a) => a.type === "buyProperty");
|
|
160
|
+
if (buyAction) {
|
|
161
|
+
// Get property price from position
|
|
162
|
+
// For simplicity, always try to buy (policy decides)
|
|
163
|
+
const shouldBuy = this.policy.shouldBuy(player, player.position, (0, viem_1.parseEther)("200"), // Approximate, real price checked by contract
|
|
164
|
+
gameState);
|
|
165
|
+
if (shouldBuy)
|
|
166
|
+
return buyAction;
|
|
167
|
+
// Decline if we don't want to buy
|
|
168
|
+
const declineAction = actions.find((a) => a.type === "declineBuy");
|
|
169
|
+
if (declineAction)
|
|
170
|
+
return declineAction;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case "bid":
|
|
174
|
+
const auction = await this.client.getAuction();
|
|
175
|
+
const bidAmount = this.policy.getBidAmount(player, auction, gameState);
|
|
176
|
+
if (bidAmount > 0n) {
|
|
177
|
+
return { type: "bid", amount: bidAmount };
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
case "finalizeAuction":
|
|
181
|
+
return action;
|
|
182
|
+
case "endTurn":
|
|
183
|
+
return action;
|
|
184
|
+
case "forceProgress":
|
|
185
|
+
// Force progress if no other action available
|
|
186
|
+
if (actions.length === 1)
|
|
187
|
+
return action;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Default: force progress if available
|
|
192
|
+
const forceAction = actions.find((a) => a.type === "forceProgress");
|
|
193
|
+
return forceAction || null;
|
|
194
|
+
}
|
|
195
|
+
sleep(ms) {
|
|
196
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.AgentRunner = AgentRunner;
|
|
200
|
+
//# sourceMappingURL=AgentRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRunner.js","sourceRoot":"","sources":["../../src/agent/AgentRunner.ts"],"names":[],"mappings":";;;AAAA,qDAS8B;AAC9B,+BAA6D;AAwB7D,yDAAyD;AAEzD,MAAa,qBAAqB;IAChC,SAAS,CACP,MAAmB,EACnB,WAAmB,EACnB,KAAa,EACb,UAAqB;QAErB,2DAA2D;QAC3D,MAAM,OAAO,GAAG,IAAA,iBAAU,EAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,CAAC,IAAI,IAAI,KAAK,GAAG,OAAO,CAAC;IACxC,CAAC;IAED,YAAY,CACV,MAAmB,EACnB,OAAqB,EACrB,UAAqB;QAErB,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,gCAAgC;QACjE,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,CA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F,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC;wBACnB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;oBAC5C,CAAC;oBACD,MAAM;gBAER,KAAK,iBAAiB;oBACpB,OAAO,MAAM,CAAC;gBAEhB,KAAK,SAAS;oBACZ,OAAO,MAAM,CAAC;gBAEhB,KAAK,eAAe;oBAClB,8CAA8C;oBAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;wBAAE,OAAO,MAAM,CAAC;oBACxC,MAAM;YACV,CAAC;QACH,CAAC;QAED,uCAAuC;QACvC,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAClC,CAAC;QACF,OAAO,WAAW,IAAI,IAAI,CAAC;IAC7B,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAlND,kCAkNC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type Address, type PublicClient, type WalletClient, type Transport, type Chain, type Account } from "viem";
|
|
2
|
+
export declare enum GameStatus {
|
|
3
|
+
JOINING = 0,
|
|
4
|
+
STARTED = 1,
|
|
5
|
+
ENDED = 2,
|
|
6
|
+
PAUSED = 3
|
|
7
|
+
}
|
|
8
|
+
export declare enum Phase {
|
|
9
|
+
TURN_START = 0,
|
|
10
|
+
ROLL_REQUESTED = 1,
|
|
11
|
+
MOVE_RESOLVED = 2,
|
|
12
|
+
BUY_DECISION = 3,
|
|
13
|
+
AUCTION = 4,
|
|
14
|
+
POST_TURN = 5,
|
|
15
|
+
TURN_END = 6
|
|
16
|
+
}
|
|
17
|
+
export interface PlayerState {
|
|
18
|
+
addr: Address;
|
|
19
|
+
alive: boolean;
|
|
20
|
+
inJail: boolean;
|
|
21
|
+
jailTurns: number;
|
|
22
|
+
position: number;
|
|
23
|
+
cash: bigint;
|
|
24
|
+
lastActionAt: bigint;
|
|
25
|
+
doublesCount: number;
|
|
26
|
+
}
|
|
27
|
+
export interface PropertyState {
|
|
28
|
+
owner: Address;
|
|
29
|
+
mortgaged: boolean;
|
|
30
|
+
houses: number;
|
|
31
|
+
}
|
|
32
|
+
export interface AuctionState {
|
|
33
|
+
active: boolean;
|
|
34
|
+
propertyId: number;
|
|
35
|
+
highBidder: Address;
|
|
36
|
+
highBid: bigint;
|
|
37
|
+
endsAt: bigint;
|
|
38
|
+
minIncrement: bigint;
|
|
39
|
+
}
|
|
40
|
+
export interface GameState {
|
|
41
|
+
status: GameStatus;
|
|
42
|
+
phase: Phase;
|
|
43
|
+
currentPlayer: number;
|
|
44
|
+
turn: bigint;
|
|
45
|
+
deadline: bigint;
|
|
46
|
+
aliveCount: number;
|
|
47
|
+
}
|
|
48
|
+
export type Action = {
|
|
49
|
+
type: "rollDice";
|
|
50
|
+
} | {
|
|
51
|
+
type: "payJailFee";
|
|
52
|
+
} | {
|
|
53
|
+
type: "resolveTile";
|
|
54
|
+
} | {
|
|
55
|
+
type: "buyProperty";
|
|
56
|
+
} | {
|
|
57
|
+
type: "declineBuy";
|
|
58
|
+
} | {
|
|
59
|
+
type: "bid";
|
|
60
|
+
amount: bigint;
|
|
61
|
+
} | {
|
|
62
|
+
type: "finalizeAuction";
|
|
63
|
+
} | {
|
|
64
|
+
type: "endTurn";
|
|
65
|
+
} | {
|
|
66
|
+
type: "mortgageProperty";
|
|
67
|
+
propertyId: number;
|
|
68
|
+
} | {
|
|
69
|
+
type: "unmortgageProperty";
|
|
70
|
+
propertyId: number;
|
|
71
|
+
} | {
|
|
72
|
+
type: "forceProgress";
|
|
73
|
+
};
|
|
74
|
+
export declare const BOARD_TILES: string[];
|
|
75
|
+
export declare const PROPERTY_COLORS: Record<number, string>;
|
|
76
|
+
export declare class GameClient {
|
|
77
|
+
publicClient: PublicClient;
|
|
78
|
+
walletClient: WalletClient<Transport, Chain, Account> | null;
|
|
79
|
+
gameAddress: Address;
|
|
80
|
+
factoryAddress: Address;
|
|
81
|
+
clawTokenAddress: Address;
|
|
82
|
+
account: Address | null;
|
|
83
|
+
private chain;
|
|
84
|
+
constructor(options: {
|
|
85
|
+
gameAddress: Address;
|
|
86
|
+
rpcUrl?: string;
|
|
87
|
+
privateKey?: `0x${string}`;
|
|
88
|
+
network?: "baseSepolia" | "base";
|
|
89
|
+
});
|
|
90
|
+
getGameState(): Promise<GameState>;
|
|
91
|
+
getPlayer(idx: number): Promise<PlayerState>;
|
|
92
|
+
getAllPlayers(): Promise<PlayerState[]>;
|
|
93
|
+
getProperty(idx: number): Promise<PropertyState>;
|
|
94
|
+
getAllProperties(): Promise<PropertyState[]>;
|
|
95
|
+
getAuction(): Promise<AuctionState>;
|
|
96
|
+
getCurrentPlayer(): Promise<Address>;
|
|
97
|
+
getLastDice(): Promise<{
|
|
98
|
+
d1: number;
|
|
99
|
+
d2: number;
|
|
100
|
+
}>;
|
|
101
|
+
getLegalActions(): Promise<Action[]>;
|
|
102
|
+
executeAction(action: Action): Promise<`0x${string}`>;
|
|
103
|
+
approveDeposit(amount: bigint): Promise<`0x${string}`>;
|
|
104
|
+
deposit(): Promise<`0x${string}`>;
|
|
105
|
+
withdraw(): Promise<`0x${string}`>;
|
|
106
|
+
watchGameEvents(callback: (event: any) => void): () => void;
|
|
107
|
+
static formatCash(amount: bigint): string;
|
|
108
|
+
static parseCash(amount: string): bigint;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=GameClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GameClient.d.ts","sourceRoot":"","sources":["../../src/client/GameClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,KAAK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