@cityofzion/bs-ethereum 2.0.1 → 2.0.3

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,8 +1,8 @@
1
1
  import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
2
2
  import { EthersLedgerServiceEthereum } from './EthersLedgerServiceEthereum';
3
3
  import Transport from '@ledgerhq/hw-transport';
4
- import { AvailableNetworkIds } from './BSEthereumHelper';
5
- export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService<BSCustomName, AvailableNetworkIds>, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger {
4
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
5
+ export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService<BSCustomName, BSEthereumNetworkId>, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger {
6
6
  #private;
7
7
  readonly blockchainName: BSCustomName;
8
8
  readonly derivationPath: string;
@@ -12,9 +12,9 @@ export declare class BSEthereum<BSCustomName extends string = string> implements
12
12
  ledgerService: EthersLedgerServiceEthereum;
13
13
  tokens: Token[];
14
14
  nftDataService: NftDataService;
15
- network: Network<AvailableNetworkIds>;
16
- constructor(blockchainName: BSCustomName, network?: Network<AvailableNetworkIds>, getLedgerTransport?: (account: Account) => Promise<Transport>);
17
- setNetwork(network: Network<AvailableNetworkIds>): void;
15
+ network: Network<BSEthereumNetworkId>;
16
+ constructor(blockchainName: BSCustomName, network?: Network<BSEthereumNetworkId>, getLedgerTransport?: (account: Account) => Promise<Transport>);
17
+ setNetwork(network: Network<BSEthereumNetworkId>): void;
18
18
  validateAddress(address: string): boolean;
19
19
  validateEncrypted(json: string): boolean;
20
20
  validateKey(key: string): boolean;
@@ -144,7 +144,7 @@ class BSEthereum {
144
144
  }
145
145
  let signer;
146
146
  if (ledgerTransport) {
147
- signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
147
+ signer = this.ledgerService.getSigner(ledgerTransport, provider);
148
148
  }
149
149
  else {
150
150
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
@@ -181,7 +181,7 @@ class BSEthereum {
181
181
  }
182
182
  let signer;
183
183
  if (ledgerTransport) {
184
- signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
184
+ signer = this.ledgerService.getSigner(ledgerTransport, provider);
185
185
  }
186
186
  else {
187
187
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
@@ -1,22 +1,27 @@
1
- import { Network } from '@cityofzion/blockchain-service';
2
- export type AvailableNetworkIds = '1' | '10' | '25' | '56' | '137' | '250' | '1101' | '8453' | '80002' | '42161' | '42220' | '43114' | '59144' | '11155111' | '12227331' | (string & {});
1
+ import { Network, NetworkId } from '@cityofzion/blockchain-service';
2
+ export type BSEthereumNetworkId = NetworkId<'1' | '10' | '25' | '56' | '137' | '250' | '1101' | '8453' | '80002' | '42161' | '42220' | '43114' | '59144' | '11155111' | '12227331'>;
3
3
  export declare class BSEthereumHelper {
4
4
  #private;
5
5
  static DERIVATION_PATH: string;
6
6
  static DEFAULT_PATH: string;
7
- static MAINNET_NETWORK_IDS: AvailableNetworkIds[];
8
- static TESTNET_NETWORK_IDS: AvailableNetworkIds[];
9
- static ALL_NETWORK_IDS: AvailableNetworkIds[];
10
- static MAINNET_NETWORKS: Network<AvailableNetworkIds>[];
11
- static TESTNET_NETWORKS: Network<AvailableNetworkIds>[];
12
- static ALL_NETWORKS: Network<AvailableNetworkIds>[];
13
- static DEFAULT_NETWORK: Network<AvailableNetworkIds>;
14
- static getNativeAsset(network: Network<AvailableNetworkIds>): {
7
+ static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId;
8
+ static NEOX_NETWORK_IDS: BSEthereumNetworkId[];
9
+ static NEOX_TESTNET_NETWORK: Network<BSEthereumNetworkId>;
10
+ static NEOX_NETWORKS: Network<BSEthereumNetworkId>[];
11
+ static MAINNET_NETWORK_IDS: BSEthereumNetworkId[];
12
+ static TESTNET_NETWORK_IDS: BSEthereumNetworkId[];
13
+ static ALL_NETWORK_IDS: BSEthereumNetworkId[];
14
+ static MAINNET_NETWORKS: Network<BSEthereumNetworkId>[];
15
+ static TESTNET_NETWORKS: Network<BSEthereumNetworkId>[];
16
+ static ALL_NETWORKS: Network<BSEthereumNetworkId>[];
17
+ static DEFAULT_NETWORK: Network<BSEthereumNetworkId>;
18
+ static getNativeAsset(network: Network<BSEthereumNetworkId>): {
15
19
  symbol: string;
16
20
  name: string;
17
21
  hash: string;
18
22
  decimals: number;
19
23
  };
20
- static getNativeSymbol(network: Network<AvailableNetworkIds>): string;
21
- static getRpcList(network: Network<AvailableNetworkIds>): string[];
24
+ static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
25
+ static getRpcList(network: Network<BSEthereumNetworkId>): string[];
26
+ static isMainnet(network: Network<BSEthereumNetworkId>): boolean;
22
27
  }
@@ -19,6 +19,9 @@ class BSEthereumHelper {
19
19
  var _b;
20
20
  return (_b = __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)[network.id]) !== null && _b !== void 0 ? _b : [];
21
21
  }
22
+ static isMainnet(network) {
23
+ return this.MAINNET_NETWORK_IDS.includes(network.id);
24
+ }
22
25
  }
23
26
  exports.BSEthereumHelper = BSEthereumHelper;
24
27
  _a = BSEthereumHelper;
@@ -138,6 +141,14 @@ _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID = { value: {
138
141
  } };
139
142
  BSEthereumHelper.DERIVATION_PATH = "m/44'/60'/0'/0/?";
140
143
  BSEthereumHelper.DEFAULT_PATH = "44'/60'/0'/0/0";
144
+ BSEthereumHelper.NEOX_TESTNET_NETWORK_ID = '12227331';
145
+ BSEthereumHelper.NEOX_NETWORK_IDS = [_a.NEOX_TESTNET_NETWORK_ID];
146
+ BSEthereumHelper.NEOX_TESTNET_NETWORK = {
147
+ id: _a.NEOX_TESTNET_NETWORK_ID,
148
+ name: 'NeoX Testnet',
149
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)[_a.NEOX_TESTNET_NETWORK_ID][0],
150
+ };
151
+ BSEthereumHelper.NEOX_NETWORKS = [_a.NEOX_TESTNET_NETWORK];
141
152
  BSEthereumHelper.MAINNET_NETWORK_IDS = [
142
153
  '1',
143
154
  '10',
@@ -151,7 +162,13 @@ BSEthereumHelper.MAINNET_NETWORK_IDS = [
151
162
  '43114',
152
163
  '59144',
153
164
  ];
154
- BSEthereumHelper.TESTNET_NETWORK_IDS = ['1101', '80002', '11155111', '12227331'];
165
+ BSEthereumHelper.TESTNET_NETWORK_IDS = [
166
+ '1101',
167
+ '80002',
168
+ '11155111',
169
+ '12227331',
170
+ _a.NEOX_TESTNET_NETWORK_ID,
171
+ ];
155
172
  BSEthereumHelper.ALL_NETWORK_IDS = [..._a.MAINNET_NETWORK_IDS, ..._a.TESTNET_NETWORK_IDS];
156
173
  BSEthereumHelper.MAINNET_NETWORKS = [
157
174
  {
@@ -218,19 +235,15 @@ BSEthereumHelper.TESTNET_NETWORKS = [
218
235
  },
219
236
  {
220
237
  id: '80002',
221
- name: 'Polygon Testnet',
238
+ name: 'Polygon Testnet Amoy',
222
239
  url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['80002'][0],
223
240
  },
224
241
  {
225
242
  id: '11155111',
226
- name: 'Ethereum Sepolia Testnet',
243
+ name: 'Sepolia Testnet',
227
244
  url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['11155111'][0],
228
245
  },
229
- {
230
- id: '12227331',
231
- name: 'Neo3 Testnet',
232
- url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['12227331'][0],
233
- },
246
+ _a.NEOX_TESTNET_NETWORK,
234
247
  ];
235
248
  BSEthereumHelper.ALL_NETWORKS = [..._a.MAINNET_NETWORKS, ..._a.TESTNET_NETWORKS];
236
249
  BSEthereumHelper.DEFAULT_NETWORK = _a.MAINNET_NETWORKS[0];
@@ -1,17 +1,15 @@
1
1
  import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
2
2
  import { RpcBDSEthereum } from './RpcBDSEthereum';
3
- import { AvailableNetworkIds } from './BSEthereumHelper';
3
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
4
4
  export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
5
5
  #private;
6
6
  static MIRROR_URL: string;
7
- static MIRROR_NETWORK_BY_NETWORK_ID: Partial<Record<AvailableNetworkIds, string>>;
8
- static getMirrorNetworkId(network: Network<AvailableNetworkIds>): string;
7
+ static MIRROR_NETWORK_BY_NETWORK_ID: Partial<Record<BSEthereumNetworkId, string>>;
9
8
  maxTimeToConfirmTransactionInMs: number;
10
- constructor(network: Network<AvailableNetworkIds>);
9
+ constructor(network: Network<BSEthereumNetworkId>);
11
10
  getTransaction(hash: string): Promise<TransactionResponse>;
12
11
  getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
13
12
  getContract(): Promise<ContractResponse>;
14
13
  getTokenInfo(hash: string): Promise<Token>;
15
14
  getBalance(address: string): Promise<BalanceResponse[]>;
16
- private parseTransactionTransfer;
17
15
  }
@@ -22,21 +22,16 @@ 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 _BitqueryBDSEthereum_client, _BitqueryBDSEthereum_network, _BitqueryBDSEthereum_tokenCache;
25
+ var _BitqueryBDSEthereum_instances, _BitqueryBDSEthereum_client, _BitqueryBDSEthereum_network, _BitqueryBDSEthereum_tokenCache, _BitqueryBDSEthereum_parseTransactionTransfer;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.BitqueryBDSEthereum = void 0;
28
28
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
29
29
  const axios_1 = __importDefault(require("axios"));
30
30
  const BSEthereumHelper_1 = require("./BSEthereumHelper");
31
31
  class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
32
- static getMirrorNetworkId(network) {
33
- const mirrorNetwork = BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[network.id];
34
- if (!mirrorNetwork)
35
- throw new Error('Mirror network is not supported');
36
- return mirrorNetwork;
37
- }
38
32
  constructor(network) {
39
33
  super(network);
34
+ _BitqueryBDSEthereum_instances.add(this);
40
35
  _BitqueryBDSEthereum_client.set(this, void 0);
41
36
  _BitqueryBDSEthereum_network.set(this, void 0);
42
37
  _BitqueryBDSEthereum_tokenCache.set(this, new Map());
@@ -47,14 +42,20 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
47
42
  }), "f");
48
43
  }
