@lifi/perps-sdk 2.4.0 → 3.1.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 (58) hide show
  1. package/dist/cjs/client/PerpsClient.d.ts +1 -1
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +10 -37
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +2 -2
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +2 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/types/provider.d.ts +2 -2
  10. package/dist/cjs/types/provider.d.ts.map +1 -1
  11. package/dist/cjs/utils/format.d.ts +3 -0
  12. package/dist/cjs/utils/format.d.ts.map +1 -1
  13. package/dist/cjs/utils/format.js +31 -24
  14. package/dist/cjs/utils/format.js.map +1 -1
  15. package/dist/cjs/version.d.ts +1 -1
  16. package/dist/cjs/version.js +1 -1
  17. package/dist/esm/client/PerpsClient.d.ts +6 -8
  18. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  19. package/dist/esm/client/PerpsClient.js +15 -46
  20. package/dist/esm/client/PerpsClient.js.map +1 -1
  21. package/dist/esm/index.d.ts +2 -2
  22. package/dist/esm/index.d.ts.map +1 -1
  23. package/dist/esm/index.js +1 -1
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/types/provider.d.ts +5 -10
  26. package/dist/esm/types/provider.d.ts.map +1 -1
  27. package/dist/esm/utils/format.d.ts +22 -0
  28. package/dist/esm/utils/format.d.ts.map +1 -1
  29. package/dist/esm/utils/format.js +57 -27
  30. package/dist/esm/utils/format.js.map +1 -1
  31. package/dist/esm/version.d.ts +1 -1
  32. package/dist/esm/version.js +1 -1
  33. package/dist/types/client/PerpsClient.d.ts +6 -8
  34. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  35. package/dist/types/index.d.ts +2 -2
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/types/provider.d.ts +5 -10
  38. package/dist/types/types/provider.d.ts.map +1 -1
  39. package/dist/types/utils/format.d.ts +22 -0
  40. package/dist/types/utils/format.d.ts.map +1 -1
  41. package/dist/types/version.d.ts +1 -1
  42. package/package.json +2 -2
  43. package/src/client/PerpsClient.ts +22 -70
  44. package/src/index.ts +2 -1
  45. package/src/types/provider.ts +4 -14
  46. package/src/utils/format.ts +108 -28
  47. package/src/version.ts +1 -1
  48. package/dist/cjs/client/clientLog.d.ts +0 -4
  49. package/dist/cjs/client/clientLog.d.ts.map +0 -1
  50. package/dist/cjs/client/clientLog.js +0 -9
  51. package/dist/cjs/client/clientLog.js.map +0 -1
  52. package/dist/esm/client/clientLog.d.ts +0 -16
  53. package/dist/esm/client/clientLog.d.ts.map +0 -1
  54. package/dist/esm/client/clientLog.js +0 -18
  55. package/dist/esm/client/clientLog.js.map +0 -1
  56. package/dist/types/client/clientLog.d.ts +0 -16
  57. package/dist/types/client/clientLog.d.ts.map +0 -1
  58. package/src/client/clientLog.ts +0 -20
@@ -1,4 +1,4 @@
1
- import type { AccountConfig, AccountConfigSetting, AccountResponse, AccountSummary, ActionResult, ActionStep, ActionType, ActivitiesResponse, ActivityType, FillsResponse, Market, Order, OrdersResponse, PerpsMarket, PerpsSigner, Position, PositionsResponse, ProviderAction, Quote, QuoteSide, RestCallSignedActionStep, SignedActionStep, SigningMethod, TradeType } from '@lifi/perps-types';
1
+ import type { AccountConfig, AccountConfigSetting, AccountResponse, AccountSummary, ActionResult, ActionStep, ActionType, ActivitiesResponse, ActivityType, FillsResponse, Market, Order, OrdersResponse, PerpsMarket, PerpsSigner, Position, PositionsResponse, ProviderAction, Quote, QuoteSide, SignedActionStep, SigningMethod, TradeType } from '@lifi/perps-types';
2
2
  import type { Address } from 'viem';
