@cityofzion/blockchain-service 1.16.3 → 1.17.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/functions.d.ts +5 -1
- package/dist/functions.js +6 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/{CryptoCompareEDS.d.ts → services/exchange-data/CryptoCompareEDS.d.ts} +1 -1
- package/dist/{CryptoCompareEDS.js → services/exchange-data/CryptoCompareEDS.js} +1 -4
- package/dist/services/exchange-data/FlamingoForthewinEDS.d.ts +8 -0
- package/dist/services/exchange-data/FlamingoForthewinEDS.js +68 -0
- package/package.json +1 -1
package/dist/functions.d.ts
CHANGED
|
@@ -19,7 +19,11 @@ export declare function waitForAccountTransaction<BSName extends string = string
|
|
|
19
19
|
export declare function fetchAccounts<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
20
20
|
export declare function generateAccount<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, untilIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
21
21
|
export declare function generateAccountForBlockchainService<BSName extends string = string>(blockchainServices: BlockchainService<BSName>[], getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
|
22
|
-
|
|
22
|
+
type NormalizedHashOptions = {
|
|
23
|
+
lowercase?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare function normalizeHash(hash: string, options?: NormalizedHashOptions): string;
|
|
23
26
|
export declare function denormalizeHash(hash: string): string;
|
|
24
27
|
export declare function countDecimals(value: string | number): number;
|
|
25
28
|
export declare function formatNumber(value: string | number, decimals?: number): string;
|
|
29
|
+
export {};
|
package/dist/functions.js
CHANGED
|
@@ -140,8 +140,12 @@ function generateAccountForBlockchainService(blockchainServices, getAccountCallb
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
exports.generateAccountForBlockchainService = generateAccountForBlockchainService;
|
|
143
|
-
function normalizeHash(hash) {
|
|
144
|
-
|
|
143
|
+
function normalizeHash(hash, options) {
|
|
144
|
+
const { lowercase = true } = options !== null && options !== void 0 ? options : {};
|
|
145
|
+
hash = hash.replace('0x', '');
|
|
146
|
+
if (lowercase)
|
|
147
|
+
hash = hash.toLowerCase();
|
|
148
|
+
return hash;
|
|
145
149
|
}
|
|
146
150
|
exports.normalizeHash = normalizeHash;
|
|
147
151
|
function denormalizeHash(hash) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./services/exchange-data/CryptoCompareEDS"), exports);
|
|
18
|
+
__exportStar(require("./services/exchange-data/FlamingoForthewinEDS"), exports);
|
|
17
19
|
__exportStar(require("./BSAggregator"), exports);
|
|
18
|
-
__exportStar(require("./CryptoCompareEDS"), exports);
|
|
19
20
|
__exportStar(require("./functions"), exports);
|
|
20
21
|
__exportStar(require("./interfaces"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, TokenPricesHistoryResponse, TokenPricesResponse } from '
|
|
1
|
+
import { ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, TokenPricesHistoryResponse, TokenPricesResponse } from '../../interfaces';
|
|
2
2
|
export declare class CryptoCompareEDS implements ExchangeDataService {
|
|
3
3
|
#private;
|
|
4
4
|
constructor();
|
|
@@ -42,10 +42,7 @@ class CryptoCompareEDS {
|
|
|
42
42
|
return Object.entries(prices.RAW).map(([symbol, priceObject]) => {
|
|
43
43
|
const usdPrice = priceObject.USD.PRICE;
|
|
44
44
|
const token = params.tokens.find(token => token.symbol === symbol);
|
|
45
|
-
return {
|
|
46
|
-
usdPrice,
|
|
47
|
-
token,
|
|
48
|
-
};
|
|
45
|
+
return { usdPrice, token };
|
|
49
46
|
});
|
|
50
47
|
});
|
|
51
48
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExchangeDataService, GetTokenPricesParams, TokenPricesResponse } from '../../interfaces';
|
|
2
|
+
import { CryptoCompareEDS } from './CryptoCompareEDS';
|
|
3
|
+
export declare class FlamingoForthewinEDS extends CryptoCompareEDS implements ExchangeDataService {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
getTokenPrices({ tokens }: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
7
|
+
private predicateToken;
|
|
8
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
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");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
var _FlamingoForthewinEDS_flamingoAxiosInstance, _FlamingoForthewinEDS_forthewinAxiosInstance;
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.FlamingoForthewinEDS = void 0;
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
23
|
+
const CryptoCompareEDS_1 = require("./CryptoCompareEDS");
|
|
24
|
+
const functions_1 = require("../../functions");
|
|
25
|
+
class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
_FlamingoForthewinEDS_flamingoAxiosInstance.set(this, axios_1.default.create({ baseURL: 'https://neo-api.b-cdn.net/flamingo' }));
|
|
29
|
+
_FlamingoForthewinEDS_forthewinAxiosInstance.set(this, axios_1.default.create({ baseURL: 'https://api.forthewin.network' }));
|
|
30
|
+
}
|
|
31
|
+
getTokenPrices({ tokens }) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const { data: flamingoData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_flamingoAxiosInstance, "f").get('/live-data/prices/latest');
|
|
34
|
+
const prices = [];
|
|
35
|
+
const neoToken = tokens.find(({ symbol }) => symbol === 'NEO');
|
|
36
|
+
if (neoToken && !flamingoData.find(this.predicateToken(neoToken)))
|
|
37
|
+
flamingoData.forEach(item => {
|
|
38
|
+
if (item.symbol === 'bNEO')
|
|
39
|
+
flamingoData.push(Object.assign(Object.assign({}, item), { symbol: neoToken.symbol, hash: neoToken.hash }));
|
|
40
|
+
});
|
|
41
|
+
flamingoData.forEach(item => {
|
|
42
|
+
const token = tokens.find(this.predicateToken(item));
|
|
43
|
+
if (!token)
|
|
44
|
+
return;
|
|
45
|
+
prices.push({ usdPrice: item.usd_price, token });
|
|
46
|
+
});
|
|
47
|
+
if (tokens.length > prices.length) {
|
|
48
|
+
const { data: forthewinData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_forthewinAxiosInstance, "f").get('/mainnet/prices');
|
|
49
|
+
Object.entries(forthewinData).forEach(([hash, usdPrice]) => {
|
|
50
|
+
const hasPrice = !!prices.find(({ token }) => this.predicateToken({ hash })(token));
|
|
51
|
+
if (hasPrice)
|
|
52
|
+
return;
|
|
53
|
+
const foundToken = tokens.find(this.predicateToken({ hash }));
|
|
54
|
+
if (!foundToken)
|
|
55
|
+
return;
|
|
56
|
+
prices.push({ usdPrice, token: foundToken });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return prices;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
predicateToken({ hash, symbol }) {
|
|
63
|
+
const normalizedHash = (0, functions_1.normalizeHash)(hash);
|
|
64
|
+
return (params) => normalizedHash === (0, functions_1.normalizeHash)(params.hash) || (!!symbol && !!params.symbol && symbol === params.symbol);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.FlamingoForthewinEDS = FlamingoForthewinEDS;
|
|
68
|
+
_FlamingoForthewinEDS_flamingoAxiosInstance = new WeakMap(), _FlamingoForthewinEDS_forthewinAxiosInstance = new WeakMap();
|