@zenx-labs/godl-supply 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +113 -104
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zenx-labs/godl-supply
2
2
 
3
- TypeScript SDK for interacting with the [GODL](https://godl.dev) on-chain program on Solana. Provides real-time WebSocket streaming, account fetching with caching, transaction building, and full type safety.
3
+ TypeScript SDK for interacting with the [GODL](https://godl.supply) on-chain program on Solana. Provides real-time WebSocket streaming, account fetching with caching, transaction building, and full type safety.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,56 +11,62 @@ npm install @zenx-labs/godl-supply
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { GodlSupply } from '@zenx-labs/godl-supply'
14
+ import { GodlSupply } from "@zenx-labs/godl-supply";
15
15
 
16
- const sdk = new GodlSupply(signer, {
17
- rpcUrl: 'https://api.mainnet-beta.solana.com', // optional, defaults to public mainnet
18
- })
16
+ // Load signer from a keypair.json file (Solana CLI format)
17
+ const sdk = await GodlSupply.create("~/.config/solana/id.json", {
18
+ rpcUrl: "https://api.mainnet-beta.solana.com", // optional, defaults to public mainnet
19
+ });
19
20
 
20
21
  // Connect to real-time WebSocket stream
21
- await sdk.connect()
22
+ await sdk.connect();
22
23
 
23
24
  // Listen for events
24
- sdk.on('board', (board) => {
25
- console.log('Round:', board.roundId)
26
- })
25
+ sdk.on("board", (board) => {
26
+ console.log("Round:", board.roundId);
27
+ });
27
28
 
28
- sdk.on('treasury', (treasury) => {
29
- console.log('Balance:', treasury.balance)
30
- })
29
+ sdk.on("treasury", (treasury) => {
30
+ console.log("Balance:", treasury.balance);
31
+ });
31
32
 
32
33
  // Fetch account data (cached + RPC fallback)
33
- const board = await sdk.getBoard()
34
- const miner = await sdk.getMiner('68m3ocDFeJ1iQE9Pyu9Exn1HdpGcTgh12zpjWM7K8pKU')
34
+ const board = await sdk.getBoard();
35
+ const miner = await sdk.getMiner(
36
+ "68m3ocDFeJ1iQE9Pyu9Exn1HdpGcTgh12zpjWM7K8pKU",
37
+ );
35
38
 
36
39
  // Disconnect when done
37
- sdk.disconnect()
40
+ sdk.disconnect();
38
41
  ```
39
42
 
40
43
  ## Signer
41
44
 
42
- The SDK expects a `Signer` compatible with the [gill](https://github.com/solana-developers/gill) library:
45
+ The SDK uses [gill](https://github.com/solana-developers/gill)'s `KeyPairSigner`. The easiest way is to use `GodlSupply.create()` with a path to your keypair.json file (Solana CLI format):
43
46
 
44
47
  ```typescript
45
- import type { Signer } from '@zenx-labs/godl-supply'
46
-
47
- const signer: Signer = {
48
- address: address('YourPublicKey...'),
49
- async signAndSendTransactions(transactions, config) {
50
- // Sign and submit transactions to the network
51
- },
52
- }
48
+ const sdk = await GodlSupply.create("~/.config/solana/id.json");
49
+ ```
50
+
51
+ For advanced use cases, you can pass a `KeyPairSigner` directly to the constructor:
52
+
53
+ ```typescript
54
+ import { GodlSupply } from "@zenx-labs/godl-supply";
55
+ import { loadKeypairSignerFromFile } from "gill/node";
56
+
57
+ const signer = await loadKeypairSignerFromFile("~/.config/solana/id.json");
58
+ const sdk = new GodlSupply(signer, { rpcUrl: "https://your-rpc.com" });
53
59
  ```
54
60
 
55
61
  ## Configuration
56
62
 
57
63
  ```typescript
58
64
  type GodlSupplyConfig = {
59
- rpcUrl?: string // Solana RPC endpoint (default: public mainnet)
60
- wsUrl?: string // GODL stream WebSocket URL (default: wss://stream.godl.dev/stream)
61
- streamApiUrl?: string // GODL stream REST API URL (default: https://stream.godl.dev)
62
- commitment?: 'confirmed' | 'finalized' | 'processed' // default: 'confirmed'
63
- }
65
+ rpcUrl?: string; // Solana RPC endpoint (default: public mainnet)
66
+ wsUrl?: string; // GODL stream WebSocket URL (default: wss://stream.godl.dev/stream)
67
+ streamApiUrl?: string; // GODL stream REST API URL (default: https://stream.godl.dev)
68
+ commitment?: "confirmed" | "finalized" | "processed"; // default: 'confirmed'
69
+ };
64
70
  ```
65
71
 
66
72
  ## API Reference
@@ -68,9 +74,9 @@ type GodlSupplyConfig = {
68
74
  ### Lifecycle
69
75
 
70
76
  ```typescript
71
- await sdk.connect() // Connect to WebSocket stream and sync initial state
72
- sdk.disconnect() // Disconnect and clear cache
73
- sdk.isConnected // boolean
77
+ await sdk.connect(); // Connect to WebSocket stream and sync initial state
78
+ sdk.disconnect(); // Disconnect and clear cache
79
+ sdk.isConnected; // boolean
74
80
  ```
75
81
 
76
82
  ### Events
@@ -79,42 +85,44 @@ The SDK emits typed events via WebSocket. Subscribe with `on()` and unsubscribe
79
85
 
80
86
  ```typescript
81
87
  // Subscribe
82
- const unsub = sdk.on('board', (board) => { /* ... */ })
88
+ const unsub = sdk.on("board", (board) => {
89
+ /* ... */
90
+ });
83
91
 
84
92
  // Unsubscribe
85
- unsub()
93
+ unsub();
86
94
  // or
87
- sdk.off('board', handler)
95
+ sdk.off("board", handler);
88
96
  ```
89
97
 
90
98
  #### Available Events
91
99
 
92
- | Event | Data Type | Description |
93
- |------------------|-----------------|------------------------------------------|
94
- | `board` | `Board` | Current board state (round info, slots) |
95
- | `round` | `Round` | Round deployment data and results |
96
- | `resetEvent` | `ResetEvent` | Round reset with winners and payouts |
97
- | `treasury` | `Treasury` | Treasury balances and reward factors |
98
- | `miner` | `Miner` | Your miner account updates |
99
- | `automation` | `Automation` | Your autominer account updates |
100
- | `slotData` | `SlotData` | Slot synchronization data |
101
- | `solMotherlode` | `SolMotherlode` | SOL motherlode amount |
102
- | `poolMember` | `PoolMember` | Your pool membership data |
103
- | `poolRound` | `PoolRound` | Pool round deployment data |
104
- | `slotTick` | `bigint` | Emitted every ~400ms with current slot |
105
- | `connected` | `boolean` | WebSocket connection state changes |
106
- | `error` | `Error` | WebSocket errors |
100
+ | Event | Data Type | Description |
101
+ | --------------- | --------------- | --------------------------------------- |
102
+ | `board` | `Board` | Current board state (round info, slots) |
103
+ | `round` | `Round` | Round deployment data and results |
104
+ | `resetEvent` | `ResetEvent` | Round reset with winners and payouts |
105
+ | `treasury` | `Treasury` | Treasury balances and reward factors |
106
+ | `miner` | `Miner` | Your miner account updates |
107
+ | `automation` | `Automation` | Your autominer account updates |
108
+ | `slotData` | `SlotData` | Slot synchronization data |
109
+ | `solMotherlode` | `SolMotherlode` | SOL motherlode amount |
110
+ | `poolMember` | `PoolMember` | Your pool membership data |
111
+ | `poolRound` | `PoolRound` | Pool round deployment data |
112
+ | `slotTick` | `bigint` | Emitted every ~400ms with current slot |
113
+ | `connected` | `boolean` | WebSocket connection state changes |
114
+ | `error` | `Error` | WebSocket errors |
107
115
 
108
116
  ### Slot Tracking
109
117
 
110
118
  The SDK maintains a local slot counter that increments every ~400ms after the initial sync from the WebSocket.
111
119
 
112
120
  ```typescript
113
- const currentSlot = sdk.getSlot()
121
+ const currentSlot = sdk.getSlot();
114
122
 
115
123
  const unsub = sdk.onSlotTick((slot) => {
116
- console.log('Slot:', slot)
117
- })
124
+ console.log("Slot:", slot);
125
+ });
118
126
  ```
119
127
 
120
128
  ### Account Getters
@@ -123,43 +131,44 @@ All account getters use a two-tier strategy: check the in-memory cache first (15
123
131
 
124
132
  ```typescript
