@cityofzion/bs-ethereum 2.0.2 → 2.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.
@@ -43,12 +43,11 @@ const ethers_1 = require("ethers");
43
43
  const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
44
44
  const ethersBytes = __importStar(require("@ethersproject/bytes"));
45
45
  const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
46
- const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
47
46
  const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
48
- const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
49
- const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
50
47
  const EthersLedgerServiceEthereum_1 = require("./EthersLedgerServiceEthereum");
51
48
  const BSEthereumHelper_1 = require("./BSEthereumHelper");
49
+ const MoralisBDSEthereum_1 = require("./MoralisBDSEthereum");
50
+ const MoralisEDSEthereum_1 = require("./MoralisEDSEthereum");
52
51
  class BSEthereum {
53
52
  constructor(blockchainName, network, getLedgerTransport) {
54
53
  _BSEthereum_instances.add(this);
@@ -61,9 +60,8 @@ class BSEthereum {
61
60
  setNetwork(network) {
62
61
  __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_setTokens).call(this, network);
63
62
  this.network = network;
64
- const bitqueryNetwork = BitqueryBDSEthereum_1.BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[network.id];
65
- this.blockchainDataService = bitqueryNetwork ? new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network) : new RpcBDSEthereum_1.RpcBDSEthereum(network);
66
- this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network, this.tokens);
63
+ this.blockchainDataService = new MoralisBDSEthereum_1.MoralisBDSEthereum(network);
64
+ this.exchangeDataService = new MoralisEDSEthereum_1.MoralisEDSEthereum(network, this.blockchainDataService);
67
65
  this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network);
68
66
  }