3
3
  import type { PerpsBaseConfig, PerpsClientSigner, SDKRequestOptions } from './config.js';
4
4
  /**
@@ -370,16 +370,11 @@ export interface PerpsProviderPlugin {
370
370
  */
371
371
  signActions?(method: SigningMethod, steps: ActionStep[], address: Address, ctx?: SignActionsContext): Promise<SignedActionStep[]>;
372
372
  /**
373
- * Execute credential-bearing rest-call steps directly against the venue.
374
- * Required for providers whose descriptors declare
375
- * `SigningMethod.AUTH_TOKEN`: the client-held credential (attached by
376
- * `signActions` as `headers`) must never transit the LI.FI backend, so the
377
- * venue call happens SDK-side. The provider owns base-URL resolution and
378
- * mapping the venue response onto {@link ActionResult}s — these results are
379
- * authoritative for the caller; `PerpsClient.execute` submits the steps to
380
- * the backend afterwards for bookkeeping only, with `headers` stripped.
373
+ * Observe the per-step results of an `/executeAction` round trip before the
374
+ * core surfaces failures. Lets a provider react to structured failure codes
375
+ * — e.g. evicting a locally stored credential the venue no longer accepts.
381
376
  */
382
- executeRestCallActions?(steps: RestCallSignedActionStep[], address: Address, options?: SDKRequestOptions): Promise<ActionResult[]>;
377
+ onExecuteResults?(address: Address, results: ActionResult[]): Promise<void>;
383
378
  }
384
379
  /**
385
380
  * Runtime provider returned by {@link PerpsSDKClient.getProvider} and
@@ -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,KAAK,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,EACT,wBAAwB,EACxB,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;AAEpB;;;;;;GAMG;A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AE,wBAAwB,EAAE,EACjC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;CAC3B;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,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,KAAK,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,QAAQ,EACR,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;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAA;IACvC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,CAAA;IACnC,0EAA0E;IAC1E,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAA;CACpD;AAED;;;;;;;GAOG;AACH;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAA;IACb,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,UAAU,CAAA;IAClB,iF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E,yBAAyB,GAChC,MAAM,GAAG,SAAS,CAAA;IAErB;;;;;;;;;OASG;IACH,aAAa,CACX,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,EAAE,cAAc,EAAE,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;CAC5E;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA"}
@@ -10,8 +10,30 @@ export interface FormatOptions {
10
10
  placeholder?: string;
11
11
  /** BCP 47 locale controlling digit grouping and separators (e.g. `'en-US'`). */
12
12
  locale?: string;
13
+ /**
14
+ * Rounding applied when reducing to `decimals` places. Defaults to
15
+ * `'halfUp'`. `'floor'` truncates toward zero (matching big.js `roundDown`),
16
+ * so the rendered magnitude never exceeds the source — use it for readouts
17
+ * validated against a ceiling (available balance, removable margin).
18
+ */
19
+ rounding?: RoundingMode;
13
20
  }
21
+ /** Rounding mode for {@link FormatOptions.rounding}. */
22
+ export type RoundingMode = 'halfUp' | 'floor';
14
23
  type FormatInput = number | string | null | undefined;
