@lifi/perps-sdk-provider-ondo 35.0.0 → 36.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.
- package/README.md +57 -0
- package/dist/cjs/OndoProvider.js +1 -1
- package/dist/cjs/OndoProvider.js.map +1 -1
- package/dist/cjs/auth/OndoTokenStore.d.ts +1 -1
- package/dist/cjs/auth/OndoTokenStore.d.ts.map +1 -1
- package/dist/cjs/auth/OndoTokenStore.js +9 -2
- package/dist/cjs/auth/OndoTokenStore.js.map +1 -1
- package/dist/cjs/types/wire.d.ts.map +1 -1
- package/dist/cjs/types/ws.d.ts +0 -4
- package/dist/cjs/types/ws.d.ts.map +1 -1
- package/dist/cjs/utils/buildFee.d.ts +4 -0
- package/dist/cjs/utils/buildFee.d.ts.map +1 -0
- package/dist/cjs/utils/buildFee.js +22 -0
- package/dist/cjs/utils/buildFee.js.map +1 -0
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +2 -6
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapPortfolioHistory.d.ts.map +1 -1
- package/dist/cjs/utils/mapPortfolioHistory.js +18 -3
- package/dist/cjs/utils/mapPortfolioHistory.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +9 -2
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/websocket/OndoWsProvider.d.ts +4 -2
- package/dist/cjs/websocket/OndoWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/OndoWsProvider.js +88 -49
- package/dist/cjs/websocket/OndoWsProvider.js.map +1 -1
- package/dist/esm/OndoProvider.js +1 -1
- package/dist/esm/OndoProvider.js.map +1 -1
- package/dist/esm/auth/OndoTokenStore.d.ts +1 -1
- package/dist/esm/auth/OndoTokenStore.d.ts.map +1 -1
- package/dist/esm/auth/OndoTokenStore.js +9 -2
- package/dist/esm/auth/OndoTokenStore.js.map +1 -1
- package/dist/esm/types/wire.d.ts +4 -0
- package/dist/esm/types/wire.d.ts.map +1 -1
- package/dist/esm/types/ws.d.ts +1 -5
- package/dist/esm/types/ws.d.ts.map +1 -1
- package/dist/esm/utils/buildFee.d.ts +8 -0
- package/dist/esm/utils/buildFee.d.ts.map +1 -0
- package/dist/esm/utils/buildFee.js +22 -0
- package/dist/esm/utils/buildFee.js.map +1 -0
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +2 -7
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapPortfolioHistory.d.ts.map +1 -1
- package/dist/esm/utils/mapPortfolioHistory.js +19 -4
- package/dist/esm/utils/mapPortfolioHistory.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts +2 -6
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +12 -9
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/websocket/OndoWsProvider.d.ts +5 -3
- package/dist/esm/websocket/OndoWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/OndoWsProvider.js +94 -56
- package/dist/esm/websocket/OndoWsProvider.js.map +1 -1
- package/dist/types/auth/OndoTokenStore.d.ts +1 -1
- package/dist/types/auth/OndoTokenStore.d.ts.map +1 -1
- package/dist/types/types/wire.d.ts +4 -0
- package/dist/types/types/wire.d.ts.map +1 -1
- package/dist/types/types/ws.d.ts +1 -5
- package/dist/types/types/ws.d.ts.map +1 -1
- package/dist/types/utils/buildFee.d.ts +8 -0
- package/dist/types/utils/buildFee.d.ts.map +1 -0
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/mapPortfolioHistory.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts +2 -6
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/websocket/OndoWsProvider.d.ts +5 -3
- package/dist/types/websocket/OndoWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/OndoProvider.ts +1 -1
- package/src/auth/OndoTokenStore.ts +13 -2
- package/src/types/wire.ts +4 -0
- package/src/types/ws.ts +1 -2
- package/src/utils/buildFee.ts +35 -0
- package/src/utils/mapFill.ts +2 -10
- package/src/utils/mapPortfolioHistory.ts +29 -4
- package/src/utils/mapPosition.ts +14 -8
- package/src/websocket/OndoWsProvider.ts +132 -63
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../../src/types/ws.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAElE,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE5C,
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../../src/types/ws.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAElE,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE5C,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,aAAa,EAAE,CAAA;IACrB,IAAI,EAAE,aAAa,EAAE,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,KAAK,GAAG,MAAM,CAAA;IAC9B,IAAI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,EAAE,mBAAmB,CAAC;IAAC,IAAI,EAAE,eAAe,EAAE,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,SAAS,EAAE,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,YAAY,EAAE,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Fee } from '@lifi/perps-types';
|
|
2
|
+
import type { OndoFill } from '../types/wire.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build the net Ondo fee and its rebate. A malformed fee or rebate omits the
|
|
5
|
+
* fee, and so does a negative rebate: Ondo documents `feeRebate` as earned.
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildFee: (row: Pick<OndoFill, "fee" | "feeRebate">, asset: string) => Fee | undefined;
|
|
8
|
+
//# sourceMappingURL=buildFee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFee.d.ts","sourceRoot":"","sources":["../../../src/utils/buildFee.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAIhD;;;GAGG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,WAAW,CAAC,EACxC,OAAO,MAAM,KACZ,GAAG,GAAG,SAgBR,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createWarnOnce, isDecimalStringGreaterThan, safeSubtractDecimalString, } from '@lifi/perps-sdk';
|
|
2
|
+
import { ONDO_PROVIDER_KEY } from '../constants.js';
|
|
3
|
+
const warnNegativeRebateOnce = createWarnOnce();
|
|
4
|
+
/**
|
|
5
|
+
* Build the net Ondo fee and its rebate. A malformed fee or rebate omits the
|
|
6
|
+
* fee, and so does a negative rebate: Ondo documents `feeRebate` as earned.
|
|
7
|
+
*/
|
|
8
|
+
export const buildFee = (row, asset) => {
|
|
9
|
+
const netFeeAmount = safeSubtractDecimalString(row.fee, row.feeRebate ?? '0');
|
|
10
|
+
if (netFeeAmount === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (row.feeRebate === undefined) {
|
|
14
|
+
return { amount: netFeeAmount, asset };
|
|
15
|
+
}
|
|
16
|
+
if (isDecimalStringGreaterThan('0', row.feeRebate)) {
|
|
17
|
+
warnNegativeRebateOnce(`${ONDO_PROVIDER_KEY}|feeRebate`, `[${ONDO_PROVIDER_KEY}] \`feeRebate\` is negative, so the fee is absent: '${row.feeRebate.slice(0, 64)}'`);
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return { amount: netFeeAmount, asset, rebate: row.feeRebate };
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=buildFee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFee.js","sourceRoot":"","sources":["../../../src/utils/buildFee.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAGnD,MAAM,sBAAsB,GAAG,cAAc,EAAE,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,GAAwC,EACxC,KAAa,EACI,EAAE;IACnB,MAAM,YAAY,GAAG,yBAAyB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,CAAA;IAC7E,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,CAAA;IACxC,CAAC;IACD,IAAI,0BAA0B,CAAC,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QACnD,sBAAsB,CACpB,GAAG,iBAAiB,YAAY,EAChC,IAAI,iBAAiB,uDAAuD,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAC1G,CAAA;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,CAAA;AAC/D,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAE5D,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,kBAAkB,CAAA;AAcnE;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,GAClB,MAAM,QAAQ,EACd,QAAQ,aAAa,KACpB,IAAI,GAAG,SA8BT,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { safeSubtractDecimalString } from '@lifi/perps-sdk';
|
|
2
1
|
import { FillClassification, LiquidityRole, OrderSide } from '@lifi/perps-types';
|
|
2
|
+
import { buildFee } from './buildFee.js';
|
|
3
3
|
import { rowTimestampToIsoStringOrWarn } from './venueValues.js';
|
|
4
4
|
const DIRECTION_CLASSIFICATIONS = {
|
|
5
5
|
openLong: FillClassification.OPENED_LONG,
|
|
@@ -9,8 +9,6 @@ const DIRECTION_CLASSIFICATIONS = {
|
|
|
9
9
|
flipLongToShort: FillClassification.SWITCHED_SHORT,
|
|
10
10
|
flipShortToLong: FillClassification.SWITCHED_LONG,
|
|
11
11
|
};
|
|
12
|
-
/** Ondo's `fee` net of `feeRebate`, or `undefined` when either is malformed. */
|
|
13
|
-
const netFeeAmount = (fill) => safeSubtractDecimalString(fill.fee, fill.feeRebate ?? '0');
|
|
14
12
|
/**
|
|
15
13
|
* Map a raw Ondo fill to the generic {@link Fill}. The fee is netted against
|
|
16
14
|
* Ondo's `feeRebate`; when the wire `direction` is absent the classification
|
|
@@ -25,7 +23,6 @@ export const mapFill = (fill, market) => {
|
|
|
25
23
|
if (createdAt === undefined) {
|
|
26
24
|
return undefined;
|
|
27
25
|
}
|
|
28
|
-
const feeAmount = netFeeAmount(fill);
|
|
29
26
|
return {
|
|
30
27
|
id: fill.id,
|
|
31
28
|
orderId: fill.orderId,
|
|
@@ -36,9 +33,7 @@ export const mapFill = (fill, market) => {
|
|
|
36
33
|
price: fill.price,
|
|
37
34
|
liquidity: fill.isMaker ? LiquidityRole.MAKER : LiquidityRole.TAKER,
|
|
38
35
|
// Ondo charges the fill fee in the market's quote asset.
|
|
39
|
-
fee:
|
|
40
|
-
? undefined
|
|
41
|
-
: { amount: feeAmount, asset: market.quoteAsset.displaySymbol },
|
|
36
|
+
fee: buildFee(fill, market.quoteAsset.displaySymbol),
|
|
42
37
|
realizedPnl: fill.pnl,
|
|
43
38
|
classification: fill.direction !== undefined
|
|
44
39
|
? DIRECTION_CLASSIFICATIONS[fill.direction]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapFill.js","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapFill.js","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAEhF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAEhE,MAAM,yBAAyB,GAC7B;IACE,QAAQ,EAAE,kBAAkB,CAAC,WAAW;IACxC,SAAS,EAAE,kBAAkB,CAAC,YAAY;IAC1C,SAAS,EAAE,kBAAkB,CAAC,WAAW;IACzC,UAAU,EAAE,kBAAkB,CAAC,YAAY;IAC3C,eAAe,EAAE,kBAAkB,CAAC,cAAc;IAClD,eAAe,EAAE,kBAAkB,CAAC,aAAa;CAClD,CAAA;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,IAAc,EACd,MAAqB,EACH,EAAE;IACpB,MAAM,SAAS,GAAG,6BAA6B,CAC7C,MAAM,EACN,MAAM,EACN,IAAI,CAAC,IAAI,EACT,MAAM,CAAC,EAAE,CACV,CAAA;IACD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,MAAM;QACN,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI;QAC1D,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK;QACnE,yDAAyD;QACzD,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC;QACpD,WAAW,EAAE,IAAI,CAAC,GAAG;QACrB,cAAc,EACZ,IAAI,CAAC,SAAS,KAAK,SAAS;YAC1B,CAAC,CAAC,yBAAyB,CAAC,IAAI,CAAC,SAAS,CAAC;YAC3C,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK;gBACnB,CAAC,CAAC,kBAAkB,CAAC,GAAG;gBACxB,CAAC,CAAC,kBAAkB,CAAC,IAAI;QAC/B,SAAS;KACV,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPortfolioHistory.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPortfolioHistory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapPortfolioHistory.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPortfolioHistory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAoDzB;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,qBAAqB,EAC5B,OAAO,uBAAuB,EAAE,EAChC,SAAS,oBAAoB,KAC5B,wBAUF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { warnSkippedVenueRow } from '@lifi/perps-sdk';
|
|
1
|
+
import { isDecimalString, safeSubtractDecimalString, warnSkippedVenueRow, } from '@lifi/perps-sdk';
|
|
2
2
|
import { ONDO_PROVIDER_KEY } from '../constants.js';
|
|
3
3
|
const summaryVolume = (summary, range) => {
|
|
4
4
|
switch (range) {
|
|
@@ -13,7 +13,7 @@ const summaryVolume = (summary, range) => {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
const POINT_ROW = 'portfolio point';
|
|
16
|
-
const mapPoint = (point) => {
|
|
16
|
+
const mapPoint = (point, baseline) => {
|
|
17
17
|
const timestamp = Date.parse(point.time);
|
|
18
18
|
if (Number.isNaN(timestamp)) {
|
|
19
19
|
warnSkippedVenueRow(ONDO_PROVIDER_KEY, POINT_ROW, 'time', point.time, {
|
|
@@ -21,8 +21,21 @@ const mapPoint = (point) => {
|
|
|
21
21
|
});
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const netFlow = getCumulativeNetFlow(point);
|
|
25
|
+
const netTransfers = baseline === undefined || netFlow === undefined
|
|
26
|
+
? undefined
|
|
27
|
+
: safeSubtractDecimalString(netFlow, baseline);
|
|
28
|
+
return {
|
|
29
|
+
timestamp,
|
|
30
|
+
accountValue: point.marginBalance,
|
|
31
|
+
pnl: point.totalPnL,
|
|
32
|
+
...(netTransfers === undefined ? {} : { netTransfers }),
|
|
33
|
+
};
|
|
25
34
|
};
|
|
35
|
+
const getCumulativeNetFlow = (point) => isDecimalString(point.allTimeDeposits) &&
|
|
36
|
+
isDecimalString(point.allTimeWithdrawals)
|
|
37
|
+
? safeSubtractDecimalString(point.allTimeDeposits, point.allTimeWithdrawals)
|
|
38
|
+
: undefined;
|
|
26
39
|
/**
|
|
27
40
|
* Join the `/v1/portfolio/summary/graph` series with the `/v1/portfolio/summary`
|
|
28
41
|
* totals for `range`. Ondo reports no 24-hour volume, so `volume` is absent
|
|
@@ -31,7 +44,9 @@ const mapPoint = (point) => {
|
|
|
31
44
|
* with an invalid time is skipped.
|
|
32
45
|
*/
|
|
33
46
|
export const mapPortfolioHistory = (range, graph, summary) => {
|
|
34
|
-
const
|
|
47
|
+
const first = graph.find((point) => !Number.isNaN(Date.parse(point.time)));
|
|
48
|
+
const baseline = first === undefined ? undefined : getCumulativeNetFlow(first);
|
|
49
|
+
const points = graph.flatMap((point) => mapPoint(point, baseline) ?? []);
|
|
35
50
|
return {
|
|
36
51
|
range,
|
|
37
52
|
points,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPortfolioHistory.js","sourceRoot":"","sources":["../../../src/utils/mapPortfolioHistory.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mapPortfolioHistory.js","sourceRoot":"","sources":["../../../src/utils/mapPortfolioHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAMxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAMnD,MAAM,aAAa,GAAG,CACpB,OAA6B,EAC7B,KAA4B,EACR,EAAE;IACtB,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,IAAI;YACP,OAAO,OAAO,CAAC,QAAQ,CAAA;QACzB,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,SAAS,CAAA;QAC1B,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,aAAa,CAAA;QAC9B,KAAK,KAAK;YACR,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,iBAAiB,CAAA;AAEnC,MAAM,QAAQ,GAAG,CACf,KAA8B,EAC9B,QAA4B,EACO,EAAE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KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC1E,MAAM,QAAQ,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAA;IAC9E,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACxE,OAAO;QACL,KAAK;QACL,MAAM;QACN,MAAM,EAAE,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC;QACrC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG;KAC7B,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { PerpsMarketDisplay, Position } from '@lifi/perps-types';
|
|
2
2
|
import type { OndoPosition } from '../types/wire.js';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* are cross-margined only. A row with an invalid quantity gives `undefined`;
|
|
6
|
-
* every other figure is the raw venue string.
|
|
7
|
-
*
|
|
8
|
-
* @param market - Backend-resolved market identity for `pos.market`.
|
|
3
|
+
/** Map an Ondo cross position, omitting a row with invalid quantity.
|
|
4
|
+
* Interpret venue ROE as a fraction and return a percent.
|
|
9
5
|
* @public
|
|
10
6
|
*/
|
|
11
7
|
export declare const mapPosition: (pos: OndoPosition, market: PerpsMarketDisplay) => Position | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPosition.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapPosition.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;GAGG;AACH,eAAO,MAAM,WAAW,GACtB,KAAK,YAAY,EACjB,QAAQ,kBAAkB,KACzB,QAAQ,GAAG,SAqCb,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,YAAY,KAAG,OAC6B,CAAA;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,YAAY,EAAE,EACzB,eAAe,CAAC,MAAM,EAAE,MAAM,KAAK,kBAAkB,KACpD,QAAQ,EAIP,CAAA"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { absDecimalString, safeIsDecimalStringZero, unknownToDecimalString, warnSkippedVenueRow, } from '@lifi/perps-sdk';
|
|
1
|
+
import { absDecimalString, buildPosition, isDecimalString, multiplyDecimalString, safeIsDecimalStringZero, unknownToDecimalString, warnSkippedVenueRow, } from '@lifi/perps-sdk';
|
|
2
2
|
import { MarginMode, PositionSide } from '@lifi/perps-types';
|
|
3
3
|
import { ONDO_PROVIDER_KEY } from '../constants.js';
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* are cross-margined only. A row with an invalid quantity gives `undefined`;
|
|
7
|
-
* every other figure is the raw venue string.
|
|
8
|
-
*
|
|
9
|
-
* @param market - Backend-resolved market identity for `pos.market`.
|
|
4
|
+
/** Map an Ondo cross position, omitting a row with invalid quantity.
|
|
5
|
+
* Interpret venue ROE as a fraction and return a percent.
|
|
10
6
|
* @public
|
|
11
7
|
*/
|
|
12
8
|
export const mapPosition = (pos, market) => {
|
|
@@ -18,20 +14,27 @@ export const mapPosition = (pos, market) => {
|
|
|
18
14
|
warnSkippedVenueRow(ONDO_PROVIDER_KEY, 'position', 'netQuantity', pos.netQuantity, { marketId: market.id });
|
|
19
15
|
return undefined;
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
const positionValue = isDecimalString(pos.notionalValue)
|
|
18
|
+
? absDecimalString(pos.notionalValue)
|
|
19
|
+
: undefined;
|
|
20
|
+
return buildPosition({
|
|
22
21
|
market,
|
|
23
22
|
side: pos.direction === 'short' ? PositionSide.SHORT : PositionSide.LONG,
|
|
24
23
|
size,
|
|
25
24
|
entryPrice: pos.averageEntryPrice,
|
|
26
25
|
markPrice: pos.markPrice,
|
|
26
|
+
...(positionValue === undefined ? {} : { positionValue }),
|
|
27
27
|
liquidationPrice: pos.liquidationPrice,
|
|
28
28
|
unrealizedPnl: pos.unrealizedPnl,
|
|
29
|
+
...(isDecimalString(pos.returnOnEquity)
|
|
30
|
+
? { returnOnEquity: multiplyDecimalString(pos.returnOnEquity, '100') }
|
|
31
|
+
: {}),
|
|
29
32
|
accruedFunding: pos.netFundingSinceNeutral,
|
|
30
33
|
leverage: pos.leverage,
|
|
31
34
|
marginUsed: pos.usedMargin,
|
|
32
35
|
initialMarginRequirement: pos.usedMargin,
|
|
33
36
|
marginMode: MarginMode.CROSS,
|
|
34
|
-
};
|
|
37
|
+
});
|
|
35
38
|
};
|
|
36
39
|
/**
|
|
37
40
|
* True when the Ondo position row is not neutral and has a non-zero quantity.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPosition.js","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAGnD
|
|
1
|
+
{"version":3,"file":"mapPosition.js","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,iBAA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C,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE;YACtE,CAAC,CAAC,EAAE,CAAC;QACP,cAAc,EAAE,GAAG,CAAC,sBAAsB;QAC1C,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,wBAAwB,EAAE,GAAG,CAAC,UAAU;QACxC,UAAU,EAAE,UAAU,CAAC,KAAK;KAC7B,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAe,EAAW,EAAE,CACzD,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,IAAI,CAAA;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,SAAyB,EACzB,aAAqD,EACzC,EAAE,CACd,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;IAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IACxD,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA"}
|
|
@@ -64,11 +64,11 @@ export declare class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
64
64
|
private contexts;
|
|
65
65
|
/** Funding seen before the market's first mark price. */
|
|
66
66
|
private pendingFunding;
|
|
67
|
-
/** Latest two-sided top-of-book mid, keyed by venue market symbol. */
|
|
68
|
-
private bookMids;
|
|
69
67
|
/** The single address this connection's login is bound to. */
|
|
70
68
|
private accountAddress;
|
|
71
69
|
private loginPromise;
|
|
70
|
+
private loginAttempt;
|
|
71
|
+
private readonly rejectedTokens;
|
|
72
72
|
private authGeneration;
|
|
73
73
|
private authBindingRefs;
|
|
74
74
|
private closeGeneration;
|
|
@@ -131,11 +131,13 @@ export declare class OndoWsProvider extends WsProviderBase<SubState> {
|
|
|
131
131
|
private readBalance;
|
|
132
132
|
/** Emit the current account summary from the venue balance figures. */
|
|
133
133
|
private emitAccountSummary;
|
|
134
|
+
/** Detach the pending login attempt, if any, and stop its acknowledgement timer. */
|
|
135
|
+
private takeLoginAttempt;
|
|
136
|
+
private rejectLogin;
|
|
134
137
|
protected handleMessage(raw: string): void;
|
|
135
138
|
/** Valid levels of one book side, best first (`-1` bids, `1` asks). */
|
|
136
139
|
private toBookLevels;
|
|
137
140
|
private handleBooks;
|
|
138
|
-
private handleTopOfBooks;
|
|
139
141
|
private handleTrades;
|
|
140
142
|
private handleKline;
|
|
141
143
|
private handleMarkPrices;
|
|
@@ -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,EAQL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAGlB,KAAK,cAAc,EAInB,cAAc,EACd,KAAK,iBAAiB,EAGvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAML,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAqEnC,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;I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qBAAqB,KAC9B,iBAKA,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DecodeChain, getMarketRegistry, isDecimalString, localStorageAdapter, numberToDecimalString, PerpsError, ReconnectingWebSocket, resolveSubscribeQuote, safeCompareDecimalStrings, toMarketDisplay, toPerpsMarketDisplay, WsProviderBase, wsLog, } from '@lifi/perps-sdk';
|
|
2
2
|
import { PerpsErrorCode, } from '@lifi/perps-types';
|
|
3
3
|
import { OndoTokenStore } from '../auth/OndoTokenStore.js';
|
|
4
4
|
import { ondoSessionRejectedError } from '../auth/sessionToken.js';
|
|
@@ -7,10 +7,8 @@ import { isOpenPosition, mapFill, mapOrderUpdates, mapPosition, OndoApiClient, O
|
|
|
7
7
|
import { intervalFromBarSpan, mapInterval } from '../utils/ohlcvInterval.js';
|
|
8
8
|
// Public channels (per market, demuxed from the frame's `market` field):
|
|
9
9
|
// orderbook → depthBooksPerps, trades → tradesPerps, candle → kLinePerps.
|
|
10
|
-
// `marketsContext`/`marketContext` merge
|
|
11
|
-
//
|
|
12
|
-
// `midPrice` is the top-of-book mid; the mark price stands in until a
|
|
13
|
-
// two-sided book arrives for the market.
|
|
10
|
+
// `marketsContext`/`marketContext` merge two wire channels — markPricesPerps
|
|
11
|
+
// and fundingRatesPerps — into the aggregated context emit, with no `midPrice`.
|
|
14
12
|
// Authenticated channels (account-wide, no market filter):
|
|
15
13
|
// orderUpdates → ordersPerps, fills → fillsPerps, positions → positionsPerps.
|
|
16
14
|
//
|
|
@@ -31,6 +29,8 @@ const ONDO_AUTH_FANOUT = [
|
|
|
31
29
|
...Object.keys(ONDO_AUTH_CHANNEL),
|
|
32
30
|
'accountSummary',
|
|
33
31
|
];
|
|
32
|
+
/** Bound on the venue's answer to a `login` op. An unmapped error leaves no other exit. */
|
|
33
|
+
const ONDO_LOGIN_ACK_TIMEOUT_MS = 10_000;
|
|
34
34
|
const isAuthChannel = (channel) => channel in ONDO_AUTH_CHANNEL;
|
|
35
35
|
const BOOK_LEVEL_ROW = 'order book level';
|
|
36
36
|
/**
|
|
@@ -70,11 +70,11 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
70
70
|
contexts = {};
|
|
71
71
|
/** Funding seen before the market's first mark price. */
|
|
72
72
|
pendingFunding = new Map();
|
|
73
|
-
/** Latest two-sided top-of-book mid, keyed by venue market symbol. */
|
|
74
|
-
bookMids = new Map();
|
|
75
73
|
/** The single address this connection's login is bound to. */
|
|
76
74
|
accountAddress;
|
|
77
75
|
loginPromise;
|
|
76
|
+
loginAttempt;
|
|
77
|
+
rejectedTokens = new Set();
|
|
78
78
|
authGeneration = 0;
|
|
79
79
|
authBindingRefs = 0;
|
|
80
80
|
closeGeneration = 0;
|
|
@@ -87,6 +87,7 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
87
87
|
// The venue's login lives and dies with the connection, so a drop must
|
|
88
88
|
// forget both the in-flight login and the address it bound.
|
|
89
89
|
this.rws.on('close', () => {
|
|
90
|
+
this.takeLoginAttempt()?.reject(new Error('Ondo WebSocket closed during login'));
|
|
90
91
|
this.loginPromise = undefined;
|
|
91
92
|
this.accountAddress = undefined;
|
|
92
93
|
});
|
|
@@ -321,8 +322,8 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
321
322
|
onClose() {
|
|
322
323
|
this.contexts = {};
|
|
323
324
|
this.pendingFunding.clear();
|
|
324
|
-
this.bookMids.clear();
|
|
325
325
|
this.loginPromise = undefined;
|
|
326
|
+
this.takeLoginAttempt()?.reject(new Error('Ondo WebSocket closed during login'));
|
|
326
327
|
this.accountAddress = undefined;
|
|
327
328
|
this.authGeneration += 1;
|
|
328
329
|
this.closeGeneration += 1;
|
|
@@ -343,10 +344,6 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
343
344
|
'fundingRatesPerps',
|
|
344
345
|
{ frame: { channel: 'fundingRatesPerps' }, needsAuth: false },
|
|
345
346
|
],
|
|
346
|
-
[
|
|
347
|
-
'topOfBooksPerps',
|
|
348
|
-
{ frame: { channel: 'topOfBooksPerps' }, needsAuth: false },
|
|
349
|
-
],
|
|
350
347
|
];
|
|
351
348
|
case 'marketContext':
|
|
352
349
|
return [
|
|
@@ -364,13 +361,6 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
364
361
|
needsAuth: false,
|
|
365
362
|
},
|
|
366
363
|
],
|
|
367
|
-
[
|
|
368
|
-
`topOfBooksPerps:${sub.marketId}`,
|
|
369
|
-
{
|
|
370
|
-
frame: { channel: 'topOfBooksPerps', markets: [sub.marketId] },
|
|
371
|
-
needsAuth: false,
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
364
|
];
|
|
375
365
|
case 'orderbook':
|
|
376
366
|
return [
|
|
@@ -458,6 +448,9 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
458
448
|
if (token === null) {
|
|
459
449
|
throw new PerpsError(PerpsErrorCode.SetupRequired, `No Ondo session for ${address}. Run the SIWE login before subscribing to account channels.`);
|
|
460
450
|
}
|
|
451
|
+
if (this.rejectedTokens.has(token.token)) {
|
|
452
|
+
throw ondoSessionRejectedError('WebSocket subscription', new OndoSessionExpiredError('Ondo rejected the session token'));
|
|
453
|
+
}
|
|
461
454
|
return token;
|
|
462
455
|
}
|
|
463
456
|
/**
|
|
@@ -468,9 +461,28 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
468
461
|
ensureLogin(address) {
|
|
469
462
|
if (this.loginPromise === undefined) {
|
|
470
463
|
const login = this.requireSession(address).then((token) => {
|
|
471
|
-
if (this.loginPromise
|
|
472
|
-
|
|
464
|
+
if (this.loginPromise !== login) {
|
|
465
|
+
return;
|
|
473
466
|
}
|
|
467
|
+
return new Promise((resolve, reject) => {
|
|
468
|
+
this.rws.send(JSON.stringify({ op: 'login', args: { token: token.token } }));
|
|
469
|
+
const attempt = {
|
|
470
|
+
address,
|
|
471
|
+
token: token.token,
|
|
472
|
+
accepted: false,
|
|
473
|
+
timer: setTimeout(() => {
|
|
474
|
+
if (this.loginAttempt !== attempt) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
this.rejectLogin(new PerpsError(PerpsErrorCode.TimeoutError, 'Ondo did not acknowledge the WebSocket login.'), false);
|
|
478
|
+
// The venue may still hold a half-open login on this socket.
|
|
479
|
+
this.rws.reconnect();
|
|
480
|
+
}, ONDO_LOGIN_ACK_TIMEOUT_MS),
|
|
481
|
+
resolve,
|
|
482
|
+
reject,
|
|
483
|
+
};
|
|
484
|
+
this.loginAttempt = attempt;
|
|
485
|
+
});
|
|
474
486
|
});
|
|
475
487
|
this.loginPromise = login;
|
|
476
488
|
login.catch(() => {
|
|
@@ -539,7 +551,7 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
539
551
|
if (!(err instanceof OndoSessionExpiredError)) {
|
|
540
552
|
throw err;
|
|
541
553
|
}
|
|
542
|
-
await this.tokenStore.remove(address);
|
|
554
|
+
await this.tokenStore.remove(address, token.token);
|
|
543
555
|
throw ondoSessionRejectedError('account summary', err);
|
|
544
556
|
}
|
|
545
557
|
return {
|
|
@@ -567,6 +579,45 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
567
579
|
},
|
|
568
580
|
});
|
|
569
581
|
}
|
|
582
|
+
/** Detach the pending login attempt, if any, and stop its acknowledgement timer. */
|
|
583
|
+
takeLoginAttempt() {
|
|
584
|
+
const attempt = this.loginAttempt;
|
|
585
|
+
if (attempt !== undefined) {
|
|
586
|
+
clearTimeout(attempt.timer);
|
|
587
|
+
this.loginAttempt = undefined;
|
|
588
|
+
}
|
|
589
|
+
return attempt;
|
|
590
|
+
}
|
|
591
|
+
rejectLogin(error, unauthorized) {
|
|
592
|
+
const attempt = this.takeLoginAttempt();
|
|
593
|
+
if (attempt === undefined) {
|
|
594
|
+
wsLog.serverError(this.providerKey, `Login error without a pending login: ${error.message}`);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
this.loginPromise = undefined;
|
|
598
|
+
const address = attempt.address.toLowerCase();
|
|
599
|
+
if (unauthorized) {
|
|
600
|
+
this.rejectedTokens.add(attempt.token);
|
|
601
|
+
void this.tokenStore
|
|
602
|
+
.remove(attempt.address, attempt.token)
|
|
603
|
+
.catch((cause) => wsLog.handlerFailure(this.providerKey, cause));
|
|
604
|
+
}
|
|
605
|
+
for (const [key, state] of this.wireSubs) {
|
|
606
|
+
if (state.needsAuth) {
|
|
607
|
+
this.unregisterSub(key);
|
|
608
|
+
this.rws.send(JSON.stringify({ op: 'unsubscribe', ...state.frame }));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
this.authWireRefs.clear();
|
|
612
|
+
this.authBindingRefs = 0;
|
|
613
|
+
this.authGeneration += 1;
|
|
614
|
+
this.accountAddress = undefined;
|
|
615
|
+
this.clearAccountSummary();
|
|
616
|
+
attempt.reject(error);
|
|
617
|
+
for (const channel of ONDO_AUTH_FANOUT) {
|
|
618
|
+
this.rejectChannel(`${channel}:${address}`, error);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
570
621
|
handleMessage(raw) {
|
|
571
622
|
let msg;
|
|
572
623
|
try {
|
|
@@ -576,8 +627,27 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
576
627
|
wsLog.parseFailure(this.providerKey, raw);
|
|
577
628
|
return;
|
|
578
629
|
}
|
|
630
|
+
if (msg.type === 'loggedIn') {
|
|
631
|
+
if (this.loginAttempt !== undefined) {
|
|
632
|
+
clearTimeout(this.loginAttempt.timer);
|
|
633
|
+
this.loginAttempt.accepted = true;
|
|
634
|
+
this.loginAttempt.resolve();
|
|
635
|
+
}
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
579
638
|
if (msg.type === 'error') {
|
|
580
|
-
|
|
639
|
+
if (msg.msg?.startsWith('error parsing jwt: ')) {
|
|
640
|
+
this.rejectLogin(ondoSessionRejectedError('WebSocket subscription', new OndoSessionExpiredError('Ondo rejected the session token')), true);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (this.loginAttempt !== undefined &&
|
|
644
|
+
!this.loginAttempt.accepted &&
|
|
645
|
+
(msg.msg === 'already logged in on this connection' ||
|
|
646
|
+
msg.msg === 'account already has too many connections')) {
|
|
647
|
+
this.rejectLogin(new PerpsError(PerpsErrorCode.ThirdPartyError, msg.msg), false);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
wsLog.serverError(this.providerKey, 'Venue rejected a WebSocket request');
|
|
581
651
|
return;
|
|
582
652
|
}
|
|
583
653
|
if (msg.type !== 'update') {
|
|
@@ -588,9 +658,6 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
588
658
|
case 'depthBooksPerps':
|
|
589
659
|
this.handleBooks(msg.data);
|
|
590
660
|
break;
|
|
591
|
-
case 'topOfBooksPerps':
|
|
592
|
-
this.handleTopOfBooks(msg.data);
|
|
593
|
-
break;
|
|
594
661
|
case 'tradesPerps':
|
|
595
662
|
this.handleTrades(msg.data);
|
|
596
663
|
break;
|
|
@@ -648,30 +715,6 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
648
715
|
});
|
|
649
716
|
}
|
|
650
717
|
}
|
|
651
|
-
handleTopOfBooks(snapshots) {
|
|
652
|
-
const touched = [];
|
|
653
|
-
for (const { market, bids, asks } of snapshots) {
|
|
654
|
-
const bestBid = this.toBookLevels(market, bids, -1)[0];
|
|
655
|
-
const bestAsk = this.toBookLevels(market, asks, 1)[0];
|
|
656
|
-
if (bestBid === undefined || bestAsk === undefined) {
|
|
657
|
-
this.bookMids.delete(market);
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
this.bookMids.set(market, divideDecimalString(addDecimalString(bestBid.price, bestAsk.price), '2'));
|
|
661
|
-
}
|
|
662
|
-
const context = this.contexts[market];
|
|
663
|
-
if (context !== undefined) {
|
|
664
|
-
this.contexts[market] = {
|
|
665
|
-
...context,
|
|
666
|
-
midPrice: this.bookMids.get(market) ?? context.markPrice,
|
|
667
|
-
};
|
|
668
|
-
touched.push(market);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
if (touched.length > 0) {
|
|
672
|
-
this.emitContexts(touched);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
718
|
handleTrades(trades) {
|
|
676
719
|
const byMarket = new Map();
|
|
677
720
|
for (const trade of trades) {
|
|
@@ -721,8 +764,6 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
721
764
|
...this.contexts[market],
|
|
722
765
|
provider: this.providerKey,
|
|
723
766
|
marketId: market,
|
|
724
|
-
// The mark price stands in until a two-sided top-of-book arrives.
|
|
725
|
-
midPrice: this.bookMids.get(market) ?? markPrice,
|
|
726
767
|
markPrice,
|
|
727
768
|
oraclePrice,
|
|
728
769
|
};
|
|
@@ -753,10 +794,7 @@ export class OndoWsProvider extends WsProviderBase {
|
|
|
753
794
|
this.emitContexts(touched);
|
|
754
795
|
}
|
|
755
796
|
emitContexts(markets) {
|
|
756
|
-
this.
|
|
757
|
-
channel: 'marketsContext',
|
|
758
|
-
data: { ...this.contexts },
|
|
759
|
-
});
|
|
797
|
+
this.emitMarketsContext(() => ({ ...this.contexts }));
|
|
760
798
|
for (const market of markets) {
|
|
761
799
|
const context = this.contexts[market];
|
|
762
800
|
if (context !== undefined) {
|