@yuants/vendor-hyperliquid 0.6.4 → 0.7.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.
Files changed (109) hide show
  1. package/dist/api/private-api.js +1 -1
  2. package/dist/api/private-api.js.map +1 -1
  3. package/dist/api/sign.js.map +1 -0
  4. package/dist/api/types.js +4 -8
  5. package/dist/api/types.js.map +1 -1
  6. package/dist/index.js +1 -7
  7. package/dist/index.js.map +1 -1
  8. package/dist/services/accounts/perp.js +4 -16
  9. package/dist/services/accounts/perp.js.map +1 -1
  10. package/dist/services/accounts/spot.js +4 -5
  11. package/dist/services/accounts/spot.js.map +1 -1
  12. package/dist/services/exchange.js +79 -0
  13. package/dist/services/exchange.js.map +1 -0
  14. package/dist/services/markets/interest-rate.js +13 -7
  15. package/dist/services/markets/interest-rate.js.map +1 -1
  16. package/dist/services/markets/ohlc.js +11 -7
  17. package/dist/services/markets/ohlc.js.map +1 -1
  18. package/dist/services/markets/product.js +6 -6
  19. package/dist/services/markets/product.js.map +1 -1
  20. package/dist/services/markets/quote.js +4 -4
  21. package/dist/services/markets/quote.js.map +1 -1
  22. package/dist/services/orders/cancelOrder.js +1 -1
  23. package/dist/services/orders/cancelOrder.js.map +1 -1
  24. package/dist/services/orders/listOrders.js +17 -38
  25. package/dist/services/orders/listOrders.js.map +1 -1
  26. package/dist/services/orders/modifyOrder.js +2 -2
  27. package/dist/services/orders/modifyOrder.js.map +1 -1
  28. package/dist/services/orders/submitOrder.js +1 -1
  29. package/dist/services/orders/submitOrder.js.map +1 -1
  30. package/dist/{utils.js → services/utils.js} +13 -6
  31. package/dist/services/utils.js.map +1 -0
  32. package/lib/api/private-api.js +1 -1
  33. package/lib/api/private-api.js.map +1 -1
  34. package/lib/api/sign.d.ts.map +1 -0
  35. package/lib/api/sign.js.map +1 -0
  36. package/lib/api/types.d.ts +3 -4
  37. package/lib/api/types.d.ts.map +1 -1
  38. package/lib/api/types.js +6 -10
  39. package/lib/api/types.js.map +1 -1
  40. package/lib/index.d.ts +1 -6
  41. package/lib/index.d.ts.map +1 -1
  42. package/lib/index.js +1 -7
  43. package/lib/index.js.map +1 -1
  44. package/lib/services/accounts/perp.d.ts +1 -1
  45. package/lib/services/accounts/perp.d.ts.map +1 -1
  46. package/lib/services/accounts/perp.js +6 -18
  47. package/lib/services/accounts/perp.js.map +1 -1
  48. package/lib/services/accounts/spot.d.ts +1 -1
  49. package/lib/services/accounts/spot.d.ts.map +1 -1
  50. package/lib/services/accounts/spot.js +6 -7
  51. package/lib/services/accounts/spot.js.map +1 -1
  52. package/lib/services/exchange.d.ts +2 -0
  53. package/lib/services/exchange.d.ts.map +1 -0
  54. package/lib/services/exchange.js +81 -0
  55. package/lib/services/exchange.js.map +1 -0
  56. package/lib/services/markets/interest-rate.js +13 -7
  57. package/lib/services/markets/interest-rate.js.map +1 -1
  58. package/lib/services/markets/ohlc.js +10 -6
  59. package/lib/services/markets/ohlc.js.map +1 -1
  60. package/lib/services/markets/product.d.ts +2 -1
  61. package/lib/services/markets/product.d.ts.map +1 -1
  62. package/lib/services/markets/product.js +8 -6
  63. package/lib/services/markets/product.js.map +1 -1
  64. package/lib/services/markets/quote.js +4 -4
  65. package/lib/services/markets/quote.js.map +1 -1
  66. package/lib/services/orders/cancelOrder.js +1 -1
  67. package/lib/services/orders/cancelOrder.js.map +1 -1
  68. package/lib/services/orders/listOrders.d.ts +7 -3
  69. package/lib/services/orders/listOrders.d.ts.map +1 -1
  70. package/lib/services/orders/listOrders.js +21 -41
  71. package/lib/services/orders/listOrders.js.map +1 -1
  72. package/lib/services/orders/modifyOrder.d.ts.map +1 -1
  73. package/lib/services/orders/modifyOrder.js +7 -7
  74. package/lib/services/orders/modifyOrder.js.map +1 -1
  75. package/lib/services/orders/submitOrder.js +1 -1
  76. package/lib/services/orders/submitOrder.js.map +1 -1
  77. package/lib/{utils.d.ts → services/utils.d.ts} +4 -0
  78. package/lib/services/utils.d.ts.map +1 -0
  79. package/lib/{utils.js → services/utils.js} +15 -7
  80. package/lib/services/utils.js.map +1 -0
  81. package/package.json +15 -15
  82. package/temp/package-deps.json +37 -38
  83. package/dist/services/account-actions-with-credential.js +0 -36
  84. package/dist/services/account-actions-with-credential.js.map +0 -1
  85. package/dist/services/legacy.js +0 -51
  86. package/dist/services/legacy.js.map +0 -1
  87. package/dist/services/order-actions-with-credential.js +0 -20
  88. package/dist/services/order-actions-with-credential.js.map +0 -1
  89. package/dist/sign.js.map +0 -1
  90. package/dist/utils.js.map +0 -1
  91. package/lib/services/account-actions-with-credential.d.ts +0 -2
  92. package/lib/services/account-actions-with-credential.d.ts.map +0 -1
  93. package/lib/services/account-actions-with-credential.js +0 -38
  94. package/lib/services/account-actions-with-credential.js.map +0 -1
  95. package/lib/services/legacy.d.ts +0 -2
  96. package/lib/services/legacy.d.ts.map +0 -1
  97. package/lib/services/legacy.js +0 -53
  98. package/lib/services/legacy.js.map +0 -1
  99. package/lib/services/order-actions-with-credential.d.ts +0 -2
  100. package/lib/services/order-actions-with-credential.d.ts.map +0 -1
  101. package/lib/services/order-actions-with-credential.js +0 -22
  102. package/lib/services/order-actions-with-credential.js.map +0 -1
  103. package/lib/sign.d.ts.map +0 -1
  104. package/lib/sign.js.map +0 -1
  105. package/lib/utils.d.ts.map +0 -1
  106. package/lib/utils.js.map +0 -1
  107. /package/dist/{sign.js → api/sign.js} +0 -0
  108. /package/lib/{sign.d.ts → api/sign.d.ts} +0 -0
  109. /package/lib/{sign.js → api/sign.js} +0 -0
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const data_account_1 = require("@yuants/data-account");
4
- const protocol_1 = require("@yuants/protocol");
5
- const utils_1 = require("@yuants/utils");
6
- const types_1 = require("../api/types");
7
- const perp_1 = require("./accounts/perp");
8
- const spot_1 = require("./accounts/spot");
9
- (0, data_account_1.provideAccountActionsWithCredential)(protocol_1.Terminal.fromNodeEnv(), 'HYPERLIQUID', {
10
- type: 'object',
11
- required: ['private_key'],
12
- properties: {
13
- private_key: { type: 'string' },
14
- },
15
- }, {
16
- listAccounts: async (credential) => {
17
- console.info(`[${(0, utils_1.formatTime)(Date.now())}] Listing accounts for ${(0, types_1.getAddressFromCredential)(credential)}`);
18
- return [
19
- {
20
- account_id: `hyperliquid/${(0, types_1.getAddressFromCredential)(credential)}/perp`,
21
- },
22
- {
23
- account_id: `hyperliquid/${(0, types_1.getAddressFromCredential)(credential)}/spot`,
24
- },
25
- ];
26
- },
27
- getAccountInfo: async (credential, account_id) => {
28
- console.info(`[${(0, utils_1.formatTime)(Date.now())}] Getting account info for ${account_id}`);
29
- if (account_id.endsWith('/perp')) {
30
- return (0, perp_1.getPerpAccountInfo)(credential, account_id);
31
- }
32
- if (account_id.endsWith('/spot')) {
33
- return (0, spot_1.getSpotAccountInfo)(credential, account_id);
34
- }
35
- throw new Error(`Unsupported account type for account_id: ${account_id}`);
36
- },
37
- });
38
- //# sourceMappingURL=account-actions-with-credential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../../src/services/account-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,uDAA2E;AAC3E,+CAA4C;AAC5C,yCAA2C;AAC3C,wCAAqE;AAErE,0CAAqD;AACrD,0CAAqD;AAErD,IAAA,kDAAmC,EACjC,mBAAQ,CAAC,WAAW,EAAE,EACtB,aAAa,EACb;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,aAAa,CAAC;IACzB,UAAU,EAAE;QACV,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAChC;CACF,EACD;IACE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;QACjC,OAAO,CAAC,IAAI,CACV,IAAI,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,0BAA0B,IAAA,gCAAwB,EAAC,UAAU,CAAC,EAAE,CAC3F,CAAC;QACF,OAAO;YACL;gBACE,UAAU,EAAE,eAAe,IAAA,gCAAwB,EAAC,UAAU,CAAC,OAAO;aACvE;YACD;gBACE,UAAU,EAAE,eAAe,IAAA,gCAAwB,EAAC,UAAU,CAAC,OAAO;aACvE;SACF,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QAC/C,OAAO,CAAC,IAAI,CAAC,IAAI,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,8BAA8B,UAAU,EAAE,CAAC,CAAC;QAEnF,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACnD;QACD,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACnD;QACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,UAAU,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF,CACF,CAAC","sourcesContent":["import { provideAccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { formatTime } from '@yuants/utils';\nimport { ICredential, getAddressFromCredential } from '../api/types';\n\nimport { getPerpAccountInfo } from './accounts/perp';\nimport { getSpotAccountInfo } from './accounts/spot';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'HYPERLIQUID',\n {\n type: 'object',\n required: ['private_key'],\n properties: {\n private_key: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n console.info(\n `[${formatTime(Date.now())}] Listing accounts for ${getAddressFromCredential(credential)}`,\n );\n return [\n {\n account_id: `hyperliquid/${getAddressFromCredential(credential)}/perp`,\n },\n {\n account_id: `hyperliquid/${getAddressFromCredential(credential)}/spot`,\n },\n ];\n },\n getAccountInfo: async (credential, account_id) => {\n console.info(`[${formatTime(Date.now())}] Getting account info for ${account_id}`);\n\n if (account_id.endsWith('/perp')) {\n return getPerpAccountInfo(credential, account_id);\n }\n if (account_id.endsWith('/spot')) {\n return getSpotAccountInfo(credential, account_id);\n }\n throw new Error(`Unsupported account type for account_id: ${account_id}`);\n },\n },\n);\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=legacy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../src/services/legacy.ts"],"names":[],"mappings":""}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const data_account_1 = require("@yuants/data-account");
4
- const data_order_1 = require("@yuants/data-order");
5
- const protocol_1 = require("@yuants/protocol");
6
- const types_1 = require("../api/types");
7
- const perp_1 = require("./accounts/perp");
8
- const spot_1 = require("./accounts/spot");
9
- const cancelOrder_1 = require("./orders/cancelOrder");
10
- const listOrders_1 = require("./orders/listOrders");
11
- const submitOrder_1 = require("./orders/submitOrder");
12
- const terminal = protocol_1.Terminal.fromNodeEnv();
13
- const credential = (0, types_1.getDefaultCredential)();
14
- const walletAddress = (0, types_1.getAddressFromCredential)(credential).toLowerCase();
15
- const defaultPerpAccountId = `hyperliquid/${walletAddress}/perp`;
16
- const defaultSpotAccountId = `hyperliquid/${walletAddress}/spot`;
17
- (0, data_account_1.addAccountMarket)(terminal, { account_id: defaultPerpAccountId, market_id: 'HYPERLIQUID/PERP' });
18
- (0, data_account_1.addAccountMarket)(terminal, { account_id: defaultSpotAccountId, market_id: 'HYPERLIQUID/SPOT' });
19
- (0, data_account_1.provideAccountInfoService)(terminal, defaultPerpAccountId, async () => {
20
- const info = await (0, perp_1.getPerpAccountInfo)(credential, defaultPerpAccountId);
21
- return info;
22
- }, { auto_refresh_interval: 1000 });
23
- (0, data_order_1.providePendingOrdersService)(terminal, defaultPerpAccountId, async () => (0, listOrders_1.listOrders)(credential, defaultPerpAccountId), { auto_refresh_interval: 2000 });
24
- (0, data_account_1.provideAccountInfoService)(terminal, defaultSpotAccountId, async () => (0, spot_1.getSpotAccountInfo)(credential, defaultSpotAccountId), { auto_refresh_interval: 5000 });
25
- terminal.server.provideService('SubmitOrder', {
26
- required: ['account_id', 'product_id', 'order_type', 'order_direction', 'volume'],
27
- properties: {
28
- account_id: { const: defaultPerpAccountId },
29
- },
30
- }, async (msg) => {
31
- return {
32
- res: {
33
- code: 0,
34
- message: 'OK',
35
- data: await (0, submitOrder_1.submitOrder)(credential, msg.req),
36
- },
37
- };
38
- });
39
- terminal.server.provideService('CancelOrder', {
40
- required: ['account_id', 'order_id', 'product_id'],
41
- properties: {
42
- account_id: { const: defaultPerpAccountId },
43
- },
44
- }, async (msg) => {
45
- await (0, cancelOrder_1.cancelOrderAction)(credential, msg.req);
46
- return {
47
- res: {
48
- code: 0,
49
- message: 'OK',
50
- },
51
- };
52
- });
53
- //# sourceMappingURL=legacy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../src/services/legacy.ts"],"names":[],"mappings":";;AAAA,uDAAmF;AACnF,mDAAyE;AACzE,+CAA4C;AAC5C,wCAA8E;AAC9E,0CAAqD;AACrD,0CAAqD;AACrD,sDAAyD;AACzD,oDAAiD;AACjD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,IAAA,4BAAoB,GAAE,CAAC;AAC1C,MAAM,aAAa,GAAG,IAAA,gCAAwB,EAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;AACzE,MAAM,oBAAoB,GAAG,eAAe,aAAa,OAAO,CAAC;AACjE,MAAM,oBAAoB,GAAG,eAAe,aAAa,OAAO,CAAC;AAEjE,IAAA,+BAAgB,EAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,oBAAoB,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAChG,IAAA,+BAAgB,EAAC,QAAQ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IAClD,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE;KAC5C;CACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;IACZ,MAAM,IAAA,+BAAiB,EAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,CAAC;YACP,OAAO,EAAE,IAAI;SACd;KACF,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { getAddressFromCredential, getDefaultCredential } from '../api/types';\nimport { getPerpAccountInfo } from './accounts/perp';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { cancelOrderAction } from './orders/cancelOrder';\nimport { listOrders } from './orders/listOrders';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\nconst walletAddress = getAddressFromCredential(credential).toLowerCase();\nconst defaultPerpAccountId = `hyperliquid/${walletAddress}/perp`;\nconst defaultSpotAccountId = `hyperliquid/${walletAddress}/spot`;\n\naddAccountMarket(terminal, { account_id: defaultPerpAccountId, market_id: 'HYPERLIQUID/PERP' });\naddAccountMarket(terminal, { account_id: defaultSpotAccountId, market_id: 'HYPERLIQUID/SPOT' });\n\nprovideAccountInfoService(\n terminal,\n defaultPerpAccountId,\n async () => {\n const info = await getPerpAccountInfo(credential, defaultPerpAccountId);\n return info;\n },\n { auto_refresh_interval: 1000 },\n);\n\nprovidePendingOrdersService(\n terminal,\n defaultPerpAccountId,\n async () => listOrders(credential, defaultPerpAccountId),\n { auto_refresh_interval: 2000 },\n);\n\nprovideAccountInfoService(\n terminal,\n defaultSpotAccountId,\n async () => getSpotAccountInfo(credential, defaultSpotAccountId),\n { auto_refresh_interval: 5000 },\n);\n\nterminal.server.provideService<IOrder, { order_id?: string }>(\n 'SubmitOrder',\n {\n required: ['account_id', 'product_id', 'order_type', 'order_direction', 'volume'],\n properties: {\n account_id: { const: defaultPerpAccountId },\n },\n },\n async (msg) => {\n return {\n res: {\n code: 0,\n message: 'OK',\n data: await submitOrder(credential, msg.req),\n },\n };\n },\n);\n\nterminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { const: defaultPerpAccountId },\n },\n },\n async (msg) => {\n await cancelOrderAction(credential, msg.req);\n return {\n res: {\n code: 0,\n message: 'OK',\n },\n };\n },\n);\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=order-actions-with-credential.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"order-actions-with-credential.d.ts","sourceRoot":"","sources":["../../src/services/order-actions-with-credential.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const data_order_1 = require("@yuants/data-order");
4
- const protocol_1 = require("@yuants/protocol");
5
- const cancelOrder_1 = require("./orders/cancelOrder");
6
- const listOrders_1 = require("./orders/listOrders");
7
- const modifyOrder_1 = require("./orders/modifyOrder");
8
- const submitOrder_1 = require("./orders/submitOrder");
9
- const terminal = protocol_1.Terminal.fromNodeEnv();
10
- (0, data_order_1.provideOrderActionsWithCredential)(terminal, 'HYPERLIQUID', {
11
- type: 'object',
12
- required: ['private_key'],
13
- properties: {
14
- private_key: { type: 'string' },
15
- },
16
- }, {
17
- submitOrder: submitOrder_1.submitOrder,
18
- cancelOrder: cancelOrder_1.cancelOrderAction,
19
- modifyOrder: modifyOrder_1.modifyOrder,
20
- listOrders: listOrders_1.listOrders,
21
- });
22
- //# sourceMappingURL=order-actions-with-credential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"order-actions-with-credential.js","sourceRoot":"","sources":["../../src/services/order-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,mDAAuE;AACvE,+CAA4C;AAE5C,sDAAyD;AACzD,oDAAiD;AACjD,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,8CAAiC,EAC/B,QAAQ,EACR,aAAa,EACb;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,aAAa,CAAC;IACzB,UAAU,EAAE;QACV,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAChC;CACF,EACD;IACE,WAAW,EAAE,yBAAW;IACxB,WAAW,EAAE,+BAAiB;IAC9B,WAAW,EAAE,yBAAW;IACxB,UAAU,EAAE,uBAAU;CACvB,CACF,CAAC","sourcesContent":["import { provideOrderActionsWithCredential } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from '../api/types';\nimport { cancelOrderAction } from './orders/cancelOrder';\nimport { listOrders } from './orders/listOrders';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideOrderActionsWithCredential<ICredential>(\n terminal,\n 'HYPERLIQUID',\n {\n type: 'object',\n required: ['private_key'],\n properties: {\n private_key: { type: 'string' },\n },\n },\n {\n submitOrder: submitOrder,\n cancelOrder: cancelOrderAction,\n modifyOrder: modifyOrder,\n listOrders: listOrders,\n },\n);\n"]}
package/lib/sign.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3C,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,SAAS;IACjB,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,iBAAiB,EAAE,MAAM,C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,YAA2B,EAC3B,SAAkB;IAElB,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,qBAAqB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACrC,OAAO,MAAM,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC;AAZD,oCAYC","sourcesContent":["import { encode } from '@msgpack/msgpack';\nimport { keccak256, Wallet } from 'ethers';\n\ninterface PhantomAgent {\n source: string;\n connectionId: string;\n}\n\ninterface L1Payload {\n domain: {\n chainId: number;\n name: string;\n verifyingContract: string;\n version: string;\n };\n types: {\n Agent: Array<{ name: string; type: string }>;\n EIP712Domain: Array<{ name: string; type: string }>;\n };\n primaryType: string;\n message: PhantomAgent;\n}\n\ninterface Signature {\n r: string;\n s: string;\n v: number;\n}\n\nfunction addressToBytes(address: string): Uint8Array {\n const cleanAddress = address.startsWith('0x') ? address.slice(2) : address;\n return new Uint8Array(Buffer.from(cleanAddress, 'hex'));\n}\n\nfunction actionHash(\n action: any,\n vaultAddress: string | null,\n nonce: number,\n expiresAfter: number | null,\n): string {\n let data: any = new Uint8Array(encode(action));\n\n const nonceBytes = new Uint8Array(8);\n const nonceView = new DataView(nonceBytes.buffer);\n nonceView.setBigUint64(0, BigInt(nonce), false); // false = big endian\n data = concatUint8Arrays(data, nonceBytes);\n\n if (vaultAddress == null) {\n data = concatUint8Arrays(data, new Uint8Array([0x00]));\n } else {\n data = concatUint8Arrays(data, new Uint8Array([0x01]));\n data = concatUint8Arrays(data, addressToBytes(vaultAddress));\n }\n if (expiresAfter != null) {\n data = concatUint8Arrays(data, new Uint8Array([0x00]));\n const expiresBytes = new Uint8Array(8);\n const expiresView = new DataView(expiresBytes.buffer);\n expiresView.setBigUint64(0, BigInt(expiresAfter), false); // false = big endian\n data = concatUint8Arrays(data, expiresBytes);\n }\n\n return keccak256(data);\n}\n\nfunction concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n\n return result;\n}\n\nfunction constructPhantomAgent(hash: string, isMainnet: boolean): PhantomAgent {\n return {\n source: isMainnet ? 'a' : 'b',\n connectionId: hash,\n };\n}\n\nfunction l1Payload(phantomAgent: PhantomAgent): L1Payload {\n return {\n domain: {\n chainId: 1337,\n name: 'Exchange',\n verifyingContract: '0x0000000000000000000000000000000000000000',\n version: '1',\n },\n types: {\n Agent: [\n { name: 'source', type: 'string' },\n { name: 'connectionId', type: 'bytes32' },\n ],\n EIP712Domain: [\n { name: 'name', type: 'string' },\n { name: 'version', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n { name: 'verifyingContract', type: 'address' },\n ],\n },\n primaryType: 'Agent',\n message: phantomAgent,\n };\n}\n\nasync function signInner(wallet: Wallet, data: L1Payload): Promise<Signature> {\n const signature = await wallet.signTypedData(data.domain, { Agent: data.types.Agent }, data.message);\n\n const r = signature.slice(0, 66);\n const s = '0x' + signature.slice(66, 130);\n const v = parseInt(signature.slice(130, 132), 16);\n\n return { r, s, v };\n}\n\n/**\n * 签署 L1 动作\n *\n * @param wallet - 以太坊钱包实例\n * @param action - 要签署的动作数据\n * @param activePool - 活跃池地址(可以为 null)\n * @param nonce - 随机数\n * @param expiresAfter - 过期时间(可以为 null)\n * @param isMainnet - 是否为主网\n * @returns 签名对象\n */\nexport async function signL1Action(\n wallet: Wallet,\n action: any,\n activePool: string | null,\n nonce: number,\n expiresAfter: number | null,\n isMainnet: boolean,\n): Promise<Signature> {\n const hash = actionHash(action, activePool, nonce, expiresAfter);\n const phantomAgent = constructPhantomAgent(hash, isMainnet);\n const data = l1Payload(phantomAgent);\n return await signInner(wallet, data);\n}\n\nexport { actionHash, addressToBytes, constructPhantomAgent, l1Payload };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,mBAAW,cAAc;IACvB,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED,aAAK,SAAS,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAgDzG,eAAO,MAAM,gBAAgB,eAAsB,MAAM,KAAG,QAAQ,SAAS,CAiB5E,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,YAAY,WAAW,GAAG,MAAM,cAAc,MAAM,KAAG,MA+B9F,CAAC;AAqBF,eAAO,MAAM,iBAAiB,UAAiB,MAAM;;;;;;;;;;;;;;EAiBpD,CAAC;AAEF,eAAO,MAAM,uBAAuB,SAAgB,MAAM,SAAS,OAAO,oBAKzE,CAAC"}
package/lib/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,yCAA2C;AAC3C,iDAAsF;AAStF,MAAM,SAAS,GAAG,KAAM,CAAC;AACzB,MAAM,OAAO,GAAG,IAAK,CAAC;AAEtB,0CAA0C;AAC1C,MAAM,aAAa,GAAG,IAAA,mBAAW,EAC/B,KAAK,IAAI,EAAE;IACT,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAqB,GAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmD,CAAC;IACvE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAA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WAAW,EAAE;YACX,CAAC,EAAE,SAAS,CAAC,OAAO;YACpB,CAAC,EAAE,KAAK;YACR,CAAC,EAAE,GAAG,KAAK,EAAE;YACb,CAAC,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE;YACpB,CAAC,EAAE,UAAU;YACb,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE;SACtB;KACF,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,iBAAiB,qBAiB5B;AAEK,MAAM,uBAAuB,GAAG,KAAK,EAAE,IAAY,EAAE,KAAc,EAAE,EAAE;IAC5E,MAAM,IAAI,GAAG,CAAC,MAAM,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAE,CAAC;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACrC,OAAO,GAAG,GAAG,QAAQ,CAAC;AACxB,CAAC,CAAC;AALW,QAAA,uBAAuB,2BAKlC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { getAllMids, getPerpetualsMetaData, getSpotMetaData } from './api/public-api';\n\nconst enum InstrumentType {\n PERPETUAL = 'PERPETUAL',\n SPOT = 'SPOT',\n}\n\ntype AssetInfo = { assetId: number; szDecimals: number; instType: InstrumentType; baseCurrency: string };\n\nconst CACHE_TTL = 60_000;\nconst MID_TTL = 5_000;\n\n// Create caches using createCache utility\nconst perpMetaCache = createCache<Map<string, { assetId: number; szDecimals: number }>>(\n async () => {\n console.info(`[Hyperliquid] Refreshing perpetual metadata cache`);\n const meta = await getPerpetualsMetaData();\n const map = new Map<string, { assetId: number; szDecimals: number }>();\n meta.universe.forEach((token, index) =>\n map.set(token.name, { assetId: index, szDecimals: token.szDecimals }),\n );\n return map;\n },\n { expire: CACHE_TTL },\n);\n\nconst spotMetaCache = createCache<Map<string, { assetId: number; szDecimals: number }>>(\n async () => {\n console.info(`[Hyperliquid] Refreshing spot metadata cache`);\n const meta = await getSpotMetaData();\n const map = new Map<string, { assetId: number; szDecimals: number }>();\n meta.tokens.forEach((token) =>\n map.set(token.name, { assetId: token.index, szDecimals: token.szDecimals }),\n );\n return map;\n },\n { expire: CACHE_TTL },\n);\n\nconst midPriceCache = createCache<Map<string, number>>(\n async () => {\n console.info(`[Hyperliquid] Refreshing mid price cache`);\n const mids = await getAllMids();\n const map = new Map<string, number>();\n for (const [coin, price] of Object.entries(mids ?? {})) {\n const value = Number(price);\n if (Number.isFinite(value)) {\n map.set(coin, value);\n }\n }\n return map;\n },\n { expire: MID_TTL },\n);\n\nexport const resolveAssetInfo = async (product_id: string): Promise<AssetInfo> => {\n const [instType, symbol] = decodePath(product_id);\n if (!instType || !symbol) {\n throw new Error(`Invalid product_id: ${product_id}`);\n }\n const baseCurrency = symbol.split('-')[0];\n if (instType === InstrumentType.PERPETUAL) {\n const map = (await perpMetaCache.query('perp'))!;\n const info = map.get(baseCurrency)!;\n return { ...info, instType: InstrumentType.PERPETUAL, baseCurrency };\n }\n if (instType === InstrumentType.SPOT) {\n const map = (await spotMetaCache.query('spot'))!;\n const info = map.get(baseCurrency)!;\n return { ...info, instType: InstrumentType.SPOT, baseCurrency };\n }\n throw new Error(`Unsupported instrument type: ${instType}`);\n};\n\nexport const roundPrice = (price: number, instType: 'PERPETUAL' | 'SPOT', szDecimals: number): string => {\n const MAX_DECIMALS = instType === 'PERPETUAL' ? 6 : 8;\n const maxDecimalPlaces = Math.max(0, MAX_DECIMALS - szDecimals);\n if (!Number.isFinite(price)) {\n throw new Error(`Invalid price: ${price}`);\n }\n\n // Handle significant figures (max 5)\n const priceStr = price.toString();\n const significantFigures = priceStr.replace(/^0+\\.?0*/, '').replace(/\\./g, '').length;\n\n let roundedPrice = price;\n if (significantFigures > 5) {\n // Logic to round to 5 sig figs\n // This is complex to do perfectly with just numbers, but let's try to be safe\n const magnitude = Math.floor(Math.log10(Math.abs(price)));\n // We want 5 sig figs.\n // e.g. 123456 -> 123460 (mag 5, round to 10^(5-4)=10^1)\n // e.g. 0.00123456 -> 0.0012346 (mag -3, round to 10^(-3-4)=10^-7)\n const factor = Math.pow(10, magnitude - 4);\n roundedPrice = Math.round(price / factor) * factor;\n }\n\n // Now format to maxDecimalPlaces without scientific notation\n // Use toFixed which returns fixed point notation\n let s = roundedPrice.toFixed(maxDecimalPlaces);\n // Remove trailing zeros and decimal point if integer\n if (s.includes('.')) {\n s = s.replace(/\\.?0+$/, '');\n }\n return s;\n};\n\nconst resolvePrice = async (\n order: IOrder,\n instType: 'PERPETUAL' | 'SPOT',\n szDecimals: number,\n baseCurrency: string,\n) => {\n if (order.order_type === 'MARKET') {\n const mid = await getMidPriceWithSlippage(\n baseCurrency,\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT',\n );\n return roundPrice(mid, instType, szDecimals);\n }\n if (!order.price) {\n throw new Error('price is required for non-market orders');\n }\n return roundPrice(+order.price, instType, szDecimals);\n};\n\nexport const buildOrderPayload = async (order: IOrder) => {\n const assetInfo = await resolveAssetInfo(order.product_id);\n const isBuy = order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT';\n const reduceOnly = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price = await resolvePrice(order, assetInfo.instType, assetInfo.szDecimals, assetInfo.baseCurrency);\n const tif = order.order_type === 'MARKET' ? 'Ioc' : order.order_type === 'MAKER' ? 'Alo' : 'Gtc';\n return {\n assetInfo,\n orderParams: {\n a: assetInfo.assetId,\n b: isBuy,\n p: `${price}`,\n s: `${order.volume}`,\n r: reduceOnly,\n t: { limit: { tif } },\n },\n };\n};\n\nexport const getMidPriceWithSlippage = async (coin: string, isBuy: boolean) => {\n const mids = (await midPriceCache.query('mids'))!;\n const mid = mids.get(coin)!;\n const slippage = isBuy ? 1.05 : 0.95;\n return mid * slippage;\n};\n"]}
File without changes
File without changes
File without changes