@lifi/perps-sdk 0.0.0-preview-8effdce → 0.0.0-preview-e1b82a0

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 (92) hide show
  1. package/README.md +12 -1
  2. package/dist/cjs/client/PerpsClient.d.ts +3 -2
  3. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  4. package/dist/cjs/client/PerpsClient.js +11 -2
  5. package/dist/cjs/client/PerpsClient.js.map +1 -1
  6. package/dist/cjs/decimal/format.d.ts.map +1 -1
  7. package/dist/cjs/decimal/format.js +0 -3
  8. package/dist/cjs/decimal/format.js.map +1 -1
  9. package/dist/cjs/decimal/parse.d.ts +0 -1
  10. package/dist/cjs/decimal/parse.d.ts.map +1 -1
  11. package/dist/cjs/decimal/parse.js +0 -8
  12. package/dist/cjs/decimal/parse.js.map +1 -1
  13. package/dist/cjs/decimal/requireDecimal.d.ts +1 -1
  14. package/dist/cjs/decimal/requireDecimal.d.ts.map +1 -1
  15. package/dist/cjs/decimal/requireDecimal.js +6 -1
  16. package/dist/cjs/decimal/requireDecimal.js.map +1 -1
  17. package/dist/cjs/index.d.ts +4 -5
  18. package/dist/cjs/index.d.ts.map +1 -1
  19. package/dist/cjs/index.js +3 -6
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/types/api.d.ts +4 -0
  22. package/dist/cjs/types/api.d.ts.map +1 -1
  23. package/dist/cjs/types/provider.d.ts +5 -1
  24. package/dist/cjs/types/provider.d.ts.map +1 -1
  25. package/dist/cjs/types/withdrawal.d.ts +12 -4
  26. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  27. package/dist/cjs/version.d.ts +1 -1
  28. package/dist/cjs/version.js +1 -1
  29. package/dist/esm/client/PerpsClient.d.ts +17 -4
  30. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  31. package/dist/esm/client/PerpsClient.js +25 -4
  32. package/dist/esm/client/PerpsClient.js.map +1 -1
  33. package/dist/esm/decimal/format.d.ts.map +1 -1
  34. package/dist/esm/decimal/format.js +0 -4
  35. package/dist/esm/decimal/format.js.map +1 -1
  36. package/dist/esm/decimal/parse.d.ts +0 -10
  37. package/dist/esm/decimal/parse.d.ts.map +1 -1
  38. package/dist/esm/decimal/parse.js +1 -17
  39. package/dist/esm/decimal/parse.js.map +1 -1
  40. package/dist/esm/decimal/requireDecimal.d.ts +8 -2
  41. package/dist/esm/decimal/requireDecimal.d.ts.map +1 -1
  42. package/dist/esm/decimal/requireDecimal.js +14 -3
  43. package/dist/esm/decimal/requireDecimal.js.map +1 -1
  44. package/dist/esm/index.d.ts +4 -5
  45. package/dist/esm/index.d.ts.map +1 -1
  46. package/dist/esm/index.js +1 -2
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/types/api.d.ts +9 -0
  49. package/dist/esm/types/api.d.ts.map +1 -1
  50. package/dist/esm/types/provider.d.ts +22 -5
  51. package/dist/esm/types/provider.d.ts.map +1 -1
  52. package/dist/esm/types/withdrawal.d.ts +32 -7
  53. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  54. package/dist/esm/version.d.ts +1 -1
  55. package/dist/esm/version.js +1 -1
  56. package/dist/types/client/PerpsClient.d.ts +17 -4
  57. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  58. package/dist/types/decimal/format.d.ts.map +1 -1
  59. package/dist/types/decimal/parse.d.ts +0 -10
  60. package/dist/types/decimal/parse.d.ts.map +1 -1
  61. package/dist/types/decimal/requireDecimal.d.ts +8 -2
  62. package/dist/types/decimal/requireDecimal.d.ts.map +1 -1
  63. package/dist/types/index.d.ts +4 -5
  64. package/dist/types/index.d.ts.map +1 -1
  65. package/dist/types/types/api.d.ts +9 -0
  66. package/dist/types/types/api.d.ts.map +1 -1
  67. package/dist/types/types/provider.d.ts +22 -5
  68. package/dist/types/types/provider.d.ts.map +1 -1
  69. package/dist/types/types/withdrawal.d.ts +32 -7
  70. package/dist/types/types/withdrawal.d.ts.map +1 -1
  71. package/dist/types/version.d.ts +1 -1
  72. package/package.json +2 -2
  73. package/src/client/PerpsClient.ts +35 -5
  74. package/src/decimal/format.ts +0 -4
  75. package/src/decimal/parse.ts +1 -28
  76. package/src/decimal/requireDecimal.ts +17 -4
  77. package/src/index.ts +5 -7
  78. package/src/types/api.ts +10 -0
  79. package/src/types/provider.ts +31 -5
  80. package/src/types/withdrawal.ts +35 -8
  81. package/src/version.ts +1 -1
  82. package/dist/cjs/decimal/compare.d.ts +0 -3
  83. package/dist/cjs/decimal/compare.d.ts.map +0 -1
  84. package/dist/cjs/decimal/compare.js +0 -8
  85. package/dist/cjs/decimal/compare.js.map +0 -1
  86. package/dist/esm/decimal/compare.d.ts +0 -11
  87. package/dist/esm/decimal/compare.d.ts.map +0 -1
  88. package/dist/esm/decimal/compare.js +0 -13
  89. package/dist/esm/decimal/compare.js.map +0 -1
  90. package/dist/types/decimal/compare.d.ts +0 -11
  91. package/dist/types/decimal/compare.d.ts.map +0 -1
  92. package/src/decimal/compare.ts +0 -17
