@shipload/sdk 1.0.0-next.62 → 1.0.0-next.64

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 (62) hide show
  1. package/lib/shipload.d.ts +1829 -501
  2. package/lib/shipload.js +4325 -1324
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +4286 -1389
  5. package/lib/shipload.m.js.map +1 -1
  6. package/lib/testing.d.ts +391 -13
  7. package/lib/testing.js +1692 -107
  8. package/lib/testing.js.map +1 -1
  9. package/lib/testing.m.js +1693 -108
  10. package/lib/testing.m.js.map +1 -1
  11. package/package.json +2 -2
  12. package/src/contracts/fund.ts +201 -0
  13. package/src/contracts/platform.ts +73 -1
  14. package/src/contracts/server.ts +946 -26
  15. package/src/contracts/token.ts +170 -0
  16. package/src/contracts.ts +2 -0
  17. package/src/data/catalog.test.ts +19 -0
  18. package/src/data/catalog.ts +6 -0
  19. package/src/data/charters.json +198 -0
  20. package/src/data/citizenry-adjectives.json +42 -0
  21. package/src/data/citizenry-nouns.json +50 -0
  22. package/src/data/entities.json +36 -0
  23. package/src/data/item-ids.ts +2 -0
  24. package/src/data/items.json +12 -0
  25. package/src/data/kind-registry.json +20 -3
  26. package/src/data/kind-registry.ts +5 -0
  27. package/src/data/metadata.ts +14 -0
  28. package/src/data/recipes.json +0 -48
  29. package/src/derivation/capabilities.ts +14 -0
  30. package/src/derivation/recipe-usage.test.ts +0 -2
  31. package/src/format.ts +9 -0
  32. package/src/index-module.ts +32 -2
  33. package/src/influence/categories.ts +32 -0
  34. package/src/influence/charters.test.ts +126 -0
  35. package/src/influence/charters.ts +120 -0
  36. package/src/influence/citizenry.ts +38 -0
  37. package/src/influence/constants.ts +63 -0
  38. package/src/influence/decay.ts +20 -0
  39. package/src/influence/decomp.ts +95 -0
  40. package/src/influence/demand.ts +106 -0
  41. package/src/influence/duration.ts +36 -0
  42. package/src/influence/index.ts +63 -0
  43. package/src/influence/influence.test.ts +317 -0
  44. package/src/influence/quality.ts +25 -0
  45. package/src/influence/valuation.ts +154 -0
  46. package/src/managers/actions.ts +227 -5
  47. package/src/managers/balances.test.ts +161 -0
  48. package/src/managers/balances.ts +93 -0
  49. package/src/managers/construction.ts +11 -1
  50. package/src/managers/context.ts +18 -0
  51. package/src/managers/entities.ts +11 -0
  52. package/src/managers/index.ts +15 -1
  53. package/src/managers/influence.test.ts +58 -0
  54. package/src/managers/influence.ts +347 -0
  55. package/src/managers/nft.test.ts +8 -1
  56. package/src/managers/nft.ts +56 -16
  57. package/src/nft/description.ts +7 -0
  58. package/src/scheduling/task-cargo.ts +1 -0
  59. package/src/shipload.ts +10 -0
  60. package/src/types.ts +23 -4
  61. package/src/utils/hash.ts +4 -0
  62. package/src/utils/system.ts +1 -5
package/src/shipload.ts CHANGED
@@ -12,7 +12,9 @@ import type {EpochsManager} from './managers/epochs'
12
12
  import type {ActionsManager} from './managers/actions'
13
13
  import type {ClusterManager} from './managers/cluster'
14
14
  import type {NftManager} from './managers/nft'
15
+ import type {BalancesManager} from './managers/balances'
15
16
  import type {JobsManager} from './managers/jobs'
17
+ import type {InfluenceManager} from './managers/influence'
16
18
  import type {SubscriptionsManager} from './subscriptions/manager'
17
19
  import type {GameState} from './entities/gamestate'
18
20
 
@@ -133,10 +135,18 @@ export class Shipload {
133
135
  return this._context.nft
134
136
  }
135
137
 
