@cityofzion/bs-ethereum 1.4.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,20 @@
1
- import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialBy, 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
- export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger {
4
+ import { AvailableNetworkIds } from './BSEthereumHelper';
5
+ export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService<BSCustomName, AvailableNetworkIds>, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger {
6
+ #private;
5
7
  readonly blockchainName: BSCustomName;
6
- readonly feeToken: Token;
7
8
  readonly derivationPath: string;
9
+ feeToken: Token;
8
10
  blockchainDataService: BlockchainDataService;
9
11
  exchangeDataService: ExchangeDataService;
10
- ledgerService: LedgerServiceEthereum;
12
+ ledgerService: EthersLedgerServiceEthereum;
11
13
  tokens: Token[];
12
14
  nftDataService: NftDataService;
13
- network: Network;
14
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, getLedgerTransport?: (account: Account) => Promise<Transport>);
15
- setNetwork(param: PartialBy<Network, 'url'>): void;
15
+ network: Network<AvailableNetworkIds>;
16
+ constructor(blockchainName: BSCustomName, network?: Network<AvailableNetworkIds>, getLedgerTransport?: (account: Account) => Promise<Transport>);
17
+ setNetwork(network: Network<AvailableNetworkIds>): void;
16
18
  validateAddress(address: string): boolean;
17
19
  validateEncrypted(json: string): boolean;
18
20
  validateKey(key: string): boolean;
@@ -31,41 +31,39 @@ 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");
37
43
  const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
38
44
  const ethersBytes = __importStar(require("@ethersproject/bytes"));
39
45
  const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
40
- const constants_1 = require("./constants");
41
46
  const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
42
47
  const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
43
48
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
44
49
  const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
45
- const LedgerServiceEthereum_1 = require("./LedgerServiceEthereum");
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.TOKENS[network.type];
52
- this.feeToken = this.tokens.find(token => token.symbol === 'ETH');
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(param) {
56
- var _a;
57
- const network = {
58
- type: param.type,
59
- url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
60
- };
61
+ setNetwork(network) {
62
+ __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_setTokens).call(this, network);
61
63
  this.network = network;
62
- if (network.type !== 'mainnet') {
63
- this.blockchainDataService = new RpcBDSEthereum_1.RpcBDSEthereum(network);
64
- }
65
- else {
66
- this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network);
67
- }
68
- this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type);
64
+ const bitqueryNetwork = BitqueryBDSEthereum_1.BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID[network.id];
65
+ this.blockchainDataService = bitqueryNetwork ? new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network) : new RpcBDSEthereum_1.RpcBDSEthereum(network);
66
+ this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network, this.tokens);
69
67
  this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network);
70
68
  }