@@ -1,16 +1,16 @@
1
- import type { ActionType, Asset, DecimalString, WithdrawalRoute } from '@lifi/perps-types';
1
+ import type { ActionType, Asset, DecimalString, WithdrawalAssetRef, WithdrawalType } from '@lifi/perps-types';
2
2
  import type { Address } from 'viem';
3
- export type { WithdrawalRoute };
4
3
  /**
5
- * One withdrawable `(asset, route)` selection as the provider reports it, keyed
6
- * by provider-native asset id and awaiting the core asset-metadata join.
4
+ * One withdrawable `(asset, category)` selection as the provider reports it,
5
+ * keyed by provider-native asset id and awaiting the core asset-metadata join.
7
6
  *
8
7
  * @public
9
8
  */
10
9
  export interface ProviderWithdrawableBalance {
11
10
  /** Provider-native `Asset.id`; never a display symbol. */
12
11
  assetId: string;
13
- route: WithdrawalRoute;
12
+ /** The provider category the row draws from; the same value as `Balance.categoryId`. */
13
+ categoryId: string;
14
14
  /** Withdrawable amount in the asset's own units. Always greater than zero. */
15
15
  available: DecimalString;
16
16
  /**
@@ -33,7 +33,7 @@ export interface ProviderWithdrawableBalance {
33
33
  isFeeDeducted?: boolean;
34
34
  }
35
35
  /**
36
- * One withdrawable `(asset, route)` selection a caller can act on: the amount
36
+ * One withdrawable `(asset, category)` selection a caller can act on: the amount
37
37
  * clears the asset's venue minimum, and `asset` carries the precision and
38
38
  * minimum needed to scale and validate the withdrawal.
39
39
  *
@@ -41,7 +41,8 @@ export interface ProviderWithdrawableBalance {
41
41
  */
42
42
  export interface WithdrawableBalance {
43
43
  asset: Asset;
44
- route: WithdrawalRoute;
44
+ /** The provider category the row draws from; the same value as `Balance.categoryId`. */
45
+ categoryId: string;
45
46
  /** Withdrawable amount in the asset's own units. */
46
47
  available: DecimalString;
47
48
  /**
@@ -68,6 +69,30 @@ export interface WithdrawableBalance {
68
69
  */
69
70
  isFeeDeducted?: boolean;
70
71
  }
72
+ /**
73
+ * One way a venue can settle a withdrawal from a holding.
74
+ *
75
+ * @public
76
+ */
77
+ export interface WithdrawalTypeOption {
78
+ type: WithdrawalType;
79
+ /** Largest `amount` this type accepts from the holding, in the asset's own units. */
80
+ max: DecimalString;
81
+ /**
82
+ * Provider-specific options to pass unchanged as
83
+ * `WithdrawalParams.withdrawalOptions` when the user picks this type.
84
+ */
85
+ withdrawalOptions: Record<string, unknown>;
86
+ }
87
+ /**
88
+ * The withdrawal types a venue offers for one holding.
89
+ *
90
+ * @public
91
+ */
92
+ export interface WithdrawalSourceTypes {
93
+ source: WithdrawalAssetRef;
94
+ options: WithdrawalTypeOption[];
95
+ }
71
96
  /**
72
97
  * The venue accepts a withdrawal to `destination` now.
73
98
  *
@@ -1 +1 @@
1
- {"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,KAAK,EACL,aAAa,EACb,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,GAAG,EAAE,aAAa,CAAA;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,oDAAoD;IACpD,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,GAAG,EAAE,aAAa,CAAA;IAClB;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,eAAe,CAAA;IACrB,qEAAqE;IACrE,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,yBAAyB,CAAA"}
1
+ {"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,KAAK,EACL,aAAa,EACb,kBAAkB,EAClB,cAAc,EACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,wFAAwF;IACxF,UAAU,EAAE,MAAM,CAAA;IAClB,8EAA8E;IAC9E,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,GAAG,EAAE,aAAa,CAAA;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,wFAAwF;IACxF,UAAU,EAAE,MAAM,CAAA;IAClB,oDAAoD;IACpD,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,GAAG,EAAE,aAAa,CAAA;IAClB;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,cAAc,CAAA;IACpB,qFAAqF;IACrF,GAAG,EAAE,aAAa,CAAA;IAClB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC3C;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,kBAAkB,CAAA;IAC1B,OAAO,EAAE,oBAAoB,EAAE,CAAA;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,eAAe,CAAA;IACrB,qEAAqE;IACrE,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,yBAAyB,CAAA"}
@@ -9,5 +9,5 @@ export declare const name = "@lifi/perps-sdk";
9
9
  *
10
10
  * @public
11
11
  */
12
- export declare const version = "0.0.0-preview-8effdce";
12
+ export declare const version = "0.0.0-preview-e1b82a0";
13
13
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk",
3
- "version": "0.0.0-preview-8effdce",
3
+ "version": "0.0.0-preview-e1b82a0",
4
4
  "description": "LI.FI Perps SDK for perpetuals trading",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "big.js": "^7.0.1",
47
47
  "partysocket": "^1.1.19",
48
48
  "viem": "^2.55.18",
49
- "@lifi/perps-types": "^0.0.0-preview-8effdce"
49
+ "@lifi/perps-types": "^0.0.0-preview-e1b82a0"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
@@ -60,6 +60,7 @@ import type {
60
60
  GetPortfolioHistoryParams,
61
61
  GetSetupParams,
62
62
  GetWithdrawableBalancesParams,
63
+ GetWithdrawalTypesParams,
63
64
  GetWithdrawFlowParams,
64
65
  ModifyOrdersParams,
65
66
  PerpsClientOptions,
@@ -85,7 +86,11 @@ import type {
85
86
  SignActionProgress,
86
87
  SignActionsContext,
87
88
  } from '../types/provider.js'
88
- import type { WithdrawableBalance, WithdrawFlow } from '../types/withdrawal.js'
89
+ import type {
90
+ WithdrawableBalance,
91
+ WithdrawalSourceTypes,
92
+ WithdrawFlow,
93
+ } from '../types/withdrawal.js'
89
94
  import { isUserFacingSetupStep } from '../utils/setupActions.js'
90
95
  import { signTypedDataWithSigner } from '../utils/signTypedData.js'
91
96
  import {
@@ -838,8 +843,9 @@ export class PerpsClient {
838
843
  }
839
844
 
840
845
  /**
841
- * The `(asset, route)` selections `params.address` can actually withdraw at
842
- * `params.provider`. The venue owns how its balances split across routes;
846
+ * The `(asset, category)` selections `params.address` can actually withdraw
847
+ * at `params.provider`. The venue owns how its balances split across
848
+ * categories;
843
849
  * this join adds the core `/assets` metadata — precision, L1 identity and
844
850
  * the per-asset minimum — and drops every row the minimum rules out, plus
845
851
  * any row whose asset the provider's registry does not carry, since without
@@ -893,7 +899,12 @@ export class PerpsClient {
893
899
  }
894
900
  if (row.withdrawalFee === undefined) {
895
901
  return [
896
- { asset, route: row.route, available: row.available, max: row.max },
902
+ {
903
+ asset,
904
+ categoryId: row.categoryId,
905
+ available: row.available,
906
+ max: row.max,
907
+ },
897
908
  ]
898
909
  }
899
910
  if (!isNonNegativeDecimal(row.withdrawalFee)) {
@@ -905,7 +916,7 @@ export class PerpsClient {
905
916
  return [
906
917
  {
907
918
  asset,
908
- route: row.route,
919
+ categoryId: row.categoryId,
909
920
  available: row.available,
910
921
  max: row.max,
911
922
  withdrawalFee: row.withdrawalFee,
@@ -917,6 +928,25 @@ export class PerpsClient {
917
928
  })
918
929
  }
919
930
 
931
+ /**
932
+ * The withdrawal types `params.address` can choose per holding at
933
+ * `params.provider`, each with its cap and the `withdrawalOptions` to pass
934
+ * unchanged in `WithdrawalParams`.
935
+ *
936
+ * @returns `undefined` when the registered plugin declares no withdrawal
937
+ * types read.
938
+ * @throws {PerpsError} When the provider plugin is not registered, or when
939
+ * the plugin read fails.
940
+ * @public
941
+ */
942
+ async getWithdrawalTypes(
943
+ params: GetWithdrawalTypesParams,
944
+ options?: SDKRequestOptions
945
+ ): Promise<WithdrawalSourceTypes[] | undefined> {
946
+ const plugin = this.requireProvider(params.provider)
947
+ return plugin.getWithdrawalTypes?.({ address: params.address }, options)
948
+ }
949
+
920
950
  /**
921
951
  * The account's portfolio value and cumulative PnL over `params.range` at
922
952
  * `params.provider`, read directly from the venue.
@@ -69,10 +69,6 @@ function toFiniteNumber(value: FormatInput): number | null {
69
69
  * the guard digits are chopped: `99.999` at 2dp → `99.99`, `0.29` → `0.29`.
70
70
  */
71
71
  function truncateAbs(abs: number, decimals: number): number {
72
- // `toFixed` emits exponent notation at >= 1e21; every double that large is an integer.
73
- if (Number.isInteger(abs)) {
74
- return abs
75
- }
76
72
  const s = abs.toFixed(Math.min(decimals + FLOAT_GUARD_DIGITS, 100))
77
73
  const dot = s.indexOf('.')
78
74
  const cut = decimals === 0 ? dot : dot + 1 + decimals
@@ -1,9 +1,4 @@
1
- import {
2
- DECIMAL_PATTERN,
3
- type DecimalString,
4
- PerpsErrorCode,
5
- } from '@lifi/perps-types'
6
- import { PerpsError } from '../errors/PerpsError.js'
1
+ import { DECIMAL_PATTERN, type DecimalString } from '@lifi/perps-types'
7
2
 
8
3
  /**
9
4
  * Parse a string to a float, stripping common formatting artefacts.
@@ -63,25 +58,3 @@ export function parseDecimal(
63
58
  export function isDecimalString(value: unknown): value is DecimalString {
64
59
  return typeof value === 'string' && DECIMAL_PATTERN.test(value)
65
60
  }
66
-
67
- /**
68
- * Check a decimal input against the {@link DecimalString} contract, naming
69
- * the field it came from, so a malformed amount fails at the SDK boundary
70
- * instead of inside big.js.
71
- *
72
- * @returns `value`, unchanged.
73
- * @throws {PerpsError} `ValidationError` naming `field`.
74
- * @public
75
- */
76
- export function validateDecimalString(
77
- value: DecimalString,
78
- field: string
79
- ): DecimalString {
80
- if (!isDecimalString(value)) {
81
- throw new PerpsError(
82
- PerpsErrorCode.ValidationError,
83
- `Invalid \`${field}\`: '${value}' is not a decimal string.`
84
- )
85
- }
86
- return value
87
- }
@@ -1,8 +1,21 @@
1
- import type { DecimalString } from '@lifi/perps-types'
1
+ import { type DecimalString, PerpsErrorCode } from '@lifi/perps-types'
2
2
  import Big from 'big.js'
3
- import { validateDecimalString } from './parse.js'
3
+ import { PerpsError } from '../errors/PerpsError.js'
4
+ import { isDecimalString } from './parse.js'
4
5
 
5
- /** Parse a decimal input after {@link validateDecimalString} accepts it. */
6
+ /**
7
+ * Parse a decimal input, naming the field it came from when the
8
+ * value breaks the {@link DecimalString} contract, so a malformed amount
9
+ * fails at the SDK boundary instead of inside big.js.
10
+ *
11
+ * @throws {PerpsError} `ValidationError` naming `field`.
12
+ */
6
13
  export function requireDecimal(value: DecimalString, field: string): Big {
7
- return new Big(validateDecimalString(value, field))
14
+ if (!isDecimalString(value)) {
15
+ throw new PerpsError(
16
+ PerpsErrorCode.ValidationError,
17
+ `Invalid \`${field}\`: '${value}' is not a decimal string.`
18
+ )
19
+ }
20
+ return new Big(value)
8
21
  }
package/src/index.ts CHANGED
@@ -17,7 +17,6 @@ export {
17
17
  } from './client/createPerpsClient.js'
18
18
  export { PerpsClient } from './client/PerpsClient.js'
19
19
  export { requireProvider } from './client/requireProvider.js'
20
- export { isDecimalStringGreaterThan } from './decimal/compare.js'
21
20
  export type { BaseUnitsRounding } from './decimal/convert.js'
22
21
  export {
23
22
  baseUnitsToDecimal,
@@ -34,11 +33,7 @@ export {
34
33
  formatSignedUsd,
35
34
  formatUsd,
36
35
  } from './decimal/format.js'
37
- export {
38
- isDecimalString,
39
- parseDecimal,
40
- validateDecimalString,
41
- } from './decimal/parse.js'
36
+ export { isDecimalString, parseDecimal } from './decimal/parse.js'
42
37
  export { PerpsErrorMessage } from './errors/constants.js'
43
38
  export { PerpsError } from './errors/PerpsError.js'
44
39
  export {
@@ -177,6 +172,7 @@ export type {
177
172
  GetPortfolioHistoryParams,
178
173
  GetSetupParams,
179
174
  GetWithdrawableBalancesParams,
175
+ GetWithdrawalTypesParams,
180
176
  GetWithdrawFlowParams,
181
177
  ModifyOrdersParams,
182
178
  PerpsClientOptions,
@@ -223,6 +219,7 @@ export type {
223
219
  ProviderGetPositionsParams,
224
220
  ProviderGetQuoteParams,
225
221
  ProviderGetWithdrawableBalancesParams,
222
+ ProviderGetWithdrawalTypesParams,
226
223
  ProviderGetWithdrawFlowParams,
227
224
  QuoteListener,
228
225
  SignActionProgress,
@@ -231,7 +228,8 @@ export type {
231
228
  export type {
232
229
  ProviderWithdrawableBalance,
233
230
  WithdrawableBalance,
234
- WithdrawalRoute,
231
+ WithdrawalSourceTypes,
232
+ WithdrawalTypeOption,
235
233
  WithdrawFlow,
236
234
  WithdrawFlowReady,
237
235
  WithdrawFlowSetupRequired,
package/src/types/api.ts CHANGED
@@ -293,6 +293,16 @@ export interface GetWithdrawableBalancesParams {
293
293
  address: Address
294
294
  }
295
295
 
296
+ /**
297
+ * Parameters for {@link PerpsClient.getWithdrawalTypes}.
298
+ *
299
+ * @public
300
+ */
301
+ export interface GetWithdrawalTypesParams {
302
+ provider: string
303
+ address: Address
304
+ }
305
+
296
306
  /**
297
307
  * Parameters for {@link PerpsClient.getPortfolioHistory}.
298
308
  *
@@ -37,7 +37,11 @@ import type {
37
37
  SDKRequestOptions,
38
38
  } from './config.js'
39
39
  import type { DepositFlow } from './deposit.js'
40
- import type { ProviderWithdrawableBalance, WithdrawFlow } from './withdrawal.js'
40
+ import type {
41
+ ProviderWithdrawableBalance,
42
+ WithdrawalSourceTypes,
43
+ WithdrawFlow,
44
+ } from './withdrawal.js'
41
45
 
42
46
  /**
43
47
  * Low-level SDK client: resolved config, the optional end-user wallet, and the
@@ -199,6 +203,15 @@ export interface ProviderGetWithdrawableBalancesParams {
199
203
  address: Address
200
204
  }
201
205
 
206
+ /**
207
+ * Read params for {@link PerpsProviderPlugin.getWithdrawalTypes}.
208
+ *
209
+ * @public
210
+ */
211
+ export interface ProviderGetWithdrawalTypesParams {
212
+ address: Address
213
+ }
214
+
202
215
  /**
203
216
  * Read params for {@link PerpsProvider.getPositions}.
204
217
  *
@@ -434,20 +447,33 @@ export interface PerpsProviderPlugin {
434
447
  ): Promise<WithdrawFlow>
435
448
 
436
449
  /**
437
- * The `(asset, route)` pairs `params.address` currently has something to
450
+ * The `(asset, category)` pairs `params.address` currently has something to
438
451
  * withdraw from, keyed by provider-native asset id. Only the venue knows how
439
- * its balance payload splits across routes, so the split is owned here; the
452
+ * its balance payload splits across categories, so the split is owned here; the
440
453
  * per-asset venue minimum is applied by `PerpsClient.getWithdrawableBalances`,
441
454
  * which holds the core asset registry.
442
455
  *
443
- * Optional: a provider whose withdrawals are not a per-route selection omits
444
- * it, and `PerpsClient.getWithdrawableBalances` then resolves `undefined`.
456
+ * Optional: a provider whose withdrawals are not a per-category selection
457
+ * omits it, and `PerpsClient.getWithdrawableBalances` then resolves
458
+ * `undefined`.
445
459
  */
446
460
  getWithdrawableBalances?(
447
461
  params: ProviderGetWithdrawableBalancesParams,
448
462
  options?: SDKRequestOptions
449
463
  ): Promise<ProviderWithdrawableBalance[]>
450
464
 
465
+ /**
466
+ * The withdrawal types `params.address` can choose per withdrawable holding,
467
+ * each with its cap and the `withdrawalOptions` to send with it.
468
+ *
469
+ * Optional: a provider with one withdrawal type omits it, and
470
+ * `PerpsClient.getWithdrawalTypes` then resolves `undefined`.
471
+ */
472
+ getWithdrawalTypes?(
473
+ params: ProviderGetWithdrawalTypesParams,
474
+ options?: SDKRequestOptions
475
+ ): Promise<WithdrawalSourceTypes[]>
476
+
451
477
  getPositions(
452
478
  params: ProviderGetPositionsParams,
453
479
  options?: SDKRequestOptions
@@ -2,22 +2,22 @@ import type {
2
2
  ActionType,
3
3
  Asset,
4
4
  DecimalString,
5
- WithdrawalRoute,
5
+ WithdrawalAssetRef,
6
+ WithdrawalType,
6
7
  } from '@lifi/perps-types'
7
8
  import type { Address } from 'viem'
8
9
 
9
- export type { WithdrawalRoute }
10
-
11
10
  /**
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.
11
+ * One withdrawable `(asset, category)` selection as the provider reports it,
12
+ * keyed by provider-native asset id and awaiting the core asset-metadata join.
14
13
  *
15
14
  * @public
16
15
  */
17
16
  export interface ProviderWithdrawableBalance {
18
17
  /** Provider-native `Asset.id`; never a display symbol. */
19
18
  assetId: string
20
- route: WithdrawalRoute
19
+ /** The provider category the row draws from; the same value as `Balance.categoryId`. */
20
+ categoryId: string
21
21
  /** Withdrawable amount in the asset's own units. Always greater than zero. */
22
22
  available: DecimalString
23
23
  /**
@@ -41,7 +41,7 @@ export interface ProviderWithdrawableBalance {
41
41
  }
42
42
 
43
43
  /**
44
- * One withdrawable `(asset, route)` selection a caller can act on: the amount
44
+ * One withdrawable `(asset, category)` selection a caller can act on: the amount
45
45
  * clears the asset's venue minimum, and `asset` carries the precision and
46
46
  * minimum needed to scale and validate the withdrawal.
47
47
  *
@@ -49,7 +49,8 @@ export interface ProviderWithdrawableBalance {
49
49
  */
50
50
  export interface WithdrawableBalance {
51
51
  asset: Asset
52
- route: WithdrawalRoute
52
+ /** The provider category the row draws from; the same value as `Balance.categoryId`. */
53
+ categoryId: string
53
54
  /** Withdrawable amount in the asset's own units. */
54
55
  available: DecimalString
55
56
  /**
@@ -77,6 +78,32 @@ export interface WithdrawableBalance {
77
78
  isFeeDeducted?: boolean
78
79
  }
79
80
 
81
+ /**
82
+ * One way a venue can settle a withdrawal from a holding.
83
+ *
84
+ * @public
85
+ */
86
+ export interface WithdrawalTypeOption {
87
+ type: WithdrawalType
88
+ /** Largest `amount` this type accepts from the holding, in the asset's own units. */
89
+ max: DecimalString
90
+ /**
91
+ * Provider-specific options to pass unchanged as
92
+ * `WithdrawalParams.withdrawalOptions` when the user picks this type.
93
+ */
94
+ withdrawalOptions: Record<string, unknown>
95
+ }
96
+
97
+ /**
98
+ * The withdrawal types a venue offers for one holding.
99
+ *
100
+ * @public
101
+ */
102
+ export interface WithdrawalSourceTypes {
103
+ source: WithdrawalAssetRef
104
+ options: WithdrawalTypeOption[]
105
+ }
106
+
80
107
  /**
81
108
  * The venue accepts a withdrawal to `destination` now.
82
109
  *
package/src/version.ts CHANGED
@@ -10,4 +10,4 @@ export const name = '@lifi/perps-sdk'
10
10
  *
11
11
  * @public
12
12
  */
13
- export const version = '0.0.0-preview-8effdce'
13
+ export const version = '0.0.0-preview-e1b82a0'
@@ -1,3 +0,0 @@
1
- import type { DecimalString } from '@lifi/perps-types';
2
- export declare function isDecimalStringGreaterThan(a: DecimalString, b: DecimalString): boolean;
3
- //# sourceMappingURL=compare.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/decimal/compare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAWtD,wBAAgB,0BAA0B,CACxC,CAAC,EAAE,aAAa,EAChB,CAAC,EAAE,aAAa,GACf,OAAO,CAET"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDecimalStringGreaterThan = isDecimalStringGreaterThan;
4
- const requireDecimal_js_1 = require("./requireDecimal.js");
5
- function isDecimalStringGreaterThan(a, b) {
6
- return (0, requireDecimal_js_1.requireDecimal)(a, 'a').gt((0, requireDecimal_js_1.requireDecimal)(b, 'b'));
7
- }
8
- //# sourceMappingURL=compare.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/decimal/compare.ts"],"names":[],"mappings":";;AAWA,gEAKC;AAfD,2DAAoD;AAUpD,SAAgB,0BAA0B,CACxC,CAAgB,EAChB,CAAgB;IAEhB,OAAO,IAAA,kCAAc,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,IAAA,kCAAc,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1D,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { DecimalString } from '@lifi/perps-types';
2
- /**
3
- * Exact `a > b` on two {@link DecimalString}s, with no float rounding, so a
4
- * funds gate can tell `'1.0000000000000001'` from `'1'`. The other relations
5
- * follow from it: `a <= b` is `!isDecimalStringGreaterThan(a, b)`.
6
- *
7
- * @throws {PerpsError} `ValidationError` when either operand is not a decimal string.
8
- * @public
9
- */
10
- export declare function isDecimalStringGreaterThan(a: DecimalString, b: DecimalString): boolean;
11
- //# sourceMappingURL=compare.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/decimal/compare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,CAAC,EAAE,aAAa,EAChB,CAAC,EAAE,aAAa,GACf,OAAO,CAET"}
@@ -1,13 +0,0 @@
1
- import { requireDecimal } from './requireDecimal.js';
2
- /**
3
- * Exact `a > b` on two {@link DecimalString}s, with no float rounding, so a
4
- * funds gate can tell `'1.0000000000000001'` from `'1'`. The other relations
5
- * follow from it: `a <= b` is `!isDecimalStringGreaterThan(a, b)`.
6
- *
7
- * @throws {PerpsError} `ValidationError` when either operand is not a decimal string.
8
- * @public
9
- */
10
- export function isDecimalStringGreaterThan(a, b) {
11
- return requireDecimal(a, 'a').gt(requireDecimal(b, 'b'));
12
- }
13
- //# sourceMappingURL=compare.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/decimal/compare.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,CAAgB,EAChB,CAAgB;IAEhB,OAAO,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1D,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { DecimalString } from '@lifi/perps-types';
2
- /**
3
- * Exact `a > b` on two {@link DecimalString}s, with no float rounding, so a
4
- * funds gate can tell `'1.0000000000000001'` from `'1'`. The other relations
5
- * follow from it: `a <= b` is `!isDecimalStringGreaterThan(a, b)`.
6
- *
7
- * @throws {PerpsError} `ValidationError` when either operand is not a decimal string.
8
- * @public
9
- */
10
- export declare function isDecimalStringGreaterThan(a: DecimalString, b: DecimalString): boolean;
11
- //# sourceMappingURL=compare.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/decimal/compare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,CAAC,EAAE,aAAa,EAChB,CAAC,EAAE,aAAa,GACf,OAAO,CAET"}
@@ -1,17 +0,0 @@
1
- import type { DecimalString } from '@lifi/perps-types'
2
- import { requireDecimal } from './requireDecimal.js'
3
-
4
- /**
5
- * Exact `a > b` on two {@link DecimalString}s, with no float rounding, so a
6
- * funds gate can tell `'1.0000000000000001'` from `'1'`. The other relations
7
- * follow from it: `a <= b` is `!isDecimalStringGreaterThan(a, b)`.
8
- *
9
- * @throws {PerpsError} `ValidationError` when either operand is not a decimal string.
10
- * @public
11
- */
12
- export function isDecimalStringGreaterThan(
13
- a: DecimalString,
14
- b: DecimalString
15
- ): boolean {
16
- return requireDecimal(a, 'a').gt(requireDecimal(b, 'b'))
17
- }