@lifi/perps-sdk-provider-ondo 9.0.0 → 10.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 +29 -0
- package/dist/cjs/OndoProvider.d.ts.map +1 -1
- package/dist/cjs/OndoProvider.js +26 -5
- package/dist/cjs/OndoProvider.js.map +1 -1
- package/dist/cjs/types/wire.d.ts +35 -0
- package/dist/cjs/types/wire.d.ts.map +1 -1
- package/dist/cjs/utils/depositAddress.d.ts.map +1 -1
- package/dist/cjs/utils/depositAddress.js +3 -0
- package/dist/cjs/utils/depositAddress.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/mapActivity.d.ts +5 -3
- package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
- package/dist/cjs/utils/mapActivity.js +70 -12
- package/dist/cjs/utils/mapActivity.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +4 -1
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
- package/dist/cjs/utils/mapOrder.js +4 -2
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/esm/OndoProvider.d.ts.map +1 -1
- package/dist/esm/OndoProvider.js +44 -6
- package/dist/esm/OndoProvider.js.map +1 -1
- package/dist/esm/types/wire.d.ts +53 -0
- package/dist/esm/types/wire.d.ts.map +1 -1
- package/dist/esm/utils/depositAddress.d.ts +3 -2
- package/dist/esm/utils/depositAddress.d.ts.map +1 -1
- package/dist/esm/utils/depositAddress.js +6 -2
- package/dist/esm/utils/depositAddress.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/mapActivity.d.ts +27 -6
- package/dist/esm/utils/mapActivity.d.ts.map +1 -1
- package/dist/esm/utils/mapActivity.js +93 -13
- package/dist/esm/utils/mapActivity.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +5 -1
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapOrder.d.ts +5 -1
- package/dist/esm/utils/mapOrder.d.ts.map +1 -1
- package/dist/esm/utils/mapOrder.js +10 -3
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/types/OndoProvider.d.ts.map +1 -1
- package/dist/types/types/wire.d.ts +53 -0
- package/dist/types/types/wire.d.ts.map +1 -1
- package/dist/types/utils/depositAddress.d.ts +3 -2
- package/dist/types/utils/depositAddress.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/mapActivity.d.ts +27 -6
- package/dist/types/utils/mapActivity.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/mapOrder.d.ts +5 -1
- package/dist/types/utils/mapOrder.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/OndoProvider.ts +78 -28
- package/src/types/wire.ts +63 -0
- package/src/utils/depositAddress.ts +6 -2
- package/src/utils/index.ts +6 -1
- package/src/utils/mapActivity.ts +106 -13
- package/src/utils/mapFill.ts +5 -1
- package/src/utils/mapOrder.ts +12 -3
package/src/utils/mapActivity.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
DepositActivity,
|
|
2
3
|
FundingActivity,
|
|
3
4
|
LiquidationActivity,
|
|
4
5
|
MarketDisplay,
|
|
6
|
+
WithdrawalActivity,
|
|
5
7
|
} from '@lifi/perps-types'
|
|
6
8
|
import { ActivityType } from '@lifi/perps-types'
|
|
7
9
|
import { ONDO_PROVIDER_KEY } from '../constants.js'
|
|
8
10
|
import type {
|
|
9
11
|
OndoFundingFeeTransfer,
|
|
10
12
|
OndoLiquidationEvent,
|
|
13
|
+
OndoWalletDeposit,
|
|
14
|
+
OndoWalletWithdrawal,
|
|
11
15
|
} from '../types/wire.js'
|
|
12
16
|
|
|
13
17
|
/**
|
|
@@ -37,25 +41,114 @@ export const mapFundingActivity = (
|
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
|
-
* Map an Ondo liquidation event to a {@link LiquidationActivity}
|
|
41
|
-
*
|
|
42
|
-
*
|
|
44
|
+
* Map an Ondo liquidation event to a {@link LiquidationActivity}, or `null`
|
|
45
|
+
* when the event names no triggering position. Ondo margin accounts are
|
|
46
|
+
* cross-only, so `leverageType` is always `'cross'`. Ondo reports no account
|
|
47
|
+
* value at liquidation time, so `accountValue` stays absent. One Ondo event
|
|
48
|
+
* carries the whole cross-margin cascade in `triggeringPositions`, so every
|
|
49
|
+
* liquidated market and size reaches `liquidatedPositions`.
|
|
43
50
|
*
|
|
44
51
|
* @public
|
|
45
52
|
*/
|
|
46
53
|
export const mapLiquidationActivity = (
|
|
47
54
|
event: OndoLiquidationEvent,
|
|
48
55
|
resolveMarket: (market: string) => MarketDisplay
|
|
49
|
-
): LiquidationActivity =>
|
|
50
|
-
|
|
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) => ({
|
|
56
|
+
): LiquidationActivity | null => {
|
|
57
|
+
const liquidatedPositions = (event.triggeringPositions ?? []).map((p) => ({
|
|
58
58
|
market: resolveMarket(p.market),
|
|
59
59
|
size: p.netQuantity,
|
|
60
|
-
}))
|
|
60
|
+
}))
|
|
61
|
+
if (liquidatedPositions.length === 0) {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
id: event.id,
|
|
66
|
+
provider: ONDO_PROVIDER_KEY,
|
|
67
|
+
timestamp: new Date(event.time).toISOString(),
|
|
68
|
+
type: ActivityType.LIQUIDATION,
|
|
69
|
+
...(event.filledQuoteSize === undefined
|
|
70
|
+
? {}
|
|
71
|
+
: { liquidatedNotionalPosition: event.filledQuoteSize }),
|
|
72
|
+
leverageType: 'cross',
|
|
73
|
+
liquidatedPositions,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Ondo reports no transaction id on a deposit it has not yet matched to a
|
|
78
|
+
// chain transaction, so two such deposits would share the bare `deposit:`
|
|
79
|
+
// key. Fall back to the fields the venue does report.
|
|
80
|
+
const depositId = (deposit: OndoWalletDeposit): string => {
|
|
81
|
+
if (deposit.txid === '') {
|
|
82
|
+
return `deposit:${deposit.time}:${deposit.coin}:${deposit.size}`
|
|
83
|
+
}
|
|
84
|
+
return deposit.logIndex === undefined
|
|
85
|
+
? `deposit:${deposit.txid}`
|
|
86
|
+
: `deposit:${deposit.txid}:${deposit.logIndex}`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Map an Ondo wallet deposit to a {@link DepositActivity}. Ondo carries no
|
|
91
|
+
* deposit id on the wire and addresses a single deposit by transaction id, so
|
|
92
|
+
* the id is `deposit:<txid>`, suffixed with `logIndex` when one transaction
|
|
93
|
+
* carried several deposits. `coin` is already a display symbol, so it is the
|
|
94
|
+
* normalized asset identity.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export const mapDepositActivity = (
|
|
99
|
+
deposit: OndoWalletDeposit
|
|
100
|
+
): DepositActivity => ({
|
|
101
|
+
id: depositId(deposit),
|
|
102
|
+
provider: ONDO_PROVIDER_KEY,
|
|
103
|
+
timestamp: new Date(deposit.time).toISOString(),
|
|
104
|
+
type: ActivityType.DEPOSIT,
|
|
105
|
+
asset: deposit.coin,
|
|
106
|
+
amount: deposit.size,
|
|
107
|
+
...(deposit.txid === ''
|
|
108
|
+
? {}
|
|
109
|
+
: { explorerLink: `https://scan.li.fi/tx/${deposit.txid}` }),
|
|
61
110
|
})
|
|
111
|
+
|
|
112
|
+
const SETTLING_WITHDRAWAL_STATUSES = new Set<string>([
|
|
113
|
+
'complete',
|
|
114
|
+
'pending',
|
|
115
|
+
'unknown',
|
|
116
|
+
])
|
|
117
|
+
|
|
118
|
+
/** Ondo denominates a withdrawal fee in USD, whatever asset it withdraws. */
|
|
119
|
+
const ONDO_WITHDRAWAL_FEE_SYMBOL = 'USD'
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Map an Ondo wallet withdrawal to a {@link WithdrawalActivity}, or `null`
|
|
123
|
+
* when the venue reports a status under which no value left the account. Ondo
|
|
124
|
+
* charges the fee in USD, so `fee.asset` is `USD` and not the withdrawn asset.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export const mapWithdrawalActivity = (
|
|
129
|
+
withdrawal: OndoWalletWithdrawal
|
|
130
|
+
): WithdrawalActivity | null => {
|
|
131
|
+
if (!SETTLING_WITHDRAWAL_STATUSES.has(withdrawal.status)) {
|
|
132
|
+
return null
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
id: withdrawal.withdrawal_id,
|
|
136
|
+
provider: ONDO_PROVIDER_KEY,
|
|
137
|
+
timestamp: new Date(withdrawal.time).toISOString(),
|
|
138
|
+
type: ActivityType.WITHDRAWAL,
|
|
139
|
+
asset: withdrawal.coin,
|
|
140
|
+
amount: withdrawal.size,
|
|
141
|
+
// Loose equality also drops a `null` the live API may send for "no fee".
|
|
142
|
+
...(withdrawal.usdFee == null
|
|
143
|
+
? {}
|
|
144
|
+
: {
|
|
145
|
+
fee: {
|
|
146
|
+
amount: withdrawal.usdFee,
|
|
147
|
+
asset: ONDO_WITHDRAWAL_FEE_SYMBOL,
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
...(withdrawal.txid === ''
|
|
151
|
+
? {}
|
|
152
|
+
: { explorerLink: `https://scan.li.fi/tx/${withdrawal.txid}` }),
|
|
153
|
+
}
|
|
154
|
+
}
|
package/src/utils/mapFill.ts
CHANGED
|
@@ -35,7 +35,11 @@ export const mapFill = (fill: OndoFill, market: MarketDisplay): Fill => ({
|
|
|
35
35
|
price: fill.price,
|
|
36
36
|
status: FillStatus.FILLED,
|
|
37
37
|
liquidity: fill.isMaker ? LiquidityRole.MAKER : LiquidityRole.TAKER,
|
|
38
|
-
|
|
38
|
+
// Ondo charges the fill fee in the market's quote asset.
|
|
39
|
+
fee: {
|
|
40
|
+
amount: new Big(fill.fee).minus(fill.feeRebate ?? '0').toFixed(),
|
|
41
|
+
asset: market.quoteAsset.displaySymbol,
|
|
42
|
+
},
|
|
39
43
|
realizedPnl: fill.pnl,
|
|
40
44
|
classification:
|
|
41
45
|
fill.direction !== undefined
|
package/src/utils/mapOrder.ts
CHANGED
|
@@ -22,6 +22,10 @@ const toIso = (time: string): string => new Date(time).toISOString()
|
|
|
22
22
|
const mapSide = (side: OndoOrder['side']): OrderSide =>
|
|
23
23
|
side === 'buy' ? OrderSide.BUY : OrderSide.SELL
|
|
24
24
|
|
|
25
|
+
/** Resting quantity: submitted size minus filled size, in base-asset units. */
|
|
26
|
+
const deriveRemainingSize = (size: string, filledSize: string): string =>
|
|
27
|
+
new Big(size).minus(filledSize).toFixed()
|
|
28
|
+
|
|
25
29
|
/** @public */
|
|
26
30
|
export const mapOrderType = (type: OndoOrderType): OrderType => {
|
|
27
31
|
switch (type) {
|
|
@@ -88,7 +92,11 @@ export const isTriggerOrder = (order: OndoOrder): boolean =>
|
|
|
88
92
|
order.stopOrderType !== undefined ||
|
|
89
93
|
order.triggerPrice !== undefined
|
|
90
94
|
|
|
91
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Map an active non-trigger Ondo order to an {@link OpenOrder}. Ondo reports
|
|
97
|
+
* the submitted and filled quantities only, so `remainingSize` is derived.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
92
100
|
export const mapOrder = (
|
|
93
101
|
order: OndoOrder,
|
|
94
102
|
market: MarketDisplay
|
|
@@ -97,7 +105,8 @@ export const mapOrder = (
|
|
|
97
105
|
market,
|
|
98
106
|
side: mapSide(order.side),
|
|
99
107
|
type: mapOrderType(order.type),
|
|
100
|
-
|
|
108
|
+
originalSize: new Big(order.size).toFixed(),
|
|
109
|
+
remainingSize: deriveRemainingSize(order.size, order.filledSize),
|
|
101
110
|
price: order.price,
|
|
102
111
|
filledSize: order.filledSize,
|
|
103
112
|
reduceOnly: order.reduceOnly ?? false,
|
|
@@ -177,7 +186,7 @@ export const mapOrderDetail = (
|
|
|
177
186
|
type: mapOrderType(order.type),
|
|
178
187
|
price: order.price,
|
|
179
188
|
originalSize: order.size,
|
|
180
|
-
remainingSize:
|
|
189
|
+
remainingSize: deriveRemainingSize(order.size, order.filledSize),
|
|
181
190
|
filledSize: order.filledSize,
|
|
182
191
|
timeInForce:
|
|
183
192
|
order.timeInForce === undefined
|