@proof-labs/trading-sdk 4.0.0 → 4.2.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.
- package/README.md +81 -0
- package/dist/account-state.d.ts +17 -0
- package/dist/account-state.d.ts.map +1 -0
- package/dist/account-state.js +63 -0
- package/dist/account-state.js.map +1 -0
- package/dist/client.d.ts +26 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +75 -1
- package/dist/client.js.map +1 -1
- package/dist/codec-adapter.d.ts.map +1 -1
- package/dist/codec-adapter.js +3 -1
- package/dist/codec-adapter.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/financial-state.d.ts +65 -0
- package/dist/financial-state.d.ts.map +1 -0
- package/dist/financial-state.js +345 -0
- package/dist/financial-state.js.map +1 -0
- package/dist/governance-query.d.ts +5 -1
- package/dist/governance-query.d.ts.map +1 -1
- package/dist/governance-query.js +74 -0
- package/dist/governance-query.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/market-snapshot.d.ts +11 -0
- package/dist/market-snapshot.d.ts.map +1 -0
- package/dist/market-snapshot.js +326 -0
- package/dist/market-snapshot.js.map +1 -0
- package/dist/oracle-permissions.d.ts +51 -0
- package/dist/oracle-permissions.d.ts.map +1 -0
- package/dist/oracle-permissions.js +191 -0
- package/dist/oracle-permissions.js.map +1 -0
- package/dist/types.d.ts +99 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -2
- package/dist/types.js.map +1 -1
- package/dist/wasm/proof_trading_sdk_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Proof Trading SDK
|
|
2
2
|
|
|
3
|
+
### Atomic financial evidence (TypeScript 4.2)
|
|
4
|
+
|
|
5
|
+
`client.queryFinancialState({ markets: [1], owners: [ownerHex] })` reads one
|
|
6
|
+
finalized-store snapshot through the gateway only. Select 1–8 markets and 1–8
|
|
7
|
+
owners; inputs are copied, sorted and canonicalized, with duplicates rejected.
|
|
8
|
+
The response includes exact selected market fee/funding settings, raw account
|
|
9
|
+
balances and positions, the fee pool, selected markets' insurance pools, and
|
|
10
|
+
optional PLP configuration. The PLP account is automatically included once.
|
|
11
|
+
All integers retain precision and absent stored values remain `null`; at most
|
|
12
|
+
2048 positions total and a one-MiB HTTP response are accepted, within five seconds.
|
|
13
|
+
A framing-only preflight also bounds nesting and aggregate value slots before
|
|
14
|
+
the maintained MessagePack decoder allocates containers; values are not decoded
|
|
15
|
+
by a second codec.
|
|
16
|
+
|
|
17
|
+
This is not equity, accrued-funding valuation, solvency or trading/withdrawal
|
|
18
|
+
authorization. `feesAccrued` is a lifetime fee/rebate counter, not cash.
|
|
19
|
+
`plp.bootstrapBalance` is a historical baseline, not additional PLP funds;
|
|
20
|
+
actual PLP cash is only its account balance. Do not double-count either field.
|
|
21
|
+
Other endpoints must be bracketed at the same `finalizedHeight` for cross-read
|
|
22
|
+
comparisons; the method does not claim a historical-height query parameter.
|
|
23
|
+
|
|
24
|
+
`queryAccountState(ownerHex?)` reads exact finalized settled balance and raw
|
|
25
|
+
positions through the gateway, without oracle valuation. Its bigint values are
|
|
26
|
+
not equity, accrued funding, available collateral or authorization. When
|
|
27
|
+
`queryAccount` fails closed during unsafe oracle conditions, show valuation as
|
|
28
|
+
unavailable; do not substitute this raw cash balance as healthy equity. Match
|
|
29
|
+
`finalizedHeight` across bracketed reads for a coherent economic snapshot.
|
|
30
|
+
|
|
3
31
|
TypeScript SDK for the [Proof Exchange](https://proof.trade): Ed25519 signing,
|
|
4
32
|
MessagePack codec, timestamp-nonce allocation, and gateway/CometBFT submission
|
|
5
33
|
for every exchange action.
|
|
@@ -150,8 +178,10 @@ class ExchangeClient {
|
|
|
150
178
|
queryOrderbook(market: number): Promise<Orderbook>;
|
|
151
179
|
queryOpenOrders(addressHex?: string): Promise<OpenOrder[]>;
|
|
152
180
|
queryMarkets(): Promise<MarketConfig[]>;
|
|
181
|
+
queryMarketsSnapshot(): Promise<MarketsSnapshot>;
|
|
153
182
|
queryAccount(addressHex?: string): Promise<AccountInfo | null>;
|
|
154
183
|
queryHealth(): Promise<{ status: string; height: number }>;
|
|
184
|
+
queryOraclePermissions(market: number): Promise<OraclePermissions>;
|
|
155
185
|
queryWithdrawal(id: bigint): Promise<WithdrawalRecord | null>;
|
|
156
186
|
queryPositionTriggers(addressHex?: string): Promise<PositionTriggerInfo[]>;
|
|
157
187
|
queryTriggerMarketConfigs(): Promise<TriggerMarketConfigInfo[]>;
|
|
@@ -181,6 +211,57 @@ class ExchangeClient {
|
|
|
181
211
|
}
|
|
182
212
|
```
|
|
183
213
|
|
|
214
|
+
For chain-pinned, atomic committed market inventory, see
|
|
215
|
+
[the snapshot guide](docs/market-snapshot.md). The optional Rust `gateway`
|
|
216
|
+
feature additionally provides committed-time and exact-hash receipt reads plus
|
|
217
|
+
one-shot submission of already-signed bytes. It does not manage a caller's
|
|
218
|
+
durable journal, nonce allocation, retries or cutover authority.
|
|
219
|
+
|
|
220
|
+
`queryOraclePermissions(market)` reads one underlying perp's committed oracle
|
|
221
|
+
policy, calendar epoch and verdict at an exact finalized height. It preserves
|
|
222
|
+
u64 values as `bigint`, and returns `Legacy` with no permission claim while the
|
|
223
|
+
new policy is inactive. `Satisfied` covers only this oracle dependency, not all
|
|
224
|
+
portfolio dependencies or other trading checks. It never reads provider/observer
|
|
225
|
+
health, and is separate from the prohibited operational-health API in ADR 0002.
|
|
226
|
+
|
|
227
|
+
### Optional native Rust gateway transport
|
|
228
|
+
|
|
229
|
+
Rust `proof-trading-sdk` 3.2.0 exposes `gateway::GatewayClient` with the optional
|
|
230
|
+
`gateway` feature. Default codec/WASM builds do not acquire an HTTP transport.
|
|
231
|
+
The four explicit operations are `chain_identity`, `oracle_permissions`,
|
|
232
|
+
`submit_signed_bytes` and `committed_receipt`; they use only the existing gateway
|
|
233
|
+
routes, with no direct-node fallback, signing, nonce allocation or hidden retry.
|
|
234
|
+
|
|
235
|
+
Configure an HTTPS origin (HTTP requires a URL-normalized loopback IP, not a DNS
|
|
236
|
+
name; numeric IPv4 aliases that normalize to loopback are allowed), a
|
|
237
|
+
1ms–60s total request deadline and a response cap no larger than 1MiB. Defaults
|
|
238
|
+
are 10 seconds and 256KiB. Redirects, environment proxies and automatic retries
|
|
239
|
+
are disabled. An optional API key is sent only in `X-Api-Key` and is redacted
|
|
240
|
+
from diagnostics. Signed input is limited to 4096 bytes, fitting the gateway's
|
|
241
|
+
default JSON body cap after base64 encoding. These are client resource bounds,
|
|
242
|
+
not production admission policy.
|
|
243
|
+
|
|
244
|
+
`SubmissionOutcome` distinguishes committed execution, CheckTx rejection,
|
|
245
|
+
pending execution and explicit pre-admission rejection. A transport/error body
|
|
246
|
+
or hash mismatch retains `GatewayError.reconcile_hash`: the transaction may
|
|
247
|
+
have landed, so retain its exact bytes and reconcile rather than re-sign.
|
|
248
|
+
`committed_receipt` requires the requested hash and a positive committed height;
|
|
249
|
+
not-found/not-indexed errors never clear pending state. A code-zero receipt is
|
|
250
|
+
execution success, **not** an oracle permission certificate. Retry-After remains
|
|
251
|
+
an exact delay, an absolute HTTP date, or explicitly `Invalid`; callers must not
|
|
252
|
+
discard an invalid header and retry immediately.
|
|
253
|
+
|
|
254
|
+
For a deliberately read-only local contract probe, with no signing/key inputs:
|
|
255
|
+
|
|
256
|
+
```sh
|
|
257
|
+
cargo run -p proof-trading-sdk --features gateway --example gateway_oracle_probe -- \
|
|
258
|
+
http://127.0.0.1:9080 EXPECTED_CHAIN 1
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
It checks chain identity before the permission read and reports both heights;
|
|
262
|
+
sequential reads are not a single atomic snapshot. Neither a successful probe
|
|
263
|
+
nor a committed market permission authorizes a portfolio action or release.
|
|
264
|
+
|
|
184
265
|
Position triggers are exact-position-generation brackets. For an existing
|
|
185
266
|
bracket, `queryPositionTriggers()` returns its epoch; first attach must use the
|
|
186
267
|
epoch on the canonical account position read and must never guess `1`. Submit
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Raw settled ledger facts. Never equity, margin, or withdrawal authorization. */
|
|
2
|
+
export interface RawAccountPosition {
|
|
3
|
+
owner: string;
|
|
4
|
+
market: number;
|
|
5
|
+
side: "Buy" | "Sell";
|
|
6
|
+
entryPrice: bigint;
|
|
7
|
+
size: bigint;
|
|
8
|
+
lastFundingIndex: bigint;
|
|
9
|
+
}
|
|
10
|
+
export interface AccountState {
|
|
11
|
+
owner: string;
|
|
12
|
+
finalizedHeight: bigint;
|
|
13
|
+
balance: bigint;
|
|
14
|
+
positions: RawAccountPosition[];
|
|
15
|
+
}
|
|
16
|
+
export declare function decodeAccountState(raw: unknown, expectedOwner?: string): AccountState;
|
|
17
|
+
//# sourceMappingURL=account-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-state.d.ts","sourceRoot":"","sources":["../src/account-state.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AACD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,kBAAkB,EAAE,CAAC;CACjC;AAkCD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,OAAO,EACZ,aAAa,CAAC,EAAE,MAAM,GACrB,YAAY,CAgCd"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function invalid(field) {
|
|
2
|
+
throw new Error(`account state decode: invalid ${field}`);
|
|
3
|
+
}
|
|
4
|
+
function tuple(value, length, field) {
|
|
5
|
+
if (!Array.isArray(value) || value.length !== length)
|
|
6
|
+
return invalid(field);
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function integer(value, field, signed = false) {
|
|
10
|
+
if (typeof value === "number" && Number.isSafeInteger(value))
|
|
11
|
+
value = BigInt(value);
|
|
12
|
+
const min = signed ? -(1n << 63n) : 0n;
|
|
13
|
+
const max = signed ? (1n << 63n) - 1n : (1n << 64n) - 1n;
|
|
14
|
+
if (typeof value !== "bigint" || value < min || value > max)
|
|
15
|
+
return invalid(field);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function owner(value) {
|
|
19
|
+
if (!(value instanceof Uint8Array) && !Array.isArray(value))
|
|
20
|
+
return invalid("owner");
|
|
21
|
+
const bytes = Array.from(value);
|
|
22
|
+
if (bytes.length !== 20 ||
|
|
23
|
+
bytes.some((b) => typeof b !== "number" || !Number.isInteger(b) || b < 0 || b > 255))
|
|
24
|
+
return invalid("owner");
|
|
25
|
+
return bytes
|
|
26
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
27
|
+
.join("");
|
|
28
|
+
}
|
|
29
|
+
export function decodeAccountState(raw, expectedOwner) {
|
|
30
|
+
const fields = tuple(raw, 4, "response");
|
|
31
|
+
const address = owner(fields[0]);
|
|
32
|
+
if (expectedOwner !== undefined && address !== expectedOwner.toLowerCase())
|
|
33
|
+
return invalid("owner binding");
|
|
34
|
+
if (!Array.isArray(fields[3]) || fields[3].length > 2048)
|
|
35
|
+
return invalid("positions");
|
|
36
|
+
let previous = -1n;
|
|
37
|
+
const positions = fields[3].map((rawPosition) => {
|
|
38
|
+
const p = tuple(rawPosition, 6, "position");
|
|
39
|
+
const positionOwner = owner(p[0]);
|
|
40
|
+
const market = integer(p[1], "market");
|
|
41
|
+
if (market > 0xffffffffn || market <= previous || positionOwner !== address)
|
|
42
|
+
return invalid("position binding/order");
|
|
43
|
+
previous = market;
|
|
44
|
+
const side = p[2];
|
|
45
|
+
if (side !== "Buy" && side !== "Sell")
|
|
46
|
+
return invalid("side");
|
|
47
|
+
return {
|
|
48
|
+
owner: positionOwner,
|
|
49
|
+
market: Number(market),
|
|
50
|
+
side,
|
|
51
|
+
entryPrice: integer(p[3], "entry price"),
|
|
52
|
+
size: integer(p[4], "size"),
|
|
53
|
+
lastFundingIndex: integer(p[5], "funding index", true),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
owner: address,
|
|
58
|
+
finalizedHeight: integer(fields[1], "height"),
|
|
59
|
+
balance: integer(fields[2], "balance"),
|
|
60
|
+
positions,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=account-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-state.js","sourceRoot":"","sources":["../src/account-state.ts"],"names":[],"mappings":"AAgBA,SAAS,OAAO,CAAC,KAAa;IAC5B,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;AAC5D,CAAC;AACD,SAAS,KAAK,CAAC,KAAc,EAAE,MAAc,EAAE,KAAa;IAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC;AACf,CAAC;AACD,SAAS,OAAO,CAAC,KAAc,EAAE,KAAa,EAAE,MAAM,GAAG,KAAK;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;QAC1D,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,EA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,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC;SACvD,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,KAAK,EAAE,OAAO;QACd,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC7C,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC;QACtC,SAAS;KACV,CAAC;AACJ,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type AccountState } from "./account-state.js";
|
|
2
|
+
import { type FinancialState, type FinancialStateSelection } from "./financial-state.js";
|
|
3
|
+
import type { Action, TxResult, PlaceOrder, MarketOrder, AccountInfo, HistoryCashFlow, HistoryFillsPage, HistoryPositionSnapshot, HistoryResolution, MarketConfig, OpenOrder, AdlQueueEntry, Orderbook, Ticker, WithdrawalRecord, AdminSignerRegistry, ProposalPage, ImpactMarketInfo, EventInfo, SetPositionTriggers, PositionTriggerInfo, TriggerStatus, PositionTriggerHistoryFilters, PositionTriggerHistoryPage, TriggerMarketHistoryFilters, TriggerMarketHistoryPage, TriggerMarketConfigInfo } from "./types.js";
|
|
4
|
+
import type { MarketsSnapshot } from "./types.js";
|
|
5
|
+
import { type OraclePermissions } from "./oracle-permissions.js";
|
|
2
6
|
/**
|
|
3
7
|
* Fetch the 32-byte chain_id binding from a CometBFT RPC's `/status`
|
|
4
8
|
* endpoint. Hashes `result.node_info.network` via `chainIdFromString`.
|
|
@@ -128,6 +132,8 @@ export declare class ExchangeClient {
|
|
|
128
132
|
* `/v1/status`, or `${rpcUrl}/status` on the direct path) on first submit.
|
|
129
133
|
*/
|
|
130
134
|
private chainId;
|
|
135
|
+
/** Inventory reconciliation requires the caller's pin, not auto-discovery. */
|
|
136
|
+
private readonly inventoryChainId;
|
|
131
137
|
private allowUnbound;
|
|
132
138
|
/** Single-flight guard so concurrent submits share one /status fetch. */
|
|
133
139
|
private chainIdPromise;
|
|
@@ -445,6 +451,9 @@ export declare class ExchangeClient {
|
|
|
445
451
|
*/
|
|
446
452
|
private queryOwnerScoped;
|
|
447
453
|
queryOrderbook(market: number): Promise<Orderbook>;
|
|
454
|
+
/** One atomic committed inventory. Requires explicit chainId; never falls
|
|
455
|
+
* back to a node or synthesizes inventory from independent list reads. */
|
|
456
|
+
queryMarketsSnapshot(): Promise<MarketsSnapshot>;
|
|
448
457
|
/** List all registered market configs. */
|
|
449
458
|
queryMarkets(): Promise<MarketConfig[]>;
|
|
450
459
|
/** List all impact-market families (the 5-book event structures: an
|
|
@@ -453,6 +462,16 @@ export declare class ExchangeClient {
|
|
|
453
462
|
* never a partially-rendered list (decoder pinned to engine golden bytes
|
|
454
463
|
* in governance-query.test.ts). */
|
|
455
464
|
queryImpactMarkets(): Promise<ImpactMarketInfo[]>;
|
|
465
|
+
/** All standalone events (G17). Each is two prediction-binary books (EBY/EBN)
|
|
466
|
+
* under one `EventInfo`, no underlying perp. Fail-closed like the impact
|
|
467
|
+
* read: a missing envelope or malformed row is a refusal. Decoder pinned to
|
|
468
|
+
* the engine golden vector in governance-query.test.ts. */
|
|
469
|
+
queryEvents(): Promise<EventInfo[]>;
|
|
470
|
+
/** A single standalone event by id, or `null` if it does not exist. The node
|
|
471
|
+
* returns 404 for a missing event (the engine's msgpack-nil, translated like
|
|
472
|
+
* the impact-market route), so a raw fetch is used here to map 404 -> null
|
|
473
|
+
* while still throwing on real transport / decode failures. */
|
|
474
|
+
queryEvent(eventId: number): Promise<EventInfo | null>;
|
|
456
475
|
/** Current whole-position trigger brackets for one owner. Immutable
|
|
457
476
|
* lifecycle history is a separate gateway/indexer query below. */
|
|
458
477
|
queryPositionTriggers(addressHex?: string): Promise<PositionTriggerInfo[]>;
|
|
@@ -462,6 +481,8 @@ export declare class ExchangeClient {
|
|
|
462
481
|
/** Read the fail-closed next-height trigger admission predicate. Heights
|
|
463
482
|
* are parsed from raw JSON into bigint without a lossy Number round-trip. */
|
|
464
483
|
queryTriggerStatus(): Promise<TriggerStatus>;
|
|
484
|
+
/** One committed oracle dependency, not provider health or action authorization. */
|
|
485
|
+
queryOraclePermissions(market: number): Promise<OraclePermissions>;
|
|
465
486
|
/** Immutable owner-bearing trigger lifecycle history. This always uses the
|
|
466
487
|
* public gateway, including when the client is configured for direct-node
|
|
467
488
|
* current-state reads; the node does not own indexer history. */
|
|
@@ -504,6 +525,10 @@ export declare class ExchangeClient {
|
|
|
504
525
|
/** Fetch a withdrawal record by id. Returns `null` for unknown ids
|
|
505
526
|
* (the engine encodes "not found" as msgpack `nil`, not HTTP 404). */
|
|
506
527
|
queryWithdrawal(id: bigint): Promise<WithdrawalRecord | null>;
|
|
528
|
+
/** Raw finalized ledger facts, independent of oracle valuation. Not authorization. */
|
|
529
|
+
queryFinancialState(selection: FinancialStateSelection): Promise<FinancialState>;
|
|
530
|
+
/** Raw finalized ledger facts, independent of oracle valuation. Not authorization. */
|
|
531
|
+
queryAccountState(addressHex?: string): Promise<AccountState>;
|
|
507
532
|
queryAccount(addressHex?: string): Promise<AccountInfo | null>;
|
|
508
533
|
/** Convenience: fetch just the USDC balance (microUSDC) for an address. */
|
|
509
534
|
queryBalance(addressHex?: string): Promise<bigint | null>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC7B,MAAM,sBAAsB,CAAC;AAkB9B,OAAO,KAAK,EACV,MAAM,EAEN,QAAQ,EACR,UAAU,EACV,WAAW,EACX,WAAW,EAGX,eAAe,EACf,gBAAg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AC,MAAM,EAAE,OAAO,CAAC,CAAC;IAoBnE;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAkElB,wEAAwE;IACxE,UAAU;CAGX;AAED,4DAA4D;AAC5D,MAAM,WAAW,eAAe;IAC9B;4DACwD;IACxD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC;gEAC4D;IAC5D,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
package/dist/client.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { signAndEncode } from "./codec.js";
|
|
2
|
+
import { decodeAccountState } from "./account-state.js";
|
|
3
|
+
import { fetchFinancialState, } from "./financial-state.js";
|
|
2
4
|
import { ready as initWasm } from "./wasm-loader.js";
|
|
3
5
|
import { txEngineError, txFromEngineCode, txOk, txTimeout, txTransportError, } from "./tx-result.js";
|
|
4
6
|
import { getPublicKey, pubkeyToOwner, ownerToHex, bytesToHex, sign, UNBOUND_CHAIN_ID, chainIdFromString, } from "./crypto.js";
|
|
5
|
-
import { decodeAdminSignerRegistryInfo, decodeImpactMarketInfo, decodeProposalPage, } from "./governance-query.js";
|
|
7
|
+
import { decodeAdminSignerRegistryInfo, decodeImpactMarketInfo, decodeEventInfo, decodeProposalPage, } from "./governance-query.js";
|
|
6
8
|
import { Decoder } from "@msgpack/msgpack";
|
|
9
|
+
import { readMarketsSnapshot } from "./market-snapshot.js";
|
|
7
10
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
8
11
|
import { decodePositionTriggerInfos, decodeTriggerMarketConfigInfos, decodeTriggerStatusJson, validateCancelPositionTriggers, validateSetPositionTriggers, } from "./triggers.js";
|
|
9
12
|
import { decodePositionTriggerHistoryPage, decodeTriggerMarketHistoryPage, positionTriggerHistorySearchParams, triggerMarketHistorySearchParams, validateTriggerHistoryMarket, } from "./trigger-history.js";
|
|
10
13
|
const msgpackDecoder = new Decoder({ useBigInt64: true });
|
|
14
|
+
import { decodeOraclePermissions, validateOraclePermissionMarket, } from "./oracle-permissions.js";
|
|
11
15
|
/**
|
|
12
16
|
* Fetch the 32-byte chain_id binding from a CometBFT RPC's `/status`
|
|
13
17
|
* endpoint. Hashes `result.node_info.network` via `chainIdFromString`.
|
|
@@ -42,6 +46,8 @@ export class ExchangeClient {
|
|
|
42
46
|
* `/v1/status`, or `${rpcUrl}/status` on the direct path) on first submit.
|
|
43
47
|
*/
|
|
44
48
|
chainId;
|
|
49
|
+
/** Inventory reconciliation requires the caller's pin, not auto-discovery. */
|
|
50
|
+
inventoryChainId;
|
|
45
51
|
allowUnbound;
|
|
46
52
|
/** Single-flight guard so concurrent submits share one /status fetch. */
|
|
47
53
|
chainIdPromise = null;
|
|
@@ -96,6 +102,7 @@ export class ExchangeClient {
|
|
|
96
102
|
// path resolveChainId() fetches /status on first submit; on the gateway
|
|
97
103
|
// path chainId must be pinned (the gateway does not serve /status).
|
|
98
104
|
this.chainId = opts.chainId ? chainIdFromString(opts.chainId) : null;
|
|
105
|
+
this.inventoryChainId = this.chainId?.slice() ?? null;
|
|
99
106
|
this.allowUnbound = opts.allowUnbound ?? false;
|
|
100
107
|
void opts.concurrentNonces;
|
|
101
108
|
}
|
|
@@ -811,6 +818,14 @@ export class ExchangeClient {
|
|
|
811
818
|
asks: raw[1].map(parseLevel),
|
|
812
819
|
};
|
|
813
820
|
}
|
|
821
|
+
/** One atomic committed inventory. Requires explicit chainId; never falls
|
|
822
|
+
* back to a node or synthesizes inventory from independent list reads. */
|
|
823
|
+
async queryMarketsSnapshot() {
|
|
824
|
+
if (!this.inventoryChainId) {
|
|
825
|
+
throw new Error("market snapshot requires an explicit pinned chainId");
|
|
826
|
+
}
|
|
827
|
+
return readMarketsSnapshot(this.gatewayUrl, this.inventoryChainId);
|
|
828
|
+
}
|
|
814
829
|
/** List all registered market configs. */
|
|
815
830
|
async queryMarkets() {
|
|
816
831
|
const json = await fetchApiJson(`${this.readBaseUrl}/v1/markets`);
|
|
@@ -834,6 +849,42 @@ export class ExchangeClient {
|
|
|
834
849
|
}
|
|
835
850
|
return raw.map((r, i) => decodeImpactMarketInfo(r, i));
|
|
836
851
|
}
|
|
852
|
+
/** All standalone events (G17). Each is two prediction-binary books (EBY/EBN)
|
|
853
|
+
* under one `EventInfo`, no underlying perp. Fail-closed like the impact
|
|
854
|
+
* read: a missing envelope or malformed row is a refusal. Decoder pinned to
|
|
855
|
+
* the engine golden vector in governance-query.test.ts. */
|
|
856
|
+
async queryEvents() {
|
|
857
|
+
const json = await fetchApiJson(`${this.readBaseUrl}/v1/events`);
|
|
858
|
+
if (typeof json.data !== "string") {
|
|
859
|
+
throw new Error("governance decode: events response has no encoded-data envelope");
|
|
860
|
+
}
|
|
861
|
+
const raw = msgpackDecoder.decode(fromBase64(json.data));
|
|
862
|
+
if (!Array.isArray(raw)) {
|
|
863
|
+
throw new Error("governance decode: events is not an array");
|
|
864
|
+
}
|
|
865
|
+
return raw.map((r, i) => decodeEventInfo(r, i));
|
|
866
|
+
}
|
|
867
|
+
/** A single standalone event by id, or `null` if it does not exist. The node
|
|
868
|
+
* returns 404 for a missing event (the engine's msgpack-nil, translated like
|
|
869
|
+
* the impact-market route), so a raw fetch is used here to map 404 -> null
|
|
870
|
+
* while still throwing on real transport / decode failures. */
|
|
871
|
+
async queryEvent(eventId) {
|
|
872
|
+
const res = await fetch(`${this.readBaseUrl}/v1/event/${eventId}`);
|
|
873
|
+
if (res.status === 404)
|
|
874
|
+
return null;
|
|
875
|
+
const json = (await res.json());
|
|
876
|
+
if (!res.ok || json.error) {
|
|
877
|
+
const msg = json.error ?? `HTTP ${res.status}`;
|
|
878
|
+
throw new Error(`API error: ${msg}`);
|
|
879
|
+
}
|
|
880
|
+
if (typeof json.data !== "string") {
|
|
881
|
+
throw new Error("governance decode: event response has no encoded-data envelope");
|
|
882
|
+
}
|
|
883
|
+
const raw = msgpackDecoder.decode(fromBase64(json.data));
|
|
884
|
+
if (raw == null)
|
|
885
|
+
return null;
|
|
886
|
+
return decodeEventInfo(raw);
|
|
887
|
+
}
|
|
837
888
|
/** Current whole-position trigger brackets for one owner. Immutable
|
|
838
889
|
* lifecycle history is a separate gateway/indexer query below. */
|
|
839
890
|
async queryPositionTriggers(addressHex) {
|
|
@@ -876,6 +927,14 @@ export class ExchangeClient {
|
|
|
876
927
|
}
|
|
877
928
|
return decodeTriggerStatusJson(text);
|
|
878
929
|
}
|
|
930
|
+
/** One committed oracle dependency, not provider health or action authorization. */
|
|
931
|
+
async queryOraclePermissions(market) {
|
|
932
|
+
validateOraclePermissionMarket(market);
|
|
933
|
+
const path = `/v1/oracle/permissions/${market}`;
|
|
934
|
+
const json = await fetchApiJson(`${this.readBaseUrl}${path}`);
|
|
935
|
+
const bytes = fromBase64(requireEncodedData(json, path));
|
|
936
|
+
return decodeOraclePermissions(msgpackDecoder.decode(bytes), market);
|
|
937
|
+
}
|
|
879
938
|
/** Immutable owner-bearing trigger lifecycle history. This always uses the
|
|
880
939
|
* public gateway, including when the client is configured for direct-node
|
|
881
940
|
* current-state reads; the node does not own indexer history. */
|
|
@@ -987,6 +1046,21 @@ export class ExchangeClient {
|
|
|
987
1046
|
requestHeight: BigInt(raw[5]),
|
|
988
1047
|
};
|
|
989
1048
|
}
|
|
1049
|
+
/** Raw finalized ledger facts, independent of oracle valuation. Not authorization. */
|
|
1050
|
+
async queryFinancialState(selection) {
|
|
1051
|
+
return fetchFinancialState(this.gatewayUrl, selection);
|
|
1052
|
+
}
|
|
1053
|
+
/** Raw finalized ledger facts, independent of oracle valuation. Not authorization. */
|
|
1054
|
+
async queryAccountState(addressHex) {
|
|
1055
|
+
const hex = addressHex ?? this.addressHex;
|
|
1056
|
+
if (!hex || !/^[0-9a-fA-F]{40}$/.test(hex)) {
|
|
1057
|
+
throw new Error("account state owner must be a 40-character hex address");
|
|
1058
|
+
}
|
|
1059
|
+
const owner = hex.toLowerCase();
|
|
1060
|
+
const path = `/v1/account/${owner}/state`;
|
|
1061
|
+
const json = await fetchApiJson(`${this.readBaseUrl}${path}`);
|
|
1062
|
+
return decodeAccountState(msgpackDecoder.decode(fromBase64(requireEncodedData(json, path))), owner);
|
|
1063
|
+
}
|
|
990
1064
|
async queryAccount(addressHex) {
|
|
991
1065
|
const hex = addressHex ?? this.addressHex;
|
|
992
1066
|
if (!hex)
|