49
44
  getTransaction(hash) {
45
+ const _super = Object.create(null, {
46
+ getTransaction: { get: () => super.getTransaction }
47
+ });
50
48
  return __awaiter(this, void 0, void 0, function* () {
51
- const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
49
+ const mirrorNetwork = BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f").id];
50
+ if (!mirrorNetwork) {
51
+ return _super.getTransaction.call(this, hash);
52
+ }
52
53
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-transaction/${hash}`, {
53
54
  params: { network: mirrorNetwork },
54
55
  });
55
56
  if (!result.data || !result.data.ethereum.transfers.length)
56
57
  throw new Error('Transaction not found');
57
- const transfers = result.data.ethereum.transfers.map(this.parseTransactionTransfer);
58
+ const transfers = result.data.ethereum.transfers.map(__classPrivateFieldGet(this, _BitqueryBDSEthereum_instances, "m", _BitqueryBDSEthereum_parseTransactionTransfer));
58
59
  const { block: { height, timestamp: { unixtime }, }, transaction: { gasValue, hash: transactionHash }, } = result.data.ethereum.transfers[0];
59
60
  return {
60
61
  block: height,
@@ -67,11 +68,17 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
67
68
  });
68
69
  }
69
70
  getTransactionsByAddress({ address, page = 1, }) {
71
+ const _super = Object.create(null, {
72
+ getTransactionsByAddress: { get: () => super.getTransactionsByAddress }
73
+ });
70
74
  var _a, _b, _c, _d, _e, _f, _g, _h;
71
75
  return __awaiter(this, void 0, void 0, function* () {
76
+ const mirrorNetwork = BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f").id];
77
+ if (!mirrorNetwork) {
78
+ return _super.getTransactionsByAddress.call(this, { address, page });
79
+ }
72
80
  const limit = 10;
73
81
  const offset = limit * (page - 1);
74
- const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
75
82
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-transactions/${address}`, {
76
83
  params: { network: mirrorNetwork, limit, offset },
77
84
  });
@@ -81,7 +88,7 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
81
88
  const mixedTransfers = [...((_e = (_d = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.ethereum) === null || _d === void 0 ? void 0 : _d.sent) !== null && _e !== void 0 ? _e : []), ...((_h = (_g = (_f = result === null || result === void 0 ? void 0 : result.data) === null || _f === void 0 ? void 0 : _f.ethereum) === null || _g === void 0 ? void 0 : _g.received) !== null && _h !== void 0 ? _h : [])];
82
89
  const transactions = new Map();
83
90
  mixedTransfers.forEach(transfer => {
84
- const transactionTransfer = this.parseTransactionTransfer(transfer);
91
+ const transactionTransfer = __classPrivateFieldGet(this, _BitqueryBDSEthereum_instances, "m", _BitqueryBDSEthereum_parseTransactionTransfer).call(this, transfer);
85
92
  const existingTransaction = transactions.get(transfer.transaction.hash);
86
93
  if (existingTransaction) {
87
94
  existingTransaction.transfers.push(transactionTransfer);
@@ -104,16 +111,29 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
104
111
  });
105
112
  }
106
113
  getContract() {
114
+ const _super = Object.create(null, {
115
+ getContract: { get: () => super.getContract }
116
+ });
107
117
  return __awaiter(this, void 0, void 0, function* () {
118
+ const mirrorNetwork = BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f").id];
119
+ if (!mirrorNetwork) {
120
+ return _super.getContract.call(this);
121
+ }
108
122
  throw new Error("Bitquery doesn't support contract info");
109
123
  });
110
124
  }
111
125
  getTokenInfo(hash) {
126
+ const _super = Object.create(null, {
127
+ getTokenInfo: { get: () => super.getTokenInfo }
128
+ });
112
129
  return __awaiter(this, void 0, void 0, function* () {
130
+ const mirrorNetwork = BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f").id];
131
+ if (!mirrorNetwork) {
132
+ return _super.getTokenInfo.call(this, hash);
133
+ }
113
134
  if (__classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").has(hash)) {
114
135
  return __classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").get(hash);
115
136
  }
116
- const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
117
137
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-token-info/${hash}`, {
118
138
  params: { network: mirrorNetwork },
119
139
  });
@@ -133,9 +153,15 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
133
153
  });
134
154
  }
135
155
  getBalance(address) {
156
+ const _super = Object.create(null, {
157
+ getBalance: { get: () => super.getBalance }
158
+ });
136
159
  var _a, _b, _c, _d;
137
160
  return __awaiter(this, void 0, void 0, function* () {
138
- const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
161
+ const mirrorNetwork = BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f").id];
162
+ if (!mirrorNetwork) {
163
+ return _super.getBalance.call(this, address);
164
+ }
139
165
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-balance/${address}`, {
140
166
  params: { network: mirrorNetwork },
141
167
  });
@@ -164,33 +190,32 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
164
190
  return balances;
165
191
  });
166
192
  }
167
- parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, symbol, name }, entityId, sender, receiver, }) {
168
- if (tokenType === 'ERC721') {
169
- return {
170
- from: sender.address,
171
- to: receiver.address,
172
- tokenId: entityId,
173
- contractHash: address,
174
- type: 'nft',
175
- };
176
- }
193
+ }
194
+ exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
195
+ _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_network = new WeakMap(), _BitqueryBDSEthereum_tokenCache = new WeakMap(), _BitqueryBDSEthereum_instances = new WeakSet(), _BitqueryBDSEthereum_parseTransactionTransfer = function _BitqueryBDSEthereum_parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, symbol, name }, entityId, sender, receiver, }) {
196
+ if (tokenType === 'ERC721') {
177
197
  return {
178
198
  from: sender.address,
179
199
  to: receiver.address,
200
+ tokenId: entityId,
180
201
  contractHash: address,
181
- amount: amount.toString(),
182
- token: {
183
- decimals: decimals,
184
- hash: address,
185
- symbol: symbol,
186
- name: name,
187
- },
188
- type: 'token',
202
+ type: 'nft',
189
203
  };
190
204
  }
191
- }
192
- exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
193
- _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_network = new WeakMap(), _BitqueryBDSEthereum_tokenCache = new WeakMap();
205
+ return {
206
+ from: sender.address,
207
+ to: receiver.address,
208
+ contractHash: address,
209
+ amount: amount.toString(),
210
+ token: {
211
+ decimals: decimals,
212
+ hash: address,
213
+ symbol: symbol,
214
+ name: name,
215
+ },
216
+ type: 'token',
217
+ };
218
+ };
194
219
  BitqueryBDSEthereum.MIRROR_URL = 'https://i4l7kcg43c.execute-api.us-east-1.amazonaws.com/production/';
