@lifi/perps-sdk-provider-ondo 21.0.0 → 22.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 +2 -1
- package/dist/cjs/OndoProvider.d.ts.map +1 -1
- package/dist/cjs/OndoProvider.js +31 -7
- package/dist/cjs/OndoProvider.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +4 -5
- 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 +8 -10
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +2 -5
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.js +1 -0
- package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
- package/dist/cjs/websocket/OndoWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/OndoWsProvider.js.map +1 -1
- package/dist/esm/OndoProvider.d.ts.map +1 -1
- package/dist/esm/OndoProvider.js +31 -9
- package/dist/esm/OndoProvider.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +4 -2
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapOrder.d.ts.map +1 -1
- package/dist/esm/utils/mapOrder.js +8 -7
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +2 -2
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/utils/withdrawableBalances.d.ts +3 -2
- package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/esm/utils/withdrawableBalances.js +4 -2
- package/dist/esm/utils/withdrawableBalances.js.map +1 -1
- package/dist/esm/websocket/OndoWsProvider.d.ts +1 -2
- package/dist/esm/websocket/OndoWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/OndoWsProvider.js +1 -2
- package/dist/esm/websocket/OndoWsProvider.js.map +1 -1
- package/dist/types/OndoProvider.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/mapOrder.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/utils/withdrawableBalances.d.ts +3 -2
- package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/types/websocket/OndoWsProvider.d.ts +1 -2
- package/dist/types/websocket/OndoWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/OndoProvider.ts +68 -14
- package/src/utils/mapFill.ts +4 -2
- package/src/utils/mapOrder.ts +8 -7
- package/src/utils/mapPosition.ts +2 -2
- package/src/utils/withdrawableBalances.ts +4 -2
- package/src/websocket/OndoWsProvider.ts +1 -2
package/src/OndoProvider.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
getMarketRegistry,
|
|
9
9
|
getProviders,
|
|
10
10
|
localStorageAdapter,
|
|
11
|
+
maxOf,
|
|
12
|
+
minOf,
|
|
11
13
|
PerpsError,
|
|
12
14
|
type PerpsProviderPlugin,
|
|
13
15
|
type PerpsSDKClient,
|
|
@@ -17,6 +19,7 @@ import {
|
|
|
17
19
|
type ProviderGetAvailableToTradeParams,
|
|
18
20
|
type ProviderGetDepositFlowParams,
|
|
19
21
|
type ProviderGetFillsParams,
|
|
22
|
+
type ProviderGetMarketSettingsParams,
|
|
20
23
|
type ProviderGetOrderParams,
|
|
21
24
|
type ProviderGetOrdersParams,
|
|
22
25
|
type ProviderGetPortfolioHistoryParams,
|
|
@@ -51,6 +54,7 @@ import type {
|
|
|
51
54
|
FundingActivity,
|
|
52
55
|
LiquidationActivity,
|
|
53
56
|
MarketDisplay,
|
|
57
|
+
MarketSettings,
|
|
54
58
|
OndoAccountConfig,
|
|
55
59
|
Order,
|
|
56
60
|
OrdersResponse,
|
|
@@ -64,8 +68,13 @@ import type {
|
|
|
64
68
|
SigningMethod,
|
|
65
69
|
WithdrawalActivity,
|
|
66
70
|
} from '@lifi/perps-types'
|
|
67
|
-
import {
|
|
68
|
-
|
|
71
|
+
import {
|
|
72
|
+
ActionType,
|
|
73
|
+
ActivityType,
|
|
74
|
+
MarginMode,
|
|
75
|
+
PerpsErrorCode,
|
|
76
|
+
} from '@lifi/perps-types'
|
|
77
|
+
import Big from 'big.js'
|
|
69
78
|
import { type Address, getAddress } from 'viem'
|
|
70
79
|
import { projectOndoConfigSettings } from './accountConfig.js'
|
|
71
80
|
import { getAccountSummary } from './accountSummary.js'
|
|
@@ -137,13 +146,6 @@ import {
|
|
|
137
146
|
type OrderSource,
|
|
138
147
|
} from './utils/orderCursor.js'
|
|
139
148
|
|
|
140
|
-
const transferableWithin = (venueFigure: Big, units: Big): string => {
|
|
141
|
-
if (venueFigure.lt(0)) {
|
|
142
|
-
return '0'
|
|
143
|
-
}
|
|
144
|
-
return (venueFigure.gt(units) ? units : venueFigure).toFixed()
|
|
145
|
-
}
|
|
146
|
-
|
|
147
149
|
/**
|
|
148
150
|
* Construction options for the Ondo {@link PerpsProviderPlugin}.
|
|
149
151
|
*
|
|
@@ -371,13 +373,16 @@ export const ondoProvider = (
|
|
|
371
373
|
units: balance.walletBalance,
|
|
372
374
|
valueUsd: balance.walletBalance,
|
|
373
375
|
price: '1',
|
|
374
|
-
transferable:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
376
|
+
transferable: minOf(
|
|
377
|
+
maxOf(
|
|
378
|
+
toWireBig(
|
|
379
|
+
balance.withdrawableMargin,
|
|
380
|
+
'balance.withdrawableMargin'
|
|
381
|
+
),
|
|
382
|
+
new Big(0)
|
|
378
383
|
),
|
|
379
384
|
walletBalance
|
|
380
|
-
),
|
|
385
|
+
).toFixed(),
|
|
381
386
|
},
|
|
382
387
|
]
|
|
383
388
|
: [],
|
|
@@ -436,6 +441,55 @@ export const ondoProvider = (
|
|
|
436
441
|
)
|
|
437
442
|
},
|
|
438
443
|
|
|
444
|
+
/** Ondo is cross-only, so the venue reports leverage alone. */
|
|
445
|
+
async getMarketSettings(
|
|
446
|
+
params: ProviderGetMarketSettingsParams,
|
|
447
|
+
opts?: SDKRequestOptions
|
|
448
|
+
): Promise<MarketSettings> {
|
|
449
|
+
const { marketId, categoryId } = params.market
|
|
450
|
+
if (categoryId !== ONDO_PROVIDER_KEY) {
|
|
451
|
+
const error = new PerpsError(
|
|
452
|
+
PerpsErrorCode.ValidationError,
|
|
453
|
+
`Ondo market '${marketId}' in category '${categoryId}' is not a perps market`
|
|
454
|
+
)
|
|
455
|
+
error.tool = ONDO_PROVIDER_KEY
|
|
456
|
+
throw error
|
|
457
|
+
}
|
|
458
|
+
return withSession(
|
|
459
|
+
params.address,
|
|
460
|
+
() => {
|
|
461
|
+
throw new OndoSessionExpiredError(
|
|
462
|
+
`No valid Ondo session token stored for ${params.address}. Run the SIWE login first.`
|
|
463
|
+
)
|
|
464
|
+
},
|
|
465
|
+
async (token) => {
|
|
466
|
+
const leverages = await apiClient(opts).get<OndoLeverage[]>(
|
|
467
|
+
'/v1/perps/leverage',
|
|
468
|
+
{ params: { market: marketId }, authToken: token.token }
|
|
469
|
+
)
|
|
470
|
+
const row = leverages.find((r) => r.market === marketId)
|
|
471
|
+
if (row === undefined) {
|
|
472
|
+
const error = new PerpsError(
|
|
473
|
+
PerpsErrorCode.SDKError,
|
|
474
|
+
`Ondo returned no leverage for market '${marketId}'`
|
|
475
|
+
)
|
|
476
|
+
error.tool = ONDO_PROVIDER_KEY
|
|
477
|
+
throw error
|
|
478
|
+
}
|
|
479
|
+
const leverage = toWireBig(row.leverage, 'leverage')
|
|
480
|
+
if (leverage.lte(0)) {
|
|
481
|
+
const error = new PerpsError(
|
|
482
|
+
PerpsErrorCode.SDKError,
|
|
483
|
+
`Ondo field \`leverage\` must be positive: '${row.leverage}'`
|
|
484
|
+
)
|
|
485
|
+
error.tool = ONDO_PROVIDER_KEY
|
|
486
|
+
throw error
|
|
487
|
+
}
|
|
488
|
+
return { marginMode: MarginMode.CROSS, leverage: leverage.toNumber() }
|
|
489
|
+
}
|
|
490
|
+
)
|
|
491
|
+
},
|
|
492
|
+
|
|
439
493
|
async getAvailableToTrade(
|
|
440
494
|
params: ProviderGetAvailableToTradeParams,
|
|
441
495
|
opts?: SDKRequestOptions
|
package/src/utils/mapFill.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Fill, MarketDisplay } from '@lifi/perps-types'
|
|
2
2
|
import { FillClassification, LiquidityRole, OrderSide } from '@lifi/perps-types'
|
|
3
|
-
import Big from 'big.js'
|
|
4
3
|
import type { OndoFill, OndoFillDirection } from '../types/wire.js'
|
|
4
|
+
import { toWireBig } from './decimal.js'
|
|
5
5
|
|
|
6
6
|
const DIRECTION_CLASSIFICATIONS: Record<OndoFillDirection, FillClassification> =
|
|
7
7
|
{
|
|
@@ -32,7 +32,9 @@ export const mapFill = (fill: OndoFill, market: MarketDisplay): Fill => ({
|
|
|
32
32
|
liquidity: fill.isMaker ? LiquidityRole.MAKER : LiquidityRole.TAKER,
|
|
33
33
|
// Ondo charges the fill fee in the market's quote asset.
|
|
34
34
|
fee: {
|
|
35
|
-
amount:
|
|
35
|
+
amount: toWireBig(fill.fee, 'fee')
|
|
36
|
+
.minus(toWireBig(fill.feeRebate ?? '0', 'feeRebate'))
|
|
37
|
+
.toFixed(),
|
|
36
38
|
asset: market.quoteAsset.displaySymbol,
|
|
37
39
|
},
|
|
38
40
|
realizedPnl: fill.pnl,
|
package/src/utils/mapOrder.ts
CHANGED
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
PerpsErrorCode,
|
|
14
14
|
TimeInForce,
|
|
15
15
|
} from '@lifi/perps-types'
|
|
16
|
-
import Big from 'big.js'
|
|
17
16
|
import type { OndoOrder, OndoTwapOrder } from '../types/wire.js'
|
|
17
|
+
import { toWireBig } from './decimal.js'
|
|
18
18
|
|
|
19
19
|
/** Map supported Ondo lifecycle states; unsupported states fail explicitly. */
|
|
20
20
|
export const mapOrderStatus = (status: string): OrderStatus => {
|
|
@@ -73,7 +73,10 @@ export const mapOrder = (
|
|
|
73
73
|
parentOrderId?: string
|
|
74
74
|
): Order => {
|
|
75
75
|
const twap = 'twapId' in order
|
|
76
|
-
const filled =
|
|
76
|
+
const filled = toWireBig(order.filledSize, 'filledSize')
|
|
77
|
+
const totalSize = twap
|
|
78
|
+
? toWireBig(order.totalSize, 'totalSize')
|
|
79
|
+
: toWireBig(order.size, 'size')
|
|
77
80
|
const status = twap
|
|
78
81
|
? twapStatus(order.orderStatus)
|
|
79
82
|
: mapOrderStatus(order.status)
|
|
@@ -88,10 +91,8 @@ export const mapOrder = (
|
|
|
88
91
|
status === OrderStatus.OPEN && filled.gt(0)
|
|
89
92
|
? OrderStatus.PARTIALLY_FILLED
|
|
90
93
|
: status,
|
|
91
|
-
originalSize:
|
|
92
|
-
remainingSize:
|
|
93
|
-
.minus(filled)
|
|
94
|
-
.toFixed(),
|
|
94
|
+
originalSize: totalSize.toFixed(),
|
|
95
|
+
remainingSize: totalSize.minus(filled).toFixed(),
|
|
95
96
|
filledSize: order.filledSize,
|
|
96
97
|
reduceOnly: order.reduceOnly ?? false,
|
|
97
98
|
createdAt,
|
|
@@ -104,7 +105,7 @@ export const mapOrder = (
|
|
|
104
105
|
? {
|
|
105
106
|
averagePrice: twap
|
|
106
107
|
? order.avgFilledPrice
|
|
107
|
-
:
|
|
108
|
+
: toWireBig(order.filledCost, 'filledCost').div(filled).toFixed(),
|
|
108
109
|
}
|
|
109
110
|
: {}),
|
|
110
111
|
}
|
package/src/utils/mapPosition.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PerpsMarketDisplay, Position } from '@lifi/perps-types'
|
|
2
2
|
import { MarginMode, PositionSide } from '@lifi/perps-types'
|
|
3
|
-
import Big from 'big.js'
|
|
4
3
|
import type { OndoPosition } from '../types/wire.js'
|
|
4
|
+
import { toWireBig } from './decimal.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Map a raw Ondo position to the generic Position type. Ondo margin accounts
|
|
@@ -16,7 +16,7 @@ export const mapPosition = (
|
|
|
16
16
|
): Position => ({
|
|
17
17
|
market,
|
|
18
18
|
side: pos.direction === 'short' ? PositionSide.SHORT : PositionSide.LONG,
|
|
19
|
-
size:
|
|
19
|
+
size: toWireBig(pos.netQuantity, 'netQuantity').abs().toFixed(),
|
|
20
20
|
entryPrice: pos.averageEntryPrice,
|
|
21
21
|
markPrice: pos.markPrice,
|
|
22
22
|
liquidationPrice: pos.liquidationPrice,
|
|
@@ -10,8 +10,9 @@ import { toWireBig } from './decimal.js'
|
|
|
10
10
|
*
|
|
11
11
|
* @param assetId - `Asset.id` the row is keyed by.
|
|
12
12
|
* @param withdrawalFeeUsd - The account's `withdrawalFeeUSD`. Ondo collateral
|
|
13
|
-
* is USDC, so the USD fee is the row fee 1:1 in collateral units.
|
|
14
|
-
* leaves the row without a
|
|
13
|
+
* is USDC, so the USD fee is the row fee 1:1 in collateral units. Ondo
|
|
14
|
+
* charges it on top of the requested amount. Absent leaves the row without a
|
|
15
|
+
* fee.
|
|
15
16
|
* @public
|
|
16
17
|
*/
|
|
17
18
|
export const ondoWithdrawableBalances = (
|
|
@@ -38,6 +39,7 @@ export const ondoWithdrawableBalances = (
|
|
|
38
39
|
withdrawalFeeUsd,
|
|
39
40
|
'account.withdrawalFeeUSD'
|
|
40
41
|
).toFixed(),
|
|
42
|
+
isFeeDeducted: false,
|
|
41
43
|
}),
|
|
42
44
|
},
|
|
43
45
|
]
|
|
@@ -842,8 +842,7 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
842
842
|
*
|
|
843
843
|
* Closes over the per-instance options (storage, apiUrl override) so
|
|
844
844
|
* `PerpsWsClient` can call the returned factory with just
|
|
845
|
-
* `({ provider, wsUrl, client })` at subscribe time.
|
|
846
|
-
* Ondo advertises a single venue, no sub-DEX filtering.
|
|
845
|
+
* `({ provider, wsUrl, client })` at subscribe time.
|
|
847
846
|
*
|
|
848
847
|
* @public
|
|
849
848
|
*/
|