71
69
  validateAddress(address) {
@@ -146,7 +144,7 @@ class BSEthereum {
146
144
  }
147
145
  let signer;
148
146
  if (ledgerTransport) {
149
- signer = new LedgerServiceEthereum_1.LedgerSigner(ledgerTransport, provider);
147
+ signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
150
148
  }
151
149
  else {
152
150
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
@@ -154,7 +152,7 @@ class BSEthereum {
154
152
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
155
153
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
156
154
  let transactionParams;
157
- const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === param.intent.tokenHash);
155
+ const isNative = this.feeToken.hash === param.intent.tokenHash;
158
156
  if (isNative) {
159
157
  transactionParams = {
160
158
  to: param.intent.receiverAddress,
@@ -183,14 +181,14 @@ class BSEthereum {
183
181
  }
184
182
  let signer;
185
183
  if (ledgerTransport) {
186
- signer = new LedgerServiceEthereum_1.LedgerSigner(ledgerTransport, provider);
184
+ signer = new EthersLedgerServiceEthereum_1.EthersLedgerSigner(ledgerTransport, provider);
187
185
  }
188
186
  else {
189
187
  signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
190
188
  }
191
189
  const gasPrice = yield provider.getGasPrice();
192
190
  let estimated;
193
- const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === param.intent.tokenHash);
191
+ const isNative = this.feeToken.hash === param.intent.tokenHash;
194
192
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
195
193
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
196
194
  if (!isNative) {
@@ -217,3 +215,8 @@ class BSEthereum {
217
215
  }
218
216
  }
219
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,22 @@
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 & {});
3
+ export declare class BSEthereumHelper {
4
+ #private;
5
+ static DERIVATION_PATH: string;
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>): {
15
+ symbol: string;
16
+ name: string;
17
+ hash: string;
18
+ decimals: number;
19
+ };
20
+ static getNativeSymbol(network: Network<AvailableNetworkIds>): string;
21
+ static getRpcList(network: Network<AvailableNetworkIds>): string[];
22
+ }
@@ -0,0 +1,236 @@
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
+ }
23
+ exports.BSEthereumHelper = BSEthereumHelper;
24
+ _a = BSEthereumHelper;
25
+ _BSEthereumHelper_NATIVE_ASSET = { value: {
26
+ decimals: 18,
27
+ hash: '-',
28
+ name: 'ETH',
29
+ symbol: 'ETH',
30
+ } };
31
+ _BSEthereumHelper_NATIVE_SYMBOL_BY_NETWORK_ID = { value: {
32
+ '1': 'ETH',
33
+ '10': 'ETH',
34
+ '25': 'CRO',
35
+ '56': 'BNB',
36
+ '137': 'MATIC',
37
+ '1101': 'ETH',
38
+ '250': 'FTM',
39
+ '8453': 'ETH',
40
+ '80002': 'MATIC',
41
+ '42161': 'ETH',
42
+ '42220': 'CELO',
43
+ '43114': 'AVAX',
44
+ '59144': 'ETH',
45
+ '11155111': 'ETH',
46
+ '12227331': 'GAS',
47
+ } };
48
+ _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID = { value: {
49
+ '1': [
50
+ 'https://eth.llamarpc.com',
51
+ 'https://mainnet.infura.io/v3/',
52
+ 'https://ethereum-rpc.publicnode.com',
53
+ 'https://endpoints.omniatech.io/v1/eth/mainnet/public',
54
+ 'https://rpc.flashbots.net',
55
+ 'https://rpc.mevblocker.io',
56
+ ],
57
+ '10': [
58
+ 'https://optimism.llamarpc.com',
59
+ 'https://endpoints.omniatech.io/v1/op/mainnet/public',
60
+ 'https://optimism-rpc.publicnode.com',
61
+ 'https://optimism.meowrpc.com',
62
+ 'https://optimism.rpc.subquery.network/public',
63
+ ],
64
+ '25': ['https://cronos-evm-rpc.publicnode.com', 'https://1rpc.io/cro', 'https://rpc.vvs.finance'],
65
+ '56': [
66
+ 'https://bsc-dataseed.binance.org/',
67
+ 'https://binance.llamarpc.com',
68
+ 'https://bsc-dataseed.bnbchain.org',
69
+ 'https://endpoints.omniatech.io/v1/bsc/mainnet/public',
70
+ 'https://bsc-rpc.publicnode.com',
71
+ ],
72
+ '137': [
73
+ 'https://polygon-mainnet.infura.io',
74
+ 'https://polygon.llamarpc.com',
75
+ 'https://endpoints.omniatech.io/v1/matic/mainnet/public',
76
+ 'https://polygon.drpc.org',
77
+ 'https://polygon.meowrpc.com',
78
+ ],
79
+ '250': [
80
+ 'https://endpoints.omniatech.io/v1/fantom/mainnet/public',
81
+ 'https://rpcapi.fantom.network',
82
+ 'https://fantom-pokt.nodies.app',
83
+ 'https://fantom-rpc.publicnode.com',
84
+ 'https://fantom.drpc.org',
85
+ ],
86
+ '1101': [
87
+ 'https://polygon-zkevm.drpc.org',
88
+ 'https://polygon-zkevm.blockpi.network/v1/rpc/public',
89
+ 'https://1rpc.io/polygon/zkevm',
90
+ ],
91
+ '80002': [
92
+ 'https://polygon-amoy.drpc.org',
93
+ 'https://rpc.ankr.com/polygon_amoy',
94
+ 'https://polygon-amoy-bor-rpc.publicnode.com',
95
+ ],
96
+ '8453': [
97
+ 'https://base.rpc.subquery.network/public',
98
+ 'https://base.llamarpc.com',
99
+ 'https://mainnet.base.org',
100
+ 'https://1rpc.io/base',
101
+ 'https://base.meowrpc.com',
102
+ 'https://base-rpc.publicnode.com',
103
+ 'https://endpoints.omniatech.io/v1/base/mainnet/public',
104
+ ],
105
+ '42161': [
106
+ 'https://arbitrum.llamarpc.com',
107
+ 'https://arbitrum-one-rpc.publicnode.com',
108
+ 'https://arb-mainnet-public.unifra.io',
109
+ 'https://arbitrum-one.publicnode.com',
110
+ ],
111
+ '42220': [
112
+ 'https://forno.celo.org',
113
+ 'https://api.tatum.io/v3/blockchain/node/celo-mainnet',
114
+ 'https://rpc.ankr.com/celo',
115
+ ],
116
+ '43114': [
117
+ 'https://avalanche-mainnet.infura.io',
118
+ 'https://avalanche-c-chain-rpc.publicnode.com',
119
+ 'https://avalanche.public-rpc.com',
120
+ 'https://endpoints.omniatech.io/v1/avax/mainnet/public',
121
+ 'https://avalanche.drpc.org',
122
+ ],
123
+ '59144': [
124
+ 'https://linea.decubate.com',
125
+ 'https://linea.blockpi.network/v1/rpc/public',
126
+ 'https://linea.decubate.com',
127
+ ],
128
+ '11155111': [
129
+ 'https://ethereum-sepolia.rpc.subquery.network/public',
130
+ 'https://ethereum-sepolia-rpc.publicnode.com',
131
+ 'https://endpoints.omniatech.io/v1/eth/sepolia/public',
132
+ 'https://eth-sepolia.public.blastapi.io',
133
+ 'https://eth-sepolia-public.unifra.io',
134
+ 'https://1rpc.io/sepolia',
135
+ 'https://eth-sepolia.api.onfinality.io/public',
136
+ ],
137
+ '12227331': ['https://neoxseed1.ngd.network'],
138
+ } };
139
+ BSEthereumHelper.DERIVATION_PATH = "m/44'/60'/0'/0/?";
140
+ BSEthereumHelper.DEFAULT_PATH = "44'/60'/0'/0/0";
141
+ BSEthereumHelper.MAINNET_NETWORK_IDS = [
142
+ '1',
143
+ '10',
144
+ '25',
145
+ '56',
146
+ '137',
147
+ '250',
148
+ '8453',
149
+ '42161',
150
+ '42220',
151
+ '43114',
152
+ '59144',
153
+ ];
154
+ BSEthereumHelper.TESTNET_NETWORK_IDS = ['1101', '80002', '11155111', '12227331'];
155
+ BSEthereumHelper.ALL_NETWORK_IDS = [..._a.MAINNET_NETWORK_IDS, ..._a.TESTNET_NETWORK_IDS];
156
+ BSEthereumHelper.MAINNET_NETWORKS = [
157
+ {
158
+ id: '1',
159
+ name: 'Ethereum Mainnet',
160
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['1'][0],
161
+ },
162
+ {
163
+ id: '10',
164
+ name: 'Optimism Mainnet',
165
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['10'][0],
166
+ },
167
+ {
168
+ id: '25',
169
+ name: 'Cronos Mainnet',
170
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['25'][0],
171
+ },
172
+ {
173
+ id: '56',
174
+ name: 'Binance Smart Chain Mainnet',
175
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['56'][0],
176
+ },
177
+ {
178
+ id: '137',
179
+ name: 'Polygon Mainnet',
180
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['137'][0],
181
+ },
182
+ {
183
+ id: '250',
184
+ name: 'Fantom Mainnet',
185
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['250'][0],
186
+ },
187
+ {
188
+ id: '8453',
189
+ name: 'Base Protocol Mainnet',
190
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['8453'][0],
191
+ },
192
+ {
193
+ id: '42161',
194
+ name: 'Arbitrum Mainnet',
195
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['42161'][0],
196
+ },
197
+ {
198
+ id: '42220',
199
+ name: 'Celo Mainnet',
200
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['42220'][0],
201
+ },
202
+ {
203
+ id: '43114',
204
+ name: 'Avalanche Mainnet',
205
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['43114'][0],
206
+ },
207
+ {
208
+ id: '59144',
209
+ name: 'Linea Mainnet',
210
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['59144'][0],
211
+ },
212
+ ];
213
+ BSEthereumHelper.TESTNET_NETWORKS = [
214
+ {
215
+ id: '1101',
216
+ name: 'Polygon zkEVM Testnet',
217
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['1101'][0],
218
+ },
219
+ {
220
+ id: '80002',
221
+ name: 'Polygon Testnet',
222
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['80002'][0],
223
+ },
224
+ {
225
+ id: '11155111',
226
+ name: 'Ethereum Sepolia Testnet',
227
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['11155111'][0],
228
+ },
229
+ {
230
+ id: '12227331',
231
+ name: 'Neo3 Testnet',
232
+ url: __classPrivateFieldGet(_a, _a, "f", _BSEthereumHelper_RPC_LIST_BY_NETWORK_ID)['12227331'][0],
233
+ },
234
+ ];
235
+ BSEthereumHelper.ALL_NETWORKS = [..._a.MAINNET_NETWORKS, ..._a.TESTNET_NETWORKS];
236
+ BSEthereumHelper.DEFAULT_NETWORK = _a.MAINNET_NETWORKS[0];
@@ -1,9 +1,13 @@
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
4
  export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
