@domfi/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +786 -0
  3. package/dist/actions.cjs +1 -0
  4. package/dist/actions.d.cts +17 -0
  5. package/dist/actions.d.ts +17 -0
  6. package/dist/actions.js +1 -0
  7. package/dist/api.cjs +1 -0
  8. package/dist/api.d.cts +664 -0
  9. package/dist/api.d.ts +664 -0
  10. package/dist/api.js +0 -0
  11. package/dist/chunk-2VSPOLVO.js +1 -0
  12. package/dist/chunk-5YZVCHRU.js +0 -0
  13. package/dist/chunk-77XMXAXE.js +1 -0
  14. package/dist/chunk-7OVWNPZQ.js +1 -0
  15. package/dist/chunk-BMYMNNJK.js +1 -0
  16. package/dist/chunk-C5Y2WM7C.js +1 -0
  17. package/dist/chunk-C64LJM7D.js +2 -0
  18. package/dist/chunk-CLOFJTBP.js +1 -0
  19. package/dist/chunk-CMREWGOI.js +1 -0
  20. package/dist/chunk-D5VE2O4F.js +1 -0
  21. package/dist/chunk-LDE3JHVE.js +1 -0
  22. package/dist/chunk-N4Q67DTE.js +1 -0
  23. package/dist/chunk-SZE5DE54.js +1 -0
  24. package/dist/chunk-XHQVWI2J.js +1 -0
  25. package/dist/chunk-YU5DN3PI.js +1 -0
  26. package/dist/config.cjs +2 -0
  27. package/dist/config.d.cts +132 -0
  28. package/dist/config.d.ts +132 -0
  29. package/dist/config.js +1 -0
  30. package/dist/contracts.cjs +1 -0
  31. package/dist/contracts.d.cts +13073 -0
  32. package/dist/contracts.d.ts +13073 -0
  33. package/dist/contracts.js +1 -0
  34. package/dist/delegation.cjs +1 -0
  35. package/dist/delegation.d.cts +7 -0
  36. package/dist/delegation.d.ts +7 -0
  37. package/dist/delegation.js +0 -0
  38. package/dist/errors.cjs +3 -0
  39. package/dist/errors.d.cts +155 -0
  40. package/dist/errors.d.ts +155 -0
  41. package/dist/errors.js +3 -0
  42. package/dist/index.cjs +2 -0
  43. package/dist/index.d.cts +216 -0
  44. package/dist/index.d.ts +216 -0
  45. package/dist/index.js +1 -0
  46. package/dist/math.cjs +1 -0
  47. package/dist/math.d.cts +273 -0
  48. package/dist/math.d.ts +273 -0
  49. package/dist/math.js +1 -0
  50. package/dist/position-BnhSFyGe.d.cts +56 -0
  51. package/dist/position-BnhSFyGe.d.ts +56 -0
  52. package/dist/rawSchemas-MAT7EZCV.js +1 -0
  53. package/dist/referrals.cjs +1 -0
  54. package/dist/referrals.d.cts +66 -0
  55. package/dist/referrals.d.ts +66 -0
  56. package/dist/referrals.js +1 -0
  57. package/dist/serde.cjs +1 -0
  58. package/dist/serde.d.cts +24 -0
  59. package/dist/serde.d.ts +24 -0
  60. package/dist/serde.js +1 -0
  61. package/dist/token.cjs +1 -0
  62. package/dist/token.d.cts +32 -0
  63. package/dist/token.d.ts +32 -0
  64. package/dist/token.js +0 -0
  65. package/dist/trading.cjs +1 -0
  66. package/dist/trading.d.cts +20 -0
  67. package/dist/trading.d.ts +20 -0
  68. package/dist/trading.js +1 -0
  69. package/dist/types-7s13ZSql.d.ts +533 -0
  70. package/dist/types-BK6dYOXr.d.cts +118 -0
  71. package/dist/types-CMtixBIP.d.cts +464 -0
  72. package/dist/types-DB1r_Ppi.d.ts +464 -0
  73. package/dist/types-DDgJiEFg.d.ts +780 -0
  74. package/dist/types-DJBX-p4X.d.cts +780 -0
  75. package/dist/types-DQft82W7.d.cts +533 -0
  76. package/dist/types-DhCzEwnS.d.ts +118 -0
  77. package/dist/types-veTDfbhq.d.ts +436 -0
  78. package/dist/types-x1MvxSdy.d.cts +436 -0
  79. package/dist/units-BYd75H7U.d.cts +22 -0
  80. package/dist/units-BYd75H7U.d.ts +22 -0
  81. package/dist/units.cjs +1 -0
  82. package/dist/units.d.cts +248 -0
  83. package/dist/units.d.ts +248 -0
  84. package/dist/units.js +1 -0
  85. package/dist/valuation.cjs +1 -0
  86. package/dist/valuation.d.cts +5 -0
  87. package/dist/valuation.d.ts +5 -0
  88. package/dist/valuation.js +1 -0
  89. package/dist/vault.cjs +1 -0
  90. package/dist/vault.d.cts +34 -0
  91. package/dist/vault.d.ts +34 -0
  92. package/dist/vault.js +1 -0
  93. package/package.json +181 -0
