@cityofzion/bs-ethereum 2.0.0 → 2.0.2

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,19 +1,20 @@
1
- import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialNetwork, Token, TransferParam } from '@cityofzion/blockchain-service';
2
- import { LedgerServiceEthereum } from './LedgerServiceEthereum';
1
+ import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
2
+ import { EthersLedgerServiceEthereum } from './EthersLedgerServiceEthereum';
3
3
  import Transport from '@ledgerhq/hw-transport';
4
- import { AvailableNetworkIds } from './constants';
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
+ #private;
6
7
  readonly blockchainName: BSCustomName;
7
- readonly feeToken: Token;
8
8
  readonly derivationPath: string;
9
+ feeToken: Token;
9
10
  blockchainDataService: BlockchainDataService;
10
11
  exchangeDataService: ExchangeDataService;
11
- ledgerService: LedgerServiceEthereum;
12
+ ledgerService: EthersLedgerServiceEthereum;
12
13
  tokens: Token[];
13
14
  nftDataService: NftDataService;
14
- network: Network<AvailableNetworkIds>;
15
- constructor(blockchainName: BSCustomName, network: PartialNetwork<AvailableNetworkIds>, getLedgerTransport?: (account: Account) => Promise<Transport>);
16
- setNetwork(partialNetwork: PartialNetwork<AvailableNetworkIds>): void;
15
+ network: Network<BSEthereumNetworkId>;
16
+ constructor(blockchainName: BSCustomName, network?: Network<BSEthereumNetworkId>, getLedgerTransport?: (account: Account) => Promise<Transport>);
17
+ setNetwork(network: Network<BSEthereumNetworkId>): void;
17
18
  validateAddress(address: string): boolean;
18
19
  validateEncrypted(json: string): boolean;
19
20
  validateKey(key: string): boolean;
@@ -31,6 +31,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
35
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
36
+ 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");
37
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
38
+ };
39
+ var _BSEthereum_instances, _BSEthereum_setTokens;
34
40
  Object.defineProperty(exports, "__esModule", { value: true });
35
41
  exports.BSEthereum = void 0;
36
42
  const ethers_1 = require("ethers");
@@ -41,28 +47,23 @@ const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
41
47
  const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
42
48
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
43
49
  const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
44
- const LedgerServiceEthereum_1 = require("./LedgerServiceEthereum");
45
- const constants_1 = require("./constants");
50
+ const EthersLedgerServiceEthereum_1 = require("./EthersLedgerServiceEthereum");
51
+ const BSEthereumHelper_1 = require("./BSEthereumHelper");
46
52
  class BSEthereum {
47
53
  constructor(blockchainName, network, getLedgerTransport) {
54
+ _BSEthereum_instances.add(this);
55
+ network = network !== null && network !== void 0 ? network : BSEthereumHelper_1.BSEthereumHelper.DEFAULT_NETWORK;
48
56
  this.blockchainName = blockchainName;
49
- this.ledgerService = new LedgerServiceEthereum_1.LedgerServiceEthereum(getLedgerTransport);
50
- this.derivationPath = constants_1.DERIVATION_PATH;
51
- this.tokens = [constants_1.NATIVE_ASSET_BY_NETWORK_ID[network.id]];
52
- this.feeToken = constants_1.NATIVE_ASSET_BY_NETWORK_ID[network.id];
57
+ this.ledgerService = new EthersLedgerServiceEthereum_1.EthersLedgerServiceEthereum(getLedgerTransport);
58
+ this.derivationPath = BSEthereumHelper_1.BSEthereumHelper.DERIVATION_PATH;
53
59
  this.setNetwork(network);
54
60
  }
55
- setNetwork(partialNetwork) {
56
- var _a, _b;
57
- const network = {
58
- id: partialNetwork.id,
59
- name: (_a = partialNetwork.name) !== null && _a !== void 0 ? _a : constants_1.NETWORK_NAME_BY_NETWORK_ID[partialNetwork.id],
60
- url: (_b = partialNetwork.url) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_URL_BY_NETWORK_ID[partialNetwork.id],
61
- };
61
+ setNetwork(network) {
62
+ __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_setTokens).call(this, network);
62
63
  this.network = network;
63
- const bitqueryNetwork = constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_ID[partialNetwork.id];
64
+ const bitqueryNetwork = BitqueryBDSEthereum_1.BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[network.id];
64
65
  this.blockchainDataService = bitqueryNetwork ? new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network) : new RpcBDSEthereum_1.RpcBDSEthereum(network);
65
- this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.id);
66
+ this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network, this.tokens);
66
67
  this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network);
