@lifi/perps-sdk-provider-ondo 36.1.0 → 37.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/dist/cjs/OndoProvider.d.ts.map +1 -1
- package/dist/cjs/OndoProvider.js +6 -3
- package/dist/cjs/OndoProvider.js.map +1 -1
- package/dist/cjs/utils/fillLeverages.d.ts +4 -0
- package/dist/cjs/utils/fillLeverages.d.ts.map +1 -0
- package/dist/cjs/utils/fillLeverages.js +39 -0
- package/dist/cjs/utils/fillLeverages.js.map +1 -0
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +3 -2
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/websocket/OndoWsProvider.d.ts +4 -1
- package/dist/cjs/websocket/OndoWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/OndoWsProvider.js +37 -7
- package/dist/cjs/websocket/OndoWsProvider.js.map +1 -1
- package/dist/esm/OndoProvider.d.ts.map +1 -1
- package/dist/esm/OndoProvider.js +7 -4
- package/dist/esm/OndoProvider.js.map +1 -1
- package/dist/esm/utils/fillLeverages.d.ts +12 -0
- package/dist/esm/utils/fillLeverages.d.ts.map +1 -0
- package/dist/esm/utils/fillLeverages.js +43 -0
- package/dist/esm/utils/fillLeverages.js.map +1 -0
- package/dist/esm/utils/mapFill.d.ts +2 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +5 -3
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/websocket/OndoWsProvider.d.ts +13 -2
- package/dist/esm/websocket/OndoWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/OndoWsProvider.js +48 -9
- package/dist/esm/websocket/OndoWsProvider.js.map +1 -1
- package/dist/types/OndoProvider.d.ts.map +1 -1
- package/dist/types/utils/fillLeverages.d.ts +12 -0
- package/dist/types/utils/fillLeverages.d.ts.map +1 -0
- package/dist/types/utils/mapFill.d.ts +2 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/websocket/OndoWsProvider.d.ts +13 -2
- package/dist/types/websocket/OndoWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/OndoProvider.ts +14 -3
- package/src/utils/fillLeverages.ts +67 -0
- package/src/utils/mapFill.ts +26 -21
- package/src/websocket/OndoWsProvider.ts +65 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PerpsSDKClient, type ProviderGetQuoteParams, type QuoteListener, type StorageAdapter, WsProviderBase, type WsProviderFactory } from '@lifi/perps-sdk';
|
|
2
2
|
import { type Subscription } from '@lifi/perps-types';
|
|
3
|
-
import type
|
|
3
|
+
import { type Address } from 'viem';
|
|
4
4
|
interface SubState {
|
|
5
5
|
/** Subscribe payload minus `op` — re-sent verbatim on every (re)open. */
|
|
6
6
|
frame: {
|
|
@@ -60,6 +60,7 @@ export declare class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
60
60
|
* out of order. `'latest'` coalesces the backlog to one trailing refresh.
|
|
61
61
|
*/
|
|
62
62
|
private readonly accountSummaryChain;
|
|
63
|
+
private readonly fillChain;
|
|
63
64
|
/** Complete (mark-price-bearing) contexts, keyed by venue market symbol. */
|
|
64
65
|
private contexts;
|
|
65
66
|
/** Funding seen before the market's first mark price. */
|
|
@@ -89,8 +90,18 @@ export declare class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
89
90
|
* false — leaving the binding intact — while any is still live.
|
|
90
91
|
*/
|
|
91
92
|
private releaseBindingIfIdle;
|
|
92
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Release a channel's binding reservation, including one still opening.
|
|
95
|
+
* The last release cycles the connection only when a login was sent on it,
|
|
96
|
+
* because the venue holds that login until the socket closes.
|
|
97
|
+
*/
|
|
93
98
|
private releaseBinding;
|
|
99
|
+
private authChannelKeys;
|
|
100
|
+
/**
|
|
101
|
+
* The venue login is per connection, so one credential failure stops every
|
|
102
|
+
* private channel of the address.
|
|
103
|
+
*/
|
|
104
|
+
protected resolveChannelKeys(key: string, state: SubState): string[];
|
|
94
105
|
/** Register a wire sub, ref-counting the shared authenticated channels. */
|
|
95
106
|
private acquireWire;
|
|
96
107
|
/** Mirror of {@link acquireWire}: drop the wire sub on its last release. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OndoWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/OndoWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"OndoWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/OndoWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAGlB,KAAK,cAAc,EAInB,cAAc,EACd,KAAK,iBAAiB,EAGvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,MAAM,CAAA;AAsE9C,UAAU,QAAQ;IAChB,yEAAyE;IACzE,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACnE,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,6EAA6E;IAC7E,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;AAID;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,cAAc,CAAC,QAAQ,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAC3C,OAA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3
|
+
"version": "37.0.0",
|
|
4
4
|
"description": "Ondo Perps provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"big.js": "^7.0.1",
|
|
46
|
-
"@lifi/perps-types": "^
|
|
46
|
+
"@lifi/perps-types": "^30.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"viem": ">=2.57.11 <2.57.12",
|
|
50
|
-
"@lifi/perps-sdk": "^
|
|
50
|
+
"@lifi/perps-sdk": "^34.0.0"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
package/src/OndoProvider.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ACTIVE_ORDER_STATUSES,
|
|
3
3
|
type ActionSignerContribution,
|
|
4
|
+
buildFill,
|
|
4
5
|
calculateTransferable,
|
|
5
6
|
createWarnOnce,
|
|
6
7
|
type DepositFlow,
|
|
@@ -130,6 +131,7 @@ import {
|
|
|
130
131
|
type OndoPage,
|
|
131
132
|
OndoSessionExpiredError,
|
|
132
133
|
} from './utils/apiClient.js'
|
|
134
|
+
import { fetchFillLeverages } from './utils/fillLeverages.js'
|
|
133
135
|
import {
|
|
134
136
|
listOndoDepositAddress,
|
|
135
137
|
mapDepositActivity,
|
|
@@ -965,11 +967,20 @@ export const ondoProvider = (
|
|
|
965
967
|
marketRegistry().sync(),
|
|
966
968
|
])
|
|
967
969
|
|
|
968
|
-
const
|
|
970
|
+
const mapped = page.result.flatMap((fill): Fill[] => {
|
|
969
971
|
const market = marketDisplay(fill.market)
|
|
970
|
-
const
|
|
971
|
-
return
|
|
972
|
+
const mappedFill = market && mapFill(fill, market)
|
|
973
|
+
return mappedFill ? [mappedFill] : []
|
|
972
974
|
})
|
|
975
|
+
const leverages = await fetchFillLeverages(
|
|
976
|
+
client,
|
|
977
|
+
token.token,
|
|
978
|
+
mapped,
|
|
979
|
+
opts?.signal
|
|
980
|
+
)
|
|
981
|
+
const items = mapped.map((fill) =>
|
|
982
|
+
buildFill(fill, leverages.get(fill.market.id))
|
|
983
|
+
)
|
|
973
984
|
|
|
974
985
|
const nextCursor = page.pageInfo?.nextCursor
|
|
975
986
|
return {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWarnOnce,
|
|
3
|
+
isDecimalString,
|
|
4
|
+
isDecimalStringGreaterThan,
|
|
5
|
+
} from '@lifi/perps-sdk'
|
|
6
|
+
import type { DecimalString, Fill } from '@lifi/perps-types'
|
|
7
|
+
import { ONDO_PROVIDER_KEY } from '../constants.js'
|
|
8
|
+
import type { OndoLeverage } from '../types/wire.js'
|
|
9
|
+
import type { OndoApiClient } from './apiClient.js'
|
|
10
|
+
|
|
11
|
+
const warnLeverageReadOnce = createWarnOnce()
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Current leverage setting of each market that a fill with a `closedSize`
|
|
15
|
+
* trades, keyed by `Market.id`. One `/v1/perps/leverage` read covers every
|
|
16
|
+
* market. A failed read gives an empty map, and a market without a positive
|
|
17
|
+
* leverage row stays out, so the ROE of its fills stays absent.
|
|
18
|
+
*
|
|
19
|
+
* @throws The abort reason when `signal` aborts.
|
|
20
|
+
*/
|
|
21
|
+
export const fetchFillLeverages = async (
|
|
22
|
+
client: OndoApiClient,
|
|
23
|
+
authToken: string,
|
|
24
|
+
fills: readonly Fill[],
|
|
25
|
+
signal?: AbortSignal
|
|
26
|
+
): Promise<Map<string, DecimalString>> => {
|
|
27
|
+
const marketIds = new Set(
|
|
28
|
+
fills.flatMap((fill) =>
|
|
29
|
+
fill.closedSize === undefined ? [] : [fill.market.id]
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
if (marketIds.size === 0) {
|
|
33
|
+
return new Map()
|
|
34
|
+
}
|
|
35
|
+
let rows: OndoLeverage[]
|
|
36
|
+
try {
|
|
37
|
+
rows = await client.get<OndoLeverage[]>('/v1/perps/leverage', {
|
|
38
|
+
authToken,
|
|
39
|
+
})
|
|
40
|
+
} catch (error) {
|
|
41
|
+
signal?.throwIfAborted()
|
|
42
|
+
warnLeverageReadOnce(
|
|
43
|
+
'leverage',
|
|
44
|
+
`[${ONDO_PROVIDER_KEY}] leverage read failed; fills carry no returnOnEquity: ${String(error)}`
|
|
45
|
+
)
|
|
46
|
+
return new Map()
|
|
47
|
+
}
|
|
48
|
+
const leverages = new Map<string, DecimalString>()
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
if (
|
|
51
|
+
marketIds.has(row.market) &&
|
|
52
|
+
isDecimalString(row.leverage) &&
|
|
53
|
+
isDecimalStringGreaterThan(row.leverage, '0')
|
|
54
|
+
) {
|
|
55
|
+
leverages.set(row.market, row.leverage)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const marketId of marketIds) {
|
|
59
|
+
if (!leverages.has(marketId)) {
|
|
60
|
+
warnLeverageReadOnce(
|
|
61
|
+
marketId,
|
|
62
|
+
`[${ONDO_PROVIDER_KEY}] no positive leverage for market '${marketId}'; its fills carry no returnOnEquity`
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return leverages
|
|
67
|
+
}
|
package/src/utils/mapFill.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildFill } from '@lifi/perps-sdk'
|
|
1
2
|
import type { Fill, MarketDisplay } from '@lifi/perps-types'
|
|
2
3
|
import { FillClassification, LiquidityRole, OrderSide } from '@lifi/perps-types'
|
|
3
4
|
import type { OndoFill, OndoFillDirection } from '../types/wire.js'
|
|
@@ -18,7 +19,8 @@ const DIRECTION_CLASSIFICATIONS: Record<OndoFillDirection, FillClassification> =
|
|
|
18
19
|
* Map a raw Ondo fill to the generic {@link Fill}. The fee is netted against
|
|
19
20
|
* Ondo's `feeRebate`; when the wire `direction` is absent the classification
|
|
20
21
|
* is the bare fill side. Size and price are the raw venue strings. A fill
|
|
21
|
-
* with an invalid time gives `undefined`.
|
|
22
|
+
* with an invalid time gives `undefined`. A closing fill gets `closedSize`
|
|
23
|
+
* and `entryPrice`, but no `returnOnEquity`: the fill carries no leverage.
|
|
22
24
|
*
|
|
23
25
|
* @param market - Backend-resolved market identity for `fill.market`.
|
|
24
26
|
* @public
|
|
@@ -36,24 +38,27 @@ export const mapFill = (
|
|
|
36
38
|
if (createdAt === undefined) {
|
|
37
39
|
return undefined
|
|
38
40
|
}
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
return buildFill(
|
|
42
|
+
{
|
|
43
|
+
id: fill.id,
|
|
44
|
+
orderId: fill.orderId,
|
|
45
|
+
clientOrderId: fill.clientOrderId,
|
|
46
|
+
market,
|
|
47
|
+
side: fill.side === 'buy' ? OrderSide.BUY : OrderSide.SELL,
|
|
48
|
+
size: fill.size,
|
|
49
|
+
price: fill.price,
|
|
50
|
+
liquidity: fill.isMaker ? LiquidityRole.MAKER : LiquidityRole.TAKER,
|
|
51
|
+
// Ondo charges the fill fee in the market's quote asset.
|
|
52
|
+
fee: buildFee(fill, market.quoteAsset.displaySymbol),
|
|
53
|
+
realizedPnl: fill.pnl,
|
|
54
|
+
classification:
|
|
55
|
+
fill.direction !== undefined
|
|
56
|
+
? DIRECTION_CLASSIFICATIONS[fill.direction]
|
|
57
|
+
: fill.side === 'buy'
|
|
58
|
+
? FillClassification.BUY
|
|
59
|
+
: FillClassification.SELL,
|
|
60
|
+
createdAt,
|
|
61
|
+
},
|
|
62
|
+
undefined
|
|
63
|
+
)
|
|
59
64
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
buildFill,
|
|
2
3
|
DecodeChain,
|
|
3
4
|
getMarketRegistry,
|
|
4
5
|
isDecimalString,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
wsLog,
|
|
22
23
|
} from '@lifi/perps-sdk'
|
|
23
24
|
import {
|
|
25
|
+
type Fill,
|
|
24
26
|
type MarketContext,
|
|
25
27
|
type MarketDisplay,
|
|
26
28
|
type OndoAccountBalance,
|
|
@@ -28,7 +30,7 @@ import {
|
|
|
28
30
|
type PerpsMarketDisplay,
|
|
29
31
|
type Subscription,
|
|
30
32
|
} from '@lifi/perps-types'
|
|
31
|
-
import type
|
|
33
|
+
import { type Address, isAddress } from 'viem'
|
|
32
34
|
import { OndoTokenStore } from '../auth/OndoTokenStore.js'
|
|
33
35
|
import { ondoSessionRejectedError } from '../auth/sessionToken.js'
|
|
34
36
|
import {
|
|
@@ -51,6 +53,7 @@ import type {
|
|
|
51
53
|
OndoWsMessage,
|
|
52
54
|
OndoWsTrade,
|
|
53
55
|
} from '../types/index.js'
|
|
56
|
+
import { fetchFillLeverages } from '../utils/fillLeverages.js'
|
|
54
57
|
import {
|
|
55
58
|
isOpenPosition,
|
|
56
59
|
mapFill,
|
|
@@ -162,6 +165,11 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
162
165
|
wsLog.handlerFailure(this.providerKey, err)
|
|
163
166
|
)
|
|
164
167
|
|
|
168
|
+
// A closing fill waits for a leverage read, so fills frames emit in order.
|
|
169
|
+
private readonly fillChain = new DecodeChain('every', (err) =>
|
|
170
|
+
wsLog.handlerFailure(this.providerKey, err)
|
|
171
|
+
)
|
|
172
|
+
|
|
165
173
|
/** Complete (mark-price-bearing) contexts, keyed by venue market symbol. */
|
|
166
174
|
private contexts: Record<string, MarketContext> = {}
|
|
167
175
|
/** Funding seen before the market's first mark price. */
|
|
@@ -404,24 +412,49 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
404
412
|
if (bound === undefined) {
|
|
405
413
|
return true
|
|
406
414
|
}
|
|
407
|
-
for (const
|
|
408
|
-
if (!this.closeChannelIfIdle(
|
|
415
|
+
for (const key of this.authChannelKeys(bound)) {
|
|
416
|
+
if (!this.closeChannelIfIdle(key)) {
|
|
409
417
|
return false
|
|
410
418
|
}
|
|
411
419
|
}
|
|
412
420
|
return true
|
|
413
421
|
}
|
|
414
422
|
|
|
415
|
-
/**
|
|
423
|
+
/**
|
|
424
|
+
* Release a channel's binding reservation, including one still opening.
|
|
425
|
+
* The last release cycles the connection only when a login was sent on it,
|
|
426
|
+
* because the venue holds that login until the socket closes.
|
|
427
|
+
*/
|
|
416
428
|
private releaseBinding(): void {
|
|
417
429
|
this.authBindingRefs -= 1
|
|
418
430
|
if (this.authBindingRefs > 0) {
|
|
419
431
|
return
|
|
420
432
|
}
|
|
421
433
|
this.accountAddress = undefined
|
|
434
|
+
const login = this.loginPromise
|
|
422
435
|
this.loginPromise = undefined
|
|
423
436
|
this.authGeneration += 1
|
|
424
|
-
|
|
437
|
+
if (login !== undefined) {
|
|
438
|
+
this.rws.reconnect()
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
private authChannelKeys(address: string): string[] {
|
|
443
|
+
return ONDO_AUTH_FANOUT.map((channel) => `${channel}:${address}`)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* The venue login is per connection, so one credential failure stops every
|
|
448
|
+
* private channel of the address.
|
|
449
|
+
*/
|
|
450
|
+
protected override resolveChannelKeys(
|
|
451
|
+
key: string,
|
|
452
|
+
state: SubState
|
|
453
|
+
): string[] {
|
|
454
|
+
if (!state.needsAuth || state.address === undefined) {
|
|
455
|
+
return super.resolveChannelKeys(key, state)
|
|
456
|
+
}
|
|
457
|
+
return this.authChannelKeys(state.address.toLowerCase())
|
|
425
458
|
}
|
|
426
459
|
|
|
427
460
|
/** Register a wire sub, ref-counting the shared authenticated channels. */
|
|
@@ -499,6 +532,7 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
499
532
|
this.authWireRefs.clear()
|
|
500
533
|
this.authBindingRefs = 0
|
|
501
534
|
this.clearAccountSummary()
|
|
535
|
+
this.fillChain.reset()
|
|
502
536
|
}
|
|
503
537
|
|
|
504
538
|
/** Wire subs for `sub`, keyed uniquely for the base's replay registry. */
|
|
@@ -682,8 +716,9 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
682
716
|
return this.loginPromise
|
|
683
717
|
}
|
|
684
718
|
|
|
685
|
-
private restClient(): OndoApiClient {
|
|
719
|
+
private restClient(signal?: AbortSignal): OndoApiClient {
|
|
686
720
|
return new OndoApiClient(this.apiUrl, {
|
|
721
|
+
signal,
|
|
687
722
|
fetchImpl: this.client?.config.fetch,
|
|
688
723
|
})
|
|
689
724
|
}
|
|
@@ -828,8 +863,8 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
828
863
|
this.accountAddress = undefined
|
|
829
864
|
this.clearAccountSummary()
|
|
830
865
|
attempt.reject(error)
|
|
831
|
-
for (const
|
|
832
|
-
this.rejectChannel(
|
|
866
|
+
for (const key of this.authChannelKeys(address)) {
|
|
867
|
+
this.rejectChannel(key, error)
|
|
833
868
|
}
|
|
834
869
|
}
|
|
835
870
|
|
|
@@ -1082,7 +1117,7 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
1082
1117
|
if (address === undefined) {
|
|
1083
1118
|
return
|
|
1084
1119
|
}
|
|
1085
|
-
const mapped = []
|
|
1120
|
+
const mapped: Fill[] = []
|
|
1086
1121
|
for (const fill of fills) {
|
|
1087
1122
|
const market = this.resolveMarket(fill.market)
|
|
1088
1123
|
const mappedFill = market && mapFill(fill, market)
|
|
@@ -1090,7 +1125,27 @@ export class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
1090
1125
|
mapped.push(mappedFill)
|
|
1091
1126
|
}
|
|
1092
1127
|
}
|
|
1093
|
-
this.
|
|
1128
|
+
this.fillChain.push(async () => {
|
|
1129
|
+
const leverages = isAddress(address, { strict: false })
|
|
1130
|
+
? await this.readFrameEnrichment('fill leverage', async (signal) => {
|
|
1131
|
+
const token = await this.tokenStore.get(address)
|
|
1132
|
+
return token === null
|
|
1133
|
+
? undefined
|
|
1134
|
+
: fetchFillLeverages(
|
|
1135
|
+
this.restClient(signal),
|
|
1136
|
+
token.token,
|
|
1137
|
+
mapped,
|
|
1138
|
+
signal
|
|
1139
|
+
)
|
|
1140
|
+
})
|
|
1141
|
+
: undefined
|
|
1142
|
+
this.emit(`fills:${address}`, {
|
|
1143
|
+
channel: 'fills',
|
|
1144
|
+
data: mapped.map((fill) =>
|
|
1145
|
+
buildFill(fill, leverages?.get(fill.market.id))
|
|
1146
|
+
),
|
|
1147
|
+
})
|
|
1148
|
+
})
|
|
1094
1149
|
if (this.accountSummary !== undefined) {
|
|
1095
1150
|
const generation = this.accountSummaryGeneration
|
|
1096
1151
|
this.accountSummaryChain.push(() =>
|