@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.
- package/README.md +113 -104
- 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.
|
|
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
|
|
14
|
+
import { GodlSupply } from "@zenx-labs/godl-supply";
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
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(
|
|
25
|
-
console.log(
|
|
26
|
-
})
|
|
25
|
+
sdk.on("board", (board) => {
|
|
26
|
+
console.log("Round:", board.roundId);
|
|
27
|
+
});
|
|
27
28
|
|
|
28
|
-
sdk.on(
|
|
29
|
-
console.log(
|
|
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(
|
|
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
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
60
|
-
wsUrl?: string
|
|
61
|
-
streamApiUrl?: string // GODL stream REST API URL (default: https://stream.godl.dev)
|
|
62
|
-
commitment?:
|
|
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()
|
|
72
|
-
sdk.disconnect()
|
|
73
|
-
sdk.isConnected
|
|
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(
|
|
88
|
+
const unsub = sdk.on("board", (board) => {
|
|
89
|
+
/* ... */
|
|
90
|
+
});
|
|
83
91
|
|
|
84
92
|
// Unsubscribe
|
|
85
|
-
unsub()
|
|
93
|
+
unsub();
|
|
86
94
|
// or
|
|
87
|
-
sdk.off(
|
|
95
|
+
sdk.off("board", handler);
|
|
88
96
|
```
|
|
89
97
|
|
|
90
98
|
#### Available Events
|
|
91
99
|
|
|
92
|
-
| Event
|
|
93
|
-
|
|
94
|
-
| `board`
|
|
95
|
-
| `round`
|
|
96
|
-
| `resetEvent`
|
|
97
|
-
| `treasury`
|
|
98
|
-
| `miner`
|
|
99
|
-
| `automation`
|
|
100
|
-
| `slotData`
|
|
101
|
-
| `solMotherlode`
|
|
102
|
-
| `poolMember`
|
|
103
|
-
| `poolRound`
|
|
104
|
-
| `slotTick`
|
|
105
|
-
| `connected`
|
|
106
|
-
| `error`
|
|
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(
|
|
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
|
|
127
|
-
const treasury = await sdk.getTreasury()
|
|
128
|
-
const config
|
|
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
|
|
132
|
-
const miner2
|
|
133
|
-
const automation = await sdk.getAutomation()
|
|
134
|
-
const stake
|
|
135
|
-
const stakeV2
|
|
136
|
-
const allStakes
|
|
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
|
|
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()
|
|
144
|
-
const 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,
|
|
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,
|
|
176
|
-
isPooled: false,
|
|
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)
|
|
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(
|
|
210
|
+
const sig = await sdk.setStakeExecutor(0n, address("executor..."));
|
|
202
211
|
|
|
203
212
|
// NFT boost
|
|
204
|
-
const sig = await sdk.stakeNft(0n, address(
|
|
205
|
-
const sig = await sdk.unstakeNft(0n, address(
|
|
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
|
|
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,
|
|
251
|
-
} from
|
|
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(
|
|
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
|
|
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,
|
|
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,
|
|
279
|
-
GODL_MINT,
|
|
280
|
-
ENTROPY_PROGRAM_ADDRESS,
|
|
281
|
-
EXECUTOR_ADDRESS,
|
|
282
|
-
AUTOMATION_FEE,
|
|
283
|
-
NFT_BOOST_COLLECTION,
|
|
284
|
-
} from
|
|
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.
|
|
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",
|