@shipload/sdk 1.0.0-next.71 → 1.0.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/shipload.d.ts +41 -21
- package/lib/shipload.js +517 -348
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +510 -345
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +1 -6
- package/lib/testing.js +59 -43
- package/lib/testing.js.map +1 -1
- package/lib/testing.m.js +59 -43
- package/lib/testing.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +3 -17
- package/src/data/capability-formulas.ts +4 -4
- package/src/data/entities.json +84 -68
- package/src/data/item-ids.ts +5 -4
- package/src/data/items.json +30 -24
- package/src/data/kind-registry.json +75 -39
- package/src/data/kind-registry.ts +13 -0
- package/src/data/metadata.ts +35 -0
- package/src/data/recipes.json +194 -155
- package/src/derivation/build-methods.test.ts +4 -4
- package/src/derivation/capabilities.test.ts +14 -10
- package/src/derivation/capabilities.ts +8 -10
- package/src/derivation/capability-mappings.ts +4 -4
- package/src/derivation/capacity-fn-registry.test.ts +9 -0
- package/src/derivation/capacity-fn-registry.ts +18 -0
- package/src/derivation/recipe-usage.test.ts +7 -11
- package/src/index-module.ts +6 -0
- package/src/influence/influence.test.ts +1 -1
- package/src/managers/actions.ts +5 -0
- package/src/managers/context.ts +9 -0
- package/src/managers/fund.ts +49 -0
- package/src/managers/index.ts +3 -0
- package/src/nft/description.ts +5 -10
- package/src/resolution/resolve-item.test.ts +15 -10
- package/src/shipload.ts +5 -0
package/src/managers/context.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {ActionsManager} from './actions'
|
|
|
13
13
|
import {ClusterManager} from './cluster'
|
|
14
14
|
import {NftManager} from './nft'
|
|
15
15
|
import {BalancesManager} from './balances'
|
|
16
|
+
import {FundManager} from './fund'
|
|
16
17
|
import {JobsManager} from './jobs'
|
|
17
18
|
import {InfluenceManager} from './influence'
|
|
18
19
|
import {SubscriptionsManager} from '../subscriptions/manager'
|
|
@@ -27,6 +28,7 @@ export class GameContext {
|
|
|
27
28
|
private _clusters?: ClusterManager
|
|
28
29
|
private _nft?: NftManager
|
|
29
30
|
private _balances?: BalancesManager
|
|
31
|
+
private _funds?: FundManager
|
|
30
32
|
private _jobs?: JobsManager
|
|
31
33
|
private _influence?: InfluenceManager
|
|
32
34
|
private _subscriptions?: SubscriptionsManager
|
|
@@ -106,6 +108,13 @@ export class GameContext {
|
|
|
106
108
|
return this._balances
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
get funds(): FundManager {
|
|
112
|
+
if (!this._funds) {
|
|
113
|
+
this._funds = new FundManager(this)
|
|
114
|
+
}
|
|
115
|
+
return this._funds
|
|
116
|
+
}
|
|
117
|
+
|
|
109
118
|
get jobs(): JobsManager {
|
|
110
119
|
if (!this._jobs) {
|
|
111
120
|
this._jobs = new JobsManager(this)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {type Asset, Name, type NameType, type UInt16} from '@wharfkit/antelope'
|
|
2
|
+
import type {FundContract} from '../contracts'
|
|
3
|
+
import type {PlatformBalance} from './balances'
|
|
4
|
+
import {BaseManager} from './base'
|
|
5
|
+
|
|
6
|
+
export interface FundBeneficiary {
|
|
7
|
+
account: Name
|
|
8
|
+
bps: UInt16
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface FundToken {
|
|
12
|
+
tokenContract: Name
|
|
13
|
+
symbol: Asset.Symbol
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FundAccrued {
|
|
17
|
+
tokenContract: Name
|
|
18
|
+
balance: Asset
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Live fund ledger reads. Token custody can exceed the amounts accrued to beneficiaries. */
|
|
22
|
+
export class FundManager extends BaseManager {
|
|
23
|
+
async getBeneficiaries(): Promise<FundBeneficiary[]> {
|
|
24
|
+
const rows = (await this.fund
|
|
25
|
+
.table('benefs', this.fund.account)
|
|
26
|
+
.all()) as FundContract.Types.benef_row[]
|
|
27
|
+
return rows.map((row) => ({account: row.account, bps: row.bps}))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getTokens(): Promise<FundToken[]> {
|
|
31
|
+
const rows = (await this.fund
|
|
32
|
+
.table('tokens', this.fund.account)
|
|
33
|
+
.all()) as FundContract.Types.token_row[]
|
|
34
|
+
return rows.map((row) => ({tokenContract: row.token_contract, symbol: row.token_symbol}))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Includes zero rows and claims for tokens no longer accepted; no rows returns []. */
|
|
38
|
+
async getAccrued(beneficiary: NameType): Promise<FundAccrued[]> {
|
|
39
|
+
const rows = (await this.fund
|
|
40
|
+
.table('accrued', Name.from(beneficiary))
|
|
41
|
+
.all()) as FundContract.Types.accrued_row[]
|
|
42
|
+
return rows.map((row) => ({tokenContract: row.token_contract, balance: row.balance}))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Platform balances that have not reached the fund's accrual ledger yet. */
|
|
46
|
+
async getUncollected(): Promise<PlatformBalance[]> {
|
|
47
|
+
return this.context.balances.getPlatformBalances(this.fund.account)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/managers/index.ts
CHANGED
package/src/nft/description.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {MASS_UNITS_PER_TONNE, type ModuleType} from '../types'
|
|
|
32
32
|
import {ENTITY_SHIP, getPackedEntityType} from '../data/kind-registry'
|
|
33
33
|
import {getBaseHullmassFor} from '../derivation/capabilities'
|
|
34
34
|
import {computeEffectiveModuleStat} from '../derivation/stat-scaling'
|
|
35
|
+
import {resolveCapacityFnName, type CapacityFnName} from '../derivation/capacity-fn-registry'
|
|
35
36
|
|
|
36
37
|
function idiv(a: number, b: number): number {
|
|
37
38
|
return Math.floor(a / b)
|
|
@@ -89,24 +90,18 @@ export function computeBaseCapacityDepot(stats: bigint): number {
|
|
|
89
90
|
return Math.floor(500_000 * 6 ** (s / 1998))
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
const
|
|
93
|
+
const CAPACITY_FN_BY_NAME: Record<CapacityFnName, (stats: bigint) => number> = {
|
|
93
94
|
ship: computeBaseCapacityShip,
|
|
94
95
|
warehouse: computeBaseCapacityWarehouse,
|
|
95
96
|
workshop: computeBaseCapacityWorkshop,
|
|
96
|
-
extractor: computeBaseCapacityContainer,
|
|
97
|
-
factory: computeBaseCapacityContainer,
|
|
98
|
-
builddock: computeBaseCapacityContainer,
|
|
99
|
-
mdriver: computeBaseCapacityContainer,
|
|
100
|
-
mcatcher: computeBaseCapacityContainer,
|
|
101
97
|
container: computeBaseCapacityContainer,
|
|
102
|
-
nexus: computeBaseCapacityContainer,
|
|
103
98
|
depot: computeBaseCapacityDepot,
|
|
104
99
|
}
|
|
105
100
|
|
|
106
101
|
export function computeBaseCapacityForEntity(itemId: number, stats: bigint): number {
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
109
|
-
return
|
|
102
|
+
const fnName = resolveCapacityFnName(itemId)
|
|
103
|
+
if (!fnName) return 0
|
|
104
|
+
return CAPACITY_FN_BY_NAME[fnName](stats)
|
|
110
105
|
}
|
|
111
106
|
|
|
112
107
|
export const computeEngineThrust = (vol: number, tier: number): number =>
|
|
@@ -2,11 +2,16 @@ import {expect, test} from 'bun:test'
|
|
|
2
2
|
import {UInt16, UInt64} from '@wharfkit/antelope'
|
|
3
3
|
import {resolveItem} from './resolve-item'
|
|
4
4
|
import {encodeStats} from '../derivation/crafting'
|
|
5
|
-
import {computeBaseHullmass, computeContainerCapabilities} from '../derivation/capabilities'
|
|
6
5
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
computeBaseHullmass,
|
|
7
|
+
computeContainerCapabilities,
|
|
8
|
+
applyCapacityTier,
|
|
9
|
+
} from '../derivation/capabilities'
|
|
10
|
+
import {getItem} from '../data/catalog'
|
|
11
|
+
import {
|
|
12
|
+
ITEM_EXTRACTOR_T2_PACKED,
|
|
13
|
+
ITEM_FACTORY_T2_PACKED,
|
|
14
|
+
ITEM_HUB_T2_PACKED,
|
|
10
15
|
ITEM_MASS_DRIVER_T1_PACKED,
|
|
11
16
|
ITEM_MASS_CATCHER_T1_PACKED,
|
|
12
17
|
} from '../data/item-ids'
|
|
@@ -16,8 +21,8 @@ function hullStats(strength: number, density: number, hardness: number): UInt64
|
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
const CONTAINER_ENTITIES = [
|
|
19
|
-
['factory',
|
|
20
|
-
['extractor',
|
|
24
|
+
['factory', ITEM_FACTORY_T2_PACKED],
|
|
25
|
+
['extractor', ITEM_EXTRACTOR_T2_PACKED],
|
|
21
26
|
['mass driver', ITEM_MASS_DRIVER_T1_PACKED],
|
|
22
27
|
['mass catcher', ITEM_MASS_CATCHER_T1_PACKED],
|
|
23
28
|
] as const
|
|
@@ -28,21 +33,21 @@ for (const [label, itemId] of CONTAINER_ENTITIES) {
|
|
|
28
33
|
const resolved = resolveItem(UInt16.from(itemId), stats)
|
|
29
34
|
const hull = resolved.attributes?.find((g) => g.capability === 'Hull')
|
|
30
35
|
const capacity = hull?.attributes.find((a) => a.label === 'Capacity')?.value
|
|
31
|
-
const
|
|
36
|
+
const base = computeContainerCapabilities({
|
|
32
37
|
strength: 300,
|
|
33
38
|
hardness: 400,
|
|
34
39
|
density: 100,
|
|
35
40
|
}).capacity
|
|
36
|
-
expect(capacity).toBe(
|
|
41
|
+
expect(capacity).toBe(applyCapacityTier(base, getItem(itemId).tier))
|
|
37
42
|
})
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
test('resolveItem resolves the station hub with hullmass and zero cargo capacity', () => {
|
|
41
46
|
const stats = hullStats(300, 100, 400)
|
|
42
|
-
const resolved = resolveItem(UInt16.from(
|
|
47
|
+
const resolved = resolveItem(UInt16.from(ITEM_HUB_T2_PACKED), stats)
|
|
43
48
|
const hull = resolved.attributes?.find((g) => g.capability === 'Hull')
|
|
44
49
|
expect(hull?.attributes.find((a) => a.label === 'Mass')?.value).toBe(
|
|
45
|
-
computeBaseHullmass(
|
|
50
|
+
computeBaseHullmass(ITEM_HUB_T2_PACKED, {density: 100})
|
|
46
51
|
)
|
|
47
52
|
expect(hull?.attributes.find((a) => a.label === 'Capacity')?.value).toBe(0)
|
|
48
53
|
})
|
package/src/shipload.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {ActionsManager} from './managers/actions'
|
|
|
13
13
|
import type {ClusterManager} from './managers/cluster'
|
|
14
14
|
import type {NftManager} from './managers/nft'
|
|
15
15
|
import type {BalancesManager} from './managers/balances'
|
|
16
|
+
import type {FundManager} from './managers/fund'
|
|
16
17
|
import type {JobsManager} from './managers/jobs'
|
|
17
18
|
import type {InfluenceManager} from './managers/influence'
|
|
18
19
|
import type {SubscriptionsManager} from './subscriptions/manager'
|
|
@@ -154,6 +155,10 @@ export class Shipload {
|
|
|
154
155
|
return this._context.nft
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
get funds(): FundManager {
|
|
159
|
+
return this._context.funds
|
|
160
|
+
}
|
|
161
|
+
|
|
157
162
|
get balances(): BalancesManager {
|
|
158
163
|
return this._context.balances
|
|
159
164
|
}
|