67
68
  }
68
69
  validateAddress(address) {
@@ -143,7 +144,7 @@ class BSEthereum {
143
144
  }
144
145
  let signer;
145
146
  if (ledgerTransport) {
146
- signer = new LedgerServiceEthereum_1.LedgerSigner(ledgerTransport, provider);
147
+ signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
147
148
  }
148
149
  else {
149
150
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
@@ -151,7 +152,7 @@ class BSEthereum {
151
152
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
152
153
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
153
154
  let transactionParams;
154
- const isNative = constants_1.NATIVE_ASSET_BY_NETWORK_ID[this.network.id].hash === param.intent.tokenHash;
155
+ const isNative = this.feeToken.hash === param.intent.tokenHash;
155
156
  if (isNative) {
156
157
  transactionParams = {
157
158
  to: param.intent.receiverAddress,
@@ -180,14 +181,14 @@ class BSEthereum {
180
181
  }
181
182
  let signer;
182
183
  if (ledgerTransport) {
183
- signer = new LedgerServiceEthereum_1.LedgerSigner(ledgerTransport, provider);
184
+ signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
184
185
  }
185
186
  else {
186
187
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
187
188
  }
188
189
  const gasPrice = yield provider.getGasPrice();
189
190
  let estimated;
190
- const isNative = constants_1.NATIVE_ASSET_BY_NETWORK_ID[this.network.id].hash === param.intent.tokenHash;
191
+ const isNative = this.feeToken.hash === param.intent.tokenHash;
191
192
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
192
193
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
193
194
  if (!isNative) {
@@ -214,3 +215,8 @@ class BSEthereum {
214
215
  }
215
216
  }
216
217
  exports.BSEthereum = BSEthereum;
218
+ _BSEthereum_instances = new WeakSet(), _BSEthereum_setTokens = function _BSEthereum_setTokens(network) {
219
+ const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(network);
220
+ this.tokens = [nativeAsset];
221
+ this.feeToken = nativeAsset;
222
+ };
@@ -0,0 +1,27 @@
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
+ export declare class BSEthereumHelper {
4
+ #private;
5
+ static DERIVATION_PATH: string;
6
+ static DEFAULT_PATH: string;
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>): {
19
+ symbol: string;
20
+ name: string;
21
+ hash: string;
22
+ decimals: number;
23
+ };
24
+ static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
25
+ static getRpcList(network: Network<BSEthereumNetworkId>): string[];
26
+ static isMainnet(network: Network<BSEthereumNetworkId>): boolean;
27
+ }
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _a, _BSEthereumHelper_NATIVE_ASSET, _BSEthereumHelper_NATIVE_SYMBOL_BY_NETWORK_ID, _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BSEthereumHelper = void 0;
10
+ class BSEthereumHelper {
11
+ static getNativeAsset(network) {
12
+ return Object.assign(Object.assign({}, __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_NATIVE_ASSET)), { symbol: this.getNativeSymbol(network) });
13
+ }
14
+ static getNativeSymbol(network) {
15
+ var _b;
16
+ return (_b = __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_NATIVE_SYMBOL_BY_NETWORK_ID)[network.id]) !== null && _b !== void 0 ? _b : 'ETH';
17
+ }
18
+ static getRpcList(network) {
19
+ var _b;
20
+ return (_b = __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)[network.id]) !== null && _b !== void 0 ? _b : [];
21
+ }
22
+ static isMainnet(network) {
23
+ return this.MAINNET_NETWORK_IDS.includes(network.id);
24
+ }
25
+ }
26
+ exports.BSEthereumHelper = BSEthereumHelper;
27
+ _a = BSEthereumHelper;
28
+ _BSEthereumHelper_NATIVE_ASSET = { value: {
29
+ decimals: 18,
30
+ hash: '-',
31
+ name: 'ETH',
32
+ symbol: 'ETH',
33
+ } };
34
+ _BSEthereumHelper_NATIVE_SYMBOL_BY_NETWORK_ID = { value: {
35
+ '1': 'ETH',
36
+ '10': 'ETH',
37
+ '25': 'CRO',
38
+ '56': 'BNB',
39
+ '137': 'MATIC',
40
+ '1101': 'ETH',
41
+ '250': 'FTM',
42
+ '8453': 'ETH',
43
+ '80002': 'MATIC',
44
+ '42161': 'ETH',
45
+ '42220': 'CELO',
46
+ '43114': 'AVAX',
47
+ '59144': 'ETH',
48
+ '11155111': 'ETH',
49
+ '12227331': 'GAS',
50
+ } };
51
+ _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID = { value: {
52
+ '1': [
53
+ 'https://eth.llamarpc.com',
54
+ 'https://mainnet.infura.io/v3/',
55
+ 'https://ethereum-rpc.publicnode.com',
56
+ 'https://endpoints.omniatech.io/v1/eth/mainnet/public',
57
+ 'https://rpc.flashbots.net',
58
+ 'https://rpc.mevblocker.io',
59
+ ],
60
+ '10': [
61
+ 'https://optimism.llamarpc.com',
62
+ 'https://endpoints.omniatech.io/v1/op/mainnet/public',
63
+ 'https://optimism-rpc.publicnode.com',
64
+ 'https://optimism.meowrpc.com',
65
+ 'https://optimism.rpc.subquery.network/public',
66
+ ],
67
+ '25': ['https://cronos-evm-rpc.publicnode.com', 'https://1rpc.io/cro', 'https://rpc.vvs.finance'],
68
+ '56': [
69
+ 'https://bsc-dataseed.binance.org/',
70
+ 'https://binance.llamarpc.com',
71
+ 'https://bsc-dataseed.bnbchain.org',
72
+ 'https://endpoints.omniatech.io/v1/bsc/mainnet/public',
73
+ 'https://bsc-rpc.publicnode.com',
74
+ ],
75
+ '137': [
76
+ 'https://polygon-mainnet.infura.io',
77
+ 'https://polygon.llamarpc.com',
78
+ 'https://endpoints.omniatech.io/v1/matic/mainnet/public',
79
+ 'https://polygon.drpc.org',
80
+ 'https://polygon.meowrpc.com',
81
+ ],
82
+ '250': [
83
+ 'https://endpoints.omniatech.io/v1/fantom/mainnet/public',
84
+ 'https://rpcapi.fantom.network',
85
+ 'https://fantom-pokt.nodies.app',
86
+ 'https://fantom-rpc.publicnode.com',
87
+ 'https://fantom.drpc.org',
88
+ ],
89
+ '1101': [
90
+ 'https://polygon-zkevm.drpc.org',
91
+ 'https://polygon-zkevm.blockpi.network/v1/rpc/public',
92
+ 'https://1rpc.io/polygon/zkevm',
93
+ ],
94
+ '80002': [
95
+ 'https://polygon-amoy.drpc.org',
96
+ 'https://rpc.ankr.com/polygon_amoy',
97
+ 'https://polygon-amoy-bor-rpc.publicnode.com',
98
+ ],
99
+ '8453': [
100
+ 'https://base.rpc.subquery.network/public',
101
+ 'https://base.llamarpc.com',
102
+ 'https://mainnet.base.org',
103
+ 'https://1rpc.io/base',
104
+ 'https://base.meowrpc.com',
105
+ 'https://base-rpc.publicnode.com',
106
+ 'https://endpoints.omniatech.io/v1/base/mainnet/public',
107
+ ],
108
+ '42161': [
109
+ 'https://arbitrum.llamarpc.com',
110
+ 'https://arbitrum-one-rpc.publicnode.com',
111
+ 'https://arb-mainnet-public.unifra.io',
112
+ 'https://arbitrum-one.publicnode.com',
113
+ ],
114
+ '42220': [
115
+ 'https://forno.celo.org',
116
+ 'https://api.tatum.io/v3/blockchain/node/celo-mainnet',
117
+ 'https://rpc.ankr.com/celo',
118
+ ],
119
+ '43114': [
120
+ 'https://avalanche-mainnet.infura.io',
121
+ 'https://avalanche-c-chain-rpc.publicnode.com',
122
+ 'https://avalanche.public-rpc.com',
123
+ 'https://endpoints.omniatech.io/v1/avax/mainnet/public',
124
+ 'https://avalanche.drpc.org',
125
+ ],
126
+ '59144': [
127
+ 'https://linea.decubate.com',
128
+ 'https://linea.blockpi.network/v1/rpc/public',
129
+ 'https://linea.decubate.com',
130
+ ],
131
+ '11155111': [
132
+ 'https://ethereum-sepolia.rpc.subquery.network/public',
133
+ 'https://ethereum-sepolia-rpc.publicnode.com',
134
+ 'https://endpoints.omniatech.io/v1/eth/sepolia/public',
135
+ 'https://eth-sepolia.public.blastapi.io',
136
+ 'https://eth-sepolia-public.unifra.io',
137
+ 'https://1rpc.io/sepolia',
138
+ 'https://eth-sepolia.api.onfinality.io/public',
139
+ ],
140
+ '12227331': ['https://neoxseed1.ngd.network'],
141
+ } };
142
+ BSEthereumHelper.DERIVATION_PATH = "m/44'/60'/0'/0/?";
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];
152
+ BSEthereumHelper.MAINNET_NETWORK_IDS = [
153
+ '1',
154
+ '10',
155
+ '25',
156
+ '56',
157
+ '137',
158
+ '250',
159
+ '8453',
160
+ '42161',
161
+ '42220',
162
+ '43114',
163
+ '59144',
164
+ ];
165
+ BSEthereumHelper.TESTNET_NETWORK_IDS = [
166
+ '1101',
167
+ '80002',
168
+ '11155111',
169
+ '12227331',
170
+ _a.NEOX_TESTNET_NETWORK_ID,
171
+ ];
172
+ BSEthereumHelper.ALL_NETWORK_IDS = [..._a.MAINNET_NETWORK_IDS, ..._a.TESTNET_NETWORK_IDS];
173
+ BSEthereumHelper.MAINNET_NETWORKS = [
174
+ {
175
+ id: '1',
176
+ name: 'Ethereum Mainnet',
177
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['1'][0],
178
+ },
179
+ {
180
+ id: '10',
181
+ name: 'Optimism Mainnet',
182
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['10'][0],
183
+ },
184
+ {
185
+ id: '25',
186
+ name: 'Cronos Mainnet',
187
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['25'][0],
188
+ },
189
+ {
190
+ id: '56',
191
+ name: 'Binance Smart Chain Mainnet',
192
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['56'][0],
193
+ },
194
+ {
195
+ id: '137',
196
+ name: 'Polygon Mainnet',
197
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['137'][0],
198
+ },
199
+ {
200
+ id: '250',
201
+ name: 'Fantom Mainnet',
202
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['250'][0],
203
+ },
204
+ {
205
+ id: '8453',
206
+ name: 'Base Protocol Mainnet',
207
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['8453'][0],
208
+ },
209
+ {
210
+ id: '42161',
211
+ name: 'Arbitrum Mainnet',
212
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['42161'][0],
213
+ },
214
+ {
215
+ id: '42220',
216
+ name: 'Celo Mainnet',
217
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['42220'][0],
218
+ },
219
+ {
220
+ id: '43114',
221
+ name: 'Avalanche Mainnet',
222
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['43114'][0],
223
+ },
224
+ {
225
+ id: '59144',
226
+ name: 'Linea Mainnet',
227
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['59144'][0],
228
+ },
229
+ ];
230
+ BSEthereumHelper.TESTNET_NETWORKS = [
231
+ {
232
+ id: '1101',
233
+ name: 'Polygon zkEVM Testnet',
234
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['1101'][0],
235
+ },
236
+ {
237
+ id: '80002',
238
+ name: 'Polygon Testnet Amoy',
239
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['80002'][0],
240
+ },
241
+ {
242
+ id: '11155111',
243
+ name: 'Sepolia Testnet',
244
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['11155111'][0],
245
+ },
246
+ _a.NEOX_TESTNET_NETWORK,
247
+ ];
248
+ BSEthereumHelper.ALL_NETWORKS = [..._a.MAINNET_NETWORKS, ..._a.TESTNET_NETWORKS];
249
+ BSEthereumHelper.DEFAULT_NETWORK = _a.MAINNET_NETWORKS[0];
@@ -1,14 +1,15 @@
1
1
  import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
