@proof-labs/trading-sdk 7.3.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +70 -24
  2. package/dist/account-recovery.d.ts +117 -0
  3. package/dist/account-recovery.d.ts.map +1 -0
  4. package/dist/account-recovery.js +330 -0
  5. package/dist/account-recovery.js.map +1 -0
  6. package/dist/client.d.ts +42 -54
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +138 -160
  9. package/dist/client.js.map +1 -1
  10. package/dist/codec-adapter.d.ts.map +1 -1
  11. package/dist/codec-adapter.js +13 -0
  12. package/dist/codec-adapter.js.map +1 -1
  13. package/dist/errors.d.ts +23 -1
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/errors.js +73 -2
  16. package/dist/errors.js.map +1 -1
  17. package/dist/feed-types.d.ts +22 -0
  18. package/dist/feed-types.d.ts.map +1 -1
  19. package/dist/feed.d.ts +52 -0
  20. package/dist/feed.d.ts.map +1 -1
  21. package/dist/feed.js +342 -24
  22. package/dist/feed.js.map +1 -1
  23. package/dist/financial-state.d.ts.map +1 -1
  24. package/dist/financial-state.js +16 -4
  25. package/dist/financial-state.js.map +1 -1
  26. package/dist/governance-query.d.ts.map +1 -1
  27. package/dist/governance-query.js +69 -0
  28. package/dist/governance-query.js.map +1 -1
  29. package/dist/index.d.ts +6 -3
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +4 -2
  32. package/dist/index.js.map +1 -1
  33. package/dist/insurance-funding.d.ts +6 -0
  34. package/dist/insurance-funding.d.ts.map +1 -0
  35. package/dist/insurance-funding.js +54 -0
  36. package/dist/insurance-funding.js.map +1 -0
  37. package/dist/liquidation-config.d.ts +11 -0
  38. package/dist/liquidation-config.d.ts.map +1 -0
  39. package/dist/liquidation-config.js +54 -0
  40. package/dist/liquidation-config.js.map +1 -0
  41. package/dist/liquidation-events.d.ts +135 -0
  42. package/dist/liquidation-events.d.ts.map +1 -0
  43. package/dist/liquidation-events.js +273 -0
  44. package/dist/liquidation-events.js.map +1 -0
  45. package/dist/types.d.ts +88 -13
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/wasm/proof_trading_sdk_wasm_bg.wasm +0 -0
  48. package/package.json +1 -1