195
220
  BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID = {
196
221
  '1': 'ethereum',
@@ -1,8 +1,9 @@
1
- import { CryptoCompareEDS, Currency, ExchangeDataService, Network, Token, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
- import { AvailableNetworkIds } from './BSEthereumHelper';
1
+ import { CryptoCompareEDS, Currency, ExchangeDataService, GetTokenPriceHistory, Network, Token, TokenPricesHistoryResponse, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
3
3
  export declare class BitqueryEDSEthereum extends CryptoCompareEDS implements ExchangeDataService {
4
4
  #private;
5
- constructor(network: Network<AvailableNetworkIds>, tokens: Token[]);
5
+ constructor(network: Network<BSEthereumNetworkId>, tokens: Token[]);
6
6
  getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
+ getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
7
8
  private getCurrencyRatio;
8
9
  }
@@ -29,6 +29,7 @@ const blockchain_service_1 = require("@cityofzion/blockchain-service");
29
29
  const axios_1 = __importDefault(require("axios"));
30
30
  const dayjs_1 = __importDefault(require("dayjs"));
31
31
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
32
+ const BSEthereumHelper_1 = require("./BSEthereumHelper");
32
33
  const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
33
34
  dayjs_1.default.extend(utc_1.default);
34
35
  class BitqueryEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
@@ -43,8 +44,13 @@ class BitqueryEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
43
44
  }
44
45
  getTokenPrices(currency) {
45
46
  return __awaiter(this, void 0, void 0, function* () {
47
+ if (BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _BitqueryEDSEthereum_network, "f")))
48
+ throw new Error('Exchange is only available on mainnet');
46
49
  const twoDaysAgo = dayjs_1.default.utc().subtract(2, 'day').startOf('date').toISOString();
47
- const mirrorNetwork = BitqueryBDSEthereum_1.BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryEDSEthereum_network, "f"));
50
+ const mirrorNetwork = BitqueryBDSEthereum_1.BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryEDSEthereum_network, "f").id];
51
+ if (!mirrorNetwork) {
52
+ throw new Error('BitqueryEDSEthereum is not available for this network');
53
+ }
48
54
  const result = yield __classPrivateFieldGet(this, _BitqueryEDSEthereum_client, "f").get(`/get-price`, {
49
55
  params: { network: mirrorNetwork, after: twoDaysAgo },
50
56
  });
