@proof-labs/trading-sdk 5.1.0 → 5.3.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 +27 -0
- package/dist/client.js +18 -3
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +13 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +22 -3
- package/dist/errors.js.map +1 -1
- package/dist/gateway-reads.d.ts +11 -0
- package/dist/gateway-reads.d.ts.map +1 -1
- package/dist/gateway-reads.js +29 -2
- package/dist/gateway-reads.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/market-stats.d.ts +49 -0
- package/dist/market-stats.d.ts.map +1 -0
- package/dist/market-stats.js +138 -0
- package/dist/market-stats.js.map +1 -0
- package/dist/sub-accounts.d.ts +18 -0
- package/dist/sub-accounts.d.ts.map +1 -0
- package/dist/sub-accounts.js +132 -0
- package/dist/sub-accounts.js.map +1 -0
- package/dist/trigger-history.d.ts.map +1 -1
- package/dist/trigger-history.js +64 -1
- package/dist/trigger-history.js.map +1 -1
- package/dist/types.d.ts +50 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/wasm/proof_trading_sdk_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type Address, Side, TimeInForce, ActionType, type ActionTypeValue, type Action, type TraderAction, type OperatorAction, type PlaceOrder, type CancelOrder, type CancelClientOrder, type CancelAllOrders, type CancelReplaceOrder, type AmendOrder, type AtomicBasketLeg, type AtomicBasketOrder, type ClosePosition, type OracleUpdate, type OracleUpdateComposite, type MarketOrder, type MarketsSnapshot, type Deposit, type Withdraw, type CreateMarket, type WithdrawRequest, type ConfirmDeposit, type DepositLocator, type ConfirmWithdrawal, type FailWithdrawal, type ConfirmWithdrawalReceipt, type FailWithdrawalReceipt, type AuthorizeWithdrawal, type TriggerLimb, type SetPositionTriggers, type CancelPositionTriggers, type SetTriggerMarketConfig, type SetOracleGuards, type BridgeWithdrawalReceipt, type OperatorReceiptProof, type ApproveAgent, type RevokeAgent, type EventOracleSource, type PriceComparison, type ResolveEvent, type CreateEvent, type AttachConditional, type AttachedConditional, type EventInfo, type EventStatus, type CreateSubAccount, type SubAccountTransfer, type ClaimWithdrawalPayout, type UpdateMarketFees, type SetUserMarketLeverage, type GovernanceAction, type AdminAction, type AdminBatchItem, type EmergencyAction, type UpdateAdminSignerRegistry, type CancelAllOrdersForAccount, type ProposeAdminAction, type ApproveAdminAction, type RejectAdminAction, type EmergencyAdminAction, type AdminSignerRegistry, type ExpiryReason, type ProposalStatus, type ProposalDisplayInfo, type ProposalPage, Branch, Outcome, type TxResult, type TxOutcome, type TxEvent, type ExchangeEvent, type OrderPlacedEvent, type OrderCancelledEvent, type TradeExecutedEvent, type PositionUpdatedEvent, type PositionClosedEvent, type PriceUpdatedEvent, type FundingAppliedEvent, type FundingSettledEvent, type AccountLiquidatedEvent, type MarketCreatedEvent, type AdlQueueEntry, type Ticker, type Orderbook, type OrderbookLevel, type OpenOrder, type TriggerKind, type TriggerLimbState, type TriggerOutcomeReason, type TriggerEvaluation, type StoredTriggerLimb, type TriggerMarketConfig, type PendingTriggerMarketConfig, type TriggerMarketConfigState, type TriggerMarketConfigInfo, type TriggerEffectiveAvailability, type PositionTriggerBracket, type PositionTriggerInfo, type TriggerStatus, type TriggerHistoryTime, type PositionTriggerHistoryFilters, type TriggerMarketHistoryFilters, type PositionTriggerHistoryEventType, type TriggerMarketHistoryEventType, type TriggerHistoryEventType, type TriggerHistoryPayloadBase, type OwnerTriggerHistoryPayloadBase, type PositionTriggersSetHistoryPayload, type PositionTriggersCancelledHistoryPayload, type PositionTriggersInvalidatedHistoryPayload, type PositionTriggerActivatedHistoryPayload, type PositionTriggerExecutedHistoryPayload, type PositionTriggerDeferredHistoryPayload, type TriggerMarketDeferredHistoryPayload, type TriggerMarketResumedHistoryPayload, type TriggerHistoryEvent, type PositionTriggerHistoryEvent, type TriggerMarketHistoryEvent, type PositionTriggerHistoryPage, type TriggerMarketHistoryPage, type AccountInfo, type PositionInfo, type MarketConfig, type MarkSourceMode, type BindingScenarioEntry, type HistoryCashFlow, type HistoryFill, type HistoryFillsPage, type HistoryResolution, type HistoryPositionSnapshot, type HistoryPosition, type HistoryPositionsPage, type WithdrawalStatus, type WithdrawalRecord, type MarketKind, type FeeTier, type AgentApprovedEvent, type AgentRevokedEvent, type FeesCollectedEvent, } from "./types.js";
|
|
1
|
+
export { type Address, Side, TimeInForce, ActionType, type ActionTypeValue, type Action, type TraderAction, type OperatorAction, type PlaceOrder, type CancelOrder, type CancelClientOrder, type CancelAllOrders, type CancelReplaceOrder, type AmendOrder, type AtomicBasketLeg, type AtomicBasketOrder, type ClosePosition, type OracleUpdate, type OracleUpdateComposite, type MarketOrder, type MarketsSnapshot, type Deposit, type Withdraw, type CreateMarket, type WithdrawRequest, type ConfirmDeposit, type DepositLocator, type ConfirmWithdrawal, type FailWithdrawal, type ConfirmWithdrawalReceipt, type FailWithdrawalReceipt, type AuthorizeWithdrawal, type TriggerLimb, type SetPositionTriggers, type CancelPositionTriggers, type SetTriggerMarketConfig, type SetOracleGuards, type BridgeWithdrawalReceipt, type OperatorReceiptProof, type ApproveAgent, type RevokeAgent, type EventOracleSource, type PriceComparison, type ResolveEvent, type CreateEvent, type AttachConditional, type AttachedConditional, type EventInfo, type EventStatus, type CreateSubAccount, type SubAccountTransfer, type ClaimWithdrawalPayout, type UpdateMarketFees, type SetUserMarketLeverage, type GovernanceAction, type AdminAction, type AdminBatchItem, type EmergencyAction, type UpdateAdminSignerRegistry, type CancelAllOrdersForAccount, type ProposeAdminAction, type ApproveAdminAction, type RejectAdminAction, type EmergencyAdminAction, type AdminSignerRegistry, type ExpiryReason, type ProposalStatus, type ProposalDisplayInfo, type ProposalPage, Branch, Outcome, type TxResult, type TxOutcome, type TxEvent, type ExchangeEvent, type OrderPlacedEvent, type OrderCancelledEvent, type TradeExecutedEvent, type PositionUpdatedEvent, type PositionClosedEvent, type PriceUpdatedEvent, type FundingAppliedEvent, type FundingSettledEvent, type AccountLiquidatedEvent, type MarketCreatedEvent, type AdlQueueEntry, type Ticker, type Orderbook, type OrderbookLevel, type OpenOrder, type TriggerKind, type TriggerLimbState, type TriggerOutcomeReason, type TriggerEvaluation, type StoredTriggerLimb, type TriggerMarketConfig, type PendingTriggerMarketConfig, type TriggerMarketConfigState, type TriggerMarketConfigInfo, type TriggerEffectiveAvailability, type PositionTriggerBracket, type PositionTriggerInfo, type TriggerStatus, type TriggerHistoryTime, type PositionTriggerHistoryFilters, type TriggerMarketHistoryFilters, type PositionTriggerHistoryEventType, type TriggerMarketHistoryEventType, type TriggerHistoryEventType, type TriggerHistoryPayloadBase, type OwnerTriggerHistoryPayloadBase, type PendingTriggerHistoryPayloadBase, type PendingTriggersAttachedHistoryPayload, type PendingTriggersDiscardedHistoryPayload, type PendingTriggerDiscardReason, type PositionTriggersSetHistoryPayload, type PositionTriggersCancelledHistoryPayload, type PositionTriggersInvalidatedHistoryPayload, type PositionTriggerActivatedHistoryPayload, type PositionTriggerExecutedHistoryPayload, type PositionTriggerDeferredHistoryPayload, type TriggerMarketDeferredHistoryPayload, type TriggerMarketResumedHistoryPayload, type TriggerHistoryEvent, type PositionTriggerHistoryEvent, type TriggerMarketHistoryEvent, type PositionTriggerHistoryPage, type TriggerMarketHistoryPage, type AccountInfo, type PositionInfo, type MarketConfig, type MarkSourceMode, type BindingScenarioEntry, type HistoryCashFlow, type HistoryFill, type HistoryFillsPage, type HistoryResolution, type HistoryPositionSnapshot, type HistoryPosition, type HistoryPositionsPage, type WithdrawalStatus, type WithdrawalRecord, type MarketKind, type FeeTier, type AgentApprovedEvent, type AgentRevokedEvent, type FeesCollectedEvent, } from "./types.js";
|
|
2
2
|
export { MAX_TRIGGER_SLIPPAGE_BPS, validateSetPositionTriggers, validateCancelPositionTriggers, validateOrderTriggers, type OrderTriggerFields, validateSetTriggerMarketConfig, decodePositionTriggerInfos, decodeTriggerMarketConfigInfos, decodeTriggerStatusJson, } from "./triggers.js";
|
|
3
3
|
export { validateSetOracleGuards } from "./oracle-guards.js";
|
|
4
4
|
export { decodePositionTriggerHistoryPage, decodeTriggerMarketHistoryPage, positionTriggerHistorySearchParams, triggerMarketHistorySearchParams, } from "./trigger-history.js";
|
|
@@ -6,7 +6,7 @@ export { ENVELOPE_VERSION, encodeSignedTx, signAndEncode, signEnvelopeFromPayloa
|
|
|
6
6
|
export { ready } from "./wasm-loader.js";
|
|
7
7
|
export { decodeAdminAction, decodeAdminSignerRegistry, decodeAdminSignerRegistryInfo, decodeProposalPage, decodeProposalDisplayInfo, decodeProposalStatus, } from "./governance-query.js";
|
|
8
8
|
export { fetchChainId } from "./client.js";
|
|
9
|
-
export { GatewayHttpError, type ExecErrorInfo, ExecErrorCode, decodeExecError, execErrorName, } from "./errors.js";
|
|
9
|
+
export { GatewayHttpError, isMissingMark, type ExecErrorInfo, ExecErrorCode, decodeExecError, execErrorName, } from "./errors.js";
|
|
10
10
|
export { generateKeypair, getPublicKey, pubkeyToOwner, deriveSubAccount, SUB_ACCOUNT_DERIVATION_DOMAIN, ownerToHex, hexToBytes, bytesToHex, signingMessage, sign, verify, chainIdFromString, UNBOUND_CHAIN_ID, DOMAIN_PREFIX, } from "./crypto.js";
|
|
11
11
|
export { ExchangeClient, type ExchangeClientOptions, type WsStreamOptions, } from "./client.js";
|
|
12
12
|
export { decodeOraclePermissions } from "./oracle-permissions.js";
|
|
@@ -16,7 +16,9 @@ export type { OraclePermissions, OraclePolicyEpoch, OraclePolicySource, Committe
|
|
|
16
16
|
export { GatewayFeed, type GatewayFeedOptions, type AccountFeedAuth, type AccountAuthProvider, type WebSocketLike, type WebSocketFactory, } from "./feed.js";
|
|
17
17
|
export type { FeedChannel, FeedOrderbookLevel, OrderbookSnapshotFrame, OrderbookUpdateFrame, OrderbookFrame, TradeFrame, AccountSnapshotFrame, AccountEventFrame, AccountFrame, FeedFrame, FeedErrorFrame, FeedState, } from "./feed-types.js";
|
|
18
18
|
export { type GatewayReads, type GatewayReadOptions, type GatewayFetch, type HistoryWindow, type OwnerHistoryParams, type CandleHistoryParams, type AccountEventsParams, type GatewayTriggerLimbJson, type GatewayPendingTriggerRow, type GatewayTriggerPositionRow, } from "./gateway-reads.js";
|
|
19
|
+
export { decodeSubAccountList, type SubAccountListRow, } from "./sub-accounts.js";
|
|
19
20
|
export type { ExternalSigner } from "./client.js";
|
|
20
21
|
export type { PortfolioHistoryOptions, PortfolioHistoryPage, } from "./portfolio-history.js";
|
|
21
22
|
export { queryOraclePriceHistoryPage, type OraclePriceHistoryPoint, type OraclePriceHistoryPage, type OraclePriceHistoryOptions, } from "./oracle-price-history.js";
|
|
23
|
+
export { queryMarketStats, decodeMarketStatsResponse, type MarketStatsResponse, type MarketStats, type MarketStatsStatus, } from "./market-stats.js";
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EACZ,IAAI,EACJ,WAAW,EACX,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cA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EACjB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EACV,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EACZ,IAAI,EACJ,WAAW,EACX,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,iBA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EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EACV,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export { ready } from "./wasm-loader.js";
|
|
|
15
15
|
export { decodeAdminAction, decodeAdminSignerRegistry, decodeAdminSignerRegistryInfo, decodeProposalPage, decodeProposalDisplayInfo, decodeProposalStatus, } from "./governance-query.js";
|
|
16
16
|
export { fetchChainId } from "./client.js";
|
|
17
17
|
// Errors
|
|
18
|
-
export { GatewayHttpError, ExecErrorCode, decodeExecError, execErrorName, } from "./errors.js";
|
|
18
|
+
export { GatewayHttpError, isMissingMark, ExecErrorCode, decodeExecError, execErrorName, } from "./errors.js";
|
|
19
19
|
// Crypto
|
|
20
20
|
export { generateKeypair, getPublicKey, pubkeyToOwner, deriveSubAccount, SUB_ACCOUNT_DERIVATION_DOMAIN, ownerToHex, hexToBytes, bytesToHex, signingMessage, sign, verify, chainIdFromString, UNBOUND_CHAIN_ID, DOMAIN_PREFIX, } from "./crypto.js";
|
|
21
21
|
// Client
|
|
@@ -24,5 +24,7 @@ export { decodeOraclePermissions } from "./oracle-permissions.js";
|
|
|
24
24
|
export { decodeFinancialState, } from "./financial-state.js";
|
|
25
25
|
export { decodeAccountState, } from "./account-state.js";
|
|
26
26
|
export { GatewayFeed, } from "./feed.js";
|
|
27
|
+
export { decodeSubAccountList, } from "./sub-accounts.js";
|
|
27
28
|
export { queryOraclePriceHistoryPage, } from "./oracle-price-history.js";
|
|
29
|
+
export { queryMarketStats, decodeMarketStatsResponse, } from "./market-stats.js";
|
|
28
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAEL,IAAI,EACJ,WAAW,EACX,UAAU,EAkEV,MAAM,EACN,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAEL,IAAI,EACJ,WAAW,EACX,UAAU,EAkEV,MAAM,EACN,OAAO,GA6ER,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,8BAA8B,EAC9B,qBAAqB,EAErB,8BAA8B,EAC9B,0BAA0B,EAC1B,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EACL,gCAAgC,EAChC,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,GACjC,MAAM,sBAAsB,CAAC;AAE9B,QAAQ;AACR,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,QAAQ,EACR,oBAAoB,EAEpB,cAAc,EACd,wBAAwB,GAEzB,MAAM,YAAY,CAAC;AACpB,8EAA8E;AAC9E,+DAA+D;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,yEAAyE;AACzE,4EAA4E;AAC5E,wEAAwE;AACxE,sDAAsD;AACtD,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,6BAA6B,EAC7B,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,SAAS;AACT,OAAO,EACL,gBAAgB,EAChB,aAAa,EAEb,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,SAAS;AACT,OAAO,EACL,eAAe,EACf,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,6BAA6B,EAC7B,UAAU,EACV,UAAU,EACV,UAAU,EACV,cAAc,EACd,IAAI,EACJ,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,SAAS;AACT,OAAO,EACL,cAAc,GAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACL,oBAAoB,GAKrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,GAGnB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,EACL,WAAW,GAMZ,MAAM,WAAW,CAAC;AA2BnB,OAAO,EACL,oBAAoB,GAErB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,2BAA2B,GAI5B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,GAI1B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GatewayReadOptions, GatewayReads } from "./gateway-reads.js";
|
|
2
|
+
export type MarketStatsStatus = "ready" | "stale" | "unavailable";
|
|
3
|
+
export interface MarketStats {
|
|
4
|
+
market: number;
|
|
5
|
+
sz_decimals: number | null;
|
|
6
|
+
status: MarketStatsStatus;
|
|
7
|
+
unavailable_reason: string | null;
|
|
8
|
+
/** Sum of raw contract quantities across executions, counting each trade once. */
|
|
9
|
+
volume_24h_contracts: string | null;
|
|
10
|
+
/** Exact plain-decimal USDC dollars, already adjusted by sz_decimals. */
|
|
11
|
+
volume_24h_usdc: string | null;
|
|
12
|
+
/** Latest trade at or before window_start; raw integer micro-USDC. */
|
|
13
|
+
reference_price: string | null;
|
|
14
|
+
/** Latest trade before window_end; raw integer micro-USDC. */
|
|
15
|
+
last_price: string | null;
|
|
16
|
+
/** Signed basis points relative to reference_price, rounded to six decimals. */
|
|
17
|
+
change_24h_bps: string | null;
|
|
18
|
+
/** Trade extrema in [window_start, window_end); raw integer micro-USDC. */
|
|
19
|
+
high_price: string | null;
|
|
20
|
+
low_price: string | null;
|
|
21
|
+
/** Current committed raw contracts by side, not long plus short notional. */
|
|
22
|
+
open_interest: {
|
|
23
|
+
long_contracts: string;
|
|
24
|
+
short_contracts: string;
|
|
25
|
+
} | null;
|
|
26
|
+
open_interest_unavailable_reason: string | null;
|
|
27
|
+
}
|
|
28
|
+
export interface MarketStatsResponse {
|
|
29
|
+
as_of: string;
|
|
30
|
+
window_start: string;
|
|
31
|
+
window_end: string;
|
|
32
|
+
indexed_height: string | null;
|
|
33
|
+
indexed_at: string | null;
|
|
34
|
+
stale_after_seconds: number;
|
|
35
|
+
/** Indexer frontier freshness; inspect each market and metric's coverage too. */
|
|
36
|
+
status: MarketStatsStatus;
|
|
37
|
+
markets: MarketStats[];
|
|
38
|
+
}
|
|
39
|
+
/** Internal shared request validation for the raw and decoded read surfaces. */
|
|
40
|
+
export declare function marketStatsMarketIds(markets: readonly number[]): string;
|
|
41
|
+
/** One consistent indexed snapshot through the caller's SDK gateway transport.
|
|
42
|
+
* Unavailable metrics stay null; this read never substitutes zero or estimates.
|
|
43
|
+
*/
|
|
44
|
+
export declare function queryMarketStats(reads: Pick<GatewayReads, "marketStats">, markets: readonly number[], opts?: GatewayReadOptions): Promise<MarketStatsResponse>;
|
|
45
|
+
/** Decode without losing precision or confusing absent evidence with zero.
|
|
46
|
+
* Additive unknown fields are ignored for forward compatibility.
|
|
47
|
+
*/
|
|
48
|
+
export declare function decodeMarketStatsResponse(value: unknown): MarketStatsResponse;
|
|
49
|
+
//# sourceMappingURL=market-stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market-stats.d.ts","sourceRoot":"","sources":["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AgBD,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAOvE;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,EACxC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAiB9B;AA8CD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAgG7E"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** The history database's market key is signed int32, including market zero. */
|
|
2
|
+
function marketId(value) {
|
|
3
|
+
if (typeof value !== "number" ||
|
|
4
|
+
!Number.isInteger(value) ||
|
|
5
|
+
value < 0 ||
|
|
6
|
+
value > 0x7fff_ffff)
|
|
7
|
+
throw new Error("Invalid market statistics market: expected an integer in [0, 2147483647]");
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
/** Internal shared request validation for the raw and decoded read surfaces. */
|
|
11
|
+
export function marketStatsMarketIds(markets) {
|
|
12
|
+
if (!Array.isArray(markets) || markets.length < 1 || markets.length > 50)
|
|
13
|
+
throw new Error("Invalid market statistics request: expected 1–50 markets");
|
|
14
|
+
const ids = markets.map(marketId);
|
|
15
|
+
if (new Set(ids).size !== ids.length)
|
|
16
|
+
throw new Error("Invalid market statistics request: duplicate market");
|
|
17
|
+
return ids.join(",");
|
|
18
|
+
}
|
|
19
|
+
/** One consistent indexed snapshot through the caller's SDK gateway transport.
|
|
20
|
+
* Unavailable metrics stay null; this read never substitutes zero or estimates.
|
|
21
|
+
*/
|
|
22
|
+
export async function queryMarketStats(reads, markets, opts = {}) {
|
|
23
|
+
marketStatsMarketIds(markets);
|
|
24
|
+
const requested = [...markets];
|
|
25
|
+
opts.signal?.throwIfAborted();
|
|
26
|
+
const response = await reads.marketStats({ markets: requested }, opts);
|
|
27
|
+
const body = await response.json();
|
|
28
|
+
opts.signal?.throwIfAborted();
|
|
29
|
+
const decoded = decodeMarketStatsResponse(body);
|
|
30
|
+
const expected = new Set(requested);
|
|
31
|
+
if (decoded.markets.length !== expected.size ||
|
|
32
|
+
decoded.markets.some((row) => !expected.has(row.market)))
|
|
33
|
+
throw new Error("Invalid market statistics response: requested market coverage mismatch");
|
|
34
|
+
return decoded;
|
|
35
|
+
}
|
|
36
|
+
const UNSIGNED = /^(?:0|[1-9][0-9]*)$/;
|
|
37
|
+
const USDC = /^(?:0|[1-9][0-9]*)(?:\.[0-9]{1,24})?$/;
|
|
38
|
+
const BPS = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]{1,6})?$/;
|
|
39
|
+
function record(value) {
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
41
|
+
invalid("object");
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function invalid(field) {
|
|
45
|
+
throw new Error(`Invalid market statistics response: ${field}`);
|
|
46
|
+
}
|
|
47
|
+
function status(value) {
|
|
48
|
+
if (value !== "ready" && value !== "stale" && value !== "unavailable")
|
|
49
|
+
invalid("status");
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function reason(value, field) {
|
|
53
|
+
if (value !== null && typeof value !== "string")
|
|
54
|
+
invalid(field);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
function decimal(value, field, pattern = UNSIGNED) {
|
|
58
|
+
if (typeof value !== "string" || !pattern.test(value))
|
|
59
|
+
invalid(field);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function nullableDecimal(value, field, pattern = UNSIGNED) {
|
|
63
|
+
return value === null ? null : decimal(value, field, pattern);
|
|
64
|
+
}
|
|
65
|
+
function timestamp(value, field) {
|
|
66
|
+
if (typeof value !== "string" ||
|
|
67
|
+
!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(value) ||
|
|
68
|
+
!Number.isFinite(Date.parse(value)))
|
|
69
|
+
invalid(field);
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
/** Decode without losing precision or confusing absent evidence with zero.
|
|
73
|
+
* Additive unknown fields are ignored for forward compatibility.
|
|
74
|
+
*/
|
|
75
|
+
export function decodeMarketStatsResponse(value) {
|
|
76
|
+
const body = record(value);
|
|
77
|
+
const as_of = timestamp(body.as_of, "as_of");
|
|
78
|
+
const window_start = timestamp(body.window_start, "window_start");
|
|
79
|
+
const window_end = timestamp(body.window_end, "window_end");
|
|
80
|
+
if (Date.parse(as_of) !== Date.parse(window_end) ||
|
|
81
|
+
Date.parse(window_end) - Date.parse(window_start) !== 86_400_000)
|
|
82
|
+
invalid("rolling 24-hour window");
|
|
83
|
+
const indexed_height = nullableDecimal(body.indexed_height, "indexed_height", /^[1-9][0-9]*$/);
|
|
84
|
+
const indexed_at = body.indexed_at === null ? null : timestamp(body.indexed_at, "indexed_at");
|
|
85
|
+
if ((indexed_height === null) !== (indexed_at === null))
|
|
86
|
+
invalid("indexed frontier");
|
|
87
|
+
if (typeof body.stale_after_seconds !== "number" ||
|
|
88
|
+
!Number.isSafeInteger(body.stale_after_seconds) ||
|
|
89
|
+
body.stale_after_seconds <= 0)
|
|
90
|
+
invalid("stale_after_seconds");
|
|
91
|
+
if (!Array.isArray(body.markets) ||
|
|
92
|
+
body.markets.length < 1 ||
|
|
93
|
+
body.markets.length > 50)
|
|
94
|
+
invalid("markets");
|
|
95
|
+
const markets = body.markets.map((value) => {
|
|
96
|
+
const row = record(value);
|
|
97
|
+
if (row.sz_decimals !== null &&
|
|
98
|
+
(typeof row.sz_decimals !== "number" ||
|
|
99
|
+
!Number.isInteger(row.sz_decimals) ||
|
|
100
|
+
row.sz_decimals < 0 ||
|
|
101
|
+
row.sz_decimals > 18))
|
|
102
|
+
invalid("sz_decimals");
|
|
103
|
+
const oi = row.open_interest === null ? null : record(row.open_interest);
|
|
104
|
+
return {
|
|
105
|
+
market: marketId(row.market),
|
|
106
|
+
sz_decimals: row.sz_decimals,
|
|
107
|
+
status: status(row.status),
|
|
108
|
+
unavailable_reason: reason(row.unavailable_reason, "unavailable_reason"),
|
|
109
|
+
volume_24h_contracts: nullableDecimal(row.volume_24h_contracts, "volume_24h_contracts"),
|
|
110
|
+
volume_24h_usdc: nullableDecimal(row.volume_24h_usdc, "volume_24h_usdc", USDC),
|
|
111
|
+
reference_price: nullableDecimal(row.reference_price, "reference_price"),
|
|
112
|
+
last_price: nullableDecimal(row.last_price, "last_price"),
|
|
113
|
+
change_24h_bps: nullableDecimal(row.change_24h_bps, "change_24h_bps", BPS),
|
|
114
|
+
high_price: nullableDecimal(row.high_price, "high_price"),
|
|
115
|
+
low_price: nullableDecimal(row.low_price, "low_price"),
|
|
116
|
+
open_interest: oi === null
|
|
117
|
+
? null
|
|
118
|
+
: {
|
|
119
|
+
long_contracts: decimal(oi.long_contracts, "open_interest.long_contracts"),
|
|
120
|
+
short_contracts: decimal(oi.short_contracts, "open_interest.short_contracts"),
|
|
121
|
+
},
|
|
122
|
+
open_interest_unavailable_reason: reason(row.open_interest_unavailable_reason, "open_interest_unavailable_reason"),
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
if (new Set(markets.map((row) => row.market)).size !== markets.length)
|
|
126
|
+
invalid("duplicate market");
|
|
127
|
+
return {
|
|
128
|
+
as_of,
|
|
129
|
+
window_start,
|
|
130
|
+
window_end,
|
|
131
|
+
indexed_height,
|
|
132
|
+
indexed_at,
|
|
133
|
+
stale_after_seconds: body.stale_after_seconds,
|
|
134
|
+
status: status(body.status),
|
|
135
|
+
markets,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=market-stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market-stats.js","sourceRoot":"","sources":["../src/market-stats.ts"],"names":[],"mappings":"AAuCA,gFAAgF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O,CAAC,MAAM;QACnE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9B,OAAO;QACL,KAAK;QACL,YAAY;QACZ,UAAU;QACV,cAAc;QACd,UAAU;QACV,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface SubAccountListRow {
|
|
2
|
+
/** Derived child address, 40-char lowercase hex, no `0x` prefix. */
|
|
3
|
+
address: string;
|
|
4
|
+
/** Registering master, 40-char lowercase hex, no `0x` prefix. */
|
|
5
|
+
master: string;
|
|
6
|
+
/** Client-chosen id, 1..=0xFFFFFFFF, unique per master, never reused. */
|
|
7
|
+
id: number;
|
|
8
|
+
/** Display name, UTF-8, trailing NUL padding stripped. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Consensus height at which the child was registered. */
|
|
11
|
+
createdHeight: bigint;
|
|
12
|
+
}
|
|
13
|
+
/** Decode a `/info` `subAccountList` response: validate the
|
|
14
|
+
* `{"data": "<base64 msgpack>"}` envelope, decode the msgpack array of
|
|
15
|
+
* positional registry rows, and return typed rows. Throws on any deviation —
|
|
16
|
+
* including duplicate ids or addresses, which the registry never emits. */
|
|
17
|
+
export declare function decodeSubAccountList(body: unknown): SubAccountListRow[];
|
|
18
|
+
//# sourceMappingURL=sub-accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-accounts.d.ts","sourceRoot":"","sources":["../src/sub-accounts.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,EAAE,EAAE,MAAM,CAAC;IACX,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,aAAa,EAAE,MAAM,CAAC;CACvB;AAkFD;;;4EAG4E;AAC5E,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,EAAE,CAiCvE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** Sub-account registry read. The gateway serves
|
|
2
|
+
* `POST /info {"type":"subAccountList","user"}` by proxying the node's
|
|
3
|
+
* `GET /v1/sub_accounts/{addr}` verbatim, so the body is the house envelope
|
|
4
|
+
* `{"data": "<base64 msgpack>"}`. The inner payload is a msgpack array of
|
|
5
|
+
* `proof-wire` `SubAccount` rows. rmp-serde encodes each row as a positional
|
|
6
|
+
* array `[master, sub_account_id, address, name, created_height]`, and each
|
|
7
|
+
* fixed byte field as an array of integers (a bin is accepted too).
|
|
8
|
+
*
|
|
9
|
+
* Fail-closed like every decode module here: a malformed envelope, row or
|
|
10
|
+
* field throws rather than degrading a value-bearing read to empty state.
|
|
11
|
+
* An HTTP 501 from the route means the registry query is not available,
|
|
12
|
+
* never an empty registry. */
|
|
13
|
+
import { Decoder } from "@msgpack/msgpack";
|
|
14
|
+
/** Decode budget, not a business rule: the engine bounds the registry
|
|
15
|
+
* (per-owner ceiling plus a global bound); this only stops a hostile or
|
|
16
|
+
* garbled payload from allocating unbounded rows. Generous against any
|
|
17
|
+
* decided limit, so a legitimate registry never trips it. */
|
|
18
|
+
const MAX_ROWS = 4096;
|
|
19
|
+
function invalid(detail) {
|
|
20
|
+
throw new Error(`sub-account list decode: ${detail}`);
|
|
21
|
+
}
|
|
22
|
+
/** `wire_bytes` encodes `[u8; N]` as a msgpack ARRAY of integers; a BIN is
|
|
23
|
+
* accepted too. Either way the exact byte length is required. */
|
|
24
|
+
function fixedBytes(value, length, field) {
|
|
25
|
+
if (value instanceof Uint8Array) {
|
|
26
|
+
if (value.length !== length)
|
|
27
|
+
return invalid(`${field} length`);
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
if (value.length !== length)
|
|
32
|
+
return invalid(`${field} length`);
|
|
33
|
+
if (value.some((b) => !Number.isInteger(b) || b < 0 || b > 255))
|
|
34
|
+
return invalid(`${field} byte`);
|
|
35
|
+
return Uint8Array.from(value);
|
|
36
|
+
}
|
|
37
|
+
return invalid(`${field} encoding`);
|
|
38
|
+
}
|
|
39
|
+
function hex(bytes) {
|
|
40
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
41
|
+
}
|
|
42
|
+
function rowId(value) {
|
|
43
|
+
// A 64-bit msgpack integer decodes as a bigint; it is still an id, only
|
|
44
|
+
// out of range.
|
|
45
|
+
if (typeof value !== "bigint" && !Number.isSafeInteger(value))
|
|
46
|
+
return invalid("id");
|
|
47
|
+
const id = value;
|
|
48
|
+
if (id < 1 || id > 0xffffffff)
|
|
49
|
+
return invalid("id range (1..=0xFFFFFFFF, 0 is not a valid child id)");
|
|
50
|
+
return Number(id);
|
|
51
|
+
}
|
|
52
|
+
function createdHeight(value) {
|
|
53
|
+
if (typeof value === "number" && Number.isSafeInteger(value))
|
|
54
|
+
value = BigInt(value);
|
|
55
|
+
if (typeof value !== "bigint" || value < 0n || value >= 1n << 64n)
|
|
56
|
+
return invalid("created_height");
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function rowName(value) {
|
|
60
|
+
const bytes = fixedBytes(value, 32, "name");
|
|
61
|
+
let end = bytes.length;
|
|
62
|
+
while (end > 0 && bytes[end - 1] === 0)
|
|
63
|
+
end -= 1;
|
|
64
|
+
try {
|
|
65
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes.slice(0, end));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return invalid("name (invalid UTF-8)");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Wire field count of `SubAccount`. Later fields are appended as optional,
|
|
72
|
+
* so a longer row still decodes; a shorter one is malformed. */
|
|
73
|
+
const ROW_FIELDS = 5;
|
|
74
|
+
function decodeRow(raw) {
|
|
75
|
+
if (!Array.isArray(raw))
|
|
76
|
+
return invalid("row (expected a positional array)");
|
|
77
|
+
if (raw.length < ROW_FIELDS)
|
|
78
|
+
return invalid(`row (expected ${ROW_FIELDS} fields, got ${raw.length})`);
|
|
79
|
+
const [master, id, address, name, height] = raw;
|
|
80
|
+
return {
|
|
81
|
+
address: hex(fixedBytes(address, 20, "address")),
|
|
82
|
+
master: hex(fixedBytes(master, 20, "master")),
|
|
83
|
+
id: rowId(id),
|
|
84
|
+
name: rowName(name),
|
|
85
|
+
createdHeight: createdHeight(height),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Decode a `/info` `subAccountList` response: validate the
|
|
89
|
+
* `{"data": "<base64 msgpack>"}` envelope, decode the msgpack array of
|
|
90
|
+
* positional registry rows, and return typed rows. Throws on any deviation —
|
|
91
|
+
* including duplicate ids or addresses, which the registry never emits. */
|
|
92
|
+
export function decodeSubAccountList(body) {
|
|
93
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
94
|
+
return invalid("envelope (expected an object with a data field)");
|
|
95
|
+
const data = body.data;
|
|
96
|
+
if (typeof data !== "string" || data.length === 0)
|
|
97
|
+
return invalid("envelope data (expected base64 msgpack)");
|
|
98
|
+
let bytes;
|
|
99
|
+
try {
|
|
100
|
+
const binary = atob(data);
|
|
101
|
+
bytes = new Uint8Array(binary.length);
|
|
102
|
+
for (let i = 0; i < binary.length; i++)
|
|
103
|
+
bytes[i] = binary.charCodeAt(i);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return invalid("envelope data (invalid base64)");
|
|
107
|
+
}
|
|
108
|
+
let payload;
|
|
109
|
+
try {
|
|
110
|
+
payload = new Decoder({ useBigInt64: true }).decode(bytes);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return invalid("payload (invalid msgpack)");
|
|
114
|
+
}
|
|
115
|
+
if (!Array.isArray(payload))
|
|
116
|
+
return invalid("payload (expected an array)");
|
|
117
|
+
if (payload.length > MAX_ROWS)
|
|
118
|
+
return invalid(`payload length (exceeds ${MAX_ROWS} rows)`);
|
|
119
|
+
const seenIds = new Set();
|
|
120
|
+
const seenAddresses = new Set();
|
|
121
|
+
return payload.map((raw) => {
|
|
122
|
+
const row = decodeRow(raw);
|
|
123
|
+
if (seenIds.has(row.id))
|
|
124
|
+
return invalid(`duplicate id ${row.id}`);
|
|
125
|
+
if (seenAddresses.has(row.address))
|
|
126
|
+
return invalid("duplicate address");
|
|
127
|
+
seenIds.add(row.id);
|
|
128
|
+
seenAddresses.add(row.address);
|
|
129
|
+
return row;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=sub-accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-accounts.js","sourceRoot":"","sources":["../src/sub-accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;+BAW+B;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAe3C;;;8DAG8D;AAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEtB,SAAS,OAAO,CAAC,MAAc;IAC7B,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAM,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;kEACkE;AAClE,SAAS,UAAU,CAAC,KAAc,EAAE,MAAc,EAAE,KAAa;IAC/D,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;QAC/D,IAAI,KAAK,C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3E,IAAI,OAAO,CAAC,MAAM,GAAG,QAAQ;QAC3B,OAAO,OAAO,CAAC,2BAA2B,QAAQ,QAAQ,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACxC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAqB,EAAE;QAC5C,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,OAAO,CAAC,gBAAgB,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QAClE,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,OAAO,OAAO,CAAC,mBAAmB,CAAC,CAAC;QACxE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpB,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC/B,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-history.d.ts","sourceRoot":"","sources":["../src/trigger-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"trigger-history.d.ts","sourceRoot":"","sources":["../src/trigger-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,6BAA6B,EAC7B,0BAA0B,EAM1B,2BAA2B,EAC3B,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAkjBpB,kFAAkF;AAClF,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,OAAO,EACd,aAAa,EAAE,MAAM,EACrB,cAAc,CAAC,EAAE,MAAM,GACtB,0BAA0B,CAmB5B;AAED,+EAA+E;AAC/E,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,EACd,cAAc,EAAE,MAAM,GACrB,wBAAwB,CAiB1B;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlE;AA0DD,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAMjB;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,GAAE,2BAAgC,GACxC,eAAe,CAEjB"}
|
package/dist/trigger-history.js
CHANGED
|
@@ -10,6 +10,25 @@ const OWNER_EVENT_TYPES = new Set([
|
|
|
10
10
|
"position_trigger_activated",
|
|
11
11
|
"position_trigger_executed",
|
|
12
12
|
"position_trigger_deferred",
|
|
13
|
+
"pending_triggers_attached",
|
|
14
|
+
"pending_triggers_discarded",
|
|
15
|
+
]);
|
|
16
|
+
/** Owner lifecycle types bound to a position: they carry `position_epoch` and `group_id`. */
|
|
17
|
+
const POSITION_EVENT_TYPES = new Set([
|
|
18
|
+
"position_triggers_set",
|
|
19
|
+
"position_triggers_cancelled",
|
|
20
|
+
"position_triggers_invalidated",
|
|
21
|
+
"position_trigger_activated",
|
|
22
|
+
"position_trigger_executed",
|
|
23
|
+
"position_trigger_deferred",
|
|
24
|
+
]);
|
|
25
|
+
const PENDING_DISCARD_REASONS = new Set([
|
|
26
|
+
"order_cancelled",
|
|
27
|
+
"order_expired",
|
|
28
|
+
"order_replaced",
|
|
29
|
+
"unfilled_terminal",
|
|
30
|
+
"install_rejected",
|
|
31
|
+
"position_closed",
|
|
13
32
|
]);
|
|
14
33
|
const MARKET_EVENT_TYPES = new Set([
|
|
15
34
|
"trigger_market_deferred",
|
|
@@ -148,6 +167,19 @@ function requireUnsignedPayload(payload, keys) {
|
|
|
148
167
|
function requireNonemptyPayload(payload, key) {
|
|
149
168
|
return string(payload[key], `payload.${key}`);
|
|
150
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The wire's limb render for one pending-bracket limb: present is
|
|
172
|
+
* `trigger_price=<u64>,max_slippage_bps=<u64>,client_trigger_id=<u64|none>`
|
|
173
|
+
* (that exact shape and order); absent is the key with an empty value.
|
|
174
|
+
*/
|
|
175
|
+
const LIMB_RENDER = /^trigger_price=(?:0|[1-9][0-9]*),max_slippage_bps=(?:0|[1-9][0-9]*),client_trigger_id=(?:none|(?:0|[1-9][0-9]*))$/;
|
|
176
|
+
function requireLimbRender(value, name) {
|
|
177
|
+
if (value === "")
|
|
178
|
+
return;
|
|
179
|
+
if (!LIMB_RENDER.test(value)) {
|
|
180
|
+
throw new Error(`trigger history decode: ${name} is not the wire limb render`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
151
183
|
function validatePayload(payload, eventType, eventKey, blockHeight, executionOrdinal, eventOrdinal, market, eventOwner) {
|
|
152
184
|
unsigned(payload.block_height, "payload.block_height", U64_MAX, true);
|
|
153
185
|
unsigned(payload.execution_ordinal, "payload.execution_ordinal");
|
|
@@ -165,7 +197,11 @@ function validatePayload(payload, eventType, eventKey, blockHeight, executionOrd
|
|
|
165
197
|
owner(payload.owner, "payload.owner") !== eventOwner) {
|
|
166
198
|
throw new Error("trigger history decode: payload owner disagrees with event");
|
|
167
199
|
}
|
|
168
|
-
|
|
200
|
+
// A pending bracket is bound to a not-yet-filled order: it has no position
|
|
201
|
+
// identity yet, so it carries `order_id` instead of epoch/group.
|
|
202
|
+
if (POSITION_EVENT_TYPES.has(eventType)) {
|
|
203
|
+
requireUnsignedPayload(payload, ["position_epoch", "group_id"]);
|
|
204
|
+
}
|
|
169
205
|
}
|
|
170
206
|
else if ("owner" in payload) {
|
|
171
207
|
throw new Error("trigger history decode: shared market payload carries owner");
|
|
@@ -189,10 +225,37 @@ function validatePayload(payload, eventType, eventKey, blockHeight, executionOrd
|
|
|
189
225
|
if (payload.stop_limb_id === "0" && payload.take_profit_limb_id === "0") {
|
|
190
226
|
throw new Error("trigger history decode: set event has no trigger limbs");
|
|
191
227
|
}
|
|
228
|
+
// Additive since schema 39: the placement order whose first fill
|
|
229
|
+
// installed the bracket. "0" is the engine's none-sentinel; absent on
|
|
230
|
+
// rows projected before the attribute existed.
|
|
231
|
+
if (payload.source_order_id !== undefined) {
|
|
232
|
+
unsigned(payload.source_order_id, "payload.source_order_id");
|
|
233
|
+
}
|
|
192
234
|
break;
|
|
193
235
|
}
|
|
194
236
|
case "position_triggers_cancelled":
|
|
237
|
+
break;
|
|
195
238
|
case "position_triggers_invalidated":
|
|
239
|
+
// Additive since schema 39: the engine's u8 invalidation attribute,
|
|
240
|
+
// "0" = unspecified; absent on pre-upgrade rows.
|
|
241
|
+
if (payload.invalidation_reason !== undefined) {
|
|
242
|
+
unsigned(payload.invalidation_reason, "payload.invalidation_reason", 255n);
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
case "pending_triggers_attached": {
|
|
246
|
+
requireLimbRender(payload.stop_loss, "payload.stop_loss");
|
|
247
|
+
requireLimbRender(payload.take_profit, "payload.take_profit");
|
|
248
|
+
if (payload.stop_loss === "" && payload.take_profit === "") {
|
|
249
|
+
throw new Error("trigger history decode: pending attach carries no trigger limbs");
|
|
250
|
+
}
|
|
251
|
+
unsigned(payload.order_id, "payload.order_id", U64_MAX, true);
|
|
252
|
+
// "0" = the order carried no client order id.
|
|
253
|
+
unsigned(payload.client_order_id, "payload.client_order_id");
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
case "pending_triggers_discarded":
|
|
257
|
+
unsigned(payload.order_id, "payload.order_id", U64_MAX, true);
|
|
258
|
+
enumString(payload.reason, PENDING_DISCARD_REASONS, "payload.reason");
|
|
196
259
|
break;
|
|
197
260
|
case "position_trigger_activated":
|
|
198
261
|
requireUnsignedPayload(payload, [
|