@shipload/sdk 1.0.0-next.7 → 1.0.0-next.71

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 (203) hide show
  1. package/lib/scan.d.ts +52 -0
  2. package/lib/scan.js +162 -0
  3. package/lib/scan.js.map +1 -0
  4. package/lib/scan.m.js +152 -0
  5. package/lib/scan.m.js.map +1 -0
  6. package/lib/shipload.d.ts +5822 -1484
  7. package/lib/shipload.js +20838 -5419
  8. package/lib/shipload.js.map +1 -1
  9. package/lib/shipload.m.js +20674 -5669
  10. package/lib/shipload.m.js.map +1 -1
  11. package/lib/testing.d.ts +1691 -0
  12. package/lib/testing.js +7109 -0
  13. package/lib/testing.js.map +1 -0
  14. package/lib/testing.m.js +7103 -0
  15. package/lib/testing.m.js.map +1 -0
  16. package/package.json +20 -2
  17. package/src/capabilities/craftable.test.ts +82 -0
  18. package/src/capabilities/craftable.ts +82 -0
  19. package/src/capabilities/crafting.test.ts +80 -0
  20. package/src/capabilities/crafting.ts +50 -8
  21. package/src/capabilities/gathering.test.ts +29 -0
  22. package/src/capabilities/gathering.ts +38 -20
  23. package/src/capabilities/hauling.ts +0 -5
  24. package/src/capabilities/index.ts +0 -1
  25. package/src/capabilities/modules.ts +27 -30
  26. package/src/capabilities/movement.ts +1 -1
  27. package/src/capabilities/storage.test.ts +26 -0
  28. package/src/capabilities/storage.ts +22 -7
  29. package/src/contracts/fund.ts +306 -0
  30. package/src/contracts/platform.ts +312 -3
  31. package/src/contracts/server.ts +2793 -478
  32. package/src/contracts/token.ts +170 -0
  33. package/src/contracts.ts +2 -0
  34. package/src/coordinates/address.ts +88 -0
  35. package/src/coordinates/constants.test.ts +15 -0
  36. package/src/coordinates/constants.ts +23 -0
  37. package/src/coordinates/index.ts +15 -0
  38. package/src/coordinates/memo.test.ts +47 -0
  39. package/src/coordinates/memo.ts +20 -0
  40. package/src/coordinates/permutation.ts +77 -0
  41. package/src/coordinates/regions.ts +48 -0
  42. package/src/coordinates/sectors.ts +115 -0
  43. package/src/data/capabilities.ts +49 -18
  44. package/src/data/capability-formulas.ts +26 -14
  45. package/src/data/catalog.test.ts +19 -0
  46. package/src/data/catalog.ts +13 -3
  47. package/src/data/charters.json +396 -0
  48. package/src/data/citizenry-adjectives.json +42 -0
  49. package/src/data/citizenry-nouns.json +50 -0
  50. package/src/data/colors.ts +14 -32
  51. package/src/data/entities.json +421 -15
  52. package/src/data/item-ids.ts +53 -13
  53. package/src/data/items.json +330 -77
  54. package/src/data/kind-registry.json +212 -0
  55. package/src/data/kind-registry.ts +192 -0
  56. package/src/data/metadata.ts +312 -51
  57. package/src/data/recipes-runtime.ts +6 -23
  58. package/src/data/recipes.json +2173 -173
  59. package/src/data/tiers.ts +9 -6
  60. package/src/derivation/build-methods.test.ts +71 -0
  61. package/src/derivation/build-methods.ts +50 -0
  62. package/src/derivation/capabilities.test.ts +348 -0
  63. package/src/derivation/capabilities.ts +707 -0
  64. package/src/derivation/capability-mappings.ts +60 -16
  65. package/src/derivation/crafting.test.ts +17 -0
  66. package/src/derivation/crafting.ts +57 -34
  67. package/src/derivation/index.ts +27 -2
  68. package/src/derivation/recipe-usage.test.ts +88 -0
  69. package/src/derivation/recipe-usage.ts +141 -0
  70. package/src/derivation/reserve-regen.ts +34 -0
  71. package/src/derivation/resources.ts +9 -1
  72. package/src/derivation/rollups.test.ts +55 -0
  73. package/src/derivation/rollups.ts +72 -0
  74. package/src/derivation/stars.test.ts +67 -0
  75. package/src/derivation/stars.ts +25 -0
  76. package/src/derivation/stat-scaling.ts +12 -0
  77. package/src/derivation/stats.ts +6 -6
  78. package/src/derivation/strata.ts +5 -3
  79. package/src/derivation/stratum.ts +26 -22
  80. package/src/derivation/tiers.ts +40 -7
  81. package/src/derivation/upgrades.ts +14 -0
  82. package/src/derivation/wormhole.ts +154 -0
  83. package/src/entities/entity.ts +102 -0
  84. package/src/entities/gamestate.ts +3 -28
  85. package/src/entities/makers.ts +144 -136
  86. package/src/entities/slot-multiplier.ts +43 -0
  87. package/src/entity/hydrate.test.ts +156 -0
  88. package/src/entity/hydrate.ts +86 -0
  89. package/src/errors.ts +21 -16
  90. package/src/format.ts +42 -9
  91. package/src/index-module.ts +425 -32
  92. package/src/influence/ballot.test.ts +103 -0
  93. package/src/influence/ballot.ts +98 -0
  94. package/src/influence/categories.ts +32 -0
  95. package/src/influence/charter-metadata.test.ts +136 -0
  96. package/src/influence/charter-metadata.ts +236 -0
  97. package/src/influence/charters.test.ts +112 -0
  98. package/src/influence/charters.ts +150 -0
  99. package/src/influence/citizenry.ts +38 -0
  100. package/src/influence/civic-shuttle.test.ts +202 -0
  101. package/src/influence/civic-shuttle.ts +142 -0
  102. package/src/influence/civic.test.ts +287 -0
  103. package/src/influence/civic.ts +269 -0
  104. package/src/influence/constants.ts +84 -0
  105. package/src/influence/decay.ts +20 -0
  106. package/src/influence/decomp.ts +95 -0
  107. package/src/influence/demand.ts +106 -0
  108. package/src/influence/duration.ts +101 -0
  109. package/src/influence/index.ts +118 -0
  110. package/src/influence/influence.test.ts +450 -0
  111. package/src/influence/quality.ts +25 -0
  112. package/src/influence/valuation.ts +154 -0
  113. package/src/managers/actions.ts +950 -93
  114. package/src/managers/balances.test.ts +161 -0
  115. package/src/managers/balances.ts +93 -0
  116. package/src/managers/base.ts +10 -2
  117. package/src/managers/cluster.test.ts +39 -0
  118. package/src/managers/cluster.ts +53 -0
  119. package/src/managers/construction-types.ts +80 -0
  120. package/src/managers/construction.ts +453 -0
  121. package/src/managers/context.ts +58 -1
  122. package/src/managers/coordinates.ts +14 -0
  123. package/src/managers/entities.ts +35 -63
  124. package/src/managers/epochs.ts +72 -1
  125. package/src/managers/index.ts +38 -1
  126. package/src/managers/influence.test.ts +56 -0
  127. package/src/managers/influence.ts +425 -0
  128. package/src/managers/jobs.test.ts +96 -0
  129. package/src/managers/jobs.ts +58 -0
  130. package/src/managers/locations.ts +25 -29
  131. package/src/managers/nft.test.ts +21 -0
  132. package/src/managers/nft.ts +110 -0
  133. package/src/managers/players.ts +25 -0
  134. package/src/managers/plot.ts +122 -0
  135. package/src/nft/atomicassets.abi.json +1342 -0
  136. package/src/nft/atomicassets.ts +237 -0
  137. package/src/nft/atomicdata.ts +130 -0
  138. package/src/nft/buildImmutableData.ts +388 -0
  139. package/src/nft/description.ts +222 -100
  140. package/src/nft/index.ts +3 -0
  141. package/src/planner/index.ts +296 -0
  142. package/src/planner/planner.test.ts +459 -0
  143. package/src/receipts.ts +22 -0
  144. package/src/resolution/describe-module.ts +43 -25
  145. package/src/resolution/display-name.ts +39 -11
  146. package/src/resolution/resolve-item.test.ts +48 -0
  147. package/src/resolution/resolve-item.ts +112 -58
  148. package/src/scan/index.ts +244 -0
  149. package/src/scan/scan-wasm.base64.ts +2 -0
  150. package/src/scheduling/accessor.ts +65 -23
  151. package/src/scheduling/availability.test.ts +320 -0
  152. package/src/scheduling/availability.ts +251 -0
  153. package/src/scheduling/cancel.test.ts +550 -0
  154. package/src/scheduling/cancel.ts +254 -0
  155. package/src/scheduling/cluster-stock.test.ts +31 -0
  156. package/src/scheduling/cluster-stock.ts +15 -0
  157. package/src/scheduling/energy.ts +47 -0
  158. package/src/scheduling/epoch.ts +1 -0
  159. package/src/scheduling/idle-resolve.ts +45 -0
  160. package/src/scheduling/jobs.test.ts +448 -0
  161. package/src/scheduling/jobs.ts +343 -0
  162. package/src/scheduling/lane-core.ts +128 -0
  163. package/src/scheduling/lanes.test.ts +250 -0
  164. package/src/scheduling/lanes.ts +279 -0
  165. package/src/scheduling/projection.ts +265 -149
  166. package/src/scheduling/schedule.test.ts +163 -0
  167. package/src/scheduling/schedule.ts +282 -116
  168. package/src/scheduling/task-cargo.test.ts +110 -0
  169. package/src/scheduling/task-cargo.ts +62 -0
  170. package/src/scheduling/task-effects.test.ts +35 -0
  171. package/src/scheduling/task-effects.ts +34 -0
  172. package/src/scheduling/unwrap.test.ts +86 -0
  173. package/src/scheduling/unwrap.ts +190 -0
  174. package/src/shipload.ts +63 -4
  175. package/src/subscriptions/manager.cluster.test.ts +51 -0
  176. package/src/subscriptions/manager.ts +245 -172
  177. package/src/subscriptions/mappers.ts +5 -8
  178. package/src/subscriptions/types.ts +28 -3
  179. package/src/testing/catalog-hash.ts +19 -0
  180. package/src/testing/index.ts +2 -0
  181. package/src/testing/projection-parity.ts +167 -0
  182. package/src/travel/reach.test.ts +86 -0
  183. package/src/travel/reach.ts +34 -0
  184. package/src/travel/route-build.test.ts +63 -0
  185. package/src/travel/route-build.ts +60 -0
  186. package/src/travel/route-planner.ts +288 -0
  187. package/src/travel/route-simulator.ts +170 -0
  188. package/src/travel/travel.ts +190 -123
  189. package/src/types/capabilities.ts +37 -8
  190. package/src/types/entity.ts +3 -3
  191. package/src/types/index.ts +0 -1
  192. package/src/types.ts +81 -23
  193. package/src/utils/cargo.test.ts +14 -0
  194. package/src/utils/cargo.ts +2 -0
  195. package/src/utils/display-name.ts +70 -0
  196. package/src/utils/hash.ts +22 -2
  197. package/src/utils/system.ts +24 -5
  198. package/src/capabilities/loading.ts +0 -8
  199. package/src/entities/container.ts +0 -123
  200. package/src/entities/ship-deploy.ts +0 -295
  201. package/src/entities/ship.ts +0 -221
  202. package/src/entities/warehouse.ts +0 -127
  203. package/src/types/entity-traits.ts +0 -69
