@cityofzion/blockchain-service 1.0.1 → 1.1.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.
@@ -1,5 +1,5 @@
1
1
  import { AccountWithDerivationPath, BlockchainService } from './interfaces';
2
- export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName> = BlockchainService<BSCustomName>> {
2
+ export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName, string> = BlockchainService<BSCustomName, string>> {
3
3
  #private;
4
4
  readonly blockchainServicesByName: Record<BSCustomName, BSCustom>;
5
5
  constructor(blockchainServices: Record<BSCustomName, BSCustom>);
@@ -8,8 +8,8 @@ export declare class BSAggregator<BSCustomName extends string = string, BSCustom
8
8
  validateTextAllBlockchains(text: string): boolean;
9
9
  validateKeyAllBlockchains(wif: string): boolean;
10
10
  validateEncryptedAllBlockchains(keyOrJson: string): boolean;
11
- getBlockchainNameByAddress(address: string): BSCustomName | undefined;
12
- getBlockchainNameByKey(wif: string): BSCustomName | undefined;
13
- getBlockchainNameByEncrypted(keyOrJson: string): BSCustomName | undefined;
11
+ getBlockchainNameByAddress(address: string): BSCustomName[];
12
+ getBlockchainNameByKey(wif: string): BSCustomName[];
13
+ getBlockchainNameByEncrypted(keyOrJson: string): BSCustomName[];
14
14
  generateAccountFromMnemonicAllBlockchains(mnemonic: string, skippedAddresses?: string[]): Promise<Map<BSCustomName, AccountWithDerivationPath[]>>;
15
15
  }
@@ -47,16 +47,13 @@ class BSAggregator {
47
47
  return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateEncrypted(keyOrJson));
48
48
  }
49
49
  getBlockchainNameByAddress(address) {
50
- var _a;
51
- return (_a = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").find(bs => bs.validateAddress(address))) === null || _a === void 0 ? void 0 : _a.blockchainName;
50
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateAddress(address)).map(bs => bs.blockchainName);
52
51
  }
53
52
  getBlockchainNameByKey(wif) {
54
- var _a;
55
- return (_a = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").find(bs => bs.validateKey(wif))) === null || _a === void 0 ? void 0 : _a.blockchainName;
53
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateKey(wif)).map(bs => bs.blockchainName);
56
54
  }
57
55
  getBlockchainNameByEncrypted(keyOrJson) {
58
- var _a;
59
- return (_a = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").find(bs => bs.validateEncrypted(keyOrJson))) === null || _a === void 0 ? void 0 : _a.blockchainName;
56
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateEncrypted(keyOrJson)).map(bs => bs.blockchainName);
60
57
  }