125
133
  // Global state
126
- const board = await sdk.getBoard()
127
- const treasury = await sdk.getTreasury()
128
- const config = await sdk.getConfig()
134
+ const board = await sdk.getBoard();
135
+ const treasury = await sdk.getTreasury();
136
+ const config = await sdk.getConfig();
129
137
 
130
138
  // Per-user accounts (defaults to signer if no authority provided)
131
- const miner = await sdk.getMiner()
132
- const miner2 = await sdk.getMiner('SomeOtherPublicKey...')
133
- const automation = await sdk.getAutomation() // returns null if not set up
134
- const stake = await sdk.getStake()
135
- const stakeV2 = await sdk.getStakeV2(0n) // by stake ID
136
- const allStakes = await sdk.getStakeV2Accounts() // all StakeV2 accounts
139
+ const miner = await sdk.getMiner();
140
+ const miner2 = await sdk.getMiner("SomeOtherPublicKey...");
141
+ const automation = await sdk.getAutomation(); // returns null if not set up
142
+ const stake = await sdk.getStake();
143
+ const stakeV2 = await sdk.getStakeV2(0n); // by stake ID
144
+ const allStakes = await sdk.getStakeV2Accounts(); // all StakeV2 accounts
137
145
 
138
146
  // Round data
139
- const round = await sdk.getRound(42n) // returns null if not found
140
- const poolRound = await sdk.getPoolRound(42n)
147
+ const round = await sdk.getRound(42n); // returns null if not found
148
+ const poolRound = await sdk.getPoolRound(42n);
141
149
 
