@zktx.io/sui-mcp 0.5.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 (218) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSES/@mysten-bcs-2.0.5-Apache-2.0.txt +205 -0
  3. package/LICENSES/@mysten-sui-2.17.0-Apache-2.0.txt +201 -0
  4. package/LICENSES/@mysten-utils-0.3.3-Apache-2.0.txt +205 -0
  5. package/LICENSES/fancy-canvas-2.1.0-MIT.txt +7 -0
  6. package/LICENSES/lightweight-charts-5.2.0-NOTICE.txt +2 -0
  7. package/README.md +288 -0
  8. package/dist/adapters/adapterLifecycleValidators.js +5 -0
  9. package/dist/adapters/adapterPromptSurfaces.js +60 -0
  10. package/dist/adapters/deepbook/deepbookHumanReviewProducer.js +178 -0
  11. package/dist/adapters/deepbook/deepbookQuotePolicy.js +112 -0
  12. package/dist/adapters/deepbook/deepbookReviewEvidence.js +507 -0
  13. package/dist/adapters/deepbook/deepbookReviewLifecycle.js +85 -0
  14. package/dist/adapters/deepbook/deepbookSwapIntent.js +79 -0
  15. package/dist/adapters/deepbook/deepbookTransactionMaterialProducer.js +254 -0
  16. package/dist/adapters/intentPlanFactories.js +51 -0
  17. package/dist/adapters/reviewAdapters.js +47 -0
  18. package/dist/core/action/adapterLifecycleValidation.js +12 -0
  19. package/dist/core/action/contractNameRegistry.js +151 -0
  20. package/dist/core/action/forbiddenFields.js +43 -0
  21. package/dist/core/action/humanReadableReviewEvidence.js +193 -0
  22. package/dist/core/action/humanReadableReviewProjectionVerifier.js +29 -0
  23. package/dist/core/action/ptbVisualizationProducer.js +71 -0
  24. package/dist/core/action/receiptPtbGraph.js +29 -0
  25. package/dist/core/action/reviewCheckResults.js +6 -0
  26. package/dist/core/action/reviewStateValidation.js +11 -0
  27. package/dist/core/action/reviewTimeSimulationEvidence.js +470 -0
  28. package/dist/core/action/schemas.js +491 -0
  29. package/dist/core/action/signableAdapterContract.js +998 -0
  30. package/dist/core/action/suiChainReceiptEvidence.js +106 -0
  31. package/dist/core/action/suiChainReceiptMapping.js +107 -0
  32. package/dist/core/action/suiChainReceiptReader.js +211 -0
  33. package/dist/core/action/suiChainReceiptVerifier.js +178 -0
  34. package/dist/core/action/swapHumanReadableReviewProjection.js +130 -0
  35. package/dist/core/action/swapQuotePolicyEvidence.js +271 -0
  36. package/dist/core/action/transactionFunding.js +244 -0
  37. package/dist/core/action/transactionObjectOwnershipEvidence.js +256 -0
  38. package/dist/core/action/transactionObjectOwnershipProducer.js +323 -0
  39. package/dist/core/action/types.js +33 -0
  40. package/dist/core/action/walletReviewContractAssembler.js +286 -0
  41. package/dist/core/activity/accountAssetTimeline.js +157 -0
  42. package/dist/core/activity/accountAssetTimelineUsdcReferences.js +120 -0
  43. package/dist/core/activity/activityStore.js +16 -0
  44. package/dist/core/activity/externalActivityCoverage.js +76 -0
  45. package/dist/core/activity/externalActivityTransactionStream.js +82 -0
  46. package/dist/core/activity/localDataService.js +296 -0
  47. package/dist/core/activity/localDataTypes.js +11 -0
  48. package/dist/core/activity/localDataValidation.js +439 -0
  49. package/dist/core/activity/schemaVersion.js +2 -0
  50. package/dist/core/activity/sqliteActivityStore.js +1068 -0
  51. package/dist/core/activity/sqliteActivityStoreRows.js +389 -0
  52. package/dist/core/activity/sqliteActivityStoreSchema.js +367 -0
  53. package/dist/core/activity/sqliteActivityStoreTypes.js +5 -0
  54. package/dist/core/activity/suiFunctionTarget.js +43 -0
  55. package/dist/core/activity/transactionActivityAccountEffects.js +186 -0
  56. package/dist/core/activity/transactionActivityAnalysis.js +295 -0
  57. package/dist/core/activity/transactionActivityClassifier.js +306 -0
  58. package/dist/core/activity/transactionActivityDetails.js +229 -0
  59. package/dist/core/activity/transactionActivityProtocolRules.js +218 -0
  60. package/dist/core/activity/transactionActivityScanPolicy.js +170 -0
  61. package/dist/core/activity/transactionActivityService.js +379 -0
  62. package/dist/core/activity/transactionActivityTypes.js +18 -0
  63. package/dist/core/eventlog/sink.js +35 -0
  64. package/dist/core/evidence/settlementFamilies.js +85 -0
  65. package/dist/core/evidence/userAnswerUse.js +1 -0
  66. package/dist/core/numeric/rawU64.js +63 -0
  67. package/dist/core/preferences/preferencesStore.js +26 -0
  68. package/dist/core/preferences/sqlitePreferencesRepository.js +136 -0
  69. package/dist/core/proposal/externalProposalReview.js +347 -0
  70. package/dist/core/proposal/schemas.js +208 -0
  71. package/dist/core/proposal/types.js +35 -0
  72. package/dist/core/read/amounts.js +14 -0
  73. package/dist/core/read/coinMetadata.js +60 -0
  74. package/dist/core/read/deepbookOfficialIndexerSource.js +373 -0
  75. package/dist/core/read/deepbookRawQuoteClient.js +86 -0
  76. package/dist/core/read/deepbookReadHelpers.js +321 -0
  77. package/dist/core/read/deepbookRegistry.js +157 -0
  78. package/dist/core/read/deepbookSourceOwners.js +159 -0
  79. package/dist/core/read/deepbookUsdcChartService.js +342 -0
  80. package/dist/core/read/intentEvidenceResponseFormatting.js +228 -0
  81. package/dist/core/read/readCardInputs.js +19 -0
  82. package/dist/core/read/readCardResult.js +40 -0
  83. package/dist/core/read/readResponseGuidance.js +402 -0
  84. package/dist/core/read/readService.js +1639 -0
  85. package/dist/core/read/readServiceTypes.js +88 -0
  86. package/dist/core/read/settlementParityFormatting.js +82 -0
  87. package/dist/core/read/walletReadHelpers.js +99 -0
  88. package/dist/core/review/reviewChecks.js +45 -0
  89. package/dist/core/review/reviewComputation.js +38 -0
  90. package/dist/core/review/reviewComputationResult.js +87 -0
  91. package/dist/core/session/cardSession.js +31 -0
  92. package/dist/core/session/cardSessionStore.js +204 -0
  93. package/dist/core/session/keyedRecordStore.js +18 -0
  94. package/dist/core/session/liveReviewSessionContract.js +3 -0
  95. package/dist/core/session/localSession.js +31 -0
  96. package/dist/core/session/privateReviewArtifacts.js +75 -0
  97. package/dist/core/session/reviewValidity.js +49 -0
  98. package/dist/core/session/sessionErrors.js +9 -0
  99. package/dist/core/session/sessionRecordStore.js +40 -0
  100. package/dist/core/session/sessionStore.js +655 -0
  101. package/dist/core/session/settingsSession.js +1 -0
  102. package/dist/core/session/settingsSessions.js +45 -0
  103. package/dist/core/session/sqliteCardStore.js +88 -0
  104. package/dist/core/session/sqliteSessionStore.js +213 -0
  105. package/dist/core/session/sqliteTransactionMaterialStore.js +64 -0
  106. package/dist/core/session/sqliteWalletWorkflowStore.js +821 -0
  107. package/dist/core/session/status.js +60 -0
  108. package/dist/core/session/transactionMaterialStore.js +221 -0
  109. package/dist/core/session/transactionRequest.js +72 -0
  110. package/dist/core/session/wait.js +79 -0
  111. package/dist/core/session/walletConnection.js +92 -0
  112. package/dist/core/session/walletRuntime.js +38 -0
  113. package/dist/core/session/walletWorkflow.js +608 -0
  114. package/dist/core/session/workflowState.js +80 -0
  115. package/dist/core/session/workflowView.js +150 -0
  116. package/dist/core/suiAddress.js +18 -0
  117. package/dist/core/suiEndpoint.js +72 -0
  118. package/dist/mcp/activeAccountResponse.js +24 -0
  119. package/dist/mcp/prompts.js +146 -0
  120. package/dist/mcp/registerTool.js +19 -0
  121. package/dist/mcp/resources.js +72 -0
  122. package/dist/mcp/responseGuidance.js +326 -0
  123. package/dist/mcp/result.js +17 -0
  124. package/dist/mcp/schemas.js +11 -0
  125. package/dist/mcp/server.js +32 -0
  126. package/dist/mcp/serverInfo.js +131 -0
  127. package/dist/mcp/toolErrors.js +118 -0
  128. package/dist/mcp/toolNames.js +58 -0
  129. package/dist/mcp/tools/account/index.js +44 -0
  130. package/dist/mcp/tools/action/prepareSuiActionReview.js +126 -0
  131. package/dist/mcp/tools/read/commonSchemas.js +43 -0
  132. package/dist/mcp/tools/read/deepbookReadTools.js +686 -0
  133. package/dist/mcp/tools/read/index.js +14 -0
  134. package/dist/mcp/tools/read/readToolHelpers.js +97 -0
  135. package/dist/mcp/tools/read/reviewActivityTools.js +179 -0
  136. package/dist/mcp/tools/read/serverStatusTools.js +100 -0
  137. package/dist/mcp/tools/read/transactionActivityOutput.js +371 -0
  138. package/dist/mcp/tools/read/transactionActivityTools.js +858 -0
  139. package/dist/mcp/tools/read/walletReadTools.js +734 -0
  140. package/dist/mcp/tools/session/executionResultTools.js +44 -0
  141. package/dist/mcp/tools/session/index.js +8 -0
  142. package/dist/mcp/tools/session/shared.js +36 -0
  143. package/dist/mcp/tools/session/statusTools.js +69 -0
  144. package/dist/mcp/tools/session/walletConnectionTools.js +69 -0
  145. package/dist/mcp/tools/settings/index.js +66 -0
  146. package/dist/mcp-app/account.html +3133 -0
  147. package/dist/mcp-app/account.notices.txt +973 -0
  148. package/dist/mcp-app/chart.html +3354 -0
  149. package/dist/mcp-app/chart.notices.txt +1194 -0
  150. package/dist/mcp-app/connect.html +3179 -0
  151. package/dist/mcp-app/connect.notices.txt +1012 -0
  152. package/dist/mcp-app/receipt.html +8430 -0
  153. package/dist/mcp-app/receipt.notices.txt +3549 -0
  154. package/dist/mcp-app/review.html +8430 -0
  155. package/dist/mcp-app/review.notices.txt +3549 -0
  156. package/dist/mcp-ui/contracts.js +31 -0
  157. package/dist/mcp-ui/readCards.js +28 -0
  158. package/dist/mcp-ui/tools.js +134 -0
  159. package/dist/review-app/brand-dark.svg +1 -0
  160. package/dist/review-app/brand-light.svg +1 -0
  161. package/dist/review-app/favicon.svg +1 -0
  162. package/dist/review-app/settings.css +1 -0
  163. package/dist/review-app/settings.js +1 -0
  164. package/dist/review-app/ui.css +809 -0
  165. package/dist/review-server/assets.js +48 -0
  166. package/dist/review-server/html.js +45 -0
  167. package/dist/review-server/http.js +47 -0
  168. package/dist/review-server/middleware/hostOrigin.js +48 -0
  169. package/dist/review-server/middleware/reviewToken.js +7 -0
  170. package/dist/review-server/reviewServerPolicy.js +1 -0
  171. package/dist/review-server/server.js +72 -0
  172. package/dist/review-server/settingsApi.js +158 -0
  173. package/dist/runtime/application.js +203 -0
  174. package/dist/runtime/config.js +97 -0
  175. package/dist/runtime/localSettingsService.js +198 -0
  176. package/dist/runtime/logger.js +66 -0
  177. package/dist/runtime/reviewDependencies.js +58 -0
  178. package/dist/runtime/reviewServerAcquire.js +93 -0
  179. package/dist/runtime/runtimeTermination.js +60 -0
  180. package/dist/runtime/shared/authenticatedFetch.js +127 -0
  181. package/dist/runtime/shared/control.js +93 -0
  182. package/dist/runtime/shared/dataAccess.js +66 -0
  183. package/dist/runtime/shared/mcpHttp.js +84 -0
  184. package/dist/runtime/shared/ownerLease.js +50 -0
  185. package/dist/runtime/shared/server.js +98 -0
  186. package/dist/runtime/shared/stdio.js +113 -0
  187. package/dist/runtime/smokeMainnetRead.js +391 -0
  188. package/dist/runtime/smokeMainnetReadAssertions.js +306 -0
  189. package/dist/runtime/smokeReview.js +40 -0
  190. package/dist/runtime/start.js +90 -0
  191. package/dist/runtime/suiEndpoint.js +97 -0
  192. package/dist/runtime/suiTransactionGraphqlMapping.js +200 -0
  193. package/dist/runtime/suiTransactionGraphqlQueries.js +231 -0
  194. package/dist/runtime/suiTransactionGraphqlSource.js +148 -0
  195. package/dist/runtime/walletConnectConfig.js +3 -0
  196. package/dist/runtime/walletConnectStorage.js +99 -0
  197. package/dist/runtime/walletConnectTransport.js +128 -0
  198. package/dist/runtime/walletSdkChild.js +3 -0
  199. package/dist/runtime/walletSdkChildRuntime.js +160 -0
  200. package/dist/runtime/walletSdkIpc.js +26 -0
  201. package/dist/runtime/walletSdkProcess.js +358 -0
  202. package/docs/AGENT_BEHAVIOR.md +524 -0
  203. package/docs/AGENT_DEVELOPMENT_POLICY.md +815 -0
  204. package/docs/FRONTEND_POLICY.md +534 -0
  205. package/docs/LOCAL_DB_ARCHITECTURE.md +381 -0
  206. package/docs/MCP_SETUP.md +742 -0
  207. package/docs/MCP_TOOLS.md +1318 -0
  208. package/docs/SDK_API.md +206 -0
  209. package/docs/SIGNABLE_ADAPTER_CONTRACT.md +396 -0
  210. package/docs/TRANSACTION_ACTIVITY_LOG.md +194 -0
  211. package/docs/UTILITY_INDEX.md +275 -0
  212. package/docs/WALLET_CONNECTION.md +238 -0
  213. package/docs/golden-scenarios/BEHAVIOR_MATRIX.md +166 -0
  214. package/docs/golden-scenarios/INTENT_EVIDENCE_GOLDEN_ANSWERS.md +161 -0
  215. package/docs/golden-scenarios/INTENT_EVIDENCE_MATRIX.md +259 -0
  216. package/package.json +79 -0
  217. package/protocols/deepbook-margin.md +15 -0
  218. package/protocols/deepbook-v3.md +24 -0
