@cityofzion/bs-ethereum 2.2.13 → 2.4.0

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.
Files changed (28) hide show
  1. package/dist/BSEthereum.d.ts +8 -8
  2. package/dist/BSEthereum.js +79 -50
  3. package/dist/{BSEthereumHelper.d.ts → constants/BSEthereumConstants.d.ts} +6 -15
  4. package/dist/constants/BSEthereumConstants.js +235 -0
  5. package/dist/helpers/BSEthereumHelper.d.ts +16 -0
  6. package/dist/helpers/BSEthereumHelper.js +58 -0
  7. package/dist/index.d.ts +11 -7
  8. package/dist/index.js +11 -7
  9. package/dist/{BlockscoutNeoXBDSEthereum.d.ts → services/blockchain-data/BlockscoutBDSEthereum.d.ts} +2 -2
  10. package/dist/{BlockscoutNeoXBDSEthereum.js → services/blockchain-data/BlockscoutBDSEthereum.js} +23 -22
  11. package/dist/{MoralisBDSEthereum.d.ts → services/blockchain-data/MoralisBDSEthereum.d.ts} +1 -1
  12. package/dist/{MoralisBDSEthereum.js → services/blockchain-data/MoralisBDSEthereum.js} +2 -2
  13. package/dist/{RpcBDSEthereum.d.ts → services/blockchain-data/RpcBDSEthereum.d.ts} +1 -1
  14. package/dist/{RpcBDSEthereum.js → services/blockchain-data/RpcBDSEthereum.js} +2 -2
  15. package/dist/{BlockscoutNeoXEDSEthereum.d.ts → services/exchange-data/BlockscoutEDSEthereum.d.ts} +1 -1
  16. package/dist/{BlockscoutNeoXEDSEthereum.js → services/exchange-data/BlockscoutEDSEthereum.js} +17 -15
  17. package/dist/{MoralisEDSEthereum.d.ts → services/exchange-data/MoralisEDSEthereum.d.ts} +1 -1
  18. package/dist/{MoralisEDSEthereum.js → services/exchange-data/MoralisEDSEthereum.js} +2 -2
  19. package/dist/{BlockscoutNeoXESEthereum.d.ts → services/explorer/BlockscoutESEthereum.d.ts} +2 -2
  20. package/dist/{BlockscoutNeoXESEthereum.js → services/explorer/BlockscoutESEthereum.js} +25 -16
  21. package/dist/{EthersLedgerServiceEthereum.d.ts → services/ledger/EthersLedgerServiceEthereum.d.ts} +9 -8
  22. package/dist/{EthersLedgerServiceEthereum.js → services/ledger/EthersLedgerServiceEthereum.js} +40 -58
  23. package/dist/{GhostMarketNDSEthereum.d.ts → services/nft-data/GhostMarketNDSEthereum.d.ts} +1 -1
  24. package/dist/{RpcNDSEthereum.js → services/nft-data/RpcNDSEthereum.js} +1 -1
  25. package/package.json +2 -2
  26. package/dist/BSEthereumHelper.js +0 -259
  27. /package/dist/{GhostMarketNDSEthereum.js → services/nft-data/GhostMarketNDSEthereum.js} +0 -0
  28. /package/dist/{RpcNDSEthereum.d.ts → services/nft-data/RpcNDSEthereum.d.ts} +0 -0
@@ -1,11 +1,10 @@
1
- import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, ExplorerService, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
2
- import { EthersLedgerServiceEthereum } from './EthersLedgerServiceEthereum';
3
- import Transport from '@ledgerhq/hw-transport';
4
- import { BSEthereumNetworkId } from './BSEthereumHelper';
1
+ import { Account, BSCalculableFee, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, ExplorerService, Network, NftDataService, Token, TransferParam, GetLedgerTransport } from '@cityofzion/blockchain-service';
2
+ import { BSEthereumNetworkId } from './constants/BSEthereumConstants';
3
+ import { EthersLedgerServiceEthereum } from './services/ledger/EthersLedgerServiceEthereum';
5
4
  export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService<BSCustomName, BSEthereumNetworkId>, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger, BSWithExplorerService {
6
5
  #private;
7
6
  readonly blockchainName: BSCustomName;
8
- readonly derivationPath: string;
7
+ readonly bip44DerivationPath: string;
9
8
  feeToken: Token;
10
9
  blockchainDataService: BlockchainDataService;
11
10
  exchangeDataService: ExchangeDataService;
@@ -14,18 +13,19 @@ export declare class BSEthereum<BSCustomName extends string = string> implements
14
13
  nftDataService: NftDataService;
15
14
  network: Network<BSEthereumNetworkId>;
16
15
  explorerService: ExplorerService;
17
- constructor(blockchainName: BSCustomName, network?: Network<BSEthereumNetworkId>, getLedgerTransport?: (account: Account) => Promise<Transport>);
16
+ constructor(blockchainName: BSCustomName, network?: Network<BSEthereumNetworkId>, getLedgerTransport?: GetLedgerTransport);
17
+ clone(): BSEthereum<BSCustomName>;
18
18
  setNetwork(network: Network<BSEthereumNetworkId>): void;
19
19
  validateAddress(address: string): boolean;
20
20
  validateEncrypted(json: string): boolean;
21
21
  validateKey(key: string): boolean;
22
22
  validateNameServiceDomainFormat(domainName: string): boolean;
23
- generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
23
+ generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Account;
24
24
  generateAccountFromKey(key: string): Account;
25
25
  generateAccountFromPublicKey(publicKey: string): Account;
26
26
  decrypt(json: string, password: string): Promise<Account>;
27
27
  encrypt(key: string, password: string): Promise<string>;
28
- transfer(param: TransferParam): Promise<string>;
28
+ transfer(param: TransferParam): Promise<string[]>;
29
29
  calculateTransferFee(param: TransferParam): Promise<string>;
30
30
  resolveNameServiceDomain(domainName: string): Promise<string>;
31
31
  }
