@cityofzion/bs-ethereum 2.7.9 → 2.7.11

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.
@@ -4,6 +4,7 @@ export declare class BSEthereumConstants {
4
4
  static DEFAULT_DECIMALS: number;
5
5
  static DEFAULT_GAS_LIMIT: number;
6
6
  static NATIVE_SYMBOL_BY_NETWORK_ID: Record<BSEthereumNetworkId, string>;
7
+ static NATIVE_WRAPPED_HASH_BY_NETWORK_ID: Partial<Record<BSEthereumNetworkId, string>>;
7
8
  static RPC_LIST_BY_NETWORK_ID: Record<BSEthereumNetworkId, string[]>;
8
9
  static DEFAULT_BIP44_DERIVATION_PATH: string;
9
10
  static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId;
@@ -26,6 +26,9 @@ BSEthereumConstants.NATIVE_SYMBOL_BY_NETWORK_ID = {
26
26
  '47763': 'GAS',
27
27
  '12227332': 'GAS',
28
28
  };
29
+ BSEthereumConstants.NATIVE_WRAPPED_HASH_BY_NETWORK_ID = {
30
+ '1': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
31
+ };
29
32
  BSEthereumConstants.RPC_LIST_BY_NETWORK_ID = {
30
33
  '1': [
31
34
  'https://eth.llamarpc.com',
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BSEthereumHelper = void 0;
13
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
13
14
  const BSEthereumConstants_1 = require("../constants/BSEthereumConstants");
14
15
  class BSEthereumHelper {
15
16
  static getNativeAsset(network) {
@@ -28,7 +29,7 @@ class BSEthereumHelper {
28
29
  return BSEthereumConstants_1.BSEthereumConstants.MAINNET_NETWORK_IDS.includes(network.id);
29
30
  }
30
31
  static normalizeHash(hash) {
31
- return hash.startsWith('0x') ? hash.slice(2) : hash;
32
+ return (0, blockchain_service_1.normalizeHash)(hash);
32
33
  }
33
34
  static wait(duration) {
34
35
  return new Promise(resolve => {
@@ -280,7 +280,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
280
280
  }
281
281
  }
282
282
  exports.MoralisBDSEthereum = MoralisBDSEthereum;
283
- MoralisBDSEthereum.BASE_URL = 'https://nxlrja2d1a.execute-api.us-east-1.amazonaws.com/production';
283
+ MoralisBDSEthereum.BASE_URL = 'https://dora.coz.io/api/v2/meta';
284
284
  MoralisBDSEthereum.SUPPORTED_CHAINS = [
285
285
  '1',
286
286
  '11155111',
@@ -23,6 +23,7 @@ var _MoralisEDSEthereum_instances, _MoralisEDSEthereum_network, _MoralisEDSEther
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.MoralisEDSEthereum = void 0;
25
25
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
26
+ const BSEthereumConstants_1 = require("../../constants/BSEthereumConstants");
26
27
  const BSEthereumHelper_1 = require("../../helpers/BSEthereumHelper");
27
28
  const MoralisBDSEthereum_1 = require("../blockchain-data/MoralisBDSEthereum");
28
29
  class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
@@ -47,17 +48,25 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
47
48
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
48
49
  let wrappedNativeToken;
49
50
  if (params.tokens.some(token => token.symbol === nativeToken.symbol)) {
50
- wrappedNativeToken = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
51
+ try {
52
+ wrappedNativeToken = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
53
+ }
54
+ catch (_a) {
55
+ /* empty */
56
+ }
51
57
  }
52
- const tokensBody = params.tokens.map(token => {
58
+ const tokensBody = [];
59
+ params.tokens.map(token => {
53
60
  if (token.symbol !== nativeToken.symbol) {
54
- return {
61
+ tokensBody.push({
55
62
  token_address: token.hash,
56
- };
63
+ });
64
+ }
65
+ if (wrappedNativeToken) {
66
+ tokensBody.push({
67
+ token_address: wrappedNativeToken.hash,
68
+ });
57
69
  }
58
- return {
59
- token_address: wrappedNativeToken.hash,
60
- };
61
70
  });
62
71
  const splitTokensBody = [];
63
72
  for (let i = 0; i < tokensBody.length; i += __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")) {
@@ -69,10 +78,10 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
69
78
  tokens: body,
70
79
  });
71
80
  data.forEach(item => {
72
- var _a;
73
81
  let token;
74
- if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(item.tokenAddress) ===
75
- BSEthereumHelper_1.BSEthereumHelper.normalizeHash((_a = wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash) !== null && _a !== void 0 ? _a : '')) {
82
+ if (wrappedNativeToken &&
83
+ BSEthereumHelper_1.BSEthereumHelper.normalizeHash(item.tokenAddress) ===
84
+ BSEthereumHelper_1.BSEthereumHelper.normalizeHash(wrappedNativeToken.hash)) {
76
85
  token = nativeToken;
77
86
  }
78
87
  else {
@@ -135,10 +144,15 @@ exports.MoralisEDSEthereum = MoralisEDSEthereum;
135
144
  _MoralisEDSEthereum_network = new WeakMap(), _MoralisEDSEthereum_blockchainDataService = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByHour = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByDay = new WeakMap(), _MoralisEDSEthereum_maxTokenPricesPerCall = new WeakMap(), _MoralisEDSEthereum_instances = new WeakSet(), _MoralisEDSEthereum_getWrappedNativeToken = function _MoralisEDSEthereum_getWrappedNativeToken() {
136
145
  return __awaiter(this, void 0, void 0, function* () {
137
146
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
147
+ const wrappedSymbol = `W${nativeToken.symbol}`;
148
+ const localWrappedHash = BSEthereumConstants_1.BSEthereumConstants.NATIVE_WRAPPED_HASH_BY_NETWORK_ID[__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f").id];
149
+ if (localWrappedHash) {
150
+ return Object.assign(Object.assign({}, nativeToken), { symbol: wrappedSymbol, hash: localWrappedHash });
151
+ }
138
152
  const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
139
153
  const { data } = yield client.get('/erc20/metadata/symbols', {
140
154
  params: {
141
- symbols: [`W${nativeToken.symbol}`],
155
+ symbols: [wrappedSymbol],
142
156
  },
143
157
  });
144
158
  const wrapperToken = data.find(token => token.verified_contract && !token.possible_spam);
@@ -72,7 +72,7 @@ class EthersLedgerSigner extends ethers_1.Signer {
72
72
  }
73
73
  getAddress() {
74
74
  return __awaiter(this, void 0, void 0, function* () {
75
- const { address } = yield __classPrivateFieldGet(this, _EthersLedgerSigner_ledgerApp, "f").getAddress(__classPrivateFieldGet(this, _EthersLedgerSigner_bip44Path, "f"));
75
+ const { address } = yield BSEthereumHelper_1.BSEthereumHelper.retry(() => __classPrivateFieldGet(this, _EthersLedgerSigner_ledgerApp, "f").getAddress(__classPrivateFieldGet(this, _EthersLedgerSigner_bip44Path, "f")));
76
76
  return address;
77
77
  });
78
78
  }
@@ -98,32 +98,25 @@ class EthersLedgerSigner extends ethers_1.Signer {
98
98
  });
99
99
  }
100
100
  signTransaction(transaction) {
101
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
101
+ var _a, _b, _c;
102
102
  return __awaiter(this, void 0, void 0, function* () {
103
103
  try {
104
104
  const tx = yield ethers_1.ethers.utils.resolveProperties(transaction);
105
- const unsignedTransaction = {
106
- chainId: (_a = tx.chainId) !== null && _a !== void 0 ? _a : undefined,
107
- data: (_b = tx.data) !== null && _b !== void 0 ? _b : undefined,
108
- gasLimit: (_c = tx.gasLimit) !== null && _c !== void 0 ? _c : undefined,
109
- gasPrice: (_d = tx.gasPrice) !== null && _d !== void 0 ? _d : undefined,
110
- nonce: tx.nonce ? ethers_1.ethers.BigNumber.from(tx.nonce).toNumber() : undefined,
111
- to: (_e = tx.to) !== null && _e !== void 0 ? _e : undefined,
112
- value: (_f = tx.value) !== null && _f !== void 0 ? _f : undefined,
113
- };
114
- const serializedUnsignedTransaction = ethers_1.ethers.utils.serializeTransaction(unsignedTransaction).substring(2);
105
+ const serializedUnsignedTransaction = ethers_1.ethers.utils
106
+ .serializeTransaction(tx)
107
+ .substring(2);
115
108
  const resolution = yield hw_app_eth_1.ledgerService.resolveTransaction(serializedUnsignedTransaction, {}, {});
116
- (_g = __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")) === null || _g === void 0 ? void 0 : _g.emit('getSignatureStart');
109
+ (_a = __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")) === null || _a === void 0 ? void 0 : _a.emit('getSignatureStart');
117
110
  const signature = yield BSEthereumHelper_1.BSEthereumHelper.retry(() => __classPrivateFieldGet(this, _EthersLedgerSigner_ledgerApp, "f").signTransaction(__classPrivateFieldGet(this, _EthersLedgerSigner_bip44Path, "f"), serializedUnsignedTransaction, resolution));
118
- (_h = __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")) === null || _h === void 0 ? void 0 : _h.emit('getSignatureEnd');
119
- return ethers_1.ethers.utils.serializeTransaction(unsignedTransaction, {
111
+ (_b = __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")) === null || _b === void 0 ? void 0 : _b.emit('getSignatureEnd');
112
+ return ethers_1.ethers.utils.serializeTransaction(tx, {
120
113
  v: ethers_1.ethers.BigNumber.from('0x' + signature.v).toNumber(),
121
114
  r: '0x' + signature.r,
122
115
  s: '0x' + signature.s,
123
116
  });
124
117
  }
125
118
  catch (error) {
126
- (_j = __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")) === null || _j === void 0 ? void 0 : _j.emit('getSignatureEnd');
119
+ (_c = __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")) === null || _c === void 0 ? void 0 : _c.emit('getSignatureEnd');
127
120
  throw error;
128
121
  }
129
122
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.7.9",
3
+ "version": "2.7.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -20,7 +20,7 @@
20
20
  "@ledgerhq/hw-app-eth": "~6.35.7",
21
21
  "@ethersproject/abstract-signer": "~5.7.0",
22
22
  "@ethersproject/properties": "~5.7.0",
23
- "@cityofzion/blockchain-service": "1.13.0"
23
+ "@cityofzion/blockchain-service": "1.13.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@ledgerhq/hw-transport-node-hid": "~6.28.5",