@primuslabs/por-client-sdk 0.1.13 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/zktls_client.js +5 -3
- package/dist/client/zktls_client.js.map +1 -1
- package/dist/config_schema.d.ts +326 -14
- package/dist/config_schema.js +34 -4
- package/dist/config_schema.js.map +1 -1
- package/dist/datasource/aster.d.ts +10 -0
- package/dist/datasource/binance.d.ts +25 -0
- package/dist/datasource/bybit.d.ts +20 -0
- package/dist/datasource/bybit.js +31 -0
- package/dist/datasource/bybit.js.map +1 -0
- package/dist/datasource/datasource_manager.d.ts +12 -0
- package/dist/datasource/datasource_manager.js +24 -0
- package/dist/datasource/datasource_manager.js.map +1 -1
- package/dist/datasource/extended.d.ts +20 -0
- package/dist/datasource/extended.js +31 -0
- package/dist/datasource/extended.js.map +1 -0
- package/dist/datasource/grvt.d.ts +31 -0
- package/dist/datasource/grvt.js +112 -0
- package/dist/datasource/grvt.js.map +1 -0
- package/dist/datasource/helper.d.ts +3 -2
- package/dist/datasource/helper.js +17 -3
- package/dist/datasource/helper.js.map +1 -1
- package/dist/datasource/hyperliquid.d.ts +20 -0
- package/dist/datasource/hyperliquid.js +30 -0
- package/dist/datasource/hyperliquid.js.map +1 -0
- package/dist/datasource/lighter.d.ts +20 -0
- package/dist/datasource/lighter.js +43 -0
- package/dist/datasource/lighter.js.map +1 -0
- package/dist/datasource/pacifica.d.ts +20 -0
- package/dist/datasource/pacifica.js +29 -0
- package/dist/datasource/pacifica.js.map +1 -0
- package/dist/types.d.ts +3 -2
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,6 +13,11 @@ export declare class Binance extends BaseExchange<BinanceAccount, BinanceKind> {
|
|
|
13
13
|
apiSecret: string;
|
|
14
14
|
enabled: boolean;
|
|
15
15
|
description: string;
|
|
16
|
+
subAccountId: string;
|
|
17
|
+
vaultId: string;
|
|
18
|
+
address: string;
|
|
19
|
+
accountIndex: string;
|
|
20
|
+
poolIndex: string;
|
|
16
21
|
kind: ("spot" | "usds-futures" | "coin-futures" | "unified" | "margin")[];
|
|
17
22
|
}[];
|
|
18
23
|
get usdSFuturesAccounts(): {
|
|
@@ -20,6 +25,11 @@ export declare class Binance extends BaseExchange<BinanceAccount, BinanceKind> {
|
|
|
20
25
|
apiSecret: string;
|
|
21
26
|
enabled: boolean;
|
|
22
27
|
description: string;
|
|
28
|
+
subAccountId: string;
|
|
29
|
+
vaultId: string;
|
|
30
|
+
address: string;
|
|
31
|
+
accountIndex: string;
|
|
32
|
+
poolIndex: string;
|
|
23
33
|
kind: ("spot" | "usds-futures" | "coin-futures" | "unified" | "margin")[];
|
|
24
34
|
}[];
|
|
25
35
|
get coinFuturesAccounts(): {
|
|
@@ -27,6 +37,11 @@ export declare class Binance extends BaseExchange<BinanceAccount, BinanceKind> {
|
|
|
27
37
|
apiSecret: string;
|
|
28
38
|
enabled: boolean;
|
|
29
39
|
description: string;
|
|
40
|
+
subAccountId: string;
|
|
41
|
+
vaultId: string;
|
|
42
|
+
address: string;
|
|
43
|
+
accountIndex: string;
|
|
44
|
+
poolIndex: string;
|
|
30
45
|
kind: ("spot" | "usds-futures" | "coin-futures" | "unified" | "margin")[];
|
|
31
46
|
}[];
|
|
32
47
|
get unifiedAccounts(): {
|
|
@@ -34,6 +49,11 @@ export declare class Binance extends BaseExchange<BinanceAccount, BinanceKind> {
|
|
|
34
49
|
apiSecret: string;
|
|
35
50
|
enabled: boolean;
|
|
36
51
|
description: string;
|
|
52
|
+
subAccountId: string;
|
|
53
|
+
vaultId: string;
|
|
54
|
+
address: string;
|
|
55
|
+
accountIndex: string;
|
|
56
|
+
poolIndex: string;
|
|
37
57
|
kind: ("spot" | "usds-futures" | "coin-futures" | "unified" | "margin")[];
|
|
38
58
|
}[];
|
|
39
59
|
get marginAccounts(): {
|
|
@@ -41,6 +61,11 @@ export declare class Binance extends BaseExchange<BinanceAccount, BinanceKind> {
|
|
|
41
61
|
apiSecret: string;
|
|
42
62
|
enabled: boolean;
|
|
43
63
|
description: string;
|
|
64
|
+
subAccountId: string;
|
|
65
|
+
vaultId: string;
|
|
66
|
+
address: string;
|
|
67
|
+
accountIndex: string;
|
|
68
|
+
poolIndex: string;
|
|
44
69
|
kind: ("spot" | "usds-futures" | "coin-futures" | "unified" | "margin")[];
|
|
45
70
|
}[];
|
|
46
71
|
getSpotAccountInfoRequests(verifyType?: VERIFY_TYPE): RequestParamsOutput;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VERIFY_TYPE, RequestParamsOutput } from "../types.js";
|
|
2
|
+
import { BybitKind, BybitAccount, DatasourceConfig } from "../config_schema.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export declare class Bybit extends BaseExchange<BybitAccount, BybitKind> {
|
|
5
|
+
constructor(accounts?: DatasourceConfig["bybit"]);
|
|
6
|
+
get hasMain(): boolean;
|
|
7
|
+
get mainAccounts(): {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
apiSecret: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
subAccountId: string;
|
|
13
|
+
vaultId: string;
|
|
14
|
+
address: string;
|
|
15
|
+
accountIndex: string;
|
|
16
|
+
poolIndex: string;
|
|
17
|
+
kind: "main"[];
|
|
18
|
+
}[];
|
|
19
|
+
getV5AccountWalletBalance(verifyType?: VERIFY_TYPE): RequestParamsOutput;
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ccxt from "ccxt";
|
|
2
|
+
import { makeZkTlsRequestParams } from "./helper.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export class Bybit extends BaseExchange {
|
|
5
|
+
constructor(accounts) {
|
|
6
|
+
super(accounts);
|
|
7
|
+
}
|
|
8
|
+
get hasMain() { return this.mainAccounts.length > 0; }
|
|
9
|
+
get mainAccounts() { return this.getAccounts("main"); }
|
|
10
|
+
///
|
|
11
|
+
/// =======================================================================
|
|
12
|
+
///
|
|
13
|
+
/// https://bybit-exchange.github.io/docs/v5/account/wallet-balance
|
|
14
|
+
/// https://api.bybit.com/v5/account/wallet-balance
|
|
15
|
+
getV5AccountWalletBalance(verifyType = 'HASH_COMPARISON') {
|
|
16
|
+
if (!this.hasMain)
|
|
17
|
+
return undefined;
|
|
18
|
+
const signParams = { accountType: "UNIFIED" };
|
|
19
|
+
const origRequests = [];
|
|
20
|
+
for (const acc of this.mainAccounts) {
|
|
21
|
+
const exchange = new ccxt.bybit({
|
|
22
|
+
apiKey: acc.apiKey, secret: acc.apiSecret, options: {
|
|
23
|
+
recvWindow: this.recvWindow,
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
origRequests.push(exchange.sign("v5/account/wallet-balance", "private", "GET", { ...signParams }));
|
|
27
|
+
}
|
|
28
|
+
return makeZkTlsRequestParams(origRequests, verifyType);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=bybit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bybit.js","sourceRoot":"","sources":["../../src/datasource/bybit.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,KAAM,SAAQ,YAAqC;IAC9D,YAAY,QAAoC;QAC9C,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtD,IAAI,YAAY,KAAK,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAGvD,GAAG;IACH,2EAA2E;IAC3E,GAAG;IAEH,mEAAmE;IACnE,mDAAmD;IAC5C,yBAAyB,CAAC,aAA0B,iBAAiB;QAC1E,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAEpC,MAAM,UAAU,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;QAC9C,MAAM,YAAY,GAAU,EAAE,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC;gBAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE;oBAClD,UAAU,EAAE,IAAI,CAAC,UAAU;iBAC5B;aACF,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;QACrG,CAAC;QACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { DatasourceConfig } from "../config_schema.js";
|
|
2
2
|
import { Binance } from "./binance.js";
|
|
3
3
|
import { Aster } from "./aster.js";
|
|
4
|
+
import { Grvt } from "./grvt.js";
|
|
5
|
+
import { Bybit } from "./bybit.js";
|
|
6
|
+
import { Hyperliquid } from "./hyperliquid.js";
|
|
7
|
+
import { Pacifica } from "./pacifica.js";
|
|
8
|
+
import { Extended } from "./extended.js";
|
|
9
|
+
import { Lighter } from "./lighter.js";
|
|
4
10
|
/**
|
|
5
11
|
*
|
|
6
12
|
* Usage:
|
|
@@ -11,5 +17,11 @@ import { Aster } from "./aster.js";
|
|
|
11
17
|
export declare class DatasourceManager {
|
|
12
18
|
readonly binance?: Binance;
|
|
13
19
|
readonly aster?: Aster;
|
|
20
|
+
readonly grvt?: Grvt;
|
|
21
|
+
readonly bybit?: Bybit;
|
|
22
|
+
readonly hyperliquid?: Hyperliquid;
|
|
23
|
+
readonly pacifica?: Pacifica;
|
|
24
|
+
readonly extended?: Extended;
|
|
25
|
+
readonly lighter?: Lighter;
|
|
14
26
|
constructor(config: DatasourceConfig);
|
|
15
27
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Binance } from "./binance.js";
|
|
2
2
|
import { Aster } from "./aster.js";
|
|
3
|
+
import { Grvt } from "./grvt.js";
|
|
4
|
+
import { Bybit } from "./bybit.js";
|
|
5
|
+
import { Hyperliquid } from "./hyperliquid.js";
|
|
6
|
+
import { Pacifica } from "./pacifica.js";
|
|
7
|
+
import { Extended } from "./extended.js";
|
|
8
|
+
import { Lighter } from "./lighter.js";
|
|
3
9
|
/**
|
|
4
10
|
*
|
|
5
11
|
* Usage:
|
|
@@ -10,11 +16,29 @@ import { Aster } from "./aster.js";
|
|
|
10
16
|
export class DatasourceManager {
|
|
11
17
|
binance;
|
|
12
18
|
aster;
|
|
19
|
+
grvt;
|
|
20
|
+
bybit;
|
|
21
|
+
hyperliquid;
|
|
22
|
+
pacifica;
|
|
23
|
+
extended;
|
|
24
|
+
lighter;
|
|
13
25
|
constructor(config) {
|
|
14
26
|
if (config.binance)
|
|
15
27
|
this.binance = new Binance(config.binance);
|
|
16
28
|
if (config.aster)
|
|
17
29
|
this.aster = new Aster(config.aster);
|
|
30
|
+
if (config.grvt)
|
|
31
|
+
this.grvt = new Grvt(config.grvt);
|
|
32
|
+
if (config.bybit)
|
|
33
|
+
this.bybit = new Bybit(config.bybit);
|
|
34
|
+
if (config.hyperliquid)
|
|
35
|
+
this.hyperliquid = new Hyperliquid(config.hyperliquid);
|
|
36
|
+
if (config.pacifica)
|
|
37
|
+
this.pacifica = new Pacifica(config.pacifica);
|
|
38
|
+
if (config.extended)
|
|
39
|
+
this.extended = new Extended(config.extended);
|
|
40
|
+
if (config.lighter)
|
|
41
|
+
this.lighter = new Lighter(config.lighter);
|
|
18
42
|
}
|
|
19
43
|
}
|
|
20
44
|
//# sourceMappingURL=datasource_manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource_manager.js","sourceRoot":"","sources":["../../src/datasource/datasource_manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"datasource_manager.js","sourceRoot":"","sources":["../../src/datasource/datasource_manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IACZ,OAAO,CAAW;IAClB,KAAK,CAAS;IACd,IAAI,CAAQ;IACZ,KAAK,CAAS;IACd,WAAW,CAAe;IAC1B,QAAQ,CAAY;IACpB,QAAQ,CAAY;IACpB,OAAO,CAAW;IAElC,YAAY,MAAwB;QAClC,IAAI,MAAM,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,MAAM,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,MAAM,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,MAAM,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,MAAM,CAAC,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC/E,IAAI,MAAM,CAAC,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnE,IAAI,MAAM,CAAC,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnE,IAAI,MAAM,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VERIFY_TYPE, RequestParamsOutput } from "../types.js";
|
|
2
|
+
import { ExtendedKind, ExtendedAccount, DatasourceConfig } from "../config_schema.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export declare class Extended extends BaseExchange<ExtendedAccount, ExtendedKind> {
|
|
5
|
+
constructor(accounts?: DatasourceConfig["extended"]);
|
|
6
|
+
get hasMain(): boolean;
|
|
7
|
+
get mainAccounts(): {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
apiSecret: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
subAccountId: string;
|
|
13
|
+
vaultId: string;
|
|
14
|
+
address: string;
|
|
15
|
+
accountIndex: string;
|
|
16
|
+
poolIndex: string;
|
|
17
|
+
kind: "main"[];
|
|
18
|
+
}[];
|
|
19
|
+
getV1UserBalance(verifyType?: VERIFY_TYPE): RequestParamsOutput;
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { makeZkTlsRequestParams } from "./helper.js";
|
|
2
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
3
|
+
export class Extended extends BaseExchange {
|
|
4
|
+
constructor(accounts) {
|
|
5
|
+
super(accounts);
|
|
6
|
+
}
|
|
7
|
+
get hasMain() { return this.mainAccounts.length > 0; }
|
|
8
|
+
get mainAccounts() { return this.getAccounts("main"); }
|
|
9
|
+
///
|
|
10
|
+
/// =======================================================================
|
|
11
|
+
///
|
|
12
|
+
/// https://api.docs.extended.exchange/#get-balance
|
|
13
|
+
/// https://api.starknet.extended.exchange/api/v1/user/balance
|
|
14
|
+
getV1UserBalance(verifyType = 'HASH_COMPARISON') {
|
|
15
|
+
if (!this.hasMain)
|
|
16
|
+
return undefined;
|
|
17
|
+
const origRequests = [];
|
|
18
|
+
for (const acc of this.mainAccounts) {
|
|
19
|
+
origRequests.push({
|
|
20
|
+
url: "https://api.starknet.extended.exchange/api/v1/user/balance",
|
|
21
|
+
method: "GET",
|
|
22
|
+
headers: {
|
|
23
|
+
"X-Api-Key": acc.apiKey,
|
|
24
|
+
},
|
|
25
|
+
body: "",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return makeZkTlsRequestParams(origRequests, verifyType);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=extended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extended.js","sourceRoot":"","sources":["../../src/datasource/extended.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,QAAS,SAAQ,YAA2C;IACvE,YAAY,QAAuC;QACjD,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtD,IAAI,YAAY,KAAK,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEvD,GAAG;IACH,2EAA2E;IAC3E,GAAG;IAEH,mDAAmD;IACnD,8DAA8D;IACvD,gBAAgB,CAAC,aAA0B,iBAAiB;QACjE,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAEpC,MAAM,YAAY,GAAU,EAAE,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,YAAY,CAAC,IAAI,CAAC;gBAChB,GAAG,EAAE,4DAA4D;gBACjE,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,WAAW,EAAE,GAAG,CAAC,MAAM;iBACxB;gBACD,IAAI,EAAE,EAAE;aACT,CAAC,CAAC;QACL,CAAC;QACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { VERIFY_TYPE, RequestParamsOutput } from "../types.js";
|
|
2
|
+
import { GrvtKind, GrvtAccount, DatasourceConfig } from "../config_schema.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
type AuthInfo = {
|
|
5
|
+
cookie: string;
|
|
6
|
+
accountId: string;
|
|
7
|
+
expireAt: number;
|
|
8
|
+
};
|
|
9
|
+
export declare class Grvt extends BaseExchange<GrvtAccount, GrvtKind> {
|
|
10
|
+
constructor(accounts?: DatasourceConfig["grvt"]);
|
|
11
|
+
get hasMain(): boolean;
|
|
12
|
+
get mainAccounts(): {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
apiSecret: string;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
description: string;
|
|
17
|
+
subAccountId: string;
|
|
18
|
+
vaultId: string;
|
|
19
|
+
address: string;
|
|
20
|
+
accountIndex: string;
|
|
21
|
+
poolIndex: string;
|
|
22
|
+
kind: "main"[];
|
|
23
|
+
}[];
|
|
24
|
+
private authCache;
|
|
25
|
+
private readonly GRVT_AUTH_ENDPOINT;
|
|
26
|
+
_getAuthInfo(apiKey: string): Promise<AuthInfo>;
|
|
27
|
+
getV1AccountSummary(verifyType?: VERIFY_TYPE): Promise<RequestParamsOutput>;
|
|
28
|
+
getV1VaultInvestorSummary(verifyType?: VERIFY_TYPE): Promise<RequestParamsOutput>;
|
|
29
|
+
getV1Summary(verifyType?: VERIFY_TYPE, kinds?: string[]): Promise<RequestParamsOutput>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { makeZkTlsRequestParams, mergeManyRequestParams } from "./helper.js";
|
|
2
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
export class Grvt extends BaseExchange {
|
|
5
|
+
constructor(accounts) {
|
|
6
|
+
super(accounts);
|
|
7
|
+
}
|
|
8
|
+
get hasMain() { return this.mainAccounts.length > 0; }
|
|
9
|
+
get mainAccounts() { return this.getAccounts("main"); }
|
|
10
|
+
///
|
|
11
|
+
/// =======================================================================
|
|
12
|
+
///
|
|
13
|
+
authCache = new Map();
|
|
14
|
+
// private readonly GRVT_AUTH_ENDPOINT = "https://edge.testnet.grvt.io/auth/api_key/login"; // test
|
|
15
|
+
GRVT_AUTH_ENDPOINT = "https://edge.grvt.io/auth/api_key/login"; // prod
|
|
16
|
+
async _getAuthInfo(apiKey) {
|
|
17
|
+
const cached = this.authCache.get(apiKey);
|
|
18
|
+
if (cached && Date.now() < cached.expireAt + 300_000) {
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
const res = await axios.post(this.GRVT_AUTH_ENDPOINT, { api_key: apiKey }, {
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
"Cookie": "rm=true;",
|
|
25
|
+
},
|
|
26
|
+
validateStatus: () => true,
|
|
27
|
+
});
|
|
28
|
+
const cookies = res.headers["set-cookie"] || [];
|
|
29
|
+
const gravityCookie = cookies.find((c) => c.startsWith("gravity="));
|
|
30
|
+
const accountId = res.headers["x-grvt-account-id"];
|
|
31
|
+
if (!gravityCookie || !accountId) {
|
|
32
|
+
throw new Error("GRVT auth failed");
|
|
33
|
+
}
|
|
34
|
+
const cookie = gravityCookie.split(";")[0];
|
|
35
|
+
const authInfo = {
|
|
36
|
+
cookie,
|
|
37
|
+
accountId,
|
|
38
|
+
expireAt: Date.now()
|
|
39
|
+
};
|
|
40
|
+
this.authCache.set(apiKey, authInfo);
|
|
41
|
+
return authInfo;
|
|
42
|
+
}
|
|
43
|
+
///
|
|
44
|
+
/// =======================================================================
|
|
45
|
+
///
|
|
46
|
+
/// https://api-docs.grvt.io/trading_api/#sub-account-summary-request
|
|
47
|
+
/// https://trades.grvt.io/full/v1/account_summary
|
|
48
|
+
async getV1AccountSummary(verifyType = 'HASH_COMPARISON') {
|
|
49
|
+
if (!this.hasMain)
|
|
50
|
+
return undefined;
|
|
51
|
+
const origRequests = [];
|
|
52
|
+
for (const acc of this.mainAccounts) {
|
|
53
|
+
if (!acc.subAccountId || acc.subAccountId == "") {
|
|
54
|
+
throw new Error("GRVT subAccountId is empty!");
|
|
55
|
+
}
|
|
56
|
+
const authInfo = await this._getAuthInfo(acc.apiKey);
|
|
57
|
+
origRequests.push({
|
|
58
|
+
url: "https://trades.grvt.io/full/v1/account_summary",
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
"Accept": "application/json",
|
|
63
|
+
"Cookie": authInfo.cookie,
|
|
64
|
+
"X-Grvt-Account-Id": authInfo.accountId
|
|
65
|
+
},
|
|
66
|
+
body: {
|
|
67
|
+
"sub_account_id": acc.subAccountId
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return makeZkTlsRequestParams(origRequests, verifyType);
|
|
72
|
+
}
|
|
73
|
+
/// https://api-docs.grvt.io/trading_api/#vault-investor-summary-request
|
|
74
|
+
/// https://trades.grvt.io/full/v1/vault_investor_summary
|
|
75
|
+
async getV1VaultInvestorSummary(verifyType = 'HASH_COMPARISON') {
|
|
76
|
+
if (!this.hasMain)
|
|
77
|
+
return undefined;
|
|
78
|
+
const origRequests = [];
|
|
79
|
+
for (const acc of this.mainAccounts) {
|
|
80
|
+
if (!acc.vaultId || acc.vaultId == "") {
|
|
81
|
+
throw new Error("GRVT vaultId is empty!");
|
|
82
|
+
}
|
|
83
|
+
const authInfo = await this._getAuthInfo(acc.apiKey);
|
|
84
|
+
origRequests.push({
|
|
85
|
+
url: "https://trades.grvt.io/full/v1/vault_investor_summary",
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
"Accept": "application/json",
|
|
90
|
+
"Cookie": authInfo.cookie,
|
|
91
|
+
"X-Grvt-Account-Id": authInfo.accountId
|
|
92
|
+
},
|
|
93
|
+
body: {
|
|
94
|
+
"vault_id": acc.vaultId
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return makeZkTlsRequestParams(origRequests, verifyType);
|
|
99
|
+
}
|
|
100
|
+
async getV1Summary(verifyType = "HASH_COMPARISON", kinds = ["account_summary", "vault_investor_summary"]) {
|
|
101
|
+
const requests = [];
|
|
102
|
+
if (kinds.includes("account_summary")) {
|
|
103
|
+
requests.push(this.getV1AccountSummary(verifyType));
|
|
104
|
+
}
|
|
105
|
+
if (kinds.includes("vault_investor_summary")) {
|
|
106
|
+
requests.push(this.getV1VaultInvestorSummary(verifyType));
|
|
107
|
+
}
|
|
108
|
+
const res = await Promise.all(requests);
|
|
109
|
+
return mergeManyRequestParams(res);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=grvt.js.map
|
|
@@ -0,0 +1 @@
|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B,CAAC,iBAAiB,EAAE,wBAAwB,CAAC;QAE/D,MAAM,QAAQ,GAAmC,EAAE,CAAC;QACpD,IAAI,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAC7C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { VERIFY_TYPE, RequestParams } from "../types.js";
|
|
1
|
+
import { VERIFY_TYPE, RequestParams, RequestParamsOutput } from "../types.js";
|
|
2
2
|
export declare function signQuery(secretKey: string, params: any): string;
|
|
3
|
+
export declare function mergeManyRequestParams(list: RequestParamsOutput[]): RequestParamsOutput;
|
|
3
4
|
export interface OrigRequest {
|
|
4
5
|
url: any;
|
|
5
6
|
method?: string;
|
|
6
7
|
body?: any;
|
|
7
8
|
headers?: any;
|
|
8
9
|
}
|
|
9
|
-
export declare function makeZkTlsRequestParams(origRequests: OrigRequest[], verifyType?: VERIFY_TYPE): RequestParams;
|
|
10
|
+
export declare function makeZkTlsRequestParams(origRequests: OrigRequest[], verifyType?: VERIFY_TYPE, options?: any): RequestParams;
|
|
@@ -4,7 +4,20 @@ export function signQuery(secretKey, params) {
|
|
|
4
4
|
const signature = createHmac("sha256", secretKey).update(query).digest("hex");
|
|
5
5
|
return `${query}&signature=${signature}`;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
export function mergeManyRequestParams(list) {
|
|
8
|
+
return list.reduce((acc, cur) => {
|
|
9
|
+
if (!acc)
|
|
10
|
+
return cur;
|
|
11
|
+
if (!cur)
|
|
12
|
+
return acc;
|
|
13
|
+
return {
|
|
14
|
+
verifyType: acc.verifyType,
|
|
15
|
+
requests: [...acc.requests, ...cur.requests],
|
|
16
|
+
responseResolves: [...acc.responseResolves, ...cur.responseResolves],
|
|
17
|
+
};
|
|
18
|
+
}, undefined);
|
|
19
|
+
}
|
|
20
|
+
function makeHashComparisonParams(origRequests, options) {
|
|
8
21
|
if (!Array.isArray(origRequests)) {
|
|
9
22
|
throw new Error("Invalid input: origRequests must be an array");
|
|
10
23
|
}
|
|
@@ -12,6 +25,7 @@ function makeHashComparisonParams(origRequests) {
|
|
|
12
25
|
verifyType: 'HASH_COMPARISON',
|
|
13
26
|
requests: [],
|
|
14
27
|
responseResolves: [],
|
|
28
|
+
options,
|
|
15
29
|
};
|
|
16
30
|
for (let i = 0; i < origRequests.length; i++) {
|
|
17
31
|
const origRequest = origRequests[i];
|
|
@@ -32,9 +46,9 @@ function makeHashComparisonParams(origRequests) {
|
|
|
32
46
|
}
|
|
33
47
|
return requestParams;
|
|
34
48
|
}
|
|
35
|
-
export function makeZkTlsRequestParams(origRequests, verifyType = 'HASH_COMPARISON') {
|
|
49
|
+
export function makeZkTlsRequestParams(origRequests, verifyType = 'HASH_COMPARISON', options) {
|
|
36
50
|
if (verifyType == 'HASH_COMPARISON') {
|
|
37
|
-
return makeHashComparisonParams(origRequests);
|
|
51
|
+
return makeHashComparisonParams(origRequests, options);
|
|
38
52
|
}
|
|
39
53
|
throw Error("not supported verify type");
|
|
40
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/datasource/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,SAAS,CAAC,SAAiB,EAAE,MAAW;IACtD,MAAM,KAAK,GAAG,IAAI,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{ VERIFY_TYPE, RequestParamsOutput } from "../types.js";
|
|
2
|
+
import { HyperliquidKind, HyperliquidAccount, DatasourceConfig } from "../config_schema.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export declare class Hyperliquid extends BaseExchange<HyperliquidAccount, HyperliquidKind> {
|
|
5
|
+
constructor(accounts?: DatasourceConfig["hyperliquid"]);
|
|
6
|
+
get hasMain(): boolean;
|
|
7
|
+
get mainAccounts(): {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
apiSecret: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
subAccountId: string;
|
|
13
|
+
vaultId: string;
|
|
14
|
+
address: string;
|
|
15
|
+
accountIndex: string;
|
|
16
|
+
poolIndex: string;
|
|
17
|
+
kind: "main"[];
|
|
18
|
+
}[];
|
|
19
|
+
getInfo(verifyType?: VERIFY_TYPE): RequestParamsOutput;
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import ccxt from "ccxt";
|
|
2
|
+
import { makeZkTlsRequestParams } from "./helper.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export class Hyperliquid extends BaseExchange {
|
|
5
|
+
constructor(accounts) {
|
|
6
|
+
super(accounts);
|
|
7
|
+
}
|
|
8
|
+
get hasMain() { return this.mainAccounts.length > 0; }
|
|
9
|
+
get mainAccounts() { return this.getAccounts("main"); }
|
|
10
|
+
///
|
|
11
|
+
/// =======================================================================
|
|
12
|
+
///
|
|
13
|
+
/// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-subaccounts
|
|
14
|
+
/// https://api.hyperliquid.xyz/info
|
|
15
|
+
getInfo(verifyType = 'HASH_COMPARISON') {
|
|
16
|
+
if (!this.hasMain)
|
|
17
|
+
return undefined;
|
|
18
|
+
const origRequests = [];
|
|
19
|
+
for (const acc of this.mainAccounts) {
|
|
20
|
+
if (!acc.address || acc.address == "") {
|
|
21
|
+
throw new Error("Hyperliquid address is empty!");
|
|
22
|
+
}
|
|
23
|
+
const signParams = { type: "clearinghouseState", user: acc.address };
|
|
24
|
+
const exchange = new ccxt.hyperliquid();
|
|
25
|
+
origRequests.push(exchange.sign("info", "public", "POST", { ...signParams }));
|
|
26
|
+
}
|
|
27
|
+
return makeZkTlsRequestParams(origRequests, verifyType);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=hyperliquid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperliquid.js","sourceRoot":"","sources":["../../src/datasource/hyperliquid.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,WAAY,SAAQ,YAAiD;IAChF,YAAY,QAA0C;QACpD,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtD,IAAI,YAAY,KAAK,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAGvD,GAAG;IACH,2EAA2E;IAC3E,GAAG;IAEH,iHAAiH;IACjH,oCAAoC;IAC7B,OAAO,CAAC,aAA0B,iBAAiB;QACxD,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAEpC,MAAM,YAAY,GAAU,EAAE,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;YAClD,CAAC;YAED,MAAM,UAAU,GAAG,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;YACrE,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACxC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VERIFY_TYPE, RequestParamsOutput } from "../types.js";
|
|
2
|
+
import { LighterKind, LighterAccount, DatasourceConfig } from "../config_schema.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export declare class Lighter extends BaseExchange<LighterAccount, LighterKind> {
|
|
5
|
+
constructor(accounts?: DatasourceConfig["lighter"]);
|
|
6
|
+
get hasMain(): boolean;
|
|
7
|
+
get mainAccounts(): {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
apiSecret: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
subAccountId: string;
|
|
13
|
+
vaultId: string;
|
|
14
|
+
address: string;
|
|
15
|
+
accountIndex: string;
|
|
16
|
+
poolIndex: string;
|
|
17
|
+
kind: "main"[];
|
|
18
|
+
}[];
|
|
19
|
+
getV1Account(verifyType?: VERIFY_TYPE): RequestParamsOutput;
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { makeZkTlsRequestParams } from "./helper.js";
|
|
2
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
3
|
+
export class Lighter extends BaseExchange {
|
|
4
|
+
constructor(accounts) {
|
|
5
|
+
super(accounts);
|
|
6
|
+
}
|
|
7
|
+
get hasMain() { return this.mainAccounts.length > 0; }
|
|
8
|
+
get mainAccounts() { return this.getAccounts("main"); }
|
|
9
|
+
///
|
|
10
|
+
/// =======================================================================
|
|
11
|
+
///
|
|
12
|
+
/// https://apidocs.lighter.xyz/reference/account-1
|
|
13
|
+
/// https://mainnet.zklighter.elliot.ai/api/v1/account
|
|
14
|
+
getV1Account(verifyType = 'HASH_COMPARISON') {
|
|
15
|
+
if (!this.hasMain)
|
|
16
|
+
return undefined;
|
|
17
|
+
const origRequests = [];
|
|
18
|
+
for (const acc of this.mainAccounts) {
|
|
19
|
+
if (!acc.accountIndex || acc.accountIndex == "") {
|
|
20
|
+
throw new Error("Lighter accountIndex is empty!");
|
|
21
|
+
}
|
|
22
|
+
if (!acc.poolIndex || acc.poolIndex == "") {
|
|
23
|
+
throw new Error("Lighter poolIndex is empty!");
|
|
24
|
+
}
|
|
25
|
+
// DO NOT CHANGE THE ORDER
|
|
26
|
+
origRequests.push({
|
|
27
|
+
url: `https://mainnet.zklighter.elliot.ai/api/v1/account?by=index&value=${acc.accountIndex}`
|
|
28
|
+
// const accountValue1 = accounts[0].total_asset_value
|
|
29
|
+
// const shares = accounts[0].shares.find(x => x.public_pool_index === poolIndex).shares_amount
|
|
30
|
+
});
|
|
31
|
+
origRequests.push({
|
|
32
|
+
url: `https://mainnet.zklighter.elliot.ai/api/v1/account?by=index&value=${acc.poolIndex}`
|
|
33
|
+
// const poolTotalValue = accounts[0].collateral
|
|
34
|
+
// const totalShares =accounts[0].pool_info.total_shares
|
|
35
|
+
// const sharePrice = poolTotalValue / totalShares;
|
|
36
|
+
// const accountValue2 = shares * sharePrice;
|
|
37
|
+
});
|
|
38
|
+
// const lighterTotal = accountValue1 + accountValue2
|
|
39
|
+
}
|
|
40
|
+
return makeZkTlsRequestParams(origRequests, verifyType, { "attUrlOptimization": false });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=lighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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gBACzF,gDAAgD;gBAChD,wDAAwD;gBACxD,mDAAmD;gBACnD,6CAA6C;aAC9C,CAAC,CAAC;YACH,qDAAqD;QACvD,CAAC;QACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,UAAU,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3F,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VERIFY_TYPE, RequestParamsOutput } from "../types.js";
|
|
2
|
+
import { PacificaKind, PacificaAccount, DatasourceConfig } from "../config_schema.js";
|
|
3
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
4
|
+
export declare class Pacifica extends BaseExchange<PacificaAccount, PacificaKind> {
|
|
5
|
+
constructor(accounts?: DatasourceConfig["pacifica"]);
|
|
6
|
+
get hasMain(): boolean;
|
|
7
|
+
get mainAccounts(): {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
apiSecret: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
subAccountId: string;
|
|
13
|
+
vaultId: string;
|
|
14
|
+
address: string;
|
|
15
|
+
accountIndex: string;
|
|
16
|
+
poolIndex: string;
|
|
17
|
+
kind: "main"[];
|
|
18
|
+
}[];
|
|
19
|
+
getV1Account(verifyType?: VERIFY_TYPE): RequestParamsOutput;
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { makeZkTlsRequestParams } from "./helper.js";
|
|
2
|
+
import { BaseExchange } from "./base_exchange.js";
|
|
3
|
+
export class Pacifica extends BaseExchange {
|
|
4
|
+
constructor(accounts) {
|
|
5
|
+
super(accounts);
|
|
6
|
+
}
|
|
7
|
+
get hasMain() { return this.mainAccounts.length > 0; }
|
|
8
|
+
get mainAccounts() { return this.getAccounts("main"); }
|
|
9
|
+
///
|
|
10
|
+
/// =======================================================================
|
|
11
|
+
///
|
|
12
|
+
/// https://pacifica.gitbook.io/docs/api-documentation/api/rest-api/account/get-account-info
|
|
13
|
+
/// https://api.pacifica.fi/api/v1/account
|
|
14
|
+
getV1Account(verifyType = 'HASH_COMPARISON') {
|
|
15
|
+
if (!this.hasMain)
|
|
16
|
+
return undefined;
|
|
17
|
+
const origRequests = [];
|
|
18
|
+
for (const acc of this.mainAccounts) {
|
|
19
|
+
if (!acc.address || acc.address == "") {
|
|
20
|
+
throw new Error("Pacifica address is empty!");
|
|
21
|
+
}
|
|
22
|
+
origRequests.push({
|
|
23
|
+
url: `https://api.pacifica.fi/api/v1/account?account=${acc.address}`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return makeZkTlsRequestParams(origRequests, verifyType);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pacifica.js.map
|