24
+ /**
25
+ * Format a bare number, unsigned, with no currency symbol: `1,234.50`,
26
+ * `-1,500.00`, `0.00`. The core the `$`/`%` formatters wrap; use it for
27
+ * balance labels and symbol-suffixed amounts (`12.5 LIT`).
28
+ *
29
+ * Two decimal places with locale digit grouping by default. Negatives keep a
30
+ * leading `-`. `rounding: 'floor'` truncates toward zero so the rendered
31
+ * magnitude never exceeds the source (`99.999` at 2dp → `99.99`, `-99.999` →
32
+ * `-99.99`). Null/undefined/non-finite input renders the placeholder.
33
+ *
34
+ * @public
35
+ */
36
+ export declare function formatNumber(value: FormatInput, options?: FormatOptions): string;
15
37
  /**
16
38
  * Format a USD value, unsigned: `$1,234.50`, `-$1,500.00`, `$0.00`.
17
39
  *
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/utils/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAID,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;AA+DrD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAQR;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAcR;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CA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BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAkBR"}
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/perps-sdk";
2
- export declare const version = "2.4.0";
2
+ export declare const version = "3.1.0";
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk",
3
- "version": "2.4.0",
3
+ "version": "3.1.0",
4
4
  "description": "LI.FI Perps SDK for perpetuals trading",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -44,7 +44,7 @@
44
44
  "@lifi/types": "17.82.1",
45
45
  "partysocket": "^1.1.19",
46
46
  "viem": "^2.48.8",
47
- "@lifi/perps-types": "^1.15.1"
47
+ "@lifi/perps-types": "^2.0.0"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"
@@ -2,6 +2,7 @@ import type {
2
2
  AccountResponse,
3
3
  AccountSummary,
4
4
  ActionParamsMap,
5
+ ActionResult,
5
6
  ActionStep,
6
7
  CreateActionResponse,
7
8
  ExecuteActionResponse,
@@ -9,7 +10,6 @@ import type {
9
10
  Position,
10
11
  Provider,
11
12
  ProviderAction,
12
- RestCallSignedActionStep,
13
13
  SignedActionStep,
14
14
  } from '@lifi/perps-types'
15
15
  import { ActionType, PerpsErrorCode, SigningMethod } from '@lifi/perps-types'
@@ -46,7 +46,6 @@ import {
46
46
  switchSigningChain,
47
47
  userEip712TargetChainId,
48
48
  } from '../utils/switchChain.js'
49
- import { clientLog } from './clientLog.js'
50
49
  import { createPerpsClient } from './createPerpsClient.js'
51
50
  import { requireProvider as resolveProvider } from './requireProvider.js'
52
51
 
@@ -217,6 +216,22 @@ export class PerpsClient {
217
216
  )
218
217
  }
219
218
 
219
+ /**
220
+ * Let the plugin observe `/executeAction` per-step results before the core
221
+ * surfaces failures — e.g. to evict a locally stored credential the venue
222
+ * rejected.
223
+ */
224
+ private async notifyExecuteResults(
225
+ provider: string,
226
+ address: Address,
227
+ results: ActionResult[]
228
+ ): Promise<void> {
229
+ const plugin = this.requireProvider(provider)
230
+ if (typeof plugin.onExecuteResults === 'function') {
231
+ await plugin.onExecuteResults(address, results)
232
+ }
233
+ }
234
+
220
235
  /**
221
236
  * Resolve the wallet that signs `actions`. For a USER-signed EIP-712 batch,
222
237
  * switch the configured wallet to the action's target chain via the
@@ -569,6 +584,8 @@ export class PerpsClient {
569
584
  actions: signedActions,
570
585
  })
571
586
 
587
+ await this.notifyExecuteResults(provider, address, results.results)
588
+
572
589
  const failure = results.results.find((r) => !r.success)
573
590
  if (failure) {
574
591
  throw new PerpsError(PerpsErrorCode.ExchangeRejected, failure.error)
@@ -837,16 +854,6 @@ export class PerpsClient {
837
854
  onProgress
838
855
  )
839
856
 
840
- if (descriptor.signingMethod === SigningMethod.AUTH_TOKEN) {
841
- return this.executeAuthTokenActions(
842
- provider,
843
- address,
844
- signerAddress ?? address,
845
- action,
846
- signedActions
847
- )
848
- }
849
-
850
857
  // A plugin may execute an action entirely client-side (e.g. Lighter's
851
858
  // token-authenticated venue mutations), leaving no backend-bound step. With
852
859
  // nothing to submit, skip the `/executeAction` hop.
@@ -854,7 +861,7 @@ export class PerpsClient {
854
861
  return { results: [] }
855
862
  }
856
863
 
857
- return executeAction(this.sdkClient, {
864
+ const response = await executeAction(this.sdkClient, {
858
865
  provider,
859
866
  address,
860
867
  // The submitting account: the plugin-resolved signer (Hyperliquid's
@@ -863,64 +870,9 @@ export class PerpsClient {
863
870
  action,
864
871
  actions: signedActions,
865
872
  })
866
- }
867
-
868
- /**
869
- * The `AUTH_TOKEN` arm of {@link execute}: the venue call runs client-side
870
- * via the plugin's `executeRestCallActions` because the credential headers
871
- * must never transit the LI.FI backend. The venue's results are what the
872
- * caller gets; the backend `executeAction` submission that follows is
873
- * bookkeeping only, sent with `headers` stripped.
874
- */
875
- private async executeAuthTokenActions(
876
- provider: string,
877
- address: Address,
878
- signerAddress: Address,
879
- action: ActionType,
880
- signedActions: SignedActionStep[]
881
- ): Promise<ExecuteActionResponse> {
882
- const plugin = this.requireProvider(provider)
883
- if (typeof plugin.executeRestCallActions !== 'function') {
884
- throw new PerpsError(
885
- PerpsErrorCode.SDKError,
886
- `Provider '${provider}' does not implement executeRestCallActions ` +
887
- `for signingMethod 'authToken'.`
888
- )
889
- }
890
873
 
891
- const restCallSteps = signedActions.map(
892
- (step): RestCallSignedActionStep => {
893
- if (!('request' in step) || !('headers' in step)) {
894
- throw new PerpsError(
895
- PerpsErrorCode.SDKError,
896
- `Provider '${provider}' signed action '${step.action}' with a ` +
897
- `non-rest-call step for signingMethod 'authToken'.`
898
- )
899
- }
900
- return step
901
- }
902
- )
874
+ await this.notifyExecuteResults(provider, address, response.results)
903
875
 
904
- const results = await plugin.executeRestCallActions(restCallSteps, address)
905
-
906
- try {
907
- await executeAction(this.sdkClient, {
908
- provider,
909
- address,
910
- signerAddress,
911
- action,
912
- actions: restCallSteps.map((step) => ({
913
- action: step.action,
914
- request: step.request,
915
- headers: {},
916
- })),
917
- })
918
- } catch (error) {
919
- // The venue call already succeeded above — a failed bookkeeping
920
- // submission must not mask a landed order, so it is logged, not thrown.
921
- clientLog.bookkeepingFailure(provider, error)
922
- }
923
-
924
- return { results }
876
+ return response
925
877
  }
