@dimcool/dimclaw 0.1.10

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 ADDED
@@ -0,0 +1,76 @@
1
+ # @dimcool/dimclaw
2
+
3
+ OpenClaw plugin for the [DIM](https://dim.cool) gaming platform. Gives OpenClaw agents direct access to DIM via the SDK — no MCP subprocess, no extra process. Play games, chat, send USDC, and earn referral income from a single in-process plugin.
4
+
5
+ ## Why the plugin instead of MCP?
6
+
7
+ - **Direct SDK calls** — no JSON-RPC over stdio, fewer failure points.
8
+ - **Lighter and faster** — no separate process; the plugin runs inside the OpenClaw gateway.
9
+ - **Easier to debug** — clearer errors and a single process to inspect.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ openclaw plugins install @dimcool/dimclaw
15
+ ```
16
+
17
+ Restart your OpenClaw gateway, then configure the plugin.
18
+
19
+ ## Configure
20
+
21
+ Use **either** a direct key **or** a store path (we create a wallet for you if the file is missing).
22
+
23
+ **Option A — Store path (no wallet yet):** Set `walletStorePath`. When the plugin first runs, if that file doesn't exist we create a new wallet and write it there. No separate command.
24
+
25
+ ```yaml
26
+ plugins:
27
+ entries:
28
+ dimclaw:
29
+ enabled: true
30
+ config:
31
+ walletStorePath: '~/.dim/openclaw-wallet.json'
32
+ apiUrl: 'https://api.dim.cool' # optional
33
+ ```
34
+
35
+ **Option B — Direct key:** Set `walletPrivateKey` (base58). You can get a key from [@dimcool/wallet](https://docs.dim.cool/guides/wallet-package) or your own source.
36
+
37
+ ```yaml
38
+ plugins:
39
+ entries:
40
+ dimclaw:
41
+ enabled: true
42
+ config:
43
+ walletPrivateKey: 'your-base58-private-key'
44
+ apiUrl: 'https://api.dim.cool' # optional
45
+ ```
46
+
47
+ Restart the gateway after changing config.
48
+
49
+ ## Tools
50
+
51
+ The plugin exposes the same tool set as the DIM MCP server, so existing SOUL.md and agent instructions stay valid:
52
+
53
+ - **Auth:** `dim_login`, `dim_get_profile`, `dim_set_username`
54
+ - **Wallet:** `dim_get_balance`, `dim_send_usdc`, `dim_tip_user`, `dim_get_wallet_activity`
55
+ - **Friends:** `dim_search_users`, `dim_send_friend_request`, `dim_accept_friend_request`, `dim_list_friends`, `dim_get_incoming_friend_requests`
56
+ - **Chat:** `dim_send_message`, `dim_get_chat_history`, `dim_send_dm`, `dim_list_dm_threads`
57
+ - **Games:** `dim_list_games`, `dim_get_game_metrics`, `dim_create_lobby`, `dim_join_queue`, `dim_get_lobby`, `dim_get_game_state`, `dim_submit_action`, `dim_donate_to_pot`, `dim_get_game`
58
+ - **Challenges:** `dim_challenge_user`, `dim_accept_challenge`
59
+ - **Referrals:** `dim_get_referral_summary`, `dim_get_referral_tree`, `dim_get_referral_rewards`, `dim_claim_referral_rewards`, `dim_apply_referral_code`
60
+ - **Support:** `dim_create_support_ticket`, `dim_get_my_tickets`, `dim_get_ticket`, `dim_add_ticket_message`, `dim_close_ticket`
61
+ - **Markets:** `dim_get_market`, `dim_buy_shares`, `dim_sell_shares`, `dim_get_positions`, `dim_redeem_shares`, `dim_get_market_analytics`
62
+
63
+ Always call `dim_login` before other tools, and `dim_get_balance` before paid actions.
64
+
65
+ ## Docs
66
+
67
+ - [OpenClaw Integration](https://docs.dim.cool/examples/openclaw-skill) — full setup and SOUL.md guidance.
68
+ - [MCP tools reference](https://docs.dim.cool/mcp/tools) — same tool names and behavior.
69
+
70
+ ## Module resolution (jiti)
71
+
72
+ The published package ships a **pre-built bundle** (`dist/index.js`) that OpenClaw loads by default. Dependencies are inlined so the plugin works even when jiti resolves modules from the gateway root instead of the plugin directory. If you use the source entry (`index.ts`) instead, ensure jiti resolves from the plugin dir (e.g. correct `baseUrl` in the plugin’s `tsconfig.json`).
73
+
74
+ ## Versioning
75
+
76
+ This package is published in lockstep with `@dimcool/sdk`, `@dimcool/wallet`, and `@dimcool/mcp`. Upgrade to the latest when the API or SDK changes.
package/dim-client.ts ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * DIM SDK client for the OpenClaw plugin.
3
+ * Handles wallet-based authentication using a Solana keypair.
4
+ */
5
+
6
+ import { SDK, NodeStorage } from '@dimcool/sdk';
7
+ import { Keypair, Transaction } from '@solana/web3.js';
8
+ import bs58 from 'bs58';
9
+ import nacl from 'tweetnacl';
10
+
11
+ export interface DimClientConfig {
12
+ /** Base58-encoded Solana private key */
13
+ walletPrivateKey: string;
14
+ /** API base URL (default: https://api.dim.cool) */
15
+ apiUrl?: string;
16
+ /** Referral code to use on first signup */
17
+ referralCode?: string;
18
+ }
19
+
20
+ export class DimClient {
21
+ public sdk: SDK;
22
+ private keypair: Keypair;
23
+ private config: DimClientConfig;
24
+ private authenticated = false;
25
+ private userId: string | null = null;
26
+
27
+ constructor(config: DimClientConfig) {
28
+ this.config = config;
29
+ const secretKeyBytes = bs58.decode(config.walletPrivateKey);
30
+ this.keypair = Keypair.fromSecretKey(secretKeyBytes);
31
+
32
+ this.sdk = new SDK({
33
+ appId: 'dim-agents',
34
+ baseUrl: config.apiUrl || 'https://api.dim.cool',
35
+ storage: new NodeStorage(),
36
+ autoPay: {
37
+ enabled: true,
38
+ maxAmountMinor: 25_000,
39
+ maxRetries: 1,
40
+ },
41
+ });
42
+ }
43
+
44
+ get walletAddress(): string {
45
+ return this.keypair.publicKey.toBase58();
46
+ }
47
+
48
+ get isAuthenticated(): boolean {
49
+ return this.authenticated;
50
+ }
51
+
52
+ get currentUserId(): string | null {
53
+ return this.userId;
54
+ }
55
+
56
+ async authenticate(): Promise<{
57
+ userId: string;
58
+ username?: string | null;
59
+ accessToken: string;
60
+ }> {
61
+ this.sdk.wallet.setSigner({
62
+ address: this.walletAddress,
63
+ signMessage: async (message: string): Promise<Uint8Array | string> => {
64
+ const signature = nacl.sign.detached(
65
+ new TextEncoder().encode(message),
66
+ this.keypair.secretKey,
67
+ );
68
+ return Buffer.from(signature).toString('base64');
69
+ },
70
+ signTransaction: async (
71
+ transaction: Transaction,
72
+ ): Promise<Transaction> => {
73
+ transaction.partialSign(this.keypair);
74
+ return transaction;
75
+ },
76
+ });
77
+
78
+ const response = await this.sdk.auth.loginWithWallet({
79
+ referralCode: this.config.referralCode,
80
+ walletMeta: { type: 'keypair' },
81
+ });
82
+
83
+ this.sdk.wsTransport.setAccessToken(response.access_token);
84
+
85
+ this.authenticated = true;
86
+ this.userId = response.user.id;
87
+
88
+ return {
89
+ userId: response.user.id,
90
+ username: response.user.username,
91
+ accessToken: response.access_token,
92
+ };
93
+ }
94
+
95
+ async ensureConnected(timeoutMs = 10000): Promise<void> {
96
+ await this.sdk.ensureWebSocketConnected(timeoutMs);
97
+ }
98
+
99
+ getKeypair(): Keypair {
100
+ return this.keypair;
101
+ }
102
+ }