@lifi/perps-sdk 23.1.0 → 25.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -56
- package/dist/cjs/client/PerpsClient.d.ts +3 -2
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +16 -9
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/decimal/arithmetic.d.ts +15 -0
- package/dist/cjs/decimal/arithmetic.d.ts.map +1 -0
- package/dist/cjs/decimal/arithmetic.js +53 -0
- package/dist/cjs/decimal/arithmetic.js.map +1 -0
- package/dist/cjs/decimal/big.d.ts +0 -1
- package/dist/cjs/decimal/big.d.ts.map +1 -1
- package/dist/cjs/decimal/big.js +0 -4
- package/dist/cjs/decimal/big.js.map +1 -1
- package/dist/cjs/decimal/compare.d.ts +6 -2
- package/dist/cjs/decimal/compare.d.ts.map +1 -1
- package/dist/cjs/decimal/compare.js +15 -2
- package/dist/cjs/decimal/compare.js.map +1 -1
- package/dist/cjs/decimal/convert.d.ts +10 -6
- package/dist/cjs/decimal/convert.d.ts.map +1 -1
- package/dist/cjs/decimal/convert.js +34 -21
- package/dist/cjs/decimal/convert.js.map +1 -1
- package/dist/cjs/decimal/decimalStringToBig.d.ts +5 -0
- package/dist/cjs/decimal/decimalStringToBig.d.ts.map +1 -0
- package/dist/cjs/decimal/decimalStringToBig.js +25 -0
- package/dist/cjs/decimal/decimalStringToBig.js.map +1 -0
- package/dist/cjs/decimal/format.d.ts.map +1 -1
- package/dist/cjs/decimal/format.js +70 -52
- package/dist/cjs/decimal/format.js.map +1 -1
- package/dist/cjs/decimal/parse.d.ts +5 -4
- package/dist/cjs/decimal/parse.d.ts.map +1 -1
- package/dist/cjs/decimal/parse.js +43 -25
- package/dist/cjs/decimal/parse.js.map +1 -1
- package/dist/cjs/errors/invalidInput.d.ts +3 -0
- package/dist/cjs/errors/invalidInput.d.ts.map +1 -0
- package/dist/cjs/errors/invalidInput.js +9 -0
- package/dist/cjs/errors/invalidInput.js.map +1 -0
- package/dist/cjs/index.d.ts +15 -12
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +69 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/fills.d.ts +1 -1
- package/dist/cjs/math/fills.d.ts.map +1 -1
- package/dist/cjs/math/fills.js +28 -13
- package/dist/cjs/math/fills.js.map +1 -1
- package/dist/cjs/math/order.d.ts +27 -16
- package/dist/cjs/math/order.d.ts.map +1 -1
- package/dist/cjs/math/order.js +131 -134
- package/dist/cjs/math/order.js.map +1 -1
- package/dist/cjs/math/position.d.ts +85 -35
- package/dist/cjs/math/position.d.ts.map +1 -1
- package/dist/cjs/math/position.js +93 -94
- package/dist/cjs/math/position.js.map +1 -1
- package/dist/cjs/services/getGasRecommendation.js +1 -1
- package/dist/cjs/services/getGasRecommendation.js.map +1 -1
- package/dist/cjs/services/getQuote.d.ts +1 -1
- package/dist/cjs/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/cjs/services/resolveSubscribeQuote.js +3 -2
- package/dist/cjs/services/resolveSubscribeQuote.js.map +1 -1
- package/dist/cjs/transport/request.d.ts +1 -0
- package/dist/cjs/transport/request.d.ts.map +1 -1
- package/dist/cjs/transport/request.js +2 -2
- package/dist/cjs/transport/request.js.map +1 -1
- package/dist/cjs/types/api.d.ts +4 -0
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +9 -5
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +12 -4
- package/dist/cjs/types/withdrawal.d.ts.map +1 -1
- package/dist/cjs/utils/createSafeFunction.d.ts +2 -0
- package/dist/cjs/utils/createSafeFunction.d.ts.map +1 -0
- package/dist/cjs/utils/createSafeFunction.js +15 -0
- package/dist/cjs/utils/createSafeFunction.js.map +1 -0
- package/dist/cjs/utils/timestampToIsoString.d.ts +3 -0
- package/dist/cjs/utils/timestampToIsoString.d.ts.map +1 -0
- package/dist/cjs/utils/timestampToIsoString.js +16 -0
- package/dist/cjs/utils/timestampToIsoString.js.map +1 -0
- package/dist/cjs/utils/warnOnce.d.ts +6 -0
- package/dist/cjs/utils/warnOnce.d.ts.map +1 -1
- package/dist/cjs/utils/warnOnce.js +19 -1
- package/dist/cjs/utils/warnOnce.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/websocket/PerpsWsClient.d.ts +2 -0
- package/dist/cjs/websocket/PerpsWsClient.d.ts.map +1 -1
- package/dist/cjs/websocket/PerpsWsClient.js +14 -1
- package/dist/cjs/websocket/PerpsWsClient.js.map +1 -1
- package/dist/cjs/websocket/wsLog.d.ts +2 -0
- package/dist/cjs/websocket/wsLog.d.ts.map +1 -1
- package/dist/cjs/websocket/wsLog.js +9 -0
- package/dist/cjs/websocket/wsLog.js.map +1 -1
- package/dist/cjs/wire/orderAmounts.d.ts +3 -2
- package/dist/cjs/wire/orderAmounts.d.ts.map +1 -1
- package/dist/cjs/wire/orderAmounts.js +22 -21
- package/dist/cjs/wire/orderAmounts.js.map +1 -1
- package/dist/cjs/wire/refuel.d.ts +4 -1
- package/dist/cjs/wire/refuel.d.ts.map +1 -1
- package/dist/cjs/wire/refuel.js +23 -6
- package/dist/cjs/wire/refuel.js.map +1 -1
- package/dist/cjs/wire/transferable.js +3 -3
- package/dist/cjs/wire/transferable.js.map +1 -1
- package/dist/cjs/wire/withdraw.d.ts.map +1 -1
- package/dist/cjs/wire/withdraw.js +3 -3
- package/dist/cjs/wire/withdraw.js.map +1 -1
- package/dist/esm/client/PerpsClient.d.ts +17 -4
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +30 -8
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/decimal/arithmetic.d.ts +98 -0
- package/dist/esm/decimal/arithmetic.d.ts.map +1 -0
- package/dist/esm/decimal/arithmetic.js +126 -0
- package/dist/esm/decimal/arithmetic.js.map +1 -0
- package/dist/esm/decimal/big.d.ts +0 -2
- package/dist/esm/decimal/big.d.ts.map +1 -1
- package/dist/esm/decimal/big.js +0 -4
- package/dist/esm/decimal/big.js.map +1 -1
- package/dist/esm/decimal/compare.d.ts +40 -6
- package/dist/esm/decimal/compare.d.ts.map +1 -1
- package/dist/esm/decimal/compare.js +46 -6
- package/dist/esm/decimal/compare.js.map +1 -1
- package/dist/esm/decimal/convert.d.ts +50 -36
- package/dist/esm/decimal/convert.d.ts.map +1 -1
- package/dist/esm/decimal/convert.js +64 -42
- package/dist/esm/decimal/convert.js.map +1 -1
- package/dist/esm/decimal/decimalStringToBig.d.ts +25 -0
- package/dist/esm/decimal/decimalStringToBig.d.ts.map +1 -0
- package/dist/esm/decimal/decimalStringToBig.js +37 -0
- package/dist/esm/decimal/decimalStringToBig.js.map +1 -0
- package/dist/esm/decimal/format.d.ts +4 -1
- package/dist/esm/decimal/format.d.ts.map +1 -1
- package/dist/esm/decimal/format.js +71 -70
- package/dist/esm/decimal/format.js.map +1 -1
- package/dist/esm/decimal/parse.d.ts +29 -13
- package/dist/esm/decimal/parse.d.ts.map +1 -1
- package/dist/esm/decimal/parse.js +61 -44
- package/dist/esm/decimal/parse.js.map +1 -1
- package/dist/esm/errors/invalidInput.d.ts +4 -0
- package/dist/esm/errors/invalidInput.d.ts.map +1 -0
- package/dist/esm/errors/invalidInput.js +7 -0
- package/dist/esm/errors/invalidInput.js.map +1 -0
- package/dist/esm/index.d.ts +15 -12
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +11 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/fills.d.ts +6 -3
- package/dist/esm/math/fills.d.ts.map +1 -1
- package/dist/esm/math/fills.js +31 -16
- package/dist/esm/math/fills.js.map +1 -1
- package/dist/esm/math/order.d.ts +84 -66
- package/dist/esm/math/order.d.ts.map +1 -1
- package/dist/esm/math/order.js +178 -175
- package/dist/esm/math/order.js.map +1 -1
- package/dist/esm/math/position.d.ts +155 -98
- package/dist/esm/math/position.d.ts.map +1 -1
- package/dist/esm/math/position.js +160 -156
- package/dist/esm/math/position.js.map +1 -1
- package/dist/esm/services/getGasRecommendation.js +1 -1
- package/dist/esm/services/getGasRecommendation.js.map +1 -1
- package/dist/esm/services/getQuote.d.ts +2 -2
- package/dist/esm/services/getQuote.js +1 -1
- package/dist/esm/services/resolveSubscribeQuote.d.ts +1 -1
- package/dist/esm/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/esm/services/resolveSubscribeQuote.js +4 -3
- package/dist/esm/services/resolveSubscribeQuote.js.map +1 -1
- package/dist/esm/transport/request.d.ts +5 -0
- package/dist/esm/transport/request.d.ts.map +1 -1
- package/dist/esm/transport/request.js +2 -2
- package/dist/esm/transport/request.js.map +1 -1
- package/dist/esm/types/api.d.ts +9 -0
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +30 -16
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +32 -7
- package/dist/esm/types/withdrawal.d.ts.map +1 -1
- package/dist/esm/utils/createSafeFunction.d.ts +9 -0
- package/dist/esm/utils/createSafeFunction.d.ts.map +1 -0
- package/dist/esm/utils/createSafeFunction.js +19 -0
- package/dist/esm/utils/createSafeFunction.js.map +1 -0
- package/dist/esm/utils/timestampToIsoString.d.ts +15 -0
- package/dist/esm/utils/timestampToIsoString.d.ts.map +1 -0
- package/dist/esm/utils/timestampToIsoString.js +24 -0
- package/dist/esm/utils/timestampToIsoString.js.map +1 -0
- package/dist/esm/utils/warnOnce.d.ts +27 -0
- package/dist/esm/utils/warnOnce.d.ts.map +1 -1
- package/dist/esm/utils/warnOnce.js +36 -0
- package/dist/esm/utils/warnOnce.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/websocket/PerpsWsClient.d.ts +7 -0
- package/dist/esm/websocket/PerpsWsClient.d.ts.map +1 -1
- package/dist/esm/websocket/PerpsWsClient.js +20 -2
- package/dist/esm/websocket/PerpsWsClient.js.map +1 -1
- package/dist/esm/websocket/wsLog.d.ts +12 -0
- package/dist/esm/websocket/wsLog.d.ts.map +1 -1
- package/dist/esm/websocket/wsLog.js +19 -0
- package/dist/esm/websocket/wsLog.js.map +1 -1
- package/dist/esm/wire/orderAmounts.d.ts +9 -7
- package/dist/esm/wire/orderAmounts.d.ts.map +1 -1
- package/dist/esm/wire/orderAmounts.js +24 -20
- package/dist/esm/wire/orderAmounts.js.map +1 -1
- package/dist/esm/wire/refuel.d.ts +24 -14
- package/dist/esm/wire/refuel.d.ts.map +1 -1
- package/dist/esm/wire/refuel.js +38 -17
- package/dist/esm/wire/refuel.js.map +1 -1
- package/dist/esm/wire/transferable.d.ts +2 -2
- package/dist/esm/wire/transferable.js +5 -5
- package/dist/esm/wire/transferable.js.map +1 -1
- package/dist/esm/wire/withdraw.d.ts.map +1 -1
- package/dist/esm/wire/withdraw.js +3 -3
- package/dist/esm/wire/withdraw.js.map +1 -1
- package/dist/types/client/PerpsClient.d.ts +17 -4
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/decimal/arithmetic.d.ts +98 -0
- package/dist/types/decimal/arithmetic.d.ts.map +1 -0
- package/dist/types/decimal/big.d.ts +0 -2
- package/dist/types/decimal/big.d.ts.map +1 -1
- package/dist/types/decimal/compare.d.ts +40 -6
- package/dist/types/decimal/compare.d.ts.map +1 -1
- package/dist/types/decimal/convert.d.ts +50 -36
- package/dist/types/decimal/convert.d.ts.map +1 -1
- package/dist/types/decimal/decimalStringToBig.d.ts +25 -0
- package/dist/types/decimal/decimalStringToBig.d.ts.map +1 -0
- package/dist/types/decimal/format.d.ts +4 -1
- package/dist/types/decimal/format.d.ts.map +1 -1
- package/dist/types/decimal/parse.d.ts +29 -13
- package/dist/types/decimal/parse.d.ts.map +1 -1
- package/dist/types/errors/invalidInput.d.ts +4 -0
- package/dist/types/errors/invalidInput.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -12
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/fills.d.ts +6 -3
- package/dist/types/math/fills.d.ts.map +1 -1
- package/dist/types/math/order.d.ts +84 -66
- package/dist/types/math/order.d.ts.map +1 -1
- package/dist/types/math/position.d.ts +155 -98
- package/dist/types/math/position.d.ts.map +1 -1
- package/dist/types/services/getQuote.d.ts +2 -2
- package/dist/types/services/resolveSubscribeQuote.d.ts +1 -1
- package/dist/types/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/types/transport/request.d.ts +5 -0
- package/dist/types/transport/request.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +9 -0
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +30 -16
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +32 -7
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/utils/createSafeFunction.d.ts +9 -0
- package/dist/types/utils/createSafeFunction.d.ts.map +1 -0
- package/dist/types/utils/timestampToIsoString.d.ts +15 -0
- package/dist/types/utils/timestampToIsoString.d.ts.map +1 -0
- package/dist/types/utils/warnOnce.d.ts +27 -0
- package/dist/types/utils/warnOnce.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/websocket/PerpsWsClient.d.ts +7 -0
- package/dist/types/websocket/PerpsWsClient.d.ts.map +1 -1
- package/dist/types/websocket/wsLog.d.ts +12 -0
- package/dist/types/websocket/wsLog.d.ts.map +1 -1
- package/dist/types/wire/orderAmounts.d.ts +9 -7
- package/dist/types/wire/orderAmounts.d.ts.map +1 -1
- package/dist/types/wire/refuel.d.ts +24 -14
- package/dist/types/wire/refuel.d.ts.map +1 -1
- package/dist/types/wire/transferable.d.ts +2 -2
- package/dist/types/wire/withdraw.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +48 -10
- package/src/decimal/arithmetic.ts +170 -0
- package/src/decimal/big.ts +0 -5
- package/src/decimal/compare.ts +61 -11
- package/src/decimal/convert.ts +105 -63
- package/src/decimal/decimalStringToBig.ts +42 -0
- package/src/decimal/format.ts +81 -72
- package/src/decimal/parse.ts +78 -57
- package/src/errors/invalidInput.ts +10 -0
- package/src/index.ts +80 -12
- package/src/math/fills.ts +32 -17
- package/src/math/order.ts +279 -226
- package/src/math/position.ts +280 -196
- package/src/services/getGasRecommendation.ts +1 -1
- package/src/services/getQuote.ts +2 -2
- package/src/services/resolveSubscribeQuote.ts +4 -3
- package/src/transport/request.ts +7 -2
- package/src/types/api.ts +10 -0
- package/src/types/provider.ts +39 -16
- package/src/types/withdrawal.ts +35 -8
- package/src/utils/createSafeFunction.ts +20 -0
- package/src/utils/timestampToIsoString.ts +31 -0
- package/src/utils/warnOnce.ts +60 -0
- package/src/version.ts +1 -1
- package/src/websocket/PerpsWsClient.ts +25 -2
- package/src/websocket/wsLog.ts +44 -0
- package/src/wire/orderAmounts.ts +45 -26
- package/src/wire/refuel.ts +56 -20
- package/src/wire/transferable.ts +5 -5
- package/src/wire/withdraw.ts +3 -5
- package/dist/cjs/decimal/requireDecimal.d.ts +0 -4
- package/dist/cjs/decimal/requireDecimal.d.ts.map +0 -1
- package/dist/cjs/decimal/requireDecimal.js +0 -12
- package/dist/cjs/decimal/requireDecimal.js.map +0 -1
- package/dist/esm/decimal/requireDecimal.d.ts +0 -5
- package/dist/esm/decimal/requireDecimal.d.ts.map +0 -1
- package/dist/esm/decimal/requireDecimal.js +0 -7
- package/dist/esm/decimal/requireDecimal.js.map +0 -1
- package/dist/types/decimal/requireDecimal.d.ts +0 -5
- package/dist/types/decimal/requireDecimal.d.ts.map +0 -1
- package/src/decimal/requireDecimal.ts +0 -8
package/src/decimal/format.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { DecimalString } from '@lifi/perps-types'
|
|
2
|
+
import Big from 'big.js'
|
|
3
|
+
import { decimalStringToBig } from './decimalStringToBig.js'
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Options shared by the human-facing display formatters.
|
|
@@ -8,7 +10,10 @@ import type { DecimalString } from '@lifi/perps-types'
|
|
|
8
10
|
export interface FormatOptions {
|
|
9
11
|
/** Fixed number of decimal places. Defaults are per-formatter. */
|
|
10
12
|
decimals?: number
|
|
11
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Rendered when the value is null, undefined, blank or a non-finite number.
|
|
15
|
+
* A string that is not a decimal is shown unchanged. Defaults to `'—'`.
|
|
16
|
+
*/
|
|
12
17
|
placeholder?: string
|
|
13
18
|
/** BCP 47 locale controlling digit grouping and separators (e.g. `'en-US'`). */
|
|
14
19
|
locale?: string
|
|
@@ -33,76 +38,62 @@ const DEFAULT_PLACEHOLDER = '—'
|
|
|
33
38
|
type FormatInput = number | DecimalString | string | null | undefined
|
|
34
39
|
|
|
35
40
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
const FLOAT_GUARD_DIGITS = 9
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Tolerantly coerce a display input to a finite number.
|
|
44
|
-
*
|
|
45
|
-
* Strips `$`, `,`, and surrounding whitespace from strings. Returns `null`
|
|
46
|
-
* when the value is null/undefined/blank or does not resolve to a finite
|
|
47
|
-
* number, so callers can render a placeholder instead of `$0.00` or `$NaN`.
|
|
41
|
+
* Read a display input as a `Big`. `null` means the formatter renders the
|
|
42
|
+
* placeholder; a string that does not match the decimal pattern is returned
|
|
43
|
+
* unchanged for display.
|
|
48
44
|
*/
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return null
|
|
55
|
-
}
|
|
56
|
-
n = Number(cleaned)
|
|
57
|
-
} else if (typeof value === 'number') {
|
|
58
|
-
n = value
|
|
59
|
-
} else {
|
|
45
|
+
function toBig(value: FormatInput): Big | null | string {
|
|
46
|
+
if (typeof value === 'number') {
|
|
47
|
+
return Number.isFinite(value) ? new Big(value) : null
|
|
48
|
+
}
|
|
49
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
60
50
|
return null
|
|
61
51
|
}
|
|
62
|
-
|
|
52
|
+
try {
|
|
53
|
+
return decimalStringToBig(value)
|
|
54
|
+
} catch {
|
|
55
|
+
return value
|
|
56
|
+
}
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
const s = abs.toFixed(Math.min(decimals + FLOAT_GUARD_DIGITS, 100))
|
|
77
|
-
const dot = s.indexOf('.')
|
|
78
|
-
const cut = decimals === 0 ? dot : dot + 1 + decimals
|
|
79
|
-
return Number(s.slice(0, cut))
|
|
59
|
+
function decimalSeparator(locale: string | undefined): string {
|
|
60
|
+
return (
|
|
61
|
+
new Intl.NumberFormat(locale)
|
|
62
|
+
.formatToParts(1.5)
|
|
63
|
+
.find((part) => part.type === 'decimal')?.value ?? '.'
|
|
64
|
+
)
|
|
80
65
|
}
|
|
81
66
|
|
|
82
67
|
/**
|
|
83
|
-
* Reduce `
|
|
68
|
+
* Reduce `value` to `decimals` places then split into a sign and the
|
|
84
69
|
* locale-formatted absolute body. The sign is derived from the reduced value
|
|
85
70
|
* so magnitudes that collapse to zero render without a spurious `-`/`+`.
|
|
86
71
|
* `signed` emits `+` for positives; `rounding` selects half-up or truncation.
|
|
87
72
|
*/
|
|
88
73
|
function signAndBody(
|
|
89
|
-
|
|
74
|
+
value: Big,
|
|
90
75
|
decimals: number,
|
|
91
76
|
locale: string | undefined,
|
|
92
77
|
grouping: boolean,
|
|
93
78
|
rounding: RoundingMode,
|
|
94
79
|
signed: boolean
|
|
95
80
|
): { sign: '+' | '-' | ''; body: string } {
|
|
96
|
-
const reduced =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const sign = reduced
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
81
|
+
const reduced = value.round(
|
|
82
|
+
decimals,
|
|
83
|
+
rounding === 'floor' ? Big.roundDown : Big.roundHalfUp
|
|
84
|
+
)
|
|
85
|
+
const sign = reduced.lt(0) ? '-' : signed && reduced.gt(0) ? '+' : ''
|
|
86
|
+
const [integerPart = '0', fractionPart] = reduced
|
|
87
|
+
.abs()
|
|
88
|
+
.toFixed(decimals)
|
|
89
|
+
.split('.')
|
|
90
|
+
const integerBody = grouping
|
|
91
|
+
? BigInt(integerPart).toLocaleString(locale)
|
|
92
|
+
: integerPart
|
|
93
|
+
const body =
|
|
94
|
+
fractionPart === undefined
|
|
95
|
+
? integerBody
|
|
96
|
+
: `${integerBody}${decimalSeparator(locale)}${fractionPart}`
|
|
106
97
|
return { sign, body }
|
|
107
98
|
}
|
|
108
99
|
|
|
@@ -110,14 +101,14 @@ function signAndBody(
|
|
|
110
101
|
* Auto-detect a sensible number of decimal places from a value's magnitude:
|
|
111
102
|
* `>=1` → 2, `>=0.1` → 4, `>=0.01` → 5, otherwise 6.
|
|
112
103
|
*/
|
|
113
|
-
function autoDecimals(abs:
|
|
114
|
-
if (abs
|
|
104
|
+
function autoDecimals(abs: Big): number {
|
|
105
|
+
if (abs.gte(1)) {
|
|
115
106
|
return 2
|
|
116
107
|
}
|
|
117
|
-
if (abs
|
|
108
|
+
if (abs.gte('0.1')) {
|
|
118
109
|
return 4
|
|
119
110
|
}
|
|
120
|
-
if (abs
|
|
111
|
+
if (abs.gte('0.01')) {
|
|
121
112
|
return 5
|
|
122
113
|
}
|
|
123
114
|
return 6
|
|
@@ -145,10 +136,13 @@ export function formatNumber(
|
|
|
145
136
|
locale,
|
|
146
137
|
rounding = 'halfUp',
|
|
147
138
|
} = options
|
|
148
|
-
const n =
|
|
139
|
+
const n = toBig(value)
|
|
149
140
|
if (n === null) {
|
|
150
141
|
return placeholder
|
|
151
142
|
}
|
|
143
|
+
if (typeof n === 'string') {
|
|
144
|
+
return n
|
|
145
|
+
}
|
|
152
146
|
const { sign, body } = signAndBody(n, decimals, locale, true, rounding, false)
|
|
153
147
|
return `${sign}${body}`
|
|
154
148
|
}
|
|
@@ -171,10 +165,13 @@ export function formatUsd(
|
|
|
171
165
|
locale,
|
|
172
166
|
rounding = 'halfUp',
|
|
173
167
|
} = options
|
|
174
|
-
const n =
|
|
168
|
+
const n = toBig(value)
|
|
175
169
|
if (n === null) {
|
|
176
170
|
return placeholder
|
|
177
171
|
}
|
|
172
|
+
if (typeof n === 'string') {
|
|
173
|
+
return n
|
|
174
|
+
}
|
|
178
175
|
const { sign, body } = signAndBody(n, decimals, locale, true, rounding, false)
|
|
179
176
|
return `${sign}$${body}`
|
|
180
177
|
}
|
|
@@ -198,10 +195,13 @@ export function formatSignedUsd(
|
|
|
198
195
|
locale,
|
|
199
196
|
rounding = 'halfUp',
|
|
200
197
|
} = options
|
|
201
|
-
const n =
|
|
198
|
+
const n = toBig(value)
|
|
202
199
|
if (n === null) {
|
|
203
200
|
return placeholder
|
|
204
201
|
}
|
|
202
|
+
if (typeof n === 'string') {
|
|
203
|
+
return n
|
|
204
|
+
}
|
|
205
205
|
const { sign, body } = signAndBody(n, decimals, locale, true, rounding, true)
|
|
206
206
|
return `${sign}$${body}`
|
|
207
207
|
}
|
|
@@ -225,10 +225,13 @@ export function formatSignedPercent(
|
|
|
225
225
|
locale,
|
|
226
226
|
rounding = 'halfUp',
|
|
227
227
|
} = options
|
|
228
|
-
const n =
|
|
228
|
+
const n = toBig(value)
|
|
229
229
|
if (n === null) {
|
|
230
230
|
return placeholder
|
|
231
231
|
}
|
|
232
|
+
if (typeof n === 'string') {
|
|
233
|
+
return n
|
|
234
|
+
}
|
|
232
235
|
const { sign, body } = signAndBody(n, decimals, locale, false, rounding, true)
|
|
233
236
|
return `${sign}${body}%`
|
|
234
237
|
}
|
|
@@ -252,17 +255,20 @@ export function formatPrice(
|
|
|
252
255
|
locale,
|
|
253
256
|
rounding = 'halfUp',
|
|
254
257
|
} = options
|
|
255
|
-
const n =
|
|
258
|
+
const n = toBig(value)
|
|
256
259
|
if (n === null) {
|
|
257
260
|
return placeholder
|
|
258
261
|
}
|
|
259
|
-
|
|
262
|
+
if (typeof n === 'string') {
|
|
263
|
+
return n
|
|
264
|
+
}
|
|
265
|
+
const abs = n.abs()
|
|
260
266
|
const decimals = options.decimals ?? autoDecimals(abs)
|
|
261
267
|
const { sign, body } = signAndBody(
|
|
262
268
|
n,
|
|
263
269
|
decimals,
|
|
264
270
|
locale,
|
|
265
|
-
abs
|
|
271
|
+
abs.gte(1000),
|
|
266
272
|
rounding,
|
|
267
273
|
false
|
|
268
274
|
)
|
|
@@ -283,20 +289,23 @@ export function formatCompactUsd(
|
|
|
283
289
|
options: FormatOptions = {}
|
|
284
290
|
): string {
|
|
285
291
|
const { decimals = 2, placeholder = DEFAULT_PLACEHOLDER } = options
|
|
286
|
-
const n =
|
|
292
|
+
const n = toBig(value)
|
|
287
293
|
if (n === null) {
|
|
288
294
|
return placeholder
|
|
289
295
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
296
|
+
if (typeof n === 'string') {
|
|
297
|
+
return n
|
|
298
|
+
}
|
|
299
|
+
const sign = n.lt(0) ? '-' : ''
|
|
300
|
+
const abs = n.abs()
|
|
301
|
+
if (abs.gte(1_000_000_000)) {
|
|
302
|
+
return `${sign}$${abs.div(1_000_000_000).toFixed(decimals)}B`
|
|
294
303
|
}
|
|
295
|
-
if (abs
|
|
296
|
-
return `${sign}$${(
|
|
304
|
+
if (abs.gte(1_000_000)) {
|
|
305
|
+
return `${sign}$${abs.div(1_000_000).toFixed(decimals)}M`
|
|
297
306
|
}
|
|
298
|
-
if (abs
|
|
299
|
-
return `${sign}$${(
|
|
307
|
+
if (abs.gte(1_000)) {
|
|
308
|
+
return `${sign}$${abs.div(1_000).toFixed(decimals)}K`
|
|
300
309
|
}
|
|
301
310
|
return `${sign}$${abs.toFixed(decimals)}`
|
|
302
311
|
}
|
package/src/decimal/parse.ts
CHANGED
|
@@ -1,87 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type DecimalString,
|
|
4
|
-
PerpsErrorCode,
|
|
5
|
-
} from '@lifi/perps-types'
|
|
1
|
+
import { DECIMAL_PATTERN, PerpsErrorCode } from '@lifi/perps-types'
|
|
2
|
+
import Big from 'big.js'
|
|
6
3
|
import { PerpsError } from '../errors/PerpsError.js'
|
|
4
|
+
import { createSafeFunction } from '../utils/createSafeFunction.js'
|
|
5
|
+
import { decimalStringToBig } from './decimalStringToBig.js'
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
8
|
+
* Read a decimal string as a JS float, for a chart or pixel value only. A
|
|
9
|
+
* float holds about 15 significant digits, so the result can lose precision;
|
|
10
|
+
* never use it for an amount sent to a venue.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - Thousands separators (commas)
|
|
15
|
-
* - Percentage suffixes (%)
|
|
16
|
-
* - Whitespace
|
|
17
|
-
*
|
|
18
|
-
* @returns Parsed number; `0` for empty/blank input, `NaN` when a non-empty
|
|
19
|
-
* string contains no parseable number
|
|
12
|
+
* @throws {PerpsError} `ValidationError` when `value` does not match the decimal pattern
|
|
13
|
+
* or is too large for a finite float.
|
|
14
|
+
* @public
|
|
20
15
|
*/
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
export function decimalStringToNumber(value: string): number {
|
|
17
|
+
const parsed = decimalStringToBig(value).toNumber()
|
|
18
|
+
if (!Number.isFinite(parsed)) {
|
|
19
|
+
throw new PerpsError(
|
|
20
|
+
PerpsErrorCode.ValidationError,
|
|
21
|
+
`'${value}' is too large for a finite number.`
|
|
22
|
+
)
|
|
28
23
|
}
|
|
29
|
-
return
|
|
24
|
+
return parsed
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
/**
|
|
28
|
+
* {@link decimalStringToNumber}, or `undefined` with a warning when it throws.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export const safeDecimalStringToNumber = createSafeFunction(
|
|
33
|
+
'decimalStringToNumber',
|
|
34
|
+
decimalStringToNumber
|
|
35
|
+
)
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Gives back `undefined` for a missing, malformed or non-finite value, and `0` for an empty string.
|
|
38
|
+
* Narrows an unknown value to a {@link DecimalString}. No characters are
|
|
39
|
+
* removed first.
|
|
39
40
|
*
|
|
40
41
|
* @public
|
|
41
42
|
*/
|
|
42
|
-
export function
|
|
43
|
-
value
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
export function isDecimalString(value: unknown): value is string {
|
|
44
|
+
return typeof value === 'string' && DECIMAL_PATTERN.test(value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const MAX_SPELLED_EXPONENT = 1000
|
|
48
|
+
|
|
49
|
+
function spellDecimal(value: unknown): string | undefined {
|
|
50
|
+
if (isDecimalString(value)) {
|
|
51
|
+
return value
|
|
52
|
+
}
|
|
53
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === 'number' && !Number.isFinite(value)) {
|
|
46
57
|
return undefined
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
let parsed: Big
|
|
60
|
+
try {
|
|
61
|
+
parsed = new Big(value)
|
|
62
|
+
} catch {
|
|
63
|
+
return undefined
|
|
50
64
|
}
|
|
51
|
-
|
|
65
|
+
// Spelling out an unbounded exponent builds a string of that many digits.
|
|
66
|
+
if (Math.abs(parsed.e) > MAX_SPELLED_EXPONENT) {
|
|
52
67
|
return undefined
|
|
53
68
|
}
|
|
54
|
-
|
|
55
|
-
return Number.isFinite(parsed) ? parsed : undefined
|
|
69
|
+
return (parsed.eq(0) ? new Big(0) : parsed).toFixed()
|
|
56
70
|
}
|
|
57
71
|
|
|
58
72
|
/**
|
|
59
|
-
*
|
|
73
|
+
* Read a venue value (a string or a number) as a decimal string, for a
|
|
74
|
+
* money-path value that must not go on wrong. A number or an exponent string
|
|
75
|
+
* is spelled out in full; no `$`, `%` or `,` is removed.
|
|
60
76
|
*
|
|
77
|
+
* @param tool - Provider key set on the error.
|
|
78
|
+
* @throws {PerpsError} `SDKError` naming `field` when `value` is not a finite
|
|
79
|
+
* decimal.
|
|
61
80
|
* @public
|
|
62
81
|
*/
|
|
63
|
-
export function
|
|
64
|
-
|
|
82
|
+
export function unknownToDecimalString(
|
|
83
|
+
value: unknown,
|
|
84
|
+
field: string,
|
|
85
|
+
tool: string
|
|
86
|
+
): string {
|
|
87
|
+
const decimal = spellDecimal(value)
|
|
88
|
+
if (decimal !== undefined) {
|
|
89
|
+
return decimal
|
|
90
|
+
}
|
|
91
|
+
const error = new PerpsError(
|
|
92
|
+
PerpsErrorCode.SDKError,
|
|
93
|
+
`${tool} field \`${field}\` is not a valid decimal: '${String(value)}'`
|
|
94
|
+
)
|
|
95
|
+
error.tool = tool
|
|
96
|
+
throw error
|
|
65
97
|
}
|
|
66
98
|
|
|
67
99
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* instead of inside big.js.
|
|
100
|
+
* The safe pair of {@link unknownToDecimalString}: `undefined` and a warning
|
|
101
|
+
* in place of a throw.
|
|
71
102
|
*
|
|
72
|
-
* @returns `value`, unchanged.
|
|
73
|
-
* @throws {PerpsError} `ValidationError` naming `field`.
|
|
74
103
|
* @public
|
|
75
104
|
*/
|
|
76
|
-
export
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
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
|
-
}
|
|
105
|
+
export const safeUnknownToDecimalString = createSafeFunction(
|
|
106
|
+
'unknownToDecimalString',
|
|
107
|
+
unknownToDecimalString
|
|
108
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PerpsErrorCode } from '@lifi/perps-types'
|
|
2
|
+
import { PerpsError } from './PerpsError.js'
|
|
3
|
+
|
|
4
|
+
/** A `ValidationError` that names the input parameter and the rule it breaks. */
|
|
5
|
+
export function invalidInput(parameter: string, rule: string): PerpsError {
|
|
6
|
+
return new PerpsError(
|
|
7
|
+
PerpsErrorCode.ValidationError,
|
|
8
|
+
`\`${parameter}\` ${rule}.`
|
|
9
|
+
)
|
|
10
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -17,13 +17,40 @@ 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
|
-
export type { BaseUnitsRounding } from './decimal/convert.js'
|
|
22
20
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
absDecimalString,
|
|
22
|
+
addDecimalString,
|
|
23
|
+
addDecimalStrings,
|
|
24
|
+
divideDecimalString,
|
|
25
|
+
divideDecimalStringRoundDown,
|
|
26
|
+
multiplyDecimalString,
|
|
27
|
+
safeAbsDecimalString,
|
|
28
|
+
safeAddDecimalString,
|
|
29
|
+
safeAddDecimalStrings,
|
|
30
|
+
safeDivideDecimalString,
|
|
31
|
+
safeDivideDecimalStringRoundDown,
|
|
32
|
+
safeMultiplyDecimalString,
|
|
33
|
+
safeSubtractDecimalString,
|
|
34
|
+
subtractDecimalString,
|
|
35
|
+
} from './decimal/arithmetic.js'
|
|
36
|
+
export {
|
|
37
|
+
compareDecimalStrings,
|
|
38
|
+
isDecimalStringGreaterThan,
|
|
39
|
+
isDecimalStringZero,
|
|
40
|
+
safeCompareDecimalStrings,
|
|
41
|
+
safeIsDecimalStringGreaterThan,
|
|
42
|
+
safeIsDecimalStringZero,
|
|
43
|
+
} from './decimal/compare.js'
|
|
44
|
+
export type { DecimalRounding } from './decimal/convert.js'
|
|
45
|
+
export {
|
|
46
|
+
decimalStringToScaledInteger,
|
|
25
47
|
numberToDecimalString,
|
|
26
|
-
|
|
48
|
+
roundDecimalString,
|
|
49
|
+
safeDecimalStringToScaledInteger,
|
|
50
|
+
safeNumberToDecimalString,
|
|
51
|
+
safeRoundDecimalString,
|
|
52
|
+
safeScaledIntegerToDecimalString,
|
|
53
|
+
scaledIntegerToDecimalString,
|
|
27
54
|
} from './decimal/convert.js'
|
|
28
55
|
export type { FormatOptions, RoundingMode } from './decimal/format.js'
|
|
29
56
|
export {
|
|
@@ -35,9 +62,11 @@ export {
|
|
|
35
62
|
formatUsd,
|
|
36
63
|
} from './decimal/format.js'
|
|
37
64
|
export {
|
|
65
|
+
decimalStringToNumber,
|
|
38
66
|
isDecimalString,
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
safeDecimalStringToNumber,
|
|
68
|
+
safeUnknownToDecimalString,
|
|
69
|
+
unknownToDecimalString,
|
|
41
70
|
} from './decimal/parse.js'
|
|
42
71
|
export { PerpsErrorMessage } from './errors/constants.js'
|
|
43
72
|
export { PerpsError } from './errors/PerpsError.js'
|
|
@@ -48,7 +77,7 @@ export {
|
|
|
48
77
|
} from './math/fills.js'
|
|
49
78
|
export type { ExpectedPnl } from './math/order.js'
|
|
50
79
|
export {
|
|
51
|
-
|
|
80
|
+
applySlippageToPrice,
|
|
52
81
|
buildQuote,
|
|
53
82
|
calculateExpectedPnl,
|
|
54
83
|
calculateRealizedPnlPercent,
|
|
@@ -59,6 +88,17 @@ export {
|
|
|
59
88
|
estimateRealizedPnl,
|
|
60
89
|
findMatchingPosition,
|
|
61
90
|
resolveCloseSize,
|
|
91
|
+
safeApplySlippageToPrice,
|
|
92
|
+
safeBuildQuote,
|
|
93
|
+
safeCalculateExpectedPnl,
|
|
94
|
+
safeCalculateRealizedPnlPercent,
|
|
95
|
+
safeCalculateSize,
|
|
96
|
+
safeCalculateTriggerPercent,
|
|
97
|
+
safeCalculateTriggerPrice,
|
|
98
|
+
safeEstimateFees,
|
|
99
|
+
safeEstimateRealizedPnl,
|
|
100
|
+
safeResolveCloseSize,
|
|
101
|
+
safeWalkOrderbook,
|
|
62
102
|
walkOrderbook,
|
|
63
103
|
} from './math/order.js'
|
|
64
104
|
export {
|
|
@@ -71,10 +111,24 @@ export {
|
|
|
71
111
|
calculateUnrealizedPnl,
|
|
72
112
|
estimateAverageEntryPrice,
|
|
73
113
|
estimateLiquidationPrice,
|
|
114
|
+
estimateLiquidationPriceAtMarketRate,
|
|
74
115
|
estimateNewLeverage,
|
|
75
116
|
estimateUnrealizedPnl,
|
|
76
117
|
positionSupportsMarginAdjustment,
|
|
77
118
|
positionSupportsMarginRemoval,
|
|
119
|
+
safeCalculateEffectiveLeverage,
|
|
120
|
+
safeCalculateLiquidationDistance,
|
|
121
|
+
safeCalculateNotionalValue,
|
|
122
|
+
safeCalculateRealizedPnl,
|
|
123
|
+
safeCalculateRequiredMargin,
|
|
124
|
+
safeCalculateRoe,
|
|
125
|
+
safeCalculateUnrealizedPnl,
|
|
126
|
+
safeEstimateAverageEntryPrice,
|
|
127
|
+
safeEstimateLiquidationPrice,
|
|
128
|
+
safeEstimateLiquidationPriceAtMarketRate,
|
|
129
|
+
safeEstimateNewLeverage,
|
|
130
|
+
safeEstimateUnrealizedPnl,
|
|
131
|
+
safeWouldImmediatelyLiquidate,
|
|
78
132
|
wouldImmediatelyLiquidate,
|
|
79
133
|
} from './math/position.js'
|
|
80
134
|
// Registries
|
|
@@ -177,6 +231,7 @@ export type {
|
|
|
177
231
|
GetPortfolioHistoryParams,
|
|
178
232
|
GetSetupParams,
|
|
179
233
|
GetWithdrawableBalancesParams,
|
|
234
|
+
GetWithdrawalTypesParams,
|
|
180
235
|
GetWithdrawFlowParams,
|
|
181
236
|
ModifyOrdersParams,
|
|
182
237
|
PerpsClientOptions,
|
|
@@ -223,6 +278,7 @@ export type {
|
|
|
223
278
|
ProviderGetPositionsParams,
|
|
224
279
|
ProviderGetQuoteParams,
|
|
225
280
|
ProviderGetWithdrawableBalancesParams,
|
|
281
|
+
ProviderGetWithdrawalTypesParams,
|
|
226
282
|
ProviderGetWithdrawFlowParams,
|
|
227
283
|
QuoteListener,
|
|
228
284
|
SignActionProgress,
|
|
@@ -231,12 +287,14 @@ export type {
|
|
|
231
287
|
export type {
|
|
232
288
|
ProviderWithdrawableBalance,
|
|
233
289
|
WithdrawableBalance,
|
|
234
|
-
|
|
290
|
+
WithdrawalSourceTypes,
|
|
291
|
+
WithdrawalTypeOption,
|
|
235
292
|
WithdrawFlow,
|
|
236
293
|
WithdrawFlowReady,
|
|
237
294
|
WithdrawFlowSetupRequired,
|
|
238
295
|
} from './types/withdrawal.js'
|
|
239
296
|
export { paginateActivity } from './utils/activityPaging.js'
|
|
297
|
+
export { createSafeFunction } from './utils/createSafeFunction.js'
|
|
240
298
|
export {
|
|
241
299
|
ETHEREUM_NATIVE_GAS,
|
|
242
300
|
ETHEREUM_USDC,
|
|
@@ -269,7 +327,11 @@ export {
|
|
|
269
327
|
signTypedData,
|
|
270
328
|
signTypedDataWithSigner,
|
|
271
329
|
} from './utils/signTypedData.js'
|
|
272
|
-
export {
|
|
330
|
+
export {
|
|
331
|
+
safeTimestampToIsoString,
|
|
332
|
+
timestampToIsoString,
|
|
333
|
+
} from './utils/timestampToIsoString.js'
|
|
334
|
+
export { createWarnOnce, warnSkippedVenueRow } from './utils/warnOnce.js'
|
|
273
335
|
// Version
|
|
274
336
|
export { name, version } from './version.js'
|
|
275
337
|
export { cachePromise } from './websocket/cachePromise.js'
|
|
@@ -299,9 +361,15 @@ export type {
|
|
|
299
361
|
OrderAmounts,
|
|
300
362
|
OrderAmountsInput,
|
|
301
363
|
} from './wire/orderAmounts.js'
|
|
302
|
-
export {
|
|
364
|
+
export {
|
|
365
|
+
calculateOrderAmounts,
|
|
366
|
+
safeCalculateOrderAmounts,
|
|
367
|
+
} from './wire/orderAmounts.js'
|
|
303
368
|
export type { RefuelAmountInput } from './wire/refuel.js'
|
|
304
|
-
export {
|
|
369
|
+
export {
|
|
370
|
+
calculateRefuelAmount,
|
|
371
|
+
REFUEL_FEE_MARGIN_PERCENT,
|
|
372
|
+
} from './wire/refuel.js'
|
|
305
373
|
export { snapOrderPrice, snapOrderSize } from './wire/snap.js'
|
|
306
374
|
export { calculateTransferable } from './wire/transferable.js'
|
|
307
375
|
export { calculateWithdrawMax } from './wire/withdraw.js'
|