@cityofzion/bs-ethereum 2.0.3 → 2.1.1

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) {
@@ -152,7 +150,7 @@ class BSEthereum {
152
150
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
153
151
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
154
152
  let transactionParams;
155
- const isNative = this.feeToken.hash === param.intent.tokenHash;
153
+ const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
156
154
  if (isNative) {
157
155
  transactionParams = {
158
156
  to: param.intent.receiverAddress,
@@ -188,7 +186,7 @@ class BSEthereum {
188
186
  }
189
187
  const gasPrice = yield provider.getGasPrice();
190
188
  let estimated;
191
- const isNative = this.feeToken.hash === param.intent.tokenHash;
189
+ const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
192
190
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
193
191
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
194
192
  if (!isNative) {
@@ -24,4 +24,5 @@ export declare class BSEthereumHelper {
24
24
  static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
25
25
  static getRpcList(network: Network<BSEthereumNetworkId>): string[];
26
26
  static isMainnet(network: Network<BSEthereumNetworkId>): boolean;
27
+ static normalizeHash(hash: string): string;
27
28
  }
@@ -9,7 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.BSEthereumHelper = void 0;
10
10
  class BSEthereumHelper {
11
11
  static getNativeAsset(network) {
12
- return Object.assign(Object.assign({}, __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_NATIVE_ASSET)), { symbol: this.getNativeSymbol(network) });
12
+ const symbol = this.getNativeSymbol(network);
13
+ return Object.assign(Object.assign({}, __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_NATIVE_ASSET)), { symbol, name: symbol });
13
14
  }
14
15
  static getNativeSymbol(network) {
15
16
  var _b;
@@ -22,6 +23,9 @@ class BSEthereumHelper {
22
23
  static isMainnet(network) {
23
24
  return this.MAINNET_NETWORK_IDS.includes(network.id);
24
25
  }
26
+ static normalizeHash(hash) {
27
+ return hash.startsWith('0x') ? hash.slice(2) : hash;
28
+ }
25
29
  }
26
30
  exports.BSEthereumHelper = BSEthereumHelper;
27
31
  _a = BSEthereumHelper;
@@ -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: ethers_1.ethers.utils.formatUnits(nativeBalance, nativeToken.decimals),
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: ethers_1.ethers.utils.formatUnits(balance.balance, balance.decimals),
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 (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(nativeAsset.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(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: ethers_1.ethers.utils.formatUnits(data.value, nativeToken.decimals),
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,141 @@
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
+ var _a;
66
+ let token;
67
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(item.tokenAddress) ===
68
+ BSEthereumHelper_1.BSEthereumHelper.normalizeHash((_a = wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash) !== null && _a !== void 0 ? _a : '')) {
69
+ token = nativeToken;
70
+ }
71
+ else {
72
+ token = {
73
+ decimals: Number(item.tokenDecimals),
74
+ hash: item.tokenAddress,
75
+ name: item.tokenName,
76
+ symbol: item.tokenSymbol,
77
+ };
78
+ }
79
+ return {
80
+ usdPrice: item.usdPrice,
81
+ token,
82
+ };
83
+ });
84
+ });
85
+ }
86
+ getTokenPriceHistory(params) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
89
+ throw new Error('Exchange is only available on mainnet');
90
+ if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
91
+ throw new Error('Exchange is not supported on this network');
92
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
93
+ let token;
94
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(params.token.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(nativeToken.hash)) {
95
+ token = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
96
+ }
97
+ else {
98
+ token = params.token;
99
+ }
100
+ const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
101
+ const actualBlockNumber = (yield __classPrivateFieldGet(this, _MoralisEDSEthereum_blockchainDataService, "f").getBlockHeight()) - 1; // Last block is not included
102
+ const history = [];
103
+ yield Promise.allSettled(Array.from({ length: params.limit }).map((_, index) => __awaiter(this, void 0, void 0, function* () {
104
+ const block = actualBlockNumber - index * (params.type === 'hour' ? __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") : __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByDay, "f"));
105
+ const priceResponse = yield client.get(`/erc20/${token.hash}/price`, {
106
+ params: {
107
+ to_block: block,
108
+ },
109
+ });
110
+ const blockResponse = yield client.get(`/block/${block}`);
111
+ history.push({
112
+ timestamp: new Date(blockResponse.data.timestamp).getTime(),
113
+ usdPrice: priceResponse.data.usdPrice,
114
+ token: params.token,
115
+ });
116
+ })));
117
+ return history;
118
+ });
119
+ }
120
+ }
121
+ exports.MoralisEDSEthereum = MoralisEDSEthereum;
122
+ _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() {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
125
+ const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
126
+ const { data } = yield client.get('/erc20/metadata/symbols', {
127
+ params: {
128
+ symbols: [`W${nativeToken.symbol}`],
129
+ },
130
+ });
131
+ const wrapperToken = data.find(token => token.verified_contract && !token.possible_spam);
132
+ if (!wrapperToken)
133
+ throw new Error('Wrapper token not found');
134
+ return {
135
+ decimals: Number(wrapperToken.decimals),
136
+ hash: wrapperToken.address,
137
+ name: wrapperToken.name,
138
+ symbol: wrapperToken.symbol,
139
+ };
140
+ });
141
+ };
@@ -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>;