@@ -0,0 +1,54 @@
1
+ const U64_MAX = (1n << 64n) - 1n;
2
+ const I64_MAX = (1n << 63n) - 1n;
3
+ /** Allocation bound enforced by the engine's insurance `validate_transfer`. */
4
+ const MAX_ALLOCATIONS = 8;
5
+ function validateAccount(value, field) {
6
+ if (!(value instanceof Uint8Array) ||
7
+ value.length !== 20 ||
8
+ !value.some(Boolean)) {
9
+ throw new Error(`${field} must be a 20-byte non-zero account address`);
10
+ }
11
+ }
12
+ function validateId(value, field) {
13
+ if (typeof value !== "bigint" || value < 0n || value > U64_MAX) {
14
+ throw new Error(`${field} must be an unsigned 64-bit bigint`);
15
+ }
16
+ }
17
+ function validateAllocations(allocations, label) {
18
+ if (!Array.isArray(allocations) ||
19
+ allocations.length < 1 ||
20
+ allocations.length > MAX_ALLOCATIONS) {
21
+ throw new Error(`${label} requires 1..${MAX_ALLOCATIONS} allocations`);
22
+ }
23
+ let previous = -1;
24
+ let total = 0n;
25
+ for (const [i, allocation] of allocations.entries()) {
26
+ if (!Number.isInteger(allocation.poolId) ||
27
+ allocation.poolId <= previous ||
28
+ allocation.poolId > 255) {
29
+ throw new Error(`${label} allocations[${i}].poolId must be an unsigned byte in strictly ascending order`);
30
+ }
31
+ previous = allocation.poolId;
32
+ if (typeof allocation.amount !== "bigint" ||
33
+ allocation.amount <= 0n ||
34
+ allocation.amount > I64_MAX) {
35
+ throw new Error(`${label} allocations[${i}].amount must be a positive bigint within i64::MAX`);
36
+ }
37
+ total += allocation.amount;
38
+ if (total > I64_MAX)
39
+ throw new Error(`${label} total exceeds i64::MAX`);
40
+ }
41
+ }
42
+ /** Mirrors proposal shape checks, not authority, balance or live-state checks. */
43
+ export function validateFundInsuranceFund(value) {
44
+ validateAccount(value.source, "insurance funding source");
45
+ validateId(value.fundingId, "fundingId");
46
+ validateAllocations(value.allocations, "insurance funding");
47
+ }
48
+ /** Shape checks only: quorum and pool balances remain engine checks. */
49
+ export function validateWithdrawInsuranceFund(value) {
50
+ validateId(value.withdrawalId, "withdrawalId");
51
+ validateAccount(value.recipient, "insurance withdrawal recipient");
52
+ validateAllocations(value.allocations, "insurance withdrawal");
53
+ }
54
+ //# sourceMappingURL=insurance-funding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insurance-funding.js","sourceRoot":"","sources":["../src/insurance-funding.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AACjC,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AACjC,+EAA+E;AAC/E,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,SAAS,eAAe,CAAC,KAAiB,EAAE,KAAa;IACvD,IACE,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;QAC9B,KAAK,CAAC,MAAM,KAAK,EAAE;QACnB,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EACpB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6CAA6C,CAAC,CAAC;IACzE,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,KAAa;IAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,oCAAoC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAC1B,WAAsC,EACtC,KAAa;IAEb,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;QAC3B,WAAW,CAAC,MAAM,GAAG,CAAC;QACt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,MAAM,UAAU,6BAA6B,CAC3C,KAA4B;IAE5B,UAAU,CAAC,KAAK,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAC/C,eAAe,CAAC,KAAK,CAAC,SAAS,EAAE,gCAAgC,CAAC,CAAC;IACnE,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { LiquidationConfig, SetLiquidationConfig } from "./types.js";
2
+ /** Basis points that equal a ratio of one. */
3
+ export declare const RATIO_ONE_BPS = 10000;
4
+ /** Largest partial-liquidation penalty a configuration may carry. */
5
+ export declare const MAX_PARTIAL_PENALTY_BPS = 100;
6
+ /** Mirror proof-wire's `LiquidationConfig::validate`. */
7
+ export declare function validateLiquidationConfig(config: LiquidationConfig): void;
8
+ /** Mirror proof-wire's `SetLiquidationConfig::validate`. Whether
9
+ * `predecessor` names the stored configuration stays an engine check. */
10
+ export declare function validateSetLiquidationConfig(action: SetLiquidationConfig): void;
11
+ //# sourceMappingURL=liquidation-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquidation-config.d.ts","sourceRoot":"","sources":["../src/liquidation-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAK1E,8CAA8C;AAC9C,eAAO,MAAM,aAAa,QAAS,CAAC;AAEpC,qEAAqE;AACrE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAc3C,yDAAyD;AACzD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CA4BzE;AAED;0EAC0E;AAC1E,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,oBAAoB,GAC3B,IAAI,CAON"}
@@ -0,0 +1,54 @@
1
+ const U32_MAX = 0xffff_ffff;
2
+ const U64_MAX = (1n << 64n) - 1n;
3
+ /** Basis points that equal a ratio of one. */
4
+ export const RATIO_ONE_BPS = 10_000;
5
+ /** Largest partial-liquidation penalty a configuration may carry. */
6
+ export const MAX_PARTIAL_PENALTY_BPS = 100;
7
+ function u32(value, field) {
8
+ if (!Number.isInteger(value) || value < 0 || value > U32_MAX) {
9
+ throw new Error(`${field} must be an integer in 0..=${U32_MAX}`);
10
+ }
11
+ }
12
+ function u64(value, field) {
13
+ if (typeof value !== "bigint" || value < 0n || value > U64_MAX) {
14
+ throw new Error(`${field} must be an unsigned 64-bit bigint`);
15
+ }
16
+ }
17
+ /** Mirror proof-wire's `LiquidationConfig::validate`. */
18
+ export function validateLiquidationConfig(config) {
19
+ const fields = [
20
+ "targetRatioBps",
21
+ "partialPenaltyBps",
22
+ "maxBookOrders",
23
+ "maxCommittedFills",
24
+ ];
25
+ for (const field of fields)
26
+ u32(config[field], field);
27
+ const { numerator, denominator } = config.fullCloseThreshold;
28
+ u32(numerator, "fullCloseThreshold.numerator");
29
+ u32(denominator, "fullCloseThreshold.denominator");
30
+ if (config.targetRatioBps <= RATIO_ONE_BPS) {
31
+ throw new Error(`targetRatioBps must exceed ${RATIO_ONE_BPS}`);
32
+ }
33
+ if (numerator === 0 || numerator >= denominator) {
34
+ throw new Error("fullCloseThreshold must be strictly between 0 and 1 (0 < numerator < denominator)");
35
+ }
36
+ if (config.partialPenaltyBps > MAX_PARTIAL_PENALTY_BPS) {
37
+ throw new Error(`partialPenaltyBps must be at most ${MAX_PARTIAL_PENALTY_BPS}`);
38
+ }
39
+ for (const field of fields.slice(2)) {
40
+ if (config[field] === 0)
41
+ throw new Error(`${field} must be non-zero`);
42
+ }
43
+ }
44
+ /** Mirror proof-wire's `SetLiquidationConfig::validate`. Whether
45
+ * `predecessor` names the stored configuration stays an engine check. */
46
+ export function validateSetLiquidationConfig(action) {
47
+ u64(action.predecessor, "predecessor");
48
+ u64(action.sequence, "sequence");
49
+ if (action.sequence <= action.predecessor) {
50
+ throw new Error("sequence must exceed predecessor");
51
+ }
52
+ validateLiquidationConfig(action.config);
53
+ }
54
+ //# sourceMappingURL=liquidation-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquidation-config.js","sourceRoot":"","sources":["../src/liquidation-config.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,WAAW,CAAC;AAC5B,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEjC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAEpC,qEAAqE;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,SAAS,GAAG,CAAC,KAAa,EAAE,KAAa;IACvC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,8BAA8B,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,SAAS,GAAG,CAAC,KAAa,EAAE,KAAa;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,oCAAoC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,yBAAyB,CAAC,MAAyB;IACjE,MAAM,MAAM,GAAG;QACb,gBAAgB;QAChB,mBAAmB;QACnB,eAAe;QACf,mBAAmB;KACX,CAAC;IACX,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IACtD,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC;IAC7D,GAAG,CAAC,SAAS,EAAE,8BAA8B,CAAC,CAAC;IAC/C,GAAG,CAAC,WAAW,EAAE,gCAAgC,CAAC,CAAC;IAEnD,IAAI,MAAM,CAAC,cAAc,IAAI,aAAa,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,8BAA8B,aAAa,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,IAAI,WAAW,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,iBAAiB,GAAG,uBAAuB,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,qCAAqC,uBAAuB,EAAE,CAC/D,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,mBAAmB,CAAC,CAAC;IACxE,CAAC;AACH,CAAC;AAED;0EAC0E;AAC1E,MAAM,UAAU,4BAA4B,CAC1C,MAA4B;IAE5B,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACvC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,yBAAyB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Typed decoders for the engine's liquidation events, from the string
3
+ * attributes of one ABCI event: a transaction's `TxEvent`, or a payload the
4
+ * indexer or the account feed carries verbatim.
5
+ *
6
+ * Every integer attribute is a decimal string; a u64 or i64 decodes to
7
+ * `bigint`, since identifiers and amounts can exceed 2^53. An address is 40
8
+ * lowercase hex characters. Attributes these decoders do not name, such as the chain
9
+ * coordinates (`block_height`, `event_key`, …), are ignored. A malformed
10
+ * event throws; an event of another type decodes to `null`.
11
+ */
12
+ import type { BindingScenarioEntry, LiquidationConfig, TxEvent } from "./types.js";
13
+ /** How one liquidation attempt on an owner ended in a block, as the
14
+ * engine writes it into the `outcome` attribute today. A later engine may
15
+ * add a value; the decoder passes it through. */
16
+ export declare const LIQUIDATION_PROGRESS_OUTCOMES: readonly ["not_eligible", "indeterminate", "restored_by_cancellation", "no_fill", "safe_progress", "maintenance_restored_below_target", "target_reached", "full_close_restored_by_cancellation", "full_close_no_fill", "full_close_partly_closed", "full_close_closed", "insolvent", "deferred", "failed"];
17
+ export type LiquidationProgress = (typeof LIQUIDATION_PROGRESS_OUTCOMES)[number] | (string & {});
18
+ /** Which path liquidated a position, as the `mode` attribute names it:
19
+ * `partial` is a step through the book toward the target ratio, `full` a
20
+ * close through the book below the full-close threshold, and `insolvent` a
21
+ * close at mark because equity is negative in some outcome. A later engine
22
+ * may add a mode; the decoder passes it through. */
23
+ export declare const LIQUIDATION_MODES: readonly ["partial", "full", "insolvent"];
24
+ export type LiquidationMode = (typeof LIQUIDATION_MODES)[number] | (string & {});
25
+ /** Why a liquidation attempt was refused rather than failing on an engine
26
+ * error: a position changed under the step reducing it, a resting order
27
+ * did not match its book, or a reference price was unavailable. A later
28
+ * engine may add a reason; the decoder passes it through. */
29
+ export declare const LIQUIDATION_REFUSALS: readonly ["position_mismatch", "invalid_maker", "reference_unavailable"];
30
+ export type LiquidationRefusal = (typeof LIQUIDATION_REFUSALS)[number] | (string & {});
31
+ /** The engine error code of a refused liquidation attempt
32
+ * (`ExecErrorCode.LiquidationRefused`). */
33
+ export declare const LIQUIDATION_REFUSED_CODE = 111;
34
+ /** Why auto-deleveraging left a profitable position out of a deficit's
35
+ * candidate set: `stale_oracle_dependency` means a market the
36
+ * counterparty's portfolio depends on (a position or a resting order) had
37
+ * no fresh oracle verdict, so its solvency was indeterminate. A later engine
38
+ * may add a reason; the decoder passes it through. */
39
+ export declare const ADL_SKIP_REASONS: readonly ["stale_oracle_dependency"];
40
+ export type AdlSkipReason = (typeof ADL_SKIP_REASONS)[number] | (string & {});
41
+ /** The admin quorum replaced the global liquidation configuration. */
42
+ export interface LiquidationConfigSetEvent {
43
+ type: "LiquidationConfigSet";
44
+ sequence: bigint;
45
+ config: LiquidationConfig;
46
+ proposalId: bigint;
47
+ }
48
+ /**
49
+ * The partial-liquidation penalty on one book fill that reduced `owner`'s
50
+ * position. `collected` was paid to `poolId`'s insurance fund; `waived` is
51
+ * never owed later; `assessed = collected + waived`.
52
+ */
53
+ export interface PartialLiquidationFeeEvent {
54
+ type: "PartialLiquidationFee";
55
+ owner: string;
56
+ market: number;
57
+ poolId: number;
58
+ fillId: bigint;
59
+ configSequence: bigint;
60
+ assessed: bigint;
61
+ collected: bigint;
62
+ waived: bigint;
63
+ }
64
+ /** How one owner named in a liquidation batch ended this block. */
65
+ export interface LiquidationProgressReportedEvent {
66
+ type: "LiquidationProgressReported";
67
+ owner: string;
68
+ outcome: LiquidationProgress;
69
+ configSequence: bigint;
70
+ }
71
+ /**
72
+ * One position an owner's liquidation attempt reduced, once per position
73
+ * per attempt. `sizeBefore` is the position's size before the attempt's
74
+ * first step, `sizeClosed` the total its steps closed, and `sizeAfter` what
75
+ * is left. The penalty is the sum of the per-fill penalties charged on this
76
+ * position: `penaltyCollected` went to the insurance fund and
77
+ * `penaltyWaived` is never owed later; a close at mark charges none.
78
+ * `equity` (signed), `maintenance` and `bindingOutcome` are the owner's
79
+ * binding outcome, with pending funding, when the attempt was decided.
80
+ * `bindingOutcome` has one entry per event of the account's domain, and is
81
+ * empty when the account holds no event exposure.
82
+ */
83
+ export interface PositionLiquidatedEvent {
84
+ type: "PositionLiquidated";
85
+ owner: string;
86
+ market: number;
87
+ side: "buy" | "sell";
88
+ mode: LiquidationMode;
89
+ sizeBefore: bigint;
90
+ sizeClosed: bigint;
91
+ sizeAfter: bigint;
92
+ penaltyCollected: bigint;
93
+ penaltyWaived: bigint;
94
+ equity: bigint;
95
+ maintenance: bigint;
96
+ bindingOutcome: BindingScenarioEntry[];
97
+ configSequence: bigint;
98
+ }
99
+ /**
100
+ * An owner's liquidation attempt failed and kept none of its writes.
101
+ * `code` is the engine error code. `refusal` names why when the attempt was
102
+ * refused (the engine writes `LIQUIDATION_REFUSED_CODE` then), and is
103
+ * `null` when it failed on another engine error.
104
+ */
105
+ export interface LiquidationFailedEvent {
106
+ type: "LiquidationFailed";
107
+ owner: string;
108
+ code: number;
109
+ refusal: LiquidationRefusal | null;
110
+ }
111
+ /** Auto-deleveraging left `owner`'s profitable position of `size` on
112
+ * `market` out of the candidate set for `poolId`'s deficit. */
113
+ export interface AdlCounterpartySkippedEvent {
114
+ type: "AdlCounterpartySkipped";
115
+ owner: string;
116
+ market: number;
117
+ poolId: number;
118
+ size: bigint;
119
+ reason: AdlSkipReason;
120
+ }
121
+ export type LiquidationEvent = LiquidationConfigSetEvent | PartialLiquidationFeeEvent | LiquidationProgressReportedEvent | PositionLiquidatedEvent | LiquidationFailedEvent | AdlCounterpartySkippedEvent;
122
+ /** One ABCI event: a `TxEvent`'s attribute list, or the same attributes as
123
+ * a plain object. */
124
+ export interface LiquidationEventInput {
125
+ type: string;
126
+ attributes: TxEvent["attributes"] | Readonly<Record<string, unknown>>;
127
+ }
128
+ /**
129
+ * Decode one of the six liquidation events from its ABCI type (the
130
+ * engine's snake_case name, e.g. `"partial_liquidation_fee"`) and string
131
+ * attributes. Returns `null` for any other event type, so a caller can run
132
+ * it over every event of a transaction or block.
133
+ */
134
+ export declare function decodeLiquidationEvent(event: LiquidationEventInput): LiquidationEvent | null;
135
+ //# sourceMappingURL=liquidation-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquidation-events.d.ts","sourceRoot":"","sources":["../src/liquidation-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB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,GACvB,sBAAsB,GACtB,2BAA2B,CAAC;AAEhC;sBACsB;AACtB,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACvE;AAgOD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,qBAAqB,GAC3B,gBAAgB,GAAG,IAAI,CAKzB"}
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Typed decoders for the engine's liquidation events, from the string
3
+ * attributes of one ABCI event: a transaction's `TxEvent`, or a payload the
4
+ * indexer or the account feed carries verbatim.
5
+ *
6
+ * Every integer attribute is a decimal string; a u64 or i64 decodes to
7
+ * `bigint`, since identifiers and amounts can exceed 2^53. An address is 40
8
+ * lowercase hex characters. Attributes these decoders do not name, such as the chain
9
+ * coordinates (`block_height`, `event_key`, …), are ignored. A malformed
10
+ * event throws; an event of another type decodes to `null`.
11
+ */
12
+ import { validateLiquidationConfig } from "./liquidation-config.js";
13
+ /** How one liquidation attempt on an owner ended in a block, as the
14
+ * engine writes it into the `outcome` attribute today. A later engine may
15
+ * add a value; the decoder passes it through. */
16
+ export const LIQUIDATION_PROGRESS_OUTCOMES = [
17
+ "not_eligible",
18
+ "indeterminate",
19
+ "restored_by_cancellation",
20
+ "no_fill",
21
+ "safe_progress",
22
+ "maintenance_restored_below_target",
23
+ "target_reached",
24
+ "full_close_restored_by_cancellation",
25
+ "full_close_no_fill",
26
+ "full_close_partly_closed",
27
+ "full_close_closed",
28
+ "insolvent",
29
+ "deferred",
30
+ "failed",
31
+ ];
32
+ /** Which path liquidated a position, as the `mode` attribute names it:
33
+ * `partial` is a step through the book toward the target ratio, `full` a
34
+ * close through the book below the full-close threshold, and `insolvent` a
35
+ * close at mark because equity is negative in some outcome. A later engine
36
+ * may add a mode; the decoder passes it through. */
37
+ export const LIQUIDATION_MODES = ["partial", "full", "insolvent"];
38
+ /** Why a liquidation attempt was refused rather than failing on an engine
39
+ * error: a position changed under the step reducing it, a resting order
40
+ * did not match its book, or a reference price was unavailable. A later
41
+ * engine may add a reason; the decoder passes it through. */
42
+ export const LIQUIDATION_REFUSALS = [
43
+ "position_mismatch",
44
+ "invalid_maker",
45
+ "reference_unavailable",
46
+ ];
47
+ /** The engine error code of a refused liquidation attempt
48
+ * (`ExecErrorCode.LiquidationRefused`). */
49
+ export const LIQUIDATION_REFUSED_CODE = 111;
50
+ /** Why auto-deleveraging left a profitable position out of a deficit's
51
+ * candidate set: `stale_oracle_dependency` means a market the
52
+ * counterparty's portfolio depends on (a position or a resting order) had
53
+ * no fresh oracle verdict, so its solvency was indeterminate. A later engine
54
+ * may add a reason; the decoder passes it through. */
55
+ export const ADL_SKIP_REASONS = ["stale_oracle_dependency"];
56
+ const U32_MAX = 0xffffffffn;
57
+ const U64_MAX = (1n << 64n) - 1n;
58
+ const I64_MIN = -(1n << 63n);
59
+ const I64_MAX = (1n << 63n) - 1n;
60
+ const UNSIGNED = /^(0|[1-9][0-9]*)$/;
61
+ class Attributes {
62
+ event;
63
+ values = new Map();
64
+ constructor(event, attributes) {
65
+ this.event = event;
66
+ const entries = Array.isArray(attributes)
67
+ ? attributes.map(({ key, value }) => [
68
+ key,
69
+ value,
70
+ ])
71
+ : Object.entries(attributes);
72
+ for (const [key, value] of entries) {
73
+ if (this.values.has(key))
74
+ this.fail(key, "is duplicated");
75
+ this.values.set(key, value);
76
+ }
77
+ }
78
+ fail(key, problem) {
79
+ throw new Error(`${this.event} decode: ${key} ${problem}`);
80
+ }
81
+ text(key) {
82
+ const value = this.values.get(key);
83
+ if (typeof value !== "string")
84
+ this.fail(key, "is missing");
85
+ return value;
86
+ }
87
+ unsigned(key, max) {
88
+ const text = this.text(key);
89
+ if (!UNSIGNED.test(text)) {
90
+ this.fail(key, "is not a decimal unsigned integer");
91
+ }
92
+ const value = BigInt(text);
93
+ if (value > max)
94
+ this.fail(key, `exceeds ${max}`);
95
+ return value;
96
+ }
97
+ u64(key) {
98
+ return this.unsigned(key, U64_MAX);
99
+ }
100
+ u32(key) {
101
+ return Number(this.unsigned(key, U32_MAX));
102
+ }
103
+ u8(key) {
104
+ return Number(this.unsigned(key, 0xffn));
105
+ }
106
+ i64(key) {
107
+ const text = this.text(key);
108
+ if (!/^(0|-?[1-9][0-9]*)$/.test(text)) {
109
+ this.fail(key, "is not a decimal signed integer");
110
+ }
111
+ const value = BigInt(text);
112
+ if (value < I64_MIN || value > I64_MAX) {
113
+ this.fail(key, "is outside the signed 64-bit range");
114
+ }
115
+ return value;
116
+ }
117
+ oneOf(key, values) {
118
+ const text = this.text(key);
119
+ if (!values.includes(text))
120
+ this.fail(key, `has unknown value "${text}"`);
121
+ return text;
122
+ }
123
+ /** A non-empty value passed through as written, so a value a later engine
124
+ * adds still decodes. */
125
+ label(key) {
126
+ const text = this.text(key);
127
+ if (text === "")
128
+ this.fail(key, "is empty");
129
+ return text;
130
+ }
131
+ owner(key) {
132
+ const text = this.text(key);
133
+ if (!/^[0-9a-f]{40}$/.test(text)) {
134
+ this.fail(key, "is not a 20-byte lowercase hex address");
135
+ }
136
+ return text;
137
+ }
138
+ /** `assessed`, `collected` and `waived`, checked to add up. */
139
+ penalty() {
140
+ const assessed = this.u64("assessed");
141
+ const collected = this.u64("collected");
142
+ const waived = this.u64("waived");
143
+ if (collected + waived !== assessed) {
144
+ this.fail("assessed", "is not collected + waived");
145
+ }
146
+ return { assessed, collected, waived };
147
+ }
148
+ }
149
+ function liquidationConfigSet(a) {
150
+ const config = {
151
+ targetRatioBps: a.u32("target_ratio_bps"),
152
+ fullCloseThreshold: {
153
+ numerator: a.u32("full_close_numerator"),
154
+ denominator: a.u32("full_close_denominator"),
155
+ },
156
+ partialPenaltyBps: a.u32("partial_penalty_bps"),
157
+ maxBookOrders: a.u32("max_book_orders"),
158
+ maxCommittedFills: a.u32("max_committed_fills"),
159
+ };
160
+ try {
161
+ validateLiquidationConfig(config);
162
+ }
163
+ catch (e) {
164
+ a.fail("config", `is invalid: ${e.message}`);
165
+ }
166
+ return {
167
+ type: "LiquidationConfigSet",
168
+ sequence: a.u64("sequence"),
169
+ config,
170
+ proposalId: a.u64("proposal_id"),
171
+ };
172
+ }
173
+ function partialLiquidationFee(a) {
174
+ return {
175
+ type: "PartialLiquidationFee",
176
+ owner: a.owner("owner"),
177
+ market: a.u32("market"),
178
+ poolId: a.u8("pool_id"),
179
+ fillId: a.u64("fill_id"),
180
+ configSequence: a.u64("config_sequence"),
181
+ ...a.penalty(),
182
+ };
183
+ }
184
+ function liquidationProgressReported(a) {
185
+ return {
186
+ type: "LiquidationProgressReported",
187
+ owner: a.owner("owner"),
188
+ outcome: a.label("outcome"),
189
+ configSequence: a.u64("config_sequence"),
190
+ };
191
+ }
192
+ /** `event_id:branch` pairs joined by commas, one per event, branch `yes` or
193
+ * `no`; the empty string for no event exposure. */
194
+ function bindingOutcome(a) {
195
+ const text = a.text("binding_outcome");
196
+ if (text === "")
197
+ return [];
198
+ const seen = new Set();
199
+ return text.split(",").map((pair) => {
200
+ const match = /^(0|[1-9][0-9]*):(yes|no)$/.exec(pair);
201
+ if (!match)
202
+ a.fail("binding_outcome", `has malformed entry "${pair}"`);
203
+ const eventId = BigInt(match[1]);
204
+ if (eventId > U32_MAX)
205
+ a.fail("binding_outcome", `event id exceeds ${U32_MAX}`);
206
+ if (seen.has(eventId)) {
207
+ a.fail("binding_outcome", `event id ${eventId} is repeated`);
208
+ }
209
+ seen.add(eventId);
210
+ return {
211
+ eventId: Number(eventId),
212
+ branch: match[2] === "yes" ? "Yes" : "No",
213
+ };
214
+ });
215
+ }
216
+ function positionLiquidated(a) {
217
+ return {
218
+ type: "PositionLiquidated",
219
+ owner: a.owner("owner"),
220
+ market: a.u32("market"),
221
+ side: a.oneOf("side", ["buy", "sell"]),
222
+ mode: a.label("mode"),
223
+ sizeBefore: a.u64("size_before"),
224
+ sizeClosed: a.u64("size_closed"),
225
+ sizeAfter: a.u64("size_after"),
226
+ penaltyCollected: a.u64("penalty_collected"),
227
+ penaltyWaived: a.u64("penalty_waived"),
228
+ equity: a.i64("equity"),
229
+ maintenance: a.u64("maintenance"),
230
+ bindingOutcome: bindingOutcome(a),
231
+ configSequence: a.u64("config_sequence"),
232
+ };
233
+ }
234
+ function liquidationFailed(a) {
235
+ const refusal = a.text("refusal");
236
+ return {
237
+ type: "LiquidationFailed",
238
+ owner: a.owner("owner"),
239
+ code: a.u32("code"),
240
+ refusal: refusal === "" ? null : refusal,
241
+ };
242
+ }
243
+ function adlCounterpartySkipped(a) {
244
+ return {
245
+ type: "AdlCounterpartySkipped",
246
+ owner: a.owner("owner"),
247
+ market: a.u32("market"),
248
+ poolId: a.u8("pool_id"),
249
+ size: a.u64("size"),
250
+ reason: a.label("reason"),
251
+ };
252
+ }
253
+ const DECODERS = {
254
+ liquidation_config_set: liquidationConfigSet,
255
+ partial_liquidation_fee: partialLiquidationFee,
256
+ liquidation_progress_reported: liquidationProgressReported,
257
+ position_liquidated: positionLiquidated,
258
+ liquidation_failed: liquidationFailed,
259
+ adl_counterparty_skipped: adlCounterpartySkipped,
260
+ };
261
+ /**
262
+ * Decode one of the six liquidation events from its ABCI type (the
263
+ * engine's snake_case name, e.g. `"partial_liquidation_fee"`) and string
264
+ * attributes. Returns `null` for any other event type, so a caller can run
265
+ * it over every event of a transaction or block.
266
+ */
267
+ export function decodeLiquidationEvent(event) {
268
+ const decode = Object.hasOwn(DECODERS, event.type)
269
+ ? DECODERS[event.type]
270
+ : undefined;
271
+ return decode ? decode(new Attributes(event.type, event.attributes)) : null;
272
+ }
273
+ //# sourceMappingURL=liquidation-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquidation-events.js","sourceRoot":"","sources":["../src/liquidation-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpE;;kDAEkD;AAClD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