142
150
  // Pool and referral
143
- const poolMember = await sdk.getPoolMember() // returns null if not a member
144
- const referrer = await sdk.getReferrer() // returns null if not a referrer
151
+ const poolMember = await sdk.getPoolMember(); // returns null if not a member
152
+ const referrer = await sdk.getReferrer(); // returns null if not a referrer
145
153
  ```
146
154
 
147
155
  ### Mining
148
156
 
149
157
  ```typescript
150
158
  // Deploy to the board
159
+ // amount is lamports PER SQUARE — total SOL spent = amount × squares.length
151
160
  const sig = await sdk.deploy({
152
- amount: 100,
161
+ amount: 100, // 100 lamports per square (500 lamports total for 5 squares)
153
162
  squares: [0, 5, 12, 18, 24],
154
- varAddress: address('...'),
155
- isPooled: false, // optional, default: false
156
- })
163
+ varAddress: address("..."),
164
+ isPooled: false, // optional, default: false
165
+ });
157
166
 
158
167
  // Claim rewards
159
168
  const sig = await sdk.claim({
160
169
  claimSol: true,
161
170
  claimGodl: true,
162
- })
171
+ });
163
172
  ```
164
173
 
165
174
  ### Autominer
@@ -172,37 +181,37 @@ const sig = await sdk.setupAutominer({
172
181
  squares: [0, 5, 12, 18, 24],
173
182
  strategy: 1,
174
183
  numRounds: 10,
175
- claimAndFund: false, // optional
176
- isPooled: false, // optional
177
- })
184
+ claimAndFund: false, // optional
185
+ isPooled: false, // optional
186
+ });
178
187
 
179
188
  // Fund autominer
180
- const sig = await sdk.fundAutomation(1_000_000)
189
+ const sig = await sdk.fundAutomation(1_000_000);
181
190
 
182
191
  // Stop autominer
183
- const sig = await sdk.stopAutominer()
192
+ const sig = await sdk.stopAutominer();
184
193
  ```
185
194
 
186
195
  ### Staking
187
196
 
188
197
  ```typescript
189
198
  // V1 Staking
190
- const sig = await sdk.stakeDeposit(1_000_000n)
191
- const sig = await sdk.stakeWithdraw(500_000n)
192
- const sig = await sdk.stakeClaimYield(100_000n)
199
+ const sig = await sdk.stakeDeposit(1_000_000n);
200
+ const sig = await sdk.stakeWithdraw(500_000n);
201
+ const sig = await sdk.stakeClaimYield(100_000n);
193
202
 
194
203
  // V2 Staking (with lock duration and multiplier)
195
- const sig = await sdk.stakeV2Deposit(0n, 1_000_000n, 30n) // id, amount, lockDuration
196
- const sig = await sdk.stakeV2Withdraw(0n, 500_000n)
197
- const sig = await sdk.stakeV2ClaimYield(0n, 100_000n)
198
- const sig = await sdk.stakeV2CompoundYield(0n)
204
+ const sig = await sdk.stakeV2Deposit(0n, 1_000_000n, 30n); // id, amount, lockDuration
205
+ const sig = await sdk.stakeV2Withdraw(0n, 500_000n);
206
+ const sig = await sdk.stakeV2ClaimYield(0n, 100_000n);
207
+ const sig = await sdk.stakeV2CompoundYield(0n);
199
208
 
200
209
  // Set executor for V2 stake
201
- const sig = await sdk.setStakeExecutor(0n, address('executor...'))
210
+ const sig = await sdk.setStakeExecutor(0n, address("executor..."));
202
211
 
203
212
  // NFT boost
204
- const sig = await sdk.stakeNft(0n, address('nftAsset...'))
205
- const sig = await sdk.unstakeNft(0n, address('nftAsset...'))
213
+ const sig = await sdk.stakeNft(0n, address("nftAsset..."));
214
+ const sig = await sdk.unstakeNft(0n, address("nftAsset..."));
206
215
  ```
