@conquest-eth/tools 0.0.0

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +259 -0
  3. package/dist/cli-tool-generator.d.ts +22 -0
  4. package/dist/cli-tool-generator.d.ts.map +1 -0
  5. package/dist/cli-tool-generator.js +217 -0
  6. package/dist/cli-tool-generator.js.map +1 -0
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +76 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/contracts/space-info.d.ts +7 -0
  12. package/dist/contracts/space-info.d.ts.map +1 -0
  13. package/dist/contracts/space-info.js +34 -0
  14. package/dist/contracts/space-info.js.map +1 -0
  15. package/dist/fleet/index.d.ts +4 -0
  16. package/dist/fleet/index.d.ts.map +1 -0
  17. package/dist/fleet/index.js +7 -0
  18. package/dist/fleet/index.js.map +1 -0
  19. package/dist/fleet/manager.d.ts +70 -0
  20. package/dist/fleet/manager.d.ts.map +1 -0
  21. package/dist/fleet/manager.js +92 -0
  22. package/dist/fleet/manager.js.map +1 -0
  23. package/dist/fleet/resolve.d.ts +51 -0
  24. package/dist/fleet/resolve.d.ts.map +1 -0
  25. package/dist/fleet/resolve.js +140 -0
  26. package/dist/fleet/resolve.js.map +1 -0
  27. package/dist/fleet/send.d.ts +29 -0
  28. package/dist/fleet/send.d.ts.map +1 -0
  29. package/dist/fleet/send.js +81 -0
  30. package/dist/fleet/send.js.map +1 -0
  31. package/dist/helpers/index.d.ts +14 -0
  32. package/dist/helpers/index.d.ts.map +1 -0
  33. package/dist/helpers/index.js +28 -0
  34. package/dist/helpers/index.js.map +1 -0
  35. package/dist/index.d.ts +36 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +143 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/planet/acquire.d.ts +16 -0
  40. package/dist/planet/acquire.d.ts.map +1 -0
  41. package/dist/planet/acquire.js +27 -0
  42. package/dist/planet/acquire.js.map +1 -0
  43. package/dist/planet/exit.d.ts +17 -0
  44. package/dist/planet/exit.d.ts.map +1 -0
  45. package/dist/planet/exit.js +56 -0
  46. package/dist/planet/exit.js.map +1 -0
  47. package/dist/planet/index.d.ts +4 -0
  48. package/dist/planet/index.d.ts.map +1 -0
  49. package/dist/planet/index.js +6 -0
  50. package/dist/planet/index.js.map +1 -0
  51. package/dist/planet/manager.d.ts +106 -0
  52. package/dist/planet/manager.d.ts.map +1 -0
  53. package/dist/planet/manager.js +253 -0
  54. package/dist/planet/manager.js.map +1 -0
  55. package/dist/storage/interface.d.ts +93 -0
  56. package/dist/storage/interface.d.ts.map +1 -0
  57. package/dist/storage/interface.js +2 -0
  58. package/dist/storage/interface.js.map +1 -0
  59. package/dist/storage/json-storage.d.ts +28 -0
  60. package/dist/storage/json-storage.d.ts.map +1 -0
  61. package/dist/storage/json-storage.js +148 -0
  62. package/dist/storage/json-storage.js.map +1 -0
  63. package/dist/tools/acquire_planets.d.ts +7 -0
  64. package/dist/tools/acquire_planets.d.ts.map +1 -0
  65. package/dist/tools/acquire_planets.js +63 -0
  66. package/dist/tools/acquire_planets.js.map +1 -0
  67. package/dist/tools/exit_planets.d.ts +5 -0
  68. package/dist/tools/exit_planets.d.ts.map +1 -0
  69. package/dist/tools/exit_planets.js +31 -0
  70. package/dist/tools/exit_planets.js.map +1 -0
  71. package/dist/tools/get_my_planets.d.ts +5 -0
  72. package/dist/tools/get_my_planets.d.ts.map +1 -0
  73. package/dist/tools/get_my_planets.js +30 -0
  74. package/dist/tools/get_my_planets.js.map +1 -0
  75. package/dist/tools/get_pending_exits.d.ts +3 -0
  76. package/dist/tools/get_pending_exits.d.ts.map +1 -0
  77. package/dist/tools/get_pending_exits.js +37 -0
  78. package/dist/tools/get_pending_exits.js.map +1 -0
  79. package/dist/tools/get_pending_fleets.d.ts +3 -0
  80. package/dist/tools/get_pending_fleets.d.ts.map +1 -0
  81. package/dist/tools/get_pending_fleets.js +41 -0
  82. package/dist/tools/get_pending_fleets.js.map +1 -0
  83. package/dist/tools/get_planets_around.d.ts +7 -0
  84. package/dist/tools/get_planets_around.d.ts.map +1 -0
  85. package/dist/tools/get_planets_around.js +41 -0
  86. package/dist/tools/get_planets_around.js.map +1 -0
  87. package/dist/tools/index.d.ts +10 -0
  88. package/dist/tools/index.d.ts.map +1 -0
  89. package/dist/tools/index.js +11 -0
  90. package/dist/tools/index.js.map +1 -0
  91. package/dist/tools/resolve_fleet.d.ts +5 -0
  92. package/dist/tools/resolve_fleet.d.ts.map +1 -0
  93. package/dist/tools/resolve_fleet.js +37 -0
  94. package/dist/tools/resolve_fleet.js.map +1 -0
  95. package/dist/tools/send_fleet.d.ts +16 -0
  96. package/dist/tools/send_fleet.d.ts.map +1 -0
  97. package/dist/tools/send_fleet.js +62 -0
  98. package/dist/tools/send_fleet.js.map +1 -0
  99. package/dist/tools/verify_exit_status.d.ts +5 -0
  100. package/dist/tools/verify_exit_status.d.ts.map +1 -0
  101. package/dist/tools/verify_exit_status.js +39 -0
  102. package/dist/tools/verify_exit_status.js.map +1 -0
  103. package/dist/types.d.ts +126 -0
  104. package/dist/types.d.ts.map +1 -0
  105. package/dist/types.js +34 -0
  106. package/dist/types.js.map +1 -0
  107. package/dist/util/hashing.d.ts +33 -0
  108. package/dist/util/hashing.d.ts.map +1 -0
  109. package/dist/util/hashing.js +38 -0
  110. package/dist/util/hashing.js.map +1 -0
  111. package/dist/util/time.d.ts +43 -0
  112. package/dist/util/time.d.ts.map +1 -0
  113. package/dist/util/time.js +55 -0
  114. package/dist/util/time.js.map +1 -0
  115. package/package.json +78 -0
  116. package/src/cli-tool-generator.ts +287 -0
  117. package/src/cli.ts +109 -0
  118. package/src/contracts/space-info.ts +41 -0
  119. package/src/fleet/index.ts +8 -0
  120. package/src/fleet/manager.ts +140 -0
  121. package/src/fleet/resolve.ts +187 -0
  122. package/src/fleet/send.ts +112 -0
  123. package/src/helpers/index.ts +59 -0
  124. package/src/index.ts +181 -0
  125. package/src/planet/acquire.ts +41 -0
  126. package/src/planet/exit.ts +71 -0
  127. package/src/planet/index.ts +6 -0
  128. package/src/planet/manager.ts +335 -0
  129. package/src/storage/interface.ts +111 -0
  130. package/src/storage/json-storage.ts +184 -0
  131. package/src/tools/acquire_planets.ts +81 -0
  132. package/src/tools/exit_planets.ts +35 -0
  133. package/src/tools/get_my_planets.ts +30 -0
  134. package/src/tools/get_pending_exits.ts +37 -0
  135. package/src/tools/get_pending_fleets.ts +41 -0
  136. package/src/tools/get_planets_around.ts +44 -0
  137. package/src/tools/index.ts +10 -0
  138. package/src/tools/resolve_fleet.ts +37 -0
  139. package/src/tools/send_fleet.ts +68 -0
  140. package/src/tools/verify_exit_status.ts +43 -0
  141. package/src/types.ts +178 -0
  142. package/src/util/hashing.ts +60 -0
  143. package/src/util/time.ts +66 -0