926
878
  }
package/src/index.ts CHANGED
@@ -160,9 +160,10 @@ export {
160
160
  } from './utils/depositChain.js'
161
161
  export { ExplorerChainId, explorerTxUrl } from './utils/explorer.js'
162
162
  export { classifyFillFromPosition } from './utils/fillClassification.js'
163
- export type { FormatOptions } from './utils/format.js'
163
+ export type { FormatOptions, RoundingMode } from './utils/format.js'
164
164
  export {
165
165
  formatCompactUsd,
166
+ formatNumber,
166
167
  formatPrice,
167
168
  formatSignedPercent,
168
169
  formatSignedUsd,
@@ -19,7 +19,6 @@ import type {
19
19
  ProviderAction,
20
20
  Quote,
21
21
  QuoteSide,
22
- RestCallSignedActionStep,
23
22
  SignedActionStep,
24
23
  SigningMethod,
25
24
  TradeType,
@@ -478,20 +477,11 @@ export interface PerpsProviderPlugin {
478
477
  ): Promise<SignedActionStep[]>
479
478
 
480
479
  /**
481
- * Execute credential-bearing rest-call steps directly against the venue.
482
- * Required for providers whose descriptors declare
483
- * `SigningMethod.AUTH_TOKEN`: the client-held credential (attached by
484
- * `signActions` as `headers`) must never transit the LI.FI backend, so the
485
- * venue call happens SDK-side. The provider owns base-URL resolution and
486
- * mapping the venue response onto {@link ActionResult}s — these results are
487
- * authoritative for the caller; `PerpsClient.execute` submits the steps to
488
- * the backend afterwards for bookkeeping only, with `headers` stripped.
480
+ * Observe the per-step results of an `/executeAction` round trip before the
481
+ * core surfaces failures. Lets a provider react to structured failure codes
482
+ * — e.g. evicting a locally stored credential the venue no longer accepts.
489
483
  */
490
- executeRestCallActions?(
491
- steps: RestCallSignedActionStep[],
492
- address: Address,
493
- options?: SDKRequestOptions
494
- ): Promise<ActionResult[]>
484
+ onExecuteResults?(address: Address, results: ActionResult[]): Promise<void>
495
485
  }
496
486
 
497
487
  /**
@@ -10,12 +10,29 @@ export interface FormatOptions {
10
10
  placeholder?: string
11
11
  /** BCP 47 locale controlling digit grouping and separators (e.g. `'en-US'`). */
12
12
  locale?: string
13
+ /**
14
+ * Rounding applied when reducing to `decimals` places. Defaults to
15
+ * `'halfUp'`. `'floor'` truncates toward zero (matching big.js `roundDown`),
16
+ * so the rendered magnitude never exceeds the source — use it for readouts
17
+ * validated against a ceiling (available balance, removable margin).
18
+ */
19
+ rounding?: RoundingMode
13
20
  }
