@pushchain/core 6.0.24 → 6.0.26

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 (98) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/package.json +1 -1
  3. package/src/lib/constants/abi/index.d.ts +1 -0
  4. package/src/lib/constants/abi/index.js +4 -1
  5. package/src/lib/constants/abi/prc20.evm.d.ts +32 -0
  6. package/src/lib/constants/abi/prc20.evm.js +20 -0
  7. package/src/lib/constants/abi/uea-factory.d.ts +31 -0
  8. package/src/lib/constants/abi/uea-factory.js +19 -0
  9. package/src/lib/constants/abi/universalCallback.evm.d.ts +561 -0
  10. package/src/lib/constants/abi/universalCallback.evm.js +247 -0
  11. package/src/lib/constants/abi/universalGatewayV0.json +1 -1
  12. package/src/lib/constants/abi/universalReadRegistry.evm.d.ts +247 -0
  13. package/src/lib/constants/abi/universalReadRegistry.evm.js +38 -0
  14. package/src/lib/constants/chain.d.ts +12 -0
  15. package/src/lib/constants/chain.js +24 -2
  16. package/src/lib/constants/enums.d.ts +7 -0
  17. package/src/lib/constants/enums.js +11 -0
  18. package/src/lib/constants/index.d.ts +54 -0
  19. package/src/lib/constants/index.js +38 -8
  20. package/src/lib/constants/read-state.d.ts +57 -0
  21. package/src/lib/constants/read-state.js +63 -0
  22. package/src/lib/generated/ucallback/v1/index.d.ts +2 -0
  23. package/src/lib/generated/ucallback/v1/index.js +6 -0
  24. package/src/lib/generated/ucallback/v1/query.d.ts +47 -0
  25. package/src/lib/generated/ucallback/v1/query.js +131 -0
  26. package/src/lib/generated/ucallback/v1/types.d.ts +99 -0
  27. package/src/lib/generated/ucallback/v1/types.js +366 -0
  28. package/src/lib/generated/uexecutor/v1/query.d.ts +29 -0
  29. package/src/lib/generated/uexecutor/v1/query.js +98 -1
  30. package/src/lib/index.d.ts +9 -0
  31. package/src/lib/index.js +38 -1
  32. package/src/lib/orchestrator/internals/cascade.js +5 -2
  33. package/src/lib/orchestrator/internals/errors.d.ts +6 -0
  34. package/src/lib/orchestrator/internals/errors.js +13 -1
  35. package/src/lib/orchestrator/internals/index.d.ts +1 -0
  36. package/src/lib/orchestrator/internals/index.js +6 -1
  37. package/src/lib/orchestrator/internals/push-chain-tx.js +81 -61
  38. package/src/lib/orchestrator/internals/read-state.d.ts +24 -0
  39. package/src/lib/orchestrator/internals/read-state.js +47 -0
  40. package/src/lib/orchestrator/internals/route-handlers.js +6 -1
  41. package/src/lib/orchestrator/internals/svm-helpers.js +24 -0
  42. package/src/lib/orchestrator/orchestrator.d.ts +26 -0
  43. package/src/lib/orchestrator/orchestrator.js +22 -0
  44. package/src/lib/orchestrator/orchestrator.types.d.ts +2 -0
  45. package/src/lib/orchestrator/route-detector.js +4 -0
  46. package/src/lib/progress-hook/progress-hook.js +292 -0
  47. package/src/lib/progress-hook/progress-hook.types.d.ts +35 -0
  48. package/src/lib/progress-hook/progress-hook.types.js +37 -0
  49. package/src/lib/push-chain/push-chain.d.ts +71 -0
  50. package/src/lib/push-chain/push-chain.js +28 -0
  51. package/src/lib/push-client/push-client.d.ts +42 -2
  52. package/src/lib/push-client/push-client.js +152 -13
  53. package/src/lib/read-state/budget.d.ts +16 -0
  54. package/src/lib/read-state/budget.js +32 -0
  55. package/src/lib/read-state/destination.d.ts +12 -0
  56. package/src/lib/read-state/destination.js +51 -0
  57. package/src/lib/read-state/envelopes/evm.d.ts +24 -0
  58. package/src/lib/read-state/envelopes/evm.js +147 -0
  59. package/src/lib/read-state/envelopes/index.d.ts +12 -0
  60. package/src/lib/read-state/envelopes/index.js +45 -0
  61. package/src/lib/read-state/envelopes/svm.d.ts +32 -0
  62. package/src/lib/read-state/envelopes/svm.js +117 -0
  63. package/src/lib/read-state/envelopes/web2.d.ts +29 -0
  64. package/src/lib/read-state/envelopes/web2.js +149 -0
  65. package/src/lib/read-state/errors.d.ts +70 -0
  66. package/src/lib/read-state/errors.js +116 -0
  67. package/src/lib/read-state/index.d.ts +13 -0
  68. package/src/lib/read-state/index.js +38 -0
  69. package/src/lib/read-state/preflight.d.ts +21 -0
  70. package/src/lib/read-state/preflight.js +70 -0
  71. package/src/lib/read-state/read-events.d.ts +27 -0
  72. package/src/lib/read-state/read-events.js +135 -0
  73. package/src/lib/read-state/read-executor.d.ts +18 -0
  74. package/src/lib/read-state/read-executor.js +216 -0
  75. package/src/lib/read-state/read-params.d.ts +250 -0
  76. package/src/lib/read-state/read-params.js +164 -0
  77. package/src/lib/read-state/read-state.types.d.ts +458 -0
  78. package/src/lib/read-state/read-state.types.js +72 -0
  79. package/src/lib/read-state/read-tracker.d.ts +55 -0
  80. package/src/lib/read-state/read-tracker.js +481 -0
  81. package/src/lib/read-state/registry.d.ts +21 -0
  82. package/src/lib/read-state/registry.js +53 -0
  83. package/src/lib/read-state/result-decoder.d.ts +16 -0
  84. package/src/lib/read-state/result-decoder.js +79 -0
  85. package/src/lib/read-state/spec-builder.d.ts +47 -0
  86. package/src/lib/read-state/spec-builder.js +251 -0
  87. package/src/lib/read-state/svm-account.d.ts +20 -0
  88. package/src/lib/read-state/svm-account.js +114 -0
  89. package/src/lib/read-state/svm-pda.d.ts +13 -0
  90. package/src/lib/read-state/svm-pda.js +147 -0
  91. package/src/lib/read-state/validate.d.ts +22 -0
  92. package/src/lib/read-state/validate.js +80 -0
  93. package/src/lib/universal-tx-detector/child-inbounds.d.ts +3 -1
  94. package/src/lib/universal-tx-detector/child-inbounds.js +4 -5
  95. package/src/lib/universal-tx-detector/detector-svm.js +29 -20
  96. package/src/lib/universal-tx-detector/svm-events.d.ts +17 -5
  97. package/src/lib/universal-tx-detector/svm-events.js +81 -6
  98. package/src/lib/vm-client/evm-client.js +27 -10
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC20_BALANCE_OF_ABI = void 0;
4
+ exports.toReadDestination = toReadDestination;
5
+ exports.toReadQuery = toReadQuery;
6
+ exports.toBuildReadSpecParams = toBuildReadSpecParams;
7
+ exports.resolveReadSpecParams = resolveReadSpecParams;
8
+ exports.getReadQueryKey = getReadQueryKey;
9
+ exports.toLifecycleOptions = toLifecycleOptions;
10
+ const viem_1 = require("viem");
11
+ const web3_js_1 = require("@solana/web3.js");
12
+ const svm_account_1 = require("./svm-account");
13
+ const svm_pda_1 = require("./svm-pda");
14
+ const enums_1 = require("../constants/enums");
15
+ const registry_1 = require("./registry");
16
+ const read_state_1 = require("../constants/read-state");
17
+ const destination_1 = require("./destination");
18
+ const svm_1 = require("./envelopes/svm");
19
+ const errors_1 = require("./errors");
20
+ /** Just `balanceOf` — it also types the decoded result as uint256. */
21
+ exports.ERC20_BALANCE_OF_ABI = [
22
+ {
23
+ type: 'function',
24
+ name: 'balanceOf',
25
+ stateMutability: 'view',
26
+ inputs: [{ name: 'account', type: 'address' }],
27
+ outputs: [{ name: '', type: 'uint256' }],
28
+ },
29
+ ];
30
+ const QUERY_KEYS = ['token', 'abi', 'idl', 'storageSlot', 'web2'];
31
+ function queryKind(o) {
32
+ if ('tokenProgram' in o)
33
+ throw new errors_1.InvalidReadQueryError('tokenProgram is detected from the mint; remove options.tokenProgram');
34
+ if ('accountName' in o)
35
+ throw new errors_1.InvalidReadQueryError('accountName was removed; pass the account layout as functionName (optional — inferred from the discriminator)');
36
+ const present = QUERY_KEYS.filter((k) => o[k] !== undefined);
37
+ if (present.length > 1) {
38
+ throw new errors_1.InvalidReadQueryError(`query keys are mutually exclusive, got ${present.join(' + ')}`);
39
+ }
40
+ if ((o.functionName !== undefined || o.args !== undefined) && o.abi === undefined && o.idl === undefined) {
41
+ throw new errors_1.InvalidReadQueryError('functionName and args need abi or idl');
42
+ }
43
+ return present[0] ?? 'native';
44
+ }
45
+ function toReadDestination(chain) {
46
+ return chain === enums_1.CHAIN.WEB2 ? read_state_1.WEB2_DESTINATION : { chain };
47
+ }
48
+ /** Build the internal query from the public grammar. Pure. */
49
+ function toReadQuery(subject, o, resolvedTokenProgram) {
50
+ const dest = (0, destination_1.resolveDestination)(toReadDestination(o.chain));
51
+ const kind = queryKind(o);
52
+ if (dest.namespace === read_state_1.READ_NAMESPACE.WEB2) {
53
+ if (kind !== 'web2' || !o.web2)
54
+ throw new errors_1.InvalidReadQueryError('a web2 read needs the `web2` option and no other query key');
55
+ if (!/^https:\/\//i.test(subject))
56
+ throw new errors_1.InvalidReadQueryError('web2 subject must be an https:// URL');
57
+ return { type: 'http', url: subject, ...o.web2 };
58
+ }
59
+ if (kind === 'web2')
60
+ throw new errors_1.InvalidReadQueryError('`web2` is only valid with chain CHAIN.WEB2');
61
+ if (dest.namespace === read_state_1.READ_NAMESPACE.EVM) {
62
+ if (!(0, viem_1.isAddress)(subject))
63
+ throw new errors_1.InvalidReadQueryError(`EVM subject must be an address, got ${subject}`);
64
+ switch (kind) {
65
+ case 'native':
66
+ return { type: 'accountBalance', target: subject };
67
+ case 'token': {
68
+ const token = o.token;
69
+ if (!(0, viem_1.isAddress)(token))
70
+ throw new errors_1.InvalidReadQueryError(`token must be an address, got ${token}`);
71
+ return { type: 'contractCall', target: token, abi: exports.ERC20_BALANCE_OF_ABI, functionName: 'balanceOf', args: [subject] };
72
+ }
73
+ case 'abi':
74
+ if (!o.functionName)
75
+ throw new errors_1.InvalidReadQueryError('abi needs functionName');
76
+ return { type: 'contractCall', target: subject, abi: o.abi, functionName: o.functionName, args: o.args };
77
+ case 'storageSlot':
78
+ return { type: 'storageSlot', target: subject, slot: o.storageSlot };
79
+ default:
80
+ throw new errors_1.InvalidReadQueryError(`unsupported query for eip155: ${kind}`);
81
+ }
82
+ }
83
+ // SVM: token-program ownership has already been resolved by the async public path.
84
+ switch (kind) {
85
+ case 'native':
86
+ return { type: 'lamportBalance', account: subject };
87
+ case 'token':
88
+ if (!resolvedTokenProgram)
89
+ throw new errors_1.InvalidReadQueryError('Solana token reads need mint-owner resolution; use universal.prepareRead or universal.read');
90
+ return { type: 'splTokenAccount', account: (0, svm_1.deriveAssociatedTokenAddress)(subject, o.token, resolvedTokenProgram).toBase58() };
91
+ case 'idl':
92
+ return toIdlAccountQuery(subject, o);
93
+ default:
94
+ throw new errors_1.InvalidReadQueryError(`unsupported query for solana: ${kind}; use idl for account-state decoding`);
95
+ }
96
+ }
97
+ /**
98
+ * `idl` → a raw account read that decodes with the IDL. The subject is the account,
99
+ * or the program id when `args` are the seeds of the `functionName` PDA.
100
+ */
101
+ function toIdlAccountQuery(subject, o) {
102
+ const idl = o.idl;
103
+ (0, svm_account_1.validateIdl)(idl);
104
+ const accountName = o.functionName === undefined ? undefined : (0, svm_account_1.resolveAccountName)(idl, o.functionName);
105
+ if ((0, svm_pda_1.isProgramSubject)(idl, subject)) {
106
+ if (!o.functionName)
107
+ throw new errors_1.InvalidReadQueryError('the subject is the program id: pass functionName (the account layout) and args (its PDA seeds) to derive the account');
108
+ const pda = (0, svm_pda_1.deriveIdlPda)(idl, o.functionName, o.args ?? []);
109
+ return { type: 'rawAccountData', account: pda.toBase58(), idl, accountName };
110
+ }
111
+ if (o.args !== undefined)
112
+ throw new errors_1.InvalidReadQueryError('with idl, args are PDA seeds and need the program id as the subject');
113
+ try {
114
+ new web3_js_1.PublicKey(subject);
115
+ }
116
+ catch {
117
+ throw new errors_1.InvalidReadQueryError(`Solana subject must be a base58 pubkey, got ${subject}`);
118
+ }
119
+ return { type: 'rawAccountData', account: subject, idl, accountName };
120
+ }
121
+ /** Public options → the spec builder's params. Pure; throws `InvalidReadQueryError` on a malformed request. */
122
+ function toBuildReadSpecParams(subject, o, network = enums_1.PUSH_NETWORK.TESTNET_DONUT, resolvedTokenProgram) {
123
+ const destination = toReadDestination(o.chain);
124
+ const namespace = (0, destination_1.resolveDestination)(destination).namespace;
125
+ if (namespace !== read_state_1.READ_NAMESPACE.EVM && (o.blockNumber !== undefined || o.minConfirmations !== undefined)) {
126
+ throw new errors_1.InvalidReadQueryError(`${namespace} reads do not expose blockNumber or minConfirmations; the SDK selects the read reference internally`);
127
+ }
128
+ const query = toReadQuery(subject, o, resolvedTokenProgram);
129
+ const callback = (0, registry_1.resolveReadCallback)(o.callback, network, (0, registry_1.computeReadQueryKey)(destination, query));
130
+ return {
131
+ callback,
132
+ destination,
133
+ query,
134
+ callbackGasLimit: callback.gasLimit,
135
+ refundTo: o.refundTo,
136
+ minConfirmations: o.minConfirmations,
137
+ blockNumber: o.blockNumber,
138
+ expiryBlocks: o.expiryBlocks,
139
+ maxFee: o.maxFee,
140
+ };
141
+ }
142
+ /** Resolve Solana mint ownership before the otherwise-pure options conversion. */
143
+ async function resolveReadSpecParams(subject, o, network, rpcUrls) {
144
+ const kind = queryKind(o);
145
+ const namespace = (0, destination_1.resolveDestination)(toReadDestination(o.chain)).namespace;
146
+ if (namespace === read_state_1.READ_NAMESPACE.SVM && kind === 'token') {
147
+ new web3_js_1.PublicKey(subject);
148
+ const program = await (0, svm_account_1.detectTokenProgram)(o.token, o.chain, rpcUrls[o.chain]);
149
+ return toBuildReadSpecParams(subject, o, network, program);
150
+ }
151
+ return toBuildReadSpecParams(subject, o, network);
152
+ }
153
+ /** Internal offline key helper. Solana token callers must use PreparedRead.queryKey after mint resolution. */
154
+ function getReadQueryKey(subject, options) {
155
+ return (0, registry_1.computeReadQueryKey)(toReadDestination(options.chain), toReadQuery(subject, options));
156
+ }
157
+ function toLifecycleOptions(o) {
158
+ return {
159
+ pollingIntervalMs: o?.advanced?.pollingIntervalMs,
160
+ timeoutMs: o?.advanced?.timeout,
161
+ resultShape: o?.resultShape,
162
+ };
163
+ }
164
+ //# sourceMappingURL=read-params.js.map
@@ -0,0 +1,458 @@
1
+ import type { Abi, Address, Hex } from 'viem';
2
+ import type { Idl } from '@coral-xyz/anchor';
3
+ import type { CHAIN } from '../constants/enums';
4
+ import type { ReadNamespace } from '../constants/read-state';
5
+ /**
6
+ * Where a read goes. `CHAIN` enum values are CAIP-2 and split cleanly; the
7
+ * explicit form is the low-level escape hatch; the public API uses `CHAIN.WEB2`.
8
+ */
9
+ export type ReadChain = CHAIN | typeof CHAIN.WEB2;
10
+ export type ReadDestination = {
11
+ chain: ReadChain;
12
+ } | {
13
+ chainNamespace: string;
14
+ chainId: string;
15
+ };
16
+ export type ResolvedDestination = {
17
+ chainNamespace: string;
18
+ chainId: string;
19
+ /** `${chainNamespace}:${chainId}` — the key the oracle and the node route on. */
20
+ caip2: string;
21
+ namespace: ReadNamespace;
22
+ };
23
+ export type EvmReadQuery = {
24
+ type: 'accountBalance';
25
+ target: Address;
26
+ } | {
27
+ type: 'contractCall';
28
+ target: Address;
29
+ callData: Hex;
30
+ } | {
31
+ type: 'contractCall';
32
+ target: Address;
33
+ /** encodes the call AND decodes the result */
34
+ abi: Abi;
35
+ functionName: string;
36
+ args?: readonly unknown[];
37
+ } | {
38
+ type: 'storageSlot';
39
+ target: Address;
40
+ slot: Hex | bigint;
41
+ };
42
+ /** The account being read rides in `ReadSpec.account.owner` as a raw 32-byte pubkey, not in the envelope. */
43
+ export type SvmReadQuery = {
44
+ type: 'lamportBalance';
45
+ account: string | Uint8Array;
46
+ } | {
47
+ type: 'splTokenAccount';
48
+ account: string | Uint8Array;
49
+ } | {
50
+ type: 'rawAccountData';
51
+ account: string | Uint8Array;
52
+ idl?: Idl; /** Omitted → layout inferred from the discriminator. */
53
+ accountName?: string;
54
+ };
55
+ export type Web2ValueType = 'uint256' | 'int256' | 'bool' | 'string' | 'bytes';
56
+ export interface Web2Extract {
57
+ /** JSONPath, e.g. "$.data.price" */
58
+ path: string;
59
+ valueType: Web2ValueType;
60
+ /** Numeric only. Value × 10^decimals, TRUNCATED before encoding. */
61
+ decimals?: number;
62
+ }
63
+ export interface Web2ReadQuery {
64
+ type: 'http';
65
+ method?: 'GET' | 'POST';
66
+ url: string;
67
+ /** ⚠ Written to a public event log, forever. */
68
+ headers?: Record<string, string>;
69
+ /** POST only */
70
+ body?: string | Uint8Array;
71
+ timeoutMs?: number;
72
+ /** 1–16 entries; result values come back in this order. */
73
+ extract: readonly Web2Extract[];
74
+ }
75
+ export type ReadQuery = EvmReadQuery | SvmReadQuery | Web2ReadQuery;
76
+ export type ReadResultShape = {
77
+ kind: 'svmAccount';
78
+ idl: Idl; /** Omitted → layout inferred from the discriminator. */
79
+ accountName?: string;
80
+ } | {
81
+ kind: 'uint256';
82
+ } | {
83
+ kind: 'bytes32';
84
+ } | {
85
+ kind: 'raw';
86
+ } | {
87
+ kind: 'evmCall';
88
+ abi: Abi;
89
+ functionName: string;
90
+ } | {
91
+ kind: 'web2';
92
+ extract: readonly Web2Extract[];
93
+ };
94
+ export interface EncodedReadQuery {
95
+ namespace: ReadNamespace;
96
+ queryType: number;
97
+ /** abi.encode(envelope tuple) — goes into ReadSpec.query */
98
+ encoded: Hex;
99
+ /** EVM: pinned block. SVM: minSlot floor. Web2: 0. Mirrored into ReadSpec.blockNumber by the spec builder. */
100
+ blockRef: bigint;
101
+ resultShape: ReadResultShape;
102
+ /** SVM only: the raw 32-byte pubkey that MUST go in ReadSpec.account.owner. */
103
+ ownerBytes?: Hex;
104
+ /** Non-fatal advisories (e.g. a sensitive-looking web2 header). */
105
+ warnings: string[];
106
+ }
107
+ export type DecodedReadResult = {
108
+ kind: 'svmAccount';
109
+ value: unknown; /** The IDL layout the data decoded as. */
110
+ accountName: string;
111
+ } | {
112
+ kind: 'uint256';
113
+ value: bigint;
114
+ } | {
115
+ kind: 'bytes32';
116
+ value: Hex;
117
+ } | {
118
+ kind: 'raw';
119
+ value: Hex;
120
+ } | {
121
+ kind: 'evmCall';
122
+ value: unknown;
123
+ } | {
124
+ kind: 'web2';
125
+ values: readonly unknown[];
126
+ };
127
+ export interface ReadPreflight {
128
+ destination: ResolvedDestination;
129
+ /** `UniversalCallback.estimateFee(ns, chainId)` — the protocol fee ONLY. 0 on Donut today. */
130
+ protocolFee: bigint;
131
+ /**
132
+ * `UniversalCore.chainHeightByChainNamespace(caip2)` — the oracle-observed height of the
133
+ * destination and the ceiling for `blockNumber`. Lags the real head. 0 for heightless
134
+ * namespaces (web2), where `blockNumber` must then be 0.
135
+ */
136
+ observedChainHeight: bigint;
137
+ /** Current Push Chain height, for expiry. */
138
+ pushBlockNumber: bigint;
139
+ /** Push gas price used to size the callback budget. */
140
+ pushGasPrice: bigint;
141
+ universalCallback: Address;
142
+ universalCore: Address;
143
+ /** Date.now() at fetch — pushBlockNumber moves every block; a stale preflight can miss expiry. */
144
+ fetchedAt: number;
145
+ }
146
+ export interface ReadSpec {
147
+ account: {
148
+ chainNamespace: string;
149
+ chainId: string;
150
+ owner: Hex;
151
+ };
152
+ query: Hex;
153
+ /** uint16, ≥ 1 */
154
+ minConfirmations: number;
155
+ /** uint64. Heightless namespaces (web2) MUST be 0; else 1..oracleHeight */
156
+ blockNumber: bigint;
157
+ /** uint64, > current Push height */
158
+ expiryPushChainHeight: bigint;
159
+ /** ≥ msg.value */
160
+ maxFee: bigint;
161
+ /** ≠ 0. Refunds are PUSHED here. */
162
+ revertRecipient: Address;
163
+ }
164
+ /** Positional form for `encodeFunctionData` / `encodeAbiParameters`. */
165
+ export type ReadSpecTuple = readonly [
166
+ readonly [string, string, Hex],
167
+ Hex,
168
+ number,
169
+ bigint,
170
+ bigint,
171
+ bigint,
172
+ Address
173
+ ];
174
+ export interface ReadCallback {
175
+ target?: Address;
176
+ /** Gas for the result callback, not the request entrypoint. */
177
+ gasLimit?: bigint;
178
+ /** Public payable request entrypoint on the application contract. */
179
+ abi?: Abi;
180
+ functionName?: string;
181
+ /** Defaults to (spec, callbackGasLimit). Must request exactly one read with this spec. */
182
+ args?: (spec: ReadSpecTuple, callbackGasLimit: bigint) => readonly unknown[];
183
+ }
184
+ export interface BuildReadSpecParams {
185
+ callback?: ReadCallback;
186
+ destination: ReadDestination;
187
+ query: ReadQuery;
188
+ /** 1n..1_000_000n. Execution bound on YOUR callback; also sizes the budget. */
189
+ callbackGasLimit: bigint;
190
+ /**
191
+ * Where unspent budget is PUSHED (ReadSpec.revertRecipient). Required by the contract.
192
+ * Default: the sending account (a UEA has a payable receive()). A non-UEA contract
193
+ * without one forfeits the refund — prepareRead warns.
194
+ */
195
+ refundTo?: Address;
196
+ /** EVM/web2 only: ReadSpec.account.owner. Ignored by validators for EVM; defaults to refundTo. SVM derives it from the query. */
197
+ owner?: Hex;
198
+ /** ≥ 1. Default 1. */
199
+ minConfirmations?: number;
200
+ /** Pinned destination height. Default observedChainHeight − minConfirmations (≥ 1). Web2: forced to 0. */
201
+ blockNumber?: bigint;
202
+ /** Default 300n. */
203
+ expiryBlocks?: bigint;
204
+ /** Absolute override for expiryBlocks. */
205
+ expiryPushChainHeight?: bigint;
206
+ /** Escrowed on top of the protocol fee. Default sizeCallbackBudget(gasLimit, gasPrice). Must be > 0. */
207
+ callbackBudget?: bigint;
208
+ /** Multiplier used by the default budget. */
209
+ budgetBuffer?: number;
210
+ /** Cap on msg.value. Default value × (1 + maxFeeBufferBps/10_000). */
211
+ maxFee?: bigint;
212
+ maxFeeBufferBps?: number;
213
+ }
214
+ declare const preparedReadValue: unique symbol;
215
+ export interface PreparedRead<T = unknown> {
216
+ /** SDK logical query identity, independent of pinning and payment. */
217
+ queryKey: Hex;
218
+ /** Type-only result metadata retained through preparation and execution. */
219
+ readonly [preparedReadValue]?: T;
220
+ /** App request entrypoint retained for read()/executeReads(). */
221
+ callback?: ReadCallback;
222
+ /** Public destination identifier used to prepare this read. */
223
+ chain: ReadChain;
224
+ spec: ReadSpec;
225
+ /** Positional form for viem calls. */
226
+ specTuple: ReadSpecTuple;
227
+ /** abi.encode(spec) for hand-assembled calldata. */
228
+ encodedSpec: Hex;
229
+ /** msg.value to send: protocolFee + callbackBudget. */
230
+ value: bigint;
231
+ protocolFee: bigint;
232
+ callbackBudget: bigint;
233
+ /** The same three numbers, grouped: `total` === `value`. */
234
+ fees: {
235
+ protocolFee: bigint;
236
+ callbackBudget: bigint;
237
+ total: bigint;
238
+ };
239
+ callbackGasLimit: bigint;
240
+ /** Carries the result shape for decoding, and any encoder warnings. */
241
+ encodedQuery: EncodedReadQuery;
242
+ /** Public decoder description retained through execution. */
243
+ resultShape: ReadResultShape;
244
+ preflight: ReadPreflight;
245
+ /** Advisories: sensitive headers, refundTo is a non-UEA contract, … */
246
+ warnings: string[];
247
+ }
248
+ export type SimulateReadResult = {
249
+ ok: true;
250
+ } | {
251
+ ok: false;
252
+ error: string;
253
+ errorName?: string;
254
+ args?: readonly unknown[];
255
+ };
256
+ export interface ParsedReadRequest {
257
+ /** 32-byte topic hex, lowercase — the node's primary key */
258
+ requestId: Hex;
259
+ requestIdUint: bigint;
260
+ callbackTarget: Address;
261
+ originalFunder: Address;
262
+ spec: ReadSpec;
263
+ callbackGasLimit: bigint;
264
+ totalPaid: bigint;
265
+ protocolFee: bigint;
266
+ callbackBudget: bigint;
267
+ logIndex: number;
268
+ }
269
+ /** What the fulfil / settle / expiry transactions said, parsed from UniversalCallback logs. */
270
+ export interface FulfilOutcome {
271
+ /** true = ReadFulfilled, false = CallbackFailed, undefined = neither seen in this receipt */
272
+ delivered?: boolean;
273
+ /** revert data from CallbackFailed */
274
+ failReason?: Hex;
275
+ gasReported?: bigint;
276
+ burned?: bigint;
277
+ refunded?: bigint;
278
+ refundTo?: Address;
279
+ /** RefundFailed seen — budget forfeited to the admin rescue pool */
280
+ refundFailed?: boolean;
281
+ /** RequestExpired seen */
282
+ expired?: boolean;
283
+ }
284
+ /** Minimal structural receipt — works with viem receipts and `cast receipt --json`. */
285
+ export interface ReceiptLike {
286
+ logs: readonly {
287
+ address: string;
288
+ topics: readonly string[];
289
+ data: string;
290
+ logIndex?: number | string;
291
+ }[];
292
+ }
293
+ export type ReadRef = {
294
+ txHash: Hex;
295
+ } | {
296
+ requestId: Hex | bigint;
297
+ };
298
+ export interface ReadLifecycleOptions {
299
+ /** Default `expiryBlocks × PUSH_BLOCK_TIME_MS`, capped at READ_TRACK_MAX_TIMEOUT_MS. */
300
+ timeoutMs?: number;
301
+ /** Default READ_TRACK_POLL_INTERVAL_MS; floor READ_TRACK_MIN_POLL_INTERVAL_MS. */
302
+ pollingIntervalMs?: number;
303
+ /**
304
+ * How to decode `resultData`. When omitted the tracker infers it from the on-chain
305
+ * envelope (balances → uint256, storage → bytes32, web2 → its extract list); a
306
+ * contract call has no ABI on chain and decodes to raw bytes unless given here.
307
+ */
308
+ resultShape?: ReadResultShape;
309
+ }
310
+ /** Accounting for one read, assembled from the request record and the settlement logs. */
311
+ export interface ReadFees {
312
+ /** msg.value at request time (`feesDeposited`) */
313
+ paid: bigint;
314
+ /** gone at request time, never refunded */
315
+ protocolFee: bigint;
316
+ /** escrowed for the callback */
317
+ callbackBudget: bigint;
318
+ /** consumed by the callback — `CallbackGasReported` */
319
+ burned?: bigint;
320
+ /** pushed back to `refundTo` — `RefundSent` / `RequestExpired` */
321
+ /** Unknown for EndBlock expiry: EXPIRED does not prove the recipient accepted payment. */
322
+ refunded?: bigint;
323
+ /** the push was rejected — budget sits in the admin rescue pool */
324
+ refundFailed?: boolean;
325
+ }
326
+ export interface UniversalReadResponse<T = unknown> {
327
+ requestId: Hex;
328
+ /** `requestId` as the `uint256` contracts key results by (e.g. registry `resultByRequestId`). */
329
+ requestIdUint: bigint;
330
+ /** Push tx that carried the request */
331
+ txHash: Hex;
332
+ destination: ResolvedDestination;
333
+ /** Required read destination, including `CHAIN.WEB2`. */
334
+ chain: ReadChain;
335
+ /**
336
+ * The one field that answers "did it work": `SUCCESS` means the source read
337
+ * succeeded, your callback ran, and `value` is set (when a shape is known).
338
+ * Derived by the SDK from `status`, `raw.status`, `callbackDelivered` and
339
+ * `decodeError`, which stay available for debugging.
340
+ */
341
+ outcome: READ_OUTCOME;
342
+ status: UNIVERSAL_READ_STATUS;
343
+ isTerminal: boolean;
344
+ /**
345
+ * FULFILLED only. true = `ReadFulfilled`; false = `CallbackFailed` (your callback
346
+ * reverted / ran out of gas). FULFILLED does NOT imply delivered — check both.
347
+ */
348
+ callbackDelivered?: boolean;
349
+ /** Revert data from `CallbackFailed`. */
350
+ callbackFailReason?: Hex;
351
+ /** Decoded result. Present iff FULFILLED && callbackDelivered && result SUCCESS && decodable. */
352
+ value?: T;
353
+ decoded?: DecodedReadResult;
354
+ /** Why `value` is absent although the read succeeded (shape mismatch). */
355
+ decodeError?: string;
356
+ /** Consensus bytes — what ⅔ of validators voted on. `null` before a result exists. */
357
+ raw: {
358
+ status: READ_STATUS;
359
+ resultData: Hex;
360
+ errorCode: READ_ERROR_CODE;
361
+ } | null;
362
+ errorMsg: string;
363
+ fees: ReadFees;
364
+ request: {
365
+ spec: ReadSpec;
366
+ callbackTarget: Address;
367
+ /** who paid (msg.sender at request) — NOT where refunds go */
368
+ originalFunder: Address;
369
+ /** where refunds go */
370
+ refundTo: Address;
371
+ callbackGasLimit: bigint;
372
+ logIndex: number;
373
+ createdAtHeight: bigint;
374
+ };
375
+ /** Push txs the node sent for this read (fulfil, settle, expiry sweep). */
376
+ pcTx: readonly {
377
+ txHash: Hex;
378
+ blockHeight: number;
379
+ status: string;
380
+ errorMsg: string;
381
+ }[];
382
+ explorerUrl: string;
383
+ /** Poll until terminal (or already terminal → resolves at once). Only a timeout throws. */
384
+ wait(opts?: ReadLifecycleOptions): Promise<UniversalReadResponse<T>>;
385
+ /** One fresh snapshot, no polling. */
386
+ refresh(): Promise<UniversalReadResponse<T>>;
387
+ }
388
+ export type ReadResponseTuple<R extends readonly PreparedRead[]> = {
389
+ -readonly [K in keyof R]: UniversalReadResponse<R[K] extends PreparedRead<infer T> ? T : unknown>;
390
+ };
391
+ /** One execution containing one or more independently settled read requests. */
392
+ export interface BatchReadResponse<R extends readonly PreparedRead[] = readonly PreparedRead[]> {
393
+ /** Primary Push transaction hash. For sequential fallback, see `transactionHashes`. */
394
+ txHash: Hex;
395
+ /** All request transactions in submission order when execution was non-atomic. */
396
+ transactionHashes?: readonly Hex[];
397
+ reads: ReadResponseTuple<R>;
398
+ count: number;
399
+ atomic: boolean;
400
+ /** Wait until every read is terminal. Terminal failures resolve; only timeout throws. */
401
+ wait(opts?: Omit<ReadLifecycleOptions, 'resultShape'>): Promise<ReadResponseTuple<R>>;
402
+ }
403
+ export declare enum UNIVERSAL_READ_STATUS {
404
+ UNSPECIFIED = 0,
405
+ PENDING = 1,
406
+ VOTING = 2,
407
+ /** fulfil tx succeeded — check `callbackDelivered` before trusting the result */
408
+ FULFILLED = 3,
409
+ EXPIRED = 4,
410
+ /** contract had already settled the request another way */
411
+ FAILED = 5,
412
+ ABORTED = 6
413
+ }
414
+ export declare enum READ_STATUS {
415
+ UNSPECIFIED = 0,
416
+ SUCCESS = 1,
417
+ ERROR = 2
418
+ }
419
+ export declare enum READ_ERROR_CODE {
420
+ UNSPECIFIED = 0,
421
+ INVALID_QUERY = 1,
422
+ UNSUPPORTED = 2,
423
+ REVERTED = 3,
424
+ NOT_FOUND = 4,
425
+ INVALID_RESULT = 5,
426
+ REJECTED = 6
427
+ }
428
+ /**
429
+ * SDK-derived single outcome. FULFILLED on the node only means the fulfil tx
430
+ * landed; this separates the ways a FULFILLED read can still not have worked.
431
+ */
432
+ export declare enum READ_OUTCOME {
433
+ /** Not terminal yet. */
434
+ PENDING = "PENDING",
435
+ /** Source SUCCESS, callback delivered, result decoded (or no shape to decode with). */
436
+ SUCCESS = "SUCCESS",
437
+ /** FULFILLED, but the destination returned an error (`raw.errorCode`). */
438
+ SOURCE_ERROR = "SOURCE_ERROR",
439
+ /** FULFILLED, but the receiver callback reverted or ran out of gas (`callbackFailReason`). */
440
+ CALLBACK_FAILED = "CALLBACK_FAILED",
441
+ /** Delivered, but `resultData` did not match the expected shape (`decodeError`). */
442
+ DECODE_FAILED = "DECODE_FAILED",
443
+ EXPIRED = "EXPIRED",
444
+ FAILED = "FAILED",
445
+ ABORTED = "ABORTED",
446
+ /** FULFILLED, but the fulfil receipt was unavailable, so delivery cannot be confirmed. */
447
+ UNKNOWN = "UNKNOWN"
448
+ }
449
+ /** On-chain lifecycle (`RequestStatus` in ReadTypes.sol). */
450
+ export declare enum CONTRACT_REQUEST_STATUS {
451
+ NONE = 0,
452
+ PENDING = 1,
453
+ EXECUTED = 2,
454
+ SETTLED = 3,
455
+ EXPIRED = 4
456
+ }
457
+ export declare const TERMINAL_READ_STATUSES: ReadonlySet<UNIVERSAL_READ_STATUS>;
458
+ export {};