@@ -0,0 +1,273 @@
1
+ import { P as PercentP6, U as UsdP6 } from './units-BYd75H7U.cjs';
2
+ export { p as parseUnsignedPercentToP6 } from './units-BYd75H7U.cjs';
3
+ import { Z as TradeDirection } from './types-DJBX-p4X.cjs';
4
+ export { a9 as CheckClosePercentBoundsInput, aa as CheckGroupCollateralCapInput, ab as CheckLeverageBoundsInput, ac as CheckMaxCollateralInput, ad as CheckMinimumPositionSizeInput, ae as CheckOiCapInput, af as CheckSlippageBoundsInput, k as ConstraintCheckResult, ag as checkClosePercentBounds, ah as checkGroupCollateralCap, ai as checkLeverageBounds, aj as checkMaxCollateral, ak as checkMinimumPositionSize, al as checkOiCap, am as checkSlippageBounds } from './types-DJBX-p4X.cjs';
5
+ import { Price, Leverage, WholePercent, Collateral, SignedP18, SignedP6, FeePercent, UnsignedP18 } from './units.cjs';
6
+ export { L as LiquidationMarginInput, a as LiquidationPriceInput, M as MarkValueInput, P as PercentProfitInput, U as UnrealizedPnlInput, c as UnrealizedPnlPercentInput, d as currentPercentProfit, l as liquidationMarginRaw, b as liquidationPriceRaw, m as markValueFromPercentProfit, u as unrealizedPnlFromMarkValue, e as unrealizedPnlPercentFromMarkValue } from './position-BnhSFyGe.cjs';
7
+ import '@domfi/sdk/units';
8
+ import 'viem';
9
+ import '@domfi/sdk/errors';
10
+ import './types-DQft82W7.cjs';
11
+ import './errors.cjs';
12
+ import './referrals.cjs';
13
+
14
+ /** Solidity `1e2` scale. Leverage values use this scale: 100 == 1x. */
15
+ declare const PRECISION_2 = 100n;
16
+ /** Solidity `1e6` scale. Percent P6 values use this scale: 1% == 1_000_000. */
17
+ declare const PRECISION_6 = 1000000n;
18
+ /** Solidity `1e12` scale used to convert 1e18 open interest into 1e6 USD notional. */
19
+ declare const PRECISION_12 = 1000000000000n;
20
+ /** Solidity `1e18` scale for contract prices and high-precision ratios. */
21
+ declare const PRECISION_18 = 1000000000000000000n;
22
+ /** TradingCallbacksLib.BASE_SPREAD_P: flat 0.001% execution spread, in 1e18 units. */
23
+ declare const BASE_SPREAD_P = 10000000000000n;
24
+ /** TradingCallbacksLib.MAX_GAIN_P: max 900% PnL cap for TP correction. */
25
+ declare const MAX_GAIN_P = 900n;
26
+ /** Contract commit used to generate the checked-in action-critical vectors. */
27
+ declare const mathParityTarget: "domfi-core@a8bba32d92af1f44ae625e839e4ca420aefe89c2";
28
+
29
+ /** Inputs for converting a PnL percentage target into a trigger price. */
30
+ type PnlPercentPriceInput = {
31
+ basePrice: Price;
32
+ pnlPercent: PercentP6;
33
+ leverage: Leverage;
34
+ direction: TradeDirection;
35
+ };
36
+ /** Inputs for converting a price-delta percentage into a trigger price. */
37
+ type PriceDeltaPriceInput = {
38
+ basePrice: Price;
39
+ priceDeltaPercent: PercentP6;
40
+ direction: TradeDirection;
41
+ };
42
+ /** Inputs for computing max take-profit distance. */
43
+ type MaxTpDistanceInput = {
44
+ openPrice: Price;
45
+ leverage: Leverage;
46
+ initialLeverage: Leverage;
47
+ };
48
+ /** Inputs for computing max stop-loss distance. */
49
+ type MaxSlDistanceInput = {
50
+ openPrice: Price;
51
+ leverage: Leverage;
52
+ maxSlP: WholePercent;
53
+ };
54
+ /** Inputs for correcting a take-profit price into protocol bounds. */
55
+ type CorrectTpInput = MaxTpDistanceInput & {
56
+ takeProfit: Price;
57
+ direction: TradeDirection;
58
+ };
59
+ /** Inputs for correcting a stop-loss price into protocol bounds. */
60
+ type CorrectSlInput = MaxTpDistanceInput & {
61
+ stopLoss: Price;
62
+ direction: TradeDirection;
63
+ maxSlP: WholePercent;
64
+ };
65
+ /** Violation code returned by trigger price validation. */
66
+ type TriggerPriceViolationCode = "tp_wrong_side" | "tp_exceeds_max_distance" | "sl_wrong_side" | "sl_exceeds_max_distance";
67
+ /** Result of trigger price validation. */
68
+ type TriggerPriceValidationResult = {
69
+ status: "ok";
70
+ } | {
71
+ status: "violation";
72
+ code: TriggerPriceViolationCode;
73
+ message: string;
74
+ };
75
+ /** Inputs for validating take-profit and stop-loss prices together. */
76
+ type ValidateTriggerPricesInput = MaxTpDistanceInput & {
77
+ direction: TradeDirection;
78
+ maxSlP: WholePercent;
79
+ takeProfit?: Price;
80
+ stopLoss?: Price;
81
+ };
82
+ /** Convert an unsigned PnL percent target into a TP price using contract integer order. */
83
+ declare function tpPriceFromPnlPercent(input: PnlPercentPriceInput): Price;
84
+ /** Convert an unsigned PnL percent target into an SL price using contract integer order. */
85
+ declare function slPriceFromPnlPercent(input: PnlPercentPriceInput): Price;
86
+ /** Convert an unsigned raw price-delta percent into a TP price. */
87
+ declare function tpPriceFromPriceDelta(input: PriceDeltaPriceInput): Price;
88
+ /** Convert an unsigned raw price-delta percent into an SL price. */
89
+ declare function slPriceFromPriceDelta(input: PriceDeltaPriceInput): Price;
90
+ /** Max TP distance from open, derived from TradingCallbacksLib.correctTp. */
91
+ declare function maxTpDistance(input: MaxTpDistanceInput): Price;
92
+ /** Max SL distance from open, derived from TradingCallbacksLib.correctSl. */
93
+ declare function maxSlDistance(input: MaxSlDistanceInput): Price;
94
+ /** Mirror TradingCallbacksLib.correctTp for client-side action preflight. */
95
+ declare function correctTp(input: CorrectTpInput): Price;
96
+ /** Mirror TradingCallbacksLib.correctSl for client-side action preflight. */
97
+ declare function correctSl(input: CorrectSlInput): Price;
98
+ /** Mirror TradingCallbacksLib.correctToNullSl for client-side action preflight. */
99
+ declare function correctToNullSl(input: CorrectSlInput): Price;
100
+ /** Validate TP/SL side and max-distance constraints without throwing on ordinary violations. */
101
+ declare function validateTriggerPrices(input: ValidateTriggerPricesInput): TriggerPriceValidationResult;
102
+
103
+ /** Inputs for deriving USD notional from collateral and leverage. */
104
+ type NotionalFromCollateralInput = {
105
+ collateral: Collateral;
106
+ leverage: Leverage;
107
+ };
108
+ /** Inputs for deriving minimum collateral from requested USD notional and leverage. */
109
+ type CollateralFromNotionalInput = {
110
+ notionalUsd: UsdP6;
111
+ leverage: Leverage;
112
+ };
113
+ /** USD P6 notional from collateral and P2 leverage: collateral * leverage / 100. */
114
+ declare function notionalFromCollateral(input: NotionalFromCollateralInput): UsdP6;
115
+ /** Minimal collateral needed so notionalFromCollateral(result) is at least requested notional. */
116
+ declare function collateralFromNotional(input: CollateralFromNotionalInput): Collateral;
117
+
118
+ /** Inputs for recomputing leverage after adding collateral. */
119
+ type TopUpLeverageInput = {
120
+ collateral: Collateral;
121
+ leverage: Leverage;
122
+ topUpAmount: Collateral;
123
+ };
124
+ /** Inputs for recomputing leverage after removing collateral. */
125
+ type RemoveCollateralLeverageInput = {
126
+ collateral: Collateral;
127
+ leverage: Leverage;
128
+ removeAmount: Collateral;
129
+ };
130
+ /** Result of a collateral adjustment leverage recomputation. */
131
+ type CollateralAdjustmentLeverageResult = {
132
+ /** Leverage of the position after the adjustment. */
133
+ newLeverage: Leverage;
134
+ /** Collateral of the position after the adjustment. */
135
+ newCollateral: Collateral;
136
+ /** Collateral actually added/removed after the contract's recompute (the wallet delta). */
137
+ effectiveAmount: Collateral;
138
+ };
139
+ /** Inputs for finding the collateral delta needed to reach a target leverage. */
140
+ type ReachLeverageInput = {
141
+ collateral: Collateral;
142
+ leverage: Leverage;
143
+ targetLeverage: Leverage;
144
+ };
145
+ /**
146
+ * Result of a "reach target leverage" computation.
147
+ *
148
+ * `requestedAmount` is the value to pass to `topUpCollateral` / `removeCollateral` on-chain.
149
+ * The contract may transfer a slightly smaller amount after its leverage recompute, so the
150
+ * actual collateral delta applied to the position is `effectiveAmount` (and `newLeverage` /
151
+ * `newCollateral` describe the resulting position). `requestedAmount >= effectiveAmount`.
152
+ */
153
+ type ReachLeverageResult = CollateralAdjustmentLeverageResult & {
154
+ /** Amount to pass to `topUpCollateral` / `removeCollateral` on-chain; `>= effectiveAmount`. */
155
+ requestedAmount: Collateral;
156
+ };
157
+ /** Mirror DomfiTrading.topUpCollateral leverage/collateral recomputation including +1 remainder rule. */
158
+ declare function leverageAfterTopUp(input: TopUpLeverageInput): CollateralAdjustmentLeverageResult;
159
+ /**
160
+ * Collateral to add so a position's leverage drops to (at most) targetLeverage.
161
+ *
162
+ * Adding collateral lowers leverage, so targetLeverage must be below the current leverage.
163
+ * Returns the minimal {@link ReachLeverageResult.requestedAmount} to submit to
164
+ * `topUpCollateral`; the resulting leverage never exceeds targetLeverage. The canonical
165
+ * recompute is delegated to {@link leverageAfterTopUp}, so the outcome mirrors
166
+ * DomfiTrading.topUpCollateral exactly (including the +1 remainder rule).
167
+ *
168
+ * Note: leverage is quantized, so with small collateral the nearest achievable leverage may be
169
+ * strictly below targetLeverage. Protocol min/max leverage is not enforced here; use the
170
+ * constraint checks for that.
171
+ */
172
+ declare function topUpToReachLeverage(input: ReachLeverageInput): ReachLeverageResult;
173
+ /**
174
+ * Collateral that can be removed so a position's leverage rises to (at most) targetLeverage.
175
+ *
176
+ * Removing collateral raises leverage, so targetLeverage must be above the current leverage.
177
+ * Returns the maximum safe {@link ReachLeverageResult.requestedAmount} to submit to
178
+ * `removeCollateral` — the removal whose resulting leverage is closest to, but never above,
179
+ * targetLeverage. The canonical recompute is delegated to {@link leverageAfterRemoveCollateral},
180
+ * so the outcome mirrors DomfiTrading.removeCollateral exactly.
181
+ *
182
+ * Throws when no removal reaches above the current leverage without exceeding targetLeverage
183
+ * (leverage is quantized, so adjacent targets can be unreachable). Protocol min/max leverage is
184
+ * not enforced here; use the constraint checks for that.
185
+ */
186
+ declare function removeCollateralToReachLeverage(input: ReachLeverageInput): ReachLeverageResult;
187
+ /** Mirror DomfiTrading.removeCollateral leverage/collateral recomputation with no +1 remainder rule. */
188
+ declare function leverageAfterRemoveCollateral(input: RemoveCollateralLeverageInput): CollateralAdjustmentLeverageResult;
189
+
190
+ /** Inputs for computing a raw position funding fee from cumulative funding values. */
191
+ type PositionFundingFeeInput = {
192
+ initialAccFunding: SignedP18;
193
+ endAccFunding: SignedP18;
194
+ collateral: Collateral;
195
+ leverage: Leverage;
196
+ };
197
+ /** Computes the raw signed funding fee using contract integer ordering. */
198
+ declare function positionFundingFeeRaw(input: PositionFundingFeeInput): bigint;
199
+
200
+ /** Inputs for a flat single-rate trade fee calculation. */
201
+ type TradeFeeInput = {
202
+ collateral: Collateral;
203
+ leverage: Leverage;
204
+ feeP: FeePercent;
205
+ };
206
+ /**
207
+ * Flat single-rate trade fee from collateral, leverage, and one known fee percent. This is a
208
+ * guarded convenience helper (rejects non-positive leverage); use {@link openingFee} for the
209
+ * exact maker/taker model, which mirrors the contract view including its zero-leverage behavior.
210
+ */
211
+ declare function tradeFee(input: TradeFeeInput): Collateral;
212
+ /** Inputs for the maker/taker opening-fee calculation. */
213
+ type OpeningFeeInput = {
214
+ /** Signed P6 USD notional of the trade (long open positive, short open negative). */
215
+ tradeSize: SignedP6;
216
+ /** Signed P6 USD open-interest imbalance (oiLong - oiShort). */
217
+ oiDelta: SignedP6;
218
+ leverage: Leverage;
219
+ makerFeeP: FeePercent;
220
+ takerFeeP: FeePercent;
221
+ makerMaxLeverage: Leverage;
222
+ };
223
+ /**
224
+ * Maker/taker opening fee, mirroring DomfiPairInfos._getBaseOpeningFee. Returns the total base
225
+ * fee the trader pays; the contract's dev/vault split is an allocation of this same amount.
226
+ *
227
+ * When the trade reduces the OI imbalance (`oiDelta * tradeSize < 0`) and `leverage` is within
228
+ * `makerMaxLeverage`, the imbalance-reducing portion is charged `makerFeeP`; any portion that
229
+ * overshoots zero imbalance is charged `takerFeeP`. Otherwise the whole notional is taker. The
230
+ * same function computes closing fees: pass the closing fee params and the inverted tradeSize
231
+ * sign convention (long close negative, short close positive).
232
+ */
233
+ declare function openingFee(input: OpeningFeeInput): Collateral;
234
+
235
+ /** Inputs for contract-parity execution price impact calculation. */
236
+ type PriceImpactInput = {
237
+ price: Price;
238
+ /**
239
+ * Raw on-chain open interest (1e18 token notional). Source from `marketState.rawState.oiLong` /
240
+ * `oiShort` — NOT the display `longOpenInterest` / `shortOpenInterest`.
241
+ */
242
+ oiLong: UnsignedP18;
243
+ oiShort: UnsignedP18;
244
+ collateral: Collateral;
245
+ leverage: Leverage;
246
+ isOpen: boolean;
247
+ isLong: boolean;
248
+ };
249
+ /** Result of execution price impact calculation. */
250
+ type PriceImpactResult = {
251
+ /**
252
+ * Spread-adjusted execution price. For opens this is the price the contract stores as
253
+ * `openPrice`; for closes it is the execution price used to settle the close.
254
+ */
255
+ priceAfterImpact: Price;
256
+ /**
257
+ * Price-impact magnitude in the contract's guard scale (`withinMaxNegativePnlOnOpenP`):
258
+ * `|price - priceAfterImpact| * 1e20 / price`. Here 1% impact == 1e18 and 100% == 1e20.
259
+ */
260
+ priceImpactP: bigint;
261
+ };
262
+ /**
263
+ * Execution price after spread — a verbatim mirror of TradingCallbacksLib.getTradePriceImpact.
264
+ *
265
+ * NOTE: at the pinned contract commit the OI-skew scaling is inert. Integer truncation collapses
266
+ * `skew` to {-1, 0, 1} and the multiplier to 1, so the spread is a flat 0.001% (BASE_SPREAD_P)
267
+ * applied against the trader regardless of open interest. The oiLong/oiShort/collateral/leverage
268
+ * inputs therefore do not affect the result today; they are retained for exact parity and so this
269
+ * helper tracks the contract automatically if the skew bug is fixed.
270
+ */
271
+ declare function priceImpact(input: PriceImpactInput): PriceImpactResult;
272
+
273
+ export { BASE_SPREAD_P, type CollateralAdjustmentLeverageResult, type CollateralFromNotionalInput, type CorrectSlInput, type CorrectTpInput, MAX_GAIN_P, type MaxSlDistanceInput, type MaxTpDistanceInput, type NotionalFromCollateralInput, type OpeningFeeInput, PRECISION_12, PRECISION_18, PRECISION_2, PRECISION_6, PercentP6, type PnlPercentPriceInput, type PositionFundingFeeInput, type PriceDeltaPriceInput, type PriceImpactInput, type PriceImpactResult, type ReachLeverageInput, type ReachLeverageResult, type RemoveCollateralLeverageInput, type TopUpLeverageInput, type TradeFeeInput, type TriggerPriceValidationResult, type TriggerPriceViolationCode, UsdP6, type ValidateTriggerPricesInput, collateralFromNotional, correctSl, correctToNullSl, correctTp, leverageAfterRemoveCollateral, leverageAfterTopUp, mathParityTarget, maxSlDistance, maxTpDistance, notionalFromCollateral, openingFee, positionFundingFeeRaw, priceImpact, removeCollateralToReachLeverage, slPriceFromPnlPercent, slPriceFromPriceDelta, topUpToReachLeverage, tpPriceFromPnlPercent, tpPriceFromPriceDelta, tradeFee, validateTriggerPrices };
package/dist/math.d.ts ADDED
@@ -0,0 +1,273 @@
1
+ import { P as PercentP6, U as UsdP6 } from './units-BYd75H7U.js';
2
+ export { p as parseUnsignedPercentToP6 } from './units-BYd75H7U.js';
3
+ import { Z as TradeDirection } from './types-DDgJiEFg.js';
4
+ export { a9 as CheckClosePercentBoundsInput, aa as CheckGroupCollateralCapInput, ab as CheckLeverageBoundsInput, ac as CheckMaxCollateralInput, ad as CheckMinimumPositionSizeInput, ae as CheckOiCapInput, af as CheckSlippageBoundsInput, k as ConstraintCheckResult, ag as checkClosePercentBounds, ah as checkGroupCollateralCap, ai as checkLeverageBounds, aj as checkMaxCollateral, ak as checkMinimumPositionSize, al as checkOiCap, am as checkSlippageBounds } from './types-DDgJiEFg.js';
5
+ import { Price, Leverage, WholePercent, Collateral, SignedP18, SignedP6, FeePercent, UnsignedP18 } from './units.js';
6
+ export { L as LiquidationMarginInput, a as LiquidationPriceInput, M as MarkValueInput, P as PercentProfitInput, U as UnrealizedPnlInput, c as UnrealizedPnlPercentInput, d as currentPercentProfit, l as liquidationMarginRaw, b as liquidationPriceRaw, m as markValueFromPercentProfit, u as unrealizedPnlFromMarkValue, e as unrealizedPnlPercentFromMarkValue } from './position-BnhSFyGe.js';
7
+ import '@domfi/sdk/units';
8
+ import 'viem';
9
+ import '@domfi/sdk/errors';
10
+ import './types-7s13ZSql.js';
11
+ import './errors.js';
12
+ import './referrals.js';
13
+
14
+ /** Solidity `1e2` scale. Leverage values use this scale: 100 == 1x. */
15
+ declare const PRECISION_2 = 100n;
16
+ /** Solidity `1e6` scale. Percent P6 values use this scale: 1% == 1_000_000. */
17
+ declare const PRECISION_6 = 1000000n;
18
+ /** Solidity `1e12` scale used to convert 1e18 open interest into 1e6 USD notional. */
19
+ declare const PRECISION_12 = 1000000000000n;
20
+ /** Solidity `1e18` scale for contract prices and high-precision ratios. */
21
+ declare const PRECISION_18 = 1000000000000000000n;
22
+ /** TradingCallbacksLib.BASE_SPREAD_P: flat 0.001% execution spread, in 1e18 units. */
23
+ declare const BASE_SPREAD_P = 10000000000000n;
24
+ /** TradingCallbacksLib.MAX_GAIN_P: max 900% PnL cap for TP correction. */
25
+ declare const MAX_GAIN_P = 900n;
26
+ /** Contract commit used to generate the checked-in action-critical vectors. */
27
+ declare const mathParityTarget: "domfi-core@a8bba32d92af1f44ae625e839e4ca420aefe89c2";
28
+
29
+ /** Inputs for converting a PnL percentage target into a trigger price. */
30
+ type PnlPercentPriceInput = {
31
+ basePrice: Price;
32
+ pnlPercent: PercentP6;
33
+ leverage: Leverage;
34
+ direction: TradeDirection;
35
+ };
36
+ /** Inputs for converting a price-delta percentage into a trigger price. */
37
+ type PriceDeltaPriceInput = {
38
+ basePrice: Price;
39
+ priceDeltaPercent: PercentP6;
40
+ direction: TradeDirection;
41
+ };
42
+ /** Inputs for computing max take-profit distance. */
43
+ type MaxTpDistanceInput = {
44
+ openPrice: Price;
45
+ leverage: Leverage;
46
+ initialLeverage: Leverage;
47
+ };
48
+ /** Inputs for computing max stop-loss distance. */
49
+ type MaxSlDistanceInput = {
50
+ openPrice: Price;
51
+ leverage: Leverage;
52
+ maxSlP: WholePercent;
53
+ };
54
+ /** Inputs for correcting a take-profit price into protocol bounds. */
55
+ type CorrectTpInput = MaxTpDistanceInput & {
56
+ takeProfit: Price;
57
+ direction: TradeDirection;
58
+ };
59
+ /** Inputs for correcting a stop-loss price into protocol bounds. */
60
+ type CorrectSlInput = MaxTpDistanceInput & {
61
+ stopLoss: Price;
62
+ direction: TradeDirection;
63
+ maxSlP: WholePercent;
64
+ };
65
+ /** Violation code returned by trigger price validation. */
66
+ type TriggerPriceViolationCode = "tp_wrong_side" | "tp_exceeds_max_distance" | "sl_wrong_side" | "sl_exceeds_max_distance";
67
+ /** Result of trigger price validation. */
68
+ type TriggerPriceValidationResult = {
69
+ status: "ok";
70
+ } | {
71
+ status: "violation";
72
+ code: TriggerPriceViolationCode;
73
+ message: string;
74
+ };
75
+ /** Inputs for validating take-profit and stop-loss prices together. */
76
+ type ValidateTriggerPricesInput = MaxTpDistanceInput & {
77
+ direction: TradeDirection;
78
+ maxSlP: WholePercent;
79
+ takeProfit?: Price;
80
+ stopLoss?: Price;
81
+ };
82
+ /** Convert an unsigned PnL percent target into a TP price using contract integer order. */
83
+ declare function tpPriceFromPnlPercent(input: PnlPercentPriceInput): Price;
84
+ /** Convert an unsigned PnL percent target into an SL price using contract integer order. */
85
+ declare function slPriceFromPnlPercent(input: PnlPercentPriceInput): Price;
86
+ /** Convert an unsigned raw price-delta percent into a TP price. */
87
+ declare function tpPriceFromPriceDelta(input: PriceDeltaPriceInput): Price;
88
+ /** Convert an unsigned raw price-delta percent into an SL price. */
89
+ declare function slPriceFromPriceDelta(input: PriceDeltaPriceInput): Price;
90
+ /** Max TP distance from open, derived from TradingCallbacksLib.correctTp. */
91
+ declare function maxTpDistance(input: MaxTpDistanceInput): Price;
92
+ /** Max SL distance from open, derived from TradingCallbacksLib.correctSl. */
93
+ declare function maxSlDistance(input: MaxSlDistanceInput): Price;
94
+ /** Mirror TradingCallbacksLib.correctTp for client-side action preflight. */
95
+ declare function correctTp(input: CorrectTpInput): Price;
96
+ /** Mirror TradingCallbacksLib.correctSl for client-side action preflight. */
97
+ declare function correctSl(input: CorrectSlInput): Price;
98
+ /** Mirror TradingCallbacksLib.correctToNullSl for client-side action preflight. */
99
+ declare function correctToNullSl(input: CorrectSlInput): Price;
100
+ /** Validate TP/SL side and max-distance constraints without throwing on ordinary violations. */
101
+ declare function validateTriggerPrices(input: ValidateTriggerPricesInput): TriggerPriceValidationResult;
102
+
103
+ /** Inputs for deriving USD notional from collateral and leverage. */
104
+ type NotionalFromCollateralInput = {
105
+ collateral: Collateral;
106
+ leverage: Leverage;
107
+ };
108
+ /** Inputs for deriving minimum collateral from requested USD notional and leverage. */
109
+ type CollateralFromNotionalInput = {
110
+ notionalUsd: UsdP6;
111
+ leverage: Leverage;
112
+ };
113
+ /** USD P6 notional from collateral and P2 leverage: collateral * leverage / 100. */
114
+ declare function notionalFromCollateral(input: NotionalFromCollateralInput): UsdP6;
115
+ /** Minimal collateral needed so notionalFromCollateral(result) is at least requested notional. */
116
+ declare function collateralFromNotional(input: CollateralFromNotionalInput): Collateral;
117
+
118
+ /** Inputs for recomputing leverage after adding collateral. */
119
+ type TopUpLeverageInput = {
120
+ collateral: Collateral;
121
+ leverage: Leverage;
122
+ topUpAmount: Collateral;
123
+ };
124
+ /** Inputs for recomputing leverage after removing collateral. */
125
+ type RemoveCollateralLeverageInput = {
126
+ collateral: Collateral;
127
+ leverage: Leverage;
128
+ removeAmount: Collateral;
129
+ };
130
+ /** Result of a collateral adjustment leverage recomputation. */
131
+ type CollateralAdjustmentLeverageResult = {
132
+ /** Leverage of the position after the adjustment. */
133
+ newLeverage: Leverage;
134
+ /** Collateral of the position after the adjustment. */
135
+ newCollateral: Collateral;
136
+ /** Collateral actually added/removed after the contract's recompute (the wallet delta). */
137
+ effectiveAmount: Collateral;
138
+ };
139
+ /** Inputs for finding the collateral delta needed to reach a target leverage. */
140
+ type ReachLeverageInput = {
141
+ collateral: Collateral;
142
+ leverage: Leverage;
143
+ targetLeverage: Leverage;
144
+ };
145
+ /**
146
+ * Result of a "reach target leverage" computation.
147
+ *
148
+ * `requestedAmount` is the value to pass to `topUpCollateral` / `removeCollateral` on-chain.
149
+ * The contract may transfer a slightly smaller amount after its leverage recompute, so the
150
+ * actual collateral delta applied to the position is `effectiveAmount` (and `newLeverage` /
151
+ * `newCollateral` describe the resulting position). `requestedAmount >= effectiveAmount`.
152
+ */
153
+ type ReachLeverageResult = CollateralAdjustmentLeverageResult & {
154
+ /** Amount to pass to `topUpCollateral` / `removeCollateral` on-chain; `>= effectiveAmount`. */
155
+ requestedAmount: Collateral;
156
+ };
157
+ /** Mirror DomfiTrading.topUpCollateral leverage/collateral recomputation including +1 remainder rule. */
158
+ declare function leverageAfterTopUp(input: TopUpLeverageInput): CollateralAdjustmentLeverageResult;
159
+ /**
160
+ * Collateral to add so a position's leverage drops to (at most) targetLeverage.
161
+ *
162
+ * Adding collateral lowers leverage, so targetLeverage must be below the current leverage.
163
+ * Returns the minimal {@link ReachLeverageResult.requestedAmount} to submit to
164
+ * `topUpCollateral`; the resulting leverage never exceeds targetLeverage. The canonical
165
+ * recompute is delegated to {@link leverageAfterTopUp}, so the outcome mirrors
166
+ * DomfiTrading.topUpCollateral exactly (including the +1 remainder rule).
167
+ *
168
+ * Note: leverage is quantized, so with small collateral the nearest achievable leverage may be
169
+ * strictly below targetLeverage. Protocol min/max leverage is not enforced here; use the
170
+ * constraint checks for that.
171
+ */
172
+ declare function topUpToReachLeverage(input: ReachLeverageInput): ReachLeverageResult;
173
+ /**
174
+ * Collateral that can be removed so a position's leverage rises to (at most) targetLeverage.
175
+ *
176
+ * Removing collateral raises leverage, so targetLeverage must be above the current leverage.
177
+ * Returns the maximum safe {@link ReachLeverageResult.requestedAmount} to submit to
178
+ * `removeCollateral` — the removal whose resulting leverage is closest to, but never above,
179
+ * targetLeverage. The canonical recompute is delegated to {@link leverageAfterRemoveCollateral},
180
+ * so the outcome mirrors DomfiTrading.removeCollateral exactly.
181
+ *
182
+ * Throws when no removal reaches above the current leverage without exceeding targetLeverage
183
+ * (leverage is quantized, so adjacent targets can be unreachable). Protocol min/max leverage is
184
+ * not enforced here; use the constraint checks for that.
185
+ */
186
+ declare function removeCollateralToReachLeverage(input: ReachLeverageInput): ReachLeverageResult;
187
+ /** Mirror DomfiTrading.removeCollateral leverage/collateral recomputation with no +1 remainder rule. */
188
+ declare function leverageAfterRemoveCollateral(input: RemoveCollateralLeverageInput): CollateralAdjustmentLeverageResult;
189
+
190
+ /** Inputs for computing a raw position funding fee from cumulative funding values. */
191
+ type PositionFundingFeeInput = {
192
+ initialAccFunding: SignedP18;
193
+ endAccFunding: SignedP18;
194
+ collateral: Collateral;
195
+ leverage: Leverage;
196
+ };
197
+ /** Computes the raw signed funding fee using contract integer ordering. */
198
+ declare function positionFundingFeeRaw(input: PositionFundingFeeInput): bigint;
199
+
200
+ /** Inputs for a flat single-rate trade fee calculation. */
201
+ type TradeFeeInput = {
202
+ collateral: Collateral;
203
+ leverage: Leverage;
204
+ feeP: FeePercent;
205
+ };
206
+ /**
207
+ * Flat single-rate trade fee from collateral, leverage, and one known fee percent. This is a
208
+ * guarded convenience helper (rejects non-positive leverage); use {@link openingFee} for the
209
+ * exact maker/taker model, which mirrors the contract view including its zero-leverage behavior.
210
+ */
211
+ declare function tradeFee(input: TradeFeeInput): Collateral;
212
+ /** Inputs for the maker/taker opening-fee calculation. */
213
+ type OpeningFeeInput = {
214
+ /** Signed P6 USD notional of the trade (long open positive, short open negative). */
215
+ tradeSize: SignedP6;
216
+ /** Signed P6 USD open-interest imbalance (oiLong - oiShort). */
217
+ oiDelta: SignedP6;
218
+ leverage: Leverage;
219
+ makerFeeP: FeePercent;
220
+ takerFeeP: FeePercent;
221
+ makerMaxLeverage: Leverage;
222
+ };
223
+ /**
224
+ * Maker/taker opening fee, mirroring DomfiPairInfos._getBaseOpeningFee. Returns the total base
225
+ * fee the trader pays; the contract's dev/vault split is an allocation of this same amount.
226
+ *
227
+ * When the trade reduces the OI imbalance (`oiDelta * tradeSize < 0`) and `leverage` is within
228
+ * `makerMaxLeverage`, the imbalance-reducing portion is charged `makerFeeP`; any portion that
229
+ * overshoots zero imbalance is charged `takerFeeP`. Otherwise the whole notional is taker. The
230
+ * same function computes closing fees: pass the closing fee params and the inverted tradeSize
231
+ * sign convention (long close negative, short close positive).
232
+ */
233
+ declare function openingFee(input: OpeningFeeInput): Collateral;
234
+
235
+ /** Inputs for contract-parity execution price impact calculation. */
236
+ type PriceImpactInput = {
237
+ price: Price;
238
+ /**
239
+ * Raw on-chain open interest (1e18 token notional). Source from `marketState.rawState.oiLong` /
240
+ * `oiShort` — NOT the display `longOpenInterest` / `shortOpenInterest`.
241
+ */
242
+ oiLong: UnsignedP18;
243
+ oiShort: UnsignedP18;
244
+ collateral: Collateral;
245
+ leverage: Leverage;
246
+ isOpen: boolean;
247
+ isLong: boolean;
248
+ };
249
+ /** Result of execution price impact calculation. */
250
+ type PriceImpactResult = {
251
+ /**
252
+ * Spread-adjusted execution price. For opens this is the price the contract stores as
253
+ * `openPrice`; for closes it is the execution price used to settle the close.
254
+ */
255
+ priceAfterImpact: Price;
256
+ /**
257
+ * Price-impact magnitude in the contract's guard scale (`withinMaxNegativePnlOnOpenP`):
258
+ * `|price - priceAfterImpact| * 1e20 / price`. Here 1% impact == 1e18 and 100% == 1e20.
259
+ */
260
+ priceImpactP: bigint;
261
+ };
262
+ /**
263
+ * Execution price after spread — a verbatim mirror of TradingCallbacksLib.getTradePriceImpact.
264
+ *
265
+ * NOTE: at the pinned contract commit the OI-skew scaling is inert. Integer truncation collapses
266
+ * `skew` to {-1, 0, 1} and the multiplier to 1, so the spread is a flat 0.001% (BASE_SPREAD_P)
267
+ * applied against the trader regardless of open interest. The oiLong/oiShort/collateral/leverage
268
+ * inputs therefore do not affect the result today; they are retained for exact parity and so this
269
+ * helper tracks the contract automatically if the skew bug is fixed.
270
+ */
271
+ declare function priceImpact(input: PriceImpactInput): PriceImpactResult;
272
+
273
+ export { BASE_SPREAD_P, type CollateralAdjustmentLeverageResult, type CollateralFromNotionalInput, type CorrectSlInput, type CorrectTpInput, MAX_GAIN_P, type MaxSlDistanceInput, type MaxTpDistanceInput, type NotionalFromCollateralInput, type OpeningFeeInput, PRECISION_12, PRECISION_18, PRECISION_2, PRECISION_6, PercentP6, type PnlPercentPriceInput, type PositionFundingFeeInput, type PriceDeltaPriceInput, type PriceImpactInput, type PriceImpactResult, type ReachLeverageInput, type ReachLeverageResult, type RemoveCollateralLeverageInput, type TopUpLeverageInput, type TradeFeeInput, type TriggerPriceValidationResult, type TriggerPriceViolationCode, UsdP6, type ValidateTriggerPricesInput, collateralFromNotional, correctSl, correctToNullSl, correctTp, leverageAfterRemoveCollateral, leverageAfterTopUp, mathParityTarget, maxSlDistance, maxTpDistance, notionalFromCollateral, openingFee, positionFundingFeeRaw, priceImpact, removeCollateralToReachLeverage, slPriceFromPnlPercent, slPriceFromPriceDelta, topUpToReachLeverage, tpPriceFromPnlPercent, tpPriceFromPriceDelta, tradeFee, validateTriggerPrices };
package/dist/math.js ADDED
@@ -0,0 +1 @@
1
+ export{a as positionFundingFeeRaw}from'./chunk-CLOFJTBP.js';export{k as PercentP6,l as UsdP6,g as checkClosePercentBounds,e as checkGroupCollateralCap,a as checkLeverageBounds,c as checkMaxCollateral,b as checkMinimumPositionSize,d as checkOiCap,f as checkSlippageBounds,o as collateralFromNotional,w as correctSl,x as correctToNullSl,v as correctTp,u as maxSlDistance,t as maxTpDistance,n as notionalFromCollateral,i as openingFee,m as parseUnsignedPercentToP6,j as priceImpact,q as slPriceFromPnlPercent,s as slPriceFromPriceDelta,p as tpPriceFromPnlPercent,r as tpPriceFromPriceDelta,h as tradeFee,y as validateTriggerPrices}from'./chunk-7OVWNPZQ.js';import {h,j,b}from'./chunk-SZE5DE54.js';export{e as BASE_SPREAD_P,f as MAX_GAIN_P,c as PRECISION_12,d as PRECISION_18,a as PRECISION_2,b as PRECISION_6,k as currentPercentProfit,m as liquidationMarginRaw,n as liquidationPriceRaw,l as markValueFromPercentProfit,g as mathParityTarget,o as unrealizedPnlFromMarkValue,p as unrealizedPnlPercentFromMarkValue}from'./chunk-SZE5DE54.js';import {g,k}from'./chunk-C5Y2WM7C.js';function w(r){let e=g.toRaw(r.collateral),l=k.toRaw(r.leverage),a=g.toRaw(r.topUpAmount);h(e,"collateral"),h(l,"leverage"),h(a,"topUpAmount");let m=j(e,l,100n),t=e+a,c=m*b,i=t*10000n,g$1=c/i,p=a;if(g$1<=0n)throw new Error("newLeverage must be positive");if(c%i!==0n){if(g$1+=1n,t=m*100n/g$1,t<=e)throw new Error("topUpAmount cannot produce valid collateral");p=t-e;}return {newLeverage:k.fromRaw(g$1),newCollateral:g.fromRaw(t),effectiveAmount:g.fromRaw(p)}}function te(r){let e=g.toRaw(r.collateral),l=k.toRaw(r.leverage),a=k.toRaw(r.targetLeverage);if(h(e,"collateral"),h(l,"leverage"),h(a,"targetLeverage"),a>=l)throw new Error("targetLeverage must be below current leverage to add collateral");let t=j(e,l,100n)*100n,c=t/(e+1n),i=a<c?a:c;if(i<=0n)throw new Error("targetLeverage not reachable by adding collateral");let p=j(t,1n,i)-e;if(p<=0n)throw new Error("targetLeverage not reachable by adding collateral");return {...w({collateral:r.collateral,leverage:r.leverage,topUpAmount:g.fromRaw(p)}),requestedAmount:g.fromRaw(p)}}function ae(r){let e=g.toRaw(r.collateral),l=k.toRaw(r.leverage),a=k.toRaw(r.targetLeverage);if(h(e,"collateral"),h(l,"leverage"),h(a,"targetLeverage"),a<=l)throw new Error("targetLeverage must be above current leverage to remove collateral");let t=j(e,l,100n)*100n,c=t/(a+1n)+1n,i=e-c;if(i<=0n)throw new Error("targetLeverage not reachable by removing collateral");let g$1=t/c;if(g$1<=l)throw new Error("targetLeverage not reachable by removing collateral");if(t%c!==0n&&t/g$1>=e)throw new Error("targetLeverage not reachable by removing collateral");return {...C({collateral:r.collateral,leverage:r.leverage,removeAmount:g.fromRaw(i)}),requestedAmount:g.fromRaw(i)}}function C(r){let e=g.toRaw(r.collateral),l=k.toRaw(r.leverage),a=g.toRaw(r.removeAmount);if(h(e,"collateral"),h(l,"leverage"),h(a,"removeAmount"),a>=e)throw new Error("removeAmount must be below collateral");let m=j(e,l,100n),t=e-a,c=m*b,i=t*10000n,g$1=c/i,p=a;if(g$1<=0n)throw new Error("newLeverage must be positive");if(c%i!==0n){if(t=m*100n/g$1,t>=e)throw new Error("removeAmount cannot produce valid collateral");p=e-t;}return {newLeverage:k.fromRaw(g$1),newCollateral:g.fromRaw(t),effectiveAmount:g.fromRaw(p)}}export{C as leverageAfterRemoveCollateral,w as leverageAfterTopUp,ae as removeCollateralToReachLeverage,te as topUpToReachLeverage};
@@ -0,0 +1,56 @@
1
+ /** Raw protocol inputs for current percent-profit calculation. */
2
+ type PercentProfitInput = {
3
+ openPriceRaw: bigint;
4
+ markPriceRaw: bigint;
5
+ buy: boolean;
6
+ leverageRaw: bigint | number;
7
+ initialLeverageRaw: bigint | number;
8
+ };
9
+ /** Raw protocol inputs for mark-value calculation. */
10
+ type MarkValueInput = {
11
+ collateralRaw: bigint;
12
+ percentProfitRaw: bigint;
13
+ fundingFeeRaw: bigint;
14
+ liquidationMarginRaw: bigint;
15
+ };
16
+ /** Raw protocol inputs for liquidation-margin calculation. */
17
+ type LiquidationMarginInput = {
18
+ collateralRaw: bigint;
19
+ leverageRaw: bigint | number;
20
+ maxLeverageRaw: bigint | number;
21
+ liqMarginThresholdP: bigint | number;
22
+ };
23
+ /** Raw protocol inputs for liquidation-price calculation. */
24
+ type LiquidationPriceInput = LiquidationMarginInput & {
25
+ openPriceRaw: bigint;
26
+ buy: boolean;
27
+ fundingFeeRaw: bigint;
28
+ };
29
+ /** Raw protocol inputs for unrealized PnL calculation. */
30
+ type UnrealizedPnlInput = {
31
+ collateralRaw: bigint;
32
+ markValueRaw: bigint;
33
+ };
34
+ /** Raw protocol inputs for unrealized PnL percentage calculation. */
35
+ type UnrealizedPnlPercentInput = {
36
+ collateralRaw: bigint;
37
+ markValueRaw: bigint;
38
+ };
39
+ /** Computes current percent profit in P6 percent scale, capped at protocol max gain. */
40
+ declare function currentPercentProfit(input: PercentProfitInput): bigint;
41
+ /** Computes mark value after percent profit, funding fee, and liquidation-margin floor. */
42
+ declare function markValueFromPercentProfit(input: MarkValueInput): bigint;
43
+ /** Computes DomfiPairInfos.getTradeLiquidationMargin with Solidity integer rounding. */
44
+ declare function liquidationMarginRaw(input: LiquidationMarginInput): bigint;
45
+ /** Computes DomfiPairInfos.getTradeLiquidationPricePure with Solidity integer rounding. */
46
+ declare function liquidationPriceRaw(input: LiquidationPriceInput): bigint;
47
+ /** Computes raw unrealized PnL from mark value and collateral. */
48
+ declare function unrealizedPnlFromMarkValue(input: UnrealizedPnlInput): bigint;
49
+ /**
50
+ * Net unrealized PnL as a signed percent of collateral in P6 scale (1% == 1_000_000), floored
51
+ * at -100%. Because markValueFromPercentProfit already nets funding (and floors to zero at the
52
+ * liquidation margin), this percent likewise reflects funding and bottoms out at a total loss.
53
+ */
54
+ declare function unrealizedPnlPercentFromMarkValue(input: UnrealizedPnlPercentInput): bigint;
55
+
56
+ export { type LiquidationMarginInput as L, type MarkValueInput as M, type PercentProfitInput as P, type UnrealizedPnlInput as U, type LiquidationPriceInput as a, liquidationPriceRaw as b, type UnrealizedPnlPercentInput as c, currentPercentProfit as d, unrealizedPnlPercentFromMarkValue as e, liquidationMarginRaw as l, markValueFromPercentProfit as m, unrealizedPnlFromMarkValue as u };
@@ -0,0 +1,56 @@
1
+ /** Raw protocol inputs for current percent-profit calculation. */
2
+ type PercentProfitInput = {
3
+ openPriceRaw: bigint;
4
+ markPriceRaw: bigint;
5
+ buy: boolean;
6
+ leverageRaw: bigint | number;
7
+ initialLeverageRaw: bigint | number;
8
+ };
9
+ /** Raw protocol inputs for mark-value calculation. */
10
+ type MarkValueInput = {
11
+ collateralRaw: bigint;
12
+ percentProfitRaw: bigint;
13
+ fundingFeeRaw: bigint;
14
+ liquidationMarginRaw: bigint;
15
+ };
16
+ /** Raw protocol inputs for liquidation-margin calculation. */
17
+ type LiquidationMarginInput = {
18
+ collateralRaw: bigint;
19
+ leverageRaw: bigint | number;
20
+ maxLeverageRaw: bigint | number;
21
+ liqMarginThresholdP: bigint | number;
22
+ };
23
+ /** Raw protocol inputs for liquidation-price calculation. */
24
+ type LiquidationPriceInput = LiquidationMarginInput & {
25
+ openPriceRaw: bigint;
26
+ buy: boolean;
27
+ fundingFeeRaw: bigint;
28
+ };
29
+ /** Raw protocol inputs for unrealized PnL calculation. */
30
+ type UnrealizedPnlInput = {
31
+ collateralRaw: bigint;
32
+ markValueRaw: bigint;
33
+ };
34
+ /** Raw protocol inputs for unrealized PnL percentage calculation. */
35
+ type UnrealizedPnlPercentInput = {
36
+ collateralRaw: bigint;
37
+ markValueRaw: bigint;
38
+ };
39
+ /** Computes current percent profit in P6 percent scale, capped at protocol max gain. */
40
+ declare function currentPercentProfit(input: PercentProfitInput): bigint;
41
+ /** Computes mark value after percent profit, funding fee, and liquidation-margin floor. */
42
+ declare function markValueFromPercentProfit(input: MarkValueInput): bigint;
43
+ /** Computes DomfiPairInfos.getTradeLiquidationMargin with Solidity integer rounding. */
44
+ declare function liquidationMarginRaw(input: LiquidationMarginInput): bigint;
45
+ /** Computes DomfiPairInfos.getTradeLiquidationPricePure with Solidity integer rounding. */
46
+ declare function liquidationPriceRaw(input: LiquidationPriceInput): bigint;
47
+ /** Computes raw unrealized PnL from mark value and collateral. */
48
+ declare function unrealizedPnlFromMarkValue(input: UnrealizedPnlInput): bigint;
49
+ /**
50
+ * Net unrealized PnL as a signed percent of collateral in P6 scale (1% == 1_000_000), floored
51
+ * at -100%. Because markValueFromPercentProfit already nets funding (and floors to zero at the
52
+ * liquidation margin), this percent likewise reflects funding and bottoms out at a total loss.
53
+ */
54
+ declare function unrealizedPnlPercentFromMarkValue(input: UnrealizedPnlPercentInput): bigint;
55
+
56
+ export { type LiquidationMarginInput as L, type MarkValueInput as M, type PercentProfitInput as P, type UnrealizedPnlInput as U, type LiquidationPriceInput as a, liquidationPriceRaw as b, type UnrealizedPnlPercentInput as c, currentPercentProfit as d, unrealizedPnlPercentFromMarkValue as e, liquidationMarginRaw as l, markValueFromPercentProfit as m, unrealizedPnlFromMarkValue as u };