@@ -31,48 +31,60 @@ 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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
35
+ if (kind === "m") throw new TypeError("Private method is not writable");
36
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
+ 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");
38
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
39
+ };
34
40
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
35
41
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
36
42
  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
43
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
38
44
  };
39
- var _BSEthereum_instances, _BSEthereum_buildTransferParams, _BSEthereum_setTokens;
45
+ var _BSEthereum_instances, _BSEthereum_getLedgerTransport, _BSEthereum_generateSigner, _BSEthereum_buildTransferParams, _BSEthereum_setTokens;
40
46
  Object.defineProperty(exports, "__esModule", { value: true });
41
47
  exports.BSEthereum = void 0;
42
48
  const ethers_1 = require("ethers");
43
49
  const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
44
50
  const ethersBytes = __importStar(require("@ethersproject/bytes"));
45
51
  const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
46
- const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
47
- const EthersLedgerServiceEthereum_1 = require("./EthersLedgerServiceEthereum");
48
- const BSEthereumHelper_1 = require("./BSEthereumHelper");
49
- const MoralisBDSEthereum_1 = require("./MoralisBDSEthereum");
50
- const MoralisEDSEthereum_1 = require("./MoralisEDSEthereum");
51
- const BlockscoutNeoXBDSEthereum_1 = require("./BlockscoutNeoXBDSEthereum");
52
- const BlockscoutNeoXEDSEthereum_1 = require("./BlockscoutNeoXEDSEthereum");
53
- const BlockscoutNeoXESEthereum_1 = require("./BlockscoutNeoXESEthereum");
52
+ const BSEthereumConstants_1 = require("./constants/BSEthereumConstants");
53
+ const EthersLedgerServiceEthereum_1 = require("./services/ledger/EthersLedgerServiceEthereum");
54
+ const BSEthereumHelper_1 = require("./helpers/BSEthereumHelper");
55
+ const BlockscoutBDSEthereum_1 = require("./services/blockchain-data/BlockscoutBDSEthereum");
56
+ const BlockscoutEDSEthereum_1 = require("./services/exchange-data/BlockscoutEDSEthereum");
57
+ const MoralisBDSEthereum_1 = require("./services/blockchain-data/MoralisBDSEthereum");
58
+ const MoralisEDSEthereum_1 = require("./services/exchange-data/MoralisEDSEthereum");
59
+ const GhostMarketNDSEthereum_1 = require("./services/nft-data/GhostMarketNDSEthereum");
60
+ const BlockscoutESEthereum_1 = require("./services/explorer/BlockscoutESEthereum");
54
61
  class BSEthereum {
55
62
  constructor(blockchainName, network, getLedgerTransport) {
56
63
  _BSEthereum_instances.add(this);
57
- network = network !== null && network !== void 0 ? network : BSEthereumHelper_1.BSEthereumHelper.DEFAULT_NETWORK;
64
+ _BSEthereum_getLedgerTransport.set(this, void 0);
65
+ network = network !== null && network !== void 0 ? network : BSEthereumConstants_1.BSEthereumConstants.DEFAULT_NETWORK;
58
66
  this.blockchainName = blockchainName;
59
- this.ledgerService = new EthersLedgerServiceEthereum_1.EthersLedgerServiceEthereum(getLedgerTransport);
60
- this.derivationPath = BSEthereumHelper_1.BSEthereumHelper.DERIVATION_PATH;
67
+ this.ledgerService = new EthersLedgerServiceEthereum_1.EthersLedgerServiceEthereum(this, getLedgerTransport);
68
+ __classPrivateFieldSet(this, _BSEthereum_getLedgerTransport, getLedgerTransport, "f");
69
+ this.bip44DerivationPath = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_BIP44_DERIVATION_PATH;
61
70
  this.setNetwork(network);
62
71
  }
72
+ clone() {
73
+ return new BSEthereum(this.blockchainName, this.network, __classPrivateFieldGet(this, _BSEthereum_getLedgerTransport, "f"));
74
+ }
63
75
  setNetwork(network) {
64
76
  __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_setTokens).call(this, network);
65
77
  this.network = network;
66
- if (BlockscoutNeoXBDSEthereum_1.BlockscoutNeoXBDSEthereum.isSupported(network)) {
67
- this.exchangeDataService = new BlockscoutNeoXEDSEthereum_1.BlockscoutNeoXEDSEthereum(network);
68
- this.blockchainDataService = new BlockscoutNeoXBDSEthereum_1.BlockscoutNeoXBDSEthereum(network);
78
+ if (BlockscoutBDSEthereum_1.BlockscoutBDSEthereum.isSupported(network)) {
79
+ this.exchangeDataService = new BlockscoutEDSEthereum_1.BlockscoutEDSEthereum(network);
80
+ this.blockchainDataService = new BlockscoutBDSEthereum_1.BlockscoutBDSEthereum(network);
69
81
  }
70
82
  else {
71
83
  this.exchangeDataService = new MoralisEDSEthereum_1.MoralisEDSEthereum(network, this.blockchainDataService);
72
84
  this.blockchainDataService = new MoralisBDSEthereum_1.MoralisBDSEthereum(network);
73
85
  }
74
86
  this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network);
75
- this.explorerService = new BlockscoutNeoXESEthereum_1.BlockscoutNeoXESEthereum(network);
87
+ this.explorerService = new BlockscoutESEthereum_1.BlockscoutESEthereum(network);
76
88
  }