@@ -63,6 +69,16 @@ class BitqueryEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
63
69
  return prices;
64
70
  });
65
71
  }
72
+ getTokenPriceHistory(params) {
73
+ const _super = Object.create(null, {
74
+ getTokenPriceHistory: { get: () => super.getTokenPriceHistory }
75
+ });
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _BitqueryEDSEthereum_network, "f")))
78
+ throw new Error('Exchange is only available on mainnet');
79
+ return yield _super.getTokenPriceHistory.call(this, params);
80
+ });
81
+ }
66
82
  getCurrencyRatio(currency) {
67
83
  return __awaiter(this, void 0, void 0, function* () {
68
84
  const { data } = yield axios_1.default.get(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`);
@@ -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;
@@ -1,13 +1,13 @@
1
1
  import { NftResponse, NftsResponse, GetNftParam, GetNftsByAddressParams, Network } from '@cityofzion/blockchain-service';
2
2
  import { RpcNDSEthereum } from './RpcNDSEthereum';
3
- import { AvailableNetworkIds } from './BSEthereumHelper';
3
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
4
4
  export declare class GhostMarketNDSEthereum extends RpcNDSEthereum {
5
5
  #private;
6
- static CONFIG_BY_NETWORK_ID: Partial<Record<AvailableNetworkIds, {
6
+ static CONFIG_BY_NETWORK_ID: Partial<Record<BSEthereumNetworkId, {
7
7
  url: string;
8
8
  chain: string;
9
9
  }>>;
10
- constructor(network: Network<AvailableNetworkIds>);
10
+ constructor(network: Network<BSEthereumNetworkId>);
11
11
  getNftsByAddress({ address, size, cursor }: GetNftsByAddressParams): Promise<NftsResponse>;
12
12
  getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
13
13
  private treatGhostMarketImage;
@@ -1,9 +1,9 @@
1
1
  import { BalanceResponse, BlockchainDataService, ContractResponse, Network, RpcResponse, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
2
- import { AvailableNetworkIds } from './BSEthereumHelper';
2
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
3
3
  export declare class RpcBDSEthereum implements BlockchainDataService {
4
4
  #private;
5
5
  maxTimeToConfirmTransactionInMs: number;
6
- constructor(network: Network<AvailableNetworkIds>);
6
+ constructor(network: Network<BSEthereumNetworkId>);
7
7
  getTransaction(hash: string): Promise<TransactionResponse>;
8
8
  getTransactionsByAddress(_params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
9
9
  getContract(): Promise<ContractResponse>;
@@ -23,6 +23,7 @@ var _RpcNDSEthereum_network;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.RpcNDSEthereum = void 0;
25
25
  const ethers_1 = require("ethers");
26
+ const ERC20_1 = require("./assets/abis/ERC20");
26
27
  class RpcNDSEthereum {
27
28
  constructor(network) {
28
29
  _RpcNDSEthereum_network.set(this, void 0);
@@ -32,7 +33,7 @@ class RpcNDSEthereum {
32
33
  return __awaiter(this, void 0, void 0, function* () {
33
34
  try {
34
35
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcNDSEthereum_network, "f").url);
35
- const contract = new ethers_1.ethers.Contract(contractHash, ['function balanceOf(address _owner) external view returns (uint256)'], provider);
36
+ const contract = new ethers_1.ethers.Contract(contractHash, ERC20_1.ERC20_ABI, provider);
36
37
  const response = yield contract.balanceOf(address);
37
38
  if (!response)
38
39
  throw new Error();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -22,7 +22,7 @@
22
22
  "@ledgerhq/hw-app-eth": "~6.35.7",
23
23
  "@ethersproject/abstract-signer": "~5.7.0",
24
24
  "@ethersproject/properties": "~5.7.0",
25
- "@cityofzion/blockchain-service": "1.0.1"
25
+ "@cityofzion/blockchain-service": "1.0.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@ledgerhq/hw-transport-node-hid": "~6.28.5",