@lifi/perps-sdk-provider-hyperliquid 0.0.0-preview-71d5f8b → 0.0.0-preview-2138c36
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/services/getOrder.d.ts.map +1 -1
- package/dist/cjs/services/getOrder.js +3 -7
- package/dist/cjs/services/getOrder.js.map +1 -1
- package/dist/cjs/services/getOrders.d.ts.map +1 -1
- package/dist/cjs/services/getOrders.js +23 -4
- package/dist/cjs/services/getOrders.js.map +1 -1
- package/dist/cjs/services/getWithdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/services/getWithdrawableBalances.js +8 -2
- package/dist/cjs/services/getWithdrawableBalances.js.map +1 -1
- package/dist/cjs/utils/explorer.d.ts +1 -2
- package/dist/cjs/utils/explorer.d.ts.map +1 -1
- package/dist/cjs/utils/explorer.js +1 -24
- package/dist/cjs/utils/explorer.js.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.js +8 -2
- package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
- package/dist/esm/services/getOrder.d.ts.map +1 -1
- package/dist/esm/services/getOrder.js +3 -7
- package/dist/esm/services/getOrder.js.map +1 -1
- package/dist/esm/services/getOrders.d.ts.map +1 -1
- package/dist/esm/services/getOrders.js +34 -6
- package/dist/esm/services/getOrders.js.map +1 -1
- package/dist/esm/services/getWithdrawableBalances.d.ts +5 -3
- package/dist/esm/services/getWithdrawableBalances.d.ts.map +1 -1
- package/dist/esm/services/getWithdrawableBalances.js +11 -6
- package/dist/esm/services/getWithdrawableBalances.js.map +1 -1
- package/dist/esm/utils/explorer.d.ts +1 -9
- package/dist/esm/utils/explorer.d.ts.map +1 -1
- package/dist/esm/utils/explorer.js +1 -32
- package/dist/esm/utils/explorer.js.map +1 -1
- package/dist/esm/utils/withdrawableBalances.d.ts +3 -1
- package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/esm/utils/withdrawableBalances.js +10 -2
- package/dist/esm/utils/withdrawableBalances.js.map +1 -1
- package/dist/types/services/getOrder.d.ts.map +1 -1
- package/dist/types/services/getOrders.d.ts.map +1 -1
- package/dist/types/services/getWithdrawableBalances.d.ts +5 -3
- package/dist/types/services/getWithdrawableBalances.d.ts.map +1 -1
- package/dist/types/utils/explorer.d.ts +1 -9
- package/dist/types/utils/explorer.d.ts.map +1 -1
- package/dist/types/utils/withdrawableBalances.d.ts +3 -1
- package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/services/getOrder.ts +3 -10
- package/src/services/getOrders.ts +56 -5
- package/src/services/getWithdrawableBalances.ts +33 -22
- package/src/utils/explorer.ts +2 -49
- package/src/utils/withdrawableBalances.ts +12 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrder.d.ts","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"getOrder.d.ts","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAavD,MAAM,MAAM,cAAc,GAAG,sBAAsB,CAAA;AAQnD,eAAO,MAAM,QAAQ,GACnB,oBAAoB,kBAAkB,EACtC,QAAQ,cAAc,EACtB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,KAAK,CAkDf,CAAA"}
|
|
@@ -4,7 +4,6 @@ exports.getOrder = void 0;
|
|
|
4
4
|
const perps_sdk_1 = require("@lifi/perps-sdk");
|
|
5
5
|
const perps_types_1 = require("@lifi/perps-types");
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
|
-
const explorer_js_1 = require("../utils/explorer.js");
|
|
8
7
|
const index_js_1 = require("../utils/index.js");
|
|
9
8
|
const infoClient_js_1 = require("../utils/infoClient.js");
|
|
10
9
|
const getOrder = async ({ client, apiUrl }, params, options) => {
|
|
@@ -16,10 +15,9 @@ const getOrder = async ({ client, apiUrl }, params, options) => {
|
|
|
16
15
|
err.tool = constants_js_1.PROVIDER_KEY;
|
|
17
16
|
throw err;
|
|
18
17
|
}
|
|
19
|
-
const
|
|
20
|
-
const status = await (0, infoClient_js_1.infoRequest)(apiUrl, { type: 'orderStatus', user: params.address, oid }, infoOpts);
|
|
18
|
+
const status = await (0, infoClient_js_1.infoRequest)(apiUrl, { type: 'orderStatus', user: params.address, oid }, (0, infoClient_js_1.hlInfoOptions)(client, options));
|
|
21
19
|
if (status.status !== 'order') {
|
|
22
|
-
const history = await (0, infoClient_js_1.infoRequest)(apiUrl, { type: 'twapHistory', user: params.address },
|
|
20
|
+
const history = await (0, infoClient_js_1.infoRequest)(apiUrl, { type: 'twapHistory', user: params.address }, (0, infoClient_js_1.hlInfoOptions)(client, options));
|
|
23
21
|
const twap = history.find((entry) => String(entry.twapId) === params.id && !(0, index_js_1.assetIsOutcome)(entry.state.coin));
|
|
24
22
|
if (twap !== undefined) {
|
|
25
23
|
const registry = (0, perps_sdk_1.getMarketRegistry)(client, constants_js_1.PROVIDER_KEY);
|
|
@@ -34,9 +32,7 @@ const getOrder = async ({ client, apiUrl }, params, options) => {
|
|
|
34
32
|
}
|
|
35
33
|
const registry = (0, perps_sdk_1.getMarketRegistry)(client, constants_js_1.PROVIDER_KEY);
|
|
36
34
|
await registry.sync();
|
|
37
|
-
|
|
38
|
-
const [linked] = await (0, explorer_js_1.withExplorerLinks)([order], params.address, infoOpts);
|
|
39
|
-
return linked;
|
|
35
|
+
return (0, index_js_1.mapOrder)(status.order, registry.require(status.order.order.coin));
|
|
40
36
|
};
|
|
41
37
|
exports.getOrder = getOrder;
|
|
42
38
|
//# sourceMappingURL=getOrder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrder.js","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":";;;AAAA,+CAKwB;AAExB,mDAAkD;AAClD,kDAA8C;AAM9C,
|
|
1
|
+
{"version":3,"file":"getOrder.js","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":";;;AAAA,+CAKwB;AAExB,mDAAkD;AAClD,kDAA8C;AAM9C,gDAA4D;AAC5D,0DAAmE;AAe5D,MAAM,QAAQ,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,MAAM,EAAsB,EACtC,MAAsB,EACtB,OAA2B,EACX,EAAE;IAClB,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxD,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACtD,IACE,CAAC,UAAU;QACX,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAC3D,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,sBAAU,CACxB,4BAAc,CAAC,eAAe,EAC9B,qBAAqB,MAAM,CAAC,EAAE,8CAA8C,CAC7E,CAAA;QACD,GAAG,CAAC,IAAI,GAAG,2BAAY,CAAA;QACvB,MAAM,GAAG,CAAA;IACX,CAAC;IAED,MAAM,MAAM,GAAG,MA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AM,GAAG,CAAA;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,6BAAiB,EAAC,MAAM,EAAE,2BAAY,CAAC,CAAA;IACxD,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACrB,OAAO,IAAA,mBAAQ,EAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1E,CAAC,CAAA;AAtDY,QAAA,QAAQ,YAsDpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAwB,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAE7E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAqBvD,MAAM,MAAM,eAAe,GAAG,uBAAuB,CAAA;AA6ErD,eAAO,MAAM,SAAS,GACpB,oBAAoB,kBAAkB,EACtC,QAAQ,eAAe,EACvB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,cAAc,CAoGxB,CAAA"}
|
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getOrders = void 0;
|
|
4
4
|
const perps_sdk_1 = require("@lifi/perps-sdk");
|
|
5
5
|
const constants_js_1 = require("../constants.js");
|
|
6
|
-
const explorer_js_1 = require("../utils/explorer.js");
|
|
7
6
|
const index_js_1 = require("../utils/index.js");
|
|
8
7
|
const infoClient_js_1 = require("../utils/infoClient.js");
|
|
9
8
|
const warn = (0, perps_sdk_1.createWarnOnce)();
|
|
10
|
-
const warnOnce = (key) => {
|
|
11
|
-
warn(key, `[${constants_js_1.PROVIDER_KEY}] ${key}`);
|
|
9
|
+
const warnOnce = (key, detail) => {
|
|
10
|
+
warn(key, `[${constants_js_1.PROVIDER_KEY}] ${detail === undefined ? key : `${key}: ${detail}`}`);
|
|
12
11
|
};
|
|
13
12
|
const mapRow = (coin, registry, map) => {
|
|
14
13
|
if ((0, index_js_1.assetIsOutcome)(coin)) {
|
|
@@ -29,6 +28,26 @@ const mapRow = (coin, registry, map) => {
|
|
|
29
28
|
return undefined;
|
|
30
29
|
}
|
|
31
30
|
};
|
|
31
|
+
const withExplorerLinks = async (orders, address, options) => {
|
|
32
|
+
if (!orders.some((order) => order.clientOrderId !== undefined)) {
|
|
33
|
+
return orders;
|
|
34
|
+
}
|
|
35
|
+
let txs;
|
|
36
|
+
try {
|
|
37
|
+
txs = await (0, index_js_1.fetchUserTransactions)(address, options);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (!(error instanceof perps_sdk_1.PerpsError)) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
warnOnce('explorer link lookup failed', error.message);
|
|
44
|
+
return orders;
|
|
45
|
+
}
|
|
46
|
+
return orders.map((order) => {
|
|
47
|
+
const explorerLink = (0, perps_sdk_1.explorerTxUrl)(perps_sdk_1.ExplorerChainId.HYPERLIQUID, (0, index_js_1.matchOrderActionHash)(txs, order));
|
|
48
|
+
return explorerLink === undefined ? order : { ...order, explorerLink };
|
|
49
|
+
});
|
|
50
|
+
};
|
|
32
51
|
const getOrders = async ({ client, apiUrl }, params, options) => {
|
|
33
52
|
const statuses = params.statuses ?? [...perps_sdk_1.ACTIVE_ORDER_STATUSES];
|
|
34
53
|
if (statuses.length === 0) {
|
|
@@ -84,7 +103,7 @@ const getOrders = async ({ client, apiUrl }, params, options) => {
|
|
|
84
103
|
}
|
|
85
104
|
const matching = [...rows.values()].filter((order) => statuses.includes(order.status) &&
|
|
86
105
|
(params.marketId === undefined || order.market.id === params.marketId));
|
|
87
|
-
const orders = await
|
|
106
|
+
const orders = await withExplorerLinks(matching, params.address, infoOpts);
|
|
88
107
|
return {
|
|
89
108
|
provider: constants_js_1.PROVIDER_KEY,
|
|
90
109
|
orders,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":";;;AAAA,+CAWwB;AAExB,kDAA8C;AAQ9C,gDAM0B;AAC1B,0DAI+B;AAK/B,MAAM,IAAI,GAAG,IAAA,0BAAc,GAAE,CAAA;AAE7B,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,MAAe,EAAQ,EAAE;IACtD,IAAI,CACF,GAAG,EACH,IAAI,2BAAY,KAAK,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,MAAM,EAAE,EAAE,CACxE,CAAA;AACH,CAAC,CAAA;AAQD,MAAM,MAAM,GAAG,CACb,IAAY,EACZ,QAAwB,EACxB,GAAqC,EAClB,EAAE;IACrB,IAAI,IAAA,yBAAc,EAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,sBAAU,CAAC,EAAE,CAAC;YACnC,MAAM,KAAK,CAAA;QACb,CAAC;QACD,QAAQ,C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,QAAQ,EAAE,2BAAY;QACtB,MAAM;QACN,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE;KACrE,CAAA;AACH,CAAC,CAAA;AAxGY,QAAA,SAAS,aAwGrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWithdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getWithdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,qCAAqC,EAC1C,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAcvD,MAAM,MAAM,6BAA6B,GACvC,qCAAqC,CAAA;AAgBvC,eAAO,MAAM,uBAAuB,GAClC,oBAAoB,kBAAkB,EACtC,QAAQ,6BAA6B,EACrC,UAAU,iBAAiB,KAC1B,OAAO,CAAC,2BAA2B,EAAE,CAgDvC,CAAA"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getWithdrawableBalances = void 0;
|
|
4
7
|
const perps_sdk_1 = require("@lifi/perps-sdk");
|
|
5
8
|
const perps_types_1 = require("@lifi/perps-types");
|
|
9
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
6
10
|
const constants_js_1 = require("../constants.js");
|
|
7
11
|
const infoClient_js_1 = require("../utils/infoClient.js");
|
|
8
12
|
const withdrawableBalances_js_1 = require("../utils/withdrawableBalances.js");
|
|
9
13
|
const getWithdrawableBalances = async ({ client, apiUrl }, params, options) => {
|
|
10
14
|
const registry = (0, perps_sdk_1.getMarketRegistry)(client, constants_js_1.PROVIDER_KEY);
|
|
11
15
|
const infoOpts = (0, infoClient_js_1.hlInfoOptions)(client, options);
|
|
12
|
-
const [markets, abstraction, state, spotState] = await Promise.all([
|
|
16
|
+
const [{ providers }, markets, abstraction, state, spotState] = await Promise.all([
|
|
17
|
+
(0, perps_sdk_1.getProviders)(client, options),
|
|
13
18
|
registry.sync(),
|
|
14
19
|
(0, infoClient_js_1.infoRequest)(apiUrl, { type: 'userAbstraction', user: params.address }, infoOpts),
|
|
15
20
|
(0, infoClient_js_1.infoRequest)(apiUrl, { type: 'clearinghouseState', user: params.address }, infoOpts),
|
|
@@ -21,7 +26,8 @@ const getWithdrawableBalances = async ({ client, apiUrl }, params, options) => {
|
|
|
21
26
|
error.tool = constants_js_1.PROVIDER_KEY;
|
|
22
27
|
throw error;
|
|
23
28
|
}
|
|
24
|
-
|
|
29
|
+
const feeUsd = providers.find((provider) => provider.key === constants_js_1.PROVIDER_KEY)?.withdrawalFeeUsd;
|
|
30
|
+
return (0, withdrawableBalances_js_1.hyperliquidWithdrawableBalances)(abstraction, state, spotState, quoteAsset.id, feeUsd === undefined ? undefined : new big_js_1.default(feeUsd).toFixed());
|
|
25
31
|
};
|
|
26
32
|
exports.getWithdrawableBalances = getWithdrawableBalances;
|
|
27
33
|
//# sourceMappingURL=getWithdrawableBalances.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWithdrawableBalances.js","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getWithdrawableBalances.js","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":";;;;;;AAAA,+CAOwB;AACxB,mDAAkD;AAClD,oDAAwB;AACxB,kDAA8D;AAO9D,0DAA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IAED,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAC3B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,KAAK,2BAAY,CAC5C,EAAE,gBAAgB,CAAA;IAEnB,OAAO,IAAA,yDAA+B,EACpC,WAAW,EACX,KAAK,EACL,SAAS,EACT,UAAU,CAAC,EAAE,EACb,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,gBAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAC7D,CAAA;AACH,CAAC,CAAA;AApDY,QAAA,uBAAuB,2BAoDnC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OrderBase } from '@lifi/perps-types';
|
|
2
2
|
import { type HlExplorerTx } from '../types/explorer.js';
|
|
3
3
|
import { type InfoRequestOptions } from './infoClient.js';
|
|
4
4
|
export declare const fetchUserTransactions: (address: string, options?: InfoRequestOptions) => Promise<HlExplorerTx[]>;
|
|
5
5
|
export declare const getClientOrderIds: (action: Record<string, unknown>) => string[];
|
|
6
6
|
export declare const matchOrderActionHash: (txs: HlExplorerTx[], order: Pick<OrderBase, "clientOrderId">) => string | undefined;
|
|
7
|
-
export declare const withExplorerLinks: (orders: Order[], address: string, options: InfoRequestOptions) => Promise<Order[]>;
|
|
8
7
|
//# sourceMappingURL=explorer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGlD,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAerE,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,EACf,UAAU,kBAAkB,KAC3B,OAAO,CAAC,YAAY,EAAE,CASxB,CAAA;AASD,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,MAAM,EAyBR,CAAA;AASD,eAAO,MAAM,oBAAoB,GAC/B,KAAK,YAAY,EAAE,EACnB,OAAO,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,KACtC,MAAM,GAAG,SAaX,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const perps_sdk_1 = require("@lifi/perps-sdk");
|
|
3
|
+
exports.matchOrderActionHash = exports.getClientOrderIds = exports.fetchUserTransactions = void 0;
|
|
5
4
|
const viem_1 = require("viem");
|
|
6
5
|
const constants_js_1 = require("../constants.js");
|
|
7
6
|
const explorer_js_1 = require("../types/explorer.js");
|
|
@@ -47,26 +46,4 @@ const matchOrderActionHash = (txs, order) => {
|
|
|
47
46
|
return match?.hash;
|
|
48
47
|
};
|
|
49
48
|
exports.matchOrderActionHash = matchOrderActionHash;
|
|
50
|
-
const warn = (0, perps_sdk_1.createWarnOnce)();
|
|
51
|
-
const withExplorerLinks = async (orders, address, options) => {
|
|
52
|
-
if (!orders.some((order) => order.clientOrderId !== undefined)) {
|
|
53
|
-
return orders;
|
|
54
|
-
}
|
|
55
|
-
let txs;
|
|
56
|
-
try {
|
|
57
|
-
txs = await (0, exports.fetchUserTransactions)(address, options);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
if (!(error instanceof perps_sdk_1.PerpsError)) {
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
warn('explorer link lookup failed', `[${constants_js_1.PROVIDER_KEY}] explorer link lookup failed: ${error.message}`);
|
|
64
|
-
return orders;
|
|
65
|
-
}
|
|
66
|
-
return orders.map((order) => {
|
|
67
|
-
const explorerLink = (0, perps_sdk_1.explorerTxUrl)(perps_sdk_1.ExplorerChainId.HYPERLIQUID, (0, exports.matchOrderActionHash)(txs, order));
|
|
68
|
-
return explorerLink === undefined ? order : { ...order, explorerLink };
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
exports.withExplorerLinks = withExplorerLinks;
|
|
72
49
|
//# sourceMappingURL=explorer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.js","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"explorer.js","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":";;;AACA,+BAA4B;AAC5B,kDAA8D;AAC9D,sDAAwE;AACxE,mDAAqE;AAErE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAYtC,MAAM,qBAAqB,GAAG,KAAK,EACxC,OAAe,EACf,OAA4B,EACH,EAAE;IAC3B,MAAM,IAAI,GAAG,MAAM,IAAA,0BAAU,EAC3B,2CAA4B,EAC5B,sBAAsB,EACtB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,EACtC,OAAO,CACR,CAAA;IACD,MAAM,GAAG,GAAG,IAAI,EAAE,GAAG,CAAA;IACrB,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,4BAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC7D,CAAC,CAAA;AAZY,QAAA,qBAAqB,yBAYjC;AASM,MAAM,iBAAiB,GAAG,CAC/B,MAA+B,EACrB,EAAE;IACZ,MAAM,KAAK,GAAc;QACvB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC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MAAM,CAAC;QACnB,IAAA,yBAAiB,EAAC,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CACzE,CAAA;IACD,OAAO,KAAK,EAAE,IAAI,CAAA;AACpB,CAAC,CAAA;AAhBY,QAAA,oBAAoB,wBAgBhC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ProviderWithdrawableBalance } from '@lifi/perps-sdk';
|
|
2
2
|
import type { HlAbstractionMode, HlClearinghouseState, HlSpotClearinghouseState } from '../types/index.js';
|
|
3
|
-
export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string) => ProviderWithdrawableBalance[];
|
|
3
|
+
export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string, withdrawalFee?: string) => ProviderWithdrawableBalance[];
|
|
4
4
|
//# sourceMappingURL=withdrawableBalances.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;AAiB1B,eAAO,MAAM,+BAA+B,GAC1C,aAAa,iBAAiB,GAAG,IAAI,EACrC,OAAO,oBAAoB,EAC3B,WAAW,wBAAwB,EACnC,cAAc,MAAM,EACpB,gBAAgB,MAAM,KACrB,2BAA2B,EAsC7B,CAAA"}
|
|
@@ -4,8 +4,11 @@ exports.hyperliquidWithdrawableBalances = void 0;
|
|
|
4
4
|
const abstractionMode_js_1 = require("./abstractionMode.js");
|
|
5
5
|
const assetId_js_1 = require("./assetId.js");
|
|
6
6
|
const decimal_js_1 = require("./decimal.js");
|
|
7
|
-
const hyperliquidWithdrawableBalances = (abstraction, state, spotState, quoteAssetId) => {
|
|
7
|
+
const hyperliquidWithdrawableBalances = (abstraction, state, spotState, quoteAssetId, withdrawalFee) => {
|
|
8
8
|
const rows = [];
|
|
9
|
+
const feeFor = (assetId) => withdrawalFee === undefined || assetId !== quoteAssetId
|
|
10
|
+
? {}
|
|
11
|
+
: { withdrawalFee };
|
|
9
12
|
if ((0, abstractionMode_js_1.isUnifiedAbstraction)(abstraction)) {
|
|
10
13
|
for (const balance of spotState.balances) {
|
|
11
14
|
if ((0, assetId_js_1.assetIsOutcome)(balance.coin)) {
|
|
@@ -13,10 +16,12 @@ const hyperliquidWithdrawableBalances = (abstraction, state, spotState, quoteAss
|
|
|
13
16
|
}
|
|
14
17
|
const spot = (0, decimal_js_1.toWireBig)(balance.total, 'spotBalance.total').minus((0, decimal_js_1.toWireBig)(balance.hold, 'spotBalance.hold'));
|
|
15
18
|
if (spot.gt(0)) {
|
|
19
|
+
const assetId = String(balance.token);
|
|
16
20
|
rows.push({
|
|
17
|
-
assetId
|
|
21
|
+
assetId,
|
|
18
22
|
route: 'spot',
|
|
19
23
|
available: spot.toFixed(),
|
|
24
|
+
...feeFor(assetId),
|
|
20
25
|
});
|
|
21
26
|
}
|
|
22
27
|
}
|
|
@@ -27,6 +32,7 @@ const hyperliquidWithdrawableBalances = (abstraction, state, spotState, quoteAss
|
|
|
27
32
|
assetId: quoteAssetId,
|
|
28
33
|
route: 'perps',
|
|
29
34
|
available: perps.toFixed(),
|
|
35
|
+
...feeFor(quoteAssetId),
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
return rows;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawableBalances.js","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":";;;AAMA,6DAA2D;AAC3D,6CAA6C;AAC7C,6CAAwC;
|
|
1
|
+
{"version":3,"file":"withdrawableBalances.js","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":";;;AAMA,6DAA2D;AAC3D,6CAA6C;AAC7C,6CAAwC;AAcjC,MAAM,+BAA+B,GAAG,CAC7C,WAAqC,EACrC,KAA2B,EAC3B,SAAmC,EACnC,YAAoB,EACpB,aAAsB,EACS,EAAE;IACjC,MAAM,IAAI,GAAkC,EAAE,CAAA;IAC9C,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,EAAE,CACjC,aAAa,KAAK,SAAS,IAAI,OAAO,KAAK,YAAY;QACrD,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,EAAE,aAAa,EAAE,CAAA;IAEvB,IAAI,IAAA,yCAAoB,EAAC,WAAW,CAAC,EAAE,CAAC;QACtC,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;YACzC,IAAI,IAAA,2BAAc,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjC,SAAQ;YACV,CAAC;YACD,MAAM,IAAI,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,KAAK,CAC9D,IAAA,sBAAS,EAAC,OAAO,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAC5C,CAAA;YACD,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACf,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;gBACrC,IAAI,CAAC,IAAI,CAAC;oBACR,OAAO;oBACP,KAAK,EAAE,MAAM;oBACb,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE;oBACzB,GAAG,MAAM,CAAC,OAAO,CAAC;iBACnB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,IAAA,sBAAS,EAAC,KAAK,CAAC,YAAY,EAAE,iCAAiC,CAAC,CAAA;IAC9E,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,IAAI,CAAC;YACR,OAAO,EAAE,YAAY;YACrB,KAAK,EAAE,OAAO;YACd,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;YAC1B,GAAG,MAAM,CAAC,YAAY,CAAC;SACxB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AA5CY,QAAA,+BAA+B,mCA4C3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrder.d.ts","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"getOrder.d.ts","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAQvD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,sBAAsB,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GACnB,oBAAoB,kBAAkB,EACtC,QAAQ,cAAc,EACtB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,KAAK,CAkDf,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getMarketRegistry, PerpsError, } from '@lifi/perps-sdk';
|
|
2
2
|
import { PerpsErrorCode } from '@lifi/perps-types';
|
|
3
3
|
import { PROVIDER_KEY } from '../constants.js';
|
|
4
|
-
import { withExplorerLinks } from '../utils/explorer.js';
|
|
5
4
|
import { assetIsOutcome, mapOrder } from '../utils/index.js';
|
|
6
5
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js';
|
|
7
6
|
/**
|
|
@@ -19,10 +18,9 @@ export const getOrder = async ({ client, apiUrl }, params, options) => {
|
|
|
19
18
|
err.tool = PROVIDER_KEY;
|
|
20
19
|
throw err;
|
|
21
20
|
}
|
|
22
|
-
const
|
|
23
|
-
const status = await infoRequest(apiUrl, { type: 'orderStatus', user: params.address, oid }, infoOpts);
|
|
21
|
+
const status = await infoRequest(apiUrl, { type: 'orderStatus', user: params.address, oid }, hlInfoOptions(client, options));
|
|
24
22
|
if (status.status !== 'order') {
|
|
25
|
-
const history = await infoRequest(apiUrl, { type: 'twapHistory', user: params.address },
|
|
23
|
+
const history = await infoRequest(apiUrl, { type: 'twapHistory', user: params.address }, hlInfoOptions(client, options));
|
|
26
24
|
const twap = history.find((entry) => String(entry.twapId) === params.id && !assetIsOutcome(entry.state.coin));
|
|
27
25
|
if (twap !== undefined) {
|
|
28
26
|
const registry = getMarketRegistry(client, PROVIDER_KEY);
|
|
@@ -37,8 +35,6 @@ export const getOrder = async ({ client, apiUrl }, params, options) => {
|
|
|
37
35
|
}
|
|
38
36
|
const registry = getMarketRegistry(client, PROVIDER_KEY);
|
|
39
37
|
await registry.sync();
|
|
40
|
-
|
|
41
|
-
const [linked] = await withExplorerLinks([order], params.address, infoOpts);
|
|
42
|
-
return linked;
|
|
38
|
+
return mapOrder(status.order, registry.require(status.order.order.coin));
|
|
43
39
|
};
|
|
44
40
|
//# sourceMappingURL=getOrder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrder.js","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,UAAU,GAGX,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAM9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"getOrder.js","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,UAAU,GAGX,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAM9C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AASnE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,MAAM,EAAsB,EACtC,MAAsB,EACtB,OAA2B,EACX,EAAE;IAClB,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxD,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACtD,IACE,CAAC,UAAU;QACX,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,C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AAC,IAAI,CAAC,EAAE,CAAC;QACzE,MAAM,GAAG,GAAG,IAAI,UAAU,CACxB,cAAc,CAAC,aAAa,EAC5B,oBAAoB,MAAM,CAAC,EAAE,EAAE,CAChC,CAAA;QACD,GAAG,CAAC,IAAI,GAAG,YAAY,CAAA;QACvB,MAAM,GAAG,CAAA;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACxD,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACrB,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1E,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAwB,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAE7E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAoBvD,kEAAkE;AAClE,MAAM,MAAM,eAAe,GAAG,uBAAuB,CAAA;AA4ErD,iFAAiF;AACjF,eAAO,MAAM,SAAS,GACpB,oBAAoB,kBAAkB,EACtC,QAAQ,eAAe,EACvB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,cAAc,CAoGxB,CAAA"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ACTIVE_ORDER_STATUSES, createWarnOnce, getMarketRegistry, isActiveOrderStatus, PerpsError, } from '@lifi/perps-sdk';
|
|
1
|
+
import { ACTIVE_ORDER_STATUSES, createWarnOnce, ExplorerChainId, explorerTxUrl, getMarketRegistry, isActiveOrderStatus, PerpsError, } from '@lifi/perps-sdk';
|
|
2
2
|
import { PROVIDER_KEY } from '../constants.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js';
|
|
3
|
+
import { assetIsOutcome, fetchUserTransactions, mapOrder, matchOrderActionHash, perpsDexNames, } from '../utils/index.js';
|
|
4
|
+
import { hlInfoOptions, infoRequest, } from '../utils/infoClient.js';
|
|
6
5
|
const warn = createWarnOnce();
|
|
7
|
-
const warnOnce = (key) => {
|
|
8
|
-
warn(key, `[${PROVIDER_KEY}] ${key}`);
|
|
6
|
+
const warnOnce = (key, detail) => {
|
|
7
|
+
warn(key, `[${PROVIDER_KEY}] ${detail === undefined ? key : `${key}: ${detail}`}`);
|
|
9
8
|
};
|
|
10
9
|
/**
|
|
11
10
|
* Map one venue row, or drop it. An outcome market identity, a coin the backend
|
|
@@ -32,6 +31,35 @@ const mapRow = (coin, registry, map) => {
|
|
|
32
31
|
return undefined;
|
|
33
32
|
}
|
|
34
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Set `explorerLink` on each row whose placement transaction the explorer
|
|
36
|
+
* window still holds. One explorer read serves the whole page, and it is
|
|
37
|
+
* skipped when no row carries a client order id to match on. The link is
|
|
38
|
+
* supplementary, so an explorer failure warns and leaves the rows unlinked
|
|
39
|
+
* instead of failing the order read.
|
|
40
|
+
*/
|
|
41
|
+
const withExplorerLinks = async (orders, address, options) => {
|
|
42
|
+
if (!orders.some((order) => order.clientOrderId !== undefined)) {
|
|
43
|
+
return orders;
|
|
44
|
+
}
|
|
45
|
+
let txs;
|
|
46
|
+
try {
|
|
47
|
+
txs = await fetchUserTransactions(address, options);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (!(error instanceof PerpsError)) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
// The message stays out of the key: a transport failure names hosts and
|
|
54
|
+
// ports, so keying on it would let the dedupe set grow without bound.
|
|
55
|
+
warnOnce('explorer link lookup failed', error.message);
|
|
56
|
+
return orders;
|
|
57
|
+
}
|
|
58
|
+
return orders.map((order) => {
|
|
59
|
+
const explorerLink = explorerTxUrl(ExplorerChainId.HYPERLIQUID, matchOrderActionHash(txs, order));
|
|
60
|
+
return explorerLink === undefined ? order : { ...order, explorerLink };
|
|
61
|
+
});
|
|
62
|
+
};
|
|
35
63
|
/** Read regular, trigger, and TWAP orders from the requested lifecycle feeds. */
|
|
36
64
|
export const getOrders = async ({ client, apiUrl }, params, options) => {
|
|
37
65
|
const statuses = params.statuses ?? [...ACTIVE_ORDER_STATUSES];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EAEnB,UAAU,GAGX,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EAEnB,UAAU,GAGX,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAQ9C,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,QAAQ,EACR,oBAAoB,EACpB,aAAa,GACd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,aAAa,EAEb,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAK/B,MAAM,IAAI,GAAG,cAAc,EAAE,CAAA;AAE7B,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,M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C,GAAG,CAAC,CAAC,CAC3C,CACF,CAAA;QACH,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CACF,QAAQ,IAAI,CAAC,MAAM,EAAE,EACrB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CACtE,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CACxC,CAAC,KAAK,EAAE,EAAE,CACR,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC;QAC/B,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC,QAAQ,CAAC,CACzE,CAAA;IACD,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC1E,OAAO;QACL,QAAQ,EAAE,YAAY;QACtB,MAAM;QACN,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE;KACrE,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -9,13 +9,15 @@ export type GetWithdrawableBalancesParams = ProviderGetWithdrawableBalancesParam
|
|
|
9
9
|
/**
|
|
10
10
|
* The `(asset, route)` pairs `params.address` can withdraw from Hyperliquid,
|
|
11
11
|
* read from the venue's own `withdrawable` and spot `total`/`hold` figures.
|
|
12
|
+
* Hyperliquid charges its flat withdrawal fee in USDC, so the backend's
|
|
13
|
+
* `withdrawalFeeUsd` is the fee in quote-asset units on every USDC row.
|
|
12
14
|
*
|
|
13
15
|
* Only the main perps dex is read: a withdrawal to L1 draws on that account,
|
|
14
16
|
* and a sub-dex balance reaches it through a transfer first.
|
|
15
17
|
*
|
|
16
|
-
* @throws {PerpsError} On Hyperliquid REST
|
|
17
|
-
* failures, and `SDKError` when the market registry
|
|
18
|
-
* market to name the quote asset.
|
|
18
|
+
* @throws {PerpsError} On Hyperliquid REST or backend `/providers` error,
|
|
19
|
+
* network, or parsing failures, and `SDKError` when the market registry
|
|
20
|
+
* carries no main perps market to name the quote asset.
|
|
19
21
|
* @public
|
|
20
22
|
*/
|
|
21
23
|
export declare const getWithdrawableBalances: ({ client, apiUrl }: HyperliquidContext, params: GetWithdrawableBalancesParams, options?: SDKRequestOptions) => Promise<ProviderWithdrawableBalance[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWithdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getWithdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,qCAAqC,EAC1C,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AASvD;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,GACvC,qCAAqC,CAAA;AAEvC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,GAClC,oBAAoB,kBAAkB,EACtC,QAAQ,6BAA6B,EACrC,UAAU,iBAAiB,KAC1B,OAAO,CAAC,2BAA2B,EAAE,CAgDvC,CAAA"}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import { getMarketRegistry, PerpsError, } from '@lifi/perps-sdk';
|
|
1
|
+
import { getMarketRegistry, getProviders, PerpsError, } from '@lifi/perps-sdk';
|
|
2
2
|
import { PerpsErrorCode } from '@lifi/perps-types';
|
|
3
|
+
import Big from 'big.js';
|
|
3
4
|
import { MAIN_MARKET_ID, PROVIDER_KEY } from '../constants.js';
|
|
4
5
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js';
|
|
5
6
|
import { hyperliquidWithdrawableBalances } from '../utils/withdrawableBalances.js';
|
|
6
7
|
/**
|
|
7
8
|
* The `(asset, route)` pairs `params.address` can withdraw from Hyperliquid,
|
|
8
9
|
* read from the venue's own `withdrawable` and spot `total`/`hold` figures.
|
|
10
|
+
* Hyperliquid charges its flat withdrawal fee in USDC, so the backend's
|
|
11
|
+
* `withdrawalFeeUsd` is the fee in quote-asset units on every USDC row.
|
|
9
12
|
*
|
|
10
13
|
* Only the main perps dex is read: a withdrawal to L1 draws on that account,
|
|
11
14
|
* and a sub-dex balance reaches it through a transfer first.
|
|
12
15
|
*
|
|
13
|
-
* @throws {PerpsError} On Hyperliquid REST
|
|
14
|
-
* failures, and `SDKError` when the market registry
|
|
15
|
-
* market to name the quote asset.
|
|
16
|
+
* @throws {PerpsError} On Hyperliquid REST or backend `/providers` error,
|
|
17
|
+
* network, or parsing failures, and `SDKError` when the market registry
|
|
18
|
+
* carries no main perps market to name the quote asset.
|
|
16
19
|
* @public
|
|
17
20
|
*/
|
|
18
21
|
export const getWithdrawableBalances = async ({ client, apiUrl }, params, options) => {
|
|
19
22
|
const registry = getMarketRegistry(client, PROVIDER_KEY);
|
|
20
23
|
const infoOpts = hlInfoOptions(client, options);
|
|
21
|
-
const [markets, abstraction, state, spotState] = await Promise.all([
|
|
24
|
+
const [{ providers }, markets, abstraction, state, spotState] = await Promise.all([
|
|
25
|
+
getProviders(client, options),
|
|
22
26
|
registry.sync(),
|
|
23
27
|
infoRequest(apiUrl, { type: 'userAbstraction', user: params.address }, infoOpts),
|
|
24
28
|
infoRequest(apiUrl, { type: 'clearinghouseState', user: params.address }, infoOpts),
|
|
@@ -30,6 +34,7 @@ export const getWithdrawableBalances = async ({ client, apiUrl }, params, option
|
|
|
30
34
|
error.tool = PROVIDER_KEY;
|
|
31
35
|
throw error;
|
|
32
36
|
}
|
|
33
|
-
|
|
37
|
+
const feeUsd = providers.find((provider) => provider.key === PROVIDER_KEY)?.withdrawalFeeUsd;
|
|
38
|
+
return hyperliquidWithdrawableBalances(abstraction, state, spotState, quoteAsset.id, feeUsd === undefined ? undefined : new Big(feeUsd).toFixed());
|
|
34
39
|
};
|
|
35
40
|
//# sourceMappingURL=getWithdrawableBalances.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWithdrawableBalances.js","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,UAAU,GAIX,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAO9D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAUlF
|
|
1
|
+
{"version":3,"file":"getWithdrawableBalances.js","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,UAAU,GAIX,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAO9D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAUlF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC1C,EA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AC5C,EAAE,gBAAgB,CAAA;IAEnB,OAAO,+BAA+B,CACpC,WAAW,EACX,KAAK,EACL,SAAS,EACT,UAAU,CAAC,EAAE,EACb,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAC7D,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OrderBase } from '@lifi/perps-types';
|
|
2
2
|
import { type HlExplorerTx } from '../types/explorer.js';
|
|
3
3
|
import { type InfoRequestOptions } from './infoClient.js';
|
|
4
4
|
/**
|
|
@@ -28,12 +28,4 @@ export declare const getClientOrderIds: (action: Record<string, unknown>) => str
|
|
|
28
28
|
* @public
|
|
29
29
|
*/
|
|
30
30
|
export declare const matchOrderActionHash: (txs: HlExplorerTx[], order: Pick<OrderBase, "clientOrderId">) => string | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Set `explorerLink` on each order whose placement transaction the explorer
|
|
33
|
-
* window still holds. One explorer read serves every order, and it is skipped
|
|
34
|
-
* when no order carries a client order id to match on. The link is
|
|
35
|
-
* supplementary, so an explorer failure warns and leaves the orders unlinked
|
|
36
|
-
* instead of failing the order read.
|
|
37
|
-
*/
|
|
38
|
-
export declare const withExplorerLinks: (orders: Order[], address: string, options: InfoRequestOptions) => Promise<Order[]>;
|
|
39
31
|
//# sourceMappingURL=explorer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGlD,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAKrE;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,EACf,UAAU,kBAAkB,KAC3B,OAAO,CAAC,YAAY,EAAE,CASxB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,MAAM,EAyBR,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,YAAY,EAAE,EACnB,OAAO,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,KACtC,MAAM,GAAG,SAaX,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { createWarnOnce, ExplorerChainId, explorerTxUrl, PerpsError, } from '@lifi/perps-sdk';
|
|
2
1
|
import { isHex } from 'viem';
|
|
3
|
-
import { HYPERLIQUID_EXPLORER_RPC_URL
|
|
2
|
+
import { HYPERLIQUID_EXPLORER_RPC_URL } from '../constants.js';
|
|
4
3
|
import { isHlExplorerTx } from '../types/explorer.js';
|
|
5
4
|
import { hlPostJson } from './infoClient.js';
|
|
6
5
|
const isRecord = (value) => typeof value === 'object' && value !== null;
|
|
@@ -66,34 +65,4 @@ export const matchOrderActionHash = (txs, order) => {
|
|
|
66
65
|
getClientOrderIds(tx.action).some((id) => id.toLowerCase() === wanted));
|
|
67
66
|
return match?.hash;
|
|
68
67
|
};
|
|
69
|
-
const warn = createWarnOnce();
|
|
70
|
-
/**
|
|
71
|
-
* Set `explorerLink` on each order whose placement transaction the explorer
|
|
72
|
-
* window still holds. One explorer read serves every order, and it is skipped
|
|
73
|
-
* when no order carries a client order id to match on. The link is
|
|
74
|
-
* supplementary, so an explorer failure warns and leaves the orders unlinked
|
|
75
|
-
* instead of failing the order read.
|
|
76
|
-
*/
|
|
77
|
-
export const withExplorerLinks = async (orders, address, options) => {
|
|
78
|
-
if (!orders.some((order) => order.clientOrderId !== undefined)) {
|
|
79
|
-
return orders;
|
|
80
|
-
}
|
|
81
|
-
let txs;
|
|
82
|
-
try {
|
|
83
|
-
txs = await fetchUserTransactions(address, options);
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
if (!(error instanceof PerpsError)) {
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
// The message stays out of the key: a transport failure names hosts and
|
|
90
|
-
// ports, so keying on it would let the dedupe set grow without bound.
|
|
91
|
-
warn('explorer link lookup failed', `[${PROVIDER_KEY}] explorer link lookup failed: ${error.message}`);
|
|
92
|
-
return orders;
|
|
93
|
-
}
|
|
94
|
-
return orders.map((order) => {
|
|
95
|
-
const explorerLink = explorerTxUrl(ExplorerChainId.HYPERLIQUID, matchOrderActionHash(txs, order));
|
|
96
|
-
return explorerLink === undefined ? order : { ...order, explorerLink };
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
68
|
//# sourceMappingURL=explorer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.js","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explorer.js","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAqB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,UAAU,EAA2B,MAAM,iBAAiB,CAAA;AAErE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAE7C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,OAAe,EACf,OAA4B,EACH,EAAE;IAC3B,MA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C;YACD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,GAAmB,EACnB,KAAuC,EACnB,EAAE;IACtB,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAA;IAC/B,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,kFAAkF;IAClF,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAA;IAC1C,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CACpB,CAAC,EAAE,EAAE,EAAE,CACL,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC;QACnB,iBAAiB,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CACzE,CAAA;IACD,OAAO,KAAK,EAAE,IAAI,CAAA;AACpB,CAAC,CAAA"}
|
|
@@ -8,7 +8,9 @@ import type { HlAbstractionMode, HlClearinghouseState, HlSpotClearinghouseState
|
|
|
8
8
|
* per-asset venue minimum.
|
|
9
9
|
*
|
|
10
10
|
* @param quoteAssetId - `Asset.id` the perps-route row is keyed by.
|
|
11
|
+
* @param withdrawalFee - Flat venue fee in quote-asset units, set on every
|
|
12
|
+
* quote-asset row. Absent leaves every row without a fee.
|
|
11
13
|
* @public
|
|
12
14
|
*/
|
|
13
|
-
export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string) => ProviderWithdrawableBalance[];
|
|
15
|
+
export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string, withdrawalFee?: string) => ProviderWithdrawableBalance[];
|
|
14
16
|
//# sourceMappingURL=withdrawableBalances.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;AAK1B
|
|
1
|
+
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;AAK1B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,+BAA+B,GAC1C,aAAa,iBAAiB,GAAG,IAAI,EACrC,OAAO,oBAAoB,EAC3B,WAAW,wBAAwB,EACnC,cAAc,MAAM,EACpB,gBAAgB,MAAM,KACrB,2BAA2B,EAsC7B,CAAA"}
|
|
@@ -9,10 +9,15 @@ import { toWireBig } from './decimal.js';
|
|
|
9
9
|
* per-asset venue minimum.
|
|
10
10
|
*
|
|
11
11
|
* @param quoteAssetId - `Asset.id` the perps-route row is keyed by.
|
|
12
|
+
* @param withdrawalFee - Flat venue fee in quote-asset units, set on every
|
|
13
|
+
* quote-asset row. Absent leaves every row without a fee.
|
|
12
14
|
* @public
|
|
13
15
|
*/
|
|
14
|
-
export const hyperliquidWithdrawableBalances = (abstraction, state, spotState, quoteAssetId) => {
|
|
16
|
+
export const hyperliquidWithdrawableBalances = (abstraction, state, spotState, quoteAssetId, withdrawalFee) => {
|
|
15
17
|
const rows = [];
|
|
18
|
+
const feeFor = (assetId) => withdrawalFee === undefined || assetId !== quoteAssetId
|
|
19
|
+
? {}
|
|
20
|
+
: { withdrawalFee };
|
|
16
21
|
if (isUnifiedAbstraction(abstraction)) {
|
|
17
22
|
for (const balance of spotState.balances) {
|
|
18
23
|
if (assetIsOutcome(balance.coin)) {
|
|
@@ -20,10 +25,12 @@ export const hyperliquidWithdrawableBalances = (abstraction, state, spotState, q
|
|
|
20
25
|
}
|
|
21
26
|
const spot = toWireBig(balance.total, 'spotBalance.total').minus(toWireBig(balance.hold, 'spotBalance.hold'));
|
|
22
27
|
if (spot.gt(0)) {
|
|
28
|
+
const assetId = String(balance.token);
|
|
23
29
|
rows.push({
|
|
24
|
-
assetId
|
|
30
|
+
assetId,
|
|
25
31
|
route: 'spot',
|
|
26
32
|
available: spot.toFixed(),
|
|
33
|
+
...feeFor(assetId),
|
|
27
34
|
});
|
|
28
35
|
}
|
|
29
36
|
}
|
|
@@ -34,6 +41,7 @@ export const hyperliquidWithdrawableBalances = (abstraction, state, spotState, q
|
|
|
34
41
|
assetId: quoteAssetId,
|
|
35
42
|
route: 'perps',
|
|
36
43
|
available: perps.toFixed(),
|
|
44
|
+
...feeFor(quoteAssetId),
|
|
37
45
|
});
|
|
38
46
|
}
|
|
39
47
|
return rows;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawableBalances.js","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC
|
|
1
|
+
{"version":3,"file":"withdrawableBalances.js","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,O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;YACR,OAAO,EAAE,YAAY;YACrB,KAAK,EAAE,OAAO;YACd,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;YAC1B,GAAG,MAAM,CAAC,YAAY,CAAC;SACxB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrder.d.ts","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"getOrder.d.ts","sourceRoot":"","sources":["../../../src/services/getOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAQvD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,sBAAsB,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GACnB,oBAAoB,kBAAkB,EACtC,QAAQ,cAAc,EACtB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,KAAK,CAkDf,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../../src/services/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAwB,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAE7E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAoBvD,kEAAkE;AAClE,MAAM,MAAM,eAAe,GAAG,uBAAuB,CAAA;AA4ErD,iFAAiF;AACjF,eAAO,MAAM,SAAS,GACpB,oBAAoB,kBAAkB,EACtC,QAAQ,eAAe,EACvB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,cAAc,CAoGxB,CAAA"}
|
|
@@ -9,13 +9,15 @@ export type GetWithdrawableBalancesParams = ProviderGetWithdrawableBalancesParam
|
|
|
9
9
|
/**
|
|
10
10
|
* The `(asset, route)` pairs `params.address` can withdraw from Hyperliquid,
|
|
11
11
|
* read from the venue's own `withdrawable` and spot `total`/`hold` figures.
|
|
12
|
+
* Hyperliquid charges its flat withdrawal fee in USDC, so the backend's
|
|
13
|
+
* `withdrawalFeeUsd` is the fee in quote-asset units on every USDC row.
|
|
12
14
|
*
|
|
13
15
|
* Only the main perps dex is read: a withdrawal to L1 draws on that account,
|
|
14
16
|
* and a sub-dex balance reaches it through a transfer first.
|
|
15
17
|
*
|
|
16
|
-
* @throws {PerpsError} On Hyperliquid REST
|
|
17
|
-
* failures, and `SDKError` when the market registry
|
|
18
|
-
* market to name the quote asset.
|
|
18
|
+
* @throws {PerpsError} On Hyperliquid REST or backend `/providers` error,
|
|
19
|
+
* network, or parsing failures, and `SDKError` when the market registry
|
|
20
|
+
* carries no main perps market to name the quote asset.
|
|
19
21
|
* @public
|
|
20
22
|
*/
|
|
21
23
|
export declare const getWithdrawableBalances: ({ client, apiUrl }: HyperliquidContext, params: GetWithdrawableBalancesParams, options?: SDKRequestOptions) => Promise<ProviderWithdrawableBalance[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWithdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getWithdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/services/getWithdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,qCAAqC,EAC1C,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AASvD;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,GACvC,qCAAqC,CAAA;AAEvC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,GAClC,oBAAoB,kBAAkB,EACtC,QAAQ,6BAA6B,EACrC,UAAU,iBAAiB,KAC1B,OAAO,CAAC,2BAA2B,EAAE,CAgDvC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OrderBase } from '@lifi/perps-types';
|
|
2
2
|
import { type HlExplorerTx } from '../types/explorer.js';
|
|
3
3
|
import { type InfoRequestOptions } from './infoClient.js';
|
|
4
4
|
/**
|
|
@@ -28,12 +28,4 @@ export declare const getClientOrderIds: (action: Record<string, unknown>) => str
|
|
|
28
28
|
* @public
|
|
29
29
|
*/
|
|
30
30
|
export declare const matchOrderActionHash: (txs: HlExplorerTx[], order: Pick<OrderBase, "clientOrderId">) => string | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Set `explorerLink` on each order whose placement transaction the explorer
|
|
33
|
-
* window still holds. One explorer read serves every order, and it is skipped
|
|
34
|
-
* when no order carries a client order id to match on. The link is
|
|
35
|
-
* supplementary, so an explorer failure warns and leaves the orders unlinked
|
|
36
|
-
* instead of failing the order read.
|
|
37
|
-
*/
|
|
38
|
-
export declare const withExplorerLinks: (orders: Order[], address: string, options: InfoRequestOptions) => Promise<Order[]>;
|
|
39
31
|
//# sourceMappingURL=explorer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGlD,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAKrE;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,EACf,UAAU,kBAAkB,KAC3B,OAAO,CAAC,YAAY,EAAE,CASxB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,MAAM,EAyBR,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,YAAY,EAAE,EACnB,OAAO,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,KACtC,MAAM,GAAG,SAaX,CAAA"}
|
|
@@ -8,7 +8,9 @@ import type { HlAbstractionMode, HlClearinghouseState, HlSpotClearinghouseState
|
|
|
8
8
|
* per-asset venue minimum.
|
|
9
9
|
*
|
|
10
10
|
* @param quoteAssetId - `Asset.id` the perps-route row is keyed by.
|
|
11
|
+
* @param withdrawalFee - Flat venue fee in quote-asset units, set on every
|
|
12
|
+
* quote-asset row. Absent leaves every row without a fee.
|
|
11
13
|
* @public
|
|
12
14
|
*/
|
|
13
|
-
export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string) => ProviderWithdrawableBalance[];
|
|
15
|
+
export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string, withdrawalFee?: string) => ProviderWithdrawableBalance[];
|
|
14
16
|
//# sourceMappingURL=withdrawableBalances.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;AAK1B
|
|
1
|
+
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,mBAAmB,CAAA;AAK1B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,+BAA+B,GAC1C,aAAa,iBAAiB,GAAG,IAAI,EACrC,OAAO,oBAAoB,EAC3B,WAAW,wBAAwB,EACnC,cAAc,MAAM,EACpB,gBAAgB,MAAM,KACrB,2BAA2B,EAsC7B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk-provider-hyperliquid",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-2138c36",
|
|
4
4
|
"description": "Hyperliquid provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@lifi/perps-types": "^15.0.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@lifi/perps-sdk": "^
|
|
55
|
+
"@lifi/perps-sdk": "^0.0.0-preview-2138c36"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
package/src/services/getOrder.ts
CHANGED
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
HlOrderStatusResponse,
|
|
13
13
|
HlTwapHistoryEntry,
|
|
14
14
|
} from '../types/index.js'
|
|
15
|
-
import { withExplorerLinks } from '../utils/explorer.js'
|
|
16
15
|
import { assetIsOutcome, mapOrder } from '../utils/index.js'
|
|
17
16
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
18
17
|
|
|
@@ -48,18 +47,17 @@ export const getOrder = async (
|
|
|
48
47
|
throw err
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
const infoOpts = hlInfoOptions(client, options)
|
|
52
50
|
const status = await infoRequest<HlOrderStatusResponse>(
|
|
53
51
|
apiUrl,
|
|
54
52
|
{ type: 'orderStatus', user: params.address, oid },
|
|
55
|
-
|
|
53
|
+
hlInfoOptions(client, options)
|
|
56
54
|
)
|
|
57
55
|
|
|
58
56
|
if (status.status !== 'order') {
|
|
59
57
|
const history = await infoRequest<HlTwapHistoryEntry[]>(
|
|
60
58
|
apiUrl,
|
|
61
59
|
{ type: 'twapHistory', user: params.address },
|
|
62
|
-
|
|
60
|
+
hlInfoOptions(client, options)
|
|
63
61
|
)
|
|
64
62
|
const twap = history.find(
|
|
65
63
|
(entry) =>
|
|
@@ -83,10 +81,5 @@ export const getOrder = async (
|
|
|
83
81
|
|
|
84
82
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
85
83
|
await registry.sync()
|
|
86
|
-
|
|
87
|
-
status.order,
|
|
88
|
-
registry.require(status.order.order.coin)
|
|
89
|
-
)
|
|
90
|
-
const [linked] = await withExplorerLinks([order], params.address, infoOpts)
|
|
91
|
-
return linked
|
|
84
|
+
return mapOrder(status.order, registry.require(status.order.order.coin))
|
|
92
85
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ACTIVE_ORDER_STATUSES,
|
|
3
3
|
createWarnOnce,
|
|
4
|
+
ExplorerChainId,
|
|
5
|
+
explorerTxUrl,
|
|
4
6
|
getMarketRegistry,
|
|
5
7
|
isActiveOrderStatus,
|
|
6
8
|
type MarketRegistry,
|
|
@@ -12,21 +14,34 @@ import type { MarketDisplay, Order, OrdersResponse } from '@lifi/perps-types'
|
|
|
12
14
|
import { PROVIDER_KEY } from '../constants.js'
|
|
13
15
|
import type { HyperliquidContext } from '../context.js'
|
|
14
16
|
import type {
|
|
17
|
+
HlExplorerTx,
|
|
15
18
|
HlFrontendOpenOrders,
|
|
16
19
|
HlHistoricalOrders,
|
|
17
20
|
HlTwapHistoryEntry,
|
|
18
21
|
} from '../types/index.js'
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
import {
|
|
23
|
+
assetIsOutcome,
|
|
24
|
+
fetchUserTransactions,
|
|
25
|
+
mapOrder,
|
|
26
|
+
matchOrderActionHash,
|
|
27
|
+
perpsDexNames,
|
|
28
|
+
} from '../utils/index.js'
|
|
29
|
+
import {
|
|
30
|
+
hlInfoOptions,
|
|
31
|
+
type InfoRequestOptions,
|
|
32
|
+
infoRequest,
|
|
33
|
+
} from '../utils/infoClient.js'
|
|
22
34
|
|
|
23
35
|
/** Parameters for a lifecycle-filtered Hyperliquid order read. */
|
|
24
36
|
export type GetOrdersParams = ProviderGetOrdersParams
|
|
25
37
|
|
|
26
38
|
const warn = createWarnOnce()
|
|
27
39
|
|
|
28
|
-
const warnOnce = (key: string): void => {
|
|
29
|
-
warn(
|
|
40
|
+
const warnOnce = (key: string, detail?: string): void => {
|
|
41
|
+
warn(
|
|
42
|
+
key,
|
|
43
|
+
`[${PROVIDER_KEY}] ${detail === undefined ? key : `${key}: ${detail}`}`
|
|
44
|
+
)
|
|
30
45
|
}
|
|
31
46
|
|
|
32
47
|
/**
|
|
@@ -58,6 +73,42 @@ const mapRow = (
|
|
|
58
73
|
}
|
|
59
74
|
}
|
|
60
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Set `explorerLink` on each row whose placement transaction the explorer
|
|
78
|
+
* window still holds. One explorer read serves the whole page, and it is
|
|
79
|
+
* skipped when no row carries a client order id to match on. The link is
|
|
80
|
+
* supplementary, so an explorer failure warns and leaves the rows unlinked
|
|
81
|
+
* instead of failing the order read.
|
|
82
|
+
*/
|
|
83
|
+
const withExplorerLinks = async (
|
|
84
|
+
orders: Order[],
|
|
85
|
+
address: string,
|
|
86
|
+
options: InfoRequestOptions
|
|
87
|
+
): Promise<Order[]> => {
|
|
88
|
+
if (!orders.some((order) => order.clientOrderId !== undefined)) {
|
|
89
|
+
return orders
|
|
90
|
+
}
|
|
91
|
+
let txs: HlExplorerTx[]
|
|
92
|
+
try {
|
|
93
|
+
txs = await fetchUserTransactions(address, options)
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (!(error instanceof PerpsError)) {
|
|
96
|
+
throw error
|
|
97
|
+
}
|
|
98
|
+
// The message stays out of the key: a transport failure names hosts and
|
|
99
|
+
// ports, so keying on it would let the dedupe set grow without bound.
|
|
100
|
+
warnOnce('explorer link lookup failed', error.message)
|
|
101
|
+
return orders
|
|
102
|
+
}
|
|
103
|
+
return orders.map((order) => {
|
|
104
|
+
const explorerLink = explorerTxUrl(
|
|
105
|
+
ExplorerChainId.HYPERLIQUID,
|
|
106
|
+
matchOrderActionHash(txs, order)
|
|
107
|
+
)
|
|
108
|
+
return explorerLink === undefined ? order : { ...order, explorerLink }
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
61
112
|
/** Read regular, trigger, and TWAP orders from the requested lifecycle feeds. */
|
|
62
113
|
export const getOrders = async (
|
|
63
114
|
{ client, apiUrl }: HyperliquidContext,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getMarketRegistry,
|
|
3
|
+
getProviders,
|
|
3
4
|
PerpsError,
|
|
4
5
|
type ProviderGetWithdrawableBalancesParams,
|
|
5
6
|
type ProviderWithdrawableBalance,
|
|
6
7
|
type SDKRequestOptions,
|
|
7
8
|
} from '@lifi/perps-sdk'
|
|
8
9
|
import { PerpsErrorCode } from '@lifi/perps-types'
|
|
10
|
+
import Big from 'big.js'
|
|
9
11
|
import { MAIN_MARKET_ID, PROVIDER_KEY } from '../constants.js'
|
|
10
12
|
import type { HyperliquidContext } from '../context.js'
|
|
11
13
|
import type {
|
|
@@ -27,13 +29,15 @@ export type GetWithdrawableBalancesParams =
|
|
|
27
29
|
/**
|
|
28
30
|
* The `(asset, route)` pairs `params.address` can withdraw from Hyperliquid,
|
|
29
31
|
* read from the venue's own `withdrawable` and spot `total`/`hold` figures.
|
|
32
|
+
* Hyperliquid charges its flat withdrawal fee in USDC, so the backend's
|
|
33
|
+
* `withdrawalFeeUsd` is the fee in quote-asset units on every USDC row.
|
|
30
34
|
*
|
|
31
35
|
* Only the main perps dex is read: a withdrawal to L1 draws on that account,
|
|
32
36
|
* and a sub-dex balance reaches it through a transfer first.
|
|
33
37
|
*
|
|
34
|
-
* @throws {PerpsError} On Hyperliquid REST
|
|
35
|
-
* failures, and `SDKError` when the market registry
|
|
36
|
-
* market to name the quote asset.
|
|
38
|
+
* @throws {PerpsError} On Hyperliquid REST or backend `/providers` error,
|
|
39
|
+
* network, or parsing failures, and `SDKError` when the market registry
|
|
40
|
+
* carries no main perps market to name the quote asset.
|
|
37
41
|
* @public
|
|
38
42
|
*/
|
|
39
43
|
export const getWithdrawableBalances = async (
|
|
@@ -44,24 +48,26 @@ export const getWithdrawableBalances = async (
|
|
|
44
48
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
45
49
|
const infoOpts = hlInfoOptions(client, options)
|
|
46
50
|
|
|
47
|
-
const [markets, abstraction, state, spotState] =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
const [{ providers }, markets, abstraction, state, spotState] =
|
|
52
|
+
await Promise.all([
|
|
53
|
+
getProviders(client, options),
|
|
54
|
+
registry.sync(),
|
|
55
|
+
infoRequest<HlAbstractionMode | null>(
|
|
56
|
+
apiUrl,
|
|
57
|
+
{ type: 'userAbstraction', user: params.address },
|
|
58
|
+
infoOpts
|
|
59
|
+
),
|
|
60
|
+
infoRequest<HlClearinghouseState>(
|
|
61
|
+
apiUrl,
|
|
62
|
+
{ type: 'clearinghouseState', user: params.address },
|
|
63
|
+
infoOpts
|
|
64
|
+
),
|
|
65
|
+
infoRequest<HlSpotClearinghouseState>(
|
|
66
|
+
apiUrl,
|
|
67
|
+
{ type: 'spotClearinghouseState', user: params.address },
|
|
68
|
+
infoOpts
|
|
69
|
+
),
|
|
70
|
+
])
|
|
65
71
|
|
|
66
72
|
const quoteAsset = markets.find(
|
|
67
73
|
(market) => market.categoryId === MAIN_MARKET_ID
|
|
@@ -75,10 +81,15 @@ export const getWithdrawableBalances = async (
|
|
|
75
81
|
throw error
|
|
76
82
|
}
|
|
77
83
|
|
|
84
|
+
const feeUsd = providers.find(
|
|
85
|
+
(provider) => provider.key === PROVIDER_KEY
|
|
86
|
+
)?.withdrawalFeeUsd
|
|
87
|
+
|
|
78
88
|
return hyperliquidWithdrawableBalances(
|
|
79
89
|
abstraction,
|
|
80
90
|
state,
|
|
81
91
|
spotState,
|
|
82
|
-
quoteAsset.id
|
|
92
|
+
quoteAsset.id,
|
|
93
|
+
feeUsd === undefined ? undefined : new Big(feeUsd).toFixed()
|
|
83
94
|
)
|
|
84
95
|
}
|
package/src/utils/explorer.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createWarnOnce,
|
|
3
|
-
ExplorerChainId,
|
|
4
|
-
explorerTxUrl,
|
|
5
|
-
PerpsError,
|
|
6
|
-
} from '@lifi/perps-sdk'
|
|
7
|
-
import type { Order, OrderBase } from '@lifi/perps-types'
|
|
1
|
+
import type { OrderBase } from '@lifi/perps-types'
|
|
8
2
|
import { isHex } from 'viem'
|
|
9
|
-
import { HYPERLIQUID_EXPLORER_RPC_URL
|
|
3
|
+
import { HYPERLIQUID_EXPLORER_RPC_URL } from '../constants.js'
|
|
10
4
|
import { type HlExplorerTx, isHlExplorerTx } from '../types/explorer.js'
|
|
11
5
|
import { hlPostJson, type InfoRequestOptions } from './infoClient.js'
|
|
12
6
|
|
|
@@ -97,44 +91,3 @@ export const matchOrderActionHash = (
|
|
|
97
91
|
)
|
|
98
92
|
return match?.hash
|
|
99
93
|
}
|
|
100
|
-
|
|
101
|
-
const warn = createWarnOnce()
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Set `explorerLink` on each order whose placement transaction the explorer
|
|
105
|
-
* window still holds. One explorer read serves every order, and it is skipped
|
|
106
|
-
* when no order carries a client order id to match on. The link is
|
|
107
|
-
* supplementary, so an explorer failure warns and leaves the orders unlinked
|
|
108
|
-
* instead of failing the order read.
|
|
109
|
-
*/
|
|
110
|
-
export const withExplorerLinks = async (
|
|
111
|
-
orders: Order[],
|
|
112
|
-
address: string,
|
|
113
|
-
options: InfoRequestOptions
|
|
114
|
-
): Promise<Order[]> => {
|
|
115
|
-
if (!orders.some((order) => order.clientOrderId !== undefined)) {
|
|
116
|
-
return orders
|
|
117
|
-
}
|
|
118
|
-
let txs: HlExplorerTx[]
|
|
119
|
-
try {
|
|
120
|
-
txs = await fetchUserTransactions(address, options)
|
|
121
|
-
} catch (error) {
|
|
122
|
-
if (!(error instanceof PerpsError)) {
|
|
123
|
-
throw error
|
|
124
|
-
}
|
|
125
|
-
// The message stays out of the key: a transport failure names hosts and
|
|
126
|
-
// ports, so keying on it would let the dedupe set grow without bound.
|
|
127
|
-
warn(
|
|
128
|
-
'explorer link lookup failed',
|
|
129
|
-
`[${PROVIDER_KEY}] explorer link lookup failed: ${error.message}`
|
|
130
|
-
)
|
|
131
|
-
return orders
|
|
132
|
-
}
|
|
133
|
-
return orders.map((order) => {
|
|
134
|
-
const explorerLink = explorerTxUrl(
|
|
135
|
-
ExplorerChainId.HYPERLIQUID,
|
|
136
|
-
matchOrderActionHash(txs, order)
|
|
137
|
-
)
|
|
138
|
-
return explorerLink === undefined ? order : { ...order, explorerLink }
|
|
139
|
-
})
|
|
140
|
-
}
|
|
@@ -16,15 +16,22 @@ import { toWireBig } from './decimal.js'
|
|
|
16
16
|
* per-asset venue minimum.
|
|
17
17
|
*
|
|
18
18
|
* @param quoteAssetId - `Asset.id` the perps-route row is keyed by.
|
|
19
|
+
* @param withdrawalFee - Flat venue fee in quote-asset units, set on every
|
|
20
|
+
* quote-asset row. Absent leaves every row without a fee.
|
|
19
21
|
* @public
|
|
20
22
|
*/
|
|
21
23
|
export const hyperliquidWithdrawableBalances = (
|
|
22
24
|
abstraction: HlAbstractionMode | null,
|
|
23
25
|
state: HlClearinghouseState,
|
|
24
26
|
spotState: HlSpotClearinghouseState,
|
|
25
|
-
quoteAssetId: string
|
|
27
|
+
quoteAssetId: string,
|
|
28
|
+
withdrawalFee?: string
|
|
26
29
|
): ProviderWithdrawableBalance[] => {
|
|
27
30
|
const rows: ProviderWithdrawableBalance[] = []
|
|
31
|
+
const feeFor = (assetId: string) =>
|
|
32
|
+
withdrawalFee === undefined || assetId !== quoteAssetId
|
|
33
|
+
? {}
|
|
34
|
+
: { withdrawalFee }
|
|
28
35
|
|
|
29
36
|
if (isUnifiedAbstraction(abstraction)) {
|
|
30
37
|
for (const balance of spotState.balances) {
|
|
@@ -35,10 +42,12 @@ export const hyperliquidWithdrawableBalances = (
|
|
|
35
42
|
toWireBig(balance.hold, 'spotBalance.hold')
|
|
36
43
|
)
|
|
37
44
|
if (spot.gt(0)) {
|
|
45
|
+
const assetId = String(balance.token)
|
|
38
46
|
rows.push({
|
|
39
|
-
assetId
|
|
47
|
+
assetId,
|
|
40
48
|
route: 'spot',
|
|
41
49
|
available: spot.toFixed(),
|
|
50
|
+
...feeFor(assetId),
|
|
42
51
|
})
|
|
43
52
|
}
|
|
44
53
|
}
|
|
@@ -50,6 +59,7 @@ export const hyperliquidWithdrawableBalances = (
|
|
|
50
59
|
assetId: quoteAssetId,
|
|
51
60
|
route: 'perps',
|
|
52
61
|
available: perps.toFixed(),
|
|
62
|
+
...feeFor(quoteAssetId),
|
|
53
63
|
})
|
|
54
64
|
}
|
|
55
65
|
|