@@ -0,0 +1,34 @@
1
+ import { SpaceInfo } from 'conquest-eth-v0-contracts';
2
+ export async function createSpaceInfo(clients, gameContract) {
3
+ // Fetch config from contract
4
+ const config = await clients.publicClient.readContract({
5
+ ...gameContract,
6
+ functionName: 'getConfig',
7
+ });
8
+ const contractConfig = {
9
+ genesis: BigInt(config.genesis),
10
+ resolveWindow: BigInt(config.resolveWindow),
11
+ timePerDistance: BigInt(config.timePerDistance),
12
+ exitDuration: BigInt(config.exitDuration),
13
+ acquireNumSpaceships: Number(config.acquireNumSpaceships),
14
+ };
15
+ // Create SpaceInfo instance with config
16
+ const spaceInfo = new SpaceInfo({
17
+ genesis: config.genesis,
18
+ resolveWindow: Number(config.resolveWindow),
19
+ timePerDistance: Number(config.timePerDistance),
20
+ exitDuration: Number(config.exitDuration),
21
+ acquireNumSpaceships: Number(config.acquireNumSpaceships),
22
+ productionSpeedUp: Number(config.productionSpeedUp),
23
+ productionCapAsDuration: Number(config.productionCapAsDuration),
24
+ upkeepProductionDecreaseRatePer10000th: Number(config.upkeepProductionDecreaseRatePer10000th),
25
+ fleetSizeFactor6: Number(config.fleetSizeFactor6),
26
+ giftTaxPer10000: Number(config.giftTaxPer10000),
27
+ stakeRange: config.stakeRange,
28
+ stakeMultiplier10000th: Number(config.stakeMultiplier10000th),
29
+ bootstrapSessionEndTime: Number(config.bootstrapSessionEndTime),
30
+ infinityStartTime: Number(config.infinityStartTime),
31
+ });
32
+ return { spaceInfo, contractConfig };
33
+ }
34
+ //# sourceMappingURL=space-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space-info.js","sourceRoot":"","sources":["../../src/contracts/space-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AAGpD,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,OAAkC,EAClC,YAA0B;IAE1B,6BAA6B;IAC7B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC;QACtD,GAAG,YAAY;QACf,YAAY,EAAE,WAAW;KACzB,CAAC,CAAC;IAEH,MAAM,cAAc,GAAmB;QACtC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/B,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3C,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;QAC/C,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;QACzC,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;KACzD,CAAC;IAEF,wCAAwC;IACxC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC;QAC/B,OAAO,EAAE,MAAM,CAAC,OAAwB;QACxC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3C,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;QAC/C,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;QACzC,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;QACzD,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;QACnD,uBAAuB,EAAE,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC;QAC/D,sCAAsC,EAAE,MAAM,CAAC,MAAM,CAAC,sCAAsC,CAAC;QAC7F,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;QACjD,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;QAC/C,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC;QAC7D,uBAAuB,EAAE,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC;QAC/D,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;KACnD,CAAC,CAAC;IAEH,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { FleetManager } from './manager.js';
2
+ export { sendFleet } from './send.js';
3
+ export { resolveFleet, resolveFleetWithSpaceInfo, getResolvableFleets } from './resolve.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fleet/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAC,YAAY,EAAE,yBAAyB,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,7 @@
1
+ // Fleet Manager and exports
2
+ export { FleetManager } from './manager.js';
3
+ // Send functions
4
+ export { sendFleet } from './send.js';
5
+ // Resolve functions
6
+ export { resolveFleet, resolveFleetWithSpaceInfo, getResolvableFleets } from './resolve.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fleet/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C,iBAAiB;AACjB,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpC,oBAAoB;AACpB,OAAO,EAAC,YAAY,EAAE,yBAAyB,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { Address } from 'viem';
2
+ import type { SpaceInfo } from 'conquest-eth-v0-contracts';
3
+ import type { FleetStorage } from '../storage/interface.js';
4
+ import type { ClientsWithOptionalWallet, ContractConfig, GameContract, PendingFleet } from '../types.js';
5
+ /**
6
+ * FleetManager manages the lifecycle of fleets in the Conquest game
7
+ * including sending new fleets and resolving existing ones
8
+ */
9
+ export declare class FleetManager {
10
+ private readonly clients;
11
+ private readonly gameContract;
12
+ private readonly spaceInfo;
13
+ private readonly contractConfig;
14
+ private readonly storage;
15
+ constructor(clients: ClientsWithOptionalWallet, gameContract: GameContract, spaceInfo: SpaceInfo, contractConfig: ContractConfig, storage: FleetStorage);
16
+ /**
17
+ * Ensure walletClient is available for operations that require it
18
+ */
19
+ private requireWalletClient;
20
+ /**
21
+ * Send a fleet to a destination planet
22
+ */
23
+ send(fromPlanetId: bigint, toPlanetId: bigint, quantity: number, options?: {
24
+ gift?: boolean;
25
+ specific?: Address;
26
+ arrivalTimeWanted?: bigint;
27
+ secret?: `0x${string}`;
28
+ }): Promise<PendingFleet>;
29
+ /**
30
+ * Resolve (reveal) a fleet to complete its journey
31
+ */
32
+ resolve(fleetId: string): Promise<{
33
+ resolved: true;
34
+ fleet: PendingFleet;
35
+ } | {
36
+ resolved: false;
37
+ reason: string;
38
+ }>;
39
+ /**
40
+ * Get fleets that can be resolved (not yet resolved and past resolve window)
41
+ */
42
+ getResolvableFleets(): Promise<PendingFleet[]>;
43
+ /**
44
+ * Get all pending fleets for the current sender
45
+ */
46
+ getMyPendingFleets(): Promise<PendingFleet[]>;
47
+ /**
48
+ * Get a specific fleet by ID
49
+ */
50
+ getFleet(fleetId: string): Promise<PendingFleet | null>;
51
+ /**
52
+ * Get all fleets in storage
53
+ */
54
+ getAllFleets(): Promise<PendingFleet[]>;
55
+ /**
56
+ * Resolve all fleets that are ready (batch operation)
57
+ */
58
+ resolveAllReady(): Promise<{
59
+ successful: PendingFleet[];
60
+ failed: Array<{
61
+ fleetId: string;
62
+ reason: string;
63
+ }>;
64
+ }>;
65
+ /**
66
+ * Clean up old resolved fleets from storage
67
+ */
68
+ cleanupOldResolvedFleets(olderThanDays?: number): Promise<void>;
69
+ }
70
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/fleet/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAEX,yBAAyB,EACzB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAJP,OAAO,EAAE,yBAAyB,EAClC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,YAAY;IAIvC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACG,IAAI,CACT,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,MAAM,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;KACvB,GACC,OAAO,CAAC,YAAY,CAAC;IAcxB;;OAEG;IACG,OAAO,CACZ,OAAO,EAAE,MAAM,GACb,OAAO,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,YAAY,CAAA;KAAC,GAAG;QAAC,QAAQ,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAC;IAUrF;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAIpD;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAKnD;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAI7D;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAI7C;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC;QAChC,UAAU,EAAE,YAAY,EAAE,CAAC;QAC3B,MAAM,EAAE,KAAK,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAC,CAAC,CAAC;KACjD,CAAC;IAiBF;;OAEG;IACG,wBAAwB,CAAC,aAAa,GAAE,MAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAIxE"}
@@ -0,0 +1,92 @@
1
+ import { getResolvableFleets, resolveFleetWithSpaceInfo } from './resolve.js';
2
+ import { sendFleet } from './send.js';
3
+ /**
4
+ * FleetManager manages the lifecycle of fleets in the Conquest game
5
+ * including sending new fleets and resolving existing ones
6
+ */
7
+ export class FleetManager {
8
+ clients;
9
+ gameContract;
10
+ spaceInfo;
11
+ contractConfig;
12
+ storage;
13
+ constructor(clients, gameContract, spaceInfo, contractConfig, storage) {
14
+ this.clients = clients;
15
+ this.gameContract = gameContract;
16
+ this.spaceInfo = spaceInfo;
17
+ this.contractConfig = contractConfig;
18
+ this.storage = storage;
19
+ }
20
+ /**
21
+ * Ensure walletClient is available for operations that require it
22
+ */
23
+ requireWalletClient() {
24
+ if (!this.clients.walletClient) {
25
+ throw new Error('Wallet client is required for this operation. Please provide a PRIVATE_KEY environment variable.');
26
+ }
27
+ return this.clients;
28
+ }
29
+ /**
30
+ * Send a fleet to a destination planet
31
+ */
32
+ async send(fromPlanetId, toPlanetId, quantity, options) {
33
+ return sendFleet(this.requireWalletClient(), this.gameContract, fromPlanetId, toPlanetId, quantity, this.spaceInfo, this.contractConfig, this.storage, options);
34
+ }
35
+ /**
36
+ * Resolve (reveal) a fleet to complete its journey
37
+ */
38
+ async resolve(fleetId) {
39
+ return resolveFleetWithSpaceInfo(this.requireWalletClient(), this.gameContract, this.spaceInfo, fleetId, this.storage);
40
+ }
41
+ /**
42
+ * Get fleets that can be resolved (not yet resolved and past resolve window)
43
+ */
44
+ async getResolvableFleets() {
45
+ return getResolvableFleets(this.storage, this.contractConfig.resolveWindow);
46
+ }
47
+ /**
48
+ * Get all pending fleets for the current sender
49
+ */
50
+ async getMyPendingFleets() {
51
+ const sender = this.requireWalletClient().walletClient.account.address;
52
+ return this.storage.getPendingFleetsBySender(sender);
53
+ }
54
+ /**
55
+ * Get a specific fleet by ID
56
+ */
57
+ async getFleet(fleetId) {
58
+ return this.storage.getFleet(fleetId);
59
+ }
60
+ /**
61
+ * Get all fleets in storage
62
+ */
63
+ async getAllFleets() {
64
+ return this.storage.getAllFleets();
65
+ }
66
+ /**
67
+ * Resolve all fleets that are ready (batch operation)
68
+ */
69
+ async resolveAllReady() {
70
+ const readyFleets = await this.getResolvableFleets();
71
+ const successful = [];
72
+ const failed = [];
73
+ for (const fleet of readyFleets) {
74
+ const result = await this.resolve(fleet.fleetId);
75
+ if (result.resolved) {
76
+ successful.push(result.fleet);
77
+ }
78
+ else {
79
+ failed.push({ fleetId: fleet.fleetId, reason: result.reason });
80
+ }
81
+ }
82
+ return { successful, failed };
83
+ }
84
+ /**
85
+ * Clean up old resolved fleets from storage
86
+ */
87
+ async cleanupOldResolvedFleets(olderThanDays = 7) {
88
+ const olderThan = Math.floor(Date.now() / 1000) - olderThanDays * 24 * 60 * 60;
89
+ await this.storage.cleanupOldResolvedFleets(olderThan);
90
+ }
91
+ }
92
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/fleet/manager.ts"],"names":[],"mappings":"AAUA,OAAO,EAAC,mBAAmB,EAAE,yBAAyB,EAAC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,OAAO,YAAY;IAEN;IACA;IACA;IACA;IACA;IALlB,YACkB,OAAkC,EAClC,YAA0B,EAC1B,SAAoB,EACpB,cAA8B,EAC9B,OAAqB;QAJrB,YAAO,GAAP,OAAO,CAA2B;QAClC,iBAAY,GAAZ,YAAY,CAAc;QAC1B,cAAS,GAAT,SAAS,CAAW;QACpB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,YAAO,GAAP,OAAO,CAAc;IAEpC,CAAC;IAEJ;;OAEG;IACK,mBAAmB;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACd,kGAAkG,CAClG,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,OAAkB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CACT,YAAoB,EACpB,UAAkB,EAClB,QAAgB,EAChB,OAKC;QAED,OAAO,SAAS,CACf,IAAI,CAAC,mB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,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAC,CAAC,CAAC;YAC9D,CAAC;QACF,CAAC;QAED,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,wBAAwB,CAAC,gBAAwB,CAAC;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QAC/E,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACD"}
@@ -0,0 +1,51 @@
1
+ import type { Address, WalletClient } from 'viem';
2
+ import type { SpaceInfo } from 'conquest-eth-v0-contracts';
3
+ import type { FleetStorage } from '../storage/interface.js';
4
+ import { Clients, GameContract, PendingFleet } from '../types.js';
5
+ /**
6
+ * Resolve (reveal) a fleet to complete its journey and trigger combat
7
+ *
8
+ * @param walletClient - Viem wallet client for signing transactions
9
+ * @param fleetsRevealContract - The fleets reveal contract instance with address, abi, and clients
10
+ * @param fleetId - The fleet ID to resolve
11
+ * @param storage - Storage instance for tracking pending fleets
12
+ * @returns The resolution result with either resolved fleet or reason for failure
13
+ */
14
+ export declare function resolveFleet(walletClient: WalletClient, fleetsRevealContract: {
15
+ address: Address;
16
+ abi: readonly unknown[];
17
+ publicClient: unknown;
18
+ walletClient: WalletClient | undefined;
19
+ }, fleetId: string, storage: FleetStorage): Promise<{
20
+ resolved: true;
21
+ fleet: PendingFleet;
22
+ } | {
23
+ resolved: false;
24
+ reason: string;
25
+ }>;
26
+ /**
27
+ * Resolve a fleet with custom SpaceInfo for distance calculation
28
+ *
29
+ * @param clients - Viem clients (publicClient and walletClient)
30
+ * @param gameContract - The game contract instance with address and ABI
31
+ * @param spaceInfo - SpaceInfo instance for distance calculation
32
+ * @param fleetId - The fleet ID to resolve
33
+ * @param storage - Storage instance for tracking pending fleets
34
+ * @returns The resolution result with either resolved fleet or reason for failure
35
+ */
36
+ export declare function resolveFleetWithSpaceInfo(clients: Clients, gameContract: GameContract, spaceInfo: SpaceInfo, fleetId: string, storage: FleetStorage): Promise<{
37
+ resolved: true;
38
+ fleet: PendingFleet;
39
+ } | {
40
+ resolved: false;
41
+ reason: string;
42
+ }>;
43
+ /**
44
+ * Get fleets that can be resolved (not yet resolved and past resolve window)
45
+ *
46
+ * @param storage - Storage instance for tracking pending fleets
47
+ * @param resolveWindow - The resolve window duration in seconds from contract config
48
+ * @returns List of fleets that can be resolved
49
+ */
50
+ export declare function getResolvableFleets(storage: FleetStorage, resolveWindow: bigint): Promise<PendingFleet[]>;
51
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/fleet/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,MAAM,CAAC;AAChD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAC,OAAO,EAAmB,YAAY,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AAGjF;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CACjC,YAAY,EAAE,YAAY,EAC1B,oBAAoB,EAAE;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAC;CACvC,EACD,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAAC,CAwDpF;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAAC,CAkEpF;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,YAAY,EACrB,aAAa,EAAE,MAAM,GACnB,OAAO,CAAC,YAAY,EAAE,CAAC,CASzB"}
@@ -0,0 +1,140 @@
1
+ import { getCurrentTimestamp } from '../util/time.js';
2
+ /**
3
+ * Resolve (reveal) a fleet to complete its journey and trigger combat
4
+ *
5
+ * @param walletClient - Viem wallet client for signing transactions
6
+ * @param fleetsRevealContract - The fleets reveal contract instance with address, abi, and clients
7
+ * @param fleetId - The fleet ID to resolve
8
+ * @param storage - Storage instance for tracking pending fleets
9
+ * @returns The resolution result with either resolved fleet or reason for failure
10
+ */
11
+ export async function resolveFleet(walletClient, fleetsRevealContract, fleetId, storage) {
12
+ // Get the pending fleet from storage
13
+ const pendingFleet = await storage.getFleet(fleetId);
14
+ if (!pendingFleet) {
15
+ return { resolved: false, reason: `Fleet ${fleetId} not found in storage` };
16
+ }
17
+ if (pendingFleet.resolved) {
18
+ return { resolved: false, reason: `Fleet ${fleetId} has already been resolved` };
19
+ }
20
+ // The operator must be the same as the wallet client account
21
+ const operator = walletClient.account.address;
22
+ if (pendingFleet.operator !== operator) {
23
+ return { resolved: false, reason: `Only the operator can resolve this fleet` };
24
+ }
25
+ // Build the FleetResolution struct
26
+ const resolution = {
27
+ from: pendingFleet.fromPlanetId,
28
+ to: pendingFleet.toPlanetId,
29
+ distance: 0n, // Will be calculated by SpaceInfo
30
+ arrivalTimeWanted: pendingFleet.arrivalTimeWanted,
31
+ gift: pendingFleet.gift,
32
+ specific: pendingFleet.specific,
33
+ secret: pendingFleet.secret,
34
+ fleetSender: pendingFleet.fleetSender,
35
+ operator: pendingFleet.operator,
36
+ };
37
+ // Get the contract resolveFleet function signature
38
+ const publicClient = fleetsRevealContract.publicClient;
39
+ const request = await publicClient.simulateContract({
40
+ address: fleetsRevealContract.address,
41
+ abi: fleetsRevealContract.abi,
42
+ functionName: 'resolveFleet',
43
+ args: [BigInt('0x' + fleetId), resolution],
44
+ account: operator,
45
+ });
46
+ // Send the transaction
47
+ const hash = await walletClient.writeContract(request);
48
+ // Mark fleet as resolved in storage
49
+ const resolvedAt = getCurrentTimestamp();
50
+ await storage.markResolved(fleetId, resolvedAt);
51
+ // Update the fleet record
52
+ const resolvedFleet = {
53
+ ...pendingFleet,
54
+ resolved: true,
55
+ resolvedAt,
56
+ };
57
+ return { resolved: true, fleet: resolvedFleet };
58
+ }
59
+ /**
60
+ * Resolve a fleet with custom SpaceInfo for distance calculation
61
+ *
62
+ * @param clients - Viem clients (publicClient and walletClient)
63
+ * @param gameContract - The game contract instance with address and ABI
64
+ * @param spaceInfo - SpaceInfo instance for distance calculation
65
+ * @param fleetId - The fleet ID to resolve
66
+ * @param storage - Storage instance for tracking pending fleets
67
+ * @returns The resolution result with either resolved fleet or reason for failure
68
+ */
69
+ export async function resolveFleetWithSpaceInfo(clients, gameContract, spaceInfo, fleetId, storage) {
70
+ // Get the pending fleet from storage
71
+ const pendingFleet = await storage.getFleet(fleetId);
72
+ if (!pendingFleet) {
73
+ return { resolved: false, reason: `Fleet ${fleetId} not found in storage` };
74
+ }
75
+ if (pendingFleet.resolved) {
76
+ return { resolved: false, reason: `Fleet ${fleetId} has already been resolved` };
77
+ }
78
+ // The operator must be the same as the wallet client account
79
+ const operator = clients.walletClient.account.address;
80
+ if (pendingFleet.operator !== operator) {
81
+ return { resolved: false, reason: `Only the operator can resolve this fleet` };
82
+ }
83
+ // Get planet info for distance calculation
84
+ const fromPlanet = spaceInfo.getPlanetInfoViaId(pendingFleet.fromPlanetId);
85
+ const toPlanet = spaceInfo.getPlanetInfoViaId(pendingFleet.toPlanetId);
86
+ if (!fromPlanet || !toPlanet) {
87
+ return { resolved: false, reason: 'Could not get planet info for one or both planets' };
88
+ }
89
+ // Calculate distance using SpaceInfo
90
+ const distance = spaceInfo.distance(fromPlanet, toPlanet);
91
+ // Build the FleetResolution struct
92
+ const resolution = {
93
+ from: pendingFleet.fromPlanetId,
94
+ to: pendingFleet.toPlanetId,
95
+ distance: BigInt(distance),
96
+ arrivalTimeWanted: pendingFleet.arrivalTimeWanted,
97
+ gift: pendingFleet.gift,
98
+ specific: pendingFleet.specific,
99
+ secret: pendingFleet.secret,
100
+ fleetSender: pendingFleet.fleetSender,
101
+ operator: pendingFleet.operator,
102
+ };
103
+ // Get the contract resolveFleet function signature
104
+ const simulation = await clients.publicClient.simulateContract({
105
+ address: gameContract.address,
106
+ abi: gameContract.abi,
107
+ functionName: 'resolveFleet',
108
+ args: [BigInt(fleetId), resolution],
109
+ account: operator,
110
+ });
111
+ // Send the transaction
112
+ const hash = await clients.walletClient.writeContract(simulation.request);
113
+ // Mark fleet as resolved in storage
114
+ const resolvedAt = getCurrentTimestamp();
115
+ await storage.markResolved(fleetId, resolvedAt);
116
+ // Update the fleet record
117
+ const resolvedFleet = {
118
+ ...pendingFleet,
119
+ resolved: true,
120
+ resolvedAt,
121
+ };
122
+ return { resolved: true, fleet: resolvedFleet };
123
+ }
124
+ /**
125
+ * Get fleets that can be resolved (not yet resolved and past resolve window)
126
+ *
127
+ * @param storage - Storage instance for tracking pending fleets
128
+ * @param resolveWindow - The resolve window duration in seconds from contract config
129
+ * @returns List of fleets that can be resolved
130
+ */
131
+ export async function getResolvableFleets(storage, resolveWindow) {
132
+ const currentTime = getCurrentTimestamp();
133
+ const fleets = await storage.getResolvableFleets();
134
+ return fleets.filter((fleet) => {
135
+ // Check if fleet is past the resolve window
136
+ const resolveWindowOpen = fleet.estimatedArrivalTime + Number(resolveWindow);
137
+ return !fleet.resolved && currentTime >= resolveWindowOpen;
138
+ });
139
+ }
140
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/fleet/resolve.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,YAA0B,EAC1B,oBAKC,EACD,OAAe,EACf,OAAqB;IAErB,qCAAqC;IACrC,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAErD,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,OAAO,uBAAuB,EAAC,CAAC;IAC3E,CAAC;IAED,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;QAC3B,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,OAAO,4BAA4B,EAAC,CAAC;IAChF,CAAC;IAED,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAQ,CAAC,OAAO,CAAC;IAC/C,IAAI,YAAY,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,0CAA0C,EAAC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,4CAA4C;QAC5C,MAAM,iBAAiB,GAAG,KAAK,CAAC,oBAAoB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;QAC7E,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,WAAW,IAAI,iBAAiB,CAAC;IAC5D,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { type Address } from 'viem';
2
+ import type { SpaceInfo } from 'conquest-eth-v0-contracts';
3
+ import type { FleetStorage } from '../storage/interface.js';
4
+ import type { Clients, ContractConfig, GameContract, PendingFleet } from '../types.js';
5
+ /**
6
+ * Send a fleet to a destination planet
7
+ *
8
+ * @param clients - Viem clients (publicClient and walletClient)
9
+ * @param gameContract - The game contract instance with address and ABI
10
+ * @param fromPlanetId - Source planet location ID
11
+ * @param toPlanetId - Destination planet location ID
12
+ * @param quantity - Number of spaceships to send
13
+ * @param spaceInfo - SpaceInfo instance for distance calculation
14
+ * @param contractConfig - Contract config for time calculations
15
+ * @param storage - Storage instance for tracking pending fleets
16
+ * @param options - Optional parameters
17
+ * @param options.gift - Whether the fleet is a gift (no combat)
18
+ * @param options.specific - Specific target address (advanced feature)
19
+ * @param options.arrivalTimeWanted - Preferred arrival time (advanced feature)
20
+ * @param options.secret - Random secret for hash commitment (auto-generated if not provided)
21
+ * @returns The pending fleet information
22
+ */
23
+ export declare function sendFleet(clients: Clients, gameContract: GameContract, fromPlanetId: bigint, toPlanetId: bigint, quantity: number, spaceInfo: SpaceInfo, contractConfig: ContractConfig, storage: FleetStorage, options?: {
24
+ gift?: boolean;
25
+ specific?: Address;
26
+ arrivalTimeWanted?: bigint;
27
+ secret?: `0x${string}`;
28
+ }): Promise<PendingFleet>;
29
+ //# sourceMappingURL=send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/fleet/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAC,MAAM,MAAM,CAAC;AAC/C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AAIrF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,SAAS,CAC9B,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE;IACT,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CACvB,GACC,OAAO,CAAC,YAAY,CAAC,CAuEvB"}
@@ -0,0 +1,81 @@
1
+ import { zeroAddress } from 'viem';
2
+ import { computeFleetId, computeToHash, generateSecret } from '../util/hashing.js';
3
+ import { calculateEstimatedArrivalTime, getCurrentTimestamp } from '../util/time.js';
4
+ /**
5
+ * Send a fleet to a destination planet
6
+ *
7
+ * @param clients - Viem clients (publicClient and walletClient)
8
+ * @param gameContract - The game contract instance with address and ABI
9
+ * @param fromPlanetId - Source planet location ID
10
+ * @param toPlanetId - Destination planet location ID
11
+ * @param quantity - Number of spaceships to send
12
+ * @param spaceInfo - SpaceInfo instance for distance calculation
13
+ * @param contractConfig - Contract config for time calculations
14
+ * @param storage - Storage instance for tracking pending fleets
15
+ * @param options - Optional parameters
16
+ * @param options.gift - Whether the fleet is a gift (no combat)
17
+ * @param options.specific - Specific target address (advanced feature)
18
+ * @param options.arrivalTimeWanted - Preferred arrival time (advanced feature)
19
+ * @param options.secret - Random secret for hash commitment (auto-generated if not provided)
20
+ * @returns The pending fleet information
21
+ */
22
+ export async function sendFleet(clients, gameContract, fromPlanetId, toPlanetId, quantity, spaceInfo, contractConfig, storage, options) {
23
+ const fleetSender = clients.walletClient.account.address;
24
+ const operator = fleetSender; // Default to same address
25
+ // Get planet info for distance calculation
26
+ const fromPlanet = spaceInfo.getPlanetInfoViaId(fromPlanetId);
27
+ const toPlanet = spaceInfo.getPlanetInfoViaId(toPlanetId);
28
+ if (!fromPlanet || !toPlanet) {
29
+ throw new Error('Could not get planet info for one or both planets');
30
+ }
31
+ // Calculate distance
32
+ const distance = spaceInfo.distance(fromPlanet, toPlanet);
33
+ // Generate secret if not provided
34
+ const secret = options?.secret || generateSecret();
35
+ // Calculate estimated arrival time using contract config
36
+ const estimatedArrivalTime = calculateEstimatedArrivalTime({
37
+ startTime: BigInt(getCurrentTimestamp()),
38
+ distance: BigInt(distance),
39
+ timePerDistance: contractConfig.timePerDistance,
40
+ });
41
+ const parameters = {
42
+ gift: options?.gift ?? false,
43
+ specific: options?.specific ?? zeroAddress,
44
+ arrivalTimeWanted: options?.arrivalTimeWanted || 0n,
45
+ };
46
+ const toHash = computeToHash(toPlanetId, secret, parameters);
47
+ // Get the contract send function signature
48
+ const simulation = await clients.publicClient.simulateContract({
49
+ address: gameContract.address,
50
+ abi: gameContract.abi,
51
+ functionName: 'send',
52
+ args: [fromPlanetId, quantity, toHash],
53
+ account: fleetSender,
54
+ });
55
+ // Compute fleet ID
56
+ const fleetId = computeFleetId(toHash, fromPlanetId, fleetSender, operator);
57
+ // Create pending fleet record
58
+ const pendingFleet = {
59
+ fleetId,
60
+ fromPlanetId,
61
+ toPlanetId,
62
+ quantity,
63
+ secret,
64
+ gift: parameters.gift,
65
+ specific: parameters.specific,
66
+ arrivalTimeWanted: parameters.arrivalTimeWanted,
67
+ fleetSender,
68
+ operator,
69
+ committedAt: getCurrentTimestamp(),
70
+ estimatedArrivalTime,
71
+ resolved: false,
72
+ };
73
+ // we always save to storage first in case an error happen while the tx is still broadcasted
74
+ await storage.saveFleet(pendingFleet);
75
+ // Send the transaction
76
+ const hash = await clients.walletClient.writeContract(simulation.request);
77
+ pendingFleet.hash = hash;
78
+ await storage.saveFleet(pendingFleet);
79
+ return pendingFleet;
80
+ }
81
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.js","sourceRoot":"","sources":["../../src/fleet/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAe,MAAM,MAAM,CAAC;AAI/C,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAC,6BAA6B,EAAE,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AAEnF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,OAAgB,EAChB,YAA0B,EAC1B,YAAoB,EACpB,UAAkB,EAClB,QAAgB,EAChB,SAAoB,EACpB,cAA8B,EAC9B,OAAqB,EACrB,OAKC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,OAAQ,CAAC,OAAO,CAAC;IAC1D,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,0BAA0B;IAExD,2CAA2C;IAC3C,MAAM,UAAU,GAAG,SAAS,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAE1D,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACtE,CAAC;IAED,qBAAqB;IACrB,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE1D,kCAAkC;IAClC,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,cAAc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,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAEtC,uBAAuB;IACvB,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAE1E,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;IACzB,MAAM,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAEtC,OAAO,YAAY,CAAC;AACrB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Tool, ToolEnvironment } from '../types.js';
2
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import type { FleetManager } from '../fleet/manager.js';
4
+ import type { PlanetManager } from '../planet/manager.js';
5
+ export declare function stringifyWithBigInt(obj: any, space?: number): string;
6
+ export declare function createToolEnvironment(server: McpServer, fleetManager: FleetManager, planetManager: PlanetManager): ToolEnvironment;
7
+ export declare function registerTool({ server, name, tool, fleetManager, planetManager, }: {
8
+ server: McpServer;
9
+ name: string;
10
+ tool: Tool<any>;
11
+ fleetManager: FleetManager;
12
+ planetManager: PlanetManager;
13
+ }): void;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAE,eAAe,EAAC,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AACvE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAIxD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAMpE;AAGD,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,GAC1B,eAAe,CASjB;AAGD,wBAAgB,YAAY,CAAC,EAC5B,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,aAAa,GACb,EAAE;IACF,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;CAC7B,GAAG,IAAI,CAcP"}
@@ -0,0 +1,28 @@
1
+ import { convertToCallToolResult } from '../types.js';
2
+ // Helper function to handle BigInt serialization in JSON.stringify
3
+ export function stringifyWithBigInt(obj, space) {
4
+ return JSON.stringify(obj, (_key, value) => (typeof value === 'bigint' ? value.toString() : value), space);
5
+ }
6
+ // Create tool environment with sendStatus
7
+ export function createToolEnvironment(server, fleetManager, planetManager) {
8
+ return {
9
+ sendStatus: async (_message) => {
10
+ // TODO: Implement progress notifications when sessionId is available
11
+ // For now, this is a no-op since we don't have sessionId in the current architecture
12
+ },
13
+ fleetManager,
14
+ planetManager,
15
+ };
16
+ }
17
+ // Register tool with MCP server
18
+ export function registerTool({ server, name, tool, fleetManager, planetManager, }) {
19
+ server.registerTool(name, {
20
+ description: tool.description,
21
+ inputSchema: tool.schema,
22
+ }, async (params) => {
23
+ const env = createToolEnvironment(server, fleetManager, planetManager);
24
+ const result = await tool.execute(env, params);
25
+ return convertToCallToolResult(result);
26
+ });
27
+ }
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AAEpD,mEAAmE;AACnE,MAAM,UAAU,mBAAmB,CAAC,GAAQ,EAAE,KAAc;IAC3D,OAAO,IAAI,CAAC,SAAS,CACpB,GAAG,EACH,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EACvE,KAAK,CACL,CAAC;AACH,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,qBAAqB,CACpC,MAAiB,EACjB,YAA0B,EAC1B,aAA4B;IAE5B,OAAO;QACN,UAAU,EAAE,KAAK,EAAE,QAAgB,EAAE,EAAE;YACtC,qEAAqE;YACrE,qFAAqF;QACtF,CAAC;QACD,YAAY;QACZ,aAAa;KACb,CAAC;AACH,CAAC;AAED,gCAAgC;AAChC,MAAM,UAAU,YAAY,CAAC,EAC5B,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,aAAa,GAOb;IACA,MAAM,CAAC,YAAY,CAClB,IAAI,EACJ;QACC,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,IAAI,CAAC,MAAa;KAC/B,EACD,KAAK,EAAE,MAAe,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QAEvE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAa,CAAC,CAAC;QACtD,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC,CACD,CAAC;AACH,CAAC"}