138
+ get balances(): BalancesManager {
139
+ return this._context.balances
140
+ }
141
+
136
142
  get jobs(): JobsManager {
137
143
  return this._context.jobs
138
144
  }
139
145
 
146
+ get influence(): InfluenceManager {
147
+ return this._context.influence
148
+ }
149
+
140
150
  get subscriptions(): SubscriptionsManager {
141
151
  return this._context.subscriptions
142
152
  }
package/src/types.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  type UInt64Type,
9
9
  } from '@wharfkit/antelope'
10
10
  import {ServerContract} from './contracts'
11
+ import {COORD_MAX, COORD_MIN} from './coordinates/constants'
11
12
 
12
13
  export const PRECISION = 10000
13
14
  export const CRAFT_ENERGY_DIVISOR = 150000
@@ -70,6 +71,7 @@ export enum TaskType {
70
71
  UPGRADE = 17,
71
72
  SHUTTLE = 18,
72
73
  REFIT = 19,
74
+ CONTRIBUTE = 20,
73
75
  }
74
76
 
75
77
  export enum RefitOp {
@@ -124,13 +126,30 @@ export class Coordinates extends ServerContract.Types.coordinates {
124
126
 
125
127
  export function coordsToLocationId(coords: CoordinatesType): UInt64 {
126
128
  const c = Coordinates.from(coords)
127
- const mask = BigInt(0xffffffff)
128
- const x = BigInt(c.x.toNumber()) & mask
129
- const y = BigInt(c.y.toNumber()) & mask
130
- const id = (x << BigInt(32)) | y
129
+ const x = BigInt(c.x.toString())
130
+ const y = BigInt(c.y.toString())
131
+ if (
132
+ x < BigInt(COORD_MIN) ||
133
+ x > BigInt(COORD_MAX) ||
134
+ y < BigInt(COORD_MIN) ||
135
+ y > BigInt(COORD_MAX)
136
+ ) {
137
+ throw new Error('coordinate out of int32 bounds')
138
+ }
139
+ const offset = BigInt(2147483648)
140
+ const id = ((x + offset) << BigInt(32)) | (y + offset)
131
141
  return UInt64.from(id)
132
142
  }
133
143
 
144
+ export function locationIdToCoords(id: UInt64Type): {x: number; y: number} {
145
+ const value = BigInt(UInt64.from(id).toString())
146
+ const offset = BigInt(2147483648)
147
+ return {
148
+ x: Number((value >> BigInt(32)) - offset),
149
+ y: Number((value & BigInt('0xffffffff')) - offset),
150
+ }
151
+ }
152
+
134
153
  export interface Distance {
135
154
  origin: ServerContract.ActionParams.Type.coordinates
136
155
  destination: ServerContract.ActionParams.Type.coordinates
package/src/utils/hash.ts CHANGED
@@ -9,3 +9,7 @@ export function hash512(seed: Checksum256Type, string: string): Checksum512 {
9
9
  const bytes = Bytes.from(`${seed}${string}`, 'utf8')
10
10
  return Checksum512.hash(bytes)
11
11
  }
12
+
13
+ export function uint16(hash: Checksum512, offset: number): number {
14
+ return (hash.array[offset] << 8) | hash.array[offset + 1]
15
+ }
@@ -1,5 +1,5 @@
1
1
  import {Checksum256, type Checksum256Type, type Checksum512, UInt8} from '@wharfkit/antelope'
2
- import {hash512} from './hash'
2
+ import {hash512, uint16} from './hash'
3
3
  import {Coordinates, type CoordinatesType, LocationType} from '../types'
4
4
  import {ServerContract} from '../contracts'
5
5
  import {deriveLocationSize} from '../derivation/location-size'
@@ -47,10 +47,6 @@ export function getLocationTypeName(type: LocationType): string {
47
47
  }
48
48
  }
49
49
 
50
- function uint16(hash: Checksum512, offset: number): number {
51
- return (hash.array[offset] << 8) | hash.array[offset + 1]
52
- }
53
-
54
50
  function generatePlanetName(hashResult: Checksum512): string {
55
51
  const syllableCount = 2 + (hashResult.array[0] % 2)
56
52
  const name: string[] = []