@ledgerhq/coin-hypercore 0.4.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/lib/api/getBalance.d.ts +2 -1
- package/lib/api/getBalance.d.ts.map +1 -1
- package/lib/api/getBalance.js +3 -2
- package/lib/api/getBalance.js.map +1 -1
- package/lib/api/index.d.ts +3 -3
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +6 -10
- package/lib/api/index.js.map +1 -1
- package/lib/api/listOperations.d.ts +2 -1
- package/lib/api/listOperations.d.ts.map +1 -1
- package/lib/api/listOperations.js +3 -2
- package/lib/api/listOperations.js.map +1 -1
- package/lib/config.d.ts +3 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/network/yield.d.ts +3 -2
- package/lib/network/yield.d.ts.map +1 -1
- package/lib/network/yield.js +4 -6
- package/lib/network/yield.js.map +1 -1
- package/lib-es/api/getBalance.d.ts +2 -1
- package/lib-es/api/getBalance.d.ts.map +1 -1
- package/lib-es/api/getBalance.js +3 -2
- package/lib-es/api/getBalance.js.map +1 -1
- package/lib-es/api/index.d.ts +3 -3
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +6 -7
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/listOperations.d.ts +2 -1
- package/lib-es/api/listOperations.d.ts.map +1 -1
- package/lib-es/api/listOperations.js +3 -2
- package/lib-es/api/listOperations.js.map +1 -1
- package/lib-es/config.d.ts +3 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/network/yield.d.ts +3 -2
- package/lib-es/network/yield.d.ts.map +1 -1
- package/lib-es/network/yield.js +4 -6
- package/lib-es/network/yield.js.map +1 -1
- package/package.json +2 -2
- package/src/api/getBalance.test.ts +8 -7
- package/src/api/getBalance.ts +4 -2
- package/src/api/index.integ.test.ts +11 -6
- package/src/api/index.test.ts +1 -1
- package/src/api/index.ts +16 -10
- package/src/api/listOperations.test.ts +15 -14
- package/src/api/listOperations.ts +4 -1
- package/src/config.ts +4 -1
- package/src/network/yield.test.ts +7 -8
- package/src/network/yield.ts +8 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @ledgerhq/coin-hypercore
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#770](https://github.com/LedgerHQ/coin-modules/pull/770) [`1367938`](https://github.com/LedgerHQ/coin-modules/commit/136793888c492f6bbb34cb0e90801268c55ef338) Thanks [@qperrot](https://github.com/qperrot)! - feat!: thread a mandatory `Context` (config + logger) through the coin module API (ADR-019)
|
|
8
|
+
|
|
9
|
+
Introduces `Context<T>` and `Logger` in `@ledgerhq/coin-module-framework/config`, where
|
|
10
|
+
`Context.config` is an async config accessor (`(currencyId?) => Promise<T>`). **Breaking changes:**
|
|
11
|
+
|
|
12
|
+
- Every `CoinModuleApi` method (including `getAccountInfo`) now takes a **mandatory `context` as its
|
|
13
|
+
first argument**, and all non-mandatory parameters are grouped into a single trailing `options`
|
|
14
|
+
object (e.g. `getBalance(context, address, options?)`, `craftTransaction(context, intent, { customFees })`,
|
|
15
|
+
`combine(context, tx, signature, { pubkey })`, `getStakes(context, address, { cursor })`).
|
|
16
|
+
- `CoinModuleApi` gains a **mandatory first type parameter `ConfigType`**
|
|
17
|
+
(`CoinModuleApi<ConfigType, MemoType?, TxDataType?>`).
|
|
18
|
+
- `createApi()` no longer takes a config argument; the caller builds the `Context` (config accessor
|
|
19
|
+
- logger) and passes it to each method.
|
|
20
|
+
|
|
21
|
+
Each coin module reads its coin config and logger from the provided context instead of the former
|
|
22
|
+
`getCoinConfig` singleton and the global `log`; internal layers receive the resolved config value
|
|
23
|
+
(not the context) unless they also need the logger. Providing the HTTP client through the context
|
|
24
|
+
remains out of scope.
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`1367938`](https://github.com/LedgerHQ/coin-modules/commit/136793888c492f6bbb34cb0e90801268c55ef338)]:
|
|
29
|
+
- @ledgerhq/coin-module-framework@6.0.0
|
|
30
|
+
|
|
31
|
+
## 0.4.5
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [[`f2c9b99`](https://github.com/LedgerHQ/coin-modules/commit/f2c9b99f8b2218944d00b7f13f2155708fc2f3f4)]:
|
|
36
|
+
- @ledgerhq/coin-module-framework@5.0.0
|
|
37
|
+
|
|
3
38
|
## 0.4.4
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
package/lib/api/getBalance.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HypercoreContext } from '../config';
|
|
1
2
|
import type { Balance } from '@ledgerhq/coin-module-framework/api/types';
|
|
2
|
-
export declare function getBalance(address: string): Promise<Balance[]>;
|
|
3
|
+
export declare function getBalance(context: HypercoreContext, address: string): Promise<Balance[]>;
|
|
3
4
|
//# sourceMappingURL=getBalance.d.ts.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAA;AAMxE,wBAAsB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAY/F"}
|
package/lib/api/getBalance.js
CHANGED
|
@@ -7,8 +7,9 @@ const yield_1 = require("../network/yield");
|
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
// The proxy only exposes the USDC collateral, surfaced as the account's native balance:
|
|
9
9
|
// `value` is the total account value, `locked` the margin used by open positions.
|
|
10
|
-
async function getBalance(address) {
|
|
11
|
-
const
|
|
10
|
+
async function getBalance(context, address) {
|
|
11
|
+
const config = await context.config();
|
|
12
|
+
const { collateral, accountValue, usedMargin } = await (0, yield_1.fetchBalance)(config, address);
|
|
12
13
|
const magnitude = collateral.decimals ?? yield_1.USDC_DECIMALS;
|
|
13
14
|
return [
|
|
14
15
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;
|
|
1
|
+
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAStC,gCAYC;AAjBD,4CAA8D;AAC9D,oCAAwC;AAExC,wFAAwF;AACxF,kFAAkF;AAC3E,KAAK,UAAU,UAAU,CAAC,OAAyB,EAAE,OAAe;IACzE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAA;IACrC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,oBAAY,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpF,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"}
|
package/lib/api/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CoinModuleApi } from '@ledgerhq/coin-module-framework/api/index';
|
|
3
|
-
export declare function createApi(
|
|
1
|
+
import type { HypercoreCoinConfig } from '../config';
|
|
2
|
+
import type { CoinModuleApi, MemoNotSupported, TxDataNotSupported } from '@ledgerhq/coin-module-framework/api/index';
|
|
3
|
+
export declare function createApi(): CoinModuleApi<HypercoreCoinConfig, MemoNotSupported, TxDataNotSupported>;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2CAA2C,CAAA;AAQlD,wBAAgB,SAAS,IAAI,aAAa,CACxC,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,CACnB,CAqBA"}
|
package/lib/api/index.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
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
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
5
|
exports.createApi = createApi;
|
|
9
6
|
const index_1 = require("@ledgerhq/coin-module-framework/api/index");
|
|
10
|
-
const config_1 = __importDefault(require("../config"));
|
|
11
7
|
const getBalance_1 = require("./getBalance");
|
|
12
8
|
const lastBlock_1 = require("./lastBlock");
|
|
13
9
|
const listOperations_1 = require("./listOperations");
|
|
14
10
|
const validateAddress_1 = require("./validateAddress");
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
// The caller builds the {@link Context} (config + logger) and passes it to each method (ADR-019).
|
|
12
|
+
function createApi() {
|
|
17
13
|
return {
|
|
18
|
-
lastBlock: lastBlock_1.lastBlock,
|
|
14
|
+
lastBlock: () => (0, lastBlock_1.lastBlock)(),
|
|
19
15
|
getBlockInfo: (0, index_1.notSupported)('getBlockInfo'),
|
|
20
16
|
getBlock: (0, index_1.notSupported)('getBlock'),
|
|
21
17
|
call: (0, index_1.notSupported)('call'),
|
|
22
18
|
getValidators: (0, index_1.notSupported)('getValidators'),
|
|
23
|
-
getBalance: getBalance_1.getBalance,
|
|
24
|
-
listOperations: listOperations_1.listOperations,
|
|
19
|
+
getBalance: (ctx, address) => (0, getBalance_1.getBalance)(ctx, address),
|
|
20
|
+
listOperations: (ctx, address, options) => (0, listOperations_1.listOperations)(ctx, address, options),
|
|
25
21
|
getStakes: (0, index_1.notSupported)('getStakes'),
|
|
26
22
|
getRewards: (0, index_1.notSupported)('getRewards'),
|
|
27
23
|
craftTransaction: (0, index_1.notSupported)('craftTransaction'),
|
|
@@ -31,7 +27,7 @@ function createApi(config) {
|
|
|
31
27
|
broadcast: (0, index_1.notSupported)('broadcast'),
|
|
32
28
|
validateIntent: (0, index_1.notSupported)('validateIntent'),
|
|
33
29
|
getNextSequence: (0, index_1.notSupported)('getNextSequence'),
|
|
34
|
-
validateAddress: validateAddress_1.validateAddress,
|
|
30
|
+
validateAddress: (_ctx, address, parameters) => (0, validateAddress_1.validateAddress)(address, parameters),
|
|
35
31
|
craftTransactionData: (0, index_1.notSupported)('craftTransactionData'),
|
|
36
32
|
};
|
|
37
33
|
}
|
package/lib/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAetC,8BAyBC;AAhCD,qEAAwE;AACxE,6CAAyC;AACzC,2CAAuC;AACvC,qDAAiD;AACjD,uDAAmD;AAEnD,kGAAkG;AAClG,SAAgB,SAAS;IAKvB,OAAO;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,IAAA,qBAAS,GAAE;QAC5B,YAAY,EAAE,IAAA,oBAAY,EAAC,cAAc,CAAC;QAC1C,QAAQ,EAAE,IAAA,oBAAY,EAAC,UAAU,CAAC;QAClC,IAAI,EAAE,IAAA,oBAAY,EAAC,MAAM,CAAC;QAC1B,aAAa,EAAE,IAAA,oBAAY,EAAC,eAAe,CAAC;QAC5C,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,IAAA,uBAAU,EAAC,GAAG,EAAE,OAAO,CAAC;QACtD,cAAc,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAA,+BAAc,EAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC;QAChF,SAAS,EAAE,IAAA,oBAAY,EAAC,WAAW,CAAC;QACpC,UAAU,EAAE,IAAA,oBAAY,EAAC,YAAY,CAAC;QACtC,gBAAgB,EAAE,IAAA,oBAAY,EAAC,kBAAkB,CAAC;QAClD,mBAAmB,EAAE,IAAA,oBAAY,EAAC,qBAAqB,CAAC;QACxD,YAAY,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,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,IAAA,iCAAe,EAAC,OAAO,EAAE,UAAU,CAAC;QACpF,oBAAoB,EAAE,IAAA,oBAAY,EAAC,sBAAsB,CAAC;KAC3D,CAAA;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HypercoreContext } from '../config';
|
|
1
2
|
import type { ListOperationsOptions, Operation, Page } from '@ledgerhq/coin-module-framework/api/types';
|
|
2
|
-
export declare function listOperations(address: string, { cursor, limit }: ListOperationsOptions): Promise<Page<Operation>>;
|
|
3
|
+
export declare function listOperations(context: HypercoreContext, address: string, { cursor, limit }: ListOperationsOptions): Promise<Page<Operation>>;
|
|
3
4
|
//# sourceMappingURL=listOperations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAEjD,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AA6ClD,wBAAsB,cAAc,CAClC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EACf,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACvC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAe1B"}
|
|
@@ -42,10 +42,11 @@ function parseCursor(cursor) {
|
|
|
42
42
|
}
|
|
43
43
|
return offset;
|
|
44
44
|
}
|
|
45
|
-
async function listOperations(address, { cursor, limit }) {
|
|
45
|
+
async function listOperations(context, address, { cursor, limit }) {
|
|
46
|
+
const config = await context.config();
|
|
46
47
|
const offset = parseCursor(cursor);
|
|
47
48
|
const pageLimit = limit ?? DEFAULT_LIMIT;
|
|
48
|
-
const page = await (0, yield_1.fetchActions)(address, offset, pageLimit);
|
|
49
|
+
const page = await (0, yield_1.fetchActions)(config, address, offset, pageLimit);
|
|
49
50
|
const items = page.items.filter(isSettledTransfer).map((action) => toOperation(address, action));
|
|
50
51
|
// Advance by raw items consumed, not the filtered count, so no action is skipped.
|
|
51
52
|
// The cursor is offset-based (volatile if new actions appear between calls); the proxy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;
|
|
1
|
+
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"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"}
|
package/lib/config.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { CoinConfig, CurrencyConfig } from '@ledgerhq/coin-module-framework/config';
|
|
1
|
+
import type { CoinConfig, Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config';
|
|
2
2
|
export type HypercoreConfig = {
|
|
3
3
|
node: string;
|
|
4
4
|
};
|
|
5
5
|
export type HypercoreCoinConfig = CurrencyConfig & HypercoreConfig;
|
|
6
|
+
/** The {@link Context} threaded through the coin-hypercore low layers (ADR-019). */
|
|
7
|
+
export type HypercoreContext = Context<HypercoreCoinConfig>;
|
|
6
8
|
declare const coinConfig: {
|
|
7
9
|
setCoinConfig: (config: CoinConfig<HypercoreCoinConfig>) => void;
|
|
8
10
|
getCoinConfig: (currencyId?: string) => HypercoreCoinConfig;
|
package/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAGjG,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,eAAe,CAAA;AAElE,oFAAoF;AACpF,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAE3D,QAAA,MAAM,UAAU,EAAE;IAChB,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IAChE,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,mBAAmB,CAAA;CACnB,CAAA;AAE1C,eAAe,UAAU,CAAA"}
|
package/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;AAGtC,oFAAoE;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;AAGtC,oFAAoE;AAWpE,MAAM,UAAU,GAGZ,IAAA,gBAAe,GAAuB,CAAA;AAE1C,kBAAe,UAAU,CAAA"}
|
package/lib/network/yield.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HypercoreCoinConfig } from '../config';
|
|
1
2
|
export declare const USDC_DECIMALS = 6;
|
|
2
3
|
export declare const FUND_ACTION = "fund";
|
|
3
4
|
export declare const WITHDRAW_ACTION = "withdraw";
|
|
@@ -17,7 +18,7 @@ export type YieldBalanceDto = {
|
|
|
17
18
|
availableBalance: number;
|
|
18
19
|
unrealizedPnl: number;
|
|
19
20
|
};
|
|
20
|
-
export declare function fetchBalance(address: string): Promise<YieldBalanceDto>;
|
|
21
|
+
export declare function fetchBalance(config: HypercoreCoinConfig, address: string): Promise<YieldBalanceDto>;
|
|
21
22
|
export type ActionDto = {
|
|
22
23
|
id: string;
|
|
23
24
|
action: string;
|
|
@@ -34,5 +35,5 @@ export type ActionsPage = {
|
|
|
34
35
|
limit: number;
|
|
35
36
|
items: ActionDto[];
|
|
36
37
|
};
|
|
37
|
-
export declare function fetchActions(address: string, offset: number, limit: number): Promise<ActionsPage>;
|
|
38
|
+
export declare function fetchActions(config: HypercoreCoinConfig, address: string, offset: number, limit: number): Promise<ActionsPage>;
|
|
38
39
|
//# sourceMappingURL=yield.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yield.d.ts","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"yield.d.ts","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAMpD,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,CAChC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC,CAO1B;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,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,WAAW,CAAC,CAOtB"}
|
package/lib/network/yield.js
CHANGED
|
@@ -9,26 +9,24 @@ exports.WITHDRAW_ACTION = exports.FUND_ACTION = exports.USDC_DECIMALS = void 0;
|
|
|
9
9
|
exports.fetchBalance = fetchBalance;
|
|
10
10
|
exports.fetchActions = fetchActions;
|
|
11
11
|
const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
|
|
12
|
-
const config_1 = __importDefault(require("../config"));
|
|
13
12
|
const PROVIDER_ID = 'hyperliquid';
|
|
14
|
-
const getBaseUrl = () => config_1.default.getCoinConfig().node;
|
|
15
13
|
// The collateral is USDC and the proxy omits its decimals.
|
|
16
14
|
exports.USDC_DECIMALS = 6;
|
|
17
15
|
// A deposit is the `fund` action, a withdrawal the `withdraw` action.
|
|
18
16
|
exports.FUND_ACTION = 'fund';
|
|
19
17
|
exports.WITHDRAW_ACTION = 'withdraw';
|
|
20
|
-
async function fetchBalance(address) {
|
|
18
|
+
async function fetchBalance(config, address) {
|
|
21
19
|
const { data } = await (0, live_network_1.default)({
|
|
22
20
|
method: 'POST',
|
|
23
|
-
url: `${
|
|
21
|
+
url: `${config.node}/v1/balances`,
|
|
24
22
|
data: { providerId: PROVIDER_ID, address },
|
|
25
23
|
});
|
|
26
24
|
return data;
|
|
27
25
|
}
|
|
28
|
-
async function fetchActions(address, offset, limit) {
|
|
26
|
+
async function fetchActions(config, address, offset, limit) {
|
|
29
27
|
const { data } = await (0, live_network_1.default)({
|
|
30
28
|
method: 'GET',
|
|
31
|
-
url: `${
|
|
29
|
+
url: `${config.node}/v1/actions`,
|
|
32
30
|
params: { address, offset, limit, providerId: PROVIDER_ID },
|
|
33
31
|
});
|
|
34
32
|
return data;
|
package/lib/network/yield.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yield.js","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;
|
|
1
|
+
{"version":3,"file":"yield.js","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;AAgCtC,oCAUC;AAmBD,oCAYC;AAtED,0EAA4C;AAE5C,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,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,CAChC,MAA2B,EAC3B,OAAe;IAEf,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,sBAAO,EAAkB;QAC9C,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,cAAc;QACjC,IAAI,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE;KAC3C,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAmBM,KAAK,UAAU,YAAY,CAChC,MAA2B,EAC3B,OAAe,EACf,MAAc,EACd,KAAa;IAEb,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,sBAAO,EAAc;QAC1C,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,aAAa;QAChC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE;KAC5D,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HypercoreContext } from '../config';
|
|
1
2
|
import type { Balance } from '@ledgerhq/coin-module-framework/api/types';
|
|
2
|
-
export declare function getBalance(address: string): Promise<Balance[]>;
|
|
3
|
+
export declare function getBalance(context: HypercoreContext, address: string): Promise<Balance[]>;
|
|
3
4
|
//# sourceMappingURL=getBalance.d.ts.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAA;AAMxE,wBAAsB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAY/F"}
|
package/lib-es/api/getBalance.js
CHANGED
|
@@ -4,8 +4,9 @@ import { USDC_DECIMALS, fetchBalance } from '../network/yield';
|
|
|
4
4
|
import { scaleToBigInt } from '../utils';
|
|
5
5
|
// The proxy only exposes the USDC collateral, surfaced as the account's native balance:
|
|
6
6
|
// `value` is the total account value, `locked` the margin used by open positions.
|
|
7
|
-
export async function getBalance(address) {
|
|
8
|
-
const
|
|
7
|
+
export async function getBalance(context, address) {
|
|
8
|
+
const config = await context.config();
|
|
9
|
+
const { collateral, accountValue, usedMargin } = await fetchBalance(config, address);
|
|
9
10
|
const magnitude = collateral.decimals ?? USDC_DECIMALS;
|
|
10
11
|
return [
|
|
11
12
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;
|
|
1
|
+
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/api/getBalance.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAItC,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,OAAyB,EAAE,OAAe;IACzE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAA;IACrC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpF,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"}
|
package/lib-es/api/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CoinModuleApi } from '@ledgerhq/coin-module-framework/api/index';
|
|
3
|
-
export declare function createApi(
|
|
1
|
+
import type { HypercoreCoinConfig } from '../config';
|
|
2
|
+
import type { CoinModuleApi, MemoNotSupported, TxDataNotSupported } from '@ledgerhq/coin-module-framework/api/index';
|
|
3
|
+
export declare function createApi(): CoinModuleApi<HypercoreCoinConfig, MemoNotSupported, TxDataNotSupported>;
|
|
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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2CAA2C,CAAA;AAQlD,wBAAgB,SAAS,IAAI,aAAa,CACxC,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,CACnB,CAqBA"}
|
package/lib-es/api/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { notSupported } from '@ledgerhq/coin-module-framework/api/index';
|
|
4
|
-
import coinConfig from '../config';
|
|
5
4
|
import { getBalance } from './getBalance';
|
|
6
5
|
import { lastBlock } from './lastBlock';
|
|
7
6
|
import { listOperations } from './listOperations';
|
|
8
7
|
import { validateAddress } from './validateAddress';
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// The caller builds the {@link Context} (config + logger) and passes it to each method (ADR-019).
|
|
9
|
+
export function createApi() {
|
|
11
10
|
return {
|
|
12
|
-
lastBlock,
|
|
11
|
+
lastBlock: () => lastBlock(),
|
|
13
12
|
getBlockInfo: notSupported('getBlockInfo'),
|
|
14
13
|
getBlock: notSupported('getBlock'),
|
|
15
14
|
call: notSupported('call'),
|
|
16
15
|
getValidators: notSupported('getValidators'),
|
|
17
|
-
getBalance,
|
|
18
|
-
listOperations,
|
|
16
|
+
getBalance: (ctx, address) => getBalance(ctx, address),
|
|
17
|
+
listOperations: (ctx, address, options) => listOperations(ctx, address, options),
|
|
19
18
|
getStakes: notSupported('getStakes'),
|
|
20
19
|
getRewards: notSupported('getRewards'),
|
|
21
20
|
craftTransaction: notSupported('craftTransaction'),
|
|
@@ -25,7 +24,7 @@ export function createApi(config) {
|
|
|
25
24
|
broadcast: notSupported('broadcast'),
|
|
26
25
|
validateIntent: notSupported('validateIntent'),
|
|
27
26
|
getNextSequence: notSupported('getNextSequence'),
|
|
28
|
-
validateAddress,
|
|
27
|
+
validateAddress: (_ctx, address, parameters) => validateAddress(address, parameters),
|
|
29
28
|
craftTransactionData: notSupported('craftTransactionData'),
|
|
30
29
|
};
|
|
31
30
|
}
|
package/lib-es/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAQtC,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,kGAAkG;AAClG,MAAM,UAAU,SAAS;IAKvB,OAAO;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE;QAC5B,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,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;QACtD,cAAc,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC;QAChF,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,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC;QACpF,oBAAoB,EAAE,YAAY,CAAC,sBAAsB,CAAC;KAC3D,CAAA;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HypercoreContext } from '../config';
|
|
1
2
|
import type { ListOperationsOptions, Operation, Page } from '@ledgerhq/coin-module-framework/api/types';
|
|
2
|
-
export declare function listOperations(address: string, { cursor, limit }: ListOperationsOptions): Promise<Page<Operation>>;
|
|
3
|
+
export declare function listOperations(context: HypercoreContext, address: string, { cursor, limit }: ListOperationsOptions): Promise<Page<Operation>>;
|
|
3
4
|
//# sourceMappingURL=listOperations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAEjD,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AA6ClD,wBAAsB,cAAc,CAClC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EACf,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACvC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAe1B"}
|
|
@@ -39,10 +39,11 @@ function parseCursor(cursor) {
|
|
|
39
39
|
}
|
|
40
40
|
return offset;
|
|
41
41
|
}
|
|
42
|
-
export async function listOperations(address, { cursor, limit }) {
|
|
42
|
+
export async function listOperations(context, address, { cursor, limit }) {
|
|
43
|
+
const config = await context.config();
|
|
43
44
|
const offset = parseCursor(cursor);
|
|
44
45
|
const pageLimit = limit ?? DEFAULT_LIMIT;
|
|
45
|
-
const page = await fetchActions(address, offset, pageLimit);
|
|
46
|
+
const page = await fetchActions(config, address, offset, pageLimit);
|
|
46
47
|
const items = page.items.filter(isSettledTransfer).map((action) => toOperation(address, action));
|
|
47
48
|
// Advance by raw items consumed, not the filtered count, so no action is skipped.
|
|
48
49
|
// The cursor is offset-based (volatile if new actions appear between calls); the proxy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;
|
|
1
|
+
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"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"}
|
package/lib-es/config.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { CoinConfig, CurrencyConfig } from '@ledgerhq/coin-module-framework/config';
|
|
1
|
+
import type { CoinConfig, Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config';
|
|
2
2
|
export type HypercoreConfig = {
|
|
3
3
|
node: string;
|
|
4
4
|
};
|
|
5
5
|
export type HypercoreCoinConfig = CurrencyConfig & HypercoreConfig;
|
|
6
|
+
/** The {@link Context} threaded through the coin-hypercore low layers (ADR-019). */
|
|
7
|
+
export type HypercoreContext = Context<HypercoreCoinConfig>;
|
|
6
8
|
declare const coinConfig: {
|
|
7
9
|
setCoinConfig: (config: CoinConfig<HypercoreCoinConfig>) => void;
|
|
8
10
|
getCoinConfig: (currencyId?: string) => HypercoreCoinConfig;
|
package/lib-es/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAGjG,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,eAAe,CAAA;AAElE,oFAAoF;AACpF,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAE3D,QAAA,MAAM,UAAU,EAAE;IAChB,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IAChE,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,mBAAmB,CAAA;CACnB,CAAA;AAE1C,eAAe,UAAU,CAAA"}
|
package/lib-es/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,eAAe,MAAM,wCAAwC,CAAA;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,eAAe,MAAM,wCAAwC,CAAA;AAWpE,MAAM,UAAU,GAGZ,eAAe,EAAuB,CAAA;AAE1C,eAAe,UAAU,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HypercoreCoinConfig } from '../config';
|
|
1
2
|
export declare const USDC_DECIMALS = 6;
|
|
2
3
|
export declare const FUND_ACTION = "fund";
|
|
3
4
|
export declare const WITHDRAW_ACTION = "withdraw";
|
|
@@ -17,7 +18,7 @@ export type YieldBalanceDto = {
|
|
|
17
18
|
availableBalance: number;
|
|
18
19
|
unrealizedPnl: number;
|
|
19
20
|
};
|
|
20
|
-
export declare function fetchBalance(address: string): Promise<YieldBalanceDto>;
|
|
21
|
+
export declare function fetchBalance(config: HypercoreCoinConfig, address: string): Promise<YieldBalanceDto>;
|
|
21
22
|
export type ActionDto = {
|
|
22
23
|
id: string;
|
|
23
24
|
action: string;
|
|
@@ -34,5 +35,5 @@ export type ActionsPage = {
|
|
|
34
35
|
limit: number;
|
|
35
36
|
items: ActionDto[];
|
|
36
37
|
};
|
|
37
|
-
export declare function fetchActions(address: string, offset: number, limit: number): Promise<ActionsPage>;
|
|
38
|
+
export declare function fetchActions(config: HypercoreCoinConfig, address: string, offset: number, limit: number): Promise<ActionsPage>;
|
|
38
39
|
//# sourceMappingURL=yield.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yield.d.ts","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"yield.d.ts","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAMpD,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,CAChC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC,CAO1B;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,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,WAAW,CAAC,CAOtB"}
|
package/lib-es/network/yield.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import network from '@ledgerhq/live-network';
|
|
4
|
-
import coinConfig from '../config';
|
|
5
4
|
const PROVIDER_ID = 'hyperliquid';
|
|
6
|
-
const getBaseUrl = () => coinConfig.getCoinConfig().node;
|
|
7
5
|
// The collateral is USDC and the proxy omits its decimals.
|
|
8
6
|
export const USDC_DECIMALS = 6;
|
|
9
7
|
// A deposit is the `fund` action, a withdrawal the `withdraw` action.
|
|
10
8
|
export const FUND_ACTION = 'fund';
|
|
11
9
|
export const WITHDRAW_ACTION = 'withdraw';
|
|
12
|
-
export async function fetchBalance(address) {
|
|
10
|
+
export async function fetchBalance(config, address) {
|
|
13
11
|
const { data } = await network({
|
|
14
12
|
method: 'POST',
|
|
15
|
-
url: `${
|
|
13
|
+
url: `${config.node}/v1/balances`,
|
|
16
14
|
data: { providerId: PROVIDER_ID, address },
|
|
17
15
|
});
|
|
18
16
|
return data;
|
|
19
17
|
}
|
|
20
|
-
export async function fetchActions(address, offset, limit) {
|
|
18
|
+
export async function fetchActions(config, address, offset, limit) {
|
|
21
19
|
const { data } = await network({
|
|
22
20
|
method: 'GET',
|
|
23
|
-
url: `${
|
|
21
|
+
url: `${config.node}/v1/actions`,
|
|
24
22
|
params: { address, offset, limit, providerId: PROVIDER_ID },
|
|
25
23
|
});
|
|
26
24
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yield.js","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;
|
|
1
|
+
{"version":3,"file":"yield.js","sourceRoot":"","sources":["../../src/network/yield.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,OAAO,MAAM,wBAAwB,CAAA;AAE5C,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,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,CAChC,MAA2B,EAC3B,OAAe;IAEf,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAkB;QAC9C,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,cAAc;QACjC,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,MAA2B,EAC3B,OAAe,EACf,MAAc,EACd,KAAa;IAEb,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAc;QAC1C,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,aAAa;QAChC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE;KAC5D,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-hypercore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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": "^
|
|
68
|
+
"@ledgerhq/coin-module-framework": "^6.0.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@swc/core": "1.15.11",
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreContext } from '../config'
|
|
4
5
|
import network from '@ledgerhq/live-network'
|
|
5
|
-
import coinConfig from '../config'
|
|
6
6
|
import { getBalance } from './getBalance'
|
|
7
7
|
|
|
8
8
|
jest.mock('@ledgerhq/live-network')
|
|
9
9
|
|
|
10
10
|
const mockNetwork = jest.mocked(network)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const context: HypercoreContext = {
|
|
13
|
+
config: async () => ({
|
|
14
14
|
node: 'https://perps.live.ledger.com/proxy/perps',
|
|
15
15
|
status: { type: 'active' },
|
|
16
|
-
})
|
|
17
|
-
|
|
16
|
+
}),
|
|
17
|
+
logger: jest.fn(),
|
|
18
|
+
}
|
|
18
19
|
|
|
19
20
|
afterEach(() => {
|
|
20
21
|
mockNetwork.mockClear()
|
|
@@ -34,7 +35,7 @@ describe('getBalance', () => {
|
|
|
34
35
|
},
|
|
35
36
|
})
|
|
36
37
|
|
|
37
|
-
const balances = await getBalance('0xabc')
|
|
38
|
+
const balances = await getBalance(context, '0xabc')
|
|
38
39
|
|
|
39
40
|
expect(balances).toEqual([
|
|
40
41
|
{
|
|
@@ -58,7 +59,7 @@ describe('getBalance', () => {
|
|
|
58
59
|
},
|
|
59
60
|
})
|
|
60
61
|
|
|
61
|
-
const balances = await getBalance('0xabc')
|
|
62
|
+
const balances = await getBalance(context, '0xabc')
|
|
62
63
|
|
|
63
64
|
expect(balances[0].value).toBe(0n)
|
|
64
65
|
expect(balances[0].locked).toBe(0n)
|
package/src/api/getBalance.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreContext } from '../config'
|
|
4
5
|
import type { Balance } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
6
|
import { USDC_DECIMALS, fetchBalance } from '../network/yield'
|
|
6
7
|
import { scaleToBigInt } from '../utils'
|
|
7
8
|
|
|
8
9
|
// The proxy only exposes the USDC collateral, surfaced as the account's native balance:
|
|
9
10
|
// `value` is the total account value, `locked` the margin used by open positions.
|
|
10
|
-
export async function getBalance(address: string): Promise<Balance[]> {
|
|
11
|
-
const
|
|
11
|
+
export async function getBalance(context: HypercoreContext, address: string): Promise<Balance[]> {
|
|
12
|
+
const config = await context.config()
|
|
13
|
+
const { collateral, accountValue, usedMargin } = await fetchBalance(config, address)
|
|
12
14
|
const magnitude = collateral.decimals ?? USDC_DECIMALS
|
|
13
15
|
|
|
14
16
|
return [
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreContext } from '../config'
|
|
4
5
|
import { createApi } from '.'
|
|
5
6
|
|
|
6
7
|
const NODE = 'https://perps.live.ledger.com/proxy/perps'
|
|
@@ -8,7 +9,7 @@ const NODE = 'https://perps.live.ledger.com/proxy/perps'
|
|
|
8
9
|
const ADDRESS = '0x90D5b3f3FaA3cd61fBd78bF1CE3DdB2100F4BFb2'
|
|
9
10
|
|
|
10
11
|
describe('Hypercore Api (Alpaca stub)', () => {
|
|
11
|
-
const api = createApi(
|
|
12
|
+
const api = createApi()
|
|
12
13
|
|
|
13
14
|
it.each<keyof typeof api>([
|
|
14
15
|
'getBlockInfo',
|
|
@@ -30,11 +31,15 @@ describe('Hypercore Api (Alpaca stub)', () => {
|
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
describe('Hypercore Api (Alpaca)', () => {
|
|
33
|
-
const api = createApi(
|
|
34
|
+
const api = createApi()
|
|
35
|
+
const context: HypercoreContext = {
|
|
36
|
+
config: async () => ({ node: NODE, status: { type: 'active' } }),
|
|
37
|
+
logger: () => undefined,
|
|
38
|
+
}
|
|
34
39
|
|
|
35
40
|
describe('getBalance', () => {
|
|
36
41
|
it('returns the USDC-denominated account balance', async () => {
|
|
37
|
-
const balances = await api.getBalance(ADDRESS)
|
|
42
|
+
const balances = await api.getBalance(context, ADDRESS)
|
|
38
43
|
|
|
39
44
|
expect(balances).toHaveLength(1)
|
|
40
45
|
const [balance] = balances
|
|
@@ -48,11 +53,11 @@ describe('Hypercore Api (Alpaca)', () => {
|
|
|
48
53
|
describe('listOperations', () => {
|
|
49
54
|
it('returns settled deposit/withdraw operations across all pages', async () => {
|
|
50
55
|
// Small limit to force several pages and exercise cursor chaining end-to-end.
|
|
51
|
-
const first = await api.listOperations(ADDRESS, { minHeight: 0, limit: 20 })
|
|
56
|
+
const first = await api.listOperations(context, ADDRESS, { minHeight: 0, limit: 20 })
|
|
52
57
|
const all = [...first.items]
|
|
53
58
|
let cursor = first.next
|
|
54
59
|
while (cursor !== undefined && all.length < 10_000) {
|
|
55
|
-
const page = await api.listOperations(ADDRESS, { minHeight: 0, cursor, limit: 20 })
|
|
60
|
+
const page = await api.listOperations(context, ADDRESS, { minHeight: 0, cursor, limit: 20 })
|
|
56
61
|
all.push(...page.items)
|
|
57
62
|
cursor = page.next
|
|
58
63
|
}
|
|
@@ -72,7 +77,7 @@ describe('Hypercore Api (Alpaca)', () => {
|
|
|
72
77
|
})
|
|
73
78
|
|
|
74
79
|
it('ignores minHeight and order (returns results, no throw)', async () => {
|
|
75
|
-
const { items } = await api.listOperations(ADDRESS, { minHeight: 1, order: 'asc' })
|
|
80
|
+
const { items } = await api.listOperations(context, ADDRESS, { minHeight: 1, order: 'asc' })
|
|
76
81
|
expect(items.length).toBeGreaterThan(0)
|
|
77
82
|
})
|
|
78
83
|
})
|
package/src/api/index.test.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { createApi } from '.'
|
|
|
5
5
|
|
|
6
6
|
describe('createApi', () => {
|
|
7
7
|
it('returns all API methods', () => {
|
|
8
|
-
expect(createApi(
|
|
8
|
+
expect(createApi()).toEqual({
|
|
9
9
|
broadcast: expect.any(Function),
|
|
10
10
|
call: expect.any(Function),
|
|
11
11
|
combine: expect.any(Function),
|
package/src/api/index.ts
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { HypercoreCoinConfig } from '../config'
|
|
5
|
+
import type {
|
|
6
|
+
CoinModuleApi,
|
|
7
|
+
MemoNotSupported,
|
|
8
|
+
TxDataNotSupported,
|
|
9
|
+
} from '@ledgerhq/coin-module-framework/api/index'
|
|
6
10
|
import { notSupported } from '@ledgerhq/coin-module-framework/api/index'
|
|
7
|
-
import coinConfig from '../config'
|
|
8
11
|
import { getBalance } from './getBalance'
|
|
9
12
|
import { lastBlock } from './lastBlock'
|
|
10
13
|
import { listOperations } from './listOperations'
|
|
11
14
|
import { validateAddress } from './validateAddress'
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
// The caller builds the {@link Context} (config + logger) and passes it to each method (ADR-019).
|
|
17
|
+
export function createApi(): CoinModuleApi<
|
|
18
|
+
HypercoreCoinConfig,
|
|
19
|
+
MemoNotSupported,
|
|
20
|
+
TxDataNotSupported
|
|
21
|
+
> {
|
|
16
22
|
return {
|
|
17
|
-
lastBlock,
|
|
23
|
+
lastBlock: () => lastBlock(),
|
|
18
24
|
getBlockInfo: notSupported('getBlockInfo'),
|
|
19
25
|
getBlock: notSupported('getBlock'),
|
|
20
26
|
call: notSupported('call'),
|
|
21
27
|
getValidators: notSupported('getValidators'),
|
|
22
|
-
getBalance,
|
|
23
|
-
listOperations,
|
|
28
|
+
getBalance: (ctx, address) => getBalance(ctx, address),
|
|
29
|
+
listOperations: (ctx, address, options) => listOperations(ctx, address, options),
|
|
24
30
|
getStakes: notSupported('getStakes'),
|
|
25
31
|
getRewards: notSupported('getRewards'),
|
|
26
32
|
craftTransaction: notSupported('craftTransaction'),
|
|
@@ -30,7 +36,7 @@ export function createApi(config: HypercoreConfig): CoinModuleApi {
|
|
|
30
36
|
broadcast: notSupported('broadcast'),
|
|
31
37
|
validateIntent: notSupported('validateIntent'),
|
|
32
38
|
getNextSequence: notSupported('getNextSequence'),
|
|
33
|
-
validateAddress,
|
|
39
|
+
validateAddress: (_ctx, address, parameters) => validateAddress(address, parameters),
|
|
34
40
|
craftTransactionData: notSupported('craftTransactionData'),
|
|
35
41
|
}
|
|
36
42
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreContext } from '../config'
|
|
4
5
|
import network from '@ledgerhq/live-network'
|
|
5
|
-
import coinConfig from '../config'
|
|
6
6
|
import { listOperations } from './listOperations'
|
|
7
7
|
|
|
8
8
|
jest.mock('@ledgerhq/live-network')
|
|
@@ -11,12 +11,13 @@ const mockNetwork = jest.mocked(network)
|
|
|
11
11
|
|
|
12
12
|
const ADDRESS = '0xabc'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const context: HypercoreContext = {
|
|
15
|
+
config: async () => ({
|
|
16
16
|
node: 'https://perps.live.ledger.com/proxy/perps',
|
|
17
17
|
status: { type: 'active' },
|
|
18
|
-
})
|
|
19
|
-
|
|
18
|
+
}),
|
|
19
|
+
logger: jest.fn(),
|
|
20
|
+
}
|
|
20
21
|
|
|
21
22
|
afterEach(() => {
|
|
22
23
|
mockNetwork.mockClear()
|
|
@@ -50,7 +51,7 @@ describe('listOperations', () => {
|
|
|
50
51
|
},
|
|
51
52
|
})
|
|
52
53
|
|
|
53
|
-
const { items, next } = await listOperations(ADDRESS, { minHeight: 0 })
|
|
54
|
+
const { items, next } = await listOperations(context, ADDRESS, { minHeight: 0 })
|
|
54
55
|
|
|
55
56
|
expect(items).toHaveLength(2)
|
|
56
57
|
expect(items[0]).toMatchObject({
|
|
@@ -80,7 +81,7 @@ describe('listOperations', () => {
|
|
|
80
81
|
},
|
|
81
82
|
})
|
|
82
83
|
|
|
83
|
-
const { items } = await listOperations(ADDRESS, { minHeight: 0 })
|
|
84
|
+
const { items } = await listOperations(context, ADDRESS, { minHeight: 0 })
|
|
84
85
|
|
|
85
86
|
expect(items).toHaveLength(1)
|
|
86
87
|
expect(items[0].id).toBe(`${ADDRESS}-settled`)
|
|
@@ -97,7 +98,7 @@ describe('listOperations', () => {
|
|
|
97
98
|
},
|
|
98
99
|
})
|
|
99
100
|
|
|
100
|
-
const { items } = await listOperations(ADDRESS, { minHeight: 0 })
|
|
101
|
+
const { items } = await listOperations(context, ADDRESS, { minHeight: 0 })
|
|
101
102
|
|
|
102
103
|
expect(items[0].tx.failed).toBe(true)
|
|
103
104
|
})
|
|
@@ -113,7 +114,7 @@ describe('listOperations', () => {
|
|
|
113
114
|
},
|
|
114
115
|
})
|
|
115
116
|
|
|
116
|
-
const { items, next } = await listOperations(ADDRESS, { minHeight: 0, limit: 2 })
|
|
117
|
+
const { items, next } = await listOperations(context, ADDRESS, { minHeight: 0, limit: 2 })
|
|
117
118
|
|
|
118
119
|
// Only one fund/withdraw kept, but the cursor advances by the two raw items consumed.
|
|
119
120
|
expect(items).toHaveLength(1)
|
|
@@ -131,7 +132,7 @@ describe('listOperations', () => {
|
|
|
131
132
|
data: { total: 10, offset: 2, limit: 2, items: [] },
|
|
132
133
|
})
|
|
133
134
|
|
|
134
|
-
await listOperations(ADDRESS, { minHeight: 0, cursor: '2', limit: 2 })
|
|
135
|
+
await listOperations(context, ADDRESS, { minHeight: 0, cursor: '2', limit: 2 })
|
|
135
136
|
|
|
136
137
|
expect(mockNetwork).toHaveBeenCalledWith(
|
|
137
138
|
expect.objectContaining({
|
|
@@ -146,16 +147,16 @@ describe('listOperations', () => {
|
|
|
146
147
|
data: { total: 1, offset: 0, limit: 100, items: [action({ id: 'dep' })] },
|
|
147
148
|
})
|
|
148
149
|
|
|
149
|
-
const { items } = await listOperations(ADDRESS, { minHeight: 5, order: 'asc' })
|
|
150
|
+
const { items } = await listOperations(context, ADDRESS, { minHeight: 5, order: 'asc' })
|
|
150
151
|
|
|
151
152
|
expect(items).toHaveLength(1)
|
|
152
153
|
expect(mockNetwork).toHaveBeenCalled()
|
|
153
154
|
})
|
|
154
155
|
|
|
155
156
|
it('rejects an invalid cursor', async () => {
|
|
156
|
-
await expect(
|
|
157
|
-
|
|
158
|
-
)
|
|
157
|
+
await expect(
|
|
158
|
+
listOperations(context, ADDRESS, { minHeight: 0, cursor: 'not-a-number' })
|
|
159
|
+
).rejects.toThrow('invalid cursor')
|
|
159
160
|
expect(mockNetwork).not.toHaveBeenCalled()
|
|
160
161
|
})
|
|
161
162
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreContext } from '../config'
|
|
4
5
|
import type { ActionDto } from '../network/yield'
|
|
5
6
|
import type {
|
|
6
7
|
ListOperationsOptions,
|
|
@@ -52,12 +53,14 @@ function parseCursor(cursor: string | undefined): number {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export async function listOperations(
|
|
56
|
+
context: HypercoreContext,
|
|
55
57
|
address: string,
|
|
56
58
|
{ cursor, limit }: ListOperationsOptions
|
|
57
59
|
): Promise<Page<Operation>> {
|
|
60
|
+
const config = await context.config()
|
|
58
61
|
const offset = parseCursor(cursor)
|
|
59
62
|
const pageLimit = limit ?? DEFAULT_LIMIT
|
|
60
|
-
const page = await fetchActions(address, offset, pageLimit)
|
|
63
|
+
const page = await fetchActions(config, address, offset, pageLimit)
|
|
61
64
|
|
|
62
65
|
const items = page.items.filter(isSettledTransfer).map((action) => toOperation(address, action))
|
|
63
66
|
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { CoinConfig, CurrencyConfig } from '@ledgerhq/coin-module-framework/config'
|
|
4
|
+
import type { CoinConfig, Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config'
|
|
5
5
|
import buildCoinConfig from '@ledgerhq/coin-module-framework/config'
|
|
6
6
|
|
|
7
7
|
export type HypercoreConfig = {
|
|
@@ -10,6 +10,9 @@ export type HypercoreConfig = {
|
|
|
10
10
|
|
|
11
11
|
export type HypercoreCoinConfig = CurrencyConfig & HypercoreConfig
|
|
12
12
|
|
|
13
|
+
/** The {@link Context} threaded through the coin-hypercore low layers (ADR-019). */
|
|
14
|
+
export type HypercoreContext = Context<HypercoreCoinConfig>
|
|
15
|
+
|
|
13
16
|
const coinConfig: {
|
|
14
17
|
setCoinConfig: (config: CoinConfig<HypercoreCoinConfig>) => void
|
|
15
18
|
getCoinConfig: (currencyId?: string) => HypercoreCoinConfig
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreCoinConfig } from '../config'
|
|
4
5
|
import network from '@ledgerhq/live-network'
|
|
5
|
-
import coinConfig from '../config'
|
|
6
6
|
import { fetchBalance, fetchActions } from './yield'
|
|
7
7
|
|
|
8
8
|
jest.mock('@ledgerhq/live-network')
|
|
9
9
|
|
|
10
10
|
const mockNetwork = jest.mocked(network)
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
12
|
+
const config: HypercoreCoinConfig = {
|
|
13
|
+
node: 'https://perps.live.ledger.com/proxy/perps',
|
|
14
|
+
status: { type: 'active' },
|
|
15
|
+
}
|
|
17
16
|
|
|
18
17
|
afterEach(() => {
|
|
19
18
|
mockNetwork.mockClear()
|
|
@@ -40,7 +39,7 @@ describe('fetchBalance', () => {
|
|
|
40
39
|
}
|
|
41
40
|
mockNetwork.mockResolvedValueOnce({ status: 200, data: dto })
|
|
42
41
|
|
|
43
|
-
const result = await fetchBalance('0xabc')
|
|
42
|
+
const result = await fetchBalance(config, '0xabc')
|
|
44
43
|
|
|
45
44
|
expect(mockNetwork).toHaveBeenCalledWith(
|
|
46
45
|
expect.objectContaining({
|
|
@@ -58,7 +57,7 @@ describe('fetchActions', () => {
|
|
|
58
57
|
const dto = { total: 0, offset: 10, limit: 100, items: [] }
|
|
59
58
|
mockNetwork.mockResolvedValueOnce({ status: 200, data: dto })
|
|
60
59
|
|
|
61
|
-
const result = await fetchActions('0xabc', 10, 100)
|
|
60
|
+
const result = await fetchActions(config, '0xabc', 10, 100)
|
|
62
61
|
|
|
63
62
|
expect(mockNetwork).toHaveBeenCalledWith(
|
|
64
63
|
expect.objectContaining({
|
package/src/network/yield.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { HypercoreCoinConfig } from '../config'
|
|
4
5
|
import network from '@ledgerhq/live-network'
|
|
5
|
-
import coinConfig from '../config'
|
|
6
6
|
|
|
7
7
|
const PROVIDER_ID = 'hyperliquid'
|
|
8
|
-
const getBaseUrl = () => coinConfig.getCoinConfig().node
|
|
9
8
|
|
|
10
9
|
// The collateral is USDC and the proxy omits its decimals.
|
|
11
10
|
export const USDC_DECIMALS = 6
|
|
@@ -32,10 +31,13 @@ export type YieldBalanceDto = {
|
|
|
32
31
|
unrealizedPnl: number
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
export async function fetchBalance(
|
|
34
|
+
export async function fetchBalance(
|
|
35
|
+
config: HypercoreCoinConfig,
|
|
36
|
+
address: string
|
|
37
|
+
): Promise<YieldBalanceDto> {
|
|
36
38
|
const { data } = await network<YieldBalanceDto>({
|
|
37
39
|
method: 'POST',
|
|
38
|
-
url: `${
|
|
40
|
+
url: `${config.node}/v1/balances`,
|
|
39
41
|
data: { providerId: PROVIDER_ID, address },
|
|
40
42
|
})
|
|
41
43
|
return data
|
|
@@ -59,13 +61,14 @@ export type ActionsPage = {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export async function fetchActions(
|
|
64
|
+
config: HypercoreCoinConfig,
|
|
62
65
|
address: string,
|
|
63
66
|
offset: number,
|
|
64
67
|
limit: number
|
|
65
68
|
): Promise<ActionsPage> {
|
|
66
69
|
const { data } = await network<ActionsPage>({
|
|
67
70
|
method: 'GET',
|
|
68
|
-
url: `${
|
|
71
|
+
url: `${config.node}/v1/actions`,
|
|
69
72
|
params: { address, offset, limit, providerId: PROVIDER_ID },
|
|
70
73
|
})
|
|
71
74
|
return data
|