77
89
  validateAddress(address) {
78
90
  return ethers_1.ethers.utils.isAddress(address);
@@ -99,13 +111,13 @@ class BSEthereum {
99
111
  return true;
100
112
  }
101
113
  generateAccountFromMnemonic(mnemonic, index) {
102
- const path = this.derivationPath.replace('?', index.toString());
103
- const wallet = ethers_1.ethers.Wallet.fromMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic, path);
114
+ const bip44Path = this.bip44DerivationPath.replace('?', index.toString());
115
+ const wallet = ethers_1.ethers.Wallet.fromMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic, bip44Path);
104
116
  return {
105
117
  address: wallet.address,
106
118
  key: wallet.privateKey,
107
119
  type: 'privateKey',
108
- derivationPath: path,
120
+ bip44Path,
109
121
  };
110
122
  }
111
123
  generateAccountFromKey(key) {
@@ -142,23 +154,41 @@ class BSEthereum {
142
154
  }
143
155
  transfer(param) {
144
156
  return __awaiter(this, void 0, void 0, function* () {
145
- const { signer, transactionParams, gasPrice } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, param);
146
- let gasLimit;
147
- try {
148
- gasLimit = yield signer.estimateGas(transactionParams);
149
- }
150
- catch (_a) {
151
- gasLimit = BSEthereumHelper_1.BSEthereumHelper.DEFAULT_GAS_LIMIT;
157
+ const signer = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_generateSigner).call(this, param.senderAccount, param.isLedger);
158
+ const sentTransactionHashes = [];
159
+ for (const intent of param.intents) {
160
+ let transactionHash = '';
161
+ try {
162
+ const { transactionParams, gasPrice } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, intent);
163
+ let gasLimit;
164
+ try {
165
+ gasLimit = yield signer.estimateGas(transactionParams);
166
+ }
167
+ catch (_a) {
168
+ gasLimit = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT;
169
+ }
170
+ const transaction = yield signer.sendTransaction(Object.assign(Object.assign({}, transactionParams), { gasLimit, maxPriorityFeePerGas: gasPrice, maxFeePerGas: gasPrice }));
171
+ transactionHash = transaction.hash;
172
+ }
173
+ catch (_b) {
174
+ /* empty */
175
+ }
176
+ sentTransactionHashes.push(transactionHash);
152
177
  }
153
- const transaction = yield signer.sendTransaction(Object.assign(Object.assign({}, transactionParams), { gasLimit, maxPriorityFeePerGas: gasPrice, maxFeePerGas: gasPrice }));
154
- return transaction.hash;
178
+ return sentTransactionHashes;
155
179
  });
156
180
  }
