@ledgerhq/coin-hypercore 0.2.0 → 0.4.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 (53) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/api/getBalance.d.ts +3 -0
  3. package/lib/api/getBalance.d.ts.map +1 -0
  4. package/lib/api/getBalance.js +21 -0
  5. package/lib/api/getBalance.js.map +1 -0
  6. package/lib/api/index.d.ts +1 -1
  7. package/lib/api/index.d.ts.map +1 -1
  8. package/lib/api/index.js +21 -20
  9. package/lib/api/index.js.map +1 -1
  10. package/lib/api/listOperations.d.ts +3 -0
  11. package/lib/api/listOperations.d.ts.map +1 -0
  12. package/lib/api/listOperations.js +64 -0
  13. package/lib/api/listOperations.js.map +1 -0
  14. package/lib/network/yield.d.ts +38 -0
  15. package/lib/network/yield.d.ts.map +1 -0
  16. package/lib/network/yield.js +36 -0
  17. package/lib/network/yield.js.map +1 -0
  18. package/lib/utils/index.d.ts +2 -0
  19. package/lib/utils/index.d.ts.map +1 -0
  20. package/lib/utils/index.js +11 -0
  21. package/lib/utils/index.js.map +1 -0
  22. package/lib-es/api/getBalance.d.ts +3 -0
  23. package/lib-es/api/getBalance.d.ts.map +1 -0
  24. package/lib-es/api/getBalance.js +18 -0
  25. package/lib-es/api/getBalance.js.map +1 -0
  26. package/lib-es/api/index.d.ts +1 -1
  27. package/lib-es/api/index.d.ts.map +1 -1
  28. package/lib-es/api/index.js +6 -5
  29. package/lib-es/api/index.js.map +1 -1
  30. package/lib-es/api/listOperations.d.ts +3 -0
  31. package/lib-es/api/listOperations.d.ts.map +1 -0
  32. package/lib-es/api/listOperations.js +61 -0
  33. package/lib-es/api/listOperations.js.map +1 -0
  34. package/lib-es/network/yield.d.ts +38 -0
  35. package/lib-es/network/yield.d.ts.map +1 -0
  36. package/lib-es/network/yield.js +28 -0
  37. package/lib-es/network/yield.js.map +1 -0
  38. package/lib-es/utils/index.d.ts +2 -0
  39. package/lib-es/utils/index.d.ts.map +1 -0
  40. package/lib-es/utils/index.js +8 -0
  41. package/lib-es/utils/index.js.map +1 -0
  42. package/package.json +3 -3
  43. package/src/api/getBalance.test.ts +66 -0
  44. package/src/api/getBalance.ts +21 -0
  45. package/src/api/index.integ.test.ts +55 -3
  46. package/src/api/index.test.ts +29 -0
  47. package/src/api/index.ts +6 -7
  48. package/src/api/listOperations.test.ts +163 -0
  49. package/src/api/listOperations.ts +84 -0
  50. package/src/network/yield.test.ts +72 -0
  51. package/src/network/yield.ts +72 -0
  52. package/src/utils/index.test.ts +20 -0
  53. package/src/utils/index.ts +9 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ledgerhq/coin-hypercore
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#737](https://github.com/LedgerHQ/coin-modules/pull/737) [`8e8c819`](https://github.com/LedgerHQ/coin-modules/commit/8e8c819a2af6d9f47a60ff2f56a6248d55dc271f) Thanks [@YazhuEth](https://github.com/YazhuEth)! - Implement `getBalance` (USDC account balance) and `listOperations` (deposit/withdraw only) for coin-hypercore, backed by the Yield.xyz proxy client
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#725](https://github.com/LedgerHQ/coin-modules/pull/725) [`39dd8ef`](https://github.com/LedgerHQ/coin-modules/commit/39dd8ef0eee5974437d6b13925d27cd022d8a940) Thanks [@henri-ly](https://github.com/henri-ly)! - update package to use catalog + hypercore yield client
14
+
15
+ ## 0.2.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#734](https://github.com/LedgerHQ/coin-modules/pull/734) [`fe0b58e`](https://github.com/LedgerHQ/coin-modules/commit/fe0b58ebc0e1ecc2134b4b6fc73d516662de66b9) Thanks [@adussarps](https://github.com/adussarps)! - Add the read-only smart-contract `call` API to `CoinModuleApi`, along with the `CallParams`/`CallResult` types and a shared `notSupported` helper for modules that do not implement optional API methods. Modules without a contract-read primitive (`coin-hypercore`, `coin-stellar`, `coin-xrp`) now stub `call` as unsupported.
20
+
21
+ - Updated dependencies [[`fe0b58e`](https://github.com/LedgerHQ/coin-modules/commit/fe0b58ebc0e1ecc2134b4b6fc73d516662de66b9)]:
22
+ - @ledgerhq/coin-module-framework@4.0.0
23
+
3
24
  ## 0.2.0
4
25
 
5
26
  ### Minor Changes
@@ -0,0 +1,3 @@
1
+ import type { Balance } from '@ledgerhq/coin-module-framework/api/types';
2
+ export declare function getBalance(address: string): Promise<Balance[]>;
3
+ //# sourceMappingURL=getBalance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAA;AAMxE,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAWpE"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getBalance = getBalance;
6
+ const yield_1 = require("../network/yield");
7
+ const utils_1 = require("../utils");
8
+ // The proxy only exposes the USDC collateral, surfaced as the account's native balance:
9
+ // `value` is the total account value, `locked` the margin used by open positions.
10
+ async function getBalance(address) {
11
+ const { collateral, accountValue, usedMargin } = await (0, yield_1.fetchBalance)(address);
12
+ const magnitude = collateral.decimals ?? yield_1.USDC_DECIMALS;
13
+ return [
14
+ {
15
+ value: (0, utils_1.scaleToBigInt)(accountValue, magnitude),
16
+ locked: (0, utils_1.scaleToBigInt)(usedMargin, magnitude),
17
+ asset: { type: 'native' },
18
+ },
19
+ ];
20
+ }
21
+ //# sourceMappingURL=getBalance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAQtC,gCAWC;AAhBD,4CAA8D;AAC9D,oCAAwC;AAExC,wFAAwF;AACxF,kFAAkF;AAC3E,KAAK,UAAU,UAAU,CAAC,OAAe;IAC9C,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,oBAAY,EAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,IAAI,qBAAa,CAAA;IAEtD,OAAO;QACL;YACE,KAAK,EAAE,IAAA,qBAAa,EAAC,YAAY,EAAE,SAAS,CAAC;YAC7C,MAAM,EAAE,IAAA,qBAAa,EAAC,UAAU,EAAE,SAAS,CAAC;YAC5C,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;KACF,CAAA;AACH,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { CoinModuleApi } from '@ledgerhq/coin-module-framework/api/index';
1
+ import { type CoinModuleApi } from '@ledgerhq/coin-module-framework/api/index';
2
2
  import { type HypercoreConfig } from '../config';
3
3
  export declare function createApi(config: HypercoreConfig): CoinModuleApi;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAM5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAsBhE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,2CAA2C,CAAA;AAC5F,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAI5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAuBhE"}
package/lib/api/index.js CHANGED
@@ -6,30 +6,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.createApi = createApi;
9
+ const index_1 = require("@ledgerhq/coin-module-framework/api/index");
9
10
  const config_1 = __importDefault(require("../config"));
10
- const notSupported = (name) => () => {
11
- throw new Error(`${name} is not supported`);
12
- };
11
+ const getBalance_1 = require("./getBalance");
12
+ const listOperations_1 = require("./listOperations");
13
13
  function createApi(config) {
14
14
  config_1.default.setCoinConfig(() => ({ ...config, status: { type: 'active' } }));
15
15
  return {
16
- lastBlock: notSupported('lastBlock'),
17
- getBlockInfo: notSupported('getBlockInfo'),
18
- getBlock: notSupported('getBlock'),
19
- getValidators: notSupported('getValidators'),
20
- getBalance: notSupported('getBalance'),
21
- listOperations: notSupported('listOperations'),
22
- getStakes: notSupported('getStakes'),
23
- getRewards: notSupported('getRewards'),
24
- craftTransaction: notSupported('craftTransaction'),
25
- craftRawTransaction: notSupported('craftRawTransaction'),
26
- estimateFees: notSupported('estimateFees'),
27
- combine: notSupported('combine'),
28
- broadcast: notSupported('broadcast'),
29
- validateIntent: notSupported('validateIntent'),
30
- getNextSequence: notSupported('getNextSequence'),
31
- validateAddress: notSupported('validateAddress'),
32
- craftTransactionData: notSupported('craftTransactionData'),
16
+ lastBlock: (0, index_1.notSupported)('lastBlock'),
17
+ getBlockInfo: (0, index_1.notSupported)('getBlockInfo'),
18
+ getBlock: (0, index_1.notSupported)('getBlock'),
19
+ call: (0, index_1.notSupported)('call'),
20
+ getValidators: (0, index_1.notSupported)('getValidators'),
21
+ getBalance: getBalance_1.getBalance,
22
+ listOperations: listOperations_1.listOperations,
23
+ getStakes: (0, index_1.notSupported)('getStakes'),
24
+ getRewards: (0, index_1.notSupported)('getRewards'),
25
+ craftTransaction: (0, index_1.notSupported)('craftTransaction'),
26
+ craftRawTransaction: (0, index_1.notSupported)('craftRawTransaction'),
27
+ estimateFees: (0, index_1.notSupported)('estimateFees'),
28
+ combine: (0, index_1.notSupported)('combine'),
29
+ broadcast: (0, index_1.notSupported)('broadcast'),
30
+ validateIntent: (0, index_1.notSupported)('validateIntent'),
31
+ getNextSequence: (0, index_1.notSupported)('getNextSequence'),
32
+ validateAddress: (0, index_1.notSupported)('validateAddress'),
33
+ craftTransactionData: (0, index_1.notSupported)('craftTransactionData'),
33
34
  };
34
35
  }
35
36
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;AAStC,8BAsBC;AA5BD,uDAA4D;AAE5D,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,GAAU,EAAE;IACjD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,SAAgB,SAAS,CAAC,MAAuB;IAC/C,gBAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IAE3E,OAAO;QACL,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC;QACpC,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC;QAC1C,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC;QAClC,aAAa,EAAE,YAAY,CAAC,eAAe,CAAC;QAC5C,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC;QACtC,cAAc,EAAE,YAAY,CAAC,gBAAgB,CAAC;QAC9C,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC;QACpC,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC;QACtC,gBAAgB,EAAE,YAAY,CAAC,kBAAkB,CAAC;QAClD,mBAAmB,EAAE,YAAY,CAAC,qB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AAY,EAAE,IAAA,oBAAY,EAAC,cAAc,CAAC;QAC1C,OAAO,EAAE,IAAA,oBAAY,EAAC,SAAS,CAAC;QAChC,SAAS,EAAE,IAAA,oBAAY,EAAC,WAAW,CAAC;QACpC,cAAc,EAAE,IAAA,oBAAY,EAAC,gBAAgB,CAAC;QAC9C,eAAe,EAAE,IAAA,oBAAY,EAAC,iBAAiB,CAAC;QAChD,eAAe,EAAE,IAAA,oBAAY,EAAC,iBAAiB,CAAC;QAChD,oBAAoB,EAAE,IAAA,oBAAY,EAAC,sBAAsB,CAAC;KAC3D,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ListOperationsOptions, Operation, Page } from '@ledgerhq/coin-module-framework/api/types';
2
+ export declare function listOperations(address: string, { minHeight, cursor, limit, order }: ListOperationsOptions): Promise<Page<Operation>>;
3
+ //# sourceMappingURL=listOperations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AAmDlD,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACzD,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAsB1B"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.listOperations = listOperations;
6
+ const yield_1 = require("../network/yield");
7
+ const utils_1 = require("../utils");
8
+ const DEFAULT_LIMIT = 100;
9
+ // Deposits/withdrawals that actually settled — drafts (status CREATED) have no completedAt.
10
+ function isSettledTransfer(action) {
11
+ const isTransfer = action.action === yield_1.FUND_ACTION || action.action === yield_1.WITHDRAW_ACTION;
12
+ return isTransfer && action.completedAt !== null;
13
+ }
14
+ function toOperation(address, dto) {
15
+ const isDeposit = dto.action === yield_1.FUND_ACTION;
16
+ const amount = dto.summary?.amount ?? '0';
17
+ const date = new Date(dto.completedAt ?? dto.createdAt);
18
+ return {
19
+ id: `${address}-${dto.id}`,
20
+ type: isDeposit ? 'IN' : 'OUT',
21
+ senders: [address],
22
+ recipients: [address],
23
+ value: (0, utils_1.scaleToBigInt)(amount, yield_1.USDC_DECIMALS),
24
+ asset: { type: 'native' },
25
+ tx: {
26
+ hash: dto.id,
27
+ // HyperCore actions have no block height on this API.
28
+ block: { height: 0, hash: '', time: date },
29
+ fees: 0n,
30
+ date,
31
+ failed: dto.status.toUpperCase() === 'FAILED',
32
+ },
33
+ };
34
+ }
35
+ // The proxy only supports offset pagination, so the cursor is the numeric offset.
36
+ function parseCursor(cursor) {
37
+ if (cursor === undefined)
38
+ return 0;
39
+ const offset = Number(cursor);
40
+ if (!Number.isInteger(offset) || offset < 0) {
41
+ throw new Error(`listOperations received an invalid cursor: ${cursor}`);
42
+ }
43
+ return offset;
44
+ }
45
+ async function listOperations(address, { minHeight, cursor, limit, order }) {
46
+ // The proxy has no block height and always returns actions newest-first (descending).
47
+ if (minHeight > 0) {
48
+ throw new Error('listOperations with a minHeight is not supported');
49
+ }
50
+ if (order === 'asc') {
51
+ throw new Error('listOperations with an ascending order is not supported');
52
+ }
53
+ const offset = parseCursor(cursor);
54
+ const pageLimit = limit ?? DEFAULT_LIMIT;
55
+ const page = await (0, yield_1.fetchActions)(address, offset, pageLimit);
56
+ const items = page.items.filter(isSettledTransfer).map((action) => toOperation(address, action));
57
+ // Advance by raw items consumed, not the filtered count, so no action is skipped.
58
+ // The cursor is offset-based (volatile if new actions appear between calls); the proxy
59
+ // exposes no stable id/date-based pagination.
60
+ const nextOffset = offset + page.items.length;
61
+ const next = nextOffset < page.total ? String(nextOffset) : undefined;
62
+ return { items, next };
63
+ }
64
+ //# sourceMappingURL=listOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAyDtC,wCAyBC;AA3ED,4CAMyB;AACzB,oCAAwC;AAExC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,4FAA4F;AAC5F,SAAS,iBAAiB,CAAC,MAAiB;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,KAAK,mBAAW,IAAI,MAAM,CAAC,MAAM,KAAK,uBAAe,CAAA;IACrF,OAAO,UAAU,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI,CAAA;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,OAAe,EAAE,GAAc;IAClD,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,KAAK,mBAAW,CAAA;IAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,CAAA;IACzC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAEvD,OAAO;QACL,EAAE,EAAE,GAAG,OAAO,IAAI,GAAG,CAAC,EAAE,EAAE;QAC1B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;QAC9B,OAAO,EAAE,CAAC,OAAO,CAAC;QAClB,UAAU,EAAE,CAAC,OAAO,CAAC;QACrB,KAAK,EAAE,IAAA,qBAAa,EAAC,MAAM,EAAE,qBAAa,CAAC;QAC3C,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,EAAE,EAAE;YACF,IAAI,EAAE,GAAG,CAAC,EAAE;YACZ,sDAAsD;YACtD,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;YAC1C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AAG,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC7C,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAErE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC"}
@@ -0,0 +1,38 @@
1
+ export declare const USDC_DECIMALS = 6;
2
+ export declare const FUND_ACTION = "fund";
3
+ export declare const WITHDRAW_ACTION = "withdraw";
4
+ export type TokenDto = {
5
+ symbol: string;
6
+ network: string;
7
+ name?: string;
8
+ decimals?: number;
9
+ address?: string | null;
10
+ logoURI?: string | null;
11
+ };
12
+ export type YieldBalanceDto = {
13
+ providerId: string;
14
+ collateral: TokenDto;
15
+ accountValue: number;
16
+ usedMargin: number;
17
+ availableBalance: number;
18
+ unrealizedPnl: number;
19
+ };
20
+ export declare function fetchBalance(address: string): Promise<YieldBalanceDto>;
21
+ export type ActionDto = {
22
+ id: string;
23
+ action: string;
24
+ status: string;
25
+ summary: {
26
+ amount: string;
27
+ } | null;
28
+ createdAt: string;
29
+ completedAt: string | null;
30
+ };
31
+ export type ActionsPage = {
32
+ total: number;
33
+ offset: number;
34
+ limit: number;
35
+ items: ActionDto[];
36
+ };
37
+ export declare function fetchActions(address: string, offset: number, limit: number): Promise<ActionsPage>;
38
+ //# sourceMappingURL=yield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yield.d.ts","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,aAAa,IAAI,CAAA;AAE9B,eAAO,MAAM,WAAW,SAAS,CAAA;AACjC,eAAO,MAAM,eAAe,aAAa,CAAA;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IAEf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,QAAQ,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAO5E;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IAEd,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAClC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,SAAS,EAAE,CAAA;CACnB,CAAA;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,WAAW,CAAC,CAOtB"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.WITHDRAW_ACTION = exports.FUND_ACTION = exports.USDC_DECIMALS = void 0;
9
+ exports.fetchBalance = fetchBalance;
10
+ exports.fetchActions = fetchActions;
11
+ const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
12
+ const config_1 = __importDefault(require("../config"));
13
+ const PROVIDER_ID = 'hyperliquid';
14
+ const getBaseUrl = () => config_1.default.getCoinConfig().node;
15
+ // The collateral is USDC and the proxy omits its decimals.
16
+ exports.USDC_DECIMALS = 6;
17
+ // A deposit is the `fund` action, a withdrawal the `withdraw` action.
18
+ exports.FUND_ACTION = 'fund';
19
+ exports.WITHDRAW_ACTION = 'withdraw';
20
+ async function fetchBalance(address) {
21
+ const { data } = await (0, live_network_1.default)({
22
+ method: 'POST',
23
+ url: `${getBaseUrl()}/v1/balances`,
24
+ data: { providerId: PROVIDER_ID, address },
25
+ });
26
+ return data;
27
+ }
28
+ async function fetchActions(address, offset, limit) {
29
+ const { data } = await (0, live_network_1.default)({
30
+ method: 'GET',
31
+ url: `${getBaseUrl()}/v1/actions`,
32
+ params: { address, offset, limit, providerId: PROVIDER_ID },
33
+ });
34
+ return data;
35
+ }
36
+ //# sourceMappingURL=yield.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yield.js","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;AAiCtC,oCAOC;AAmBD,oCAWC;AApED,0EAA4C;AAC5C,uDAAkC;AAElC,MAAM,WAAW,GAAG,aAAa,CAAA;AACjC,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,gBAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAA;AAExD,2DAA2D;AAC9C,QAAA,aAAa,GAAG,CAAC,CAAA;AAC9B,sEAAsE;AACzD,QAAA,WAAW,GAAG,MAAM,CAAA;AACpB,QAAA,eAAe,GAAG,UAAU,CAAA;AAqBlC,KAAK,UAAU,YAAY,CAAC,OAAe;IAChD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,sBAAO,EAAkB;QAC9C,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,GAAG,UAAU,EAAE,cAAc;QAClC,IAAI,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE;KAC3C,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAmBM,KAAK,UAAU,YAAY,CAChC,OAAe,EACf,MAAc,EACd,KAAa;IAEb,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,sBAAO,EAAc;QAC1C,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,GAAG,UAAU,EAAE,aAAa;QACjC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE;KAC5D,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function scaleToBigInt(amount: string | number, magnitude: number): bigint;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEhF"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.scaleToBigInt = scaleToBigInt;
6
+ const currencies_1 = require("@ledgerhq/coin-module-framework/currencies");
7
+ // Convert a decimal amount into its integer base-unit representation.
8
+ function scaleToBigInt(amount, magnitude) {
9
+ return BigInt((0, currencies_1.parseCurrencyUnit)({ name: '', code: '', magnitude }, String(amount)).toFixed());
10
+ }
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAKtC,sCAEC;AALD,2EAA8E;AAE9E,sEAAsE;AACtE,SAAgB,aAAa,CAAC,MAAuB,EAAE,SAAiB;IACtE,OAAO,MAAM,CAAC,IAAA,8BAAiB,EAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;AAC/F,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Balance } from '@ledgerhq/coin-module-framework/api/types';
2
+ export declare function getBalance(address: string): Promise<Balance[]>;
3
+ //# sourceMappingURL=getBalance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAA;AAMxE,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAWpE"}
@@ -0,0 +1,18 @@
1
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { USDC_DECIMALS, fetchBalance } from '../network/yield';
4
+ import { scaleToBigInt } from '../utils';
5
+ // The proxy only exposes the USDC collateral, surfaced as the account's native balance:
6
+ // `value` is the total account value, `locked` the margin used by open positions.
7
+ export async function getBalance(address) {
8
+ const { collateral, accountValue, usedMargin } = await fetchBalance(address);
9
+ const magnitude = collateral.decimals ?? USDC_DECIMALS;
10
+ return [
11
+ {
12
+ value: scaleToBigInt(accountValue, magnitude),
13
+ locked: scaleToBigInt(usedMargin, magnitude),
14
+ asset: { type: 'native' },
15
+ },
16
+ ];
17
+ }
18
+ //# sourceMappingURL=getBalance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,wFAAwF;AACxF,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe;IAC9C,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,IAAI,aAAa,CAAA;IAEtD,OAAO;QACL;YACE,KAAK,EAAE,aAAa,CAAC,YAAY,EAAE,SAAS,CAAC;YAC7C,MAAM,EAAE,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC;YAC5C,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;KACF,CAAA;AACH,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { CoinModuleApi } from '@ledgerhq/coin-module-framework/api/index';
1
+ import { type CoinModuleApi } from '@ledgerhq/coin-module-framework/api/index';
2
2
  import { type HypercoreConfig } from '../config';