2
- import { AvailableNetworkIds } from './constants';
3
2
  import { RpcBDSEthereum } from './RpcBDSEthereum';
3
+ import { BSEthereumNetworkId } from './BSEthereumHelper';
4
4
  export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
5
5
  #private;
6
+ static MIRROR_URL: string;
7
+ static MIRROR_NETWORK_BY_NETWORK_ID: Partial<Record<BSEthereumNetworkId, string>>;
6
8
  maxTimeToConfirmTransactionInMs: number;
7
- constructor(network: Network<AvailableNetworkIds>);
9
+ constructor(network: Network<BSEthereumNetworkId>);
8
10
  getTransaction(hash: string): Promise<TransactionResponse>;
9
11
  getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
10
12
  getContract(): Promise<ContractResponse>;
11
13
  getTokenInfo(hash: string): Promise<Token>;
12
14
  getBalance(address: string): Promise<BalanceResponse[]>;
13
- private parseTransactionTransfer;
14
15
  }
@@ -22,32 +22,40 @@ 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_networkId, _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
- const constants_1 = require("./constants");
29
28
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
30
29
  const axios_1 = __importDefault(require("axios"));
30
+ const BSEthereumHelper_1 = require("./BSEthereumHelper");
31
31
  class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
32
32
  constructor(network) {
33
33
  super(network);
34
+ _BitqueryBDSEthereum_instances.add(this);
34
35
  _BitqueryBDSEthereum_client.set(this, void 0);
35
- _BitqueryBDSEthereum_networkId.set(this, void 0);
36
+ _BitqueryBDSEthereum_network.set(this, void 0);
36
37
  _BitqueryBDSEthereum_tokenCache.set(this, new Map());
37
38
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 8;
38
- __classPrivateFieldSet(this, _BitqueryBDSEthereum_networkId, network.id, "f");
39
+ __classPrivateFieldSet(this, _BitqueryBDSEthereum_network, network, "f");
39
40
  __classPrivateFieldSet(this, _BitqueryBDSEthereum_client, axios_1.default.create({
40
- baseURL: constants_1.BITQUERY_MIRROR_URL,
41
+ baseURL: BitqueryBDSEthereum.MIRROR_URL,
41
42
  }), "f");
42
43
  }
