@lifi/perps-sdk-provider-ondo 0.0.0-preview-e466cdc → 0.0.0-preview-e0d34a1

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 (54) hide show
  1. package/README.md +9 -0
  2. package/dist/cjs/OndoProvider.d.ts.map +1 -1
  3. package/dist/cjs/OndoProvider.js +14 -9
  4. package/dist/cjs/OndoProvider.js.map +1 -1
  5. package/dist/cjs/types/wire.d.ts +15 -5
  6. package/dist/cjs/types/wire.d.ts.map +1 -1
  7. package/dist/cjs/utils/mapActivity.d.ts +1 -1
  8. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  9. package/dist/cjs/utils/mapActivity.js +18 -11
  10. package/dist/cjs/utils/mapActivity.js.map +1 -1
  11. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  12. package/dist/cjs/utils/mapOrder.js +2 -1
  13. package/dist/cjs/utils/mapOrder.js.map +1 -1
  14. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  15. package/dist/cjs/utils/mapPosition.js +1 -0
  16. package/dist/cjs/utils/mapPosition.js.map +1 -1
  17. package/dist/cjs/utils/mapTwap.d.ts.map +1 -1
  18. package/dist/cjs/utils/mapTwap.js +4 -7
  19. package/dist/cjs/utils/mapTwap.js.map +1 -1
  20. package/dist/esm/OndoProvider.d.ts.map +1 -1
  21. package/dist/esm/OndoProvider.js +25 -9
  22. package/dist/esm/OndoProvider.js.map +1 -1
  23. package/dist/esm/types/wire.d.ts +27 -6
  24. package/dist/esm/types/wire.d.ts.map +1 -1
  25. package/dist/esm/utils/mapActivity.d.ts +7 -4
  26. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  27. package/dist/esm/utils/mapActivity.js +24 -14
  28. package/dist/esm/utils/mapActivity.js.map +1 -1
  29. package/dist/esm/utils/mapOrder.d.ts +5 -1
  30. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  31. package/dist/esm/utils/mapOrder.js +7 -2
  32. package/dist/esm/utils/mapOrder.js.map +1 -1
  33. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  34. package/dist/esm/utils/mapPosition.js +1 -0
  35. package/dist/esm/utils/mapPosition.js.map +1 -1
  36. package/dist/esm/utils/mapTwap.d.ts.map +1 -1
  37. package/dist/esm/utils/mapTwap.js +6 -7
  38. package/dist/esm/utils/mapTwap.js.map +1 -1
  39. package/dist/types/OndoProvider.d.ts.map +1 -1
  40. package/dist/types/types/wire.d.ts +27 -6
  41. package/dist/types/types/wire.d.ts.map +1 -1
  42. package/dist/types/utils/mapActivity.d.ts +7 -4
  43. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  44. package/dist/types/utils/mapOrder.d.ts +5 -1
  45. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  46. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  47. package/dist/types/utils/mapTwap.d.ts.map +1 -1
  48. package/package.json +3 -3
  49. package/src/OndoProvider.ts +31 -13
  50. package/src/types/wire.ts +27 -6
  51. package/src/utils/mapActivity.ts +24 -14
  52. package/src/utils/mapOrder.ts +7 -2
  53. package/src/utils/mapPosition.ts +1 -0
  54. package/src/utils/mapTwap.ts +6 -7
@@ -37,25 +37,35 @@ export const mapFundingActivity = (
37
37
  }
38
38
 
39
39
  /**
40
- * Map an Ondo liquidation event to a {@link LiquidationActivity}. Ondo does
41
- * not report the account value at liquidation time, and its margin accounts
42
- * are cross-only, so `accountValue` is `'0'` and `leverageType` is `'cross'`.
40
+ * Map an Ondo liquidation event to a {@link LiquidationActivity}, or `null`
41
+ * when the event names no triggering position. Ondo margin accounts are
42
+ * cross-only, so `leverageType` is always `'cross'`. Ondo reports no account
43
+ * value at liquidation time, so `accountValue` stays absent. One Ondo event
44
+ * carries the whole cross-margin cascade in `triggeringPositions`, so every
45
+ * liquidated market and size reaches `liquidatedPositions`.
43
46
  *
44
47
  * @public
45
48
  */