@@ -1,8 +1,17 @@
1
1
  import {
2
- type Action,
2
+ Action,
3
+ Asset,
4
+ type AssetType,
5
+ Bytes,
6
+ Checksum256,
7
+ type Checksum256Type,
8
+ ExtendedAsset,
3
9
  Int64,
10
+ type Int64Type,
4
11
  Name,
5
12
  type NameType,
13
+ UInt8,
14
+ type UInt8Type,
6
15
  UInt16,
7
16
  type UInt16Type,
8
17
  UInt32,
@@ -11,21 +20,169 @@ import {
11
20
  type UInt64Type,
12
21
  } from '@wharfkit/antelope'
13
22
  import {BaseManager} from './base'
14
- import {type CoordinatesType, EntityType, type EntityTypeName} from '../types'
15
- import {ServerContract} from '../contracts'
23
+ import {Coordinates, PRECISION, type ClusterSlotType, type CoordinatesType} from '../types'
24
+ import {ServerContract, TokenContract} from '../contracts'
25
+ import {ATOMICASSETS_ABI, SHIPLOAD_COLLECTION} from '../nft/atomicassets'
26
+ import {getItem} from '../data/catalog'
27
+ import type {JobCancelRoute} from '../scheduling/jobs'
28
+
29
+ const CHARGE_K = 100n
30
+ const ENERGY_DIVISOR = 10n
31
+ const ENERGY_FLOOR = 1_000n
32
+ const UINT32_MAX = 4_294_967_295
33
+ const UINT32_MAX_BIGINT = 4_294_967_295n
34
+ const UINT32_MOD = 4_294_967_296n
35
+ const UINT64_MAX = 18_446_744_073_709_551_615n
36
+ const PRECISION_BIGINT = BigInt(PRECISION)
37
+
38
+ export type LaunchNumericInput =
39
+ | number
40
+ | bigint
41
+ | string
42
+ | {toNumber(): number}
43
+ | {toString(): string}
44
+
45
+ export interface LaunchStatsInput {
46
+ charge_rate?: LaunchNumericInput
47
+ chargeRate?: LaunchNumericInput
48
+ velocity: LaunchNumericInput
49
+ drain: LaunchNumericInput
50
+ }
51
+
52
+ export interface LaunchQuoteLauncher {
53
+ coordinates: CoordinatesType
54
+ launcher: LaunchStatsInput
55
+ generator?: {capacity: LaunchNumericInput}
56
+ }
57
+
58
+ export interface LaunchQuoteCatcher {
59
+ coordinates: CoordinatesType
60
+ }
61
+
62
+ export interface LaunchQuote {
63
+ chargeTime: number
64
+ flightTime: number
65
+ arrival: Date
66
+ energyCost: number
67
+ maxReach: bigint
68
+ }
69
+
70
+ function toNumber(value: LaunchNumericInput): number {
71
+ if (typeof value === 'number') return Math.trunc(value)
72
+ if (typeof value === 'bigint') return Number(value)
73
+ if (typeof value === 'string') return Number(value)
74
+ if ('toNumber' in value && typeof value.toNumber === 'function') return value.toNumber()
75
+ return Number(value.toString())
76
+ }
77
+
78
+ function requiredNumber(value: LaunchNumericInput | undefined, label: string): number {
79
+ if (value === undefined) throw new Error(`launch quote requires ${label}`)
80
+ return toNumber(value)
81
+ }
82
+
83
+ function toBigInt(value: LaunchNumericInput | undefined): bigint {
84
+ if (value === undefined) return 0n
85
+ if (typeof value === 'bigint') return value
86
+ if (typeof value === 'number') return BigInt(Math.trunc(value))
87
+ if (typeof value === 'string') return BigInt(value)
88
+ return BigInt(value.toString())
89
+ }
90
+
91
+ function saturatingMul(lhs: bigint, rhs: bigint): bigint {
92
+ if (lhs !== 0n && rhs > UINT64_MAX / lhs) {
93
+ return UINT64_MAX
94
+ }
95
+ return lhs * rhs
96
+ }
97
+
98
+ function clampLaunchResult(value: bigint): number {
99
+ if (value < 1n) return 1
100
+ if (value > UINT32_MAX_BIGINT) return UINT32_MAX
101
+ return Number(value)
102
+ }
103
+
104
+ function clampEnergyResult(value: bigint): number {
105
+ if (value < ENERGY_FLOOR) return Number(ENERGY_FLOOR)
106
+ if (value > UINT32_MAX_BIGINT) return UINT32_MAX
107
+ return Number(value)
108
+ }
109
+
110
+ function toUint32(value: bigint): bigint {
111
+ return value % UINT32_MOD
112
+ }
113
+
114
+ function calcDistance(origin: CoordinatesType, destination: CoordinatesType): bigint {
115
+ const a = Coordinates.from(origin)
116
+ const b = Coordinates.from(destination)
117
+ const dx = toNumber(a.x) - toNumber(b.x)
118
+ const dy = toNumber(a.y) - toNumber(b.y)
119
+ return BigInt(Math.trunc(Math.sqrt(dx * dx + dy * dy) * PRECISION))
120
+ }
121
+
122
+ function calcCargoItemMassUint32(item: ServerContract.ActionParams.Type.cargo_item): bigint {
123
+ let mass = toUint32(BigInt(getItem(item.item_id).mass) * toUint32(toBigInt(item.quantity)))
124
+
125
+ for (const mod of item.modules) {
126
+ if (mod.installed) {
127
+ mass = toUint32(mass + BigInt(getItem(mod.installed.item_id).mass))
128
+ }
129
+ }
130
+
131
+ return mass
132
+ }
133
+
134
+ function calcPayloadMass(items: ServerContract.ActionParams.Type.cargo_item[]): bigint {
135
+ let mass = 0n
136
+ for (const item of items) {
137
+ mass = toUint32(mass + calcCargoItemMassUint32(item))
138
+ }
139
+ return mass
140
+ }
141
+
142
+ function calcChargeTime(chargeRate: number, mass: bigint): number {
143
+ const rate = BigInt(chargeRate || 1)
144
+ const t = (mass * CHARGE_K) / rate
145
+ return clampLaunchResult(t + 1n)
146
+ }
147
+
148
+ function calcFlightTime(velocity: number, distance: bigint): number {
149
+ const v = BigInt(velocity || 1)
150
+ return clampLaunchResult(distance / (v * PRECISION_BIGINT))
151
+ }
152
+
153
+ function calcLaunchEnergy(drain: number, mass: bigint, distance: bigint): number {
154
+ const e =
155
+ saturatingMul(saturatingMul(mass, distance / PRECISION_BIGINT), BigInt(drain)) /
156
+ ENERGY_DIVISOR
157
+ return clampEnergyResult(e)
158
+ }
159
+
160
+ function calcMaxReach(energyBudget: bigint, mass: bigint, drain: number): bigint {
161
+ if (energyBudget < 1n) return 0n
162
+ if (energyBudget >= UINT32_MAX_BIGINT || mass === 0n || drain === 0) return UINT64_MAX
163
+
164
+ const numerator = (energyBudget + 1n) * ENERGY_DIVISOR - 1n
165
+ const denominator = mass * BigInt(drain)
166
+ const distanceUnits = numerator / denominator
167
+ const maxDistance = distanceUnits * PRECISION_BIGINT + (PRECISION_BIGINT - 1n)
168
+ return maxDistance > UINT64_MAX ? UINT64_MAX : maxDistance
169
+ }
16
170
 
17
171
  export type EntityRefInput = {
18
172
  entityType: NameType
19
173
  entityId: UInt64Type
20
174
  }
21
175
 
176
+ export type WaypointInput = {x: Int64Type; y: Int64Type}
177
+
22
178
  export class ActionsManager extends BaseManager {
179
+ private tokenContracts = new Map<string, TokenContract.Contract>()
180
+
23
181
  travel(shipId: UInt64Type, destination: CoordinatesType, recharge = true): Action {
24
182
  const x = Int64.from(destination.x)
25
183
  const y = Int64.from(destination.y)
26
184
 
27
185
  return this.server.action('travel', {
28
- entity_type: EntityType.SHIP,
29
186
  id: UInt64.from(shipId),
30
187
  x,
31
188
  y,
@@ -33,13 +190,17 @@ export class ActionsManager extends BaseManager {
33
190
  })
34
191
  }
35
192
 
36
- grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
37
- const entityRefs = entities.map((e) =>
193
+ private entityRefs(entities: EntityRefInput[]) {
194
+ return entities.map((e) =>
38
195
  ServerContract.Types.entity_ref.from({
39
196
  entity_type: e.entityType,
40
197
  entity_id: UInt64.from(e.entityId),
41
198
  })
42
199
  )
200
+ }
201
+
202
+ grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
203
+ const entityRefs = this.entityRefs(entities)
43
204
  const x = Int64.from(destination.x)
44
205
  const y = Int64.from(destination.y)
45
206
 
@@ -51,13 +212,58 @@ export class ActionsManager extends BaseManager {
51
212
  })
52
213
  }
53
214
 
54
- resolve(
55
- entityId: UInt64Type,
56
- entityType: EntityTypeName = EntityType.SHIP,
57
- count?: UInt64Type
215
+ travelplan(entities: EntityRefInput[], waypoints: WaypointInput[], recharge = true): Action {
216
+ const entityRefs = this.entityRefs(entities)
217
+ const wps = waypoints.map((w) =>
218
+ ServerContract.Types.route_waypoint.from({x: Int64.from(w.x), y: Int64.from(w.y)})
219
+ )
220
+ return this.server.action('travelplan', {
221
+ entities: entityRefs,
222
+ waypoints: wps,
223
+ recharge,
224
+ })
225
+ }
226
+
227
+ transit(shipId: UInt64Type, entrance: CoordinatesType, exit: CoordinatesType): Action {
228
+ return this.server.action('transit', {
229
+ id: UInt64.from(shipId),
230
+ ax: Int64.from(entrance.x),
231
+ ay: Int64.from(entrance.y),
232
+ bx: Int64.from(exit.x),
233
+ by: Int64.from(exit.y),
234
+ })
235
+ }
236
+
237
+ grouptransit(
238
+ entities: EntityRefInput[],
239
+ entrance: CoordinatesType,
240
+ exit: CoordinatesType
58
241
  ): Action {
242
+ const entityRefs = this.entityRefs(entities)
243
+ return this.server.action('grouptransit', {
244
+ entities: entityRefs,
245
+ ax: Int64.from(entrance.x),
246
+ ay: Int64.from(entrance.y),
247
+ bx: Int64.from(exit.x),
248
+ by: Int64.from(exit.y),
249
+ })
250
+ }
251
+
252
+ getwormhole(x: Int64Type, y: Int64Type): Action {
253
+ return this.server.action('getwormhole', {x: Int64.from(x), y: Int64.from(y)})
254
+ }
255
+
256
+ getdistance(origin: CoordinatesType, destination: CoordinatesType): Action {
257
+ return this.server.action('getdistance', {
258
+ ax: Int64.from(origin.x),
259
+ ay: Int64.from(origin.y),
260
+ bx: Int64.from(destination.x),
261
+ by: Int64.from(destination.y),
262
+ })
263
+ }
264
+
265
+ resolve(entityId: UInt64Type, count?: UInt64Type): Action {
59
266
  const params: ServerContract.ActionParams.resolve = {
60
- entity_type: entityType,
61
267
  id: UInt64.from(entityId),
62
268
  }
63
269
  if (count !== undefined) {
@@ -66,42 +272,163 @@ export class ActionsManager extends BaseManager {
66
272
  return this.server.action('resolve', params)
67
273
  }
68
274
 
69
- cancel(
70
- entityId: UInt64Type,
71
- count: UInt64Type,
72
- entityType: EntityTypeName = EntityType.SHIP
73
- ): Action {
275
+ resolveall(owner: NameType): Action {
276
+ return this.server.action('resolveall', {
277
+ owner: Name.from(owner),
278
+ })
279
+ }
280
+
281
+ cancel(entityId: UInt64Type, laneKey: number, count: UInt64Type): Action {
74
282
  return this.server.action('cancel', {
75
- entity_type: entityType,
76
283
  id: UInt64.from(entityId),
284
+ lane_key: UInt8.from(laneKey),
77
285
  count: UInt64.from(count),
78
286
  })
79
287
  }
80
288
 
81
- recharge(entityId: UInt64Type, entityType: EntityTypeName = EntityType.SHIP): Action {
289
+ recharge(entityId: UInt64Type): Action {
82
290
  return this.server.action('recharge', {
83
- entity_type: entityType,
84
291
  id: UInt64.from(entityId),
85
292
  })
86
293
  }
87
294
 
88
- transfer(
89
- sourceType: EntityTypeName,
90
- sourceId: UInt64Type,
91
- destType: EntityTypeName,
92
- destId: UInt64Type,
295
+ rename(entityId: UInt64Type, name: string): Action {
296
+ return this.server.action('rename', {
297
+ id: UInt64.from(entityId),
298
+ name,
299
+ })
300
+ }
301
+
302
+ refrshentity(entityId: UInt64Type): Action {
303
+ return this.server.action('refrshentity', {
304
+ entity_id: UInt64.from(entityId),
305
+ })
306
+ }
307
+
308
+ load(
309
+ id: UInt64Type,
310
+ fromId: UInt64Type,
93
311
  items: ServerContract.ActionParams.Type.cargo_item[]
94
312
  ): Action {
95
- const cargoItems = items.map((i) => ServerContract.Types.cargo_item.from(i))
96
- return this.server.action('transfer', {
97
- source_type: sourceType,
98
- source_id: UInt64.from(sourceId),
99
- dest_type: destType,
100
- dest_id: UInt64.from(destId),
101
- items: cargoItems,
313
+ return this.server.action('load', {
314
+ id: UInt64.from(id),
315
+ from_id: UInt64.from(fromId),
316
+ items,
317
+ })
318
+ }
319
+
320
+ unload(
321
+ id: UInt64Type,
322
+ toId: UInt64Type,
323
+ items: ServerContract.ActionParams.Type.cargo_item[]
324
+ ): Action {
325
+ return this.server.action('unload', {
326
+ id: UInt64.from(id),
327
+ to_id: UInt64.from(toId),
328
+ items,
329
+ })
330
+ }
331
+
332
+ depotstore(
333
+ shipId: UInt64Type,
334
+ depotId: UInt64Type,
335
+ items: ServerContract.ActionParams.Type.cargo_item[]
336
+ ): Action {
337
+ return this.server.action('depotstore', {
338
+ ship_id: UInt64.from(shipId),
339
+ depot_id: UInt64.from(depotId),
340
+ items,
102
341
  })
103
342
  }
104
343
 
344
+ depottake(
345
+ shipId: UInt64Type,
346
+ depotId: UInt64Type,
347
+ items: ServerContract.ActionParams.Type.cargo_item[]
348
+ ): Action {
349
+ return this.server.action('depottake', {
350
+ ship_id: UInt64.from(shipId),
351
+ depot_id: UInt64.from(depotId),
352
+ items,
353
+ })
354
+ }
355
+
356
+ shuttle(
357
+ carrierId: UInt64Type,
358
+ fromId: UInt64Type,
359
+ toId: UInt64Type,
360
+ items: ServerContract.ActionParams.Type.cargo_item[]
361
+ ): Action {
362
+ return this.server.action('shuttle', {
363
+ carrier: UInt64.from(carrierId),
364
+ from_id: UInt64.from(fromId),
365
+ to_id: UInt64.from(toId),
366
+ items,
367
+ })
368
+ }
369
+
370
+ civicshuttle(
371
+ buildingId: UInt64Type,
372
+ fromId: UInt64Type,
373
+ toId: UInt64Type,
374
+ items: ServerContract.ActionParams.Type.cargo_item[]
375
+ ): Action {
376
+ return this.server.action('civicshuttle', {
377
+ building: UInt64.from(buildingId),
378
+ from_id: UInt64.from(fromId),
379
+ to_id: UInt64.from(toId),
380
+ items,
381
+ })
382
+ }
383
+
384
+ cancelcivic(buildingId: UInt64Type, laneKey: UInt8Type, fromId: UInt64Type): Action {
385
+ return this.server.action('cancelcivic', {
386
+ building: UInt64.from(buildingId),
387
+ lane_key: UInt8.from(laneKey),
388
+ from_id: UInt64.from(fromId),
389
+ })
390
+ }
391
+
392
+ launch(
393
+ launcherId: UInt64Type,
394
+ catcherId: UInt64Type,
395
+ items: ServerContract.ActionParams.Type.cargo_item[]
396
+ ): Action {
397
+ return this.server.action('launch', {
398
+ launcher_id: UInt64.from(launcherId),
399
+ catcher_id: UInt64.from(catcherId),
400
+ items,
401
+ })
402
+ }
403
+
404
+ getLaunchQuote(
405
+ launcher: LaunchQuoteLauncher,
406
+ catcher: LaunchQuoteCatcher,
407
+ items: ServerContract.ActionParams.Type.cargo_item[],
408
+ start = new Date()
409
+ ): LaunchQuote {
410
+ const chargeRate = requiredNumber(
411
+ launcher.launcher.charge_rate ?? launcher.launcher.chargeRate,
412
+ 'launcher charge rate'
413
+ )
414
+ const velocity = requiredNumber(launcher.launcher.velocity, 'launcher velocity')
415
+ const drain = requiredNumber(launcher.launcher.drain, 'launcher drain')
416
+ const mass = calcPayloadMass(items)
417
+ const distance = calcDistance(launcher.coordinates, catcher.coordinates)
418
+ const chargeTime = calcChargeTime(chargeRate, mass)
419
+ const flightTime = calcFlightTime(velocity, distance)
420
+ const energyCost = calcLaunchEnergy(drain, mass, distance)
421
+ const maxReach = calcMaxReach(toBigInt(launcher.generator?.capacity), mass, drain)
422
+
423
+ return {
424
+ chargeTime,
425
+ flightTime,
426
+ arrival: new Date(start.getTime() + (chargeTime + flightTime) * 1000),
427
+ energyCost,
428
+ maxReach,
429
+ }
430
+ }
431
+
105
432
  foundCompany(account: NameType, name: string): Action {
106
433
  return this.platform.action('foundcompany', {
107
434
  account: Name.from(account),
@@ -116,35 +443,47 @@ export class ActionsManager extends BaseManager {
116
443
  }
117
444
 
118
445
  gather(
119
- source: EntityRefInput,
120
- destination: EntityRefInput,
446
+ sourceId: UInt64Type,
447
+ destinationId: UInt64Type,
121
448
  stratum: UInt16Type,
122
- quantity: UInt32Type
449
+ quantity: UInt32Type,
450
+ slot?: UInt8Type
123
451
  ): Action {
124
- return this.server.action('gather', {
125
- source: ServerContract.Types.entity_ref.from({
126
- entity_type: source.entityType,
127
- entity_id: UInt64.from(source.entityId),
128
- }),
129
- destination: ServerContract.Types.entity_ref.from({
130
- entity_type: destination.entityType,
131
- entity_id: UInt64.from(destination.entityId),
132
- }),
452
+ const params: ServerContract.ActionParams.gather = {
453
+ source_id: UInt64.from(sourceId),
454
+ destination_id: UInt64.from(destinationId),
133
455
  stratum: UInt16.from(stratum),
134
456
  quantity: UInt32.from(quantity),
135
- })
457
+ }
458
+ if (slot !== undefined) {
459
+ params.slot = UInt8.from(slot)
460
+ }
461
+ return this.server.action('gather', params)
136
462
  }
137
463
 
138
- warp(
139
- entityId: UInt64Type,
140
- destination: CoordinatesType,
141
- entityType: EntityTypeName = EntityType.SHIP
464
+ gatherplan(
465
+ sourceId: UInt64Type,
466
+ destinationId: UInt64Type,
467
+ stratum: UInt16Type,
468
+ quantity: UInt32Type,
469
+ recharge = true,
470
+ slots: number[] = []
142
471
  ): Action {
472
+ return this.server.action('gatherplan', {
473
+ source_id: UInt64.from(sourceId),
474
+ destination_id: UInt64.from(destinationId),
475
+ stratum: UInt16.from(stratum),
476
+ quantity: UInt32.from(quantity),
477
+ recharge,
478
+ slots: Bytes.from(slots),
479
+ })
480
+ }
481
+
482
+ warp(entityId: UInt64Type, destination: CoordinatesType): Action {
143
483
  const x = Int64.from(destination.x)
144
484
  const y = Int64.from(destination.y)
145
485
 
146
486
  return this.server.action('warp', {
147
- entity_type: entityType,
148
487
  id: UInt64.from(entityId),
149
488
  x,
150
489
  y,
@@ -152,116 +491,634 @@ export class ActionsManager extends BaseManager {
152
491
  }
153
492
 
154
493
  craft(
155
- entityType: EntityTypeName,
156
494
  entityId: UInt64Type,
157
495
  recipeId: number,
158
496
  quantity: number,
159
- inputs: ServerContract.ActionParams.Type.cargo_item[]
497
+ inputs: ServerContract.ActionParams.Type.cargo_item[],
498
+ target?: UInt64Type,
499
+ slot?: UInt8Type
160
500
  ): Action {
161
- const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
162
- return this.server.action('craft', {
163
- entity_type: entityType,
501
+ const params: ServerContract.ActionParams.craft = {
164
502
  id: UInt64.from(entityId),
165
503
  recipe_id: UInt16.from(recipeId),
166
504
  quantity: UInt32.from(quantity),
167
- inputs: cargoInputs,
168
- })
505
+ inputs,
506
+ }
507
+ if (target !== undefined) {
508
+ params.target = UInt64.from(target)
509
+ }
510
+ if (slot !== undefined) {
511
+ params.slot = UInt8.from(slot)
512
+ }
513
+ return this.server.action('craft', params)
514
+ }
515
+
516
+ craftjob(
517
+ shipId: UInt64Type,
518
+ workshopId: UInt64Type,
519
+ recipeId: UInt16Type,
520
+ quantity: UInt32Type,
521
+ inputs: ServerContract.ActionParams.Type.cargo_item[]
522
+ ): Action {
523
+ const params: ServerContract.ActionParams.craftjob = {
524
+ ship_id: UInt64.from(shipId),
525
+ workshop_id: UInt64.from(workshopId),
526
+ recipe_id: UInt16.from(recipeId),
527
+ quantity: UInt32.from(quantity),
528
+ inputs,
529
+ }
530
+ return this.server.action('craftjob', params)
531
+ }
532
+
533
+ cancelcraft(jobId: UInt64Type): Action {
534
+ const params: ServerContract.ActionParams.cancelcraft = {
535
+ job_id: UInt64.from(jobId),
536
+ }
537
+ return this.server.action('cancelcraft', params)
538
+ }
539
+
540
+ canceljob(route: JobCancelRoute): Action {
541
+ if (route.kind === 'dropoff') return this.cancel(route.shipId, route.laneKey, route.count)
542
+ if (route.kind === 'build') return this.cancelbuild(route.jobId)
543
+ return this.cancelcraft(route.jobId)
169
544
  }
170
545
 
171
- blend(
172
- entityType: EntityTypeName,
546
+ clustercraft(
173
547
  entityId: UInt64Type,
548
+ recipeId: number,
549
+ quantity: number,
550
+ sources: ServerContract.ActionParams.Type.cluster_source[],
551
+ target?: UInt64Type,
552
+ slot?: UInt8Type
553
+ ): Action {
554
+ const params: ServerContract.ActionParams.clustercraft = {
555
+ id: UInt64.from(entityId),
556
+ recipe_id: UInt16.from(recipeId),
557
+ quantity: UInt32.from(quantity),
558
+ sources,
559
+ }
560
+ if (target !== undefined) {
561
+ params.target = UInt64.from(target)
562
+ }
563
+ if (slot !== undefined) {
564
+ params.slot = UInt8.from(slot)
565
+ }
566
+ return this.server.action('clustercraft', params)
567
+ }
568
+
569
+ claimcraft(jobId: UInt64Type, shipId: UInt64Type): Action {
570
+ const params: ServerContract.ActionParams.claimcraft = {
571
+ job_id: UInt64.from(jobId),
572
+ ship_id: UInt64.from(shipId),
573
+ }
574
+ return this.server.action('claimcraft', params)
575
+ }
576
+
577
+ buildjob(
578
+ targetId: UInt64Type,
579
+ dockId: UInt64Type,
580
+ targetItemId: UInt16Type,
174
581
  inputs: ServerContract.ActionParams.Type.cargo_item[]
175
582
  ): Action {
176
- const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
583
+ const params: ServerContract.ActionParams.buildjob = {
584
+ target_id: UInt64.from(targetId),
585
+ dock_id: UInt64.from(dockId),
586
+ target_item_id: UInt16.from(targetItemId),
587
+ inputs,
588
+ }
589
+ return this.server.action('buildjob', params)
590
+ }
591
+
592
+ claimbuild(jobId: UInt64Type): Action {
593
+ const params: ServerContract.ActionParams.claimbuild = {
594
+ job_id: UInt64.from(jobId),
595
+ }
596
+ return this.server.action('claimbuild', params)
597
+ }
598
+
599
+ cancelbuild(jobId: UInt64Type): Action {
600
+ const params: ServerContract.ActionParams.cancelbuild = {
601
+ job_id: UInt64.from(jobId),
602
+ }
603
+ return this.server.action('cancelbuild', params)
604
+ }
605
+
606
+ blend(entityId: UInt64Type, inputs: ServerContract.ActionParams.Type.cargo_item[]): Action {
177
607
  return this.server.action('blend', {
178
- entity_type: entityType,
179
608
  id: UInt64.from(entityId),
180
- inputs: cargoInputs,
609
+ inputs,
181
610
  })
182
611
  }
183
612
 
184
613
  deploy(
185
- entityType: EntityTypeName,
186
614
  entityId: UInt64Type,
187
- ref: ServerContract.ActionParams.Type.cargo_ref
615
+ ref: ServerContract.ActionParams.Type.cargo_ref,
616
+ slot?: ClusterSlotType
188
617
  ): Action {
189
618
  return this.server.action('deploy', {
190
- entity_type: entityType,
191
619
  id: UInt64.from(entityId),
192
- ref: ServerContract.Types.cargo_ref.from(ref),
620
+ ref,
621
+ slot: slot ? {hub: UInt64.from(slot.hub), gx: slot.gx, gy: slot.gy} : undefined,
622
+ })
623
+ }
624
+
625
+ upgrade(
626
+ builderId: UInt64Type,
627
+ targetId: UInt64Type,
628
+ targetItemId: UInt16Type,
629
+ inputs: ServerContract.ActionParams.Type.cargo_item[],
630
+ slot?: UInt8Type
631
+ ): Action {
632
+ const params: ServerContract.ActionParams.upgrade = {
633
+ builder_id: UInt64.from(builderId),
634
+ target_id: UInt64.from(targetId),
635
+ target_item_id: UInt16.from(targetItemId),
636
+ inputs,
637
+ }
638
+ if (slot !== undefined) {
639
+ params.slot = UInt8.from(slot)
640
+ }
641
+ return this.server.action('upgrade', params)
642
+ }
643
+
644
+ claimplot(entityId: UInt64Type, targetItemId: UInt16Type, slot: ClusterSlotType): Action {
645
+ return this.server.action('claimplot', {
646
+ builder_id: UInt64.from(entityId),
647
+ target_item_id: UInt16.from(targetItemId),
648
+ slot: {hub: UInt64.from(slot.hub), gx: slot.gx, gy: slot.gy},
649
+ })
650
+ }
651
+
652
+ movetile(
653
+ hubId: UInt64Type,
654
+ fromGx: number,
655
+ fromGy: number,
656
+ toGx: number,
657
+ toGy: number
658
+ ): Action {
659
+ return this.server.action('movetile', {
660
+ hub_id: UInt64.from(hubId),
661
+ from_gx: fromGx,
662
+ from_gy: fromGy,
663
+ to_gx: toGx,
664
+ to_gy: toGy,
665
+ })
666
+ }
667
+
668
+ swaptile(hubId: UInt64Type, aGx: number, aGy: number, bGx: number, bGy: number): Action {
669
+ return this.server.action('swaptile', {
670
+ hub_id: UInt64.from(hubId),
671
+ a_gx: aGx,
672
+ a_gy: aGy,
673
+ b_gx: bGx,
674
+ b_gy: bGy,
675
+ })
676
+ }
677
+
678
+ buildplot(entityId: UInt64Type, plotId: UInt64Type): Action {
679
+ return this.server.action('buildplot', {
680
+ builder_id: UInt64.from(entityId),
681
+ plot_id: UInt64.from(plotId),
682
+ })
683
+ }
684
+
685
+ abandonplot(plotId: UInt64Type): Action {
686
+ return this.server.action('abandonplot', {
687
+ plot_id: UInt64.from(plotId),
193
688
  })
194
689
  }
195
690
 
196
691
  addmodule(
197
- entityType: EntityTypeName,
198
692
  entityId: UInt64Type,
199
693
  moduleIndex: number,
200
694
  moduleRef: ServerContract.ActionParams.Type.cargo_ref,
201
695
  targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
202
696
  ): Action {
203
697
  return this.server.action('addmodule', {
204
- entity_type: entityType,
205
698
  entity_id: UInt64.from(entityId),
206
699
  module_index: moduleIndex,
207
- module_ref: ServerContract.Types.cargo_ref.from(moduleRef),
208
- target_ref: targetRef ? ServerContract.Types.cargo_ref.from(targetRef) : null,
700
+ module_ref: moduleRef,
701
+ target_ref: targetRef ?? undefined,
209
702
  })
210
703
  }
211
704
 
212
705
  rmmodule(
213
- entityType: EntityTypeName,
214
706
  entityId: UInt64Type,
215
707
  moduleIndex: number,
216
708
  targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
217
709
  ): Action {
218
710
  return this.server.action('rmmodule', {
219
- entity_type: entityType,
220
711
  entity_id: UInt64.from(entityId),
221
712
  module_index: moduleIndex,
222
- target_ref: targetRef ? ServerContract.Types.cargo_ref.from(targetRef) : null,
713
+ target_ref: targetRef ?? undefined,
223
714
  })
224
715
  }
225
716
 
226
- wrap(
227
- owner: NameType,
228
- entityType: EntityTypeName,
717
+ swapmodule(
229
718
  entityId: UInt64Type,
230
- items: ServerContract.ActionParams.Type.cargo_item[]
719
+ moduleIndex: number,
720
+ moduleRef: ServerContract.ActionParams.Type.cargo_ref
231
721
  ): Action {
232
- const cargoItems = items.map((i) => ServerContract.Types.cargo_item.from(i))
233
- return this.server.action('wrap', {
234
- owner: Name.from(owner),
235
- entity_type: entityType,
722
+ return this.server.action('swapmodule', {
236
723
  entity_id: UInt64.from(entityId),
237
- items: cargoItems,
724
+ module_index: moduleIndex,
725
+ module_ref: moduleRef,
726
+ })
727
+ }
728
+
729
+ open(owner: NameType, tokenContract: NameType, tokenSymbol: Asset.SymbolType): Action {
730
+ return this.platform.action('open', {
731
+ owner: Name.from(owner),
732
+ token_contract: Name.from(tokenContract),
733
+ token_symbol: Asset.Symbol.from(tokenSymbol),
238
734
  })
239
735
  }
240
736
 
241
- undeploy(host: EntityRefInput, target: EntityRefInput): Action {
737
+ close(owner: NameType, tokenContract: NameType, tokenSymbol: Asset.SymbolType): Action {
738
+ return this.platform.action('close', {
739
+ owner: Name.from(owner),
740
+ token_contract: Name.from(tokenContract),
741
+ token_symbol: Asset.Symbol.from(tokenSymbol),
742
+ })
743
+ }
744
+
745
+ withdraw(
746
+ owner: NameType,
747
+ quantity: AssetType,
748
+ tokenContract: NameType,
749
+ memo = 'withdraw'
750
+ ): Action {
751
+ return this.platform.action('withdraw', {
752
+ owner: Name.from(owner),
753
+ quantity: ExtendedAsset.from({
754
+ quantity: Asset.from(quantity),
755
+ contract: Name.from(tokenContract),
756
+ }),
757
+ memo,
758
+ })
759
+ }
760
+
761
+ tokenContract(account: NameType): TokenContract.Contract {
762
+ const name = Name.from(account)
763
+ const key = String(name)
764
+ let contract = this.tokenContracts.get(key)
765
+ if (!contract) {
766
+ contract = new TokenContract.Contract({client: this.client, account: name})
767
+ this.tokenContracts.set(key, contract)
768
+ }
769
+ return contract
770
+ }
771
+
772
+ tokenTransfer(
773
+ from: NameType,
774
+ to: NameType,
775
+ quantity: AssetType,
776
+ tokenContract: NameType,
777
+ memo = ''
778
+ ): Action {
779
+ return this.tokenContract(tokenContract).action('transfer', {
780
+ from: Name.from(from),
781
+ to: Name.from(to),
782
+ quantity: Asset.from(quantity),
783
+ memo,
784
+ })
785
+ }
786
+
787
+ // `open` is an idempotent no-op; omitting it is what produces the "call open first" abort.
788
+ deposit(
789
+ owner: NameType,
790
+ quantity: AssetType,
791
+ tokenContract: NameType,
792
+ opts: {memo?: string; open?: boolean} = {}
793
+ ): Action[] {
794
+ const amount = Asset.from(quantity)
795
+ const actions: Action[] = []
796
+ if (opts.open !== false) {
797
+ actions.push(this.open(owner, tokenContract, amount.symbol))
798
+ }
799
+ actions.push(
800
+ this.tokenTransfer(
801
+ owner,
802
+ this.platform.account,
803
+ amount,
804
+ tokenContract,
805
+ opts.memo ?? 'deposit'
806
+ )
807
+ )
808
+ return actions
809
+ }
810
+
811
+ async wrap(
812
+ owner: NameType,
813
+ entityId: UInt64Type,
814
+ nexusId: UInt64Type,
815
+ cargoId: UInt64Type,
816
+ quantity: UInt64Type,
817
+ opts: {claimRam?: boolean} = {}
818
+ ): Promise<Action[]> {
819
+ const actions: Action[] = [
820
+ this.platform.action('wrapcargo', {
821
+ game: this.server.account,
822
+ owner: Name.from(owner),
823
+ entity_id: UInt64.from(entityId),
824
+ nexus_id: UInt64.from(nexusId),
825
+ cargo_id: UInt64.from(cargoId),
826
+ quantity: UInt64.from(quantity),
827
+ }),
828
+ ]
829
+ // setlastpayer is what fires logrampayer and clears the wrap gate; skipping it strands it.
830
+ const claimRam = opts.claimRam ?? true
831
+ if (claimRam) {
832
+ actions.push(this.setLastPayer(owner, SHIPLOAD_COLLECTION))
833
+ }
834
+ return actions
835
+ }
836
+
837
+ undeploy(hostId: UInt64Type, targetId: UInt64Type): Action {
242
838
  return this.server.action('undeploy', {
243
- host_type: Name.from(host.entityType),
244
- host_id: UInt64.from(host.entityId),
245
- target_type: Name.from(target.entityType),
246
- target_id: UInt64.from(target.entityId),
839
+ host_id: UInt64.from(hostId),
840
+ target_id: UInt64.from(targetId),
247
841
  })
248
842
  }
249
843
 
250
- wrapEntity(entity: EntityRefInput): Action {
251
- return this.server.action('wrapentity', {
252
- entity_type: Name.from(entity.entityType),
253
- entity_id: UInt64.from(entity.entityId),
844
+ claimStarter(owner: NameType): Action {
845
+ return this.server.action('claimstarter', {
846
+ owner: Name.from(owner),
254
847
  })
255
848
  }
256
849
 
257
- demolish(entity: EntityRefInput): Action {
850
+ async wrapEntity(
851
+ owner: NameType,
852
+ entityId: UInt64Type,
853
+ nexusId: UInt64Type,
854
+ opts: {claimRam?: boolean} = {}
855
+ ): Promise<Action[]> {
856
+ const actions: Action[] = [
857
+ this.platform.action('wrapentity', {
858
+ game: this.server.account,
859
+ owner: Name.from(owner),
860
+ entity_id: UInt64.from(entityId),
861
+ nexus_id: UInt64.from(nexusId),
862
+ }),
863
+ ]
864
+ // setlastpayer is what fires logrampayer and clears the wrap gate; skipping it strands it.
865
+ const claimRam = opts.claimRam ?? true
866
+ if (claimRam) {
867
+ actions.push(this.setLastPayer(owner, SHIPLOAD_COLLECTION))
868
+ }
869
+ return actions
870
+ }
871
+
872
+ setunwrapmin(assetId: UInt64Type): Action {
873
+ return this.server.action('setunwrapmin', {
874
+ asset_id: UInt64.from(assetId),
875
+ })
876
+ }
877
+
878
+ placecargo(owner: NameType, hostId: UInt64Type, assetId: UInt64Type): Action {
879
+ return this.server.action('placecargo', {
880
+ owner: Name.from(owner),
881
+ host_id: UInt64.from(hostId),
882
+ asset_id: UInt64.from(assetId),
883
+ })
884
+ }
885
+
886
+ placeentity(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action {
887
+ return this.server.action('placeentity', {
888
+ owner: Name.from(owner),
889
+ asset_id: UInt64.from(assetId),
890
+ target_nexus_id: UInt64.from(targetNexusId),
891
+ })
892
+ }
893
+
894
+ transferForUnwrap(owner: NameType, assetId: UInt64Type): Action {
895
+ return Action.from(
896
+ {
897
+ account: this.atomicAssetsAccount,
898
+ name: 'transfer',
899
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
900
+ data: {
901
+ from: Name.from(owner),
902
+ to: this.platform.account,
903
+ asset_ids: [UInt64.from(assetId)],
904
+ memo: 'unwrap',
905
+ },
906
+ },
907
+ ATOMICASSETS_ABI
908
+ )
909
+ }
910
+
911
+ sendAsset(owner: NameType, recipient: NameType, assetId: UInt64Type, memo = ''): Action {
912
+ return Action.from(
913
+ {
914
+ account: this.atomicAssetsAccount,
915
+ name: 'transfer',
916
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
917
+ data: {
918
+ from: Name.from(owner),
919
+ to: Name.from(recipient),
920
+ asset_ids: [UInt64.from(assetId)],
921
+ memo,
922
+ },
923
+ },
924
+ ATOMICASSETS_ABI
925
+ )
926
+ }
927
+
928
+ // Two top-level actions the wallet signs to unwrap an NFT into a host's cargo.
929
+ unwrapCargoTx(owner: NameType, assetId: UInt64Type, hostId: UInt64Type): Action[] {
930
+ return [this.transferForUnwrap(owner, assetId), this.placecargo(owner, hostId, assetId)]
931
+ }
932
+
933
+ // Two top-level actions the wallet signs to place an entity NFT at a nexus.
934
+ unwrapEntityTx(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action[] {
935
+ return [
936
+ this.transferForUnwrap(owner, assetId),
937
+ this.placeentity(owner, assetId, targetNexusId),
938
+ ]
939
+ }
940
+
941
+ setRamPayer(newPayer: NameType, assetId: UInt64Type): Action {
942
+ return Action.from(
943
+ {
944
+ account: this.atomicAssetsAccount,
945
+ name: 'setrampayer',
946
+ authorization: [{actor: Name.from(newPayer), permission: 'active'}],
947
+ data: {new_payer: Name.from(newPayer), asset_id: UInt64.from(assetId)},
948
+ },
949
+ ATOMICASSETS_ABI
950
+ )
951
+ }
952
+
953
+ setLastPayer(owner: NameType, collectionName: NameType): Action {
954
+ return Action.from(
955
+ {
956
+ account: this.atomicAssetsAccount,
957
+ name: 'setlastpayer',
958
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
959
+ data: {owner: Name.from(owner), collection_name: Name.from(collectionName)},
960
+ },
961
+ ATOMICASSETS_ABI
962
+ )
963
+ }
964
+
965
+ demolish(entityId: UInt64Type): Action {
258
966
  return this.server.action('demolish', {
259
- entity_type: Name.from(entity.entityType),
260
- entity_id: UInt64.from(entity.entityId),
967
+ entity_id: UInt64.from(entityId),
261
968
  })
262
969
  }
263
970
 
264
971
  joinGame(account: NameType, companyName: string): Action[] {
265
972
  return [this.foundCompany(account, companyName), this.join(account)]
266
973
  }
974
+
975
+ commit(oracleId: NameType, epoch: UInt64Type, commit: Checksum256Type): Action {
976
+ return this.server.action('commit', {
977
+ oracle_id: Name.from(oracleId),
978
+ epoch: UInt64.from(epoch),
979
+ commit: Checksum256.from(commit),
980
+ })
981
+ }
982
+
983
+ reveal(oracleId: NameType, epoch: UInt64Type, reveal: Checksum256Type): Action {
984
+ return this.server.action('reveal', {
985
+ oracle_id: Name.from(oracleId),
986
+ epoch: UInt64.from(epoch),
987
+ reveal: Checksum256.from(reveal),
988
+ })
989
+ }
990
+
991
+ addoracle(oracleId: NameType): Action {
992
+ return this.server.action('addoracle', {
993
+ oracle_id: Name.from(oracleId),
994
+ })
995
+ }
996
+
997
+ removeoracle(oracleId: NameType): Action {
998
+ return this.server.action('removeoracle', {
999
+ oracle_id: Name.from(oracleId),
1000
+ })
1001
+ }
1002
+
1003
+ setthreshold(threshold: UInt8Type): Action {
1004
+ return this.server.action('setthreshold', {
1005
+ threshold: UInt8.from(threshold),
1006
+ })
1007
+ }
1008
+
1009
+ setdeadline(deadline: UInt32Type): Action {
1010
+ return this.server.action('setdeadline', {
1011
+ deadline: UInt32.from(deadline),
1012
+ })
1013
+ }
1014
+
1015
+ closeepoch(epoch: UInt64Type): Action {
1016
+ return this.server.action('closeepoch', {
1017
+ epoch: UInt64.from(epoch),
1018
+ })
1019
+ }
1020
+
1021
+ cleanrsvp(epoch: UInt64Type, maxRows: UInt64Type): Action {
1022
+ return this.server.action('cleanrsvp', {
1023
+ epoch: UInt64.from(epoch),
1024
+ max_rows: UInt64.from(maxRows),
1025
+ })
1026
+ }
1027
+
1028
+ addFundToken(tokenContract: NameType, tokenSymbol: Asset.SymbolType): Action {
1029
+ return this.fund.action('addtoken', {
1030
+ token_contract: Name.from(tokenContract),
1031
+ token_symbol: Asset.Symbol.from(tokenSymbol),
1032
+ })
1033
+ }
1034
+
1035
+ removeFundToken(tokenContract: NameType): Action {
1036
+ return this.fund.action('deltoken', {
1037
+ token_contract: Name.from(tokenContract),
1038
+ })
1039
+ }
1040
+
1041
+ collectFund(): Action {
1042
+ return this.fund.action('collect', {})
1043
+ }
1044
+
1045
+ found(player: NameType, entityId: UInt64Type, location: CoordinatesType): Action {
1046
+ return this.server.action('found', {
1047
+ player: Name.from(player),
1048
+ entity_id: UInt64.from(entityId),
1049
+ x: Int64.from(location.x),
1050
+ y: Int64.from(location.y),
1051
+ })
1052
+ }
1053
+
1054
+ naturalize(player: NameType, location: CoordinatesType): Action {
1055
+ return this.server.action('naturalize', {
1056
+ player: Name.from(player),
1057
+ x: Int64.from(location.x),
1058
+ y: Int64.from(location.y),
1059
+ })
1060
+ }
1061
+
1062
+ contribute(
1063
+ player: NameType,
1064
+ entityId: UInt64Type,
1065
+ location: CoordinatesType,
1066
+ bundle: ServerContract.ActionParams.Type.cargo_item[]
1067
+ ): Action {
1068
+ return this.platform.action('contribute', {
1069
+ game: this.server.account,
1070
+ player: Name.from(player),
1071
+ entity_id: UInt64.from(entityId),
1072
+ x: Int64.from(location.x),
1073
+ y: Int64.from(location.y),
1074
+ bundle,
1075
+ })
1076
+ }
1077
+
1078
+ // addcontrib asserts the citizenship rows exist, so naturalize must precede contribute.
1079
+ firstContribution(
1080
+ player: NameType,
1081
+ entityId: UInt64Type,
1082
+ location: CoordinatesType,
1083
+ bundle: ServerContract.ActionParams.Type.cargo_item[]
1084
+ ): Action[] {
1085
+ return [
1086
+ this.naturalize(player, location),
1087
+ this.contribute(player, entityId, location, bundle),
1088
+ ]
1089
+ }
1090
+
1091
+ mintready(maxMints?: UInt32Type): Action {
1092
+ const params: {max_mints?: UInt32} = {}
1093
+ if (maxMints !== undefined) {
1094
+ params.max_mints = UInt32.from(maxMints)
1095
+ }
1096
+ return this.server.action('mintready', params)
1097
+ }
1098
+
1099
+ charterready(location: CoordinatesType): Action {
1100
+ return this.server.action('charterready', {
1101
+ x: Int64.from(location.x),
1102
+ y: Int64.from(location.y),
1103
+ })
1104
+ }
1105
+
1106
+ castballot(player: NameType, ballotId: UInt64Type, picks: number[]): Action {
1107
+ return this.server.action('castballot', {
1108
+ player,
1109
+ ballot_id: UInt64.from(ballotId),
1110
+ picks: picks.map((pick) => UInt32.from(pick)),
1111
+ })
1112
+ }
1113
+
1114
+ settleballot(ballotId: UInt64Type, maxPages: UInt32Type = UInt32.from(0)): Action {
1115
+ return this.server.action('settleballot', {
1116
+ ballot_id: UInt64.from(ballotId),
1117
+ max_pages: UInt32.from(maxPages),
1118
+ })
1119
+ }
1120
+
1121
+ voteready(maxPages: UInt32Type = UInt32.from(0)): Action {
1122
+ return this.server.action('voteready', {max_pages: UInt32.from(maxPages)})
1123
+ }
267
1124
  }