69
67
  validateAddress(address) {
@@ -144,7 +142,7 @@ class BSEthereum {
144
142
  }
145
143
  let signer;
146
144
  if (ledgerTransport) {
147
- signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
145
+ signer = this.ledgerService.getSigner(ledgerTransport, provider);
148
146
  }
149
147
  else {
150
148
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
@@ -181,7 +179,7 @@ class BSEthereum {
181
179
  }
182
180
  let signer;
183
181
  if (ledgerTransport) {
184
- signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
182
+ signer = this.ledgerService.getSigner(ledgerTransport, provider);
185
183
  }
186
184
  else {
187
185
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
@@ -18,5 +18,5 @@ export declare class EthersLedgerServiceEthereum implements LedgerService {
18
18
  constructor(getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined);
19
19
  getAddress(transport: Transport): Promise<string>;
20
20
  getPublicKey(transport: Transport): Promise<string>;
21
- getSigner(transport: Transport): EthersLedgerSigner;
21
+ getSigner(transport: Transport, provider?: ethers.providers.Provider): EthersLedgerSigner;
22
22
  }
@@ -200,18 +200,18 @@ class EthersLedgerServiceEthereum {
200
200
  }
201
201
  getAddress(transport) {
202
202
  return __awaiter(this, void 0, void 0, function* () {
203
- const signer = new EthersLedgerSigner(transport);
203
+ const signer = this.getSigner(transport);
204
204
  return yield signer.getAddress();
205
205
  });
206
206
  }
207
207
  getPublicKey(transport) {
208
208
  return __awaiter(this, void 0, void 0, function* () {
209
- const signer = new EthersLedgerSigner(transport);
209
+ const signer = this.getSigner(transport);
210
210
  return yield signer.getPublicKey();
211
211
  });
212
212
  }
213
- getSigner(transport) {
214
- return new EthersLedgerSigner(transport, undefined, this.emitter);
213
+ getSigner(transport, provider) {
214
+ return new EthersLedgerSigner(transport, provider, this.emitter);
215
215
  }
216
216
  }
217
217
  exports.EthersLedgerServiceEthereum = EthersLedgerServiceEthereum;
@@ -0,0 +1,15 @@
1
+ import { BalanceResponse, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
2
+ import { RpcBDSEthereum } from './RpcBDSEthereum';
3
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
4
+ export declare class MoralisBDSEthereum extends RpcBDSEthereum {
5
+ static BASE_URL: string;
6
+ static SUPPORTED_CHAINS: string[];
7
+ static getClient(network: Network<BSEthereumNetworkId>): import("axios").AxiosInstance;
8
+ static isSupported(network: Network<BSEthereumNetworkId>): boolean;
9
+ constructor(network: Network<BSEthereumNetworkId>);
10
+ getBalance(address: string): Promise<BalanceResponse[]>;
11
+ getTokenInfo(hash: string): Promise<Token>;
12
+ getTransaction(hash: string): Promise<TransactionResponse>;
13
+ getTransactionsByAddress(params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
14
+ getContract(hash: string): Promise<ContractResponse>;
15
+ }
@@ -0,0 +1,323 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MoralisBDSEthereum = void 0;
16
+ const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
17
+ const BSEthereumHelper_1 = require("./BSEthereumHelper");
18
+ const axios_1 = __importDefault(require("axios"));
19
+ const ethers_1 = require("ethers");
20
+ const ERC20_1 = require("./assets/abis/ERC20");
21
+ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
22
+ static getClient(network) {
23
+ return axios_1.default.create({
24
+ baseURL: MoralisBDSEthereum.BASE_URL,
25
+ params: {
26
+ chain: `0x${Number(network.id).toString(16)}`,
27
+ },
28
+ });
29
+ }
30
+ static isSupported(network) {
31
+ return MoralisBDSEthereum.SUPPORTED_CHAINS.includes(network.id);
32
+ }
33
+ constructor(network) {
34
+ super(network);
35
+ }
36
+ getBalance(address) {
37
+ const _super = Object.create(null, {
38
+ getBalance: { get: () => super.getBalance }
39
+ });
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (!MoralisBDSEthereum.isSupported(this._network)) {
42
+ return _super.getBalance.call(this, address);
43
+ }
44
+ const client = MoralisBDSEthereum.getClient(this._network);
45
+ const { data: { balance: nativeBalance }, } = yield client.get(`${address}/balance`);
46
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
47
+ const balances = [
48
+ {
49
+ amount: nativeBalance,
50
+ token: nativeToken,
51
+ },
52
+ ];
53
+ const { data: erc20Balances } = yield client.get(`${address}/erc20`);
54
+ erc20Balances.forEach(balance => {
55
+ if (balance.possible_spam)
56
+ return;
57
+ balances.push({
58
+ amount: balance.balance,
59
+ token: {
60
+ decimals: balance.decimals,
61
+ hash: balance.token_address,
62
+ name: balance.name,
63
+ symbol: balance.symbol,
64
+ },
65
+ });
66
+ });
67
+ return balances;
68
+ });
69
+ }
70
+ getTokenInfo(hash) {
71
+ const _super = Object.create(null, {
72
+ getTokenInfo: { get: () => super.getTokenInfo }
73
+ });
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ if (!MoralisBDSEthereum.isSupported(this._network)) {
76
+ return _super.getTokenInfo.call(this, hash);
77
+ }
78
+ const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
79
+ if (nativeAsset.hash === hash)
80
+ return nativeAsset;
81
+ if (this._tokenCache.has(hash)) {
82
+ return this._tokenCache.get(hash);
83
+ }
84
+ const client = MoralisBDSEthereum.getClient(this._network);
85
+ const response = yield client.get(`/erc20/metadata`, {
86
+ params: {
87
+ addresses: [hash],
88
+ },
89
+ });
90
+ const data = response.data[0];
91
+ const token = {
92
+ decimals: Number(data.decimals),
93
+ symbol: data.symbol,
94
+ hash,
95
+ name: data.name,
96
+ };
97
+ this._tokenCache.set(hash, token);
98
+ return token;
99
+ });
100
+ }
101
+ getTransaction(hash) {
102
+ const _super = Object.create(null, {
103
+ getTransaction: { get: () => super.getTransaction }
104
+ });
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ if (!MoralisBDSEthereum.isSupported(this._network)) {
107
+ return _super.getTransaction.call(this, hash);
108
+ }
109
+ const client = MoralisBDSEthereum.getClient(this._network);
110
+ const { data } = yield client.get(`/transaction/${hash}/verbose`);
111
+ const transfers = [];
112
+ if (data.value && Number(data.value) > 0) {
113
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
114
+ transfers.push({
115
+ amount: data.value,
116
+ from: data.from_address,
117
+ to: data.to_address,
118
+ type: 'token',
119
+ token: nativeToken,
120
+ contractHash: nativeToken.hash,
121
+ });
122
+ }
123
+ if (data.logs) {
124
+ const promises = data.logs.map((log) => __awaiter(this, void 0, void 0, function* () {
125
+ var _a, _b, _c, _d;
126
+ if (!log.decoded_event)
127
+ return;
128
+ if (log.decoded_event.label.toLowerCase() !== 'transfer')
129
+ return;
130
+ const contractHash = log.address;
131
+ const amount = (_a = log.decoded_event.params.find((param) => param.name === 'value')) === null || _a === void 0 ? void 0 : _a.value;
132
+ const from = (_b = log.decoded_event.params.find((param) => param.name === 'from')) === null || _b === void 0 ? void 0 : _b.value;
133
+ const to = (_c = log.decoded_event.params.find((param) => param.name === 'to')) === null || _c === void 0 ? void 0 : _c.value;
134
+ if (!from || !to)
135
+ return;
136
+ if (amount) {
137
+ const token = yield this.getTokenInfo(contractHash);
138
+ transfers.push({
139
+ contractHash,
140
+ amount: ethers_1.ethers.utils.formatUnits(amount, token.decimals),
141
+ from,
142
+ to,
143
+ type: 'token',
144
+ });
145
+ }
146
+ const tokenId = (_d = log.decoded_event.params.find((param) => param.name === 'tokenId')) === null || _d === void 0 ? void 0 : _d.value;
147
+ if (!tokenId)
148
+ return;
149
+ transfers.push({
150
+ contractHash,
151
+ tokenId,
152
+ from,
153
+ to,
154
+ type: 'nft',
155
+ });
156
+ }));
157
+ yield Promise.allSettled(promises);
158
+ }
159
+ return {
160
+ block: Number(data.block_number),
161
+ hash,
162
+ notifications: [],
163
+ time: new Date(data.block_timestamp).getTime(),
164
+ transfers,
165
+ fee: data.transaction_fee,
166
+ };
167
+ });
168
+ }
169
+ getTransactionsByAddress(params) {
170
+ const _super = Object.create(null, {
171
+ getTransactionsByAddress: { get: () => super.getTransactionsByAddress }
172
+ });
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ if (!MoralisBDSEthereum.isSupported(this._network)) {
175
+ return _super.getTransactionsByAddress.call(this, params);
176
+ }
177
+ const client = MoralisBDSEthereum.getClient(this._network);
178
+ const { data } = yield client.get(`/wallets/${params.address}/history`, {
179
+ params: {
180
+ limit: 15,
181
+ cursor: params.cursor,
182
+ },
183
+ });
184
+ const transactions = [];
185
+ const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
186
+ const promises = data.result.map((item) => __awaiter(this, void 0, void 0, function* () {
187
+ const transfers = [];
188
+ item.native_transfers.forEach(transfer => {
189
+ transfers.push({
190
+ amount: ethers_1.ethers.utils.formatUnits(transfer.value, nativeAsset.decimals),
191
+ from: transfer.from_address,
192
+ to: transfer.to_address,
193
+ type: 'token',
194
+ token: nativeAsset,
195
+ contractHash: nativeAsset.hash,
196
+ });
197
+ });
198
+ item.erc20_transfers.forEach(transfer => {
199
+ if (transfer.possible_spam)
200
+ return;
201
+ transfers.push({
202
+ amount: ethers_1.ethers.utils.formatUnits(transfer.value, transfer.token_decimals),
203
+ from: transfer.from_address,
204
+ to: transfer.to_address,
205
+ type: 'token',
206
+ token: {
207
+ decimals: Number(transfer.token_decimals),
208
+ hash: transfer.address,
209
+ name: transfer.token_name,
210
+ symbol: transfer.token_symbol,
211
+ },
212
+ contractHash: transfer.address,
213
+ });
214
+ });
215
+ item.nft_transfers.forEach(transfer => {
216
+ transfers.push({
217
+ contractHash: transfer.token_address,
218
+ tokenId: transfer.token_id,
219
+ from: transfer.from_address,
220
+ to: transfer.to_address,
221
+ type: 'nft',
222
+ });
223
+ });
224
+ transactions.push({
225
+ block: Number(item.block_number),
226
+ hash: item.hash,
227
+ notifications: [],
228
+ time: new Date(item.block_timestamp).getTime(),
229
+ transfers,
230
+ fee: item.transaction_fee,
231
+ });
232
+ }));
233
+ yield Promise.allSettled(promises);
234
+ return {
235
+ nextCursor: data.cursor,
236
+ transactions,
237
+ };
238
+ });
239
+ }
240
+ getContract(hash) {
241
+ const _super = Object.create(null, {
242
+ getContract: { get: () => super.getContract }
243
+ });
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ if (!MoralisBDSEthereum.isSupported(this._network)) {
246
+ return _super.getContract.call(this, hash);
247
+ }
248
+ try {
249
+ const client = MoralisBDSEthereum.getClient(this._network);
250
+ const { data } = yield client.get(`erc20/metadata`, {
251
+ params: {
252
+ addresses: [hash],
253
+ },
254
+ });
255
+ const methods = [];
256
+ ERC20_1.ERC20_ABI.forEach(abi => {
257
+ var _a, _b;
258
+ if (abi.type !== 'function')
259
+ return;
260
+ const parameters = (_a = abi.inputs) === null || _a === void 0 ? void 0 : _a.map(param => ({
261
+ name: param.name,
262
+ type: param.type,
263
+ }));
264
+ methods.push({
265
+ name: (_b = abi.name) !== null && _b !== void 0 ? _b : '',
266
+ parameters: parameters !== null && parameters !== void 0 ? parameters : [],
267
+ });
268
+ });
269
+ return {
270
+ hash,
271
+ name: data[0].name,
272
+ methods,
273
+ };
274
+ }
275
+ catch (_a) {
276
+ throw new Error('Contract not found or not an ERC20 token');
277
+ }
278
+ });
279
+ }
280
+ }
281
+ exports.MoralisBDSEthereum = MoralisBDSEthereum;
282
+ MoralisBDSEthereum.BASE_URL = 'https://nxlrja2d1a.execute-api.us-east-1.amazonaws.com/production';
283
+ MoralisBDSEthereum.SUPPORTED_CHAINS = [
284
+ '1',
285
+ '11155111',
286
+ '17000',
287
+ '137',
288
+ '80002',
289
+ '56',
290
+ '97',
291
+ '42161',
292
+ '421614',
293
+ '8453',
294
+ '84532',
295
+ '10',
296
+ '11155420',
297
+ '59144',
298
+ '59141',
299
+ '43114',
300
+ '250',
301
+ '4002',
302
+ '25',
303
+ '11297108109',
304
+ '2020',
305
+ '100',
306
+ '10200',
307
+ '88888',
308
+ '88882',
309
+ '369',
310
+ '1284',
311
+ '1285',
312
+ '1287',
313
+ '81457',
314
+ '168587773',
315
+ '324',
316
+ '300',
317
+ '5000',
318
+ '5003',
319
+ '1101',
320
+ '2442',
321
+ '7000',
322
+ '7001',
323
+ ];
@@ -0,0 +1,8 @@
1
+ import { BlockchainDataService, CryptoCompareEDS, ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, Network, TokenPricesHistoryResponse, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
3
+ export declare class MoralisEDSEthereum extends CryptoCompareEDS implements ExchangeDataService {
4
+ #private;
5
+ constructor(network: Network<BSEthereumNetworkId>, blockchainDataService: BlockchainDataService);
6
+ getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
7
+ getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
8
+ }
@@ -0,0 +1,139 @@
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 _MoralisEDSEthereum_instances, _MoralisEDSEthereum_network, _MoralisEDSEthereum_blockchainDataService, _MoralisEDSEthereum_numberOfBlockByHour, _MoralisEDSEthereum_numberOfBlockByDay, _MoralisEDSEthereum_getWrappedNativeToken;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.MoralisEDSEthereum = void 0;
25
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
26
+ const BSEthereumHelper_1 = require("./BSEthereumHelper");
27
+ const MoralisBDSEthereum_1 = require("./MoralisBDSEthereum");
28
+ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
29
+ constructor(network, blockchainDataService) {
30
+ super();
31
+ _MoralisEDSEthereum_instances.add(this);
32
+ _MoralisEDSEthereum_network.set(this, void 0);
33
+ _MoralisEDSEthereum_blockchainDataService.set(this, void 0);
34
+ _MoralisEDSEthereum_numberOfBlockByHour.set(this, (15 / 60) * 60);
35
+ _MoralisEDSEthereum_numberOfBlockByDay.set(this, __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") * 24);
36
+ __classPrivateFieldSet(this, _MoralisEDSEthereum_network, network, "f");
37
+ __classPrivateFieldSet(this, _MoralisEDSEthereum_blockchainDataService, blockchainDataService, "f");
38
+ }
39
+ getTokenPrices(params) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
42
+ throw new Error('Exchange is only available on mainnet');
43
+ if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
44
+ throw new Error('Exchange is not supported on this network');
45
+ const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
46
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
47
+ let wrappedNativeToken;
48
+ if (params.tokens.some(token => token.symbol === nativeToken.symbol)) {
49
+ wrappedNativeToken = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
50
+ }
51
+ const tokensBody = params.tokens.map(token => {
52
+ if (token.symbol !== nativeToken.symbol) {
53
+ return {
54
+ token_address: token.hash,
55
+ };
56
+ }
57
+ return {
58
+ token_address: wrappedNativeToken.hash,
59
+ };
60
+ });
61
+ const { data } = yield client.post(`/erc20/prices`, {
62
+ tokens: tokensBody,
63
+ });
64
+ return data.map(item => {
65
+ let token;
66
+ if (item.tokenAddress === (wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash)) {
67
+ token = nativeToken;
68
+ }
69
+ else {
70
+ token = {
71
+ decimals: Number(item.tokenDecimals),
72
+ hash: item.tokenAddress,
73
+ name: item.tokenName,
74
+ symbol: item.tokenSymbol,
75
+ };
76
+ }
77
+ return {
78
+ usdPrice: item.usdPrice,
79
+ token,
80
+ };
81
+ });
82
+ });
83
+ }
84
+ getTokenPriceHistory(params) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
87
+ throw new Error('Exchange is only available on mainnet');
88
+ if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
89
+ throw new Error('Exchange is not supported on this network');
90
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
91
+ let token;
92
+ if (params.token.hash === nativeToken.hash) {
93
+ token = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
94
+ }
95
+ else {
96
+ token = params.token;
97
+ }
98
+ const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
99
+ const actualBlockNumber = (yield __classPrivateFieldGet(this, _MoralisEDSEthereum_blockchainDataService, "f").getBlockHeight()) - 1; // Last block is not included
100
+ const history = [];
101
+ yield Promise.allSettled(Array.from({ length: params.limit }).map((_, index) => __awaiter(this, void 0, void 0, function* () {
102
+ const block = actualBlockNumber - index * (params.type === 'hour' ? __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") : __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByDay, "f"));
103
+ const priceResponse = yield client.get(`/erc20/${token.hash}/price`, {
104
+ params: {
105
+ to_block: block,
106
+ },
107
+ });
108
+ const blockResponse = yield client.get(`/block/${block}`);
109
+ history.push({
110
+ timestamp: new Date(blockResponse.data.timestamp).getTime(),
111
+ usdPrice: priceResponse.data.usdPrice,
112
+ token: params.token,
113
+ });
114
+ })));
115
+ return history;
116
+ });
117
+ }
118
+ }
119
+ exports.MoralisEDSEthereum = MoralisEDSEthereum;
120
+ _MoralisEDSEthereum_network = new WeakMap(), _MoralisEDSEthereum_blockchainDataService = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByHour = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByDay = new WeakMap(), _MoralisEDSEthereum_instances = new WeakSet(), _MoralisEDSEthereum_getWrappedNativeToken = function _MoralisEDSEthereum_getWrappedNativeToken() {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
123
+ const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
124
+ const { data } = yield client.get('/erc20/metadata/symbols', {
125
+ params: {
126
+ symbols: [`W${nativeToken.symbol}`],
127
+ },
128
+ });
129
+ const wrapperToken = data.find(token => token.verified_contract && !token.possible_spam);
130
+ if (!wrapperToken)
131
+ throw new Error('Wrapper token not found');
132
+ return {
133
+ decimals: Number(wrapperToken.decimals),
134
+ hash: wrapperToken.address,
135
+ name: wrapperToken.name,
136
+ symbol: wrapperToken.symbol,
137
+ };
138
+ });
139
+ };
@@ -1,12 +1,13 @@
1
1
  import { BalanceResponse, BlockchainDataService, ContractResponse, Network, RpcResponse, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
2
2
  import { BSEthereumNetworkId } from './BSEthereumHelper';
3
3
  export declare class RpcBDSEthereum implements BlockchainDataService {
4
- #private;
4
+ _network: Network<BSEthereumNetworkId>;
5
+ _tokenCache: Map<string, Token>;
5
6
  maxTimeToConfirmTransactionInMs: number;
6
7
  constructor(network: Network<BSEthereumNetworkId>);
7
8
  getTransaction(hash: string): Promise<TransactionResponse>;
8
9
  getTransactionsByAddress(_params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
9
- getContract(): Promise<ContractResponse>;
10
+ getContract(_hash: string): Promise<ContractResponse>;
10
11
  getTokenInfo(hash: string): Promise<Token>;
11
12
  getBalance(address: string): Promise<BalanceResponse[]>;
12
13
  getBlockHeight(): Promise<number>;