14
21
 
22
+ /** Rounding mode for {@link FormatOptions.rounding}. */
23
+ export type RoundingMode = 'halfUp' | 'floor'
24
+
15
25
  const DEFAULT_PLACEHOLDER = '—'
16
26
 
17
27
  type FormatInput = number | string | null | undefined
18
28
 
29
+ /**
30
+ * Extra decimal places used to normalise IEEE-754 representation noise before
31
+ * truncating. `toFixed` at this higher precision cleans values like
32
+ * `0.28999999…` back to `0.29`; truncation then chops the guard digits.
33
+ */
34
+ const FLOAT_GUARD_DIGITS = 9
35
+
19
36
  /**
20
37
  * Tolerantly coerce a display input to a finite number.
21
38
  *
@@ -40,19 +57,38 @@ function toFiniteNumber(value: FormatInput): number | null {
40
57
  }
41
58
 
42
59
  /**
43
- * Round to `decimals` then split into a sign (`'-'` or `''`) and the
44
- * locale-formatted absolute body. Deriving the sign from the rounded value
45
- * avoids `-$0.00` for values that round to zero.
60
+ * Truncate a non-negative value toward zero to `decimals` places using its
61
+ * decimal string, never float scaling. Representation noise is first
62
+ * normalised by `toFixed` at {@link FLOAT_GUARD_DIGITS} extra precision, then
63
+ * the guard digits are chopped: `99.999` at 2dp → `99.99`, `0.29` → `0.29`.
64
+ */
65
+ function truncateAbs(abs: number, decimals: number): number {
66
+ const s = abs.toFixed(Math.min(decimals + FLOAT_GUARD_DIGITS, 100))
67
+ const dot = s.indexOf('.')
68
+ const cut = decimals === 0 ? dot : dot + 1 + decimals
69
+ return Number(s.slice(0, cut))
70
+ }
71
+
72
+ /**
73
+ * Reduce `n` to `decimals` places then split into a sign and the
74
+ * locale-formatted absolute body. The sign is derived from the reduced value
75
+ * so magnitudes that collapse to zero render without a spurious `-`/`+`.
76
+ * `signed` emits `+` for positives; `rounding` selects half-up or truncation.
46
77
  */