43
44
  getTransaction(hash) {
45
+ const _super = Object.create(null, {
46
+ getTransaction: { get: () => super.getTransaction }
47
+ });
44
48
  return __awaiter(this, void 0, void 0, function* () {
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
+ }
45
53
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-transaction/${hash}`, {
46
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkId, "f")] },
54
+ params: { network: mirrorNetwork },
47
55
  });
48
56
  if (!result.data || !result.data.ethereum.transfers.length)
49
57
  throw new Error('Transaction not found');
50
- const transfers = result.data.ethereum.transfers.map(this.parseTransactionTransfer);
58
+ const transfers = result.data.ethereum.transfers.map(__classPrivateFieldGet(this, _BitqueryBDSEthereum_instances, "m", _BitqueryBDSEthereum_parseTransactionTransfer));
51
59
  const { block: { height, timestamp: { unixtime }, }, transaction: { gasValue, hash: transactionHash }, } = result.data.ethereum.transfers[0];
52
60
  return {
53
61
  block: height,
@@ -60,12 +68,19 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
60
68
  });
61
69
  }
62
70
  getTransactionsByAddress({ address, page = 1, }) {
71
+ const _super = Object.create(null, {
72
+ getTransactionsByAddress: { get: () => super.getTransactionsByAddress }
73
+ });
63
74
  var _a, _b, _c, _d, _e, _f, _g, _h;
64
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
+ }
65
80
  const limit = 10;
66
81
  const offset = limit * (page - 1);
67
82
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-transactions/${address}`, {
68
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkId, "f")], limit, offset },
83
+ params: { network: mirrorNetwork, limit, offset },
69
84
  });