46
49
  export const mapLiquidationActivity = (
47
50
  event: OndoLiquidationEvent,
48
51
  resolveMarket: (market: string) => MarketDisplay
49
- ): LiquidationActivity => ({
50
- id: event.id,
51
- provider: ONDO_PROVIDER_KEY,
52
- timestamp: new Date(event.time).toISOString(),
53
- type: ActivityType.LIQUIDATION,
54
- liquidatedNotionalPosition: event.filledQuoteSize ?? '0',
55
- accountValue: '0',
56
- leverageType: 'cross',
57
- liquidatedPositions: (event.triggeringPositions ?? []).map((p) => ({
52
+ ): LiquidationActivity | null => {
53
+ const liquidatedPositions = (event.triggeringPositions ?? []).map((p) => ({
58
54
  market: resolveMarket(p.market),
59
55
  size: p.netQuantity,
60
- })),
61
- })
56
+ }))
57
+ if (liquidatedPositions.length === 0) {
58
+ return null
59
+ }
60
+ return {
61
+ id: event.id,
62
+ provider: ONDO_PROVIDER_KEY,
63
+ timestamp: new Date(event.time).toISOString(),
64
+ type: ActivityType.LIQUIDATION,
65
+ ...(event.filledQuoteSize === undefined
66
+ ? {}
67
+ : { liquidatedNotionalPosition: event.filledQuoteSize }),
68
+ leverageType: 'cross',
69
+ liquidatedPositions,
70
+ }
71
+ }
@@ -88,7 +88,11 @@ export const isTriggerOrder = (order: OndoOrder): boolean =>
88
88
  order.stopOrderType !== undefined ||
89
89
  order.triggerPrice !== undefined
90
90
 
91
- /** Map an active non-trigger Ondo order to an {@link OpenOrder}. @public */
91
+ /**
92
+ * Map an active non-trigger Ondo order to an {@link OpenOrder}. Ondo reports
93
+ * the submitted and filled quantities only, so `remainingSize` is derived.
94
+ * @public
95
+ */
92
96
  export const mapOrder = (
93
97
  order: OndoOrder,
94
98
  market: MarketDisplay
@@ -97,7 +101,8 @@ export const mapOrder = (
97
101
  market,
98
102
  side: mapSide(order.side),
99
103
  type: mapOrderType(order.type),
100
- size: order.size,
104
+ originalSize: new Big(order.size).toFixed(),
105
+ remainingSize: new Big(order.size).minus(order.filledSize).toFixed(),
101
106
  price: order.price,
102
107
  filledSize: order.filledSize,
103
108
  reduceOnly: order.reduceOnly ?? false,
@@ -21,6 +21,7 @@ export const mapPosition = (
21
21
  markPrice: pos.markPrice,
22
22
  liquidationPrice: pos.liquidationPrice,
23
23
  unrealizedPnl: pos.unrealizedPnl,
24
+ accruedFunding: pos.netFundingSinceNeutral,
24
25
  leverage: Number.parseFloat(pos.leverage),
25
26
  marginUsed: pos.usedMargin,
26
27
  initialMarginRequirement: pos.usedMargin,
@@ -13,19 +13,18 @@ export const mapRunningTwap = (
13
13
  order: OndoTwapOrder,
14
14
  market: Market
15
15
  ): TwapOrder => {
16
- const filledSize = new Big(order.filledSize)
17
16
  return {
18
17
  twapId: order.twapId,
19
18
  market: toMarketDisplay(market),
20
19
  side: order.side === 'buy' ? OrderSide.BUY : OrderSide.SELL,
21
- totalSize: order.size,
20
+ totalSize: order.totalSize,
22
21
  filledSize: order.filledSize,
23
- ...(filledSize.eq(0)
22
+ // The venue reports `avgFilledPrice: '0'` before the first child fill,
23
+ // where the shared model omits the field.
24
+ ...(new Big(order.filledSize).eq(0)
24
25
  ? {}
25
- : {
26
- avgFillPrice: new Big(order.filledCost).div(filledSize).toString(),
27
- }),
28
- startedAt: new Date(order.createdAt).toISOString(),
26
+ : { avgFillPrice: order.avgFilledPrice }),
27
+ startedAt: new Date(order.startTime).toISOString(),
29
28
  durationSeconds: order.runningTime,
30
29
  status: TwapOrderStatus.RUNNING,
31
30
  }