4
5
  #private;
6
+ static MIRROR_URL: string;
7
+ static MIRROR_NETWORK_BY_NETWORK_ID: Partial<Record<AvailableNetworkIds, string>>;
8
+ static getMirrorNetworkId(network: Network<AvailableNetworkIds>): string;
5
9
  maxTimeToConfirmTransactionInMs: number;
6
- constructor(network: Network);
10
+ constructor(network: Network<AvailableNetworkIds>);
7
11
  getTransaction(hash: string): Promise<TransactionResponse>;
8
12
  getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
9
13
  getContract(): Promise<ContractResponse>;
@@ -22,29 +22,35 @@ 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_networkType;
25
+ var _BitqueryBDSEthereum_client, _BitqueryBDSEthereum_network, _BitqueryBDSEthereum_tokenCache;
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
+ 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
+ }
32
38
  constructor(network) {
33
39
  super(network);
34
40
  _BitqueryBDSEthereum_client.set(this, void 0);
35
- _BitqueryBDSEthereum_networkType.set(this, void 0);
41
+ _BitqueryBDSEthereum_network.set(this, void 0);
42
+ _BitqueryBDSEthereum_tokenCache.set(this, new Map());
36
43
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 8;
37
- if (network.type === 'custom')
38
- throw new Error('Custom network not supported');
39
- __classPrivateFieldSet(this, _BitqueryBDSEthereum_networkType, network.type, "f");
44
+ __classPrivateFieldSet(this, _BitqueryBDSEthereum_network, network, "f");
40
45
  __classPrivateFieldSet(this, _BitqueryBDSEthereum_client, axios_1.default.create({
41
- baseURL: constants_1.BITQUERY_MIRROR_URL,
46
+ baseURL: BitqueryBDSEthereum.MIRROR_URL,
42
47
  }), "f");
43
48
  }