207
216
 
208
217
  ## Low-Level Instruction Builders
@@ -228,7 +237,7 @@ import {
228
237
  getSetStakeExecutorV2Instruction,
229
238
  getStakeNftInstruction,
230
239
  getUnstakeNftInstruction,
231
- } from '@zenx-labs/godl-supply'
240
+ } from "@zenx-labs/godl-supply";
232
241
  ```
233
242
 
234
243
  ## PDA Derivation
@@ -247,13 +256,13 @@ import {
247
256
  getStakeV2Pda,
248
257
  getPoolRoundPda,
249
258
  getPoolMemberPda,
250
- getGodlAta, // returns Promise<Address>
251
- } from '@zenx-labs/godl-supply'
259
+ getGodlAta, // returns Promise<Address>
260
+ } from "@zenx-labs/godl-supply";
252
261
 
253
- const [boardKey, bump] = getBoardPda()
254
- const [minerKey, bump] = getMinerPda(publicKey)
255
- const [stakeKey, bump] = getStakeV2Pda(publicKey, 0n)
256
- const ata = await getGodlAta(address('owner...'))
262
+ const [boardKey, bump] = getBoardPda();
263
+ const [minerKey, bump] = getMinerPda(publicKey);
264
+ const [stakeKey, bump] = getStakeV2Pda(publicKey, 0n);
265
+ const ata = await getGodlAta(address("owner..."));
257
266
  ```
258
267
 
259
268
  ## Advanced Usage
@@ -261,27 +270,27 @@ const ata = await getGodlAta(address('owner...'))
261
270
  The SDK exports internal components for custom integrations:
262
271
 
263
272
  ```typescript
264
- import { HotCache, SlotTracker, AccountFetcher } from '@zenx-labs/godl-supply'
273
+ import { HotCache, SlotTracker, AccountFetcher } from "@zenx-labs/godl-supply";
265
274
 
266
275
  // Custom cache with 5s TTL
267
- const cache = new HotCache(5_000)
276
+ const cache = new HotCache(5_000);
268
277
 
269
278
  // Direct account fetching without the full client
270
- const fetcher = new AccountFetcher(rpc, cache, 'https://stream.godl.dev')
271
- const initData = await fetcher.fetchInitData()
279
+ const fetcher = new AccountFetcher(rpc, cache, "https://stream.godl.dev");
280
+ const initData = await fetcher.fetchInitData();
272
281
  ```
273
282
 
274
283
  ## Constants
275
284
 
276
285
  ```typescript
277
286
  import {
278
- GODL_PROGRAM_ID, // Program public key
279
- GODL_MINT, // GODL token mint address
280
- ENTROPY_PROGRAM_ADDRESS, // Entropy program for randomness
281
- EXECUTOR_ADDRESS, // Autominer executor
282
- AUTOMATION_FEE, // Fee per automation round (30,000 lamports)
283
- NFT_BOOST_COLLECTION, // NFT collection for stake boosts
284
- } from '@zenx-labs/godl-supply'
287
+ GODL_PROGRAM_ID, // Program public key
288
+ GODL_MINT, // GODL token mint address
289
+ ENTROPY_PROGRAM_ADDRESS, // Entropy program for randomness
290
+ EXECUTOR_ADDRESS, // Autominer executor
291
+ AUTOMATION_FEE, // Fee per automation round (30,000 lamports)
292
+ NFT_BOOST_COLLECTION, // NFT collection for stake boosts
293
+ } from "@zenx-labs/godl-supply";
285
294
  ```
286
295
 
287
296
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenx-labs/godl-supply",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript SDK for interacting with the GODL on-chain program",
5
5
  "license": "ISC",
6
6
  "author": "bootapollo",
@@ -23,7 +23,8 @@
23
23
  "build": "tsc",
24
24
  "dev": "tsc --watch",
25
25
  "test": "vitest run",
26
- "test:watch": "vitest"
26
+ "test:watch": "vitest",
27
+ "sniper": "npx tsx tests/ev-sniper.test.ts"
27
28
  },
28
29
  "dependencies": {
29
30
  "@msgpack/msgpack": "^3.1.2",