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

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