157
181
  calculateTransferFee(param) {
158
182
  return __awaiter(this, void 0, void 0, function* () {
159
- const { signer, transactionParams, gasPrice } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, param);
160
- const estimated = yield signer.estimateGas(transactionParams);
161
- return ethers_1.ethers.utils.formatEther(gasPrice.mul(estimated));
183
+ const signer = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_generateSigner).call(this, param.senderAccount, param.isLedger);
184
+ let fee = ethers_1.ethers.utils.parseEther('0');
185
+ for (const intent of param.intents) {
186
+ const { gasPrice, transactionParams } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, intent);
187
+ const estimated = yield signer.estimateGas(transactionParams);
188
+ const intentFee = gasPrice.mul(estimated);
189
+ fee = fee.add(intentFee);
190
+ }
191
+ return ethers_1.ethers.utils.formatEther(fee);
162
192
  });
163
193
  }
164
194
  resolveNameServiceDomain(domainName) {
@@ -172,44 +202,43 @@ class BSEthereum {
172
202
  }
173
203
  }
174
204
  exports.BSEthereum = BSEthereum;
175
- _BSEthereum_instances = new WeakSet(), _BSEthereum_buildTransferParams = function _BSEthereum_buildTransferParams(param) {
176
- var _a;
205
+ _BSEthereum_getLedgerTransport = new WeakMap(), _BSEthereum_instances = new WeakSet(), _BSEthereum_generateSigner = function _BSEthereum_generateSigner(account, isLedger) {
177
206
  return __awaiter(this, void 0, void 0, function* () {
178
207
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
179
- let ledgerTransport;
180
- if (param.isLedger) {
208
+ if (isLedger) {
181
209
  if (!this.ledgerService.getLedgerTransport)
182
210
  throw new Error('You must provide getLedgerTransport function to use Ledger');
183
- ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
184
- }
185
- let signer;
186
- if (ledgerTransport) {
187
- signer = this.ledgerService.getSigner(ledgerTransport, provider);
211
+ if (typeof account.bip44Path !== 'string')
212
+ throw new Error('Your account must have bip44 path to use Ledger');
213
+ const ledgerTransport = yield this.ledgerService.getLedgerTransport(account);
214
+ return this.ledgerService.getSigner(ledgerTransport, account.bip44Path, provider);
188
215
  }
189
- else {
190
- signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
191
- }
192
- const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
193
- const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
216
+ return new ethers_1.ethers.Wallet(account.key, provider);
217
+ });
218
+ }, _BSEthereum_buildTransferParams = function _BSEthereum_buildTransferParams(intent) {
219
+ var _a;
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
222
+ const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
223
+ const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
194
224
  const gasPrice = yield provider.getGasPrice();
195
225
  let transactionParams = {
196
226
  type: 2,
197
227
  };
198
- const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
228
+ const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(intent.tokenHash);
199
229
  if (isNative) {
200
- transactionParams.to = param.intent.receiverAddress;
230
+ transactionParams.to = intent.receiverAddress;
201
231
  transactionParams.value = amount;
202
232
  }
203
233
  else {
204
- const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, [
234
+ const contract = new ethers_1.ethers.Contract(intent.tokenHash, [
205
235
  'function transfer(address to, uint amount) returns (bool)',
206
236
  ]);
207
- const populatedTransaction = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
237
+ const populatedTransaction = yield contract.populateTransaction.transfer(intent.receiverAddress, amount);
208
238
  transactionParams = Object.assign(Object.assign({}, populatedTransaction), transactionParams);
209
239
  }
210
240
  return {
211
241
  transactionParams,
212
- signer,
213
242
  gasPrice,
214
243
  };
215
244
  });
@@ -1,11 +1,12 @@
1
- import { Network, NetworkId } from '@cityofzion/blockchain-service';
1
+ import { Network, NetworkId, Token } from '@cityofzion/blockchain-service';
2
2
  export type BSEthereumNetworkId = NetworkId<'1' | '10' | '25' | '56' | '137' | '250' | '1101' | '8453' | '80002' | '42161' | '42220' | '43114' | '59144' | '11155111' | '47763' | '12227332'>;
3
- export declare class BSEthereumHelper {
4
- #private;
3
+ export declare class BSEthereumConstants {
5
4
  static DEFAULT_DECIMALS: number;
6
5
  static DEFAULT_GAS_LIMIT: number;
7
- static DERIVATION_PATH: string;
8
- static DEFAULT_PATH: string;
6
+ static NATIVE_ASSET: Token;
7
+ static NATIVE_SYMBOL_BY_NETWORK_ID: Record<BSEthereumNetworkId, string>;
8
+ static RPC_LIST_BY_NETWORK_ID: Record<BSEthereumNetworkId, string[]>;
9
+ static DEFAULT_BIP44_DERIVATION_PATH: string;
9
10
  static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId;
10
11
  static NEOX_MAINNET_NETWORK_ID: BSEthereumNetworkId;
11
12
  static NEOX_NETWORK_IDS: BSEthereumNetworkId[];
@@ -19,14 +20,4 @@ export declare class BSEthereumHelper {
19
20
  static TESTNET_NETWORKS: Network<BSEthereumNetworkId>[];
20
21
  static ALL_NETWORKS: Network<BSEthereumNetworkId>[];
21
22
  static DEFAULT_NETWORK: Network<BSEthereumNetworkId>;
22
- static getNativeAsset(network: Network<BSEthereumNetworkId>): {
23
- symbol: string;
24
- name: string;
25
- hash: string;
26
- decimals: number;
27
- };
28
- static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
29
- static getRpcList(network: Network<BSEthereumNetworkId>): string[];
30
- static isMainnet(network: Network<BSEthereumNetworkId>): boolean;
31
- static normalizeHash(hash: string): string;
32
23
  }
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BSEthereumConstants = void 0;
5
+ class BSEthereumConstants {
6
+ }
7
+ exports.BSEthereumConstants = BSEthereumConstants;
8
+ _a = BSEthereumConstants;
9
+ BSEthereumConstants.DEFAULT_DECIMALS = 18;
10
+ BSEthereumConstants.DEFAULT_GAS_LIMIT = 0x5208;
11
+ BSEthereumConstants.NATIVE_ASSET = {
12
+ decimals: 18,
13
+ hash: '-',
14
+ name: 'ETH',
15
+ symbol: 'ETH',
16
+ };
17
+ BSEthereumConstants.NATIVE_SYMBOL_BY_NETWORK_ID = {
18
+ '1': 'ETH',
19
+ '10': 'ETH',
20
+ '25': 'CRO',
21
+ '56': 'BNB',
22
+ '137': 'MATIC',
23
+ '1101': 'ETH',
24
+ '250': 'FTM',
25
+ '8453': 'ETH',
26
+ '80002': 'MATIC',
27
+ '42161': 'ETH',
28
+ '42220': 'CELO',
29
+ '43114': 'AVAX',
30
+ '59144': 'ETH',
31
+ '11155111': 'ETH',
32
+ '47763': 'GAS',
33
+ '12227332': 'GAS',
34
+ };
35
+ BSEthereumConstants.RPC_LIST_BY_NETWORK_ID = {
36
+ '1': [
37
+ 'https://eth.llamarpc.com',
38
+ 'https://mainnet.infura.io/v3/',
39
+ 'https://ethereum-rpc.publicnode.com',
40
+ 'https://endpoints.omniatech.io/v1/eth/mainnet/public',
41
+ 'https://rpc.flashbots.net',
42
+ 'https://rpc.mevblocker.io',
43
+ ],
44
+ '10': [
45
+ 'https://optimism.llamarpc.com',
46
+ 'https://endpoints.omniatech.io/v1/op/mainnet/public',
47
+ 'https://optimism-rpc.publicnode.com',
48
+ 'https://optimism.meowrpc.com',
49
+ 'https://optimism.rpc.subquery.network/public',
50
+ ],
51
+ '25': ['https://cronos-evm-rpc.publicnode.com', 'https://1rpc.io/cro', 'https://rpc.vvs.finance'],
52
+ '56': [
53
+ 'https://bsc-dataseed.binance.org/',
54
+ 'https://binance.llamarpc.com',
55
+ 'https://bsc-dataseed.bnbchain.org',
56
+ 'https://endpoints.omniatech.io/v1/bsc/mainnet/public',
57
+ 'https://bsc-rpc.publicnode.com',
58
+ ],
59
+ '137': [
60
+ 'https://polygon-mainnet.infura.io',
61
+ 'https://polygon.llamarpc.com',
62
+ 'https://endpoints.omniatech.io/v1/matic/mainnet/public',
63
+ 'https://polygon.drpc.org',
64
+ 'https://polygon.meowrpc.com',
65
+ ],
66
+ '250': [
67
+ 'https://endpoints.omniatech.io/v1/fantom/mainnet/public',
68
+ 'https://rpcapi.fantom.network',
69
+ 'https://fantom-pokt.nodies.app',
70
+ 'https://fantom-rpc.publicnode.com',
71
+ 'https://fantom.drpc.org',
72
+ ],
73
+ '1101': [
74
+ 'https://polygon-zkevm.drpc.org',
75
+ 'https://polygon-zkevm.blockpi.network/v1/rpc/public',
76
+ 'https://1rpc.io/polygon/zkevm',
77
+ ],
78
+ '80002': [
79
+ 'https://polygon-amoy.drpc.org',
80
+ 'https://rpc.ankr.com/polygon_amoy',
81
+ 'https://polygon-amoy-bor-rpc.publicnode.com',
82
+ ],
83
+ '8453': [
84
+ 'https://base.rpc.subquery.network/public',
85
+ 'https://base.llamarpc.com',
86
+ 'https://mainnet.base.org',
87
+ 'https://1rpc.io/base',
88
+ 'https://base.meowrpc.com',
89
+ 'https://base-rpc.publicnode.com',
90
+ 'https://endpoints.omniatech.io/v1/base/mainnet/public',
91
+ ],
92
+ '42161': [
93
+ 'https://arbitrum.llamarpc.com',
94
+ 'https://arbitrum-one-rpc.publicnode.com',
95
+ 'https://arb-mainnet-public.unifra.io',
96
+ 'https://arbitrum-one.publicnode.com',
97
+ ],
98
+ '42220': [
99
+ 'https://forno.celo.org',
100
+ 'https://api.tatum.io/v3/blockchain/node/celo-mainnet',
101
+ 'https://rpc.ankr.com/celo',
102
+ ],
103
+ '43114': [
104
+ 'https://avalanche-mainnet.infura.io',
105
+ 'https://avalanche-c-chain-rpc.publicnode.com',
106
+ 'https://avalanche.public-rpc.com',
107
+ 'https://endpoints.omniatech.io/v1/avax/mainnet/public',
108
+ 'https://avalanche.drpc.org',
109
+ ],
110
+ '59144': [
111
+ 'https://linea.decubate.com',
112
+ 'https://linea.blockpi.network/v1/rpc/public',
113
+ 'https://linea.decubate.com',
114
+ ],
115
+ '11155111': [
116
+ 'https://ethereum-sepolia.rpc.subquery.network/public',
117
+ 'https://ethereum-sepolia-rpc.publicnode.com',
118
+ 'https://endpoints.omniatech.io/v1/eth/sepolia/public',
119
+ 'https://eth-sepolia.public.blastapi.io',
120
+ 'https://eth-sepolia-public.unifra.io',
121
+ 'https://1rpc.io/sepolia',
122
+ 'https://eth-sepolia.api.onfinality.io/public',
123
+ ],
124
+ '47763': ['https://mainnet-1.rpc.banelabs.org'],
125
+ '12227332': ['https://neoxt4seed1.ngd.network'],
126
+ };
127
+ BSEthereumConstants.DEFAULT_BIP44_DERIVATION_PATH = "m/44'/60'/0'/0/?";
128
+ BSEthereumConstants.NEOX_TESTNET_NETWORK_ID = '12227332';
129
+ BSEthereumConstants.NEOX_MAINNET_NETWORK_ID = '47763';
130
+ BSEthereumConstants.NEOX_NETWORK_IDS = [_a.NEOX_TESTNET_NETWORK_ID, _a.NEOX_MAINNET_NETWORK_ID];
131
+ BSEthereumConstants.NEOX_TESTNET_NETWORK = {
132
+ id: _a.NEOX_TESTNET_NETWORK_ID,
133
+ name: 'NeoX Testnet',
134
+ url: _a.RPC_LIST_BY_NETWORK_ID[_a.NEOX_TESTNET_NETWORK_ID][0],
135
+ };
136
+ BSEthereumConstants.NEOX_MAINNET_NETWORK = {
137
+ id: _a.NEOX_MAINNET_NETWORK_ID,
138
+ name: 'NeoX Mainnet',
139
+ url: _a.RPC_LIST_BY_NETWORK_ID[_a.NEOX_MAINNET_NETWORK_ID][0],
140
+ };
141
+ BSEthereumConstants.NEOX_NETWORKS = [_a.NEOX_TESTNET_NETWORK, _a.NEOX_MAINNET_NETWORK];
142
+ BSEthereumConstants.MAINNET_NETWORK_IDS = [
143
+ '1',
144
+ '10',
145
+ '25',
146
+ '56',
147
+ '137',
148
+ '250',
149
+ '8453',
150
+ '42161',
151
+ '42220',
152
+ '43114',
153
+ '59144',
154
+ _a.NEOX_MAINNET_NETWORK_ID,
155
+ ];
156
+ BSEthereumConstants.TESTNET_NETWORK_IDS = ['1101', '80002', '11155111', _a.NEOX_TESTNET_NETWORK_ID];
157
+ BSEthereumConstants.ALL_NETWORK_IDS = [..._a.MAINNET_NETWORK_IDS, ..._a.TESTNET_NETWORK_IDS];
158
+ BSEthereumConstants.MAINNET_NETWORKS = [
159
+ {
160
+ id: '1',
161
+ name: 'Ethereum Mainnet',
162
+ url: _a.RPC_LIST_BY_NETWORK_ID['1'][0],
163
+ },
164
+ {
165
+ id: '10',
166
+ name: 'Optimism Mainnet',
167
+ url: _a.RPC_LIST_BY_NETWORK_ID['10'][0],
168
+ },
169
+ {
170
+ id: '25',
171
+ name: 'Cronos Mainnet',
172
+ url: _a.RPC_LIST_BY_NETWORK_ID['25'][0],
173
+ },
174
+ {
175
+ id: '56',
176
+ name: 'Binance Smart Chain Mainnet',
177
+ url: _a.RPC_LIST_BY_NETWORK_ID['56'][0],
178
+ },
179
+ {
180
+ id: '137',
181
+ name: 'Polygon Mainnet',
182
+ url: _a.RPC_LIST_BY_NETWORK_ID['137'][0],
183
+ },
184
+ {
185
+ id: '250',
186
+ name: 'Fantom Mainnet',
187
+ url: _a.RPC_LIST_BY_NETWORK_ID['250'][0],
188
+ },
189
+ {
190
+ id: '8453',
191
+ name: 'Base Protocol Mainnet',
192
+ url: _a.RPC_LIST_BY_NETWORK_ID['8453'][0],
193
+ },
194
+ {
195
+ id: '42161',
196
+ name: 'Arbitrum Mainnet',
197
+ url: _a.RPC_LIST_BY_NETWORK_ID['42161'][0],
198
+ },
199
+ {
200
+ id: '42220',
201
+ name: 'Celo Mainnet',
202
+ url: _a.RPC_LIST_BY_NETWORK_ID['42220'][0],
203
+ },
204
+ {
205
+ id: '43114',
206
+ name: 'Avalanche Mainnet',
207
+ url: _a.RPC_LIST_BY_NETWORK_ID['43114'][0],
208
+ },
209
+ {
210
+ id: '59144',
211
+ name: 'Linea Mainnet',
212
+ url: _a.RPC_LIST_BY_NETWORK_ID['59144'][0],
213
+ },
214
+ _a.NEOX_MAINNET_NETWORK,
215
+ ];
216
+ BSEthereumConstants.TESTNET_NETWORKS = [
217
+ {
218
+ id: '1101',
219
+ name: 'Polygon zkEVM Testnet',
220
+ url: _a.RPC_LIST_BY_NETWORK_ID['1101'][0],
221
+ },
222
+ {
223
+ id: '80002',
224
+ name: 'Polygon Testnet Amoy',
225
+ url: _a.RPC_LIST_BY_NETWORK_ID['80002'][0],
226
+ },
227
+ {
228
+ id: '11155111',
229
+ name: 'Sepolia Testnet',
230
+ url: _a.RPC_LIST_BY_NETWORK_ID['11155111'][0],
231
+ },
232
+ _a.NEOX_TESTNET_NETWORK,
233
+ ];
234
+ BSEthereumConstants.ALL_NETWORKS = [..._a.MAINNET_NETWORKS, ..._a.TESTNET_NETWORKS];
235
+ BSEthereumConstants.DEFAULT_NETWORK = _a.MAINNET_NETWORKS[0];
@@ -0,0 +1,16 @@
1
+ import { Network } from '@cityofzion/blockchain-service';
2
+ import { BSEthereumNetworkId } from '../constants/BSEthereumConstants';
3
+ export declare class BSEthereumHelper {
4
+ static getNativeAsset(network: Network<BSEthereumNetworkId>): {
5
+ symbol: string;
6
+ name: string;
7
+ hash: string;
8
+ decimals: number;
9
+ };
10
+ static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
11
+ static getRpcList(network: Network<BSEthereumNetworkId>): string[];
12
+ static isMainnet(network: Network<BSEthereumNetworkId>): boolean;
13
+ static normalizeHash(hash: string): string;
14
+ static wait(duration: number): Promise<void>;
15
+ static retry<T = any>(callback: () => Promise<T>): Promise<T>;
16
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BSEthereumHelper = void 0;
13
+ const BSEthereumConstants_1 = require("../constants/BSEthereumConstants");
14
+ class BSEthereumHelper {
15
+ static getNativeAsset(network) {
16
+ const symbol = this.getNativeSymbol(network);
17
+ return Object.assign(Object.assign({}, BSEthereumConstants_1.BSEthereumConstants.NATIVE_ASSET), { symbol, name: symbol });
18
+ }
19
+ static getNativeSymbol(network) {
20
+ var _a;
21
+ return (_a = BSEthereumConstants_1.BSEthereumConstants.NATIVE_SYMBOL_BY_NETWORK_ID[network.id]) !== null && _a !== void 0 ? _a : 'ETH';
22
+ }
23
+ static getRpcList(network) {
24
+ var _a;
25
+ return (_a = BSEthereumConstants_1.BSEthereumConstants.RPC_LIST_BY_NETWORK_ID[network.id]) !== null && _a !== void 0 ? _a : [];
26
+ }
27
+ static isMainnet(network) {
28
+ return BSEthereumConstants_1.BSEthereumConstants.MAINNET_NETWORK_IDS.includes(network.id);
29
+ }
30
+ static normalizeHash(hash) {
31
+ return hash.startsWith('0x') ? hash.slice(2) : hash;
32
+ }
33
+ static wait(duration) {
34
+ return new Promise(resolve => {
35
+ setTimeout(resolve, duration);
36
+ });
37
+ }
38
+ static retry(callback) {
39
+ // eslint-disable-next-line no-async-promise-executor
40
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
41
+ // Wait up to 5 seconds
42
+ for (let i = 0; i < 50; i++) {
43
+ try {
44
+ const result = yield callback();
45
+ return resolve(result);
46
+ }
47
+ catch (error) {
48
+ if (error.id !== 'TransportLocked') {
49
+ return reject(error);
50
+ }
51
+ }
52
+ yield this.wait(100);
53
+ }
54
+ return reject(new Error('timeout'));
55
+ }));
56
+ }
57
+ }
58
+ exports.BSEthereumHelper = BSEthereumHelper;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  export * from './BSEthereum';
2
- export * from './BSEthereumHelper';
3
- export * from './EthersLedgerServiceEthereum';
4
- export * from './GhostMarketNDSEthereum';
5
- export * from './MoralisBDSEthereum';
6
- export * from './MoralisEDSEthereum';
7
- export * from './RpcBDSEthereum';
8
- export * from './RpcNDSEthereum';
2
+ export * from './helpers/BSEthereumHelper';
3
+ export * from './constants/BSEthereumConstants';
4
+ export * from './services/blockchain-data/BlockscoutBDSEthereum';
5
+ export * from './services/blockchain-data/MoralisBDSEthereum';
6
+ export * from './services/blockchain-data/RpcBDSEthereum';
7
+ export * from './services/exchange-data/BlockscoutEDSEthereum';
8
+ export * from './services/exchange-data/MoralisEDSEthereum';
9
+ export * from './services/explorer/BlockscoutESEthereum';
10
+ export * from './services/ledger/EthersLedgerServiceEthereum';
11
+ export * from './services/nft-data/GhostMarketNDSEthereum';
12
+ export * from './services/nft-data/RpcNDSEthereum';
package/dist/index.js CHANGED
@@ -15,10 +15,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BSEthereum"), exports);
18
- __exportStar(require("./BSEthereumHelper"), exports);
19
- __exportStar(require("./EthersLedgerServiceEthereum"), exports);
20
- __exportStar(require("./GhostMarketNDSEthereum"), exports);
21
- __exportStar(require("./MoralisBDSEthereum"), exports);
22
- __exportStar(require("./MoralisEDSEthereum"), exports);
23
- __exportStar(require("./RpcBDSEthereum"), exports);
24
- __exportStar(require("./RpcNDSEthereum"), exports);
18
+ __exportStar(require("./helpers/BSEthereumHelper"), exports);
19
+ __exportStar(require("./constants/BSEthereumConstants"), exports);
20
+ __exportStar(require("./services/blockchain-data/BlockscoutBDSEthereum"), exports);
21
+ __exportStar(require("./services/blockchain-data/MoralisBDSEthereum"), exports);
22
+ __exportStar(require("./services/blockchain-data/RpcBDSEthereum"), exports);
23
+ __exportStar(require("./services/exchange-data/BlockscoutEDSEthereum"), exports);
24
+ __exportStar(require("./services/exchange-data/MoralisEDSEthereum"), exports);
25
+ __exportStar(require("./services/explorer/BlockscoutESEthereum"), exports);
26
+ __exportStar(require("./services/ledger/EthersLedgerServiceEthereum"), exports);
27
+ __exportStar(require("./services/nft-data/GhostMarketNDSEthereum"), exports);
28
+ __exportStar(require("./services/nft-data/RpcNDSEthereum"), exports);
@@ -1,7 +1,7 @@
1
1
  import { BalanceResponse, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
2
2
  import { RpcBDSEthereum } from './RpcBDSEthereum';
3
- import { BSEthereumNetworkId } from './BSEthereumHelper';
4
- export declare class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum {
3
+ import { BSEthereumNetworkId } from '../../constants/BSEthereumConstants';
4
+ export declare class BlockscoutBDSEthereum extends RpcBDSEthereum {
5
5
  static BASE_URL_BY_CHAIN_ID: Partial<Record<BSEthereumNetworkId, string>>;
6
6
  static isSupported(network: Network<BSEthereumNetworkId>): boolean;
7
7
  static getClient(network: Network<BSEthereumNetworkId>): import("axios").AxiosInstance;