47
78
  function signAndBody(
48
79
  n: number,
49
80
  decimals: number,
50
81
  locale: string | undefined,
51
- grouping: boolean
52
- ): { sign: '-' | ''; body: string } {
53
- const rounded = Number(n.toFixed(decimals))
54
- const sign = rounded < 0 ? '-' : ''
55
- const body = Math.abs(rounded).toLocaleString(locale, {
82
+ grouping: boolean,
83
+ rounding: RoundingMode,
84
+ signed: boolean
85
+ ): { sign: '+' | '-' | ''; body: string } {
86
+ const reduced =
87
+ rounding === 'floor'
88
+ ? (n < 0 ? -1 : 1) * truncateAbs(Math.abs(n), decimals)
89
+ : Number(n.toFixed(decimals))
90
+ const sign = reduced < 0 ? '-' : signed && reduced > 0 ? '+' : ''
91
+ const body = Math.abs(reduced).toLocaleString(locale, {
56
92
  minimumFractionDigits: decimals,
57
93
  maximumFractionDigits: decimals,
58
94
  useGrouping: grouping,
@@ -77,6 +113,36 @@ function autoDecimals(abs: number): number {
77
113
  return 6
78
114
  }
79
115
 
116
+ /**
117
+ * Format a bare number, unsigned, with no currency symbol: `1,234.50`,
118
+ * `-1,500.00`, `0.00`. The core the `$`/`%` formatters wrap; use it for
119
+ * balance labels and symbol-suffixed amounts (`12.5 LIT`).
120
+ *
121
+ * Two decimal places with locale digit grouping by default. Negatives keep a
122
+ * leading `-`. `rounding: 'floor'` truncates toward zero so the rendered
123
+ * magnitude never exceeds the source (`99.999` at 2dp → `99.99`, `-99.999` →
124
+ * `-99.99`). Null/undefined/non-finite input renders the placeholder.
125
+ *
126
+ * @public
127
+ */
128
+ export function formatNumber(
129
+ value: FormatInput,
130
+ options: FormatOptions = {}
131
+ ): string {
132
+ const {
133
+ decimals = 2,
134
+ placeholder = DEFAULT_PLACEHOLDER,
135
+ locale,
136
+ rounding = 'halfUp',
137
+ } = options
138
+ const n = toFiniteNumber(value)
139
+ if (n === null) {
140
+ return placeholder
141
+ }
142
+ const { sign, body } = signAndBody(n, decimals, locale, true, rounding, false)
143
+ return `${sign}${body}`
144
+ }
145
+
80
146
  /**
81
147
  * Format a USD value, unsigned: `$1,234.50`, `-$1,500.00`, `$0.00`.
82
148
  *
@@ -89,12 +155,17 @@ export function formatUsd(
89
155
  value: FormatInput,
90
156
  options: FormatOptions = {}
91
157
  ): string {
92
- const { decimals = 2, placeholder = DEFAULT_PLACEHOLDER, locale } = options
158
+ const {
159
+ decimals = 2,
160
+ placeholder = DEFAULT_PLACEHOLDER,
161
+ locale,
162
+ rounding = 'halfUp',
163
+ } = options
93
164
  const n = toFiniteNumber(value)
94
165
  if (n === null) {
95
166
  return placeholder
96
167
  }
97
- const { sign, body } = signAndBody(n, decimals, locale, true)
168
+ const { sign, body } = signAndBody(n, decimals, locale, true, rounding, false)
98
169
  return `${sign}$${body}`
99
170
  }
100
171
 
@@ -111,18 +182,17 @@ export function formatSignedUsd(
111
182
  value: FormatInput,
112
183
  options: FormatOptions = {}
113
184
  ): string {
114
- const { decimals = 2, placeholder = DEFAULT_PLACEHOLDER, locale } = options
185
+ const {
186
+ decimals = 2,
187
+ placeholder = DEFAULT_PLACEHOLDER,
188
+ locale,
189
+ rounding = 'halfUp',
190
+ } = options
115
191
  const n = toFiniteNumber(value)
116
192
  if (n === null) {
117
193
  return placeholder
118
194
  }
119
- const rounded = Number(n.toFixed(decimals))
120
- const sign = rounded > 0 ? '+' : rounded < 0 ? '-' : ''
121
- const body = Math.abs(rounded).toLocaleString(locale, {
122
- minimumFractionDigits: decimals,
123
- maximumFractionDigits: decimals,
124
- useGrouping: true,
125
- })
195
+ const { sign, body } = signAndBody(n, decimals, locale, true, rounding, true)
126
196
  return `${sign}$${body}`
127
197
  }
128
198
 
@@ -139,18 +209,17 @@ export function formatSignedPercent(
139
209
  value: FormatInput,
140
210
  options: FormatOptions = {}
141
211
  ): string {
142
- const { decimals = 2, placeholder = DEFAULT_PLACEHOLDER, locale } = options
212
+ const {
213
+ decimals = 2,
214
+ placeholder = DEFAULT_PLACEHOLDER,
215
+ locale,
216
+ rounding = 'halfUp',
217
+ } = options
143
218
  const n = toFiniteNumber(value)
144
219
  if (n === null) {
145
220
  return placeholder
146
221
  }
147
- const rounded = Number(n.toFixed(decimals))
148
- const sign = rounded > 0 ? '+' : rounded < 0 ? '-' : ''
149
- const body = Math.abs(rounded).toLocaleString(locale, {
150
- minimumFractionDigits: decimals,
151
- maximumFractionDigits: decimals,
152
- useGrouping: false,
153
- })
222
+ const { sign, body } = signAndBody(n, decimals, locale, false, rounding, true)
154
223
  return `${sign}${body}%`
155
224
  }
156
225
 
@@ -168,14 +237,25 @@ export function formatPrice(
168
237
  value: FormatInput,
169
238
  options: FormatOptions = {}
170
239
  ): string {
171
- const { placeholder = DEFAULT_PLACEHOLDER, locale } = options
240
+ const {
241
+ placeholder = DEFAULT_PLACEHOLDER,
242
+ locale,
243
+ rounding = 'halfUp',
244
+ } = options
172
245
  const n = toFiniteNumber(value)
173
246
  if (n === null) {
174
247
  return placeholder
175
248
  }
176
249
  const abs = Math.abs(n)
177
250
  const decimals = options.decimals ?? autoDecimals(abs)
178
- const { sign, body } = signAndBody(n, decimals, locale, abs >= 1000)
251
+ const { sign, body } = signAndBody(
252
+ n,
253
+ decimals,
254
+ locale,
255
+ abs >= 1000,
256
+ rounding,
257
+ false
258
+ )
179
259
  return `${sign}$${body}`
180
260
  }
181
261
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/perps-sdk'
2
- export const version = '2.4.0'
2
+ export const version = '3.1.0'
@@ -1,4 +0,0 @@
1
- export declare const clientLog: {
2
- readonly bookkeepingFailure: (provider: string, error: unknown) => void;
3
- };
4
- //# sourceMappingURL=clientLog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientLog.d.ts","sourceRoot":"","sources":["../../../src/client/clientLog.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,SAAS;4CAMS,MAAM,SAAS,OAAO,KAAG,IAAI;CAMlD,CAAA"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clientLog = void 0;
4
- exports.clientLog = {
5
- bookkeepingFailure(provider, error) {
6
- console.error(`[${provider}] backend bookkeeping submission failed after venue execution`, error);
7
- },
8
- };
9
- //# sourceMappingURL=clientLog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientLog.js","sourceRoot":"","sources":["../../../src/client/clientLog.ts"],"names":[],"mappings":";;;AAOa,QAAA,SAAS,GAAG;IAMvB,kBAAkB,CAAC,QAAgB,EAAE,KAAc;QACjD,OAAO,CAAC,KAAK,CACX,IAAI,QAAQ,+DAA+D,EAC3E,KAAK,CACN,CAAA;IACH,CAAC;CACO,CAAA"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Structured logger for client-layer (non-WebSocket) diagnostics, the REST-side
3
- * counterpart to {@link wsLog}, so failures surface through a single named
4
- * channel rather than scattered `console` calls.
5
- *
6
- * @internal
7
- */
8
- export declare const clientLog: {
9
- /**
10
- * The backend bookkeeping submission rejected after the venue call already
11
- * landed. Surfaced at `error` and swallowed by the caller — a failed
12
- * mirror-write must never mask an order that already executed on the venue.
13
- */
14
- readonly bookkeepingFailure: (provider: string, error: unknown) => void;
15
- };
16
- //# sourceMappingURL=clientLog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientLog.d.ts","sourceRoot":"","sources":["../../../src/client/clientLog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;IACpB;;;;OAIG;4CAC0B,MAAM,SAAS,OAAO,KAAG,IAAI;CAMlD,CAAA"}
@@ -1,18 +0,0 @@
1
- /**
2
- * Structured logger for client-layer (non-WebSocket) diagnostics, the REST-side
3
- * counterpart to {@link wsLog}, so failures surface through a single named
4
- * channel rather than scattered `console` calls.
5
- *
6
- * @internal
7
- */
8
- export const clientLog = {
9
- /**
10
- * The backend bookkeeping submission rejected after the venue call already
11
- * landed. Surfaced at `error` and swallowed by the caller — a failed
12
- * mirror-write must never mask an order that already executed on the venue.
13
- */
14
- bookkeepingFailure(provider, error) {
15
- console.error(`[${provider}] backend bookkeeping submission failed after venue execution`, error);
16
- },
17
- };
18
- //# sourceMappingURL=clientLog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientLog.js","sourceRoot":"","sources":["../../../src/client/clientLog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;;;OAIG;IACH,kBAAkB,CAAC,QAAgB,EAAE,KAAc;QACjD,OAAO,CAAC,KAAK,CACX,IAAI,QAAQ,+DAA+D,EAC3E,KAAK,CACN,CAAA;IACH,CAAC;CACO,CAAA"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Structured logger for client-layer (non-WebSocket) diagnostics, the REST-side
3
- * counterpart to {@link wsLog}, so failures surface through a single named
4
- * channel rather than scattered `console` calls.
5
- *
6
- * @internal
7
- */
8
- export declare const clientLog: {
9
- /**
10
- * The backend bookkeeping submission rejected after the venue call already
11
- * landed. Surfaced at `error` and swallowed by the caller — a failed
12
- * mirror-write must never mask an order that already executed on the venue.
13
- */
14
- readonly bookkeepingFailure: (provider: string, error: unknown) => void;
15
- };
16
- //# sourceMappingURL=clientLog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientLog.d.ts","sourceRoot":"","sources":["../../../src/client/clientLog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;IACpB;;;;OAIG;4CAC0B,MAAM,SAAS,OAAO,KAAG,IAAI;CAMlD,CAAA"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Structured logger for client-layer (non-WebSocket) diagnostics, the REST-side
3
- * counterpart to {@link wsLog}, so failures surface through a single named
4
- * channel rather than scattered `console` calls.
5
- *
6
- * @internal
7
- */
8
- export const clientLog = {
9
- /**
10
- * The backend bookkeeping submission rejected after the venue call already
11
- * landed. Surfaced at `error` and swallowed by the caller — a failed
12
- * mirror-write must never mask an order that already executed on the venue.
13
- */
14
- bookkeepingFailure(provider: string, error: unknown): void {
15
- console.error(
16
- `[${provider}] backend bookkeeping submission failed after venue execution`,
17
- error
18
- )
19
- },
20
- } as const