@vordium/sdk 0.1.2 → 0.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 +55 -3
- package/dist/cjs/builder.js +256 -0
- package/dist/cjs/client.js +452 -62
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/network.js +53 -1
- package/dist/cjs/nonce.js +419 -1
- package/dist/cjs/orders.js +3 -0
- package/dist/cjs/pins.js +60 -0
- package/dist/cjs/resend.js +188 -0
- package/dist/cjs/types.js +4 -0
- package/dist/esm/builder.d.ts +158 -0
- package/dist/esm/builder.js +235 -0
- package/dist/esm/client.d.ts +119 -9
- package/dist/esm/client.js +453 -66
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/network.d.ts +23 -4
- package/dist/esm/network.js +51 -1
- package/dist/esm/nonce.d.ts +109 -0
- package/dist/esm/nonce.js +410 -0
- package/dist/esm/orders.js +3 -0
- package/dist/esm/pins.d.ts +29 -0
- package/dist/esm/pins.js +51 -0
- package/dist/esm/resend.d.ts +74 -0
- package/dist/esm/resend.js +180 -0
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/types.js +4 -0
- package/package.json +1 -1
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import { type MarginMode, type TwapRules } from './account.js';
|
|
1
|
+
import { type MarginMode, type TwapRules, type TwapValue } from './account.js';
|
|
2
2
|
import { type PolicyV1 } from './agents.js';
|
|
3
3
|
import { type DomainClass, type TypedDomain } from './domains.js';
|
|
4
4
|
import { type Transport } from './http.js';
|
|
5
5
|
import { type Network, type NetworkPreset } from './network.js';
|
|
6
|
-
import { type
|
|
6
|
+
import { type NonceSource } from './nonce.js';
|
|
7
|
+
import { ChainClock } from './resend.js';
|
|
7
8
|
import { type BatchAction, type OrderInput, type Submitted } from './orders.js';
|
|
8
9
|
import { type AgentRefusal, type Equity, type OpenOrder, type Position } from './reads.js';
|
|
9
10
|
import { type TypedSigner } from './sign.js';
|
|
10
11
|
import { type MarketRules, type PairSpec } from './rounding.js';
|
|
12
|
+
import { type BuilderApprovals, type BuilderStats, type OrderBuilder, type ReferralLevel } from './builder.js';
|
|
11
13
|
/**
|
|
12
14
|
* The result of a write. `applied` is true only once the chain's own read shows the change. A submission (HTTP 202) is
|
|
13
15
|
* not an application: `applied: false` with the chain's answer means the chain has not shown it (yet, or at all).
|
|
14
16
|
*/
|
|
15
17
|
export interface Result {
|
|
16
|
-
|
|
18
|
+
/** true once the chain's read shows it; false only when the network refused it (it certainly did not apply); null
|
|
19
|
+
* when it may have been received and the chain's read has not shown it within the wait (`unknown: true`). */
|
|
20
|
+
applied: boolean | null;
|
|
17
21
|
status: number;
|
|
18
22
|
answer: unknown;
|
|
19
23
|
detail: string;
|
|
24
|
+
/** It may have been received, and the chain's read did not show it yet: read the account before sending it anew. */
|
|
25
|
+
unknown?: boolean;
|
|
20
26
|
}
|
|
21
27
|
export interface ConnectOptions {
|
|
22
28
|
network?: 'mainnet' | 'testnet' | NetworkPreset;
|
|
@@ -24,6 +30,13 @@ export interface ConnectOptions {
|
|
|
24
30
|
timeoutMs?: number;
|
|
25
31
|
/** How long a checked node identity is trusted before it is read again (ms). */
|
|
26
32
|
identityTtlMs?: number;
|
|
33
|
+
/** Called when the network's reports differ from its pin, or it has none (reads go on; nothing is signed). */
|
|
34
|
+
onPinProblem?: (message: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Check each new nonce against the network's block time (its latest block, read at most every 5 minutes). On by
|
|
37
|
+
* default with the built-in transport; with a transport of your own, off unless set. Off: against this computer's clock.
|
|
38
|
+
*/
|
|
39
|
+
chainClock?: boolean;
|
|
27
40
|
}
|
|
28
41
|
/** A connection to one Vordium network: reads, and the signing domains of its node. */
|
|
29
42
|
export declare class Vordium {
|
|
@@ -32,12 +45,17 @@ export declare class Vordium {
|
|
|
32
45
|
private readonly timeoutMs;
|
|
33
46
|
private readonly ttlMs;
|
|
34
47
|
private checkedAt;
|
|
48
|
+
/** The network's block time for the nonce window check; null checks against this computer's clock. */
|
|
49
|
+
readonly chainClock: ChainClock | null;
|
|
35
50
|
private constructor();
|
|
51
|
+
/** The network's block time now (ms), estimated from its latest block; null when it cannot be read. */
|
|
52
|
+
chainTimeMs(): Promise<number | null>;
|
|
36
53
|
/** Read and check the network (spec, node and JSON-RPC must agree) and return a client for it. Testnet by default. */
|
|
37
54
|
static connect(opts?: ConnectOptions): Promise<Vordium>;
|
|
38
55
|
/**
|
|
39
|
-
* The signing domain of the node this client posts to
|
|
40
|
-
*
|
|
56
|
+
* The signing domain of the node this client posts to, built from the network's pin (`PINS`) after the network's
|
|
57
|
+
* reports were checked against it. The node's identity is read again after the TTL; a node that now serves another
|
|
58
|
+
* chain is refused, never followed.
|
|
41
59
|
*/
|
|
42
60
|
domain(cls: DomainClass): Promise<TypedDomain>;
|
|
43
61
|
/** GET a path of the REST API; null on 404, raises on another failure. */
|
|
@@ -86,12 +104,24 @@ export declare class Vordium {
|
|
|
86
104
|
crossMargin(owner: string): Promise<unknown>;
|
|
87
105
|
/** The dead-man switch's committed state and limits. */
|
|
88
106
|
scheduleCancelState(owner: string): Promise<unknown>;
|
|
107
|
+
/** `GET /builder/approvals/<user>`: the builders `user` approved, the count, the most allowed, its nonce, `active`. */
|
|
108
|
+
builderApprovals(user: string): Promise<BuilderApprovals>;
|
|
109
|
+
/** `GET /builder/stats/<builder>`: volume, fees (= unclaimed + claimed), users in 30 days, caps, claim nonce, `active`. */
|
|
110
|
+
builderStats(builder: string): Promise<BuilderStats>;
|
|
111
|
+
/** `GET /referral/stats/<address>` as the network answers it. */
|
|
112
|
+
referralStats(address: string): Promise<unknown>;
|
|
113
|
+
/** The account's referral level (`L1`, `L2`, `PARTNER`) and its period progress; null where levels are not shown. */
|
|
114
|
+
referralLevel(address: string): Promise<ReferralLevel | null>;
|
|
115
|
+
/** `GET /referral/tiers`: the levels table, the L2 rule, the partner bounds and the referee caps. */
|
|
116
|
+
referralTiers(): Promise<unknown>;
|
|
117
|
+
/** The network's block time in whole seconds, else this computer's clock. */
|
|
118
|
+
nowS(): Promise<number>;
|
|
89
119
|
/** The TWAP route and limits from the network spec (refused when not published). */
|
|
90
120
|
twapRules(): TwapRules;
|
|
91
121
|
/** A trading account: `owner` signs account operations; `sessionSigner` (a session or agent key) signs orders. */
|
|
92
122
|
account(owner: TypedSigner, opts?: {
|
|
93
123
|
sessionSigner?: TypedSigner;
|
|
94
|
-
nonce?:
|
|
124
|
+
nonce?: NonceSource;
|
|
95
125
|
specs?: unknown;
|
|
96
126
|
}): Promise<Account>;
|
|
97
127
|
/** An agent's own handle: places orders with the agent key for its owner, and may tighten its own policy. */
|
|
@@ -105,10 +135,13 @@ export declare class Account {
|
|
|
105
135
|
readonly owner: string;
|
|
106
136
|
private readonly ownerSigner;
|
|
107
137
|
private readonly sessionSigner;
|
|
108
|
-
|
|
138
|
+
/** The account's client-nonce source: its persisted allocator in the `orders` space by default. */
|
|
139
|
+
readonly nonce: NonceSource;
|
|
109
140
|
/** Market rules this handle holds; null = read them from the node for each order. */
|
|
110
141
|
readonly specs: MarketRules | null;
|
|
111
|
-
constructor(client: Vordium, owner: string, ownerSigner: TypedSigner | null, sessionSigner: TypedSigner | null,
|
|
142
|
+
constructor(client: Vordium, owner: string, ownerSigner: TypedSigner | null, sessionSigner: TypedSigner | null,
|
|
143
|
+
/** The account's client-nonce source: its persisted allocator in the `orders` space by default. */
|
|
144
|
+
nonce: NonceSource,
|
|
112
145
|
/** Market rules this handle holds; null = read them from the node for each order. */
|
|
113
146
|
specs?: MarketRules | null);
|
|
114
147
|
/** The rules an order uses: the ones this handle holds, else read from the node now. */
|
|
@@ -119,6 +152,27 @@ export declare class Account {
|
|
|
119
152
|
/** Orders are signed by the session (or agent) key, else by the owner key. */
|
|
120
153
|
private orderSigner;
|
|
121
154
|
private sign;
|
|
155
|
+
/**
|
|
156
|
+
* A fresh nonce, checked against the network's window before anything is signed ({@link ClockOutOfWindow} otherwise):
|
|
157
|
+
* the account's client nonce (`orders`), or the `account` nonce of `signer` (session, margin mode, agent operations).
|
|
158
|
+
*/
|
|
159
|
+
private fresh;
|
|
160
|
+
/**
|
|
161
|
+
* POST one signed body, the same bytes on every try. With `dedup` (a write the network applies once per nonce) a lost
|
|
162
|
+
* connection, a timeout or a busy gateway sends it again (never a new nonce); without it only a copy that never left
|
|
163
|
+
* this machine is sent again, and a lost answer throws {@link DeliveryUnknown}.
|
|
164
|
+
*/
|
|
165
|
+
private postSame;
|
|
166
|
+
/**
|
|
167
|
+
* An account operation, for a result the chain's own read decides: `proceed` is true when the network took it (2xx),
|
|
168
|
+
* or when it is not known whether it arrived (then the read-back alone says whether it applied).
|
|
169
|
+
*/
|
|
170
|
+
private postForResult;
|
|
171
|
+
/**
|
|
172
|
+
* A write the network does not apply once per nonce (batch, cancel-all, modify, take-profit / stop-loss): never sent
|
|
173
|
+
* again after a lost answer. Unknown is `submitted: false, unknown: true` with the refusal `delivery_unknown`: read the
|
|
174
|
+
* account before sending a new one.
|
|
175
|
+
*/
|
|
122
176
|
private send;
|
|
123
177
|
/**
|
|
124
178
|
* Sign and submit one order (Market or Limit). The answer is a submission; the order is on the book when
|
|
@@ -127,9 +181,22 @@ export declare class Account {
|
|
|
127
181
|
*/
|
|
128
182
|
placeOrder(o: Omit<OrderInput, 'owner' | 'clientNonce'> & {
|
|
129
183
|
clientNonce?: number;
|
|
184
|
+
builder?: OrderBuilder | null;
|
|
185
|
+
worstPrice?: string | number | null;
|
|
130
186
|
}): Promise<Submitted & {
|
|
131
187
|
clientNonce: number;
|
|
188
|
+
attempts: number;
|
|
189
|
+
alreadyReceived: boolean;
|
|
190
|
+
unknown: boolean;
|
|
191
|
+
found?: Record<string, unknown> | null;
|
|
192
|
+
builder?: OrderBuilder;
|
|
132
193
|
}>;
|
|
194
|
+
/**
|
|
195
|
+
* The account's order with `clientNonce` as the network lists it: resting (open orders), else its record; null when
|
|
196
|
+
* it lists neither (or cannot be read). With `signed`, only an order that carries the signed market, side and size or
|
|
197
|
+
* price counts: another signer of the account may use the same millisecond nonce.
|
|
198
|
+
*/
|
|
199
|
+
orderByClientNonce(clientNonce: number, signed?: SignedOrder): Promise<Record<string, unknown> | null>;
|
|
133
200
|
/**
|
|
134
201
|
* Where the order with `clientNonce` stands, from the chain: `resting` while the book holds it, else what the account's
|
|
135
202
|
* order records say (`filled`, `cancelled`, `expired`), or null when the chain has no record of it (a refused order
|
|
@@ -139,7 +206,12 @@ export declare class Account {
|
|
|
139
206
|
waitForOrder(clientNonce: number, ms?: number, opts?: {
|
|
140
207
|
final?: boolean;
|
|
141
208
|
}): Promise<'resting' | 'filled' | 'cancelled' | 'expired' | null>;
|
|
142
|
-
cancelOrder(orderId: bigint | number): Promise<Submitted
|
|
209
|
+
cancelOrder(orderId: bigint | number): Promise<Submitted & {
|
|
210
|
+
done?: boolean;
|
|
211
|
+
filled?: boolean;
|
|
212
|
+
unknown?: boolean;
|
|
213
|
+
attempts?: number;
|
|
214
|
+
}>;
|
|
143
215
|
/** Take-profit / stop-loss on an open position (8-decimal prices; 0 leaves a leg unset). */
|
|
144
216
|
setTpSl(pairId: number, positionId: bigint | number, takeProfit8: bigint, stopLoss8: bigint): Promise<Submitted>;
|
|
145
217
|
/** Up to the published maximum of place / cancel actions in one signed batch. Cancels apply first. */
|
|
@@ -173,6 +245,9 @@ export declare class Account {
|
|
|
173
245
|
*/
|
|
174
246
|
scheduleCancel(cancelAtMs: number): Promise<Submitted & {
|
|
175
247
|
nonce: number;
|
|
248
|
+
attempts: number;
|
|
249
|
+
unknown: boolean;
|
|
250
|
+
alreadyReceived: boolean;
|
|
176
251
|
}>;
|
|
177
252
|
revokeSession(waitMs?: number): Promise<Result>;
|
|
178
253
|
/**
|
|
@@ -197,6 +272,24 @@ export declare class Account {
|
|
|
197
272
|
cancelTwap(twapId: bigint | number, waitMs?: number): Promise<Result>;
|
|
198
273
|
/** The market's margin mode as the chain reads it ("cross" | "isolated"), or null. */
|
|
199
274
|
marginMode(pairId: number): Promise<MarginMode | null>;
|
|
275
|
+
/** An order's builder after the network's reads allow it (rule active, fee within the perps cap, approved, funded). */
|
|
276
|
+
private checkedBuilder;
|
|
277
|
+
/** The builders this account approved (`approvals`, `count`, `max`, `nonce`, `active`). */
|
|
278
|
+
builderApprovals(): Promise<BuilderApprovals>;
|
|
279
|
+
/** This account's stats as a builder. */
|
|
280
|
+
builderStats(): Promise<BuilderStats>;
|
|
281
|
+
/**
|
|
282
|
+
* Let `builder` charge this account up to `maxFeeCbps` per order (500 cbps = 5 bps = 0.05 %); approving a builder
|
|
283
|
+
* again replaces its fee. Signed with the account's own key. Refused before signing when builder fees are not active,
|
|
284
|
+
* the fee is 0 or above the highest cap (`caps_cbps`), the builder is this account, or the account already approved
|
|
285
|
+
* the most builders it may (`max`).
|
|
286
|
+
*/
|
|
287
|
+
approveBuilderFee(builder: string, maxFeeCbps: number, waitMs?: number): Promise<Result>;
|
|
288
|
+
/** Withdraw the approval of `builder` (an approval of 0). Orders that name it are refused from then on. */
|
|
289
|
+
revokeBuilderFee(builder: string, waitMs?: number): Promise<Result>;
|
|
290
|
+
private approve;
|
|
291
|
+
/** As a builder: move the unclaimed fees to this account's balance. Refused before signing when there is nothing. */
|
|
292
|
+
claimBuilderFees(waitMs?: number): Promise<Result>;
|
|
200
293
|
/** Cross or isolated for one market — only while it holds no open position and no resting order of the account. */
|
|
201
294
|
setMarginMode(pairId: number, mode: MarginMode, waitMs?: number): Promise<Result>;
|
|
202
295
|
private submitAgentOp;
|
|
@@ -237,3 +330,20 @@ export declare class Account {
|
|
|
237
330
|
* (every slice on the lot, never more than asked), the lowest price UP and the highest DOWN (the band never widens).
|
|
238
331
|
*/
|
|
239
332
|
export declare function twapOnSteps(spec: PairSpec, total18: bigint, numSlices: number, minPrice8: bigint, maxPrice8: bigint): [bigint, bigint, bigint];
|
|
333
|
+
/** The signed fields of an order, for a read-back. */
|
|
334
|
+
export interface SignedOrder {
|
|
335
|
+
pairId: number;
|
|
336
|
+
side: number;
|
|
337
|
+
size: bigint;
|
|
338
|
+
price: bigint | null;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Whether an order record carries what was signed: its market and side, and its size or limit price. A field the
|
|
342
|
+
* record does not show is not counted; one it shows with another value is a mismatch; a record that shows neither size
|
|
343
|
+
* nor price is not enough.
|
|
344
|
+
*/
|
|
345
|
+
export declare function matchesSigned(rec: Record<string, unknown>, signed: SignedOrder): boolean;
|
|
346
|
+
/** Whether a TWAP the chain lists is the one signed: its client nonce, market, side and total size. */
|
|
347
|
+
export declare function twapMatches(row: Record<string, unknown>, v: TwapValue): boolean;
|
|
348
|
+
/** How an order that is not resting was closed, from the account's records: `cancelled`, `filled`, or null. */
|
|
349
|
+
export declare function cancelOutcome(records: Array<Record<string, unknown>>, orderId: bigint): 'cancelled' | 'filled' | null;
|