@ocap/types 1.28.9 → 1.29.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.
@@ -0,0 +1,503 @@
1
+ // core/types/interfaces/resolver.ts
2
+ // Shared types for GraphQL resolver interface
3
+ //
4
+ // NOTE: This file defines the contract between resolver implementations (like OCAPResolver)
5
+ // and consumers (like @ocap/gql). Return types are flexible because:
6
+ // 1. Resolvers transform data before returning (e.g., formatTx, formatTokenMap)
7
+ // 2. Info methods construct objects rather than fetching exact Proto types
8
+ // 3. List methods use resolver-specific paging (IPaging) instead of IndexDB paging (TPageInfo)
9
+
10
+ // ============ Import Proto types ============
11
+ import type {
12
+ TRequestEstimateGas,
13
+ TRequestGetAccountState,
14
+ TRequestGetAccountTokens,
15
+ TRequestGetEvidenceState,
16
+ TRequestGetRollupBlock,
17
+ TRequestGetState,
18
+ TRequestGetTokenDistribution,
19
+ TRequestGetTx,
20
+ TRequestListAssetTransactions,
21
+ TRequestListAssets,
22
+ TRequestListDelegations,
23
+ TRequestListFactories,
24
+ TRequestListRollupBlocks,
25
+ TRequestListRollupValidators,
26
+ TRequestListRollups,
27
+ TRequestListStakes,
28
+ TRequestListTokenFactories,
29
+ TRequestListTokenFlows,
30
+ TRequestListTokens,
31
+ TRequestListTopAccounts,
32
+ TRequestListTransactions,
33
+ TRequestSearch,
34
+ TRequestVerifyAccountRisk,
35
+ } from '../lib/rpc_pb';
36
+
37
+ import type { TGasEstimate } from '../lib/type_pb';
38
+
39
+ import type {
40
+ TIndexedTokenFlow,
41
+ TSearchResult,
42
+ TTokenDistribution,
43
+ TTokenMeta,
44
+ TVerifyAccountRiskResult,
45
+ } from '../lib/trace-type_pb';
46
+
47
+ // ============ Import interface types ============
48
+ import type { RequiredBy } from './base';
49
+ import type {
50
+ IAccountState,
51
+ IAssetFactoryState,
52
+ IAssetState,
53
+ IDelegateState,
54
+ IEvidenceState,
55
+ IForeignToken,
56
+ IRollupBlock,
57
+ IRollupState,
58
+ IRollupValidator,
59
+ IStakeState,
60
+ ITokenFactoryState,
61
+ ITokenState,
62
+ TokenBalanceMap,
63
+ } from './state';
64
+
65
+ import type { TTransactionReceipt } from '../lib/type_pb';
66
+ import type { TPageInfo } from './indexdb';
67
+
68
+ // Note: We don't import IList*Result from indexdb because resolver uses its own paging format
69
+
70
+ // ============ Resolver Context ============
71
+
72
+ /**
73
+ * Request context passed to resolver methods from HTTP request
74
+ * Index signature allows compatibility with Record<string, unknown>
75
+ */
76
+ export interface IResolverContext {
77
+ featureSwitch: Record<string, unknown>;
78
+ gasStakeHeaders: { token: string; pk: string };
79
+ request: { userAgent: string | undefined; ip: string; id: string };
80
+ [key: string]: unknown;
81
+ }
82
+
83
+ // ============ Extended Request Args (Proto types missing fields) ============
84
+
85
+ /**
86
+ * getAccountState args - extends TRequestGetAccountState with expandContext
87
+ */
88
+ export interface IGetAccountStateArgs extends Partial<TRequestGetAccountState> {
89
+ address: string;
90
+ expandContext?: boolean;
91
+ }
92
+
93
+ /**
94
+ * getAccountTokens args - token is optional (Proto requires it)
95
+ */
96
+ export type IGetAccountTokensArgs = RequiredBy<Partial<TRequestGetAccountTokens>, 'address'>;
97
+
98
+ // ============ Token Info (Resolver formatted) ============
99
+
100
+ /**
101
+ * Token info with balance - extends TTokenMeta with additional fields
102
+ * Used for formatted token data in resolver responses
103
+ */
104
+ export interface ITokenInfo extends Partial<TTokenMeta> {
105
+ address: string;
106
+ foreignToken?: IForeignToken | null;
107
+ /** Token value for inputs/outputs */
108
+ value?: string;
109
+ }
110
+
111
+ // ============ Extended State Types (tokens field format differs) ============
112
+
113
+ /**
114
+ * Extended account state for resolver - tokens as ITokenInfo[] instead of TokenBalanceMap
115
+ */
116
+ export interface IResolverAccountState extends Omit<IAccountState, 'tokens'> {
117
+ tokens?: ITokenInfo[] | TokenBalanceMap;
118
+ }
119
+
120
+ /**
121
+ * Extended stake state for resolver - tokens/revokedTokens as ITokenInfo[]
122
+ */
123
+ export interface IResolverStakeState extends Omit<IStakeState, 'tokens' | 'revokedTokens'> {
124
+ tokens?: ITokenInfo[] | TokenBalanceMap;
125
+ revokedTokens?: ITokenInfo[] | TokenBalanceMap;
126
+ }
127
+
128
+ /**
129
+ * Extended rollup state for resolver - with tokenInfo and statistics
130
+ */
131
+ export interface IResolverRollupState extends IRollupState {
132
+ tokenInfo?: ITokenInfo;
133
+ foreignToken?: IForeignToken | null;
134
+ totalDepositAmount?: string;
135
+ totalWithdrawAmount?: string;
136
+ }
137
+
138
+ /**
139
+ * Extended factory state for resolver - tokens as ITokenInfo[]
140
+ */
141
+ export interface IResolverFactoryState extends Omit<IAssetFactoryState, 'tokens'> {
142
+ tokens?: ITokenInfo[] | TokenBalanceMap;
143
+ }
144
+
145
+ // ============ Resolver Response Types ============
146
+
147
+ /**
148
+ * Token flows list result
149
+ */
150
+ export interface ITokenFlowsResult {
151
+ data: TIndexedTokenFlow[];
152
+ paging?: TPageInfo;
153
+ }
154
+
155
+ /**
156
+ * Search result wrapper
157
+ */
158
+ export interface ISearchResult {
159
+ results: TSearchResult[];
160
+ }
161
+
162
+ /**
163
+ * Estimate gas result
164
+ */
165
+ export interface IEstimateGasResult {
166
+ estimate: TGasEstimate;
167
+ }
168
+
169
+ /**
170
+ * Empty blocks result (placeholder)
171
+ */
172
+ export interface IBlocksResult {
173
+ blocks: never[];
174
+ }
175
+
176
+ // ============ Address Args Helper ============
177
+
178
+ /**
179
+ * Simple address args - used by multiple state getters
180
+ */
181
+ export type IAddressArgs = Pick<TRequestGetState, 'address'>;
182
+
183
+ // ============ Resolver Paging ============
184
+
185
+ /**
186
+ * Resolver paging - simpler than TPageInfo, used by list methods
187
+ */
188
+ export interface IResolverPaging {
189
+ size?: number;
190
+ cursor?: string | number;
191
+ order?: { field: string; type: string };
192
+ total?: number;
193
+ next?: boolean;
194
+ }
195
+
196
+ // ============ Resolver Transaction ============
197
+
198
+ /**
199
+ * Transaction inner JSON structure
200
+ */
201
+ export interface IResolverTxItxJson {
202
+ _type?: string;
203
+ type_url?: string;
204
+ data?: Record<string, unknown>;
205
+ address?: string;
206
+ factory?: string;
207
+ rollup?: string;
208
+ tokenFactory?: string;
209
+ evidence?: { hash: string };
210
+ sender?: { tokens: ITokenInfo[] };
211
+ receiver?: { tokens: ITokenInfo[] };
212
+ tokens?: ITokenInfo[];
213
+ inputs?: Array<{ tokens: ITokenInfo[] }>;
214
+ outputs?: Array<{ tokens: ITokenInfo[] }>;
215
+ withdraw_tx_hash?: string;
216
+ token?: Partial<ITokenState>;
217
+ endpoint?: string;
218
+ actualFee?: string;
219
+ [key: string]: unknown;
220
+ }
221
+
222
+ /**
223
+ * Transaction in resolver format - returned by getTx, listTransactions, etc.
224
+ * Different from TIndexedTransaction: resolver adds formatted tokens, receipts, etc.
225
+ */
226
+ export interface IResolverTransaction {
227
+ hash: string;
228
+ time: string;
229
+ code?: string;
230
+ sender?: string;
231
+ receiver?: string;
232
+ receipts?: TTransactionReceipt[];
233
+ tokenSymbols?: ITokenInfo[];
234
+ accounts?: string[];
235
+ tx: {
236
+ from: string;
237
+ itx: { typeUrl: string };
238
+ itxJson: IResolverTxItxJson;
239
+ signatures?: Array<{ signer: string }>;
240
+ [key: string]: unknown;
241
+ };
242
+ [key: string]: unknown;
243
+ }
244
+
245
+ // ============ Resolver List Results ============
246
+
247
+ /**
248
+ * Base list result with resolver paging
249
+ */
250
+ interface IResolverListResult {
251
+ paging?: IResolverPaging;
252
+ }
253
+
254
+ /**
255
+ * Transactions list result
256
+ */
257
+ export interface IResolverListTransactionsResult extends IResolverListResult {
258
+ transactions: IResolverTransaction[];
259
+ }
260
+
261
+ /**
262
+ * Assets list result
263
+ */
264
+ export interface IResolverListAssetsResult extends IResolverListResult {
265
+ assets: IAssetState[];
266
+ account?: IResolverAccountState;
267
+ }
268
+
269
+ /**
270
+ * Accounts list result
271
+ */
272
+ export interface IResolverListAccountsResult extends IResolverListResult {
273
+ accounts: IResolverAccountState[];
274
+ }
275
+
276
+ /**
277
+ * Tokens list result
278
+ */
279
+ export interface IResolverListTokensResult extends IResolverListResult {
280
+ tokens: ITokenState[];
281
+ }
282
+
283
+ /**
284
+ * Factories list result
285
+ */
286
+ export interface IResolverListFactoriesResult extends IResolverListResult {
287
+ factories: IResolverFactoryState[];
288
+ }
289
+
290
+ /**
291
+ * Stakes list result
292
+ */
293
+ export interface IResolverListStakesResult extends IResolverListResult {
294
+ stakes: IResolverStakeState[];
295
+ }
296
+
297
+ /**
298
+ * Delegations list result
299
+ */
300
+ export interface IResolverListDelegationsResult extends IResolverListResult {
301
+ delegations: IDelegateState[];
302
+ }
303
+
304
+ /**
305
+ * Rollups list result
306
+ */
307
+ export interface IResolverListRollupsResult extends IResolverListResult {
308
+ rollups: IResolverRollupState[];
309
+ }
310
+
311
+ /**
312
+ * Rollup blocks list result
313
+ */
314
+ export interface IResolverListRollupBlocksResult extends IResolverListResult {
315
+ blocks: IRollupBlock[];
316
+ }
317
+
318
+ /**
319
+ * Rollup validators list result
320
+ */
321
+ export interface IResolverListRollupValidatorsResult extends IResolverListResult {
322
+ validators: Array<IRollupValidator & { availableStake?: string }>;
323
+ }
324
+
325
+ /**
326
+ * Token factories list result
327
+ */
328
+ export interface IResolverListTokenFactoriesResult extends IResolverListResult {
329
+ tokenFactories: ITokenFactoryState[];
330
+ }
331
+
332
+ // ============ Resolver Info Types ============
333
+
334
+ /**
335
+ * Chain info returned by getChainInfo
336
+ * Constructed by resolver, not fetched from Proto
337
+ */
338
+ export interface IResolverChainInfo {
339
+ id: string;
340
+ totalTxs?: number;
341
+ blockHash?: string;
342
+ blockHeight?: number;
343
+ blockTime?: string;
344
+ version?: string;
345
+ address?: string;
346
+ appHash?: string;
347
+ consensusVersion?: string;
348
+ forgeAppsVersion?: string[];
349
+ moniker?: string;
350
+ network?: string;
351
+ supportedTxs?: string[];
352
+ synced?: boolean;
353
+ votingPower?: string;
354
+ [key: string]: unknown;
355
+ }
356
+
357
+ /**
358
+ * Node info returned by getNodeInfo
359
+ */
360
+ export interface IResolverNodeInfo {
361
+ id: string;
362
+ address?: string;
363
+ appHash?: string;
364
+ consensusVersion?: string;
365
+ forgeAppsVersion?: string[];
366
+ geoInfo?: {
367
+ city?: string;
368
+ country?: string;
369
+ latitude?: number;
370
+ longitude?: number;
371
+ };
372
+ ip?: string;
373
+ moniker?: string;
374
+ network?: string;
375
+ p2pAddress?: string;
376
+ supportedTxs?: string[];
377
+ synced?: boolean;
378
+ votingPower?: string;
379
+ [key: string]: unknown;
380
+ }
381
+
382
+ /**
383
+ * Net info returned by getNetInfo
384
+ */
385
+ export interface IResolverNetInfo {
386
+ listening: boolean;
387
+ listeners: string[];
388
+ nPeers: number;
389
+ peers: unknown[];
390
+ [key: string]: unknown;
391
+ }
392
+
393
+ /**
394
+ * Validators info returned by getValidatorsInfo
395
+ */
396
+ export interface IResolverValidatorsInfo {
397
+ blockHeight: number;
398
+ validators: Array<{
399
+ address: string;
400
+ name?: string;
401
+ proposerPriority?: string;
402
+ votingPower?: string;
403
+ }>;
404
+ [key: string]: unknown;
405
+ }
406
+
407
+ /**
408
+ * Forge stats returned by getForgeStats
409
+ * Note: Values can be string or number due to legacy data formats
410
+ */
411
+ export interface IResolverForgeStats {
412
+ numBlocks?: (string | number)[];
413
+ numTxs?: (string | number)[];
414
+ numStakes?: (string | number)[];
415
+ numValidators?: (string | number)[];
416
+ numAccounts?: (string | number)[];
417
+ numAssets?: (string | number)[];
418
+ tps?: (string | number)[];
419
+ [key: string]: unknown;
420
+ }
421
+
422
+ // ============ Main IResolver Interface ============
423
+
424
+ /**
425
+ * Complete resolver interface with typed methods
426
+ * Used by @ocap/gql to accept resolver implementations like OCAPResolver
427
+ */
428
+ export interface IResolver {
429
+ // ============ Transaction ============
430
+ sendTx(args: { tx: string; extra?: Record<string, unknown> }, ctx?: IResolverContext): Promise<string>;
431
+
432
+ // ============ Single State Getters ============
433
+ getTx(args: TRequestGetTx, ctx?: IResolverContext): Promise<IResolverTransaction | null>;
434
+ getBlock(): null;
435
+ getBlocks(): never[];
436
+ getUnconfirmedTxs(): never[];
437
+
438
+ getAccountState(args: IGetAccountStateArgs, ctx?: IResolverContext): Promise<IResolverAccountState | null>;
439
+ getAssetState(args: IAddressArgs, ctx?: IResolverContext): Promise<IAssetState | null>;
440
+ getFactoryState(args: IAddressArgs, ctx?: IResolverContext): Promise<IResolverFactoryState | null>;
441
+ getTokenState(args: IAddressArgs, ctx?: IResolverContext): Promise<ITokenState | null>;
442
+ getStakeState(args: IAddressArgs, ctx?: IResolverContext): Promise<IResolverStakeState | null>;
443
+ getRollupState(args: IAddressArgs, ctx?: IResolverContext): Promise<IResolverRollupState | null>;
444
+ getRollupBlock(args: Partial<TRequestGetRollupBlock>, ctx?: IResolverContext): Promise<IRollupBlock | null>;
445
+ getDelegateState(args: IAddressArgs, ctx?: IResolverContext): Promise<IDelegateState | null>;
446
+ getTokenFactoryState(args: IAddressArgs, ctx?: IResolverContext): Promise<ITokenFactoryState | null>;
447
+ getEvidenceState(args: TRequestGetEvidenceState, ctx?: IResolverContext): Promise<IEvidenceState | null>;
448
+ getForgeState(): Promise<Record<string, unknown>>;
449
+
450
+ // ============ Info Getters ============
451
+ getChainInfo(): Promise<IResolverChainInfo>;
452
+ getNodeInfo(): Promise<IResolverNodeInfo>;
453
+ getNetInfo(): Promise<IResolverNetInfo>;
454
+ getValidatorsInfo(): Promise<IResolverValidatorsInfo>;
455
+ getConfig(): string;
456
+ getForgeStats(): Promise<IResolverForgeStats>;
457
+
458
+ // ============ Token Helpers ============
459
+ getAccountTokens(args: IGetAccountTokensArgs, ctx?: IResolverContext): Promise<ITokenInfo[]>;
460
+ getTokenDistribution(args?: Partial<TRequestGetTokenDistribution>): Promise<TTokenDistribution | null>;
461
+
462
+ // ============ List Methods ============
463
+ listTransactions(
464
+ args?: Partial<TRequestListTransactions>,
465
+ ctx?: IResolverContext
466
+ ): Promise<IResolverListTransactionsResult>;
467
+ listAssets(args?: Partial<TRequestListAssets>, ctx?: IResolverContext): Promise<IResolverListAssetsResult>;
468
+ listAssetTransactions(
469
+ args?: Partial<TRequestListAssetTransactions>,
470
+ ctx?: IResolverContext
471
+ ): Promise<IResolverListTransactionsResult>;
472
+ listFactories(args?: Partial<TRequestListFactories>, ctx?: IResolverContext): Promise<IResolverListFactoriesResult>;
473
+ listTopAccounts(args?: Partial<TRequestListTopAccounts>): Promise<IResolverListAccountsResult>;
474
+ listTokens(args?: Partial<TRequestListTokens>, ctx?: IResolverContext): Promise<IResolverListTokensResult>;
475
+ listTokenFactories(
476
+ args?: Partial<TRequestListTokenFactories>,
477
+ ctx?: IResolverContext
478
+ ): Promise<IResolverListTokenFactoriesResult>;
479
+ listStakes(args?: Partial<TRequestListStakes>, ctx?: IResolverContext): Promise<IResolverListStakesResult>;
480
+ listRollups(args?: Partial<TRequestListRollups>, ctx?: IResolverContext): Promise<IResolverListRollupsResult>;
481
+ listRollupBlocks(
482
+ args?: Partial<TRequestListRollupBlocks>,
483
+ ctx?: IResolverContext
484
+ ): Promise<IResolverListRollupBlocksResult>;
485
+ listRollupValidators(
486
+ args?: Partial<TRequestListRollupValidators>,
487
+ ctx?: IResolverContext
488
+ ): Promise<IResolverListRollupValidatorsResult>;
489
+ listDelegations(
490
+ args?: Partial<TRequestListDelegations>,
491
+ ctx?: IResolverContext
492
+ ): Promise<IResolverListDelegationsResult>;
493
+ listBlocks(): IBlocksResult;
494
+
495
+ // ============ Search & Utility ============
496
+ search(args: Partial<TRequestSearch>): Promise<ISearchResult>;
497
+ estimateGas(args?: Partial<TRequestEstimateGas>): IEstimateGasResult;
498
+ listTokenFlows(args: Partial<TRequestListTokenFlows>, ctx?: IResolverContext): Promise<ITokenFlowsResult> | never[];
499
+ verifyAccountRisk(
500
+ args: Partial<TRequestVerifyAccountRisk>,
501
+ ctx?: IResolverContext
502
+ ): Promise<TVerifyAccountRiskResult | null> | null;
503
+ }