70
85
  if (!result.data)
71
86
  throw new Error('Address does not have transactions');
@@ -73,7 +88,7 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
73
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 : [])];
74
89
  const transactions = new Map();
75
90
  mixedTransfers.forEach(transfer => {
76
- const transactionTransfer = this.parseTransactionTransfer(transfer);
91
+ const transactionTransfer = __classPrivateFieldGet(this, _BitqueryBDSEthereum_instances, "m", _BitqueryBDSEthereum_parseTransactionTransfer).call(this, transfer);
77
92
  const existingTransaction = transactions.get(transfer.transaction.hash);
78
93
  if (existingTransaction) {
79
94
  existingTransaction.transfers.push(transactionTransfer);
@@ -96,17 +111,31 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
96
111
  });
97
112
  }
98
113
  getContract() {
114
+ const _super = Object.create(null, {
115
+ getContract: { get: () => super.getContract }
116
+ });
99
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
+ }
100
122
  throw new Error("Bitquery doesn't support contract info");
101
123
  });
102
124
  }
103
125
  getTokenInfo(hash) {
126
+ const _super = Object.create(null, {
127
+ getTokenInfo: { get: () => super.getTokenInfo }
128
+ });
104
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
+ }
105
134
  if (__classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").has(hash)) {
106
135
  return __classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").get(hash);
107
136
  }
