@lifi/perps-sdk 0.0.0-preview-2475f77 → 0.0.0-preview-2ffedda
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 +26 -0
- package/dist/cjs/client/PerpsClient.d.ts +5 -1
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +50 -0
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/api.d.ts +14 -2
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +11 -1
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +13 -0
- package/dist/cjs/types/withdrawal.d.ts.map +1 -0
- package/dist/cjs/types/withdrawal.js +3 -0
- package/dist/cjs/types/withdrawal.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/PerpsClient.d.ts +29 -1
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +71 -0
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api.d.ts +29 -2
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +36 -1
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +37 -0
- package/dist/esm/types/withdrawal.d.ts.map +1 -0
- package/dist/esm/types/withdrawal.js +2 -0
- package/dist/esm/types/withdrawal.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/client/PerpsClient.d.ts +29 -1
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +29 -2
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +36 -1
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +37 -0
- package/dist/types/types/withdrawal.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -3
- package/src/client/PerpsClient.ts +87 -0
- package/src/index.ts +10 -0
- package/src/types/api.ts +33 -1
- package/src/types/provider.ts +46 -0
- package/src/types/withdrawal.ts +39 -0
- package/src/version.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountConfigSetting, AccountResponse, ActionStep, ExecuteActionResponse, MarginMode, MarketRef, ModifyOrderInput, OrderSide, OrderType, SignedActionStep, TimeInForce, TriggerOrderInput, WithdrawalParams } from '@lifi/perps-types';
|
|
1
|
+
import type { AccountConfigSetting, AccountResponse, CancelTwapOrderParams as ActionCancelTwapOrderParams, PlaceTwapOrderParams as ActionPlaceTwapOrderParams, ActionStep, ExecuteActionResponse, MarginMode, MarketRef, ModifyOrderInput, OrderSide, OrderType, SignedActionStep, TimeInForce, TriggerOrderInput, WithdrawalParams } from '@lifi/perps-types';
|
|
2
2
|
import type { Account, Address, WalletClient } from 'viem';
|
|
3
3
|
import type { RetryConfig } from '../transport/retryPolicy.js';
|
|
4
4
|
import type { ProviderConfigs, RequestInterceptor, SwitchChainHook } from './config.js';
|
|
@@ -104,7 +104,7 @@ export interface PlaceOrderParams {
|
|
|
104
104
|
/** Opaque provider market reference. */
|
|
105
105
|
market: MarketRef;
|
|
106
106
|
side: OrderSide;
|
|
107
|
-
type: OrderType
|
|
107
|
+
type: Exclude<OrderType, OrderType.TWAP>;
|
|
108
108
|
/** Base-asset size as a decimal wire string. */
|
|
109
109
|
size: string;
|
|
110
110
|
/** Limit price as a decimal wire string; required by limit-style orders. */
|
|
@@ -141,6 +141,24 @@ export interface PlaceTriggerOrderParams {
|
|
|
141
141
|
takeProfit?: TriggerOrderInput;
|
|
142
142
|
stopLoss?: TriggerOrderInput;
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Client parameters for placing a TWAP order.
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export interface PlaceTwapOrderParams extends ActionPlaceTwapOrderParams {
|
|
150
|
+
provider: string;
|
|
151
|
+
address: Address;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Client parameters for cancelling a running TWAP order.
|
|
155
|
+
*
|
|
156
|
+
* @public
|
|
157
|
+
*/
|
|
158
|
+
export interface CancelTwapOrderParams extends ActionCancelTwapOrderParams {
|
|
159
|
+
provider: string;
|
|
160
|
+
address: Address;
|
|
161
|
+
}
|
|
144
162
|
/**
|
|
145
163
|
* Parameters for withdrawing funds.
|
|
146
164
|
*
|
|
@@ -213,6 +231,15 @@ export interface GetDepositFlowParams {
|
|
|
213
231
|
provider: string;
|
|
214
232
|
address: Address;
|
|
215
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Parameters for {@link PerpsClient.getWithdrawableBalances}.
|
|
236
|
+
*
|
|
237
|
+
* @public
|
|
238
|
+
*/
|
|
239
|
+
export interface GetWithdrawableBalancesParams {
|
|
240
|
+
provider: string;
|
|
241
|
+
address: Address;
|
|
242
|
+
}
|
|
216
243
|
/**
|
|
217
244
|
* Result from {@link PerpsClient.checkSetup}.
|
|
218
245
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/types/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,m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E,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,6CAA6C;IAC7C,aAAa,EAAE,gBAAgB,EAAE,CAAA;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,aAAa,EAAE,OAAO,CAAA;IACtB,iEAAiE;IACjE,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,qEAAqE;IACrE,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,oDAAoD;IACpD,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,wDAAwD;IACxD,aAAa,EAAE,gBAAgB,EAAE,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,qBAAqB,CAAA;CAC/B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,uEAAuE;IACvE,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CACjC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { AccountConfig, AccountConfigSetting, AccountResponse, AccountSummary, ActionResult, ActionStep, ActionType, ActivitiesResponse, ActivityType, FillsResponse, Market, MarketRef, MarketSettings, Order, OrdersResponse, PerpsMarket, PerpsSigner, Position, PositionMarginConstraints, PositionsResponse, ProviderAction, Quote, QuoteSide, SignedActionStep, SigningMethod, TradeType } from '@lifi/perps-types';
|
|
1
|
+
import type { AccountConfig, AccountConfigSetting, AccountResponse, AccountSummary, ActionResult, ActionStep, ActionType, ActivitiesResponse, ActivityType, FillsResponse, Market, MarketRef, MarketSettings, Order, OrdersResponse, PerpsMarket, PerpsSigner, Position, PositionMarginConstraints, PositionsResponse, ProviderAction, Quote, QuoteSide, SignedActionStep, SigningMethod, TradeType, TwapOrder } from '@lifi/perps-types';
|
|
2
2
|
import type { Address } from 'viem';
|
|
3
3
|
import type { PerpsBaseConfig, PerpsClientSigner, SDKRequestOptions } from './config.js';
|
|
4
4
|
import type { DepositFlow } from './deposit.js';
|
|
5
|
+
import type { ProviderWithdrawableBalance } from './withdrawal.js';
|
|
5
6
|
/**
|
|
6
7
|
* Low-level SDK client: resolved config, the optional end-user wallet, and the
|
|
7
8
|
* registered provider plugins. Returned by {@link createPerpsClient} and
|
|
@@ -136,6 +137,14 @@ export interface ProviderAccountExistsParams {
|
|
|
136
137
|
export interface ProviderGetDepositFlowParams {
|
|
137
138
|
address: Address;
|
|
138
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Read params for {@link PerpsProviderPlugin.getWithdrawableBalances}.
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
*/
|
|
145
|
+
export interface ProviderGetWithdrawableBalancesParams {
|
|
146
|
+
address: Address;
|
|
147
|
+
}
|
|
139
148
|
/**
|
|
140
149
|
* Read params for {@link PerpsProvider.getPositions}.
|
|
141
150
|
*
|
|
@@ -175,6 +184,16 @@ export interface ProviderGetOrdersParams {
|
|
|
175
184
|
/** Opaque pagination cursor from the previous response. */
|
|
176
185
|
cursor?: string;
|
|
177
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Read params for {@link PerpsProvider.getRunningTwaps}.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
export interface ProviderGetRunningTwapsParams {
|
|
193
|
+
address: Address;
|
|
194
|
+
/** Optional opaque `Market.id` filter (not a display symbol). */
|
|
195
|
+
marketId?: string;
|
|
196
|
+
}
|
|
178
197
|
/**
|
|
179
198
|
* Read params for {@link PerpsProvider.getOrder}.
|
|
180
199
|
*
|
|
@@ -314,6 +333,17 @@ export interface PerpsProviderPlugin {
|
|
|
314
333
|
* `PerpsClient.getDepositFlow` then resolves `undefined`.
|
|
315
334
|
*/
|
|
316
335
|
getDepositFlow?(params: ProviderGetDepositFlowParams, options?: SDKRequestOptions): Promise<DepositFlow>;
|
|
336
|
+
/**
|
|
337
|
+
* The `(asset, route)` pairs `params.address` currently has something to
|
|
338
|
+
* withdraw from, keyed by provider-native asset id. Only the venue knows how
|
|
339
|
+
* its balance payload splits across routes, so the split is owned here; the
|
|
340
|
+
* per-asset venue minimum is applied by `PerpsClient.getWithdrawableBalances`,
|
|
341
|
+
* which holds the core asset registry.
|
|
342
|
+
*
|
|
343
|
+
* Optional: a provider whose withdrawals are not a per-route selection omits
|
|
344
|
+
* it, and `PerpsClient.getWithdrawableBalances` then resolves `undefined`.
|
|
345
|
+
*/
|
|
346
|
+
getWithdrawableBalances?(params: ProviderGetWithdrawableBalancesParams, options?: SDKRequestOptions): Promise<ProviderWithdrawableBalance[]>;
|
|
317
347
|
getPositions(params: ProviderGetPositionsParams, options?: SDKRequestOptions): Promise<PositionsResponse>;
|
|
318
348
|
/**
|
|
319
349
|
* The user's current venue-side settings for one market — the margin mode
|
|
@@ -324,6 +354,11 @@ export interface PerpsProviderPlugin {
|
|
|
324
354
|
*/
|
|
325
355
|
getMarketSettings?(params: ProviderGetMarketSettingsParams, options?: SDKRequestOptions): Promise<MarketSettings | undefined>;
|
|
326
356
|
getOrders(params: ProviderGetOrdersParams, options?: SDKRequestOptions): Promise<OrdersResponse>;
|
|
357
|
+
/**
|
|
358
|
+
* Fetch the account's currently running TWAP parent orders directly from the
|
|
359
|
+
* venue. Child slice orders are excluded.
|
|
360
|
+
*/
|
|
361
|
+
getRunningTwaps?(params: ProviderGetRunningTwapsParams, options?: SDKRequestOptions): Promise<TwapOrder[]>;
|
|
327
362
|
getOrder(params: ProviderGetOrderParams, options?: SDKRequestOptions): Promise<Order>;
|
|
328
363
|
getFills(params: ProviderGetFillsParams, options?: SDKRequestOptions): Promise<FillsResponse>;
|
|
329
364
|
getActivity(params: ProviderGetActivityParams, options?: SDKRequestOptions): Promise<ActivitiesResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,EACN,SAAS,EACT,cAAc,EACd,KAAK,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,QAAQ,EACR,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,SAAS,EACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,EACN,SAAS,EACT,cAAc,EACd,KA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E,GACxB,oBAAoB,EAAE,CAAA;IAEzB;;;;;;;OAOG;IACH,kBAAkB,CAAC,CACjB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAEnC;;;;;;;;;;;;;;;OAeG;IACH,oBAAoB,CAAC,CACnB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,WAAW,EAAE,GACrB,OAAO,CAAC,wBAAwB,CAAC,CAAA;IAEpC;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,CAAC,CACV,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;IAE9B;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3E;;;;;;;;OAQG;IACH,mBAAmB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACzD;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Asset } from '@lifi/perps-types';
|
|
2
|
+
/**
|
|
3
|
+
* Which of a venue's two balance routes a withdrawal is drawn from. Lighter's
|
|
4
|
+
* own vocabulary, carried in the signed tx as `AssetRouteType` (`perps` = 0,
|
|
5
|
+
* `spot` = 1); an account's mode changes what the two balances mean, never
|
|
6
|
+
* which route the tx names.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type WithdrawalRoute = 'perps' | 'spot';
|
|
11
|
+
/**
|
|
12
|
+
* One withdrawable `(asset, route)` selection as the provider reports it, keyed
|
|
13
|
+
* by provider-native asset id and awaiting the core asset-metadata join.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface ProviderWithdrawableBalance {
|
|
18
|
+
/** Provider-native `Asset.id`; never a display symbol. */
|
|
19
|
+
assetId: string;
|
|
20
|
+
route: WithdrawalRoute;
|
|
21
|
+
/** Withdrawable amount in the asset's own units. Always greater than zero. */
|
|
22
|
+
available: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One withdrawable `(asset, route)` selection a caller can act on: the amount
|
|
26
|
+
* clears the asset's venue minimum, and `asset` carries the precision and
|
|
27
|
+
* minimum needed to scale and validate the withdrawal.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface WithdrawableBalance {
|
|
32
|
+
asset: Asset;
|
|
33
|
+
route: WithdrawalRoute;
|
|
34
|
+
/** Withdrawable amount in the asset's own units. */
|
|
35
|
+
available: string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;CAClB"}
|
package/dist/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-2ffedda",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -38,14 +38,15 @@
|
|
|
38
38
|
"!**/__mocks__/**",
|
|
39
39
|
"!*.tmp",
|
|
40
40
|
"!*.env",
|
|
41
|
-
"!tsconfig.json"
|
|
41
|
+
"!tsconfig.json",
|
|
42
|
+
"!tsconfig.build.json"
|
|
42
43
|
],
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"@lifi/types": "17.86.0",
|
|
45
46
|
"big.js": "^7.0.1",
|
|
46
47
|
"partysocket": "^1.1.19",
|
|
47
48
|
"viem": "^2.48.8",
|
|
48
|
-
"@lifi/perps-types": "^
|
|
49
|
+
"@lifi/perps-types": "^0.0.0-preview-2ffedda"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"access": "public"
|
|
@@ -20,8 +20,10 @@ import {
|
|
|
20
20
|
PerpsSigner,
|
|
21
21
|
SigningMethod,
|
|
22
22
|
} from '@lifi/perps-types'
|
|
23
|
+
import Big from 'big.js'
|
|
23
24
|
import type { Address } from 'viem'
|
|
24
25
|
import { PerpsError } from '../errors/PerpsError.js'
|
|
26
|
+
import { getAssetRegistry } from '../registry/assetRegistry.js'
|
|
25
27
|
import { createAction } from '../services/createAction.js'
|
|
26
28
|
import { executeAction } from '../services/executeAction.js'
|
|
27
29
|
import { getAccount as fetchAccount } from '../services/getAccount.js'
|
|
@@ -29,15 +31,18 @@ import { getProviders } from '../services/getProviders.js'
|
|
|
29
31
|
import type {
|
|
30
32
|
BuildProviderSetupParams,
|
|
31
33
|
CancelOrdersParams,
|
|
34
|
+
CancelTwapOrderParams,
|
|
32
35
|
ExecuteProviderSetupParams,
|
|
33
36
|
ExecuteProviderSetupResult,
|
|
34
37
|
GetAccountResult,
|
|
35
38
|
GetDepositFlowParams,
|
|
36
39
|
GetSetupParams,
|
|
40
|
+
GetWithdrawableBalancesParams,
|
|
37
41
|
ModifyOrdersParams,
|
|
38
42
|
PerpsClientOptions,
|
|
39
43
|
PlaceOrderParams,
|
|
40
44
|
PlaceTriggerOrderParams,
|
|
45
|
+
PlaceTwapOrderParams,
|
|
41
46
|
ProviderSetup,
|
|
42
47
|
SendAssetActionParams,
|
|
43
48
|
WithdrawParams,
|
|
@@ -51,6 +56,7 @@ import type {
|
|
|
51
56
|
SignActionProgress,
|
|
52
57
|
SignActionsContext,
|
|
53
58
|
} from '../types/provider.js'
|
|
59
|
+
import type { WithdrawableBalance } from '../types/withdrawal.js'
|
|
54
60
|
import {
|
|
55
61
|
switchSigningChain,
|
|
56
62
|
userEip712TargetChainId,
|
|
@@ -493,6 +499,57 @@ export class PerpsClient {
|
|
|
493
499
|
return plugin.getDepositFlow?.({ address: params.address })
|
|
494
500
|
}
|
|
495
501
|
|
|
502
|
+
/**
|
|
503
|
+
* The `(asset, route)` selections `params.address` can actually withdraw at
|
|
504
|
+
* `params.provider`. The venue owns how its balances split across routes;
|
|
505
|
+
* this join adds the core `/assets` metadata — precision, L1 identity and
|
|
506
|
+
* the per-asset minimum — and drops every row the minimum rules out, plus
|
|
507
|
+
* any row whose asset the provider's registry does not carry, since without
|
|
508
|
+
* that metadata the amount can be neither scaled nor validated.
|
|
509
|
+
*
|
|
510
|
+
* @returns `undefined` when the registered plugin declares no withdrawable
|
|
511
|
+
* read.
|
|
512
|
+
* @throws {PerpsError} When the provider plugin is not registered, or either
|
|
513
|
+
* the plugin read or the asset sync fails.
|
|
514
|
+
* @public
|
|
515
|
+
*/
|
|
516
|
+
async getWithdrawableBalances(
|
|
517
|
+
params: GetWithdrawableBalancesParams
|
|
518
|
+
): Promise<WithdrawableBalance[] | undefined> {
|
|
519
|
+
const plugin = this.requireProvider(params.provider)
|
|
520
|
+
const rows = await plugin.getWithdrawableBalances?.({
|
|
521
|
+
address: params.address,
|
|
522
|
+
})
|
|
523
|
+
if (rows === undefined) {
|
|
524
|
+
return undefined
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const registry = getAssetRegistry(this.sdkClient, params.provider)
|
|
528
|
+
await registry.sync()
|
|
529
|
+
return rows.flatMap((row) => {
|
|
530
|
+
const asset = registry.get(row.assetId)
|
|
531
|
+
if (asset === undefined) {
|
|
532
|
+
return []
|
|
533
|
+
}
|
|
534
|
+
const minimum = asset.minWithdrawalAmount
|
|
535
|
+
if (minimum !== undefined) {
|
|
536
|
+
let floor: Big
|
|
537
|
+
try {
|
|
538
|
+
floor = new Big(minimum)
|
|
539
|
+
} catch {
|
|
540
|
+
throw new PerpsError(
|
|
541
|
+
PerpsErrorCode.SDKError,
|
|
542
|
+
`Asset '${asset.id}' field \`minWithdrawalAmount\` is not a valid decimal.`
|
|
543
|
+
)
|
|
544
|
+
}
|
|
545
|
+
if (new Big(row.available).lt(floor)) {
|
|
546
|
+
return []
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return [{ asset, route: row.route, available: row.available }]
|
|
550
|
+
})
|
|
551
|
+
}
|
|
552
|
+
|
|
496
553
|
/**
|
|
497
554
|
* Return the unsatisfied entries on `Provider.setup` for this account as a
|
|
498
555
|
* flat, self-describing list. Trading is gated on `isReady === true`.
|
|
@@ -875,6 +932,36 @@ export class PerpsClient {
|
|
|
875
932
|
})
|
|
876
933
|
}
|
|
877
934
|
|
|
935
|
+
/**
|
|
936
|
+
* Place a time-weighted average price order through {@link execute}.
|
|
937
|
+
*
|
|
938
|
+
* @public
|
|
939
|
+
*/
|
|
940
|
+
async placeTwapOrder(
|
|
941
|
+
params: PlaceTwapOrderParams
|
|
942
|
+
): Promise<ExecuteActionResponse> {
|
|
943
|
+
return this.execute({
|
|
944
|
+
...params,
|
|
945
|
+
action: ActionType.PLACE_TWAP_ORDER,
|
|
946
|
+
params,
|
|
947
|
+
})
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Cancel a running time-weighted average price order through {@link execute}.
|
|
952
|
+
*
|
|
953
|
+
* @public
|
|
954
|
+
*/
|
|
955
|
+
async cancelTwapOrder(
|
|
956
|
+
params: CancelTwapOrderParams
|
|
957
|
+
): Promise<ExecuteActionResponse> {
|
|
958
|
+
return this.execute({
|
|
959
|
+
...params,
|
|
960
|
+
action: ActionType.CANCEL_TWAP_ORDER,
|
|
961
|
+
params,
|
|
962
|
+
})
|
|
963
|
+
}
|
|
964
|
+
|
|
878
965
|
/**
|
|
879
966
|
* Cancel one or more open orders. Convenience wrapper over {@link execute}
|
|
880
967
|
* with `ActionType.CANCEL_ORDER`.
|
package/src/index.ts
CHANGED
|
@@ -98,14 +98,17 @@ export {
|
|
|
98
98
|
export type {
|
|
99
99
|
BuildProviderSetupParams,
|
|
100
100
|
CancelOrdersParams,
|
|
101
|
+
CancelTwapOrderParams as ClientCancelTwapOrderParams,
|
|
101
102
|
GetAccountResult,
|
|
102
103
|
GetDepositFlowParams,
|
|
103
104
|
GetSetupParams,
|
|
105
|
+
GetWithdrawableBalancesParams,
|
|
104
106
|
ModifyOrdersParams,
|
|
105
107
|
PerpsClientOptions,
|
|
106
108
|
PerpsConfig,
|
|
107
109
|
PlaceOrderParams as ClientPlaceOrderParams,
|
|
108
110
|
PlaceTriggerOrderParams as ClientPlaceTriggerOrderParams,
|
|
111
|
+
PlaceTwapOrderParams as ClientPlaceTwapOrderParams,
|
|
109
112
|
ProviderSetup,
|
|
110
113
|
SendAssetActionParams,
|
|
111
114
|
WithdrawParams,
|
|
@@ -143,10 +146,17 @@ export type {
|
|
|
143
146
|
ProviderGetOrdersParams,
|
|
144
147
|
ProviderGetPositionsParams,
|
|
145
148
|
ProviderGetQuoteParams,
|
|
149
|
+
ProviderGetRunningTwapsParams,
|
|
150
|
+
ProviderGetWithdrawableBalancesParams,
|
|
146
151
|
QuoteListener,
|
|
147
152
|
SignActionProgress,
|
|
148
153
|
SignActionsContext,
|
|
149
154
|
} from './types/provider.js'
|
|
155
|
+
export type {
|
|
156
|
+
ProviderWithdrawableBalance,
|
|
157
|
+
WithdrawableBalance,
|
|
158
|
+
WithdrawalRoute,
|
|
159
|
+
} from './types/withdrawal.js'
|
|
150
160
|
export {
|
|
151
161
|
type CollateralSemantics,
|
|
152
162
|
summarizeAccount,
|
package/src/types/api.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AccountConfigSetting,
|
|
3
3
|
AccountResponse,
|
|
4
|
+
CancelTwapOrderParams as ActionCancelTwapOrderParams,
|
|
5
|
+
PlaceTwapOrderParams as ActionPlaceTwapOrderParams,
|
|
4
6
|
ActionStep,
|
|
5
7
|
ExecuteActionResponse,
|
|
6
8
|
MarginMode,
|
|
@@ -126,7 +128,7 @@ export interface PlaceOrderParams {
|
|
|
126
128
|
/** Opaque provider market reference. */
|
|
127
129
|
market: MarketRef
|
|
128
130
|
side: OrderSide
|
|
129
|
-
type: OrderType
|
|
131
|
+
type: Exclude<OrderType, OrderType.TWAP>
|
|
130
132
|
/** Base-asset size as a decimal wire string. */
|
|
131
133
|
size: string
|
|
132
134
|
/** Limit price as a decimal wire string; required by limit-style orders. */
|
|
@@ -165,6 +167,26 @@ export interface PlaceTriggerOrderParams {
|
|
|
165
167
|
stopLoss?: TriggerOrderInput
|
|
166
168
|
}
|
|
167
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Client parameters for placing a TWAP order.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export interface PlaceTwapOrderParams extends ActionPlaceTwapOrderParams {
|
|
176
|
+
provider: string
|
|
177
|
+
address: Address
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Client parameters for cancelling a running TWAP order.
|
|
182
|
+
*
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export interface CancelTwapOrderParams extends ActionCancelTwapOrderParams {
|
|
186
|
+
provider: string
|
|
187
|
+
address: Address
|
|
188
|
+
}
|
|
189
|
+
|
|
168
190
|
/**
|
|
169
191
|
* Parameters for withdrawing funds.
|
|
170
192
|
*
|
|
@@ -243,6 +265,16 @@ export interface GetDepositFlowParams {
|
|
|
243
265
|
address: Address
|
|
244
266
|
}
|
|
245
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Parameters for {@link PerpsClient.getWithdrawableBalances}.
|
|
270
|
+
*
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
export interface GetWithdrawableBalancesParams {
|
|
274
|
+
provider: string
|
|
275
|
+
address: Address
|
|
276
|
+
}
|
|
277
|
+
|
|
246
278
|
/**
|
|
247
279
|
* Result from {@link PerpsClient.checkSetup}.
|
|
248
280
|
*
|
package/src/types/provider.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
SignedActionStep,
|
|
26
26
|
SigningMethod,
|
|
27
27
|
TradeType,
|
|
28
|
+
TwapOrder,
|
|
28
29
|
} from '@lifi/perps-types'
|
|
29
30
|
import type { Address } from 'viem'
|
|
30
31
|
import type {
|
|
@@ -33,6 +34,7 @@ import type {
|
|
|
33
34
|
SDKRequestOptions,
|
|
34
35
|
} from './config.js'
|
|
35
36
|
import type { DepositFlow } from './deposit.js'
|
|
37
|
+
import type { ProviderWithdrawableBalance } from './withdrawal.js'
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Low-level SDK client: resolved config, the optional end-user wallet, and the
|
|
@@ -176,6 +178,15 @@ export interface ProviderGetDepositFlowParams {
|
|
|
176
178
|
address: Address
|
|
177
179
|
}
|
|
178
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Read params for {@link PerpsProviderPlugin.getWithdrawableBalances}.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
export interface ProviderGetWithdrawableBalancesParams {
|
|
187
|
+
address: Address
|
|
188
|
+
}
|
|
189
|
+
|
|
179
190
|
/**
|
|
180
191
|
* Read params for {@link PerpsProvider.getPositions}.
|
|
181
192
|
*
|
|
@@ -218,6 +229,17 @@ export interface ProviderGetOrdersParams {
|
|
|
218
229
|
cursor?: string
|
|
219
230
|
}
|
|
220
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Read params for {@link PerpsProvider.getRunningTwaps}.
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
export interface ProviderGetRunningTwapsParams {
|
|
238
|
+
address: Address
|
|
239
|
+
/** Optional opaque `Market.id` filter (not a display symbol). */
|
|
240
|
+
marketId?: string
|
|
241
|
+
}
|
|
242
|
+
|
|
221
243
|
/**
|
|
222
244
|
* Read params for {@link PerpsProvider.getOrder}.
|
|
223
245
|
*
|
|
@@ -377,6 +399,21 @@ export interface PerpsProviderPlugin {
|
|
|
377
399
|
options?: SDKRequestOptions
|
|
378
400
|
): Promise<DepositFlow>
|
|
379
401
|
|
|
402
|
+
/**
|
|
403
|
+
* The `(asset, route)` pairs `params.address` currently has something to
|
|
404
|
+
* withdraw from, keyed by provider-native asset id. Only the venue knows how
|
|
405
|
+
* its balance payload splits across routes, so the split is owned here; the
|
|
406
|
+
* per-asset venue minimum is applied by `PerpsClient.getWithdrawableBalances`,
|
|
407
|
+
* which holds the core asset registry.
|
|
408
|
+
*
|
|
409
|
+
* Optional: a provider whose withdrawals are not a per-route selection omits
|
|
410
|
+
* it, and `PerpsClient.getWithdrawableBalances` then resolves `undefined`.
|
|
411
|
+
*/
|
|
412
|
+
getWithdrawableBalances?(
|
|
413
|
+
params: ProviderGetWithdrawableBalancesParams,
|
|
414
|
+
options?: SDKRequestOptions
|
|
415
|
+
): Promise<ProviderWithdrawableBalance[]>
|
|
416
|
+
|
|
380
417
|
getPositions(
|
|
381
418
|
params: ProviderGetPositionsParams,
|
|
382
419
|
options?: SDKRequestOptions
|
|
@@ -399,6 +436,15 @@ export interface PerpsProviderPlugin {
|
|
|
399
436
|
options?: SDKRequestOptions
|
|
400
437
|
): Promise<OrdersResponse>
|
|
401
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Fetch the account's currently running TWAP parent orders directly from the
|
|
441
|
+
* venue. Child slice orders are excluded.
|
|
442
|
+
*/
|
|
443
|
+
getRunningTwaps?(
|
|
444
|
+
params: ProviderGetRunningTwapsParams,
|
|
445
|
+
options?: SDKRequestOptions
|
|
446
|
+
): Promise<TwapOrder[]>
|
|
447
|
+
|
|
402
448
|
getOrder(
|
|
403
449
|
params: ProviderGetOrderParams,
|
|
404
450
|
options?: SDKRequestOptions
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Asset } from '@lifi/perps-types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which of a venue's two balance routes a withdrawal is drawn from. Lighter's
|
|
5
|
+
* own vocabulary, carried in the signed tx as `AssetRouteType` (`perps` = 0,
|
|
6
|
+
* `spot` = 1); an account's mode changes what the two balances mean, never
|
|
7
|
+
* which route the tx names.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type WithdrawalRoute = 'perps' | 'spot'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One withdrawable `(asset, route)` selection as the provider reports it, keyed
|
|
15
|
+
* by provider-native asset id and awaiting the core asset-metadata join.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export interface ProviderWithdrawableBalance {
|
|
20
|
+
/** Provider-native `Asset.id`; never a display symbol. */
|
|
21
|
+
assetId: string
|
|
22
|
+
route: WithdrawalRoute
|
|
23
|
+
/** Withdrawable amount in the asset's own units. Always greater than zero. */
|
|
24
|
+
available: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One withdrawable `(asset, route)` selection a caller can act on: the amount
|
|
29
|
+
* clears the asset's venue minimum, and `asset` carries the precision and
|
|
30
|
+
* minimum needed to scale and validate the withdrawal.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export interface WithdrawableBalance {
|
|
35
|
+
asset: Asset
|
|
36
|
+
route: WithdrawalRoute
|
|
37
|
+
/** Withdrawable amount in the asset's own units. */
|
|
38
|
+
available: string
|
|
39
|
+
}
|
package/src/version.ts
CHANGED