44
49
  getTransaction(hash) {
45
50
  return __awaiter(this, void 0, void 0, function* () {
51
+ const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
46
52
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-transaction/${hash}`, {
47
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")] },
53
+ params: { network: mirrorNetwork },
48
54
  });
49
55
  if (!result.data || !result.data.ethereum.transfers.length)
50
56
  throw new Error('Transaction not found');
@@ -65,8 +71,9 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
65
71
  return __awaiter(this, void 0, void 0, function* () {
66
72
  const limit = 10;
67
73
  const offset = limit * (page - 1);
74
+ const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
68
75
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-transactions/${address}`, {
69
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")], limit, offset },
76
+ params: { network: mirrorNetwork, limit, offset },
70
77
  });
71
78
  if (!result.data)
72
79
  throw new Error('Address does not have transactions');
@@ -103,42 +110,46 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
103
110
  }
104
111
  getTokenInfo(hash) {
105
112
  return __awaiter(this, void 0, void 0, function* () {
106
- const localToken = constants_1.TOKENS[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")].find(token => token.hash === hash);
107
- if (localToken)
108
- return localToken;
113
+ if (__classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").has(hash)) {
114
+ return __classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").get(hash);
115
+ }
116
+ const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
109
117
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-token-info/${hash}`, {
110
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")] },
118
+ params: { network: mirrorNetwork },
111
119
  });
112
120
  if (!result.data || result.data.ethereum.smartContractCalls.length <= 0)
113
121
  throw new Error('Token not found');
114
122
  const { address: { address }, currency: { decimals, name, symbol, tokenType }, } = result.data.ethereum.smartContractCalls[0].smartContract;
115
123
  if (tokenType !== 'ERC20')
116
124
  throw new Error('Token is not ERC20');
117
- return {
125
+ const token = {
118
126
  hash: address,
119
- name,
120
127
  symbol,
121
128
  decimals,
129
+ name,
122
130
  };
131
+ __classPrivateFieldGet(this, _BitqueryBDSEthereum_tokenCache, "f").set(hash, token);
132
+ return token;
123
133
  });
124
134
  }
125
135
  getBalance(address) {
126
136
  var _a, _b, _c, _d;
127
137
  return __awaiter(this, void 0, void 0, function* () {
138
+ const mirrorNetwork = BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
128
139
  const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f").get(`/get-balance/${address}`, {
129
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")] },
140
+ params: { network: mirrorNetwork },
130
141
  });
131
142
  const data = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.ethereum.address[0].balances) !== null && _b !== void 0 ? _b : [];
132
- const ethBalance = (_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.ethereum.address[0].balance) !== null && _d !== void 0 ? _d : 0;
133
- const ethToken = constants_1.NATIVE_ASSETS.find(asset => asset.symbol === 'ETH');
143
+ const nativeBalance = (_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.ethereum.address[0].balance) !== null && _d !== void 0 ? _d : 0;
144
+ const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _BitqueryBDSEthereum_network, "f"));
134
145
  const balances = [
135
146
  {
136
- amount: ethBalance.toString(),
137
- token: ethToken,
147
+ amount: nativeBalance.toString(),
148
+ token: nativeToken,
138
149
  },
139
150
  ];
140
- data.forEach(({ value, currency: { address, decimals, name, symbol } }) => {
141
- if (value < 0 || address === ethToken.hash)
151
+ data.forEach(({ value, currency: { address, decimals, symbol, name } }) => {
152
+ if (value < 0 || address === nativeToken.hash)
142
153
  return;
143
154
  balances.push({
144
155
  amount: value.toString(),
@@ -153,7 +164,7 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
153
164
  return balances;
154
165
  });
155
166
  }
156
- parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, name, symbol }, entityId, sender, receiver, }) {
167
+ parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, symbol, name }, entityId, sender, receiver, }) {
157
168
  if (tokenType === 'ERC721') {
158
169
  return {
159
170
  from: sender.address,
@@ -171,12 +182,22 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
171
182
  token: {
172
183
  decimals: decimals,
173
184
  hash: address,
174
- name: name,
175
185
  symbol: symbol,
186
+ name: name,
176
187
  },
177
188
  type: 'token',
178
189
  };
179
190
  }
180
191
  }
181
192
  exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
182
- _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_networkType = new WeakMap();
193
+ _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_network = new WeakMap(), _BitqueryBDSEthereum_tokenCache = new WeakMap();
194
+ BitqueryBDSEthereum.MIRROR_URL = 'https://i4l7kcg43c.execute-api.us-east-1.amazonaws.com/production/';
195
+ BitqueryBDSEthereum.MIRROR_NETWORK_BY_NETWORK_ID = {
196
+ '1': 'ethereum',
197
+ '25': 'cronos',
198
+ '56': 'bsc',
199
+ '137': 'matic',
200
+ '250': 'fantom',
201
+ '42220': 'celo_mainnet',
202
+ '43114': 'avalanche',
203
+ };
@@ -1,7 +1,8 @@
1
- import { CryptoCompareEDS, Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
1
+ import { CryptoCompareEDS, Currency, ExchangeDataService, Network, Token, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './BSEthereumHelper';
2
3
  export declare class BitqueryEDSEthereum extends CryptoCompareEDS implements ExchangeDataService {
3
4
  #private;
4
- constructor(networkType: NetworkType);
5
+ constructor(network: Network<AvailableNetworkIds>, tokens: Token[]);
5
6
  getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
6
7
  private getCurrencyRatio;
7
8
  }
@@ -22,32 +22,31 @@ 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 _BitqueryEDSEthereum_client, _BitqueryEDSEthereum_networkType;
25
+ var _BitqueryEDSEthereum_client, _BitqueryEDSEthereum_network;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.BitqueryEDSEthereum = void 0;
28
28
  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 constants_1 = require("./constants");
32
+ const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
33
33
  dayjs_1.default.extend(utc_1.default);
34
34
  class BitqueryEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
35
- constructor(networkType) {
36
- super(networkType, constants_1.TOKENS[networkType]);
35
+ constructor(network, tokens) {
36
+ super(tokens);
37
37
  _BitqueryEDSEthereum_client.set(this, void 0);
38
- _BitqueryEDSEthereum_networkType.set(this, void 0);
39
- __classPrivateFieldSet(this, _BitqueryEDSEthereum_networkType, networkType, "f");
38
+ _BitqueryEDSEthereum_network.set(this, void 0);
39
+ __classPrivateFieldSet(this, _BitqueryEDSEthereum_network, network, "f");
40
40
  __classPrivateFieldSet(this, _BitqueryEDSEthereum_client, axios_1.default.create({
41
- baseURL: constants_1.BITQUERY_MIRROR_URL,
41
+ baseURL: BitqueryBDSEthereum_1.BitqueryBDSEthereum.MIRROR_URL,
42
42
  }), "f");
43
43
  }
44
44
  getTokenPrices(currency) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- if (__classPrivateFieldGet(this, _BitqueryEDSEthereum_networkType, "f") !== 'mainnet')
47
- throw new Error('Exchange is only available on mainnet');
48
46
  const twoDaysAgo = dayjs_1.default.utc().subtract(2, 'day').startOf('date').toISOString();
47
+ const mirrorNetwork = BitqueryBDSEthereum_1.BitqueryBDSEthereum.getMirrorNetworkId(__classPrivateFieldGet(this, _BitqueryEDSEthereum_network, "f"));
49
48
  const result = yield __classPrivateFieldGet(this, _BitqueryEDSEthereum_client, "f").get(`/get-price`, {
50
- params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryEDSEthereum_networkType, "f")], after: twoDaysAgo },
49
+ params: { network: mirrorNetwork, after: twoDaysAgo },
51
50
  });
52
51
  if (!result.data) {
53
52
  throw new Error('There is no price data');
@@ -72,4 +71,4 @@ class BitqueryEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
72
71
  }
73
72
  }
74
73
  exports.BitqueryEDSEthereum = BitqueryEDSEthereum;
75
- _BitqueryEDSEthereum_client = new WeakMap(), _BitqueryEDSEthereum_networkType = new WeakMap();
74
+ _BitqueryEDSEthereum_client = new WeakMap(), _BitqueryEDSEthereum_network = new WeakMap();
@@ -2,21 +2,21 @@ import { Account, LedgerService, LedgerServiceEmitter } from '@cityofzion/blockc
2
2
  import Transport from '@ledgerhq/hw-transport';
3
3
  import { ethers, Signer } from 'ethers';
4
4
  import { TypedDataSigner } from '@ethersproject/abstract-signer';
5
- export declare class LedgerSigner extends Signer implements TypedDataSigner {
5
+ export declare class EthersLedgerSigner extends Signer implements TypedDataSigner {
6
6
  #private;
7
7
  constructor(transport: Transport, provider?: ethers.providers.Provider, emitter?: LedgerServiceEmitter);
8
- connect(provider: ethers.providers.Provider): LedgerSigner;
8
+ connect(provider: ethers.providers.Provider): EthersLedgerSigner;
9
9
  getAddress(): Promise<string>;
10
10
  getPublicKey(): Promise<string>;
11
11
  signMessage(message: string | ethers.utils.Bytes): Promise<string>;
12
12
  signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string>;
13
13
  _signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, any>): Promise<string>;
14
14
  }
15
- export declare class LedgerServiceEthereum implements LedgerService {
15
+ export declare class EthersLedgerServiceEthereum implements LedgerService {
16
16
  getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined;
17
17
  emitter: LedgerServiceEmitter;
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): LedgerSigner;
21
+ getSigner(transport: Transport): EthersLedgerSigner;
22
22
  }