@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../../src/utils/calculations.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/utils/decimal.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"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FillClassification } from '@lifi/perps-types';
|
|
2
|
-
/**
|
|
3
|
-
* Classify a perpetual fill into the Open/Close/Increase/Reduce/Switch
|
|
4
|
-
* taxonomy from `FillClassification`.
|
|
5
|
-
*
|
|
6
|
-
* @param startPosition Signed position held BEFORE this fill (`> 0` long,
|
|
7
|
-
* `< 0` short, `0` flat).
|
|
8
|
-
* @param side Hyperliquid-style: `'B'` for buy, anything else for sell.
|
|
9
|
-
* @param sz Unsigned fill size, parsed with `parseFloat`.
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export declare function classifyFillFromPosition(startPosition: string, side: string, sz: string): FillClassification;
|
|
13
|
-
//# sourceMappingURL=fillClassification.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fillClassification.d.ts","sourceRoot":"","sources":["../../../src/utils/fillClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,kBAAkB,CAkCpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/utils/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type Big from 'big.js';
|
|
2
|
-
/** The larger of two Big values, as `Math.max` for numbers. */
|
|
3
|
-
export declare const maxOf: (a: Big, b: Big) => Big;
|
|
4
|
-
/** The smaller of two Big values, as `Math.min` for numbers. */
|
|
5
|
-
export declare const minOf: (a: Big, b: Big) => Big;
|
|
6
|
-
//# sourceMappingURL=math.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/utils/math.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAA;AAE7B,+DAA+D;AAC/D,eAAO,MAAM,KAAK,GAAI,GAAG,GAAG,EAAE,GAAG,GAAG,KAAG,GAAwB,CAAA;AAE/D,gEAAgE;AAChE,eAAO,MAAM,KAAK,GAAI,GAAG,GAAG,EAAE,GAAG,GAAG,KAAG,GAAwB,CAAA"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type Big from 'big.js';
|
|
2
|
-
/**
|
|
3
|
-
* Base size the given margin buys at `leverage`: size = margin × leverage ÷ price.
|
|
4
|
-
* Truncates, so `size × price` never exceeds `margin × leverage`.
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare function sizeFromMargin(margin: Big, leverage: number, price: Big): Big;
|
|
8
|
-
/**
|
|
9
|
-
* Margin that holds the given base size at `leverage`: margin = size × price ÷ leverage.
|
|
10
|
-
* Truncates, so `margin × leverage` never exceeds `size × price`.
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export declare function marginFromSize(size: Big, leverage: number, price: Big): Big;
|
|
14
|
-
/**
|
|
15
|
-
* Base size for a notional: size = notional ÷ price.
|
|
16
|
-
* Truncates, so `size × price` never exceeds the notional.
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export declare function sizeFromNotional(notionalUsd: Big, price: Big): Big;
|
|
20
|
-
/**
|
|
21
|
-
* Margin for a notional at `leverage`: margin = notional ÷ leverage.
|
|
22
|
-
* Truncates, so `margin × leverage` never exceeds the notional.
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
export declare function marginFromNotional(notionalUsd: Big, leverage: number): Big;
|
|
26
|
-
//# sourceMappingURL=orderEntry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderEntry.d.ts","sourceRoot":"","sources":["../../../src/utils/orderEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAA;AAG7B;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAE7E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAE3E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAElE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,CAE1E"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { type Position, type RegularOrder, type TriggerOrder } from '@lifi/perps-types';
|
|
2
|
-
/**
|
|
3
|
-
* Pick the matching open position for an order's market, if any.
|
|
4
|
-
*
|
|
5
|
-
* @param marketId - The order's `market.id`.
|
|
6
|
-
* @param positions - Open positions list (any market).
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export declare function findMatchingPosition(marketId: string, positions: readonly Position[]): Position | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Resolve the close-size against a position, applying the spec's cap rules:
|
|
12
|
-
* - `orderSize === 0` is the Hyperliquid convention for "close entire
|
|
13
|
-
* position" → close the full position size.
|
|
14
|
-
* - Otherwise cap at the absolute position size; an order larger than the
|
|
15
|
-
* position can only close what's open.
|
|
16
|
-
*
|
|
17
|
-
* Inputs are non-negative magnitudes.
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export declare function resolveCloseSize(orderSize: number, positionSize: number): number;
|
|
21
|
-
/**
|
|
22
|
-
* Expected rPnL for a resting limit order against a matching position.
|
|
23
|
-
*
|
|
24
|
-
* Reducing requires opposite sides (long position + SELL, short position +
|
|
25
|
-
* BUY). Same-side orders add to the position and have no rPnL → `null`.
|
|
26
|
-
* Projects `remainingSize`, because an already-filled quantity has realised
|
|
27
|
-
* its PnL at the fill price rather than at this order's limit price. A
|
|
28
|
-
* `remainingSize` of zero leaves nothing to project.
|
|
29
|
-
*
|
|
30
|
-
* @returns Realised PnL if the order would reduce the position, otherwise
|
|
31
|
-
* `null`.
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export declare function expectedRealizedPnlForOpenOrder(order: RegularOrder, position: Position | undefined): number | null;
|
|
35
|
-
/** Project the unfilled closing quantity of an active trigger at its trigger price. */
|
|
36
|
-
export declare function expectedRealizedPnlForTriggerOrder(order: TriggerOrder, position: Position | undefined): number | null;
|
|
37
|
-
//# sourceMappingURL=orderMath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderMath.d.ts","sourceRoot":"","sources":["../../../src/utils/orderMath.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAA;AAI1B;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,QAAQ,EAAE,GAC7B,QAAQ,GAAG,SAAS,CAEtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,CAKR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,MAAM,GAAG,IAAI,CAyCf;AAED,uFAAuF;AACvF,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,MAAM,GAAG,IAAI,CA2Cf"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse a string to a float, stripping common formatting artefacts.
|
|
3
|
-
*
|
|
4
|
-
* Handles:
|
|
5
|
-
* - Currency prefixes/suffixes ($, USD, etc.)
|
|
6
|
-
* - Explicit sign prefixes (+/-)
|
|
7
|
-
* - Thousands separators (commas)
|
|
8
|
-
* - Percentage suffixes (%)
|
|
9
|
-
* - Whitespace
|
|
10
|
-
*
|
|
11
|
-
* @returns Parsed number; `0` for empty/blank input, `NaN` when a non-empty
|
|
12
|
-
* string contains no parseable number
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* stringToFloat('$1,234.50') // 1234.5
|
|
16
|
-
* stringToFloat('') // 0
|
|
17
|
-
* ```
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export declare function stringToFloat(value: string): number;
|
|
21
|
-
/**
|
|
22
|
-
* Parse an optional decimal field, with the same formatting tolerance as {@link stringToFloat}.
|
|
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: string | null | undefined): number | undefined;
|
|
28
|
-
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/utils/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASnD;AAKD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,MAAM,GAAG,SAAS,CAYpB"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure-function helpers for predicting how a perp position changes after a
|
|
3
|
-
* fill.
|
|
4
|
-
*
|
|
5
|
-
* Sign convention: long = +1, short = -1. Sizes passed to these helpers are
|
|
6
|
-
* always non-negative magnitudes; direction is carried by `isLong`.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Direction sign for a position.
|
|
10
|
-
*
|
|
11
|
-
* @param isLong - True for long positions, false for short.
|
|
12
|
-
* @returns +1 for long, -1 for short.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export declare function directionSign(isLong: boolean): 1 | -1;
|
|
16
|
-
/**
|
|
17
|
-
* Estimated liquidation price for an isolated-margin position, parameterised
|
|
18
|
-
* by the venue's maintenance margin rate.
|
|
19
|
-
*
|
|
20
|
-
* Standard isolated-margin model (new position, no existing exposure):
|
|
21
|
-
* margin_per_unit = entryPrice / leverage
|
|
22
|
-
* maintenance_per_unit = entryPrice * mmr
|
|
23
|
-
* margin_available = margin_per_unit - maintenance_per_unit
|
|
24
|
-
* liq_price = entryPrice - side * margin_available / (1 - mmr * side)
|
|
25
|
-
*
|
|
26
|
-
* For existing positions, prefer `Position.liquidationPrice` from the venue.
|
|
27
|
-
*
|
|
28
|
-
* @param maintenanceMarginRate - Venue maintenance margin rate as a fraction
|
|
29
|
-
* (e.g. 0.01 = 1%).
|
|
30
|
-
* @returns Estimated liquidation price, or undefined if the inputs cannot
|
|
31
|
-
* produce one (zero leverage, degenerate denominator).
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export declare function estimateIsolatedLiquidationPrice(params: {
|
|
35
|
-
entryPrice: number;
|
|
36
|
-
leverage: number;
|
|
37
|
-
isLong: boolean;
|
|
38
|
-
maintenanceMarginRate: number;
|
|
39
|
-
}): number | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Whether an isolated position with this liquidation price is already past
|
|
42
|
-
* liquidation at `currentPrice`: a long liquidates when the price falls to its
|
|
43
|
-
* liquidation level, a short when it rises to it. A non-positive price on
|
|
44
|
-
* either side counts as unknown, so the result is `false`.
|
|
45
|
-
*
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
export declare function wouldImmediatelyLiquidate(params: {
|
|
49
|
-
liquidationPrice: number;
|
|
50
|
-
currentPrice: number;
|
|
51
|
-
isLong: boolean;
|
|
52
|
-
}): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Predicted average entry price after adding to an existing position.
|
|
55
|
-
*
|
|
56
|
-
* Weighted average of the current entry and the new fill price, weighted by
|
|
57
|
-
* the size of each leg in coin units. Both legs assumed in the same direction
|
|
58
|
-
* (this helper is for adding to, not flipping, a position).
|
|
59
|
-
*
|
|
60
|
-
* @param currentSize - Existing position size in coin units (>= 0).
|
|
61
|
-
* @param currentEntry - Existing position's average entry price.
|
|
62
|
-
* @param addSize - Size being added in coin units (>= 0).
|
|
63
|
-
* @param fillPrice - Price the new size is expected to fill at (mid for
|
|
64
|
-
* market, limitPrice for limit orders).
|
|
65
|
-
* @returns The new weighted-average entry price, or undefined if the inputs
|
|
66
|
-
* cannot produce a valid average (zero combined size, non-finite values).
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export declare function predictAverageEntryPrice(params: {
|
|
70
|
-
currentSize: number;
|
|
71
|
-
currentEntry: number;
|
|
72
|
-
addSize: number;
|
|
73
|
-
fillPrice: number;
|
|
74
|
-
}): number | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* Predicted effective leverage after adding margin and notional.
|
|
77
|
-
*
|
|
78
|
-
* leverage = totalNotional / totalMargin. The caller computes notional from
|
|
79
|
-
* size and price (`calculateNotionalValue`) and supplies the additional
|
|
80
|
-
* margin the user is about to put up.
|
|
81
|
-
*
|
|
82
|
-
* @returns The new effective leverage, or undefined if total margin is
|
|
83
|
-
* non-positive.
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
export declare function predictNewLeverage(params: {
|
|
87
|
-
currentNotional: number;
|
|
88
|
-
currentMargin: number;
|
|
89
|
-
addNotional: number;
|
|
90
|
-
addMargin: number;
|
|
91
|
-
}): number | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Predicted unrealised PnL at the current mark price.
|
|
94
|
-
*
|
|
95
|
-
* `pnl = (markPrice - entryPrice) * size * directionSign(isLong)`
|
|
96
|
-
*
|
|
97
|
-
* @param size - Position size as a non-negative magnitude.
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
export declare function predictUnrealizedPnl(params: {
|
|
101
|
-
entryPrice: number;
|
|
102
|
-
markPrice: number;
|
|
103
|
-
size: number;
|
|
104
|
-
isLong: boolean;
|
|
105
|
-
}): number;
|
|
106
|
-
/**
|
|
107
|
-
* Realised PnL on the portion of a position being closed.
|
|
108
|
-
*
|
|
109
|
-
* `rPnl = (closePrice - entryPrice) * closeSize * directionSign(isLong)`
|
|
110
|
-
*
|
|
111
|
-
* @param closeSize - Size being closed as a non-negative magnitude.
|
|
112
|
-
* @public
|
|
113
|
-
*/
|
|
114
|
-
export declare function realizedPnlOnClose(params: {
|
|
115
|
-
entryPrice: number;
|
|
116
|
-
closePrice: number;
|
|
117
|
-
closeSize: number;
|
|
118
|
-
isLong: boolean;
|
|
119
|
-
}): number;
|
|
120
|
-
//# sourceMappingURL=positionMath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"positionMath.d.ts","sourceRoot":"","sources":["../../../src/utils/positionMath.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAErD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE;IACvD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;IACf,qBAAqB,EAAE,MAAM,CAAA;CAC9B,GAAG,MAAM,GAAG,SAAS,CAqBrB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;CAChB,GAAG,OAAO,CAQV;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,GAAG,SAAS,CAiBrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,GAAG,SAAS,CAarB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;CAChB,GAAG,MAAM,CAUT;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;CAChB,GAAG,MAAM,CAUT"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Off-grid resolution for {@link scaleToInteger}:
|
|
3
|
-
* - `truncate` — toward zero, for sizes and collateral amounts. The wire
|
|
4
|
-
* value never exceeds the caller's intent.
|
|
5
|
-
* - `round` — half away from zero, for prices, which snap to the nearest
|
|
6
|
-
* tick.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export type ScaleToIntegerPolicy = 'truncate' | 'round';
|
|
10
|
-
/**
|
|
11
|
-
* Scale a human-readable decimal string to a scaled integer in exact decimal
|
|
12
|
-
* arithmetic — an on-grid input maps to its exact scaled integer with no
|
|
13
|
-
* binary float artifacts (`'0.29'` at 2 decimals is 29, never 28).
|
|
14
|
-
* Off-grid input resolves per `policy`; there is no silent default.
|
|
15
|
-
*
|
|
16
|
-
* @throws {PerpsError} `ValidationError` when `value` is not a decimal
|
|
17
|
-
* numeric string, `decimals` is not a non-negative integer, or the scaled
|
|
18
|
-
* result's magnitude exceeds `Number.MAX_SAFE_INTEGER`.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
export declare const scaleToInteger: (value: string, decimals: number, policy: ScaleToIntegerPolicy) => number;
|
|
22
|
-
//# sourceMappingURL=scaleToInteger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scaleToInteger.d.ts","sourceRoot":"","sources":["../../../src/utils/scaleToInteger.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,OAAO,CAAA;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,EACb,UAAU,MAAM,EAChB,QAAQ,oBAAoB,KAC3B,MA0BF,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token unit conversion utilities.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Convert a base-unit amount (bigint string) to a human-readable decimal string.
|
|
6
|
-
*
|
|
7
|
-
* @param amount - Amount in base units (e.g. "1000000" for 1 USDC)
|
|
8
|
-
* @param decimals - Token decimals (e.g. 6 for USDC)
|
|
9
|
-
* @returns Decimal string (e.g. "1.0"); `"0"` when `amount` is not a valid
|
|
10
|
-
* bigint
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* fromBaseUnits('1000000', 6) // '1'
|
|
14
|
-
* ```
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export declare function fromBaseUnits(amount: string, decimals: number): string;
|
|
18
|
-
/**
|
|
19
|
-
* Convert a base-unit amount to a number.
|
|
20
|
-
*
|
|
21
|
-
* @param amount - Amount in base units
|
|
22
|
-
* @param decimals - Token decimals
|
|
23
|
-
* @returns Numeric value, or 0 if parsing fails
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export declare function fromBaseUnitsNumber(amount: string, decimals: number): number;
|
|
27
|
-
//# sourceMappingURL=units.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/utils/units.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMtE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG5E"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Order validation utilities.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Validate margin input against available balance and exchange minimums.
|
|
6
|
-
*
|
|
7
|
-
* @param margin - Margin amount in USD
|
|
8
|
-
* @param _leverage - Position leverage (reserved for future use)
|
|
9
|
-
* @param availableBalance - Available balance, or null if unknown
|
|
10
|
-
* @param _feeRate - Fee rate as decimal, or null if unknown (reserved for future use)
|
|
11
|
-
* @param minMarginUsd - Minimum margin requirement in USD (exchange-specific).
|
|
12
|
-
* Source this from the selected provider's `minOrderValueUsd` metadata
|
|
13
|
-
* (see `@lifi/perps-types` `Provider`) rather than a client-side constant.
|
|
14
|
-
* @returns Error code: 'insufficient' | 'below-minimum' | '' (valid)
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export declare function validateMargin(margin: number, _leverage: number, availableBalance: number | null, _feeRate: number | null, minMarginUsd: number): string;
|
|
18
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,YAAY,EAAE,MAAM,GACnB,MAAM,CAcR"}
|
package/src/utils/math.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type Big from 'big.js'
|
|
2
|
-
|
|
3
|
-
/** The larger of two Big values, as `Math.max` for numbers. */
|
|
4
|
-
export const maxOf = (a: Big, b: Big): Big => (a.gt(b) ? a : b)
|
|
5
|
-
|
|
6
|
-
/** The smaller of two Big values, as `Math.min` for numbers. */
|
|
7
|
-
export const minOf = (a: Big, b: Big): Big => (a.lt(b) ? a : b)
|
package/src/utils/orderEntry.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type Big from 'big.js'
|
|
2
|
-
import { TruncBig } from './decimal.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Base size the given margin buys at `leverage`: size = margin × leverage ÷ price.
|
|
6
|
-
* Truncates, so `size × price` never exceeds `margin × leverage`.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export function sizeFromMargin(margin: Big, leverage: number, price: Big): Big {
|
|
10
|
-
return new TruncBig(margin).times(leverage).div(price)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Margin that holds the given base size at `leverage`: margin = size × price ÷ leverage.
|
|
15
|
-
* Truncates, so `margin × leverage` never exceeds `size × price`.
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
export function marginFromSize(size: Big, leverage: number, price: Big): Big {
|
|
19
|
-
return new TruncBig(size).times(price).div(leverage)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Base size for a notional: size = notional ÷ price.
|
|
24
|
-
* Truncates, so `size × price` never exceeds the notional.
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
export function sizeFromNotional(notionalUsd: Big, price: Big): Big {
|
|
28
|
-
return new TruncBig(notionalUsd).div(price)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Margin for a notional at `leverage`: margin = notional ÷ leverage.
|
|
33
|
-
* Truncates, so `margin × leverage` never exceeds the notional.
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export function marginFromNotional(notionalUsd: Big, leverage: number): Big {
|
|
37
|
-
return new TruncBig(notionalUsd).div(leverage)
|
|
38
|
-
}
|
package/src/utils/orderMath.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OrderSide,
|
|
3
|
-
OrderStatus,
|
|
4
|
-
type Position,
|
|
5
|
-
PositionSide,
|
|
6
|
-
type RegularOrder,
|
|
7
|
-
type TriggerOrder,
|
|
8
|
-
} from '@lifi/perps-types'
|
|
9
|
-
import { isActiveOrderStatus } from './orderClassification.js'
|
|
10
|
-
import { realizedPnlOnClose } from './positionMath.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Pick the matching open position for an order's market, if any.
|
|
14
|
-
*
|
|
15
|
-
* @param marketId - The order's `market.id`.
|
|
16
|
-
* @param positions - Open positions list (any market).
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export function findMatchingPosition(
|
|
20
|
-
marketId: string,
|
|
21
|
-
positions: readonly Position[]
|
|
22
|
-
): Position | undefined {
|
|
23
|
-
return positions.find((p) => p.market.id === marketId)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Resolve the close-size against a position, applying the spec's cap rules:
|
|
28
|
-
* - `orderSize === 0` is the Hyperliquid convention for "close entire
|
|
29
|
-
* position" → close the full position size.
|
|
30
|
-
* - Otherwise cap at the absolute position size; an order larger than the
|
|
31
|
-
* position can only close what's open.
|
|
32
|
-
*
|
|
33
|
-
* Inputs are non-negative magnitudes.
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export function resolveCloseSize(
|
|
37
|
-
orderSize: number,
|
|
38
|
-
positionSize: number
|
|
39
|
-
): number {
|
|
40
|
-
if (orderSize === 0) {
|
|
41
|
-
return positionSize
|
|
42
|
-
}
|
|
43
|
-
return Math.min(orderSize, positionSize)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Expected rPnL for a resting limit order against a matching position.
|
|
48
|
-
*
|
|
49
|
-
* Reducing requires opposite sides (long position + SELL, short position +
|
|
50
|
-
* BUY). Same-side orders add to the position and have no rPnL → `null`.
|
|
51
|
-
* Projects `remainingSize`, because an already-filled quantity has realised
|
|
52
|
-
* its PnL at the fill price rather than at this order's limit price. A
|
|
53
|
-
* `remainingSize` of zero leaves nothing to project.
|
|
54
|
-
*
|
|
55
|
-
* @returns Realised PnL if the order would reduce the position, otherwise
|
|
56
|
-
* `null`.
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
export function expectedRealizedPnlForOpenOrder(
|
|
60
|
-
order: RegularOrder,
|
|
61
|
-
position: Position | undefined
|
|
62
|
-
): number | null {
|
|
63
|
-
if (!position || !isActiveOrderStatus(order.status)) {
|
|
64
|
-
return null
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const isLong = position.side === PositionSide.LONG
|
|
68
|
-
const reducesPosition =
|
|
69
|
-
(isLong && order.side === OrderSide.SELL) ||
|
|
70
|
-
(!isLong && order.side === OrderSide.BUY)
|
|
71
|
-
if (!reducesPosition) {
|
|
72
|
-
return null
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const limitPrice = Number.parseFloat(order.price ?? '')
|
|
76
|
-
const entryPrice = Number.parseFloat(position.entryPrice)
|
|
77
|
-
const orderSize = Math.abs(Number.parseFloat(order.remainingSize))
|
|
78
|
-
const positionSize = Math.abs(Number.parseFloat(position.size))
|
|
79
|
-
if (
|
|
80
|
-
!Number.isFinite(limitPrice) ||
|
|
81
|
-
!Number.isFinite(entryPrice) ||
|
|
82
|
-
!Number.isFinite(orderSize) ||
|
|
83
|
-
!Number.isFinite(positionSize) ||
|
|
84
|
-
positionSize <= 0
|
|
85
|
-
) {
|
|
86
|
-
return null
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// `resolveCloseSize` reads a zero size as "close the whole position", a
|
|
90
|
-
// convention that belongs to an order's submitted size. `remainingSize` is
|
|
91
|
-
// the unfilled quantity, so zero means nothing is left to fill.
|
|
92
|
-
if (orderSize === 0) {
|
|
93
|
-
return null
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const closeSize = resolveCloseSize(orderSize, positionSize)
|
|
97
|
-
return realizedPnlOnClose({
|
|
98
|
-
entryPrice,
|
|
99
|
-
closePrice: limitPrice,
|
|
100
|
-
closeSize,
|
|
101
|
-
isLong,
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Project the unfilled closing quantity of an active trigger at its trigger price. */
|
|
106
|
-
export function expectedRealizedPnlForTriggerOrder(
|
|
107
|
-
order: TriggerOrder,
|
|
108
|
-
position: Position | undefined
|
|
109
|
-
): number | null {
|
|
110
|
-
if (
|
|
111
|
-
!position ||
|
|
112
|
-
!isActiveOrderStatus(order.status) ||
|
|
113
|
-
order.status === OrderStatus.PENDING
|
|
114
|
-
) {
|
|
115
|
-
return null
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const isLong = position.side === PositionSide.LONG
|
|
119
|
-
if (
|
|
120
|
-
(isLong && order.side !== OrderSide.SELL) ||
|
|
121
|
-
(!isLong && order.side !== OrderSide.BUY)
|
|
122
|
-
) {
|
|
123
|
-
return null
|
|
124
|
-
}
|
|
125
|
-
const triggerPrice = Number.parseFloat(order.triggerPrice)
|
|
126
|
-
const entryPrice = Number.parseFloat(position.entryPrice)
|
|
127
|
-
const orderSize = Math.abs(Number.parseFloat(order.remainingSize))
|
|
128
|
-
const positionSize = Math.abs(Number.parseFloat(position.size))
|
|
129
|
-
if (
|
|
130
|
-
!Number.isFinite(triggerPrice) ||
|
|
131
|
-
!Number.isFinite(entryPrice) ||
|
|
132
|
-
!Number.isFinite(orderSize) ||
|
|
133
|
-
!Number.isFinite(positionSize) ||
|
|
134
|
-
positionSize <= 0
|
|
135
|
-
) {
|
|
136
|
-
return null
|
|
137
|
-
}
|
|
138
|
-
if (
|
|
139
|
-
orderSize === 0 &&
|
|
140
|
-
(Number.parseFloat(order.originalSize) !== 0 || !order.reduceOnly)
|
|
141
|
-
) {
|
|
142
|
-
return null
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const closeSize = resolveCloseSize(orderSize, positionSize)
|
|
146
|
-
return realizedPnlOnClose({
|
|
147
|
-
entryPrice,
|
|
148
|
-
closePrice: triggerPrice,
|
|
149
|
-
closeSize,
|
|
150
|
-
isLong,
|
|
151
|
-
})
|
|
152
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { PerpsErrorCode } from '@lifi/perps-types'
|
|
2
|
-
import Big from 'big.js'
|
|
3
|
-
import { PerpsError } from '../errors/PerpsError.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Off-grid resolution for {@link scaleToInteger}:
|
|
7
|
-
* - `truncate` — toward zero, for sizes and collateral amounts. The wire
|
|
8
|
-
* value never exceeds the caller's intent.
|
|
9
|
-
* - `round` — half away from zero, for prices, which snap to the nearest
|
|
10
|
-
* tick.
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export type ScaleToIntegerPolicy = 'truncate' | 'round'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Scale a human-readable decimal string to a scaled integer in exact decimal
|
|
17
|
-
* arithmetic — an on-grid input maps to its exact scaled integer with no
|
|
18
|
-
* binary float artifacts (`'0.29'` at 2 decimals is 29, never 28).
|
|
19
|
-
* Off-grid input resolves per `policy`; 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 const scaleToInteger = (
|
|
27
|
-
value: string,
|
|
28
|
-
decimals: number,
|
|
29
|
-
policy: ScaleToIntegerPolicy
|
|
30
|
-
): number => {
|
|
31
|
-
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
32
|
-
throw new PerpsError(
|
|
33
|
-
PerpsErrorCode.ValidationError,
|
|
34
|
-
`Invalid decimals for integer scaling: ${decimals}`
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
let parsed: Big
|
|
38
|
-
try {
|
|
39
|
-
parsed = new Big(value)
|
|
40
|
-
} catch {
|
|
41
|
-
throw new PerpsError(
|
|
42
|
-
PerpsErrorCode.ValidationError,
|
|
43
|
-
`Invalid decimal string for integer scaling: '${value}'`
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
const scaled = parsed
|
|
47
|
-
.times(new Big(10).pow(decimals))
|
|
48
|
-
.round(0, policy === 'truncate' ? Big.roundDown : Big.roundHalfUp)
|
|
49
|
-
if (scaled.abs().gt(Number.MAX_SAFE_INTEGER)) {
|
|
50
|
-
throw new PerpsError(
|
|
51
|
-
PerpsErrorCode.ValidationError,
|
|
52
|
-
`Scaled value ${scaled.toFixed()} exceeds Number.MAX_SAFE_INTEGER and cannot be encoded exactly.`
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
return scaled.toNumber()
|
|
56
|
-
}
|
package/src/utils/units.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token unit conversion utilities.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { formatUnits } from 'viem'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Convert a base-unit amount (bigint string) to a human-readable decimal string.
|
|
9
|
-
*
|
|
10
|
-
* @param amount - Amount in base units (e.g. "1000000" for 1 USDC)
|
|
11
|
-
* @param decimals - Token decimals (e.g. 6 for USDC)
|
|
12
|
-
* @returns Decimal string (e.g. "1.0"); `"0"` when `amount` is not a valid
|
|
13
|
-
* bigint
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* fromBaseUnits('1000000', 6) // '1'
|
|
17
|
-
* ```
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export function fromBaseUnits(amount: string, decimals: number): string {
|
|
21
|
-
try {
|
|
22
|
-
return formatUnits(BigInt(amount), decimals)
|
|
23
|
-
} catch {
|
|
24
|
-
return '0'
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Convert a base-unit amount to a number.
|
|
30
|
-
*
|
|
31
|
-
* @param amount - Amount in base units
|
|
32
|
-
* @param decimals - Token decimals
|
|
33
|
-
* @returns Numeric value, or 0 if parsing fails
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export function fromBaseUnitsNumber(amount: string, decimals: number): number {
|
|
37
|
-
const value = Number(fromBaseUnits(amount, decimals))
|
|
38
|
-
return Number.isFinite(value) ? value : 0
|
|
39
|
-
}
|