@cityofzion/blockchain-service 0.11.1 → 0.12.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/dist/CryptoCompareEDS.d.ts +8 -0
- package/dist/CryptoCompareEDS.js +90 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces.d.ts +33 -9
- package/package.json +4 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Currency, ExchangeDataService, GetTokenPriceHistory, NetworkType, Token, TokenPricesHistoryResponse, TokenPricesResponse } from './interfaces';
|
|
2
|
+
export declare class CryptoCompareEDS implements ExchangeDataService {
|
|
3
|
+
#private;
|
|
4
|
+
networkType: NetworkType;
|
|
5
|
+
constructor(network: NetworkType, tokens?: Token[]);
|
|
6
|
+
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
7
|
+
getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _CryptoCompareEDS_axiosInstance, _CryptoCompareEDS_tokens;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.CryptoCompareEDS = void 0;
|
|
28
|
+
const axios_1 = __importDefault(require("axios"));
|
|
29
|
+
class CryptoCompareEDS {
|
|
30
|
+
constructor(network, tokens = []) {
|
|
31
|
+
_CryptoCompareEDS_axiosInstance.set(this, void 0);
|
|
32
|
+
_CryptoCompareEDS_tokens.set(this, void 0);
|
|
33
|
+
this.networkType = network;
|
|
34
|
+
__classPrivateFieldSet(this, _CryptoCompareEDS_tokens, tokens, "f");
|
|
35
|
+
__classPrivateFieldSet(this, _CryptoCompareEDS_axiosInstance, axios_1.default.create({ baseURL: 'https://min-api.cryptocompare.com' }), "f");
|
|
36
|
+
}
|
|
37
|
+
getTokenPrices(currency) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (this.networkType !== 'mainnet')
|
|
40
|
+
throw new Error('Exchange is only available on mainnet');
|
|
41
|
+
const tokenSymbols = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").map(token => token.symbol);
|
|
42
|
+
const { data: prices } = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get('/data/pricemultifull', {
|
|
43
|
+
params: {
|
|
44
|
+
fsyms: tokenSymbols.join(','),
|
|
45
|
+
tsyms: currency,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return Object.entries(prices.RAW)
|
|
49
|
+
.map(([symbol, priceObject]) => {
|
|
50
|
+
const price = priceObject[currency].PRICE;
|
|
51
|
+
const token = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").find(token => token.symbol === symbol);
|
|
52
|
+
if (!token || !price)
|
|
53
|
+
return;
|
|
54
|
+
return {
|
|
55
|
+
symbol,
|
|
56
|
+
price,
|
|
57
|
+
hash: token === null || token === void 0 ? void 0 : token.hash,
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
.filter((price) => price !== undefined);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getTokenPriceHistory(params) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const path = `/data/${params.type === 'hour' ? 'histohour' : 'histoday'}`;
|
|
66
|
+
const response = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get(path, {
|
|
67
|
+
params: {
|
|
68
|
+
fsym: params.tokenSymbol,
|
|
69
|
+
tsym: params.currency,
|
|
70
|
+
limit: params.limit,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const history = [];
|
|
74
|
+
response.data.Data.forEach(data => {
|
|
75
|
+
const token = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").find(token => token.symbol === params.tokenSymbol);
|
|
76
|
+
if (!token)
|
|
77
|
+
return;
|
|
78
|
+
history.push({
|
|
79
|
+
price: data.close,
|
|
80
|
+
timestamp: data.time,
|
|
81
|
+
symbol: params.tokenSymbol,
|
|
82
|
+
hash: token.hash,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return history;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.CryptoCompareEDS = CryptoCompareEDS;
|
|
90
|
+
_CryptoCompareEDS_axiosInstance = new WeakMap(), _CryptoCompareEDS_tokens = new WeakMap();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./interfaces"), exports);
|
|
18
18
|
__exportStar(require("./BSAggregator"), exports);
|
|
19
19
|
__exportStar(require("./functions"), exports);
|
|
20
|
+
__exportStar(require("./CryptoCompareEDS"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Transport from '@ledgerhq/hw-transport';
|
|
2
|
+
import TypedEmitter from 'typed-emitter';
|
|
2
3
|
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
3
4
|
export type Account = {
|
|
4
5
|
key: string;
|
|
@@ -32,15 +33,6 @@ export type TransferParam = {
|
|
|
32
33
|
priorityFee?: string;
|
|
33
34
|
isLedger?: boolean;
|
|
34
35
|
};
|
|
35
|
-
export type TokenPricesResponse = {
|
|
36
|
-
price: number;
|
|
37
|
-
symbol: string;
|
|
38
|
-
hash: string;
|
|
39
|
-
};
|
|
40
|
-
export type Currency = 'USD' | 'BRL' | 'EUR';
|
|
41
|
-
export interface ExchangeDataService {
|
|
42
|
-
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
43
|
-
}
|
|
44
36
|
export interface BlockchainService<BSCustomName extends string = string> {
|
|
45
37
|
readonly blockchainName: BSCustomName;
|
|
46
38
|
readonly derivationPath: string;
|
|
@@ -156,6 +148,28 @@ export interface BlockchainDataService {
|
|
|
156
148
|
export interface BDSClaimable {
|
|
157
149
|
getUnclaimed(address: string): Promise<string>;
|
|
158
150
|
}
|
|
151
|
+
export type TokenPricesResponse = {
|
|
152
|
+
price: number;
|
|
153
|
+
symbol: string;
|
|
154
|
+
hash: string;
|
|
155
|
+
};
|
|
156
|
+
export type TokenPricesHistoryResponse = {
|
|
157
|
+
price: number;
|
|
158
|
+
timestamp: number;
|
|
159
|
+
symbol: string;
|
|
160
|
+
hash: string;
|
|
161
|
+
};
|
|
162
|
+
export type Currency = 'USD' | 'BRL' | 'EUR';
|
|
163
|
+
export type GetTokenPriceHistory = {
|
|
164
|
+
tokenSymbol: string;
|
|
165
|
+
currency: Currency;
|
|
166
|
+
type: 'hour' | 'day';
|
|
167
|
+
limit: number;
|
|
168
|
+
};
|
|
169
|
+
export interface ExchangeDataService {
|
|
170
|
+
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
171
|
+
getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
|
|
172
|
+
}
|
|
159
173
|
export interface NftResponse {
|
|
160
174
|
id: string;
|
|
161
175
|
contractHash: string;
|
|
@@ -185,9 +199,14 @@ export type GetNftParam = {
|
|
|
185
199
|
tokenId: string;
|
|
186
200
|
contractHash: string;
|
|
187
201
|
};
|
|
202
|
+
export type HasTokenParam = {
|
|
203
|
+
address: string;
|
|
204
|
+
contractHash: string;
|
|
205
|
+
};
|
|
188
206
|
export interface NftDataService {
|
|
189
207
|
getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
190
208
|
getNft(params: GetNftParam): Promise<NftResponse>;
|
|
209
|
+
hasToken(params: HasTokenParam): Promise<boolean>;
|
|
191
210
|
}
|
|
192
211
|
export type BuildNftUrlParams = {
|
|
193
212
|
contractHash: string;
|
|
@@ -197,7 +216,12 @@ export interface ExplorerService {
|
|
|
197
216
|
buildTransactionUrl(hash: string): string;
|
|
198
217
|
buildNftUrl(params: BuildNftUrlParams): string;
|
|
199
218
|
}
|
|
219
|
+
export type LedgerServiceEmitter = TypedEmitter<{
|
|
220
|
+
getSignatureStart(): void | Promise<void>;
|
|
221
|
+
getSignatureEnd(): void | Promise<void>;
|
|
222
|
+
}>;
|
|
200
223
|
export interface LedgerService {
|
|
224
|
+
emitter: LedgerServiceEmitter;
|
|
201
225
|
getLedgerTransport?: (account: Account) => Promise<Transport>;
|
|
202
226
|
getAddress(transport: Transport): Promise<string>;
|
|
203
227
|
getPublicKey(transport: Transport): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/blockchain-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"typescript": "4.9.5"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ledgerhq/hw-transport": "~6.30.5"
|
|
21
|
+
"@ledgerhq/hw-transport": "~6.30.5",
|
|
22
|
+
"axios": "1.5.1",
|
|
23
|
+
"typed-emitter": "~2.1.0"
|
|
22
24
|
},
|
|
23
25
|
"scripts": {
|
|
24
26
|
"build": "tsc",
|