3
3
  export declare function createApi(config: HypercoreConfig): CoinModuleApi;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAM5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAsBhE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,2CAA2C,CAAA;AAC5F,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAI5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAuBhE"}
@@ -1,18 +1,19 @@
1
1
  // SPDX-FileCopyrightText: © 2024 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { notSupported } from '@ledgerhq/coin-module-framework/api/index';
3
4
  import coinConfig from '../config';
4
- const notSupported = (name) => () => {
5
- throw new Error(`${name} is not supported`);
6
- };
5
+ import { getBalance } from './getBalance';
6
+ import { listOperations } from './listOperations';
7
7
  export function createApi(config) {
8
8
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: 'active' } }));
9
9
  return {
10
10
  lastBlock: notSupported('lastBlock'),
11
11
  getBlockInfo: notSupported('getBlockInfo'),
12
12
  getBlock: notSupported('getBlock'),
13
+ call: notSupported('call'),
13
14
  getValidators: notSupported('getValidators'),
14
- getBalance: notSupported('getBalance'),
15
- listOperations: notSupported('listOperations'),
15
+ getBalance,
16
+ listOperations,
16
17
  getStakes: notSupported('getStakes'),
17
18
  getRewards: notSupported('getRewards'),
18
19
  craftTransaction: notSupported('craftTransaction'),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,UAAoC,MAAM,WAAW,CAAA;AAE5D,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,GAAU,EAAE;IACjD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,UAAU,SAAS,CAAC,MAAuB;IAC/C,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,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QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IAE3E,OAAO;QACL,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC;QACpC,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC;QAC1C,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC;QAClC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC;QAC1B,aAAa,EAAE,YAAY,CAAC,eAAe,CAAC;QAC5C,UAAU;QACV,cAAc;QACd,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC;QACpC,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC;QACtC,gBAAgB,EAAE,YAAY,CAAC,kBAAkB,CAAC;QAClD,mBAAmB,EAAE,YAAY,CAAC,qBAAqB,CAAC;QACxD,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC;QAC1C,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC;QAChC,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC;QACpC,cAAc,EAAE,YAAY,CAAC,gBAAgB,CAAC;QAC9C,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC;QAChD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC;QAChD,oBAAoB,EAAE,YAAY,CAAC,sBAAsB,CAAC;KAC3D,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ListOperationsOptions, Operation, Page } from '@ledgerhq/coin-module-framework/api/types';
