@shipload/sdk 2.0.0-rc6 → 2.0.0-rc7

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 CHANGED
@@ -1,349 +1 @@
1
- # Shipload SDK
2
-
3
- TypeScript SDK for Shipload, a blockchain-based space trading game on Antelope blockchains.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- yarn add @shipload/sdk
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```typescript
14
- import Shipload from '@shipload/sdk'
15
-
16
- // Initialize with chain
17
- const sdk = await Shipload.load('jungle4')
18
-
19
- // Get player data
20
- const player = await sdk.players.getPlayer('myaccount')
21
-
22
- // Get ships
23
- const ships = await sdk.entities.getShips('myaccount')
24
-
25
- // Find profitable trades
26
- const deals = await sdk.trades.findDeals(ships[0])
27
- ```
28
-
29
- ## Architecture
30
-
31
- ### Main Class
32
-
33
- `Shipload` is the main entry point providing access to all SDK functionality through lazy-loaded managers.
34
-
35
- ```typescript
36
- const sdk = await Shipload.load('jungle4', {
37
- platformContractName: 'shipplatform',
38
- serverContractName: 'shipserver11',
39
- })
40
-
41
- // Managers
42
- sdk.entities // Entity retrieval (ships, warehouses, containers)
43
- sdk.players // Player data
44
- sdk.locations // Location and market data
45
- sdk.trades // Trade analysis
46
- sdk.epochs // Epoch timing
47
- sdk.actions // Action builders for transactions
48
-
49
- // Game state
50
- const game = await sdk.getGame()
51
- const state = await sdk.getState()
52
- ```
53
-
54
- ### Managers
55
-
56
- | Manager | Purpose |
57
- | ------------------ | -------------------------------------------------- |
58
- | `EntitiesManager` | Fetch ships, warehouses, containers by ID or owner |
59
- | `PlayersManager` | Get player accounts and financial data |
60
- | `LocationsManager` | Market prices, system discovery, nearby planets |
61
- | `TradesManager` | Find profitable trade routes with caching |
62
- | `EpochsManager` | Epoch timing, progress, remaining time |
63
- | `ActionsManager` | Build transaction actions for all game operations |
64
-
65
- ### Entities
66
-
67
- Entity classes wrap contract data with computed properties and methods:
68
-
69
- ```typescript
70
- // Ship - Full-featured movable entity
71
- const ship = await sdk.entities.getShip(123)
72
- ship.name // Ship name
73
- ship.isIdle // No pending tasks
74
- ship.maxDistance // Max travel range
75
- ship.availableCapacity // Remaining cargo space
76
- ship.energyPercent // 0-100 energy level
77
- ship.needsRecharge // Below capacity
78
- ship.sellableCargo // Cargo that can be sold
79
- ship.sched.isComplete(now) // Schedule accessor
80
- ship.inv.totalMass // Inventory accessor
81
-
82
- // Warehouse - Stationary storage
83
- const warehouse = await sdk.entities.getWarehouse(456)
84
- warehouse.availableCapacity
85
- warehouse.orbitalAltitude
86
-
87
- // Container - Movable cargo container
88
- const container = await sdk.entities.getContainer(789)
89
- container.totalMass
90
-
91
- // Player - Account with financial helpers
92
- const player = await sdk.players.getPlayer('account')
93
- player.availableLoan
94
- player.canBuyShip()
95
- player.getNextShipCost()
96
-
97
- // Location - Coordinates with market data
98
- const location = ship.location
99
- location.marketPrices // Cached prices
100
- location.getSupply(goodId) // Available supply
101
- ```
102
-
103
- ### Capabilities
104
-
105
- Type guards for entity feature detection:
106
-
107
- ```typescript
108
- import {canMove, hasEnergy, hasStorage, hasExtractor} from '@shipload/sdk'
109
-
110
- if (canMove(entity)) {
111
- const distance = maxTravelDistance(entity)
112
- }
113
-
114
- if (hasStorage(entity)) {
115
- const space = availableCapacity(entity)
116
- }
117
- ```
118
-
119
- ## Pure Functions
120
-
121
- Game logic is implemented as pure functions for testability and contract parity.
122
-
123
- ### Market
124
-
125
- ```typescript
126
- import {marketPrice, marketPrices, getRarity, getGood, getGoods} from '@shipload/sdk'
127
-
128
- // Get price at location
129
- const price = marketPrice(location, goodId, game.config.seed, state)
130
-
131
- // Get all prices at location
132
- const prices = marketPrices(location, game.config.seed, state)
133
-
134
- // Get rarity tier (legendary, epic, rare, uncommon, common, trash)
135
- const rarity = getRarity(gameSeed, epochSeed, location, goodId)
136
-
137
- // Goods definitions
138
- const good = getGood(1) // Get good by ID
139
- const goods = getGoods() // All goods
140
- ```
141
-
142
- ### Travel
143
-
144
- ```typescript
145
- import {
146
- distanceBetweenCoordinates,
147
- estimateTravelTime,
148
- calculateFlightTime,
149
- calculateRefuelingTime,
150
- findNearbyPlanets,
151
- } from '@shipload/sdk'
152
-
153
- // Distance calculation
154
- const distance = distanceBetweenCoordinates(origin, destination)
155
-
156
- // Full travel time estimate
157
- const estimate = estimateTravelTime(ship, travelMass, distance, {
158
- includeRefuel: true,
159
- loadMass: 500,
160
- unloadMass: 300,
161
- })
162
-
163
- // Find nearby systems
164
- const planets = findNearbyPlanets(gameSeed, origin, maxDistance)
165
- ```
166
-
167
- Contract-parity functions (prefixed `calc_`) mirror C++ exactly:
168
-
169
- ```typescript
170
- import {
171
- calc_flighttime,
172
- calc_rechargetime,
173
- calc_energyusage,
174
- calc_acceleration,
175
- calc_orbital_altitude,
176
- } from '@shipload/sdk'
177
- ```
178
-
179
- ### Trading
180
-
181
- ```typescript
182
- import {
183
- calculateTradeProfit,
184
- calculateMaxTradeQuantity,
185
- findDealsForShip,
186
- analyzeCollectOptions,
187
- } from '@shipload/sdk'
188
-
189
- // Calculate profit
190
- const profit = calculateTradeProfit(quantity, buyPrice, sellPrice)
191
-
192
- // Find profitable routes
193
- const deals = await sdk.trades.findDeals(ship, origin, {
194
- maxDistance: 5000,
195
- minProfit: 100,
196
- })
197
-
198
- // Decision support when arriving
199
- const options = await sdk.trades.getCollectOptions(ship, arrivedAt)
200
- // Returns: sell-and-trade, sell-and-reposition, travel-to-sell, etc.
201
- ```
202
-
203
- ### Scheduling
204
-
205
- ```typescript
206
- import {
207
- isIdle,
208
- scheduleProgress,
209
- scheduleRemaining,
210
- currentTask,
211
- currentTaskType,
212
- } from '@shipload/sdk'
213
-
214
- // Check schedule state
215
- if (isIdle(entity)) {
216
- /* no pending tasks */
217
- }
218
-
219
- // Get progress (0-1)
220
- const progress = scheduleProgress(entity, Date.now())
221
-
222
- // Current task
223
- const task = currentTask(entity, Date.now())
224
- const taskType = currentTaskType(entity, Date.now())
225
- ```
226
-
227
- ### Projection
228
-
229
- Project entity state forward through scheduled tasks:
230
-
231
- ```typescript
232
- import {projectEntity, projectEntityAt} from '@shipload/sdk'
233
-
234
- // Project to schedule completion
235
- const projected = projectEntity(ship)
236
-
237
- // Project to specific time
238
- const futureState = projectEntityAt(ship, futureTimestamp)
239
- ```
240
-
241
- ## Actions
242
-
243
- Build transaction actions for blockchain submission:
244
-
245
- ```typescript
246
- const actions = sdk.actions
247
-
248
- // Travel
249
- const travelAction = actions.travel(shipId, destination, recharge)
250
- const groupAction = actions.grouptravel([entity1, entity2], destination)
251
-
252
- // Trading
253
- const buyAction = actions.buyGoods(entityId, goodId, quantity)
254
- const sellAction = actions.sellGoods(entityId, goodId, quantity)
255
- const sellAllAction = actions.sellAllCargo(ship)
256
-
257
- // Cargo transfer
258
- const transferAction = actions.transfer(sourceType, sourceId, destType, destId, goodId, quantity)
259
-
260
- // Ship management
261
- const rechargeAction = actions.recharge(shipId)
262
- const resolveAction = actions.resolve(entityId)
263
- const cancelAction = actions.cancel(entityId, count)
264
-
265
- // Purchases
266
- const buyShipAction = actions.buyShip(account, 'Ship Name')
267
- const buyWarehouseAction = actions.buyWarehouse(account, 'Warehouse', x, y)
268
-
269
- // Financial
270
- const loanAction = actions.takeLoan(account, amount)
271
- const payAction = actions.payLoan(account, amount)
272
-
273
- // Extraction
274
- const extractAction = actions.extract(shipId)
275
- ```
276
-
277
- ## Epoch Management
278
-
279
- ```typescript
280
- const epochs = sdk.epochs
281
-
282
- // Current epoch info
283
- const current = epochs.getCurrent()
284
- const height = epochs.getCurrentHeight()
285
-
286
- // Timing
287
- const remaining = epochs.getTimeRemaining() // milliseconds
288
- const progress = epochs.getProgress() // 0-1
289
-
290
- // Planning
291
- const fitsInEpoch = epochs.fitsInCurrentEpoch(travelDuration)
292
- ```
293
-
294
- ## Entity Factories
295
-
296
- Create entities for testing without blockchain:
297
-
298
- ```typescript
299
- import {makeShip, makeWarehouse, makeContainer} from '@shipload/sdk'
300
-
301
- const ship = makeShip({
302
- entity_id: 1,
303
- owner: 'testaccount',
304
- // ... minimal required fields
305
- })
306
- ```
307
-
308
- ## Types
309
-
310
- ```typescript
311
- import type {
312
- Entity,
313
- ShipEntity,
314
- WarehouseEntity,
315
- ContainerEntity,
316
- AnyEntity,
317
- Good,
318
- GoodPrice,
319
- Coordinates,
320
- Deal,
321
- CollectOption,
322
- ProjectedEntity,
323
- } from '@shipload/sdk'
324
-
325
- // Constants
326
- import {PRECISION, EntityType, TaskType, LocationType} from '@shipload/sdk'
327
- ```
328
-
329
- ## Contract Types
330
-
331
- Generated types from blockchain ABIs:
332
-
333
- ```typescript
334
- import {ServerContract, PlatformContract} from '@shipload/sdk'
335
-
336
- type ShipRow = ServerContract.Types.ship_row
337
- type PlayerRow = ServerContract.Types.player_row
338
- type StateRow = ServerContract.Types.state_row
339
- ```
340
-
341
- ## Development
342
-
343
- ```bash
344
- make lib # Build bundles (CJS, ESM, UMD)
345
- make test # Run tests
346
- make check # ESLint
347
- make codegen # Regenerate contract types
348
- make dev # Watch mode
349
- ```
1
+ # SDK