@cityofzion/bs-ethereum 2.1.0 → 2.1.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.
@@ -150,7 +150,7 @@ class BSEthereum {
150
150
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
151
151
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
152
152
  let transactionParams;
153
- const isNative = this.feeToken.hash === param.intent.tokenHash;
153
+ const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
154
154
  if (isNative) {
155
155
  transactionParams = {
156
156
  to: param.intent.receiverAddress,
@@ -186,7 +186,7 @@ class BSEthereum {
186
186
  }
187
187
  const gasPrice = yield provider.getGasPrice();
188
188
  let estimated;
189
- const isNative = this.feeToken.hash === param.intent.tokenHash;
189
+ const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
190
190
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
191
191
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
192
192
  if (!isNative) {
@@ -24,4 +24,5 @@ export declare class BSEthereumHelper {
24
24
  static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
25
25
  static getRpcList(network: Network<BSEthereumNetworkId>): string[];
26
26
  static isMainnet(network: Network<BSEthereumNetworkId>): boolean;
27
+ static normalizeHash(hash: string): string;
27
28
  }
@@ -9,7 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.BSEthereumHelper = void 0;
10
10
  class BSEthereumHelper {
11
11
  static getNativeAsset(network) {
12
- return Object.assign(Object.assign({}, __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_NATIVE_ASSET)), { symbol: this.getNativeSymbol(network) });
12
+ const symbol = this.getNativeSymbol(network);
13
+ return Object.assign(Object.assign({}, __classPrivateFieldGet(this, _a, "f", _BSEthereumHelper_NATIVE_ASSET)), { symbol, name: symbol });
13
14
  }
14
15
  static getNativeSymbol(network) {
15
16
  var _b;
@@ -22,6 +23,9 @@ class BSEthereumHelper {
22
23
  static isMainnet(network) {
23
24
  return this.MAINNET_NETWORK_IDS.includes(network.id);
24
25
  }
26
+ static normalizeHash(hash) {
27
+ return hash.startsWith('0x') ? hash.slice(2) : hash;
28
+ }
25
29
  }
26
30
  exports.BSEthereumHelper = BSEthereumHelper;
27
31
  _a = BSEthereumHelper;
@@ -46,7 +46,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
46
46
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
47
47
  const balances = [
48
48
  {
49
- amount: nativeBalance,
49
+ amount: ethers_1.ethers.utils.formatUnits(nativeBalance, nativeToken.decimals),
50
50
  token: nativeToken,
51
51
  },
52
52
  ];
@@ -55,7 +55,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
55
55
  if (balance.possible_spam)
56
56
  return;
57
57
  balances.push({
58
- amount: balance.balance,
58
+ amount: ethers_1.ethers.utils.formatUnits(balance.balance, balance.decimals),
59
59
  token: {
60
60
  decimals: balance.decimals,
61
61
  hash: balance.token_address,
@@ -76,7 +76,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
76
76
  return _super.getTokenInfo.call(this, hash);
77
77
  }
78
78
  const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
79
- if (nativeAsset.hash === hash)
79
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(nativeAsset.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(hash))
80
80
  return nativeAsset;
81
81
  if (this._tokenCache.has(hash)) {
82
82
  return this._tokenCache.get(hash);
@@ -112,7 +112,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
112
112
  if (data.value && Number(data.value) > 0) {
113
113
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
114
114
  transfers.push({
115
- amount: data.value,
115
+ amount: ethers_1.ethers.utils.formatUnits(data.value, nativeToken.decimals),
116
116
  from: data.from_address,
117
117
  to: data.to_address,
118
118
  type: 'token',
@@ -62,8 +62,10 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
62
62
  tokens: tokensBody,
63
63
  });
64
64
  return data.map(item => {
65
+ var _a;
65
66
  let token;
66
- if (item.tokenAddress === (wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash)) {
67
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(item.tokenAddress) ===
68
+ BSEthereumHelper_1.BSEthereumHelper.normalizeHash((_a = wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash) !== null && _a !== void 0 ? _a : '')) {
67
69
  token = nativeToken;
68
70
  }
69
71
  else {
@@ -89,7 +91,7 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
89
91
  throw new Error('Exchange is not supported on this network');
90
92
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
91
93
  let token;
92
- if (params.token.hash === nativeToken.hash) {
94
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(params.token.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(nativeToken.hash)) {
93
95
  token = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
94
96
  }
95
97
  else {
@@ -60,7 +60,7 @@ class RpcBDSEthereum {
60
60
  getTokenInfo(hash) {
61
61
  return __awaiter(this, void 0, void 0, function* () {
62
62
  const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
63
- if (nativeAsset.hash === hash)
63
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(nativeAsset.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(hash))
64
64
  return nativeAsset;
65
65
  if (this._tokenCache.has(hash)) {
66
66
  return this._tokenCache.get(hash);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",