@@ -0,0 +1,686 @@
1
+ import { mainnetPools } from "@mysten/deepbook-v3";
2
+ import { z } from "zod";
3
+ import { unknownRecordSchema } from "../../../core/action/schemas.js";
4
+ import { DEEPBOOK_SCALAR_UNIT_SOURCE } from "../../../core/read/coinMetadata.js";
5
+ import { DEEPBOOK_OFFICIAL_INDEXER_CANONICAL_USDC_COIN_TYPE, deepbookOfficialIndexerCandleSchema, deepbookOfficialIndexerIntervalSchema } from "../../../core/read/deepbookOfficialIndexerSource.js";
6
+ import { DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE, DEEPBOOK_OFFICIAL_INDEXER_RESPONSE_TEXT, DEEPBOOK_OFFICIAL_INDEXER_SOURCE_BASE, DEEPBOOK_OFFICIAL_INDEXER_USDC_REFERENCE } from "../../../core/read/deepbookSourceOwners.js";
7
+ import { DEEPBOOK_MID_PRICE_DIRECTION, DEEPBOOK_MID_PRICE_PRECISION, DEEPBOOK_MID_PRICE_SEMANTICS_KIND, DEEPBOOK_MID_PRICE_TYPE, DEEPBOOK_ACCOUNT_QUANTITY_KIND, DEEPBOOK_USDC_CANDLE_AVAILABILITY, DEEPBOOK_USDC_PRICE_HISTORY_QUANTITY_KIND, DEEPBOOK_USDC_PRICE_HISTORY_SOURCE_UNAVAILABLE_REASONS, DEEPBOOK_USDC_PRICE_HISTORY_UNSUPPORTED_CLAIMS, DEEPBOOK_USDC_PRICE_HISTORY_UNSUPPORTED_PAIR_REASONS, DEEPBOOK_QUOTE_QUANTITY_KIND, DEFAULT_DEEPBOOK_SIMULATION_SENDER, MAX_DEEPBOOK_ACCOUNT_OPEN_ORDER_IDS, MAX_DEEPBOOK_USDC_PRICE_HISTORY_BARS, MAX_DEEPBOOK_ORDERBOOK_TICKS } from "../../../core/read/readService.js";
8
+ import { noParamsInputSchema, successOutputSchema } from "../../schemas.js";
9
+ import { okToolResult } from "../../result.js";
10
+ import { TOOL_NAMES } from "../../toolNames.js";
11
+ import { fetchedAtSchema, readSourceSchema, userAnswerUseSchema } from "./commonSchemas.js";
12
+ import { readServiceError, resolveExplicitOrActiveAccount } from "./readToolHelpers.js";
13
+ const deepbookMidPriceSourceSchema = z.object({
14
+ sdk: z.string(),
15
+ transport: z.literal("grpc"),
16
+ simulation: z.literal("client.core.simulateTransaction"),
17
+ method: z.literal("midPrice"),
18
+ precision: z.literal(DEEPBOOK_MID_PRICE_PRECISION)
19
+ });
20
+ const deepbookDisplayQuoteSourceSchema = z.object({
21
+ sdk: z.literal("@mysten/deepbook-v3"),
22
+ transport: z.literal("grpc"),
23
+ simulation: z.literal("client.core.simulateTransaction"),
24
+ method: z.enum(["getQuoteQuantityOut", "getBaseQuantityOut"]),
25
+ returnValueEncoding: z.literal("bcs.u64")
26
+ });
27
+ const deepbookAccountInventorySourceSchema = z.object({
28
+ sdk: z.literal("@mysten/deepbook-v3"),
29
+ transport: z.literal("grpc"),
30
+ simulation: z.literal("client.core.simulateTransaction"),
31
+ methods: z.array(z.enum(["getBalanceManagerIds", "accountExists", "account", "lockedBalance", "accountOpenOrders"]))
32
+ });
33
+ const deepbookDisplayAccountBalancesSchema = z.object({
34
+ base: z.number().refine(Number.isFinite),
35
+ quote: z.number().refine(Number.isFinite),
36
+ deep: z.number().refine(Number.isFinite)
37
+ });
38
+ const deepbookAccountQuantitySemanticsSchema = z.object({
39
+ kind: z.literal(DEEPBOOK_ACCOUNT_QUANTITY_KIND),
40
+ rawAmountAvailable: z.literal(false),
41
+ notFor: z.tuple([
42
+ z.literal("signing"),
43
+ z.literal("funding"),
44
+ z.literal("route_liquidity"),
45
+ z.literal("withdrawal_readiness"),
46
+ z.literal("transaction_building")
47
+ ])
48
+ });
49
+ const deepbookMidPriceSemanticsSchema = z.object({
50
+ kind: z.literal(DEEPBOOK_MID_PRICE_SEMANTICS_KIND),
51
+ allowedUse: z.literal("deepbook_pool_mid_price_snapshot"),
52
+ globalMarketPriceAvailable: z.literal(false),
53
+ fiatUsdCashOutAvailable: z.literal(false),
54
+ externalMarketPriceConversionAvailable: z.literal(false),
55
+ externalMarketLookupAvailable: z.literal(false),
56
+ usdPegAssumptionAvailable: z.literal(false),
57
+ bankCashOutEstimateAvailable: z.literal(false),
58
+ quoteComparisonAvailable: z.literal(false),
59
+ priceImpactAvailable: z.literal(false),
60
+ venueComparisonAvailable: z.literal(false),
61
+ routeRecommendationAvailable: z.literal(false),
62
+ profitAndLossAvailable: z.literal(false),
63
+ costBasisAvailable: z.literal(false),
64
+ notFor: z.tuple([
65
+ z.literal("global_market_price"),
66
+ z.literal("fiat_usd_cash_out"),
67
+ z.literal("external_market_price_conversion"),
68
+ z.literal("external_market_lookup"),
69
+ z.literal("usd_peg_assumption"),
70
+ z.literal("bank_cash_out_estimate"),
71
+ z.literal("price_impact"),
72
+ z.literal("mid_price_slippage"),
73
+ z.literal("quote_vs_mid_slippage"),
74
+ z.literal("effective_quote_price"),
75
+ z.literal("venue_comparison"),
76
+ z.literal("best_route"),
77
+ z.literal("route_recommendation"),
78
+ z.literal("transaction_building"),
79
+ z.literal("signing_data"),
80
+ z.literal("signing_readiness"),
81
+ z.literal("profit_or_pnl"),
82
+ z.literal("cost_basis")
83
+ ])
84
+ });
85
+ const deepbookUsdcPriceHistorySelectorSchema = z.union([
86
+ z.object({ kind: z.literal("pool_name"), value: z.string().min(1) }).strict(),
87
+ z.object({ kind: z.literal("asset_symbol"), value: z.string().min(1) }).strict(),
88
+ z.object({ kind: z.literal("coin_type"), value: z.string().min(1) }).strict()
89
+ ]);
90
+ const deepbookUsdcPriceHistoryRangeSchema = z.object({
91
+ start: fetchedAtSchema,
92
+ end: fetchedAtSchema,
93
+ timeZone: z.literal("UTC"),
94
+ interval: deepbookOfficialIndexerIntervalSchema,
95
+ intervalDurationMs: z.number().int().positive(),
96
+ maxBars: z.literal(MAX_DEEPBOOK_USDC_PRICE_HISTORY_BARS),
97
+ requestedCandleSlots: z.number().int().positive()
98
+ }).strict();
99
+ const deepbookUsdcPriceHistoryRequestedSchema = z.object({
100
+ selector: deepbookUsdcPriceHistorySelectorSchema,
101
+ range: deepbookUsdcPriceHistoryRangeSchema
102
+ }).strict();
103
+ const deepbookUsdcPriceHistoryPairSchema = z.object({
104
+ poolName: z.string().min(1),
105
+ poolId: z.string().min(1),
106
+ baseAsset: z.object({
107
+ symbol: z.string().min(1),
108
+ coinType: z.string().min(1),
109
+ decimals: z.number().int().nonnegative()
110
+ }).strict(),
111
+ quoteAsset: z.object({
112
+ symbol: z.literal("USDC"),
113
+ coinType: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANONICAL_USDC_COIN_TYPE),
114
+ decimals: z.number().int().nonnegative()
115
+ }).strict(),
116
+ priceConvention: z.literal(DEEPBOOK_OFFICIAL_INDEXER_USDC_REFERENCE.priceConvention)
117
+ }).strict();
118
+ const deepbookUsdcPriceHistorySourceSchema = z.object({
119
+ kind: z.literal(DEEPBOOK_OFFICIAL_INDEXER_SOURCE_BASE.kind),
120
+ baseUrl: z.url(),
121
+ sourceStatement: z.string().min(1),
122
+ poolList: z.object({
123
+ url: z.url(),
124
+ fetchedAt: fetchedAtSchema
125
+ }).strict(),
126
+ candles: z.object({
127
+ url: z.url(),
128
+ fetchedAt: fetchedAtSchema,
129
+ poolName: z.string().min(1),
130
+ interval: deepbookOfficialIndexerIntervalSchema,
131
+ startTimeMs: z.number().int().nonnegative(),
132
+ endTimeMs: z.number().int().nonnegative(),
133
+ limit: z.number().int().positive()
134
+ }).strict(),
135
+ chainRecomputedBySuiMcp: z.literal(DEEPBOOK_OFFICIAL_INDEXER_SOURCE_BASE.chainRecomputedBySuiMcp)
136
+ }).strict();
137
+ const deepbookUsdcPriceHistoryUnsupportedClaimSchema = z.enum(DEEPBOOK_USDC_PRICE_HISTORY_UNSUPPORTED_CLAIMS);
138
+ const deepbookUsdcPriceHistoryQuantitySemanticsSchema = z.object({
139
+ kind: z.literal(DEEPBOOK_USDC_PRICE_HISTORY_QUANTITY_KIND),
140
+ allowedUse: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.allowedUse),
141
+ source: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.source),
142
+ quoteAsset: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.quoteAsset),
143
+ priceConvention: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.priceConvention),
144
+ usdcIsFiatUsd: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.usdcIsFiatUsd),
145
+ usdPegGuaranteeAvailable: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.usdPegGuaranteeAvailable),
146
+ chainRecomputedBySuiMcp: z.literal(DEEPBOOK_OFFICIAL_INDEXER_CANDLE_USE.chainRecomputedBySuiMcp),
147
+ liveQuoteAvailable: z.literal(false),
148
+ historicalMidPriceAvailable: z.literal(false),
149
+ globalMarketPriceAvailable: z.literal(false),
150
+ fiatUsdCashOutAvailable: z.literal(false),
151
+ routeRecommendationAvailable: z.literal(false),
152
+ transactionBuildingAvailable: z.literal(false),
153
+ signingReadinessAvailable: z.literal(false),
154
+ profitAndLossAvailable: z.literal(false),
155
+ costBasisAvailable: z.literal(false),
156
+ notFor: z.tuple([
157
+ z.literal("fiat_usd_cash_out"),
158
+ z.literal("usd_peg_assumption"),
159
+ z.literal("global_market_price"),
160
+ z.literal("historical_mid_price"),
161
+ z.literal("live_quote"),
162
+ z.literal("route_recommendation"),
163
+ z.literal("best_route"),
164
+ z.literal("transaction_building"),
165
+ z.literal("signing_data"),
166
+ z.literal("signing_readiness"),
167
+ z.literal("profit_or_pnl"),
168
+ z.literal("cost_basis")
169
+ ])
170
+ }).strict();
171
+ const deepbookUsdcPriceHistoryResponseSummarySchema = z.object({
172
+ questionKind: z.literal("deepbook_usdc_price_history"),
173
+ evidenceKind: z.literal("official_deepbook_indexer_candles"),
174
+ sourceStatement: z.literal(DEEPBOOK_OFFICIAL_INDEXER_RESPONSE_TEXT.sourceStatement),
175
+ usdcDisclaimer: z.literal(DEEPBOOK_OFFICIAL_INDEXER_RESPONSE_TEXT.usdcDisclaimer),
176
+ candleMeaning: z.literal("Each candle is returned by the DeepBookV3 official Indexer for the requested interval."),
177
+ excludedFromConclusion: z.array(deepbookUsdcPriceHistoryUnsupportedClaimSchema)
178
+ }).strict();
179
+ const deepbookUsdcPriceHistoryCommonOutputSchema = z.object({
180
+ fetchedAt: fetchedAtSchema,
181
+ requested: deepbookUsdcPriceHistoryRequestedSchema,
182
+ userAnswerUse: userAnswerUseSchema,
183
+ quantitySemantics: deepbookUsdcPriceHistoryQuantitySemanticsSchema,
184
+ responseSummary: deepbookUsdcPriceHistoryResponseSummarySchema,
185
+ unsupportedClaims: z.array(deepbookUsdcPriceHistoryUnsupportedClaimSchema)
186
+ }).strict();
187
+ const deepbookUsdcPriceHistoryOutputSchema = z.object({
188
+ ok: z.literal(true),
189
+ data: z.discriminatedUnion("status", [
190
+ deepbookUsdcPriceHistoryCommonOutputSchema.extend({
191
+ status: z.literal("ok"),
192
+ pair: deepbookUsdcPriceHistoryPairSchema,
193
+ candleAvailability: z.enum(DEEPBOOK_USDC_CANDLE_AVAILABILITY),
194
+ barCount: z.number().int().nonnegative().max(MAX_DEEPBOOK_USDC_PRICE_HISTORY_BARS),
195
+ bars: z.array(deepbookOfficialIndexerCandleSchema).max(MAX_DEEPBOOK_USDC_PRICE_HISTORY_BARS),
196
+ source: deepbookUsdcPriceHistorySourceSchema
197
+ }).strict(),
198
+ deepbookUsdcPriceHistoryCommonOutputSchema.extend({
199
+ status: z.literal("unsupported_pair"),
200
+ reason: z.enum(DEEPBOOK_USDC_PRICE_HISTORY_UNSUPPORTED_PAIR_REASONS),
201
+ matchingPoolNames: z.array(z.string()),
202
+ availablePoolNames: z.array(z.string())
203
+ }).strict(),
204
+ deepbookUsdcPriceHistoryCommonOutputSchema.extend({
205
+ status: z.literal("unsupported_range"),
206
+ reason: z.literal("requested_range_exceeds_max_bars")
207
+ }).strict(),
208
+ deepbookUsdcPriceHistoryCommonOutputSchema.extend({
209
+ status: z.literal("source_unavailable"),
210
+ reason: z.enum(DEEPBOOK_USDC_PRICE_HISTORY_SOURCE_UNAVAILABLE_REASONS),
211
+ pair: deepbookUsdcPriceHistoryPairSchema.optional(),
212
+ source: deepbookUsdcPriceHistorySourceSchema.optional()
213
+ }).strict()
214
+ ])
215
+ }).strict();
216
+ const deepbookUsdcPriceAtTimeTargetSchema = z.object({
217
+ targetTime: fetchedAtSchema,
218
+ searchWindow: z.object({
219
+ start: fetchedAtSchema,
220
+ end: fetchedAtSchema,
221
+ maxDistanceMinutes: z.number().int().positive()
222
+ }).strict()
223
+ }).strict();
224
+ const deepbookUsdcPriceAtTimeMatchSchema = z.object({
225
+ kind: z.enum(["exact_bucket", "nearest_before", "nearest_after"]),
226
+ distanceMinutes: z.number().nonnegative(),
227
+ representativePrice: z.object({
228
+ field: z.literal("matchedCandle.close"),
229
+ value: z.string().regex(/^\d+(?:\.\d+)?$/),
230
+ quoteAsset: z.literal(DEEPBOOK_OFFICIAL_INDEXER_USDC_REFERENCE.quoteAsset),
231
+ baseAssetSymbol: z.string().min(1),
232
+ priceConvention: z.literal(DEEPBOOK_OFFICIAL_INDEXER_USDC_REFERENCE.priceConvention)
233
+ }).strict()
234
+ }).strict();
235
+ const deepbookUsdcPriceAtTimeCommonOutputSchema = deepbookUsdcPriceHistoryCommonOutputSchema.extend({
236
+ target: deepbookUsdcPriceAtTimeTargetSchema
237
+ }).strict();
238
+ const deepbookUsdcPriceAtTimeOutputSchema = z.object({
239
+ ok: z.literal(true),
240
+ data: z.discriminatedUnion("status", [
241
+ deepbookUsdcPriceAtTimeCommonOutputSchema.extend({
242
+ status: z.literal("ok"),
243
+ pair: deepbookUsdcPriceHistoryPairSchema,
244
+ match: deepbookUsdcPriceAtTimeMatchSchema,
245
+ matchedCandle: deepbookOfficialIndexerCandleSchema,
246
+ candleAvailability: z.enum(DEEPBOOK_USDC_CANDLE_AVAILABILITY),
247
+ source: deepbookUsdcPriceHistorySourceSchema
248
+ }).strict(),
249
+ deepbookUsdcPriceAtTimeCommonOutputSchema.extend({
250
+ status: z.literal("no_price_in_search_window"),
251
+ pair: deepbookUsdcPriceHistoryPairSchema,
252
+ candleAvailability: z.enum(DEEPBOOK_USDC_CANDLE_AVAILABILITY),
253
+ source: deepbookUsdcPriceHistorySourceSchema
254
+ }).strict(),
255
+ deepbookUsdcPriceAtTimeCommonOutputSchema.extend({
256
+ status: z.literal("unsupported_pair"),
257
+ reason: z.enum(DEEPBOOK_USDC_PRICE_HISTORY_UNSUPPORTED_PAIR_REASONS),
258
+ matchingPoolNames: z.array(z.string()),
259
+ availablePoolNames: z.array(z.string())
260
+ }).strict(),
261
+ deepbookUsdcPriceAtTimeCommonOutputSchema.extend({
262
+ status: z.literal("unsupported_range"),
263
+ reason: z.literal("requested_range_exceeds_max_bars")
264
+ }).strict(),
265
+ deepbookUsdcPriceAtTimeCommonOutputSchema.extend({
266
+ status: z.literal("source_unavailable"),
267
+ reason: z.enum(DEEPBOOK_USDC_PRICE_HISTORY_SOURCE_UNAVAILABLE_REASONS),
268
+ pair: deepbookUsdcPriceHistoryPairSchema.optional(),
269
+ source: deepbookUsdcPriceHistorySourceSchema.optional()
270
+ }).strict()
271
+ ])
272
+ }).strict();
273
+ const deepbookQuoteQuantitySemanticsSchema = z.object({
274
+ kind: z.literal(DEEPBOOK_QUOTE_QUANTITY_KIND),
275
+ inputAmountKind: z.enum(["raw_u64", "display_source_amount_converted_to_raw_u64"]),
276
+ allowedUse: z.literal("indicative_deepbook_pool_quote"),
277
+ rawAmountAvailable: z.literal(true),
278
+ rawEvidenceField: z.literal("rawQuote"),
279
+ paymentCoverageAvailable: z.literal(false),
280
+ shortfallContributionAvailable: z.literal(false),
281
+ routeDependentPaymentSupportAvailable: z.literal(false),
282
+ requiresIntentEvidenceForCoverage: z.literal(true),
283
+ canUseForPaymentAnswer: z.literal(false),
284
+ canUseForShortfallAnswer: z.literal(false),
285
+ doNotCombineWithPaymentAnswer: z.literal(true),
286
+ requiredPaymentAnswerTool: z.literal("read.preview_intent_evidence"),
287
+ paymentAnswerUseBlockedReason: z.literal("quote_output_is_price_reference_not_payment_answer"),
288
+ requiredPaymentAnswerField: z.literal("responseSummary"),
289
+ fiatUsdCashOutAvailable: z.literal(false),
290
+ externalMarketPriceConversionAvailable: z.literal(false),
291
+ externalMarketLookupAvailable: z.literal(false),
292
+ usdPegAssumptionAvailable: z.literal(false),
293
+ bankCashOutEstimateAvailable: z.literal(false),
294
+ profitAndLossAvailable: z.literal(false),
295
+ costBasisAvailable: z.literal(false),
296
+ priceImpactAvailable: z.literal(false),
297
+ midPriceSlippageAvailable: z.literal(false),
298
+ venueComparisonAvailable: z.literal(false),
299
+ routeRecommendationAvailable: z.literal(false),
300
+ notFor: z.tuple([
301
+ z.literal("signing"),
302
+ z.literal("funding"),
303
+ z.literal("payment_coverage"),
304
+ z.literal("shortfall_contribution"),
305
+ z.literal("route_dependent_payment_support"),
306
+ z.literal("route_liquidity"),
307
+ z.literal("min_out"),
308
+ z.literal("liquidity_verdict"),
309
+ z.literal("price_impact"),
310
+ z.literal("mid_price_slippage"),
311
+ z.literal("quote_vs_mid_slippage"),
312
+ z.literal("effective_price"),
313
+ z.literal("venue_comparison"),
314
+ z.literal("best_route"),
315
+ z.literal("route_recommendation"),
316
+ z.literal("transaction_building"),
317
+ z.literal("fiat_usd_cash_out"),
318
+ z.literal("external_market_price_conversion"),
319
+ z.literal("external_market_lookup"),
320
+ z.literal("usd_peg_assumption"),
321
+ z.literal("bank_cash_out_estimate"),
322
+ z.literal("profit_or_pnl"),
323
+ z.literal("cost_basis")
324
+ ])
325
+ });
326
+ const deepbookDisplayQuoteInputAmountSchema = z.object({
327
+ display: z.string(),
328
+ raw: z.string().regex(/^[1-9]\d*$/),
329
+ asset: z.object({
330
+ symbol: z.string(),
331
+ coinType: z.string(),
332
+ decimals: z.number().int().nonnegative(),
333
+ unitSource: z.literal(DEEPBOOK_SCALAR_UNIT_SOURCE)
334
+ })
335
+ });
336
+ const deepbookDisplayQuoteSchema = z.object({
337
+ baseOut: z.string().regex(/^\d+(?:\.\d+)?$/),
338
+ quoteOut: z.string().regex(/^\d+(?:\.\d+)?$/),
339
+ deepRequired: z.string().regex(/^\d+(?:\.\d+)?$/)
340
+ });
341
+ const deepbookRawQuoteAmountSchema = z.object({
342
+ raw: z.string().regex(/^\d+$/),
343
+ symbol: z.string(),
344
+ coinType: z.string(),
345
+ decimals: z.number().int().nonnegative(),
346
+ unitSource: z.literal(DEEPBOOK_SCALAR_UNIT_SOURCE)
347
+ });
348
+ const deepbookRawQuoteSchema = z.object({
349
+ kind: z.literal("deepbook_quote_raw_u64"),
350
+ sourceMoveFunction: z.enum(["pool::get_quote_quantity_out", "pool::get_base_quantity_out"]),
351
+ returnValueSourceMoveFunction: z.literal("pool::get_quantity_out"),
352
+ returnValueOrder: z.tuple([
353
+ z.literal("base_quantity_out"),
354
+ z.literal("quote_quantity_out"),
355
+ z.literal("deep_quantity_required")
356
+ ]),
357
+ inputAmount: deepbookRawQuoteAmountSchema,
358
+ baseOut: deepbookRawQuoteAmountSchema,
359
+ quoteOut: deepbookRawQuoteAmountSchema,
360
+ deepRequired: deepbookRawQuoteAmountSchema,
361
+ directionalOutput: deepbookRawQuoteAmountSchema,
362
+ boundary: z.object({
363
+ outputBeforeSlippagePolicy: z.literal(true),
364
+ notFor: z.tuple([
365
+ z.literal("final_min_out"),
366
+ z.literal("transaction_building"),
367
+ z.literal("signing_data"),
368
+ z.literal("signing_readiness"),
369
+ z.literal("price_impact"),
370
+ z.literal("mid_price_slippage"),
371
+ z.literal("quote_vs_mid_slippage"),
372
+ z.literal("effective_price"),
373
+ z.literal("venue_comparison"),
374
+ z.literal("best_route"),
375
+ z.literal("route_recommendation"),
376
+ z.literal("fiat_usd_cash_out"),
377
+ z.literal("external_market_price_conversion"),
378
+ z.literal("external_market_lookup"),
379
+ z.literal("usd_peg_assumption"),
380
+ z.literal("bank_cash_out_estimate"),
381
+ z.literal("profit_or_pnl"),
382
+ z.literal("cost_basis")
383
+ ])
384
+ })
385
+ });
386
+ const deepbookAccountInventoryDetailStatusSchema = z.enum([
387
+ "manager_discovery_only",
388
+ "pool_key_required",
389
+ "manager_address_required",
390
+ "manager_address_not_discovered_for_active_account",
391
+ "account_not_found",
392
+ "available"
393
+ ]);
394
+ const deepbookAccountSummarySchema = z.object({
395
+ epoch: z.string(),
396
+ settledBalances: deepbookDisplayAccountBalancesSchema,
397
+ owedBalances: deepbookDisplayAccountBalancesSchema,
398
+ unclaimedRebates: deepbookDisplayAccountBalancesSchema
399
+ });
400
+ const deepbookTokenRegistryEntrySchema = z.object({
401
+ symbol: z.string(),
402
+ address: z.string(),
403
+ type: z.string(),
404
+ scalar: z.number(),
405
+ decimals: z.number().int().nonnegative(),
406
+ unitSource: z.literal(DEEPBOOK_SCALAR_UNIT_SOURCE),
407
+ feed: z.string().optional(),
408
+ currencyId: z.string().optional(),
409
+ priceInfoObjectId: z.string().optional(),
410
+ poolKeys: z.array(z.string())
411
+ });
412
+ export function registerDeepbookReadTools(server, deps) {
413
+ server.registerTool(TOOL_NAMES.readListDeepbookPools, {
414
+ title: "List DeepBook pools",
415
+ description: "List DeepBook mainnet pools from pinned SDK constants. Static registry only; not live liquidity.",
416
+ inputSchema: noParamsInputSchema,
417
+ outputSchema: successOutputSchema({
418
+ source: z.string(),
419
+ pools: z.array(unknownRecordSchema)
420
+ }),
421
+ annotations: { readOnlyHint: true, openWorldHint: false }
422
+ }, async () => okToolResult({
423
+ source: "@mysten/deepbook-v3 mainnetPools",
424
+ pools: Object.entries(mainnetPools).map(([key, pool]) => ({ key, ...pool }))
425
+ }));
426
+ server.registerTool(TOOL_NAMES.readListDeepbookTokens, {
427
+ title: "List DeepBook tokens",
428
+ description: "List DeepBook mainnet tokens from the pinned SDK constants.",
429
+ inputSchema: noParamsInputSchema,
430
+ outputSchema: successOutputSchema({
431
+ source: z.string(),
432
+ tokens: z.array(deepbookTokenRegistryEntrySchema)
433
+ }),
434
+ annotations: { readOnlyHint: true, openWorldHint: false }
435
+ }, async () => {
436
+ try {
437
+ return okToolResult({
438
+ source: "@mysten/deepbook-v3 mainnetCoins",
439
+ tokens: deps.readService.listDeepbookTokenRegistry()
440
+ });
441
+ }
442
+ catch (error) {
443
+ return readServiceError(error, deps);
444
+ }
445
+ });
446
+ server.registerTool(TOOL_NAMES.readInspectDeepbookOrderbook, {
447
+ title: "Inspect DeepBook orderbook",
448
+ description: "Return a pinned-SDK DeepBook mainnet orderbook snapshot at fetchedAt. Not a live stream.",
449
+ inputSchema: {
450
+ poolKey: z.string().min(1),
451
+ ticks: z.number().int().min(1).max(MAX_DEEPBOOK_ORDERBOOK_TICKS).optional()
452
+ },
453
+ outputSchema: successOutputSchema({
454
+ status: z.literal("ok"),
455
+ poolKey: z.string().optional(),
456
+ ticks: z.number().int().positive().optional(),
457
+ fetchedAt: fetchedAtSchema.optional(),
458
+ userAnswerUse: userAnswerUseSchema,
459
+ source: readSourceSchema.optional(),
460
+ midPrice: z.number().optional(),
461
+ poolBookParams: unknownRecordSchema.optional(),
462
+ level2TicksFromMid: unknownRecordSchema.optional()
463
+ }),
464
+ annotations: { readOnlyHint: true, openWorldHint: false }
465
+ }, async ({ poolKey, ticks }) => {
466
+ try {
467
+ return okToolResult(await deps.readService.inspectDeepbookOrderbook({
468
+ poolKey,
469
+ ticks: ticks ?? 5,
470
+ simulationSender: DEFAULT_DEEPBOOK_SIMULATION_SENDER
471
+ }));
472
+ }
473
+ catch (error) {
474
+ return readServiceError(error, deps);
475
+ }
476
+ });
477
+ server.registerTool(TOOL_NAMES.readGetDeepbookMidPrice, {
478
+ title: "Get DeepBook mid price",
479
+ description: "Return a DeepBook pool mid-price snapshot. Not price impact, route quality, global market price, fiat cash-out, transaction building, or signing readiness.",
480
+ inputSchema: {
481
+ poolKey: z.string().min(1)
482
+ },
483
+ outputSchema: successOutputSchema({
484
+ status: z.literal("ok"),
485
+ poolKey: z.string(),
486
+ base: z.string(),
487
+ quote: z.string(),
488
+ price: z.number(),
489
+ userAnswerUse: userAnswerUseSchema,
490
+ priceDirection: z.literal(DEEPBOOK_MID_PRICE_DIRECTION),
491
+ priceType: z.literal(DEEPBOOK_MID_PRICE_TYPE),
492
+ fetchedAt: fetchedAtSchema,
493
+ source: deepbookMidPriceSourceSchema,
494
+ priceSemantics: deepbookMidPriceSemanticsSchema
495
+ }),
496
+ annotations: { readOnlyHint: true, openWorldHint: false }
497
+ }, async ({ poolKey }) => {
498
+ try {
499
+ return okToolResult(await deps.readService.getDeepbookMidPrice({
500
+ poolKey,
501
+ simulationSender: DEFAULT_DEEPBOOK_SIMULATION_SENDER
502
+ }));
503
+ }
504
+ catch (error) {
505
+ return readServiceError(error, deps);
506
+ }
507
+ });
508
+ server.registerTool(TOOL_NAMES.readGetDeepbookUsdcPriceHistory, {
509
+ title: "Get DeepBook USDC price history",
510
+ description: "Return DeepBookV3 official Indexer USDC candle evidence.",
511
+ inputSchema: {
512
+ poolName: z.string().min(1).optional(),
513
+ assetSymbol: z.string().min(1).optional(),
514
+ coinType: z.string().min(1).optional(),
515
+ interval: deepbookOfficialIndexerIntervalSchema.optional(),
516
+ start: fetchedAtSchema,
517
+ end: fetchedAtSchema
518
+ },
519
+ outputSchema: deepbookUsdcPriceHistoryOutputSchema,
520
+ annotations: { readOnlyHint: true, openWorldHint: false }
521
+ }, async ({ poolName, assetSymbol, coinType, interval, start, end }) => {
522
+ try {
523
+ return okToolResult(await deps.readService.getDeepbookUsdcPriceHistory({
524
+ poolName,
525
+ assetSymbol,
526
+ coinType,
527
+ interval,
528
+ start,
529
+ end
530
+ }));
531
+ }
532
+ catch (error) {
533
+ return readServiceError(error, deps);
534
+ }
535
+ });
536
+ server.registerTool(TOOL_NAMES.readGetDeepbookUsdcPriceAtTime, {
537
+ title: "Get DeepBook USDC price at time",
538
+ description: "Return DeepBookV3 official Indexer USDC candle evidence and representative price from close around a target UTC time.",
539
+ inputSchema: {
540
+ poolName: z.string().min(1).optional(),
541
+ assetSymbol: z.string().min(1).optional(),
542
+ coinType: z.string().min(1).optional(),
543
+ interval: deepbookOfficialIndexerIntervalSchema.optional(),
544
+ targetTime: fetchedAtSchema,
545
+ maxDistanceMinutes: z.number().int().positive().optional()
546
+ },
547
+ outputSchema: deepbookUsdcPriceAtTimeOutputSchema,
548
+ annotations: { readOnlyHint: true, openWorldHint: false }
549
+ }, async ({ poolName, assetSymbol, coinType, interval, targetTime, maxDistanceMinutes }) => {
550
+ try {
551
+ return okToolResult(await deps.readService.getDeepbookUsdcPriceAtTime({
552
+ poolName,
553
+ assetSymbol,
554
+ coinType,
555
+ interval,
556
+ targetTime,
557
+ maxDistanceMinutes
558
+ }));
559
+ }
560
+ catch (error) {
561
+ return readServiceError(error, deps);
562
+ }
563
+ });
564
+ server.registerTool(TOOL_NAMES.readQuoteDeepbookAction, {
565
+ title: "Quote DeepBook action",
566
+ description: "Pinned-SDK DeepBook raw-quantity quote evidence. Not P&L, price impact, route quality, fiat cash-out, external USD lookup, signing data, or execution promise.",
567
+ inputSchema: {
568
+ poolKey: z.string().min(1),
569
+ direction: z.enum(["base_to_quote", "quote_to_base"]),
570
+ amountRaw: z.string().regex(/^[1-9]\d*$/)
571
+ },
572
+ outputSchema: successOutputSchema({
573
+ status: z.literal("ok"),
574
+ poolKey: z.string().optional(),
575
+ direction: z.enum(["base_to_quote", "quote_to_base"]).optional(),
576
+ amountRaw: z.string().optional(),
577
+ fetchedAt: fetchedAtSchema.optional(),
578
+ userAnswerUse: userAnswerUseSchema,
579
+ source: readSourceSchema.optional(),
580
+ quote: deepbookDisplayQuoteSchema.optional(),
581
+ rawQuote: deepbookRawQuoteSchema.optional(),
582
+ quantitySemantics: deepbookQuoteQuantitySemanticsSchema.optional()
583
+ }),
584
+ annotations: { readOnlyHint: true, openWorldHint: false }
585
+ }, async ({ poolKey, direction, amountRaw }) => {
586
+ try {
587
+ return okToolResult(await deps.readService.quoteDeepbookAction({
588
+ poolKey,
589
+ direction,
590
+ amountRaw,
591
+ simulationSender: DEFAULT_DEEPBOOK_SIMULATION_SENDER
592
+ }));
593
+ }
594
+ catch (error) {
595
+ return readServiceError(error, deps);
596
+ }
597
+ });
598
+ server.registerTool(TOOL_NAMES.readQuoteDeepbookDisplayAmount, {
599
+ title: "Quote DeepBook display amount",
600
+ description: "Pinned-SDK DeepBook display-amount quote evidence. Not fiat cash-out, external USD lookup, P&L, price impact, route, final min-out, signing data, or signing readiness.",
601
+ inputSchema: {
602
+ poolKey: z.string().min(1),
603
+ direction: z.enum(["base_to_quote", "quote_to_base"]),
604
+ amountDisplay: z.string().min(1)
605
+ },
606
+ outputSchema: successOutputSchema({
607
+ status: z.literal("ok"),
608
+ pool: z.object({
609
+ poolKey: z.string(),
610
+ base: z.string(),
611
+ quote: z.string()
612
+ }),
613
+ direction: z.enum(["base_to_quote", "quote_to_base"]),
614
+ inputAmount: deepbookDisplayQuoteInputAmountSchema,
615
+ fetchedAt: fetchedAtSchema,
616
+ userAnswerUse: userAnswerUseSchema,
617
+ source: deepbookDisplayQuoteSourceSchema,
618
+ quote: deepbookDisplayQuoteSchema,
619
+ rawQuote: deepbookRawQuoteSchema,
620
+ quantitySemantics: deepbookQuoteQuantitySemanticsSchema
621
+ }),
622
+ annotations: { readOnlyHint: true, openWorldHint: false }
623
+ }, async ({ poolKey, direction, amountDisplay }) => {
624
+ try {
625
+ return okToolResult(await deps.readService.quoteDeepbookDisplayAmount({
626
+ poolKey,
627
+ direction,
628
+ amountDisplay,
629
+ simulationSender: DEFAULT_DEEPBOOK_SIMULATION_SENDER
630
+ }));
631
+ }
632
+ catch (error) {
633
+ return readServiceError(error, deps);
634
+ }
635
+ });
636
+ server.registerTool(TOOL_NAMES.readSummarizeDeepbookAccountInventory, {
637
+ title: "Summarize DeepBook account inventory",
638
+ description: "Pinned-SDK DeepBook BalanceManager inventory. Display-like facts, not raw amounts or signing readiness.",
639
+ inputSchema: {
640
+ poolKey: z.string().min(1).optional(),
641
+ managerAddress: z.string().min(1).optional()
642
+ },
643
+ outputSchema: successOutputSchema({
644
+ account: z.string(),
645
+ status: z.literal("ok"),
646
+ fetchedAt: fetchedAtSchema,
647
+ source: deepbookAccountInventorySourceSchema,
648
+ requested: z.object({
649
+ poolKey: z.string().optional(),
650
+ managerAddress: z.string().optional()
651
+ }),
652
+ detailStatus: deepbookAccountInventoryDetailStatusSchema,
653
+ managerAddresses: z.array(z.string()),
654
+ userAnswerUse: userAnswerUseSchema,
655
+ quantitySemantics: deepbookAccountQuantitySemanticsSchema,
656
+ pool: z
657
+ .object({
658
+ poolKey: z.string(),
659
+ base: z.string(),
660
+ quote: z.string()
661
+ })
662
+ .optional(),
663
+ accountExists: z.boolean().optional(),
664
+ accountSummary: deepbookAccountSummarySchema.optional(),
665
+ lockedBalances: deepbookDisplayAccountBalancesSchema.optional(),
666
+ openOrderIds: z.array(z.string()).max(MAX_DEEPBOOK_ACCOUNT_OPEN_ORDER_IDS).optional(),
667
+ openOrderCount: z.number().int().nonnegative().optional(),
668
+ openOrderIdsTruncated: z.boolean().optional()
669
+ }),
670
+ annotations: { readOnlyHint: true, openWorldHint: false }
671
+ }, async ({ poolKey, managerAddress }) => {
672
+ const target = await resolveExplicitOrActiveAccount({ mode: "connected_only" }, deps);
673
+ if (target.status !== "ok")
674
+ return target.result;
675
+ try {
676
+ return okToolResult(await deps.readService.summarizeDeepbookAccountInventory({
677
+ account: target.account,
678
+ poolKey,
679
+ managerAddress
680
+ }));
681
+ }
682
+ catch (error) {
683
+ return readServiceError(error, deps);
684
+ }
685
+ });
686
+ }