108
137
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-token-info/${hash}`, {
109
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkId, "f")] },
138
+ params: { network: mirrorNetwork },
110
139
  });
111
140
  if (!result.data || result.data.ethereum.smartContractCalls.length <= 0)
112
141
  throw new Error('Token not found');
@@ -124,14 +153,21 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
124
153
  });
125
154
  }
126
155
  getBalance(address) {
156
+ const _super = Object.create(null, {
157
+ getBalance: { get: () => super.getBalance }
158
+ });
127
159
  var _a, _b, _c, _d;
128
160
  return __awaiter(this, void 0, void 0, function* () {
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
+ }
129
165
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-balance/${address}`, {
130
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkId, "f")] },
166
+ params: { network: mirrorNetwork },
131
167
  });
132
168
  const data = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.ethereum.address[0].balances) !== null && _b !== void 0 ? _b : [];
133
169
  const nativeBalance = (_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.ethereum.address[0].balance) !== null && _d !== void 0 ? _d : 0;
134
- const nativeToken = constants_1.NATIVE_ASSET_BY_NETWORK_ID[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkId, "f")];
170
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
135
171
  const balances = [
136
172
  {
137
173
  amount: nativeBalance.toString(),
@@ -154,30 +190,39 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
154
190
  return balances;
155
191
  });
156
192
  }
157
- parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, symbol, name }, entityId, sender, receiver, }) {
158
- if (tokenType === 'ERC721') {
159
- return {
160
- from: sender.address,
161
- to: receiver.address,
162
- tokenId: entityId,
163
- contractHash: address,
164
- type: 'nft',
165
- };
166
- }
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') {
167
197
  return {
168
198
  from: sender.address,
169
199
  to: receiver.address,
200
+ tokenId: entityId,
170
201
  contractHash: address,
171
- amount: amount.toString(),
172
- token: {
173
- decimals: decimals,
174
- hash: address,
175
- symbol: symbol,
176
- name: name,
177
- },
178
- type: 'token',
202
+ type: 'nft',
179
203
  };
180
204
  }
181
- }
182
- exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
183
- _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_networkId = 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
+ };
219
+ BitqueryBDSEthereum.MIRROR_URL = 'https://i4l7kcg43c.execute-api.us-east-1.amazonaws.com/production/';
220
+ BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID = {
221
+ '1': 'ethereum',
222
+ '25': 'cronos',
223
+ '56': 'bsc',
224
+ '137': 'matic',
225
+ '250': 'fantom',
226
+ '42220': 'celo_mainnet',
227
+ '43114': 'avalanche',
228
+ };
@@ -1,8 +1,9 @@
1
- import { CryptoCompareEDS, Currency, ExchangeDataService, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
- import { AvailableNetworkIds } from './constants';
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(networkId: AvailableNetworkIds);
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
  }