61
58
  generateAccountFromMnemonicAllBlockchains(mnemonic, skippedAddresses) {
62
59
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,7 +1,8 @@
1
- import { Currency, ExchangeDataService, GetTokenPriceHistory, Token, TokenPricesHistoryResponse, TokenPricesResponse } from './interfaces';
1
+ import { ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, TokenPricesHistoryResponse, TokenPricesResponse } from './interfaces';
2
2
  export declare class CryptoCompareEDS implements ExchangeDataService {
3
3
  #private;
4
- constructor(tokens?: Token[]);
5
- getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
6
- getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
4
+ constructor();
5
+ getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
6
+ getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
7
+ getCurrencyRatio(currency: string): Promise<number>;
7
8
  }
@@ -22,39 +22,31 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
22
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
- var _CryptoCompareEDS_axiosInstance, _CryptoCompareEDS_tokens;
25
+ var _CryptoCompareEDS_axiosInstance;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.CryptoCompareEDS = void 0;
28
28
  const axios_1 = __importDefault(require("axios"));
29
29
  class CryptoCompareEDS {
30
- constructor(tokens = []) {
30
+ constructor() {
31
31
  _CryptoCompareEDS_axiosInstance.set(this, void 0);
32
- _CryptoCompareEDS_tokens.set(this, void 0);
33
- __classPrivateFieldSet(this, _CryptoCompareEDS_tokens, tokens, "f");
34
32
  __classPrivateFieldSet(this, _CryptoCompareEDS_axiosInstance, axios_1.default.create({ baseURL: 'https://min-api.cryptocompare.com' }), "f");
35
33
  }
36
- getTokenPrices(currency) {
34
+ getTokenPrices(params) {
37
35
  return __awaiter(this, void 0, void 0, function* () {
38
- const tokenSymbols = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").map(token => token.symbol);
39
36
  const { data: prices } = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get('/data/pricemultifull', {
40
37
  params: {
41
- fsyms: tokenSymbols.join(','),
42
- tsyms: currency,
38
+ fsyms: params.tokens.map(token => token.symbol).join(','),
39
+ tsyms: 'USD',
43
40
  },
44
41
  });
45
- return Object.entries(prices.RAW)
46
- .map(([symbol, priceObject]) => {
47
- const price = priceObject[currency].PRICE;
48
- const token = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").find(token => token.symbol === symbol);
49
- if (!token || !price)
50
- return;
42
+ return Object.entries(prices.RAW).map(([symbol, priceObject]) => {
43
+ const usdPrice = priceObject.USD.PRICE;
44
+ const token = params.tokens.find(token => token.symbol === symbol);
51
45
  return {
52
- symbol,
53
- price,
54
- hash: token === null || token === void 0 ? void 0 : token.hash,
46
+ usdPrice,
47
+ token,
55
48
  };
56
- })
57
- .filter((price) => price !== undefined);
49
+ });
58
50
  });
59
51
  }
60
52
  getTokenPriceHistory(params) {
@@ -62,26 +54,28 @@ class CryptoCompareEDS {
62
54
  const path = `/data/${params.type === 'hour' ? 'histohour' : 'histoday'}`;
63
55
  const response = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get(path, {
64
56
  params: {
65
- fsym: params.tokenSymbol,
66
- tsym: params.currency,
57
+ fsym: params.token.symbol,
58
+ tsym: 'USD',
67
59
  limit: params.limit,
68
60
  },
69
61
  });
70
62
  const history = [];
71
63
  response.data.Data.forEach(data => {
72
- const token = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").find(token => token.symbol === params.tokenSymbol);
73
- if (!token)
74
- return;
75
64
  history.push({
76
- price: data.close,
65
+ usdPrice: data.close,
77
66
  timestamp: data.time,
78
- symbol: params.tokenSymbol,
79
- hash: token.hash,
67
+ token: params.token,
80
68
  });
81
69
  });
82
70
  return history;
83
71
  });
84
72
  }
73
+ getCurrencyRatio(currency) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const { data } = yield axios_1.default.get(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`);
76
+ return data;
77
+ });
78
+ }
85
79
  }
86
80
  exports.CryptoCompareEDS = CryptoCompareEDS;
87
- _CryptoCompareEDS_axiosInstance = new WeakMap(), _CryptoCompareEDS_tokens = new WeakMap();
81
+ _CryptoCompareEDS_axiosInstance = new WeakMap();
@@ -14,8 +14,9 @@ export interface Token {
14
14
  hash: string;
15
15
  decimals: number;
16
16
  }
17
+ export type NetworkId<T extends string = string> = T | (string & {});
17
18
  export type Network<T extends string = string> = {
18
- id: T;
19
+ id: NetworkId<T>;
19
20
  name: string;
20
21
  url: string;
21
22
  };
@@ -108,13 +109,15 @@ export type ContractParameter = {
108
109
  type: string;
109
110
  };
110
111
  export type TransactionsByAddressResponse = {
111
- totalCount: number;
112
- limit: number;
112
+ totalCount?: number;
113
+ limit?: number;
114
+ nextCursor?: string;
113
115
  transactions: TransactionResponse[];
114
116
  };
115
117
  export type TransactionsByAddressParams = {
116
118
  address: string;
117
119
  page?: number;
120
+ cursor?: string;
118
121
  };
119
122
  export type ContractMethod = {
120
123
  name: string;
@@ -148,26 +151,26 @@ export interface BDSClaimable {
148
151
  getUnclaimed(address: string): Promise<string>;
149
152
  }
150
153
  export type TokenPricesResponse = {
151
- price: number;
152
- symbol: string;
153
- hash: string;
154
+ usdPrice: number;
155
+ token: Token;
154
156
  };
155
157
  export type TokenPricesHistoryResponse = {
156
- price: number;
158
+ usdPrice: number;
157
159
  timestamp: number;
158
- symbol: string;
159
- hash: string;
160
+ token: Token;
160
161
  };
161
- export type Currency = 'USD' | 'BRL' | 'EUR';
162
- export type GetTokenPriceHistory = {
163
- tokenSymbol: string;
164
- currency: Currency;
162
+ export type GetTokenPriceHistoryParams = {
163
+ token: Token;
165
164
  type: 'hour' | 'day';
166
165
  limit: number;
167
166
  };
167
+ export type GetTokenPricesParams = {
168
+ tokens: Token[];
169
+ };
168
170
  export interface ExchangeDataService {
169
- getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
170
- getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
171
+ getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
172
+ getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
173
+ getCurrencyRatio(currency: string): Promise<number>;
171
174
  }
172
175
  export interface NftResponse {
173
176
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",