@cityofzion/blockchain-service 0.11.1 → 0.11.2
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 +27 -9
- package/package.json +3 -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
|
@@ -32,15 +32,6 @@ export type TransferParam = {
|
|
|
32
32
|
priorityFee?: string;
|
|
33
33
|
isLedger?: boolean;
|
|
34
34
|
};
|
|
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
35
|
export interface BlockchainService<BSCustomName extends string = string> {
|
|
45
36
|
readonly blockchainName: BSCustomName;
|
|
46
37
|
readonly derivationPath: string;
|
|
@@ -156,6 +147,28 @@ export interface BlockchainDataService {
|
|
|
156
147
|
export interface BDSClaimable {
|
|
157
148
|
getUnclaimed(address: string): Promise<string>;
|
|
158
149
|
}
|
|
150
|
+
export type TokenPricesResponse = {
|
|
151
|
+
price: number;
|
|
152
|
+
symbol: string;
|
|
153
|
+
hash: string;
|
|
154
|
+
};
|
|
155
|
+
export type TokenPricesHistoryResponse = {
|
|
156
|
+
price: number;
|
|
157
|
+
timestamp: number;
|
|
158
|
+
symbol: string;
|
|
159
|
+
hash: string;
|
|
160
|
+
};
|
|
161
|
+
export type Currency = 'USD' | 'BRL' | 'EUR';
|
|
162
|
+
export type GetTokenPriceHistory = {
|
|
163
|
+
tokenSymbol: string;
|
|
164
|
+
currency: Currency;
|
|
165
|
+
type: 'hour' | 'day';
|
|
166
|
+
limit: number;
|
|
167
|
+
};
|
|
168
|
+
export interface ExchangeDataService {
|
|
169
|
+
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
170
|
+
getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
|
|
171
|
+
}
|
|
159
172
|
export interface NftResponse {
|
|
160
173
|
id: string;
|
|
161
174
|
contractHash: string;
|
|
@@ -185,9 +198,14 @@ export type GetNftParam = {
|
|
|
185
198
|
tokenId: string;
|
|
186
199
|
contractHash: string;
|
|
187
200
|
};
|
|
201
|
+
export type HasTokenParam = {
|
|
202
|
+
address: string;
|
|
203
|
+
contractHash: string;
|
|
204
|
+
};
|
|
188
205
|
export interface NftDataService {
|
|
189
206
|
getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
190
207
|
getNft(params: GetNftParam): Promise<NftResponse>;
|
|
208
|
+
hasToken(params: HasTokenParam): Promise<boolean>;
|
|
191
209
|
}
|
|
192
210
|
export type BuildNftUrlParams = {
|
|
193
211
|
contractHash: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/blockchain-service",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
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,8 @@
|
|
|
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"
|
|
22
23
|
},
|
|
23
24
|
"scripts": {
|
|
24
25
|
"build": "tsc",
|