@paradex/sdk 0.11.0 → 0.12.1
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 +132 -2
- package/dist/api-errors.d.ts +76 -0
- package/dist/api-errors.js +249 -0
- package/dist/builder-app.d.ts +329 -0
- package/dist/builder-app.js +527 -0
- package/dist/builder-codes.d.ts +4 -1
- package/dist/builder-codes.js +4 -2
- package/dist/evm-owner-client.d.ts +101 -0
- package/dist/evm-owner-client.js +191 -0
- package/dist/evm-owner-signer.d.ts +81 -0
- package/dist/evm-owner-signer.js +165 -0
- package/dist/index.d.ts +48 -1
- package/dist/index.js +40 -1
- package/dist/owner-auth.d.ts +68 -0
- package/dist/owner-auth.js +184 -0
- package/dist/paraclear.d.ts +6 -1
- package/dist/paraclear.js +15 -8
- package/dist/rfq.d.ts +54 -0
- package/dist/rfq.js +64 -0
- package/dist/sbe.d.ts +47 -0
- package/dist/sbe.js +744 -0
- package/dist/session-accounts.d.ts +33 -1
- package/dist/session-accounts.js +148 -40
- package/dist/session-auth.d.ts +3 -0
- package/dist/session-auth.js +12 -0
- package/dist/session-transport.d.ts +8 -1
- package/dist/session-transport.js +4 -0
- package/dist/siwe.d.ts +35 -0
- package/dist/siwe.js +94 -0
- package/dist/trading.d.ts +98 -0
- package/dist/trading.js +39 -0
- package/dist/wallet.d.ts +78 -0
- package/dist/wallet.js +157 -0
- package/package.json +4 -2
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type * as Starknet from 'starknet';
|
|
2
|
+
import { type BuilderApprovalRecord, type BuilderLeaderboardRow, type BuilderStats, type BuilderStatsWindow } from './builder-codes.js';
|
|
3
|
+
import type { WithdrawResult } from './client.js';
|
|
4
|
+
import { type ParadexConfig } from './config.js';
|
|
5
|
+
import { type OnboardOptions } from './owner-auth.js';
|
|
6
|
+
import { type RfqEnableResult } from './rfq.js';
|
|
7
|
+
import { SessionAccounts, type GrantStatus } from './session-accounts.js';
|
|
8
|
+
import { type SessionOrder } from './session-auth.js';
|
|
9
|
+
import { type Session } from './session-connector.js';
|
|
10
|
+
import { type SessionStorage } from './session-key.js';
|
|
11
|
+
import { type HttpTransport, type WebSocketFactory } from './session-transport.js';
|
|
12
|
+
import { SessionGrantError, type SessionScope } from './session-typed-data.js';
|
|
13
|
+
import { type AccountInfo, type Fill, type FillsQuery, type Order, type OrdersHistoryQuery, type Page } from './trading.js';
|
|
14
|
+
import { type ParadexWallet } from './wallet.js';
|
|
15
|
+
export type BuilderAppEnvironment = 'prod' | 'testnet' | 'nightly';
|
|
16
|
+
/** The app's builder: its Paradex account and the fee it charges. */
|
|
17
|
+
export interface BuilderAppBuilder {
|
|
18
|
+
/** The builder's Paradex account address. */
|
|
19
|
+
readonly account: string;
|
|
20
|
+
/**
|
|
21
|
+
* Fee charged on each order, a decimal fraction of the fill's notional
|
|
22
|
+
* (`"0.0005"` = 5 bps), at most 8 decimal places.
|
|
23
|
+
*/
|
|
24
|
+
readonly feeRate: string;
|
|
25
|
+
/**
|
|
26
|
+
* The highest rate the user approves; defaults to `feeRate`. Approving
|
|
27
|
+
* more lets the app raise its fee later without a new approval.
|
|
28
|
+
*/
|
|
29
|
+
readonly maxFeeRate?: string;
|
|
30
|
+
}
|
|
31
|
+
/** The Paradex app host each environment's SIWE messages must name. */
|
|
32
|
+
export declare const SIWE_DOMAINS: Readonly<Record<BuilderAppEnvironment, string>>;
|
|
33
|
+
export interface BuilderAppParams {
|
|
34
|
+
readonly environment: BuilderAppEnvironment;
|
|
35
|
+
readonly wallet: ParadexWallet;
|
|
36
|
+
readonly builder: BuilderAppBuilder;
|
|
37
|
+
/**
|
|
38
|
+
* Where session keys live. Defaults to IndexedDB in a browser (the key
|
|
39
|
+
* survives reloads, encrypted and not extractable) and memory elsewhere.
|
|
40
|
+
*/
|
|
41
|
+
readonly storage?: SessionStorage;
|
|
42
|
+
/** Defaults to `Config.fetch(environment)`. */
|
|
43
|
+
readonly config?: ParadexConfig;
|
|
44
|
+
/** API host root, e.g. `https://api.testnet.paradex.trade`. */
|
|
45
|
+
readonly apiUrl?: string;
|
|
46
|
+
readonly wsUrl?: string;
|
|
47
|
+
readonly transport?: HttpTransport;
|
|
48
|
+
readonly webSocketFactory?: WebSocketFactory;
|
|
49
|
+
/** See {@link SessionAccountsParams.onMessageError}. */
|
|
50
|
+
readonly onMessageError?: (error: Error) => void;
|
|
51
|
+
/** Defaults to {@link SIWE_DOMAINS}. */
|
|
52
|
+
readonly siweDomain?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Lets {@link BuilderApp.listApprovals}, {@link BuilderApp.revokeApproval}
|
|
55
|
+
* and {@link BuilderApp.enableRfq} run with an injected wallet. Off by
|
|
56
|
+
* default: they need a Sign-In with Ethereum message naming the Paradex
|
|
57
|
+
* app, which MetaMask and other injected wallets flag as another site.
|
|
58
|
+
* Teaching users to click through that warning helps phishing pages, so
|
|
59
|
+
* link them to Paradex settings instead. Privy and local wallets are not
|
|
60
|
+
* affected.
|
|
61
|
+
*/
|
|
62
|
+
readonly allowCrossSiteOwnerLogin?: boolean;
|
|
63
|
+
/** Seconds since the epoch. */
|
|
64
|
+
readonly now?: () => number;
|
|
65
|
+
}
|
|
66
|
+
/** The wallet's Paradex account. */
|
|
67
|
+
export interface BuilderAppAccount {
|
|
68
|
+
/** Its address; for a wallet with no account yet, the one it will get. */
|
|
69
|
+
readonly address: string;
|
|
70
|
+
readonly exists: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** The scopes a builder session may carry. */
|
|
73
|
+
export type BuilderSessionScope = Extract<SessionScope, 'trade' | 'trade:rfq'>;
|
|
74
|
+
export interface OpenBuilderSessionOptions {
|
|
75
|
+
/**
|
|
76
|
+
* What the session may do. Defaults to `["trade"]`; pass
|
|
77
|
+
* `["trade", "trade:rfq"]` for a session that also trades RFQs. The list
|
|
78
|
+
* must include `trade`: a session without it could not place the app's
|
|
79
|
+
* orders.
|
|
80
|
+
*/
|
|
81
|
+
readonly scopes?: readonly BuilderSessionScope[];
|
|
82
|
+
/** Defaults to 7 days, the browser session default. */
|
|
83
|
+
readonly ttlSeconds?: number;
|
|
84
|
+
/** EVM sub-accounts the session also trades. */
|
|
85
|
+
readonly subaccounts?: readonly string[];
|
|
86
|
+
/** Shown to the user on their Paradex sessions page. */
|
|
87
|
+
readonly label?: string;
|
|
88
|
+
/** Called once if the session is revoked or expires. */
|
|
89
|
+
readonly onDropped?: (reason: SessionGrantError) => void;
|
|
90
|
+
}
|
|
91
|
+
export interface EnableRfqOptions {
|
|
92
|
+
/**
|
|
93
|
+
* The account to enable: the user's main account by default, or one of
|
|
94
|
+
* their EVM sub-accounts.
|
|
95
|
+
*/
|
|
96
|
+
readonly account?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface ApproveBuilderOptions {
|
|
99
|
+
/** Defaults to the app's `maxFeeRate`. */
|
|
100
|
+
readonly maxFeeRate?: string;
|
|
101
|
+
/** Defaults to and at most 180 days. */
|
|
102
|
+
readonly ttlSeconds?: number;
|
|
103
|
+
readonly subaccounts?: readonly string[];
|
|
104
|
+
}
|
|
105
|
+
export interface BuilderWithdrawParams {
|
|
106
|
+
/** Defaults to `USDC`. */
|
|
107
|
+
readonly token?: string;
|
|
108
|
+
/** Decimal amount in token units, e.g. `"25"`. */
|
|
109
|
+
readonly amount: string;
|
|
110
|
+
/**
|
|
111
|
+
* Defaults to StarkGate to the owner wallet's own Ethereum address. Pass a
|
|
112
|
+
* call (or calls) to bridge another way.
|
|
113
|
+
*/
|
|
114
|
+
readonly bridgeCall?: Starknet.Call | readonly Starknet.Call[];
|
|
115
|
+
}
|
|
116
|
+
/** An order as the app places it: the builder fields come from the app. */
|
|
117
|
+
export type BuilderOrder = Omit<SessionOrder, 'builder' | 'builderFeeRate'> & {
|
|
118
|
+
/** Overrides the app's `feeRate` for this order. */
|
|
119
|
+
readonly builderFeeRate?: string;
|
|
120
|
+
};
|
|
121
|
+
export interface EstimateBuilderFeeParams {
|
|
122
|
+
/** Order size in base units, a decimal string. */
|
|
123
|
+
readonly size: string;
|
|
124
|
+
/** Price per unit in USD, a decimal string. */
|
|
125
|
+
readonly price: string;
|
|
126
|
+
/** Fee as a decimal fraction (`"0.0005"` = 5 bps). */
|
|
127
|
+
readonly feeRate: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The builder fee a fill of `size` at `price` pays, in USDC, as a decimal
|
|
131
|
+
* string: `size × price × feeRate`. It is what the fill's `builder_fee` will
|
|
132
|
+
* read for a perpetual filled at that price. For display before an order is
|
|
133
|
+
* placed; the fill itself is the record.
|
|
134
|
+
*/
|
|
135
|
+
export declare function estimateBuilderFee({ size, price, feeRate, }: EstimateBuilderFeeParams): string;
|
|
136
|
+
/**
|
|
137
|
+
* Everything a builder's web app does with Paradex, behind one object:
|
|
138
|
+
* open the user's account and a trading session that approves the builder,
|
|
139
|
+
* trade with the builder fee, read fills, manage approvals, withdraw, and
|
|
140
|
+
* read builder stats. Builders never use subkeys.
|
|
141
|
+
*
|
|
142
|
+
* @experimental
|
|
143
|
+
*/
|
|
144
|
+
export declare class BuilderApp {
|
|
145
|
+
readonly environment: BuilderAppEnvironment;
|
|
146
|
+
readonly wallet: ParadexWallet;
|
|
147
|
+
readonly builder: Required<BuilderAppBuilder>;
|
|
148
|
+
readonly config: ParadexConfig;
|
|
149
|
+
/** The wallet's EVM address. */
|
|
150
|
+
readonly ownerAddress: string;
|
|
151
|
+
private accountState;
|
|
152
|
+
private readonly params;
|
|
153
|
+
private readonly apiUrl;
|
|
154
|
+
private readonly transport;
|
|
155
|
+
private readonly connector;
|
|
156
|
+
private readonly ownerAuth;
|
|
157
|
+
private readonly codes;
|
|
158
|
+
private readonly rfq;
|
|
159
|
+
private withdrawClient;
|
|
160
|
+
private constructor();
|
|
161
|
+
/**
|
|
162
|
+
* Reads the config and the wallet's account. Prompts the wallet only to
|
|
163
|
+
* connect (`eth_requestAccounts`) when it has no address yet.
|
|
164
|
+
*/
|
|
165
|
+
static connect(params: BuilderAppParams): Promise<BuilderApp>;
|
|
166
|
+
/** The wallet's account as last read. */
|
|
167
|
+
get account(): BuilderAppAccount;
|
|
168
|
+
/** Re-reads whether the wallet's account exists. */
|
|
169
|
+
refreshAccount(): Promise<BuilderAppAccount>;
|
|
170
|
+
/**
|
|
171
|
+
* Opens the account without a session (one `personal_sign` prompt). Only
|
|
172
|
+
* for an app that needs the account, or a referral code, before trading:
|
|
173
|
+
* {@link openSession} opens a new account itself, and a grant naming a
|
|
174
|
+
* builder carries no referral.
|
|
175
|
+
*/
|
|
176
|
+
onboard(options?: OnboardOptions): Promise<BuilderAppAccount>;
|
|
177
|
+
/**
|
|
178
|
+
* Opens a trading session that approves the app's builder (one EIP-712
|
|
179
|
+
* prompt). For a wallet with no account, the same grant opens it: the
|
|
180
|
+
* account exists at once and deploys shortly after, and a Privy wallet's
|
|
181
|
+
* access token lets a verified user skip the minimum-balance check.
|
|
182
|
+
*/
|
|
183
|
+
openSession(options?: OpenBuilderSessionOptions): Promise<BuilderSession>;
|
|
184
|
+
/**
|
|
185
|
+
* The newest stored session of this wallet's account that can still place
|
|
186
|
+
* the app's orders, or `undefined`: its grant approves the app's builder
|
|
187
|
+
* at a ceiling of at least `feeRate`, and the server reports it active.
|
|
188
|
+
* Its grant lists `trade` and, with `scopes`, every one of those too.
|
|
189
|
+
* Sessions the server reports revoked or expired are deleted from
|
|
190
|
+
* storage. When the status cannot be read (offline), the session is kept
|
|
191
|
+
* and returned; its first call re-checks it.
|
|
192
|
+
*/
|
|
193
|
+
restoreSession(options?: Pick<OpenBuilderSessionOptions, 'onDropped' | 'scopes'>): Promise<BuilderSession | undefined>;
|
|
194
|
+
private now;
|
|
195
|
+
/** Deletes a session's key from storage (after it ends). */
|
|
196
|
+
forgetSession(session: BuilderSession): Promise<void>;
|
|
197
|
+
private sessionFor;
|
|
198
|
+
/**
|
|
199
|
+
* Approves the app's builder without a session (one EIP-712 prompt), for
|
|
200
|
+
* orders the user signs with their own key. A session already approves
|
|
201
|
+
* the builder through its grant.
|
|
202
|
+
*/
|
|
203
|
+
approveBuilder(options?: ApproveBuilderOptions): Promise<BuilderApprovalRecord>;
|
|
204
|
+
/**
|
|
205
|
+
* The account's builder approvals, standalone and in-grant. Needs the
|
|
206
|
+
* owner's login: one `personal_sign` of a Sign-In with Ethereum message
|
|
207
|
+
* naming the Paradex app, reused for 5 minutes.
|
|
208
|
+
*/
|
|
209
|
+
listApprovals(options?: {
|
|
210
|
+
readonly includeInactive?: boolean;
|
|
211
|
+
}): Promise<BuilderApprovalRecord[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Revokes the account's approval of a builder (the app's by default).
|
|
214
|
+
* New orders naming it are refused at once and resting ones are
|
|
215
|
+
* cancelled. It also revokes every session of the account that names the
|
|
216
|
+
* builder, on every device, including this page's own: its
|
|
217
|
+
* {@link BuilderSession} keeps its key until its next request is refused,
|
|
218
|
+
* then the SDK drops it and calls `onDropped`. Needs the owner's
|
|
219
|
+
* login, as {@link listApprovals}.
|
|
220
|
+
*/
|
|
221
|
+
revokeApproval(builderAccount?: string): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* The Paradex app's Builder approvals settings page for this
|
|
224
|
+
* environment, where the user lists and revokes approvals with no
|
|
225
|
+
* cross-site warning.
|
|
226
|
+
*/
|
|
227
|
+
get approvalsSettingsUrl(): string;
|
|
228
|
+
/**
|
|
229
|
+
* Turns on RFQ trading for the user's account: until then its RFQ calls
|
|
230
|
+
* are refused with `RFQ_NOT_ENABLED`. A session's RFQ calls also need
|
|
231
|
+
* `trade:rfq` in its grant and Paradex allowing RFQ for the builder's
|
|
232
|
+
* sessions; this call does neither. It
|
|
233
|
+
* provisions the account on Paradigm, the RFQ venue, and registers a
|
|
234
|
+
* Paradigm delegation subkey on the account, which counts against its
|
|
235
|
+
* subkey limit. Needs the owner's login, as {@link listApprovals}; a
|
|
236
|
+
* session cannot enable RFQ. RFQ is enabled per account: pass
|
|
237
|
+
* `account` to enable one of the user's EVM sub-accounts, which takes
|
|
238
|
+
* its own owner login. Safe to call again: an enabled account gets the
|
|
239
|
+
* same state back. It can take up to 30 s; a slow call ends as a
|
|
240
|
+
* retryable 503 `SERVICE_UNAVAILABLE`, and calling again resumes it.
|
|
241
|
+
*/
|
|
242
|
+
enableRfq(options?: EnableRfqOptions): Promise<RfqEnableResult>;
|
|
243
|
+
/**
|
|
244
|
+
* Whether {@link listApprovals}, {@link revokeApproval} and
|
|
245
|
+
* {@link enableRfq} work here without sending the user to the Paradex
|
|
246
|
+
* app: false for an injected wallet unless `allowCrossSiteOwnerLogin` is
|
|
247
|
+
* set.
|
|
248
|
+
*/
|
|
249
|
+
get canManageApprovals(): boolean;
|
|
250
|
+
private ownerLogin;
|
|
251
|
+
/**
|
|
252
|
+
* Withdraws to Ethereum, signed by the owner wallet with EIP-191 (one
|
|
253
|
+
* `personal_sign` prompt). By default the funds go through StarkGate to
|
|
254
|
+
* the owner's own address and are claimable on L1 once the block is
|
|
255
|
+
* proven there.
|
|
256
|
+
*/
|
|
257
|
+
withdraw(params: BuilderWithdrawParams): Promise<WithdrawResult>;
|
|
258
|
+
waitForTransaction(hash: string, options?: Starknet.waitForTransactionOptions): Promise<Starknet.GetTransactionReceiptResponse>;
|
|
259
|
+
private evmOwnerClient;
|
|
260
|
+
/** The app's builder fee for an order of `size` at `price`, in USDC. */
|
|
261
|
+
estimateFee(size: string, price: string, feeRate?: string): string;
|
|
262
|
+
/** A builder's stats, one row per window (the app's builder by default). */
|
|
263
|
+
builderStats(builderAccount?: string): Promise<BuilderStats[]>;
|
|
264
|
+
leaderboard(window?: BuilderStatsWindow): Promise<BuilderLeaderboardRow[]>;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A trading session that approves the app's builder. Calls act on the
|
|
268
|
+
* grant's main account unless `account` names one of its sub-accounts.
|
|
269
|
+
*
|
|
270
|
+
* @experimental
|
|
271
|
+
*/
|
|
272
|
+
export declare class BuilderSession {
|
|
273
|
+
readonly session: Session;
|
|
274
|
+
readonly accounts: SessionAccounts;
|
|
275
|
+
private readonly builder;
|
|
276
|
+
/** @internal */
|
|
277
|
+
constructor(session: Session, accounts: SessionAccounts, builder: Required<BuilderAppBuilder>);
|
|
278
|
+
/** The main account the session trades. */
|
|
279
|
+
get account(): string;
|
|
280
|
+
get expiresAt(): number;
|
|
281
|
+
/** Signs and places an order carrying the app's builder fee. */
|
|
282
|
+
placeOrder(order: BuilderOrder, account?: string): Promise<Order>;
|
|
283
|
+
cancelOrder(orderId: string, account?: string): Promise<void>;
|
|
284
|
+
cancelOrderByClientId(clientId: string, account?: string): Promise<void>;
|
|
285
|
+
/** Cancels every open order, or those in one market. */
|
|
286
|
+
cancelAllOrders(options?: {
|
|
287
|
+
readonly market?: string;
|
|
288
|
+
}, account?: string): Promise<void>;
|
|
289
|
+
listOpenOrders(options?: {
|
|
290
|
+
readonly market?: string;
|
|
291
|
+
}, account?: string): Promise<readonly Order[]>;
|
|
292
|
+
listOrdersHistory(query?: OrdersHistoryQuery, account?: string): Promise<Page<Order>>;
|
|
293
|
+
/** Fills, newest first, with the builder fee each paid. */
|
|
294
|
+
listFills(query?: FillsQuery, account?: string): Promise<Page<Fill>>;
|
|
295
|
+
/**
|
|
296
|
+
* The account's onboarding state. A new account reads `ONBOARDING` and
|
|
297
|
+
* `is_deployed: false` until it deploys.
|
|
298
|
+
*/
|
|
299
|
+
accountInfo(account?: string): Promise<AccountInfo>;
|
|
300
|
+
status(): Promise<GrantStatus>;
|
|
301
|
+
/**
|
|
302
|
+
* Subscribes to a websocket channel, such as `orders.ALL`, `fills.ALL`,
|
|
303
|
+
* `positions`, `account` or `bbo.BTC-USD-PERP`; returns the unsubscribe
|
|
304
|
+
* function. Fills come without the builder fee: read it with
|
|
305
|
+
* {@link listFills}. See {@link SessionAccounts.subscribe}.
|
|
306
|
+
*/
|
|
307
|
+
subscribe(channel: string, handler: (data: unknown) => void, account?: string): Promise<() => void>;
|
|
308
|
+
/**
|
|
309
|
+
* Ends the session on the server and deletes its key from storage. Its
|
|
310
|
+
* resting orders, TWAPs and untriggered stops are cancelled. With
|
|
311
|
+
* `cancelOrders: false` only resting orders are kept: a grant that names
|
|
312
|
+
* a builder still has its TWAPs and untriggered stops cancelled, and its
|
|
313
|
+
* kept orders last until the approval ends, by revoke or expiry.
|
|
314
|
+
*
|
|
315
|
+
* The builder approval the grant carried stays active until it expires
|
|
316
|
+
* (by default, when the last of the sessions that carried it would have
|
|
317
|
+
* expired, unless {@link BuilderApp.approveBuilder} gave it its own
|
|
318
|
+
* expiry). To end it too, call
|
|
319
|
+
* {@link BuilderApp.revokeApproval}, which also revokes the account's
|
|
320
|
+
* sessions naming the builder and cancels resting orders naming it. With
|
|
321
|
+
* an injected wallet, link to {@link BuilderApp.approvalsSettingsUrl}
|
|
322
|
+
* instead.
|
|
323
|
+
*/
|
|
324
|
+
revoke(options?: {
|
|
325
|
+
readonly cancelOrders?: boolean;
|
|
326
|
+
}): Promise<void>;
|
|
327
|
+
/** Closes sockets and timers; the session stays valid. */
|
|
328
|
+
close(): void;
|
|
329
|
+
}
|