@cityofzion/bs-ethereum 2.13.3 → 2.13.5

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.
@@ -8,28 +8,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
17
+ if (kind === "m") throw new TypeError("Private method is not writable");
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
19
+ 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");
20
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
21
+ };
22
+ var _RpcBDSEthereum_instances, _RpcBDSEthereum_providerInstance, _RpcBDSEthereum_provider_get;
11
23
  Object.defineProperty(exports, "__esModule", { value: true });
12
24
  exports.RpcBDSEthereum = void 0;
13
25
  const ethers_1 = require("ethers");
14
26
  const BSEthereumHelper_1 = require("../../helpers/BSEthereumHelper");
15
27
  const ERC20_1 = require("../../assets/abis/ERC20");
16
28
  class RpcBDSEthereum {
17
- constructor(network, tokenService) {
29
+ constructor(service) {
30
+ _RpcBDSEthereum_instances.add(this);
31
+ this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5; // 5 minutes
18
32
  this._tokenCache = new Map();
19
- this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5;
20
- this._network = network;
21
- this._tokenService = tokenService;
33
+ _RpcBDSEthereum_providerInstance.set(this, void 0);
34
+ this._service = service;
22
35
  }
23
36
  getTransaction(hash) {
24
37
  return __awaiter(this, void 0, void 0, function* () {
25
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
26
- const transaction = yield provider.getTransaction(hash);
38
+ const transaction = yield __classPrivateFieldGet(this, _RpcBDSEthereum_instances, "a", _RpcBDSEthereum_provider_get).getTransaction(hash);
27
39
  if (!transaction || !transaction.blockHash || !transaction.to)
28
40
  throw new Error('Transaction not found');
29
- const block = yield provider.getBlock(transaction.blockHash);
41
+ const block = yield __classPrivateFieldGet(this, _RpcBDSEthereum_instances, "a", _RpcBDSEthereum_provider_get).getBlock(transaction.blockHash);
30
42
  if (!block)
31
43
  throw new Error('Block not found');
32
- const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
44
+ const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
33
45
  return {
34
46
  block: block.number,
35
47
  time: block.timestamp,
@@ -51,7 +63,7 @@ class RpcBDSEthereum {
51
63
  }
52
64
  getTransactionsByAddress(_params) {
53
65
  return __awaiter(this, void 0, void 0, function* () {
54
- throw new Error("RPC doesn't support get transactions history of address");
66
+ throw new Error('Method not supported.');
55
67
  });
56
68
  }
57
69
  getFullTransactionsByAddress(_params) {
@@ -66,22 +78,21 @@ class RpcBDSEthereum {
66
78
  }
67
79
  getContract(_hash) {
68
80
  return __awaiter(this, void 0, void 0, function* () {
69
- throw new Error("RPC doesn't support contract info");
81
+ throw new Error('Method not supported.');
70
82
  });
71
83
  }
72
84
  getTokenInfo(hash) {
73
85
  return __awaiter(this, void 0, void 0, function* () {
74
- const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
75
- if (this._tokenService.predicateByHash(nativeAsset, hash))
86
+ const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
87
+ if (this._service.tokenService.predicateByHash(nativeAsset, hash))
76
88
  return nativeAsset;
77
89
  if (this._tokenCache.has(hash)) {
78
90
  return this._tokenCache.get(hash);
79
91
  }
80
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
81
- const contract = new ethers_1.ethers.Contract(hash, ERC20_1.ERC20_ABI, provider);
92
+ const contract = new ethers_1.ethers.Contract(hash, ERC20_1.ERC20_ABI, __classPrivateFieldGet(this, _RpcBDSEthereum_instances, "a", _RpcBDSEthereum_provider_get));
82
93
  const decimals = yield contract.decimals();
83
94
  const symbol = yield contract.symbol();
84
- const token = this._tokenService.normalizeToken({
95
+ const token = this._service.tokenService.normalizeToken({
85
96
  decimals,
86
97
  symbol,
87
98
  hash,
@@ -93,9 +104,8 @@ class RpcBDSEthereum {
93
104
  }
94
105
  getBalance(address) {
95
106
  return __awaiter(this, void 0, void 0, function* () {
96
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
97
- const balance = yield provider.getBalance(address);
98
- const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
107
+ const balance = yield __classPrivateFieldGet(this, _RpcBDSEthereum_instances, "a", _RpcBDSEthereum_provider_get).getBalance(address);
108
+ const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
99
109
  return [
100
110
  {
101
111
  amount: ethers_1.ethers.utils.formatEther(balance),
@@ -106,43 +116,14 @@ class RpcBDSEthereum {
106
116
  }
107
117
  getBlockHeight() {
108
118
  return __awaiter(this, void 0, void 0, function* () {
109
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
110
- return yield provider.getBlockNumber();
111
- });
112
- }
113
- getRpcList() {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- const list = [];
116
- const urls = BSEthereumHelper_1.BSEthereumHelper.getRpcList(this._network);
117
- const promises = urls.map(url => {
118
- // eslint-disable-next-line no-async-promise-executor
119
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
120
- const timeout = setTimeout(() => {
121
- resolve();
122
- }, 5000);
123
- try {
124
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(url);
125
- const timeStart = Date.now();
126
- const height = yield provider.getBlockNumber();
127
- const latency = Date.now() - timeStart;
128
- list.push({
129
- url,
130
- height,
131
- latency,
132
- });
133
- }
134
- catch (_a) {
135
- /* empty */
136
- }
137
- finally {
138
- resolve();
139
- clearTimeout(timeout);
140
- }
141
- }));
142
- });
143
- yield Promise.allSettled(promises);
144
- return list;
119
+ return yield __classPrivateFieldGet(this, _RpcBDSEthereum_instances, "a", _RpcBDSEthereum_provider_get).getBlockNumber();
145
120
  });
146
121
  }
147
122
  }
148
123
  exports.RpcBDSEthereum = RpcBDSEthereum;
124
+ _RpcBDSEthereum_providerInstance = new WeakMap(), _RpcBDSEthereum_instances = new WeakSet(), _RpcBDSEthereum_provider_get = function _RpcBDSEthereum_provider_get() {
125
+ if (!__classPrivateFieldGet(this, _RpcBDSEthereum_providerInstance, "f")) {
126
+ __classPrivateFieldSet(this, _RpcBDSEthereum_providerInstance, new ethers_1.ethers.providers.JsonRpcProvider(this._service.network.url), "f");
127
+ }
128
+ return __classPrivateFieldGet(this, _RpcBDSEthereum_providerInstance, "f");
129
+ };
@@ -1,8 +1,11 @@
1
- import { BlockchainDataService, CryptoCompareEDS, ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, Network, TokenPricesHistoryResponse, TokenPricesResponse, TokenService } from '@cityofzion/blockchain-service';
2
- import { BSEthereumNetworkId } from '../../constants/BSEthereumConstants';
3
- export declare class MoralisEDSEthereum extends CryptoCompareEDS implements ExchangeDataService {
1
+ import { CryptoCompareEDS, TGetTokenPriceHistoryParams, TGetTokenPricesParams, TBSNetworkId, TTokenPricesHistoryResponse, TTokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ import { IBSEthereum } from '../../types';
3
+ export declare class MoralisEDSEthereum<N extends string, A extends TBSNetworkId> extends CryptoCompareEDS {
4
4
  #private;
5
- constructor(network: Network<BSEthereumNetworkId>, blockchainDataService: BlockchainDataService, tokenService: TokenService);
6
- getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
7
- getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
5
+ static readonly NUMBERS_OF_BLOCK_BY_HOUR: number;
6
+ static readonly NUMBER_OF_BLOCK_BY_DAY: number;
7
+ static readonly MAX_TOKEN_PRICES_PER_CALL = 24;
8
+ constructor(service: IBSEthereum<N, A>);
9
+ getTokenPrices({ tokens }: TGetTokenPricesParams): Promise<TTokenPricesResponse[]>;
10
+ getTokenPriceHistory(params: TGetTokenPriceHistoryParams): Promise<TTokenPricesHistoryResponse[]>;
8
11
  }
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
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
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
21
  };
22
- var _MoralisEDSEthereum_instances, _MoralisEDSEthereum_network, _MoralisEDSEthereum_blockchainDataService, _MoralisEDSEthereum_numberOfBlockByHour, _MoralisEDSEthereum_numberOfBlockByDay, _MoralisEDSEthereum_maxTokenPricesPerCall, _MoralisEDSEthereum_tokenService, _MoralisEDSEthereum_getWrappedNativeToken;
22
+ var _MoralisEDSEthereum_instances, _MoralisEDSEthereum_service, _MoralisEDSEthereum_apiInstance, _MoralisEDSEthereum_api_get, _MoralisEDSEthereum_getWrappedNativeToken;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.MoralisEDSEthereum = void 0;
25
25
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
@@ -27,65 +27,58 @@ const BSEthereumConstants_1 = require("../../constants/BSEthereumConstants");
27
27
  const BSEthereumHelper_1 = require("../../helpers/BSEthereumHelper");
28
28
  const MoralisBDSEthereum_1 = require("../blockchain-data/MoralisBDSEthereum");
29
29
  class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
30
- constructor(network, blockchainDataService, tokenService) {
30
+ constructor(service) {
31
31
  super();
32
32
  _MoralisEDSEthereum_instances.add(this);
33
- _MoralisEDSEthereum_network.set(this, void 0);
34
- _MoralisEDSEthereum_blockchainDataService.set(this, void 0);
35
- _MoralisEDSEthereum_numberOfBlockByHour.set(this, (15 / 60) * 60);
36
- _MoralisEDSEthereum_numberOfBlockByDay.set(this, __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") * 24);
37
- _MoralisEDSEthereum_maxTokenPricesPerCall.set(this, 24);
38
- _MoralisEDSEthereum_tokenService.set(this, void 0);
39
- __classPrivateFieldSet(this, _MoralisEDSEthereum_network, network, "f");
40
- __classPrivateFieldSet(this, _MoralisEDSEthereum_blockchainDataService, blockchainDataService, "f");
41
- __classPrivateFieldSet(this, _MoralisEDSEthereum_tokenService, tokenService, "f");
33
+ _MoralisEDSEthereum_service.set(this, void 0);
34
+ _MoralisEDSEthereum_apiInstance.set(this, void 0);
35
+ __classPrivateFieldSet(this, _MoralisEDSEthereum_service, service, "f");
42
36
  }
43
- getTokenPrices(params) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
37
+ getTokenPrices(_a) {
38
+ return __awaiter(this, arguments, void 0, function* ({ tokens }) {
39
+ if (!BSEthereumHelper_1.BSEthereumHelper.isMainnetNetwork(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f")))
46
40
  throw new Error('Exchange is only available on mainnet');
47
- if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
41
+ if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network))
48
42
  throw new Error('Exchange is not supported on this network');
49
- const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
50
- const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
43
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network);
51
44
  const tokensBody = [];
52
45
  let wrappedNativeToken;
53
- if (params.tokens.some(token => token.symbol === nativeToken.symbol)) {
46
+ if (tokens.some(token => token.symbol === nativeToken.symbol)) {
54
47
  try {
55
48
  wrappedNativeToken = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
56
49
  if (wrappedNativeToken) {
57
- tokensBody.push({ token_address: wrappedNativeToken.hash });
50
+ tokensBody.push({ token_address: wrappedNativeToken.hash.toLowerCase() });
58
51
  }
59
52
  }
60
- catch (_a) {
53
+ catch (_b) {
61
54
  /* empty */
62
55
  }
63
56
  }
64
- params.tokens.forEach(token => {
57
+ tokens.forEach(token => {
65
58
  if (token.symbol !== nativeToken.symbol) {
66
- tokensBody.push({ token_address: token.hash });
59
+ tokensBody.push({ token_address: token.hash.toLowerCase() });
67
60
  }
68
61
  });
69
62
  if (tokensBody.length === 0)
70
63
  return [];
71
64
  const splitTokensBody = [];
72
- for (let i = 0; i < tokensBody.length; i += __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")) {
73
- splitTokensBody.push(tokensBody.slice(i, i + __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")));
65
+ for (let i = 0; i < tokensBody.length; i += MoralisEDSEthereum.MAX_TOKEN_PRICES_PER_CALL) {
66
+ splitTokensBody.push(tokensBody.slice(i, i + MoralisEDSEthereum.MAX_TOKEN_PRICES_PER_CALL));
74
67
  }
75
68
  const response = [];
76
69
  yield Promise.allSettled(splitTokensBody.map((body) => __awaiter(this, void 0, void 0, function* () {
77
- const { data } = yield client.post('/erc20/prices', {
70
+ const { data } = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "a", _MoralisEDSEthereum_api_get).post('/erc20/prices', {
78
71
  tokens: body,
79
72
  });
80
73
  data.forEach(item => {
81
74
  let token;
82
- if (wrappedNativeToken && __classPrivateFieldGet(this, _MoralisEDSEthereum_tokenService, "f").predicateByHash(wrappedNativeToken, item.tokenAddress)) {
75
+ if (wrappedNativeToken && __classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").tokenService.predicateByHash(wrappedNativeToken, item.tokenAddress)) {
83
76
  token = nativeToken;
84
77
  }
85
78
  else {
86
79
  token = {
87
80
  decimals: Number(item.tokenDecimals),
88
- hash: item.tokenAddress,
81
+ hash: __classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").tokenService.normalizeHash(item.tokenAddress),
89
82
  name: item.tokenName,
90
83
  symbol: item.tokenSymbol,
91
84
  };
@@ -101,31 +94,36 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
101
94
  }
102
95
  getTokenPriceHistory(params) {
103
96
  return __awaiter(this, void 0, void 0, function* () {
104
- if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
97
+ if (!BSEthereumHelper_1.BSEthereumHelper.isMainnetNetwork(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f")))
105
98
  throw new Error('Exchange is only available on mainnet');
106
- if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
99
+ if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network))
107
100
  throw new Error('Exchange is not supported on this network');
108
- const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
101
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network);
109
102
  let token;
110
- if (__classPrivateFieldGet(this, _MoralisEDSEthereum_tokenService, "f").predicateByHash(nativeToken, params.token)) {
103
+ if (__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").tokenService.predicateByHash(nativeToken, params.token)) {
111
104
  token = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
112
105
  }
113
106
  else {
114
107
  token = params.token;
115
108
  }
116
- const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
117
- const currentBlockNumber = (yield __classPrivateFieldGet(this, _MoralisEDSEthereum_blockchainDataService, "f").getBlockHeight()) - 1; // Last block is not included
109
+ const currentBlockNumber = (yield __classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").blockchainDataService.getBlockHeight()) - 1; // Last block is not included
118
110
  const tokensBody = Array.from({ length: params.limit }).map((_, index) => ({
119
111
  token_address: token.hash,
120
- to_block: currentBlockNumber - index * (params.type === 'hour' ? __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") : __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByDay, "f")),
112
+ to_block: currentBlockNumber -
113
+ index *
114
+ (params.type === 'hour'
115
+ ? MoralisEDSEthereum.NUMBERS_OF_BLOCK_BY_HOUR
116
+ : MoralisEDSEthereum.NUMBER_OF_BLOCK_BY_DAY),
121
117
  }));
122
118
  const splitTokensBody = [];
123
- for (let i = 0; i < tokensBody.length; i += __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")) {
124
- splitTokensBody.push(tokensBody.slice(i, i + __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")));
119
+ for (let i = 0; i < tokensBody.length; i += MoralisEDSEthereum.MAX_TOKEN_PRICES_PER_CALL) {
120
+ splitTokensBody.push(tokensBody.slice(i, i + MoralisEDSEthereum.MAX_TOKEN_PRICES_PER_CALL));
125
121
  }
126
122
  const history = [];
127
123
  yield Promise.allSettled(splitTokensBody.map((body) => __awaiter(this, void 0, void 0, function* () {
128
- const priceResponse = yield client.post('/erc20/prices', { tokens: body });
124
+ const priceResponse = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "a", _MoralisEDSEthereum_api_get).post('/erc20/prices', {
125
+ tokens: body,
126
+ });
129
127
  priceResponse.data.forEach(item => {
130
128
  history.push({
131
129
  timestamp: Number(item.blockTimestamp),
@@ -139,13 +137,21 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
139
137
  }
140
138
  }
141
139
  exports.MoralisEDSEthereum = MoralisEDSEthereum;
142
- _MoralisEDSEthereum_network = new WeakMap(), _MoralisEDSEthereum_blockchainDataService = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByHour = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByDay = new WeakMap(), _MoralisEDSEthereum_maxTokenPricesPerCall = new WeakMap(), _MoralisEDSEthereum_tokenService = new WeakMap(), _MoralisEDSEthereum_instances = new WeakSet(), _MoralisEDSEthereum_getWrappedNativeToken = function _MoralisEDSEthereum_getWrappedNativeToken() {
140
+ _MoralisEDSEthereum_service = new WeakMap(), _MoralisEDSEthereum_apiInstance = new WeakMap(), _MoralisEDSEthereum_instances = new WeakSet(), _MoralisEDSEthereum_api_get = function _MoralisEDSEthereum_api_get() {
141
+ if (!__classPrivateFieldGet(this, _MoralisEDSEthereum_apiInstance, "f")) {
142
+ __classPrivateFieldSet(this, _MoralisEDSEthereum_apiInstance, MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network), "f");
143
+ }
144
+ return __classPrivateFieldGet(this, _MoralisEDSEthereum_apiInstance, "f");
145
+ }, _MoralisEDSEthereum_getWrappedNativeToken = function _MoralisEDSEthereum_getWrappedNativeToken() {
143
146
  return __awaiter(this, void 0, void 0, function* () {
144
- const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
147
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network);
145
148
  const wrappedSymbol = `W${nativeToken.symbol}`;
146
- const localWrappedHash = BSEthereumConstants_1.BSEthereumConstants.NATIVE_WRAPPED_HASH_BY_NETWORK_ID[__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f").id];
149
+ const localWrappedHash = BSEthereumConstants_1.BSEthereumConstants.NATIVE_WRAPPED_HASH_BY_NETWORK_ID[__classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").network.id];
147
150
  if (!localWrappedHash)
148
151
  throw new Error('Wrapper token not found');
149
- return __classPrivateFieldGet(this, _MoralisEDSEthereum_tokenService, "f").normalizeToken(Object.assign(Object.assign({}, nativeToken), { symbol: wrappedSymbol, hash: localWrappedHash }));
152
+ return __classPrivateFieldGet(this, _MoralisEDSEthereum_service, "f").tokenService.normalizeToken(Object.assign(Object.assign({}, nativeToken), { symbol: wrappedSymbol, hash: localWrappedHash }));
150
153
  });
151
154
  };
155
+ MoralisEDSEthereum.NUMBERS_OF_BLOCK_BY_HOUR = (60 / 15) * 60;
156
+ MoralisEDSEthereum.NUMBER_OF_BLOCK_BY_DAY = MoralisEDSEthereum.NUMBERS_OF_BLOCK_BY_HOUR * 24;
157
+ MoralisEDSEthereum.MAX_TOKEN_PRICES_PER_CALL = 24;
@@ -1,11 +1,13 @@
1
- import { BuildNftUrlParams, ExplorerService, Network, NetworkId, TokenService } from '@cityofzion/blockchain-service';
2
- import { BSEthereumNetworkId } from '../../constants/BSEthereumConstants';
3
- export declare class BlockscoutESEthereum<BSNetworkId extends NetworkId = BSEthereumNetworkId> implements ExplorerService {
4
- #private;
5
- constructor(network: Network<BSEthereumNetworkId>, tokenService: TokenService, baseUrlByNetworkId?: Partial<Record<BSNetworkId, string>>);
1
+ import { TBuildNftUrlParams, IExplorerService, TBSNetworkId } from '@cityofzion/blockchain-service';
2
+ import { IBSEthereum, TBSEthereumNetworkId } from '../../types';
3
+ export declare class BlockscoutESEthereum<N extends string, A extends TBSNetworkId> implements IExplorerService {
4
+ static readonly DEFAULT_BASE_URL_BY_NETWORK_ID: Partial<Record<TBSEthereumNetworkId, string>>;
5
+ readonly _service: IBSEthereum<N, A>;
6
+ constructor(service: IBSEthereum<N, A>);
7
+ getBaseUrl(): NonNullable<Partial<Record<TBSEthereumNetworkId, string>>[TBSNetworkId<A>]>;
6
8
  buildTransactionUrl(hash: string): string;
7
9
  buildContractUrl(contractHash: string): string;
8
- buildNftUrl(params: BuildNftUrlParams): string;
10
+ buildNftUrl(params: TBuildNftUrlParams): string;
9
11
  getAddressTemplateUrl(): string | undefined;
10
12
  getTxTemplateUrl(): string | undefined;
11
13
  getNftTemplateUrl(): string | undefined;
@@ -1,55 +1,32 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _BlockscoutESEthereum_instances, _BlockscoutESEthereum_network, _BlockscoutESEthereum_baseUrlByNetworkId, _BlockscoutESEthereum_tokenService, _BlockscoutESEthereum_getBaseUrl;
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.BlockscoutESEthereum = void 0;
16
- const BSEthereumConstants_1 = require("../../constants/BSEthereumConstants");
17
- const DEFAULT_BASE_URL_BY_NETWORK_ID = {
18
- [BSEthereumConstants_1.BSEthereumConstants.ETHEREUM_MAINNET_NETWORK_ID]: 'https://eth.blockscout.com',
19
- '10': 'https://optimism.blockscout.com',
20
- [BSEthereumConstants_1.BSEthereumConstants.POLYGON_MAINNET_NETWORK_ID]: 'https://polygon.blockscout.com',
21
- [BSEthereumConstants_1.BSEthereumConstants.BASE_MAINNET_NETWORK_ID]: 'https://base.blockscout.com',
22
- [BSEthereumConstants_1.BSEthereumConstants.ARBITRUM_MAINNET_NETWORK_ID]: 'https://arbitrum.blockscout.com',
23
- '42220': 'https://explorer.celo.org/mainnet',
24
- '59144': 'https://explorer.linea.build',
25
- '1101': 'https://zkevm.blockscout.com',
26
- '11155111': 'https://eth-sepolia.blockscout.com',
27
- };
28
4
  class BlockscoutESEthereum {
29
- constructor(network, tokenService, baseUrlByNetworkId) {
30
- _BlockscoutESEthereum_instances.add(this);
31
- _BlockscoutESEthereum_network.set(this, void 0);
32
- _BlockscoutESEthereum_baseUrlByNetworkId.set(this, void 0);
33
- _BlockscoutESEthereum_tokenService.set(this, void 0);
34
- __classPrivateFieldSet(this, _BlockscoutESEthereum_network, network, "f");
35
- __classPrivateFieldSet(this, _BlockscoutESEthereum_baseUrlByNetworkId, baseUrlByNetworkId !== null && baseUrlByNetworkId !== void 0 ? baseUrlByNetworkId : DEFAULT_BASE_URL_BY_NETWORK_ID, "f");
36
- __classPrivateFieldSet(this, _BlockscoutESEthereum_tokenService, tokenService, "f");
5
+ constructor(service) {
6
+ this._service = service;
7
+ }
8
+ getBaseUrl() {
9
+ const baseUrl = BlockscoutESEthereum.DEFAULT_BASE_URL_BY_NETWORK_ID[this._service.network.id];
10
+ if (!baseUrl) {
11
+ throw new Error('Network not supported');
12
+ }
13
+ return baseUrl;
37
14
  }
38
15
  buildTransactionUrl(hash) {
39
- const baseURL = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
40
- return `${baseURL}/tx/${__classPrivateFieldGet(this, _BlockscoutESEthereum_tokenService, "f").normalizeHash(hash)}`;
16
+ const baseURL = this.getBaseUrl();
17
+ return `${baseURL}/tx/${this._service.tokenService.normalizeHash(hash)}`;
41
18
  }
42
19
  buildContractUrl(contractHash) {
43
- const baseURL = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
44
- return `${baseURL}/address/${__classPrivateFieldGet(this, _BlockscoutESEthereum_tokenService, "f").normalizeHash(contractHash)}`;
20
+ const baseURL = this.getBaseUrl();
21
+ return `${baseURL}/address/${this._service.tokenService.normalizeHash(contractHash)}`;
45
22
  }
46
23
  buildNftUrl(params) {
47
- const baseURL = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
48
- return `${baseURL}/token/${__classPrivateFieldGet(this, _BlockscoutESEthereum_tokenService, "f").normalizeHash(params.collectionHash)}/instance/${params.tokenHash}`;
24
+ const baseURL = this.getBaseUrl();
25
+ return `${baseURL}/token/${this._service.tokenService.normalizeHash(params.collectionHash)}/instance/${params.tokenHash}`;
49
26
  }
50
27
  getAddressTemplateUrl() {
51
28
  try {
52
- const baseUrl = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
29
+ const baseUrl = this.getBaseUrl();
53
30
  return `${baseUrl}/address/{address}`;
54
31
  }
55
32
  catch (_a) {
@@ -58,7 +35,7 @@ class BlockscoutESEthereum {
58
35
  }
59
36
  getTxTemplateUrl() {
60
37
  try {
61
- const baseUrl = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
38
+ const baseUrl = this.getBaseUrl();
62
39
  return `${baseUrl}/tx/{txId}`;
63
40
  }
64
41
  catch (_a) {
@@ -67,7 +44,7 @@ class BlockscoutESEthereum {
67
44
  }
68
45
  getNftTemplateUrl() {
69
46
  try {
70
- const baseUrl = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
47
+ const baseUrl = this.getBaseUrl();
71
48
  return `${baseUrl}/token/{collectionHash}/instance/{tokenHash}`;
72
49
  }
73
50
  catch (_a) {
@@ -76,7 +53,7 @@ class BlockscoutESEthereum {
76
53
  }
77
54
  getContractTemplateUrl() {
78
55
  try {
79
- const baseUrl = __classPrivateFieldGet(this, _BlockscoutESEthereum_instances, "m", _BlockscoutESEthereum_getBaseUrl).call(this, __classPrivateFieldGet(this, _BlockscoutESEthereum_network, "f"));
56
+ const baseUrl = this.getBaseUrl();
80
57
  return `${baseUrl}/address/{hash}`;
81
58
  }
82
59
  catch (_a) {
@@ -85,10 +62,14 @@ class BlockscoutESEthereum {
85
62
  }
86
63
  }
87
64
  exports.BlockscoutESEthereum = BlockscoutESEthereum;
88
- _BlockscoutESEthereum_network = new WeakMap(), _BlockscoutESEthereum_baseUrlByNetworkId = new WeakMap(), _BlockscoutESEthereum_tokenService = new WeakMap(), _BlockscoutESEthereum_instances = new WeakSet(), _BlockscoutESEthereum_getBaseUrl = function _BlockscoutESEthereum_getBaseUrl(network) {
89
- const baseUrl = __classPrivateFieldGet(this, _BlockscoutESEthereum_baseUrlByNetworkId, "f")[network.id];
90
- if (!baseUrl) {
91
- throw new Error('Network not supported');
92
- }
93
- return baseUrl;
65
+ BlockscoutESEthereum.DEFAULT_BASE_URL_BY_NETWORK_ID = {
66
+ '1': 'https://eth.blockscout.com',
67
+ '10': 'https://optimism.blockscout.com',
68
+ '137': 'https://polygon.blockscout.com',
69
+ '8453': 'https://base.blockscout.com',
70
+ '42161': 'https://arbitrum.blockscout.com',
71
+ '42220': 'https://explorer.celo.org/mainnet',
72
+ '59144': 'https://explorer.linea.build',
73
+ '1101': 'https://zkevm.blockscout.com',
74
+ '11155111': 'https://eth-sepolia.blockscout.com',
94
75
  };
@@ -1,23 +1,24 @@
1
- import { Account, LedgerService, LedgerServiceEmitter, GetLedgerTransport, UntilIndexRecord } from '@cityofzion/blockchain-service';
1
+ import { TBSAccount, TLedgerServiceEmitter, TGetLedgerTransport, TUntilIndexRecord, ILedgerService } from '@cityofzion/blockchain-service';
2
2
  import Transport from '@ledgerhq/hw-transport';
3
3
  import { ethers, Signer } from 'ethers';
4
4
  import { TypedDataSigner } from '@ethersproject/abstract-signer';
5
5
  import { BSEthereum } from '../../BSEthereum';
6
6
  export declare class EthersLedgerSigner extends Signer implements TypedDataSigner {
7
7
  #private;
8
- constructor(transport: Transport, bip44Path: string, provider?: ethers.providers.Provider, emitter?: LedgerServiceEmitter);
8
+ static shouldRetry: (error: any) => boolean;
9
+ constructor(transport: Transport, bip44Path: string, provider?: ethers.providers.Provider, emitter?: TLedgerServiceEmitter);
9
10
  connect(provider: ethers.providers.Provider): EthersLedgerSigner;
10
11
  getAddress(): Promise<string>;
11
12
  signMessage(message: string | ethers.utils.Bytes): Promise<string>;
12
13
  signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string>;
13
14
  _signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, any>): Promise<string>;
14
15
  }
15
- export declare class EthersLedgerServiceEthereum<BSName extends string = string> implements LedgerService<BSName> {
16
+ export declare class EthersLedgerServiceEthereum<N extends string> implements ILedgerService<N> {
16
17
  #private;
17
- emitter: LedgerServiceEmitter;
18
- getLedgerTransport?: GetLedgerTransport<BSName>;
19
- constructor(blockchainService: BSEthereum<BSName>, getLedgerTransport?: GetLedgerTransport<BSName>);
20
- getAccounts(transport: Transport, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Account<BSName>[]>;
21
- getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
18
+ emitter: TLedgerServiceEmitter;
19
+ getLedgerTransport?: TGetLedgerTransport<N>;
20
+ constructor(blockchainService: BSEthereum<N>, getLedgerTransport?: TGetLedgerTransport<N>);
21
+ getAccounts(transport: Transport, untilIndexByBlockchainService?: TUntilIndexRecord<N>): Promise<TBSAccount<N>[]>;
22
+ getAccount(transport: Transport, index: number): Promise<TBSAccount<N>>;
22
23
  getSigner(transport: Transport, path: string, provider?: ethers.providers.Provider): EthersLedgerSigner;
23
24
  }