2
+ export declare function listOperations(address: string, { minHeight, cursor, limit, order }: ListOperationsOptions): Promise<Page<Operation>>;
3
+ //# sourceMappingURL=listOperations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AAmDlD,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACzD,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAsB1B"}
@@ -0,0 +1,61 @@
1
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { FUND_ACTION, USDC_DECIMALS, WITHDRAW_ACTION, fetchActions, } from '../network/yield';
4
+ import { scaleToBigInt } from '../utils';
5
+ const DEFAULT_LIMIT = 100;
6
+ // Deposits/withdrawals that actually settled — drafts (status CREATED) have no completedAt.
7
+ function isSettledTransfer(action) {
8
+ const isTransfer = action.action === FUND_ACTION || action.action === WITHDRAW_ACTION;
9
+ return isTransfer && action.completedAt !== null;
10
+ }
11
+ function toOperation(address, dto) {
12
+ const isDeposit = dto.action === FUND_ACTION;
13
+ const amount = dto.summary?.amount ?? '0';
14
+ const date = new Date(dto.completedAt ?? dto.createdAt);
15
+ return {
16
+ id: `${address}-${dto.id}`,
17
+ type: isDeposit ? 'IN' : 'OUT',
18
+ senders: [address],
19
+ recipients: [address],
20
+ value: scaleToBigInt(amount, USDC_DECIMALS),
21
+ asset: { type: 'native' },
22
+ tx: {
23
+ hash: dto.id,
24
+ // HyperCore actions have no block height on this API.
25
+ block: { height: 0, hash: '', time: date },
26
+ fees: 0n,
27
+ date,
28
+ failed: dto.status.toUpperCase() === 'FAILED',
29
+ },
30
+ };
31
+ }
32
+ // The proxy only supports offset pagination, so the cursor is the numeric offset.
33
+ function parseCursor(cursor) {
34
+ if (cursor === undefined)
35
+ return 0;
36
+ const offset = Number(cursor);
37
+ if (!Number.isInteger(offset) || offset < 0) {
38
+ throw new Error(`listOperations received an invalid cursor: ${cursor}`);
39
+ }
40
+ return offset;
41
+ }
42
+ export async function listOperations(address, { minHeight, cursor, limit, order }) {
43
+ // The proxy has no block height and always returns actions newest-first (descending).
44
+ if (minHeight > 0) {
45
+ throw new Error('listOperations with a minHeight is not supported');
46
+ }
47
+ if (order === 'asc') {
48
+ throw new Error('listOperations with an ascending order is not supported');
49
+ }
50
+ const offset = parseCursor(cursor);
51
+ const pageLimit = limit ?? DEFAULT_LIMIT;
52
+ const page = await fetchActions(address, offset, pageLimit);
53
+ const items = page.items.filter(isSettledTransfer).map((action) => toOperation(address, action));
54
+ // Advance by raw items consumed, not the filtered count, so no action is skipped.
55
+ // The cursor is offset-based (volatile if new actions appear between calls); the proxy
56
+ // exposes no stable id/date-based pagination.
57
+ const nextOffset = offset + page.items.length;
58
+ const next = nextOffset < page.total ? String(nextOffset) : undefined;
59
+ return { items, next };
60
+ }
61
+ //# sourceMappingURL=listOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAOtC,OAAO,EAEL,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,4FAA4F;AAC5F,SAAS,iBAAiB,CAAC,MAAiB;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,KAAK,eAAe,CAAA;IACrF,OAAO,UAAU,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI,CAAA;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,OAAe,EAAE,GAAc;IAClD,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,KAAK,WAAW,CAAA;IAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,CAAA;IACzC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAEvD,OAAO;QACL,EAAE,EAAE,GAAG,OAAO,IAAI,GAAG,CAAC,EAAE,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E,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,KAAK,IAAI,aAAa,CAAA;IACxC,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAE3D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IAEhG,kFAAkF;IAClF,uFAAuF;IACvF,8CAA8C;IAC9C,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC7C,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAErE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC"}
@@ -0,0 +1,38 @@
1
+ export declare const USDC_DECIMALS = 6;
2
+ export declare const FUND_ACTION = "fund";
3
+ export declare const WITHDRAW_ACTION = "withdraw";
4
+ export type TokenDto = {
5
+ symbol: string;
6
+ network: string;
7
+ name?: string;
8
+ decimals?: number;
9
+ address?: string | null;
10
+ logoURI?: string | null;
11
+ };
12
+ export type YieldBalanceDto = {
13
+ providerId: string;
14
+ collateral: TokenDto;
15
+ accountValue: number;
16
+ usedMargin: number;
17
+ availableBalance: number;
18
+ unrealizedPnl: number;
19
+ };
20
+ export declare function fetchBalance(address: string): Promise<YieldBalanceDto>;
21
+ export type ActionDto = {
22
+ id: string;
23
+ action: string;
24
+ status: string;
25
+ summary: {
26
+ amount: string;
27
+ } | null;
28
+ createdAt: string;
29
+ completedAt: string | null;
30
+ };
31
+ export type ActionsPage = {
32
+ total: number;
33
+ offset: number;
34
+ limit: number;
35
+ items: ActionDto[];
36
+ };
37
+ export declare function fetchActions(address: string, offset: number, limit: number): Promise<ActionsPage>;
38
+ //# sourceMappingURL=yield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yield.d.ts","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,aAAa,IAAI,CAAA;AAE9B,eAAO,MAAM,WAAW,SAAS,CAAA;AACjC,eAAO,MAAM,eAAe,aAAa,CAAA;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IAEf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,QAAQ,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAO5E;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IAEd,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAClC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,SAAS,EAAE,CAAA;CACnB,CAAA;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,WAAW,CAAC,CAOtB"}
@@ -0,0 +1,28 @@
1
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import network from '@ledgerhq/live-network';
4
+ import coinConfig from '../config';
5
+ const PROVIDER_ID = 'hyperliquid';
6
+ const getBaseUrl = () => coinConfig.getCoinConfig().node;
7
+ // The collateral is USDC and the proxy omits its decimals.
8
+ export const USDC_DECIMALS = 6;
9
+ // A deposit is the `fund` action, a withdrawal the `withdraw` action.
10
+ export const FUND_ACTION = 'fund';
11
+ export const WITHDRAW_ACTION = 'withdraw';
12
+ export async function fetchBalance(address) {
13
+ const { data } = await network({
14
+ method: 'POST',
15
+ url: `${getBaseUrl()}/v1/balances`,
16
+ data: { providerId: PROVIDER_ID, address },
17
+ });
18
+ return data;
19
+ }
20
+ export async function fetchActions(address, offset, limit) {
21
+ const { data } = await network({
22
+ method: 'GET',
23
+ url: `${getBaseUrl()}/v1/actions`,
24
+ params: { address, offset, limit, providerId: PROVIDER_ID },
25
+ });
26
+ return data;
27
+ }
28
+ //# sourceMappingURL=yield.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yield.js","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAEtC,OAAO,OAAO,MAAM,wBAAwB,CAAA;AAC5C,OAAO,UAAU,MAAM,WAAW,CAAA;AAElC,MAAM,WAAW,GAAG,aAAa,CAAA;AACjC,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAA;AAExD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAA;AAC9B,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAA;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAA;AAqBzC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAe;IAChD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAkB;QAC9C,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,GAAG,UAAU,EAAE,cAAc;QAClC,IAAI,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE;KAC3C,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAmBD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAe,EACf,MAAc,EACd,KAAa;IAEb,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAc;QAC1C,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,GAAG,UAAU,EAAE,aAAa;QACjC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE;KAC5D,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function scaleToBigInt(amount: string | number, magnitude: number): bigint;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEhF"}
@@ -0,0 +1,8 @@
1
+ // SPDX-FileCopyrightText: © 2024 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { parseCurrencyUnit } from '@ledgerhq/coin-module-framework/currencies';
4
+ // Convert a decimal amount into its integer base-unit representation.
5
+ export function scaleToBigInt(amount, magnitude) {
6
+ return BigInt(parseCurrencyUnit({ name: '', code: '', magnitude }, String(amount)).toFixed());
7
+ }
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAA;AAE9E,sEAAsE;AACtE,MAAM,UAAU,aAAa,CAAC,MAAuB,EAAE,SAAiB;IACtE,OAAO,MAAM,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;AAC/F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-hypercore",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Ledger Hypercore Coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -65,7 +65,7 @@
65
65
  "author": "LEDGER SAS",
66
66
  "license": "Apache-2.0",
67
67
  "dependencies": {
68
- "@ledgerhq/coin-module-framework": "^3.6.0"
68
+ "@ledgerhq/coin-module-framework": "^4.0.1"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@swc/core": "1.15.11",
@@ -94,7 +94,7 @@
94
94
  "test": "jest",
95
95
  "test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand",
96
96
  "test-watch": "jest --watch",
97
- "test-integ": "jest --config=jest.integ.config.js --passWithNoTests",
97
+ "test-integ": "jest --config=jest.integ.config.js",
98
98
  "test-integ:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --config=jest.integ.config.js",
99
99
  "typecheck": "tsc --noEmit --customConditions node",
100
100
  "unimported": "knip --include=files,dependencies",