@lifi/perps-sdk 20.1.0 → 21.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 +81 -6
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +4 -1
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
- package/dist/cjs/decimal/big.d.ts.map +1 -0
- package/dist/cjs/{utils/decimal.js → decimal/big.js} +1 -1
- package/dist/cjs/decimal/big.js.map +1 -0
- package/dist/cjs/decimal/convert.d.ts +11 -0
- package/dist/cjs/decimal/convert.d.ts.map +1 -0
- package/dist/cjs/decimal/convert.js +70 -0
- package/dist/cjs/decimal/convert.js.map +1 -0
- package/dist/cjs/decimal/format.d.ts.map +1 -0
- package/dist/cjs/decimal/format.js.map +1 -0
- package/dist/cjs/decimal/parse.d.ts +6 -0
- package/dist/cjs/decimal/parse.d.ts.map +1 -0
- package/dist/cjs/{utils → decimal}/parse.js +5 -4
- package/dist/cjs/decimal/parse.js.map +1 -0
- package/dist/cjs/index.d.ts +17 -15
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +75 -61
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/fills.d.ts +5 -0
- package/dist/cjs/math/fills.d.ts.map +1 -0
- package/dist/cjs/{utils/fillClassification.js → math/fills.js} +16 -1
- package/dist/cjs/math/fills.js.map +1 -0
- package/dist/cjs/math/order.d.ts +45 -0
- package/dist/cjs/math/order.d.ts.map +1 -0
- package/dist/cjs/math/order.js +256 -0
- package/dist/cjs/math/order.js.map +1 -0
- package/dist/cjs/math/position.d.ts +56 -0
- package/dist/cjs/math/position.d.ts.map +1 -0
- package/dist/cjs/math/position.js +160 -0
- package/dist/cjs/math/position.js.map +1 -0
- package/dist/cjs/services/resolveQuote.d.ts.map +1 -1
- package/dist/cjs/services/resolveQuote.js +2 -2
- package/dist/cjs/services/resolveQuote.js.map +1 -1
- package/dist/cjs/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/cjs/services/resolveSubscribeQuote.js +2 -2
- package/dist/cjs/services/resolveSubscribeQuote.js.map +1 -1
- package/dist/cjs/types/provider.d.ts +3 -3
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +7 -5
- package/dist/cjs/types/withdrawal.d.ts.map +1 -1
- package/dist/cjs/utils/orderClassification.d.ts +1 -3
- package/dist/cjs/utils/orderClassification.d.ts.map +1 -1
- package/dist/cjs/utils/orderClassification.js +1 -15
- package/dist/cjs/utils/orderClassification.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wire/orderAmounts.d.ts +18 -0
- package/dist/cjs/wire/orderAmounts.d.ts.map +1 -0
- package/dist/cjs/wire/orderAmounts.js +79 -0
- package/dist/cjs/wire/orderAmounts.js.map +1 -0
- package/dist/cjs/wire/refuel.d.ts +8 -0
- package/dist/cjs/wire/refuel.d.ts.map +1 -0
- package/dist/cjs/wire/refuel.js +23 -0
- package/dist/cjs/wire/refuel.js.map +1 -0
- package/dist/cjs/wire/requireDecimal.d.ts +4 -0
- package/dist/cjs/wire/requireDecimal.d.ts.map +1 -0
- package/dist/cjs/wire/requireDecimal.js +16 -0
- package/dist/cjs/wire/requireDecimal.js.map +1 -0
- package/dist/cjs/wire/snap.d.ts +5 -0
- package/dist/cjs/wire/snap.d.ts.map +1 -0
- package/dist/cjs/wire/snap.js +12 -0
- package/dist/cjs/wire/snap.js.map +1 -0
- package/dist/cjs/wire/transferable.d.ts +3 -0
- package/dist/cjs/wire/transferable.d.ts.map +1 -0
- package/dist/cjs/wire/transferable.js +13 -0
- package/dist/cjs/wire/transferable.js.map +1 -0
- package/dist/cjs/wire/withdraw.d.ts +4 -0
- package/dist/cjs/wire/withdraw.d.ts.map +1 -0
- package/dist/cjs/wire/withdraw.js +13 -0
- package/dist/cjs/wire/withdraw.js.map +1 -0
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +4 -1
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
- package/dist/esm/decimal/big.d.ts.map +1 -0
- package/dist/esm/{utils/decimal.js → decimal/big.js} +1 -1
- package/dist/esm/decimal/big.js.map +1 -0
- package/dist/esm/decimal/convert.d.ts +80 -0
- package/dist/esm/decimal/convert.d.ts.map +1 -0
- package/dist/esm/decimal/convert.js +118 -0
- package/dist/esm/decimal/convert.js.map +1 -0
- package/dist/esm/decimal/format.d.ts.map +1 -0
- package/dist/esm/decimal/format.js.map +1 -0
- package/dist/esm/decimal/parse.d.ts +29 -0
- package/dist/esm/decimal/parse.d.ts.map +1 -0
- package/dist/esm/{utils → decimal}/parse.js +9 -10
- package/dist/esm/decimal/parse.js.map +1 -0
- package/dist/esm/index.d.ts +17 -15
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +12 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/fills.d.ts +26 -0
- package/dist/esm/math/fills.d.ts.map +1 -0
- package/dist/esm/{utils/fillClassification.js → math/fills.js} +26 -2
- package/dist/esm/math/fills.js.map +1 -0
- package/dist/esm/{utils/calculations.d.ts → math/order.d.ts} +70 -75
- package/dist/esm/math/order.d.ts.map +1 -0
- package/dist/esm/{utils/calculations.js → math/order.js} +155 -111
- package/dist/esm/math/order.js.map +1 -0
- package/dist/esm/math/position.d.ts +211 -0
- package/dist/esm/math/position.d.ts.map +1 -0
- package/dist/esm/math/position.js +299 -0
- package/dist/esm/math/position.js.map +1 -0
- package/dist/esm/services/resolveQuote.d.ts.map +1 -1
- package/dist/esm/services/resolveQuote.js +1 -1
- package/dist/esm/services/resolveQuote.js.map +1 -1
- package/dist/esm/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/esm/services/resolveSubscribeQuote.js +1 -1
- package/dist/esm/services/resolveSubscribeQuote.js.map +1 -1
- package/dist/esm/types/provider.d.ts +23 -11
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +17 -5
- package/dist/esm/types/withdrawal.d.ts.map +1 -1
- package/dist/esm/utils/orderClassification.d.ts +1 -14
- package/dist/esm/utils/orderClassification.d.ts.map +1 -1
- package/dist/esm/utils/orderClassification.js +1 -25
- package/dist/esm/utils/orderClassification.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wire/orderAmounts.d.ts +55 -0
- package/dist/esm/wire/orderAmounts.d.ts.map +1 -0
- package/dist/esm/wire/orderAmounts.js +114 -0
- package/dist/esm/wire/orderAmounts.js.map +1 -0
- package/dist/esm/wire/refuel.d.ts +28 -0
- package/dist/esm/wire/refuel.d.ts.map +1 -0
- package/dist/esm/wire/refuel.js +36 -0
- package/dist/esm/wire/refuel.js.map +1 -0
- package/dist/esm/wire/requireDecimal.d.ts +11 -0
- package/dist/esm/wire/requireDecimal.d.ts.map +1 -0
- package/dist/esm/wire/requireDecimal.js +17 -0
- package/dist/esm/wire/requireDecimal.js.map +1 -0
- package/dist/esm/wire/snap.d.ts +24 -0
- package/dist/esm/wire/snap.d.ts.map +1 -0
- package/dist/esm/wire/snap.js +27 -0
- package/dist/esm/wire/snap.js.map +1 -0
- package/dist/esm/wire/transferable.d.ts +15 -0
- package/dist/esm/wire/transferable.d.ts.map +1 -0
- package/dist/esm/wire/transferable.js +22 -0
- package/dist/esm/wire/transferable.js.map +1 -0
- package/dist/esm/wire/withdraw.d.ts +14 -0
- package/dist/esm/wire/withdraw.d.ts.map +1 -0
- package/dist/esm/wire/withdraw.js +20 -0
- package/dist/esm/wire/withdraw.js.map +1 -0
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
- package/dist/types/decimal/big.d.ts.map +1 -0
- package/dist/types/decimal/convert.d.ts +80 -0
- package/dist/types/decimal/convert.d.ts.map +1 -0
- package/dist/types/decimal/format.d.ts.map +1 -0
- package/dist/types/decimal/parse.d.ts +29 -0
- package/dist/types/decimal/parse.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -15
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/fills.d.ts +26 -0
- package/dist/types/math/fills.d.ts.map +1 -0
- package/dist/types/{utils/calculations.d.ts → math/order.d.ts} +70 -75
- package/dist/types/math/order.d.ts.map +1 -0
- package/dist/types/math/position.d.ts +211 -0
- package/dist/types/math/position.d.ts.map +1 -0
- package/dist/types/services/resolveQuote.d.ts.map +1 -1
- package/dist/types/services/resolveSubscribeQuote.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +23 -11
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +17 -5
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/utils/orderClassification.d.ts +1 -14
- package/dist/types/utils/orderClassification.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wire/orderAmounts.d.ts +55 -0
- package/dist/types/wire/orderAmounts.d.ts.map +1 -0
- package/dist/types/wire/refuel.d.ts +28 -0
- package/dist/types/wire/refuel.d.ts.map +1 -0
- package/dist/types/wire/requireDecimal.d.ts +11 -0
- package/dist/types/wire/requireDecimal.d.ts.map +1 -0
- package/dist/types/wire/snap.d.ts +24 -0
- package/dist/types/wire/snap.d.ts.map +1 -0
- package/dist/types/wire/transferable.d.ts +15 -0
- package/dist/types/wire/transferable.d.ts.map +1 -0
- package/dist/types/wire/withdraw.d.ts +14 -0
- package/dist/types/wire/withdraw.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +4 -1
- package/src/decimal/convert.ts +164 -0
- package/src/{utils → decimal}/parse.ts +13 -11
- package/src/index.ts +80 -57
- package/src/{utils/fillClassification.ts → math/fills.ts} +30 -1
- package/src/{utils/calculations.ts → math/order.ts} +205 -127
- package/src/{utils/positionMath.ts → math/position.ts} +173 -21
- package/src/services/resolveQuote.ts +1 -1
- package/src/services/resolveSubscribeQuote.ts +1 -1
- package/src/types/provider.ts +23 -10
- package/src/types/withdrawal.ts +22 -5
- package/src/utils/orderClassification.ts +0 -30
- package/src/version.ts +1 -1
- package/src/wire/orderAmounts.ts +172 -0
- package/src/wire/refuel.ts +51 -0
- package/src/wire/requireDecimal.ts +24 -0
- package/src/wire/snap.ts +38 -0
- package/src/wire/transferable.ts +26 -0
- package/src/wire/withdraw.ts +29 -0
- package/dist/cjs/utils/calculations.d.ts +0 -47
- package/dist/cjs/utils/calculations.d.ts.map +0 -1
- package/dist/cjs/utils/calculations.js +0 -214
- package/dist/cjs/utils/calculations.js.map +0 -1
- package/dist/cjs/utils/decimal.d.ts.map +0 -1
- package/dist/cjs/utils/decimal.js.map +0 -1
- package/dist/cjs/utils/fillClassification.d.ts +0 -3
- package/dist/cjs/utils/fillClassification.d.ts.map +0 -1
- package/dist/cjs/utils/fillClassification.js.map +0 -1
- package/dist/cjs/utils/format.d.ts.map +0 -1
- package/dist/cjs/utils/format.js.map +0 -1
- package/dist/cjs/utils/math.d.ts +0 -4
- package/dist/cjs/utils/math.d.ts.map +0 -1
- package/dist/cjs/utils/math.js +0 -8
- package/dist/cjs/utils/math.js.map +0 -1
- package/dist/cjs/utils/orderEntry.d.ts +0 -6
- package/dist/cjs/utils/orderEntry.d.ts.map +0 -1
- package/dist/cjs/utils/orderEntry.js +0 -20
- package/dist/cjs/utils/orderEntry.js.map +0 -1
- package/dist/cjs/utils/orderMath.d.ts +0 -6
- package/dist/cjs/utils/orderMath.d.ts.map +0 -1
- package/dist/cjs/utils/orderMath.js +0 -85
- package/dist/cjs/utils/orderMath.js.map +0 -1
- package/dist/cjs/utils/parse.d.ts +0 -3
- package/dist/cjs/utils/parse.d.ts.map +0 -1
- package/dist/cjs/utils/parse.js.map +0 -1
- package/dist/cjs/utils/positionMath.d.ts +0 -37
- package/dist/cjs/utils/positionMath.d.ts.map +0 -1
- package/dist/cjs/utils/positionMath.js +0 -99
- package/dist/cjs/utils/positionMath.js.map +0 -1
- package/dist/cjs/utils/scaleToInteger.d.ts +0 -3
- package/dist/cjs/utils/scaleToInteger.d.ts.map +0 -1
- package/dist/cjs/utils/scaleToInteger.js +0 -30
- package/dist/cjs/utils/scaleToInteger.js.map +0 -1
- package/dist/cjs/utils/units.d.ts +0 -3
- package/dist/cjs/utils/units.d.ts.map +0 -1
- package/dist/cjs/utils/units.js +0 -18
- package/dist/cjs/utils/units.js.map +0 -1
- package/dist/cjs/utils/validation.d.ts +0 -2
- package/dist/cjs/utils/validation.d.ts.map +0 -1
- package/dist/cjs/utils/validation.js +0 -16
- package/dist/cjs/utils/validation.js.map +0 -1
- package/dist/esm/utils/calculations.d.ts.map +0 -1
- package/dist/esm/utils/calculations.js.map +0 -1
- package/dist/esm/utils/decimal.d.ts.map +0 -1
- package/dist/esm/utils/decimal.js.map +0 -1
- package/dist/esm/utils/fillClassification.d.ts +0 -13
- package/dist/esm/utils/fillClassification.d.ts.map +0 -1
- package/dist/esm/utils/fillClassification.js.map +0 -1
- package/dist/esm/utils/format.d.ts.map +0 -1
- package/dist/esm/utils/format.js.map +0 -1
- package/dist/esm/utils/math.d.ts +0 -6
- package/dist/esm/utils/math.d.ts.map +0 -1
- package/dist/esm/utils/math.js +0 -5
- package/dist/esm/utils/math.js.map +0 -1
- package/dist/esm/utils/orderEntry.d.ts +0 -26
- package/dist/esm/utils/orderEntry.d.ts.map +0 -1
- package/dist/esm/utils/orderEntry.js +0 -34
- package/dist/esm/utils/orderEntry.js.map +0 -1
- package/dist/esm/utils/orderMath.d.ts +0 -37
- package/dist/esm/utils/orderMath.d.ts.map +0 -1
- package/dist/esm/utils/orderMath.js +0 -113
- package/dist/esm/utils/orderMath.js.map +0 -1
- package/dist/esm/utils/parse.d.ts +0 -28
- package/dist/esm/utils/parse.d.ts.map +0 -1
- package/dist/esm/utils/parse.js.map +0 -1
- package/dist/esm/utils/positionMath.d.ts +0 -120
- package/dist/esm/utils/positionMath.d.ts.map +0 -1
- package/dist/esm/utils/positionMath.js +0 -173
- package/dist/esm/utils/positionMath.js.map +0 -1
- package/dist/esm/utils/scaleToInteger.d.ts +0 -22
- package/dist/esm/utils/scaleToInteger.d.ts.map +0 -1
- package/dist/esm/utils/scaleToInteger.js +0 -34
- package/dist/esm/utils/scaleToInteger.js.map +0 -1
- package/dist/esm/utils/units.d.ts +0 -27
- package/dist/esm/utils/units.d.ts.map +0 -1
- package/dist/esm/utils/units.js +0 -38
- package/dist/esm/utils/units.js.map +0 -1
- package/dist/esm/utils/validation.d.ts +0 -18
- package/dist/esm/utils/validation.d.ts.map +0 -1
- package/dist/esm/utils/validation.js +0 -29
- package/dist/esm/utils/validation.js.map +0 -1
- package/dist/types/utils/calculations.d.ts.map +0 -1
- package/dist/types/utils/decimal.d.ts.map +0 -1
- package/dist/types/utils/fillClassification.d.ts +0 -13
- package/dist/types/utils/fillClassification.d.ts.map +0 -1
- package/dist/types/utils/format.d.ts.map +0 -1
- package/dist/types/utils/math.d.ts +0 -6
- package/dist/types/utils/math.d.ts.map +0 -1
- package/dist/types/utils/orderEntry.d.ts +0 -26
- package/dist/types/utils/orderEntry.d.ts.map +0 -1
- package/dist/types/utils/orderMath.d.ts +0 -37
- package/dist/types/utils/orderMath.d.ts.map +0 -1
- package/dist/types/utils/parse.d.ts +0 -28
- package/dist/types/utils/parse.d.ts.map +0 -1
- package/dist/types/utils/positionMath.d.ts +0 -120
- package/dist/types/utils/positionMath.d.ts.map +0 -1
- package/dist/types/utils/scaleToInteger.d.ts +0 -22
- package/dist/types/utils/scaleToInteger.d.ts.map +0 -1
- package/dist/types/utils/units.d.ts +0 -27
- package/dist/types/utils/units.d.ts.map +0 -1
- package/dist/types/utils/validation.d.ts +0 -18
- package/dist/types/utils/validation.d.ts.map +0 -1
- package/src/utils/math.ts +0 -7
- package/src/utils/orderEntry.ts +0 -38
- package/src/utils/orderMath.ts +0 -152
- package/src/utils/scaleToInteger.ts +0 -56
- package/src/utils/units.ts +0 -39
- package/src/utils/validation.ts +0 -38
- /package/dist/cjs/{utils → decimal}/format.d.ts +0 -0
- /package/dist/cjs/{utils → decimal}/format.js +0 -0
- /package/dist/esm/{utils → decimal}/format.d.ts +0 -0
- /package/dist/esm/{utils → decimal}/format.js +0 -0
- /package/dist/types/{utils → decimal}/format.d.ts +0 -0
- /package/src/{utils/decimal.ts → decimal/big.ts} +0 -0
- /package/src/{utils → decimal}/format.ts +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type DecimalString, type Market } from '@lifi/perps-types';
|
|
2
|
+
import type { PerpsSDKClient } from '../types/provider.js';
|
|
3
|
+
/** @public */
|
|
4
|
+
export interface OrderAmountsInput {
|
|
5
|
+
sdk: PerpsSDKClient;
|
|
6
|
+
market: Market;
|
|
7
|
+
/** The field the user typed; the other two are calculated from it. */
|
|
8
|
+
held: 'margin' | 'size' | 'notional';
|
|
9
|
+
amount: DecimalString;
|
|
10
|
+
leverage: number;
|
|
11
|
+
price: DecimalString;
|
|
12
|
+
/** Decimals for the quote-asset amounts (margin, notional). Default 2. */
|
|
13
|
+
quoteDecimals?: number;
|
|
14
|
+
}
|
|
15
|
+
/** @public */
|
|
16
|
+
export interface OrderAmounts {
|
|
17
|
+
/**
|
|
18
|
+
* On the `quoteDecimals` grid: rounded up when derived, so it funds `size`
|
|
19
|
+
* at the requested leverage, and truncated when the user holds it.
|
|
20
|
+
*/
|
|
21
|
+
margin: DecimalString;
|
|
22
|
+
/** Snapped onto the venue lot grid. */
|
|
23
|
+
size: DecimalString;
|
|
24
|
+
/** Truncated to `quoteDecimals`. */
|
|
25
|
+
notional: DecimalString;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The three order-entry amounts, derived from whichever one the user typed.
|
|
29
|
+
*
|
|
30
|
+
* The held field is normalised first — truncated to `quoteDecimals` for a
|
|
31
|
+
* margin or notional, snapped onto the venue lot grid for a size — and the
|
|
32
|
+
* other two are then derived from that normalised value, so the three agree
|
|
33
|
+
* with each other rather than with an input the user cannot see.
|
|
34
|
+
*
|
|
35
|
+
* Rounding is directional, so the result always funds itself:
|
|
36
|
+
* `size × price ≤ margin × leverage`. A derived size truncates onto the lot
|
|
37
|
+
* grid and a derived notional truncates onto the quote grid, but a derived
|
|
38
|
+
* margin rounds **up** onto the quote grid, because it is the one amount that
|
|
39
|
+
* has to cover the others rather than cap them.
|
|
40
|
+
*
|
|
41
|
+
* Formulas: `size = margin × leverage ÷ price`,
|
|
42
|
+
* `margin = size × price ÷ leverage`, `notional = size × price`
|
|
43
|
+
* (or `margin × leverage` when the margin is held).
|
|
44
|
+
*
|
|
45
|
+
* @returns `null` when `amount` or `price` is not a positive decimal string,
|
|
46
|
+
* when `leverage` is not a positive finite number, or when the venue and
|
|
47
|
+
* quote grids snap the result to a non-positive amount — a sub-lot size or
|
|
48
|
+
* a sub-cent quote amount describes no order a venue can take.
|
|
49
|
+
* @throws {PerpsError} `ValidationError` when `quoteDecimals` is not a
|
|
50
|
+
* non-negative integer, or `SDKError` when `market.providerId` names no
|
|
51
|
+
* registered provider plugin.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare function calculateOrderAmounts(input: OrderAmountsInput): OrderAmounts | null;
|
|
55
|
+
//# sourceMappingURL=orderAmounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderAmounts.d.ts","sourceRoot":"","sources":["../../../src/wire/orderAmounts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,MAAM,EAEZ,MAAM,mBAAmB,CAAA;AAI1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAG1D,cAAc;AACd,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAA;IACpC,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,aAAa,CAAA;IACpB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,cAAc;AACd,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,MAAM,EAAE,aAAa,CAAA;IACrB,uCAAuC;IACvC,IAAI,EAAE,aAAa,CAAA;IACnB,oCAAoC;IACpC,QAAQ,EAAE,aAAa,CAAA;CACxB;AAqDD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,GACvB,YAAY,GAAG,IAAI,CAqDrB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { isDecimalString, PerpsErrorCode, } from '@lifi/perps-types';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { TruncBig } from '../decimal/big.js';
|
|
4
|
+
import { PerpsError } from '../errors/PerpsError.js';
|
|
5
|
+
import { snapOrderSize } from './snap.js';
|
|
6
|
+
const DEFAULT_QUOTE_DECIMALS = 2;
|
|
7
|
+
const TEN = new Big(10);
|
|
8
|
+
/** Round a quote amount down onto its decimal grid, with no trailing zeros. */
|
|
9
|
+
function quoteAmount(value, decimals) {
|
|
10
|
+
const truncated = value.round(decimals, Big.roundDown);
|
|
11
|
+
return truncated.eq(0) ? '0' : truncated.toFixed();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The smallest margin on the `decimals` grid that funds `notional` at
|
|
15
|
+
* `leverage`, so `margin × leverage ≥ notional` holds. The one derived amount
|
|
16
|
+
* that rounds up: a margin rounded down under-funds the size it backs.
|
|
17
|
+
*
|
|
18
|
+
* The ceiling is exact: the remainder decides the carry, so the result never
|
|
19
|
+
* leans on a fixed decimal-place limit the way `div` then `round` would.
|
|
20
|
+
*/
|
|
21
|
+
function coveringMargin(notional, leverage, decimals) {
|
|
22
|
+
const scale = TEN.pow(decimals);
|
|
23
|
+
const scaled = notional.times(scale);
|
|
24
|
+
const remainder = scaled.mod(leverage);
|
|
25
|
+
const whole = scaled.minus(remainder).div(leverage);
|
|
26
|
+
const covering = remainder.eq(0) ? whole : whole.plus(1);
|
|
27
|
+
return covering.eq(0) ? '0' : covering.div(scale).toFixed();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An order needs three positive amounts. A grid that snaps any of them to
|
|
31
|
+
* zero — a sub-lot size, a sub-cent quote amount — describes no order a venue
|
|
32
|
+
* can take, so the caller gets `null` instead of a result it has to re-check.
|
|
33
|
+
*/
|
|
34
|
+
function executable(amounts) {
|
|
35
|
+
const positive = new Big(amounts.size).gt(0) &&
|
|
36
|
+
new Big(amounts.margin).gt(0) &&
|
|
37
|
+
new Big(amounts.notional).gt(0);
|
|
38
|
+
return positive ? amounts : null;
|
|
39
|
+
}
|
|
40
|
+
function positiveDecimal(value) {
|
|
41
|
+
if (!isDecimalString(value)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const parsed = new TruncBig(value);
|
|
45
|
+
return parsed.gt(0) ? parsed : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The three order-entry amounts, derived from whichever one the user typed.
|
|
49
|
+
*
|
|
50
|
+
* The held field is normalised first — truncated to `quoteDecimals` for a
|
|
51
|
+
* margin or notional, snapped onto the venue lot grid for a size — and the
|
|
52
|
+
* other two are then derived from that normalised value, so the three agree
|
|
53
|
+
* with each other rather than with an input the user cannot see.
|
|
54
|
+
*
|
|
55
|
+
* Rounding is directional, so the result always funds itself:
|
|
56
|
+
* `size × price ≤ margin × leverage`. A derived size truncates onto the lot
|
|
57
|
+
* grid and a derived notional truncates onto the quote grid, but a derived
|
|
58
|
+
* margin rounds **up** onto the quote grid, because it is the one amount that
|
|
59
|
+
* has to cover the others rather than cap them.
|
|
60
|
+
*
|
|
61
|
+
* Formulas: `size = margin × leverage ÷ price`,
|
|
62
|
+
* `margin = size × price ÷ leverage`, `notional = size × price`
|
|
63
|
+
* (or `margin × leverage` when the margin is held).
|
|
64
|
+
*
|
|
65
|
+
* @returns `null` when `amount` or `price` is not a positive decimal string,
|
|
66
|
+
* when `leverage` is not a positive finite number, or when the venue and
|
|
67
|
+
* quote grids snap the result to a non-positive amount — a sub-lot size or
|
|
68
|
+
* a sub-cent quote amount describes no order a venue can take.
|
|
69
|
+
* @throws {PerpsError} `ValidationError` when `quoteDecimals` is not a
|
|
70
|
+
* non-negative integer, or `SDKError` when `market.providerId` names no
|
|
71
|
+
* registered provider plugin.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export function calculateOrderAmounts(input) {
|
|
75
|
+
const { sdk, market, held, leverage, quoteDecimals = DEFAULT_QUOTE_DECIMALS, } = input;
|
|
76
|
+
if (!Number.isInteger(quoteDecimals) || quoteDecimals < 0) {
|
|
77
|
+
throw new PerpsError(PerpsErrorCode.ValidationError, `Invalid quoteDecimals for order amounts: ${quoteDecimals}`);
|
|
78
|
+
}
|
|
79
|
+
const amount = positiveDecimal(input.amount);
|
|
80
|
+
const price = positiveDecimal(input.price);
|
|
81
|
+
if (amount === null ||
|
|
82
|
+
price === null ||
|
|
83
|
+
!Number.isFinite(leverage) ||
|
|
84
|
+
leverage <= 0) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const leverageFactor = new TruncBig(leverage);
|
|
88
|
+
if (held === 'size') {
|
|
89
|
+
const size = snapOrderSize(sdk, market, amount.toFixed());
|
|
90
|
+
const notional = new TruncBig(size).times(price);
|
|
91
|
+
return executable({
|
|
92
|
+
margin: coveringMargin(notional, leverageFactor, quoteDecimals),
|
|
93
|
+
size,
|
|
94
|
+
notional: quoteAmount(notional, quoteDecimals),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (held === 'notional') {
|
|
98
|
+
const notional = quoteAmount(amount, quoteDecimals);
|
|
99
|
+
const exact = new TruncBig(notional);
|
|
100
|
+
return executable({
|
|
101
|
+
margin: coveringMargin(exact, leverageFactor, quoteDecimals),
|
|
102
|
+
size: snapOrderSize(sdk, market, exact.div(price).toFixed()),
|
|
103
|
+
notional,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const margin = quoteAmount(amount, quoteDecimals);
|
|
107
|
+
const notional = new TruncBig(margin).times(leverage);
|
|
108
|
+
return executable({
|
|
109
|
+
margin,
|
|
110
|
+
size: snapOrderSize(sdk, market, notional.div(price).toFixed()),
|
|
111
|
+
notional: quoteAmount(notional, quoteDecimals),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=orderAmounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderAmounts.js","sourceRoot":"","sources":["../../../src/wire/orderAmounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEf,cAAc,GACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AA4BzC,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAA;AAEvB,+EAA+E;AAC/E,SAAS,WAAW,CAAC,KAAU,EAAE,QAAgB;IAC/C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IACtD,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;AACpD,CAAC;AAED;;;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AE,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC;SAC/C,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QACnD,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACpC,OAAO,UAAU,CAAC;YAChB,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,aAAa,CAAC;YAC5D,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;YAC5D,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IACjD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACrD,OAAO,UAAU,CAAC;QAChB,MAAM;QACN,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;QAC/D,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC;KAC/C,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type DecimalString } from '@lifi/perps-types';
|
|
2
|
+
/** @public */
|
|
3
|
+
export interface RefuelAmountInput {
|
|
4
|
+
/** USD value of the gas the route recommends. */
|
|
5
|
+
gasUsd: DecimalString;
|
|
6
|
+
/** USD price of one whole source token. */
|
|
7
|
+
priceUsd: DecimalString;
|
|
8
|
+
/** Decimals of the source token, which the result is spelled to exactly. */
|
|
9
|
+
decimals: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Source-token amount whose USD value covers `gasUsd`, rounded **up** onto
|
|
13
|
+
* the token's decimal grid so a refuel never lands short of the
|
|
14
|
+
* recommendation. The result keeps trailing zeros to `decimals`, so it seeds
|
|
15
|
+
* an amount input at the token's own precision.
|
|
16
|
+
*
|
|
17
|
+
* The quotient does not terminate for most prices, which is why this is a
|
|
18
|
+
* big.js primitive: an 18-decimal token needs a ceiling at 10^-18, far past
|
|
19
|
+
* what a `number` can carry.
|
|
20
|
+
*
|
|
21
|
+
* @returns `undefined` when `gasUsd` or `priceUsd` is not greater than zero,
|
|
22
|
+
* which is a route with nothing to refuel rather than a failure.
|
|
23
|
+
* @throws {PerpsError} `ValidationError` when `gasUsd` or `priceUsd` is not a
|
|
24
|
+
* {@link DecimalString}, or when `decimals` is not a non-negative integer.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function calculateRefuelAmount(input: RefuelAmountInput): DecimalString | undefined;
|
|
28
|
+
//# sourceMappingURL=refuel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refuel.d.ts","sourceRoot":"","sources":["../../../src/wire/refuel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AAKtE,cAAc;AACd,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,MAAM,EAAE,aAAa,CAAA;IACrB,2CAA2C;IAC3C,QAAQ,EAAE,aAAa,CAAA;IACvB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,GACvB,aAAa,GAAG,SAAS,CAiB3B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PerpsErrorCode } from '@lifi/perps-types';
|
|
2
|
+
import { DivBig } from '../decimal/big.js';
|
|
3
|
+
import { PerpsError } from '../errors/PerpsError.js';
|
|
4
|
+
import { requireDecimal } from './requireDecimal.js';
|
|
5
|
+
/**
|
|
6
|
+
* Source-token amount whose USD value covers `gasUsd`, rounded **up** onto
|
|
7
|
+
* the token's decimal grid so a refuel never lands short of the
|
|
8
|
+
* recommendation. The result keeps trailing zeros to `decimals`, so it seeds
|
|
9
|
+
* an amount input at the token's own precision.
|
|
10
|
+
*
|
|
11
|
+
* The quotient does not terminate for most prices, which is why this is a
|
|
12
|
+
* big.js primitive: an 18-decimal token needs a ceiling at 10^-18, far past
|
|
13
|
+
* what a `number` can carry.
|
|
14
|
+
*
|
|
15
|
+
* @returns `undefined` when `gasUsd` or `priceUsd` is not greater than zero,
|
|
16
|
+
* which is a route with nothing to refuel rather than a failure.
|
|
17
|
+
* @throws {PerpsError} `ValidationError` when `gasUsd` or `priceUsd` is not a
|
|
18
|
+
* {@link DecimalString}, or when `decimals` is not a non-negative integer.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export function calculateRefuelAmount(input) {
|
|
22
|
+
const { decimals } = input;
|
|
23
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
24
|
+
throw new PerpsError(PerpsErrorCode.ValidationError, `Invalid \`decimals\` for a refuel amount: ${decimals}`);
|
|
25
|
+
}
|
|
26
|
+
const gasUsd = requireDecimal(input.gasUsd, 'gasUsd');
|
|
27
|
+
const priceUsd = requireDecimal(input.priceUsd, 'priceUsd');
|
|
28
|
+
if (!gasUsd.gt(0) || !priceUsd.gt(0)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return new DivBig(gasUsd)
|
|
32
|
+
.div(priceUsd)
|
|
33
|
+
.round(decimals, DivBig.roundUp)
|
|
34
|
+
.toFixed(decimals);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=refuel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refuel.js","sourceRoot":"","sources":["../../../src/wire/refuel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAYpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAwB;IAExB,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,UAAU,CAClB,cAAc,CAAC,eAAe,EAC9B,6CAA6C,QAAQ,EAAE,CACxD,CAAA;IACH,CAAC;IACD,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACrD,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;IAC3D,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;SACtB,GAAG,CAAC,QAAQ,CAAC;SACb,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC;SAC/B,OAAO,CAAC,QAAQ,CAAC,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DecimalString } from '@lifi/perps-types';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parse a wire-tier decimal input, naming the field it came from when the
|
|
5
|
+
* value breaks the {@link DecimalString} contract, so a malformed amount
|
|
6
|
+
* fails at the SDK boundary instead of inside big.js.
|
|
7
|
+
*
|
|
8
|
+
* @throws {PerpsError} `ValidationError` naming `field`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function requireDecimal(value: DecimalString, field: string): Big;
|
|
11
|
+
//# sourceMappingURL=requireDecimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requireDecimal.d.ts","sourceRoot":"","sources":["../../../src/wire/requireDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAA;AAGxB;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAQvE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isDecimalString, PerpsErrorCode, } from '@lifi/perps-types';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { PerpsError } from '../errors/PerpsError.js';
|
|
4
|
+
/**
|
|
5
|
+
* Parse a wire-tier decimal input, naming the field it came from when the
|
|
6
|
+
* value breaks the {@link DecimalString} contract, so a malformed amount
|
|
7
|
+
* fails at the SDK boundary instead of inside big.js.
|
|
8
|
+
*
|
|
9
|
+
* @throws {PerpsError} `ValidationError` naming `field`.
|
|
10
|
+
*/
|
|
11
|
+
export function requireDecimal(value, field) {
|
|
12
|
+
if (!isDecimalString(value)) {
|
|
13
|
+
throw new PerpsError(PerpsErrorCode.ValidationError, `Invalid \`${field}\`: '${value}' is not a decimal string.`);
|
|
14
|
+
}
|
|
15
|
+
return new Big(value);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=requireDecimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requireDecimal.js","sourceRoot":"","sources":["../../../src/wire/requireDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,cAAc,GACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAoB,EAAE,KAAa;IAChE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,UAAU,CAClB,cAAc,CAAC,eAAe,EAC9B,aAAa,KAAK,QAAQ,KAAK,4BAA4B,CAC5D,CAAA;IACH,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DecimalString, Market } from '@lifi/perps-types';
|
|
2
|
+
import type { PerpsSDKClient } from '../types/provider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Snap `size` onto the lot grid of `market`'s venue, truncating toward zero,
|
|
5
|
+
* through the market's own provider. Takes and gives a {@link DecimalString},
|
|
6
|
+
* so a caller never converts an order size to a `number`.
|
|
7
|
+
*
|
|
8
|
+
* @throws {PerpsError} `SDKError` when `market.providerId` names no registered
|
|
9
|
+
* provider plugin.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare function snapOrderSize(sdk: PerpsSDKClient, market: Market, size: DecimalString): DecimalString;
|
|
13
|
+
/**
|
|
14
|
+
* Snap `price` onto the tick grid of `market`'s venue, rounding half-up,
|
|
15
|
+
* through the market's own provider. Takes and gives a {@link DecimalString},
|
|
16
|
+
* so a caller never converts an order price to a `number`.
|
|
17
|
+
*
|
|
18
|
+
* @throws {PerpsError} `SDKError` when `market.providerId` names no registered
|
|
19
|
+
* provider plugin, or `ValidationError` when the market lacks the tick
|
|
20
|
+
* metadata the venue's rules need.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function snapOrderPrice(sdk: PerpsSDKClient, market: Market, price: DecimalString): DecimalString;
|
|
24
|
+
//# sourceMappingURL=snap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snap.d.ts","sourceRoot":"","sources":["../../../src/wire/snap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,aAAa,GAClB,aAAa,CAEf;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,aAAa,GACnB,aAAa,CAEf"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { requireProvider } from '../client/requireProvider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Snap `size` onto the lot grid of `market`'s venue, truncating toward zero,
|
|
4
|
+
* through the market's own provider. Takes and gives a {@link DecimalString},
|
|
5
|
+
* so a caller never converts an order size to a `number`.
|
|
6
|
+
*
|
|
7
|
+
* @throws {PerpsError} `SDKError` when `market.providerId` names no registered
|
|
8
|
+
* provider plugin.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export function snapOrderSize(sdk, market, size) {
|
|
12
|
+
return requireProvider(sdk, market.providerId).snapOrderSize(market, size);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Snap `price` onto the tick grid of `market`'s venue, rounding half-up,
|
|
16
|
+
* through the market's own provider. Takes and gives a {@link DecimalString},
|
|
17
|
+
* so a caller never converts an order price to a `number`.
|
|
18
|
+
*
|
|
19
|
+
* @throws {PerpsError} `SDKError` when `market.providerId` names no registered
|
|
20
|
+
* provider plugin, or `ValidationError` when the market lacks the tick
|
|
21
|
+
* metadata the venue's rules need.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export function snapOrderPrice(sdk, market, price) {
|
|
25
|
+
return requireProvider(sdk, market.providerId).snapOrderPrice(market, price);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=snap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snap.js","sourceRoot":"","sources":["../../../src/wire/snap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAG9D;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAmB,EACnB,MAAc,EACd,IAAmB;IAEnB,OAAO,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAC5E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAmB,EACnB,MAAc,EACd,KAAoB;IAEpB,OAAO,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAC9E,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DecimalString } from '@lifi/perps-types';
|
|
2
|
+
/**
|
|
3
|
+
* The part of `units` that a venue-wide free figure releases: never below
|
|
4
|
+
* zero, never above the units held. `Balance.transferable` on every provider
|
|
5
|
+
* is this clamp over the venue's own free-margin or unlocked-balance figure.
|
|
6
|
+
*
|
|
7
|
+
* @param venueFigure - The venue's free figure for the category, which can
|
|
8
|
+
* exceed `units` or fall below zero.
|
|
9
|
+
* @param units - Units held in the category, the upper bound of the clamp.
|
|
10
|
+
* @throws {PerpsError} `ValidationError` when either input is not a
|
|
11
|
+
* {@link DecimalString}, naming the field.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateTransferable(venueFigure: DecimalString, units: DecimalString): DecimalString;
|
|
15
|
+
//# sourceMappingURL=transferable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferable.d.ts","sourceRoot":"","sources":["../../../src/wire/transferable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,aAAa,EAC1B,KAAK,EAAE,aAAa,GACnB,aAAa,CAOf"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { requireDecimal } from './requireDecimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* The part of `units` that a venue-wide free figure releases: never below
|
|
4
|
+
* zero, never above the units held. `Balance.transferable` on every provider
|
|
5
|
+
* is this clamp over the venue's own free-margin or unlocked-balance figure.
|
|
6
|
+
*
|
|
7
|
+
* @param venueFigure - The venue's free figure for the category, which can
|
|
8
|
+
* exceed `units` or fall below zero.
|
|
9
|
+
* @param units - Units held in the category, the upper bound of the clamp.
|
|
10
|
+
* @throws {PerpsError} `ValidationError` when either input is not a
|
|
11
|
+
* {@link DecimalString}, naming the field.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function calculateTransferable(venueFigure, units) {
|
|
15
|
+
const figure = requireDecimal(venueFigure, 'venueFigure');
|
|
16
|
+
const held = requireDecimal(units, 'units');
|
|
17
|
+
if (figure.lt(0)) {
|
|
18
|
+
return '0';
|
|
19
|
+
}
|
|
20
|
+
return (figure.gt(held) ? held : figure).toFixed();
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=transferable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferable.js","sourceRoot":"","sources":["../../../src/wire/transferable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAA0B,EAC1B,KAAoB;IAEpB,MAAM,MAAM,GAAG,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;IACzD,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC3C,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAA;AACpD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DecimalString } from '@lifi/perps-types';
|
|
2
|
+
import type { WithdrawableBalance } from '../types/withdrawal.js';
|
|
3
|
+
/**
|
|
4
|
+
* Largest `amount` a withdrawable row can fund: `available` when the venue
|
|
5
|
+
* deducts the fee from the amount or publishes no fee, and
|
|
6
|
+
* `available − withdrawalFee` floored at zero when the venue charges the fee
|
|
7
|
+
* on top (`isFeeDeducted === false`).
|
|
8
|
+
*
|
|
9
|
+
* @throws {PerpsError} `ValidationError` when `available` or `withdrawalFee`
|
|
10
|
+
* is not a {@link DecimalString}, naming the field.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateWithdrawMax(row: Pick<WithdrawableBalance, 'available' | 'withdrawalFee' | 'isFeeDeducted'>): DecimalString;
|
|
14
|
+
//# sourceMappingURL=withdraw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../../../src/wire/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAGjE;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,IAAI,CACP,mBAAmB,EACnB,WAAW,GAAG,eAAe,GAAG,eAAe,CAChD,GACA,aAAa,CASf"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { requireDecimal } from './requireDecimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Largest `amount` a withdrawable row can fund: `available` when the venue
|
|
4
|
+
* deducts the fee from the amount or publishes no fee, and
|
|
5
|
+
* `available − withdrawalFee` floored at zero when the venue charges the fee
|
|
6
|
+
* on top (`isFeeDeducted === false`).
|
|
7
|
+
*
|
|
8
|
+
* @throws {PerpsError} `ValidationError` when `available` or `withdrawalFee`
|
|
9
|
+
* is not a {@link DecimalString}, naming the field.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export function calculateWithdrawMax(row) {
|
|
13
|
+
const available = requireDecimal(row.available, 'available');
|
|
14
|
+
if (row.isFeeDeducted !== false || row.withdrawalFee === undefined) {
|
|
15
|
+
return available.toFixed();
|
|
16
|
+
}
|
|
17
|
+
const funded = available.minus(requireDecimal(row.withdrawalFee, 'withdrawalFee'));
|
|
18
|
+
return funded.gt(0) ? funded.toFixed() : '0';
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=withdraw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdraw.js","sourceRoot":"","sources":["../../../src/wire/withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAGC;IAED,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;IAC5D,IAAI,GAAG,CAAC,aAAa,KAAK,KAAK,IAAI,GAAG,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACnE,OAAO,SAAS,CAAC,OAAO,EAAE,CAAA;IAC5B,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAC5B,cAAc,CAAC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CACnD,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G;IACG,kBAAkB,CACtB,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,qBAAqB,CAAC;IASjC;;;;;;;;;;;;;;;OAeG;IACG,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAC9C,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,qBAAqB,CAAC;CA+ClC"}
|
|
@@ -11,4 +11,4 @@ export declare const DivBig: Big.BigConstructor;
|
|
|
11
11
|
export declare const TruncBig: Big.BigConstructor;
|
|
12
12
|
/** True when every value is a finite number, so `new DivBig(value)` cannot throw. */
|
|
13
13
|
export declare function areFinite(...values: number[]): boolean;
|
|
14
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=big.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big.d.ts","sourceRoot":"","sources":["../../../src/decimal/big.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AAExB;;;GAGG;AACH,eAAO,MAAM,MAAM,oBAAQ,CAAA;AAG3B;;;GAGG;AACH,eAAO,MAAM,QAAQ,oBAAQ,CAAA;AAI7B,qFAAqF;AACrF,wBAAgB,SAAS,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type DecimalString } from '@lifi/perps-types';
|
|
2
|
+
/**
|
|
3
|
+
* Off-grid resolution for {@link decimalToBaseUnits}:
|
|
4
|
+
* - `truncate` — toward zero, for sizes and collateral amounts. The wire
|
|
5
|
+
* value never exceeds the caller's intent.
|
|
6
|
+
* - `round` — half away from zero, for prices, which snap to the nearest
|
|
7
|
+
* tick.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type BaseUnitsRounding = 'truncate' | 'round';
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `BaseUnitsRounding`. Removed in the next major.
|
|
13
|
+
*/
|
|
14
|
+
export type ScaleToIntegerPolicy = BaseUnitsRounding;
|
|
15
|
+
/**
|
|
16
|
+
* Scale a decimal string to a scaled integer in exact decimal arithmetic — an
|
|
17
|
+
* on-grid input maps to its exact scaled integer with no binary float
|
|
18
|
+
* artifacts (`'0.29'` at 2 decimals is 29, never 28). Off-grid input resolves
|
|
19
|
+
* per `rounding`; there is no silent default.
|
|
20
|
+
*
|
|
21
|
+
* @throws {PerpsError} `ValidationError` when `value` is not a decimal
|
|
22
|
+
* numeric string, `decimals` is not a non-negative integer, or the scaled
|
|
23
|
+
* result's magnitude exceeds `Number.MAX_SAFE_INTEGER`.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const decimalToBaseUnits: (value: DecimalString, decimals: number, rounding: BaseUnitsRounding) => number;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `decimalToBaseUnits`. Removed in the next major.
|
|
29
|
+
*/
|
|
30
|
+
export declare const scaleToInteger: (value: DecimalString, decimals: number, rounding: BaseUnitsRounding) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a base-unit amount (bigint string) to a decimal string.
|
|
33
|
+
*
|
|
34
|
+
* @param amount - Amount in base units (e.g. "1000000" for 1 USDC)
|
|
35
|
+
* @param decimals - Token decimals (e.g. 6 for USDC)
|
|
36
|
+
* @returns Decimal string; `"0"` when `amount` is not a valid bigint
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* baseUnitsToDecimal('1000000', 6) // '1'
|
|
40
|
+
* ```
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export declare function baseUnitsToDecimal(amount: string, decimals: number): DecimalString;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use `baseUnitsToDecimal`. Removed in the next major.
|
|
46
|
+
*/
|
|
47
|
+
export declare const fromBaseUnits: typeof baseUnitsToDecimal;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Compose `parseDecimal(baseUnitsToDecimal(...))`. Removed in the
|
|
50
|
+
* next major.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fromBaseUnitsNumber(amount: string, decimals: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Round `value` down to `decimals` and pad the result to exactly that many
|
|
55
|
+
* decimal places. The padding is the point: this seeds a fixed-decimal input,
|
|
56
|
+
* where `'500.00'` and `'500'` are two renderings of one amount and the field
|
|
57
|
+
* wants the first. For a canonical wire amount with no trailing zeros, read
|
|
58
|
+
* the amount off `calculateOrderAmounts` or a provider snap instead.
|
|
59
|
+
*
|
|
60
|
+
* Exact decimal arithmetic throughout, so there is no 2^53 ceiling and no
|
|
61
|
+
* float artifact: `'0.01'` at 18 decimals gives
|
|
62
|
+
* `'0.010000000000000000'`, which `Number#toFixed` cannot.
|
|
63
|
+
*
|
|
64
|
+
* @throws {PerpsError} `ValidationError` when `value` is not a decimal
|
|
65
|
+
* numeric string, or `decimals` is not a non-negative integer.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export declare function truncateDecimal(value: DecimalString, decimals: number): DecimalString;
|
|
69
|
+
/**
|
|
70
|
+
* Spell a `number` as a {@link DecimalString} in plain notation: `1e-7`
|
|
71
|
+
* becomes `'0.0000001'`, never `'1e-7'`. The boundary helper for a venue or
|
|
72
|
+
* browser API that hands out numbers; a value already spelled as a decimal
|
|
73
|
+
* string must not round-trip through here, because above 15 significant
|
|
74
|
+
* digits the `number` has already lost digits.
|
|
75
|
+
*
|
|
76
|
+
* @throws {PerpsError} `ValidationError` when `value` is `NaN` or infinite.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare function numberToDecimalString(value: number): DecimalString;
|
|
80
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/decimal/convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AAMtE;;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CAAA;AAI7C,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;AAyFrD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAaR;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAaR;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAaR;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAaR;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAqBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAkBR"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DecimalString } from '@lifi/perps-types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a string to a float, stripping common formatting artefacts.
|
|
4
|
+
*
|
|
5
|
+
* Handles:
|
|
6
|
+
* - Currency prefixes/suffixes ($, USD, etc.)
|
|
7
|
+
* - Explicit sign prefixes (+/-)
|
|
8
|
+
* - Thousands separators (commas)
|
|
9
|
+
* - Percentage suffixes (%)
|
|
10
|
+
* - Whitespace
|
|
11
|
+
*
|
|
12
|
+
* @returns Parsed number; `0` for empty/blank input, `NaN` when a non-empty
|
|
13
|
+
* string contains no parseable number
|
|
14
|
+
*/
|
|
15
|
+
declare function toFloat(value: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `parseDecimal`. Removed in the next major.
|
|
18
|
+
*/
|
|
19
|
+
export declare const stringToFloat: typeof toFloat;
|
|
20
|
+
/**
|
|
21
|
+
* Parse an optional decimal field, tolerating currency symbols, grouping
|
|
22
|
+
* separators and a percentage suffix around the number.
|
|
23
|
+
* Gives back `undefined` for a missing, malformed or non-finite value, and `0` for an empty string.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseDecimal(value: DecimalString | string | null | undefined): number | undefined;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/decimal/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;;;;GAYG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAStC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,gBAAU,CAAA;AAKpC;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/C,MAAM,GAAG,SAAS,CAYpB"}
|