@cityofzion/bs-ethereum 3.1.9 → 3.1.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.
@@ -1,8 +1,9 @@
1
- import { type TBSAccount, type TTransferIntent, type TBSToken, type TTransferParams, type TGetLedgerTransport, type ITokenService, type TBSNetwork, type IBlockchainDataService, type IExchangeDataService, type INftDataService, type IExplorerService, type TPingNetworkResponse, type IWalletConnectService, type IFullTransactionsDataService, type TTransactionDefault, type TBSNetworkId } from '@cityofzion/blockchain-service';
1
+ import { type TBSAccount, type TTransferIntent, type TBSToken, type TTransferParams, type TGetLedgerTransport, type ITokenService, type TBSNetwork, type IBlockchainDataService, type IExchangeDataService, type INftDataService, type IExplorerService, type TPingNetworkResponse, type IFullTransactionsDataService, type TTransactionDefault, type TBSNetworkId, BSBigUnitAmount } from '@cityofzion/blockchain-service';
2
2
  import { ethers } from 'ethers';
3
3
  import { EthersLedgerServiceEthereum } from './services/ledger/EthersLedgerServiceEthereum';
4
4
  import type { IBSEthereum, TBSEthereumName, TBSEthereumNetworkId } from './types';
5
5
  import { TypedDataSigner } from '@ethersproject/abstract-signer';
6
+ import { WalletConnectServiceEthereum } from './services/wallet-connect/WalletConnectServiceEthereum';
6
7
  export declare class BSEthereum<N extends string = TBSEthereumName, A extends TBSNetworkId = TBSEthereumNetworkId> implements IBSEthereum<N, A> {
7
8
  #private;
8
9
  readonly name: N;
@@ -22,13 +23,13 @@ export declare class BSEthereum<N extends string = TBSEthereumName, A extends TB
22
23
  nftDataService: INftDataService;
23
24
  explorerService: IExplorerService;
24
25
  tokenService: ITokenService;
25
- walletConnectService: IWalletConnectService<N>;
26
+ walletConnectService: WalletConnectServiceEthereum<N, A>;
26
27
  fullTransactionsDataService: IFullTransactionsDataService<N>;
27
28
  constructor(name: N, network?: TBSNetwork<A>, getLedgerTransport?: TGetLedgerTransport<N>);
28
29
  _generateSigner(account: TBSAccount<N>): Promise<ethers.Signer & TypedDataSigner>;
29
30
  _buildTransferParams(intent: TTransferIntent): Promise<{
30
31
  transactionParams: ethers.utils.Deferrable<ethers.providers.TransactionRequest>;
31
- gasPrice: ethers.BigNumber;
32
+ gasPriceBn: BSBigUnitAmount;
32
33
  }>;
33
34
  setNetwork(network: TBSNetwork<A>): void;
34
35
  pingNetwork(url: string): Promise<TPingNetworkResponse>;
@@ -47,13 +47,12 @@ const blockchain_service_1 = require("@cityofzion/blockchain-service");
47
47
  const ethers_1 = require("ethers");
48
48
  const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
49
49
  const ethersBytes = __importStar(require("@ethersproject/bytes"));
50
- const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
51
50
  const BSEthereumConstants_1 = require("./constants/BSEthereumConstants");
52
51
  const EthersLedgerServiceEthereum_1 = require("./services/ledger/EthersLedgerServiceEthereum");
53
52
  const BSEthereumHelper_1 = require("./helpers/BSEthereumHelper");
54
53
  const MoralisBDSEthereum_1 = require("./services/blockchain-data/MoralisBDSEthereum");
55
54
  const MoralisEDSEthereum_1 = require("./services/exchange-data/MoralisEDSEthereum");
56
- const GhostMarketNDSEthereum_1 = require("./services/nft-data/GhostMarketNDSEthereum");
55
+ const MoralisNDSEthereum_1 = require("./services/nft-data/MoralisNDSEthereum");
57
56
  const BlockscoutESEthereum_1 = require("./services/explorer/BlockscoutESEthereum");
58
57
  const TokenServiceEthereum_1 = require("./services/token/TokenServiceEthereum");
59
58
  const WalletConnectServiceEthereum_1 = require("./services/wallet-connect/WalletConnectServiceEthereum");
@@ -91,8 +90,9 @@ class BSEthereum {
91
90
  }
92
91
  async _buildTransferParams(intent) {
93
92
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
94
- const amount = ethersBigNumber.parseFixed(intent.amount, intent.token.decimals);
93
+ const amount = new blockchain_service_1.BSBigHumanAmount(intent.amount, intent.token.decimals).toUnit().toString();
95
94
  const gasPrice = await provider.getGasPrice();
95
+ const gasPriceBn = new blockchain_service_1.BSBigUnitAmount(gasPrice.toString(), BSEthereumConstants_1.BSEthereumConstants.DEFAULT_DECIMALS);
96
96
  let transactionParams = {
97
97
  type: 2,
98
98
  };
@@ -113,7 +113,7 @@ class BSEthereum {
113
113
  }
114
114
  return {
115
115
  transactionParams,
116
- gasPrice,
116
+ gasPriceBn,
117
117
  };
118
118
  }
119
119
  setNetwork(network) {
@@ -125,7 +125,7 @@ class BSEthereum {
125
125
  __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_setTokens).call(this, network);
126
126
  this.network = network;
127
127
  this.networkUrls = networkUrls;
128
- this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(this);
128
+ this.nftDataService = new MoralisNDSEthereum_1.MoralisNDSEthereum(this);
129
129
  this.explorerService = new BlockscoutESEthereum_1.BlockscoutESEthereum(this);
130
130
  this.exchangeDataService = new MoralisEDSEthereum_1.MoralisEDSEthereum(this);
131
131
  this.blockchainDataService = new MoralisBDSEthereum_1.MoralisBDSEthereum(this);
@@ -146,7 +146,7 @@ class BSEthereum {
146
146
  return {
147
147
  latency,
148
148
  url,
149
- height: ethers_1.ethers.BigNumber.from(response.data.result).toNumber(),
149
+ height: blockchain_service_1.BSBigNumber.ensureNumber(response.data.result),
150
150
  };
151
151
  }
152
152
  validateAddress(address) {
@@ -220,21 +220,22 @@ class BSEthereum {
220
220
  let nonce = await signer.getTransactionCount('pending');
221
221
  for (const intent of intents) {
222
222
  try {
223
- const { transactionParams, gasPrice } = await this._buildTransferParams(intent);
224
- let gasLimit;
223
+ const { transactionParams, gasPriceBn } = await this._buildTransferParams(intent);
225
224
  transactionParams.nonce = nonce++;
225
+ let gasLimitBn;
226
226
  try {
227
- gasLimit = await signer.estimateGas(transactionParams);
227
+ const estimatedGas = await signer.estimateGas(transactionParams);
228
+ gasLimitBn = new blockchain_service_1.BSBigUnitAmount(estimatedGas.toString(), BSEthereumConstants_1.BSEthereumConstants.DEFAULT_DECIMALS);
228
229
  }
229
230
  catch {
230
- gasLimit = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT;
231
+ gasLimitBn = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT_BN;
231
232
  }
232
- const fee = ethers_1.ethers.utils.formatEther(gasPrice.mul(gasLimit));
233
+ const fee = gasPriceBn.multipliedBy(gasLimitBn).toHuman().toFormatted();
233
234
  const transaction = await signer.sendTransaction({
234
235
  ...transactionParams,
235
- gasLimit,
236
- maxPriorityFeePerGas: gasPrice,
237
- maxFeePerGas: gasPrice,
236
+ gasLimit: gasLimitBn.toString(),
237
+ maxPriorityFeePerGas: gasPriceBn.toString(),
238
+ maxFeePerGas: gasPriceBn.toString(),
238
239
  });
239
240
  const txId = transaction.hash;
240
241
  if (txId) {
@@ -277,14 +278,14 @@ class BSEthereum {
277
278
  }
278
279
  async calculateTransferFee(params) {
279
280
  const signer = await this._generateSigner(params.senderAccount);
280
- let fee = ethers_1.ethers.utils.parseEther('0');
281
+ let feeBn = new blockchain_service_1.BSBigUnitAmount(0, BSEthereumConstants_1.BSEthereumConstants.DEFAULT_DECIMALS);
281
282
  for (const intent of params.intents) {
282
- const { gasPrice, transactionParams } = await this._buildTransferParams(intent);
283
- const estimated = await signer.estimateGas(transactionParams);
284
- const intentFee = gasPrice.mul(estimated);
285
- fee = fee.add(intentFee);
283
+ const { gasPriceBn, transactionParams } = await this._buildTransferParams(intent);
284
+ const estimatedGas = await signer.estimateGas(transactionParams);
285
+ const intentFeeBn = gasPriceBn.multipliedBy(estimatedGas.toString());
286
+ feeBn = feeBn.plus(intentFeeBn);
286
287
  }
287
- return ethers_1.ethers.utils.formatEther(fee);
288
+ return feeBn.toHuman().toFormatted();
288
289
  }
289
290
  async resolveNameServiceDomain(domainName) {
290
291
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
@@ -1,11 +1,12 @@
1
- import type { TBSNetwork } from '@cityofzion/blockchain-service';
1
+ import { BSBigUnitAmount, type TBSNetwork } from '@cityofzion/blockchain-service';
2
2
  import type { TBSEthereumNetworkId, TBSEthereumName } from '../types';
3
3
  export declare class BSEthereumConstants {
4
4
  static readonly DEFAULT_DECIMALS = 18;
5
- static readonly DEFAULT_GAS_LIMIT = 21000;
5
+ static readonly DEFAULT_GAS_LIMIT_BN: BSBigUnitAmount;
6
6
  static readonly DEFAULT_BIP_DERIVATION_PATH = "m/44'/60'/0'/0/?";
7
7
  static readonly NATIVE_SYMBOL_BY_NETWORK_ID: Record<TBSEthereumNetworkId, string>;
8
8
  static readonly NATIVE_WRAPPED_HASH_BY_NETWORK_ID: Partial<Record<TBSEthereumNetworkId, string>>;
9
9
  static readonly RPC_LIST_BY_NETWORK_ID: Record<TBSEthereumNetworkId, string[]>;
10
10
  static readonly NETWORKS_BY_EVM: Record<TBSEthereumName, TBSNetwork<TBSEthereumNetworkId>[]>;
11
+ static readonly MORALIS_SUPPORTED_NETWORKS_IDS: TBSEthereumNetworkId[];
11
12
  }
@@ -2,12 +2,13 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.BSEthereumConstants = void 0;
5
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
5
6
  class BSEthereumConstants {
6
7
  }
7
8
  exports.BSEthereumConstants = BSEthereumConstants;
8
9
  _a = BSEthereumConstants;
9
10
  BSEthereumConstants.DEFAULT_DECIMALS = 18;
10
- BSEthereumConstants.DEFAULT_GAS_LIMIT = 0x5208;
11
+ BSEthereumConstants.DEFAULT_GAS_LIMIT_BN = new blockchain_service_1.BSBigUnitAmount(0x5208, _a.DEFAULT_DECIMALS);
11
12
  BSEthereumConstants.DEFAULT_BIP_DERIVATION_PATH = "m/44'/60'/0'/0/?";
12
13
  BSEthereumConstants.NATIVE_SYMBOL_BY_NETWORK_ID = {
13
14
  '1': 'ETH',
@@ -218,3 +219,11 @@ BSEthereumConstants.NETWORKS_BY_EVM = {
218
219
  },
219
220
  ],
220
221
  };
222
+ // prettier-ignore
223
+ BSEthereumConstants.MORALIS_SUPPORTED_NETWORKS_IDS = [
224
+ '1', '11155111', '17000', '137', '80002', '56', '97', '42161', '421614',
225
+ '8453', '84532', '10', '11155420', '59144', '59141', '43114', '250',
226
+ '4002', '25', '11297108109', '2020', '100', '10200', '88888', '88882',
227
+ '369', '1284', '1285', '1287', '81457', '168587773', '324', '300',
228
+ '5000', '5003', '1101', '2442', '7000', '7001'
229
+ ];
package/dist/index.d.ts CHANGED
@@ -6,9 +6,8 @@ export * from './services/blockchain-data/RpcBDSEthereum';
6
6
  export * from './services/exchange-data/MoralisEDSEthereum';
7
7
  export * from './services/explorer/BlockscoutESEthereum';
8
8
  export * from './services/ledger/EthersLedgerServiceEthereum';
9
- export * from './services/nft-data/GhostMarketNDSEthereum';
9
+ export * from './services/nft-data/MoralisNDSEthereum';
10
10
  export * from './services/token/TokenServiceEthereum';
11
11
  export * from './services/wallet-connect/WalletConnectServiceEthereum';
12
12
  export * from './assets/abis/ERC20';
13
- export * from './assets/abis/ERC721';
14
13
  export * from './types';
package/dist/index.js CHANGED
@@ -22,9 +22,8 @@ __exportStar(require("./services/blockchain-data/RpcBDSEthereum"), exports);
22
22
  __exportStar(require("./services/exchange-data/MoralisEDSEthereum"), exports);
23
23
  __exportStar(require("./services/explorer/BlockscoutESEthereum"), exports);
24
24
  __exportStar(require("./services/ledger/EthersLedgerServiceEthereum"), exports);
25
- __exportStar(require("./services/nft-data/GhostMarketNDSEthereum"), exports);
25
+ __exportStar(require("./services/nft-data/MoralisNDSEthereum"), exports);
26
26
  __exportStar(require("./services/token/TokenServiceEthereum"), exports);
27
27
  __exportStar(require("./services/wallet-connect/WalletConnectServiceEthereum"), exports);
28
28
  __exportStar(require("./assets/abis/ERC20"), exports);
29
- __exportStar(require("./assets/abis/ERC721"), exports);
30
29
  __exportStar(require("./types"), exports);
@@ -5,7 +5,6 @@ import { RpcBDSEthereum } from './RpcBDSEthereum';
5
5
  export declare class MoralisBDSEthereum<N extends string, A extends TBSNetworkId> extends RpcBDSEthereum<N, A> {
6
6
  #private;
7
7
  static readonly BASE_URL: string;
8
- static readonly MORALIS_SUPPORTED_NETWORKS_IDS: TBSEthereumNetworkId[];
9
8
  static getClient(network: TBSNetwork<TBSEthereumNetworkId>): axios.AxiosInstance;
10
9
  static isSupported(network: TBSNetwork<TBSEthereumNetworkId>): boolean;
11
10
  constructor(service: IBSEthereum<N, A>);
@@ -21,6 +21,7 @@ const axios_1 = __importDefault(require("axios"));
21
21
  const BSEthereumHelper_1 = require("../../helpers/BSEthereumHelper");
22
22
  const ERC20_1 = require("../../assets/abis/ERC20");
23
23
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
24
+ const BSEthereumConstants_1 = require("../../constants/BSEthereumConstants");
24
25
  class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
25
26
  static getClient(network) {
26
27
  return axios_1.default.create({
@@ -31,7 +32,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
31
32
  });
32
33
  }
33
34
  static isSupported(network) {
34
- return _a.MORALIS_SUPPORTED_NETWORKS_IDS.includes(network.id);
35
+ return BSEthereumConstants_1.BSEthereumConstants.MORALIS_SUPPORTED_NETWORKS_IDS.includes(network.id);
35
36
  }
36
37
  constructor(service) {
37
38
  super(service);
@@ -46,9 +47,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
46
47
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
47
48
  const balances = [
48
49
  {
49
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(nativeBalance, nativeToken.decimals), {
50
- decimals: nativeToken.decimals,
51
- }),
50
+ amount: new blockchain_service_1.BSBigUnitAmount(nativeBalance, nativeToken.decimals).toHuman().toFormatted(),
52
51
  token: nativeToken,
53
52
  },
54
53
  ];
@@ -57,9 +56,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
57
56
  if (balance.possible_spam || !balance.decimals || !balance.token_address || !balance.symbol)
58
57
  return;
59
58
  balances.push({
60
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(balance.balance, balance.decimals), {
61
- decimals: balance.decimals,
62
- }),
59
+ amount: new blockchain_service_1.BSBigUnitAmount(balance.balance, balance.decimals).toHuman().toFormatted(),
63
60
  token: this._service.tokenService.normalizeToken({
64
61
  decimals: balance.decimals,
65
62
  hash: balance.token_address,
@@ -107,9 +104,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
107
104
  const toUrl = this._service.explorerService.buildAddressUrl(data.to_address);
108
105
  events.push({
109
106
  eventType: 'token',
110
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(data.value, nativeToken.decimals), {
111
- decimals: nativeToken.decimals,
112
- }),
107
+ amount: new blockchain_service_1.BSBigUnitAmount(data.value, nativeToken.decimals).toHuman().toFormatted(),
113
108
  methodName: 'transfer',
114
109
  from: data.from_address,
115
110
  fromUrl,
@@ -137,9 +132,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
137
132
  const token = await this.getTokenInfo(contractHash);
138
133
  events.push({
139
134
  eventType: 'token',
140
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(amount, token.decimals), {
141
- decimals: token.decimals,
142
- }),
135
+ amount: new blockchain_service_1.BSBigUnitAmount(amount, token.decimals).toHuman().toFormatted(),
143
136
  methodName: 'transfer',
144
137
  from,
145
138
  fromUrl,
@@ -173,9 +166,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
173
166
  txIdUrl: this._service.explorerService.buildTransactionUrl(hash),
174
167
  block: Number(data.block_number),
175
168
  date: new Date(data.block_timestamp).toJSON(),
176
- networkFeeAmount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromNumber(data.transaction_fee), {
177
- decimals: this._service.feeToken.decimals,
178
- }),
169
+ networkFeeAmount: new blockchain_service_1.BSBigHumanAmount(data.transaction_fee, this._service.feeToken.decimals).toFormatted(),
179
170
  view: 'default',
180
171
  events,
181
172
  };
@@ -199,9 +190,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
199
190
  const toUrl = this._service.explorerService.buildAddressUrl(transfer.to_address);
200
191
  events.push({
201
192
  eventType: 'token',
202
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(transfer.value, nativeAsset.decimals), {
203
- decimals: nativeAsset.decimals,
204
- }),
193
+ amount: new blockchain_service_1.BSBigUnitAmount(transfer.value, nativeAsset.decimals).toHuman().toFormatted(),
205
194
  methodName: 'transfer',
206
195
  from: transfer.from_address,
207
196
  fromUrl,
@@ -225,9 +214,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
225
214
  });
226
215
  events.push({
227
216
  eventType: 'token',
228
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(transfer.value, tokenDecimals), {
229
- decimals: tokenDecimals,
230
- }),
217
+ amount: new blockchain_service_1.BSBigUnitAmount(transfer.value, tokenDecimals).toHuman().toFormatted(),
231
218
  methodName: 'transfer',
232
219
  from: transfer.from_address,
233
220
  fromUrl,
@@ -262,9 +249,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
262
249
  txIdUrl: this._service.explorerService.buildTransactionUrl(item.hash),
263
250
  block: Number(item.block_number),
264
251
  date: new Date(item.block_timestamp).toJSON(),
265
- networkFeeAmount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromNumber(item.transaction_fee), {
266
- decimals: this._service.feeToken.decimals,
267
- }),
252
+ networkFeeAmount: new blockchain_service_1.BSBigHumanAmount(item.transaction_fee, this._service.feeToken.decimals).toFormatted(),
268
253
  view: 'default',
269
254
  events,
270
255
  });
@@ -314,11 +299,3 @@ _a = MoralisBDSEthereum, _MoralisBDSEthereum_apiInstance = new WeakMap(), _Moral
314
299
  return __classPrivateFieldGet(this, _MoralisBDSEthereum_apiInstance, "f");
315
300
  };
316
301
  MoralisBDSEthereum.BASE_URL = `${blockchain_service_1.BSCommonConstants.COZ_API_URL}/api/v2/meta`;
317
- // prettier-ignore
318
- MoralisBDSEthereum.MORALIS_SUPPORTED_NETWORKS_IDS = [
319
- '1', '11155111', '17000', '137', '80002', '56', '97', '42161', '421614',
320
- '8453', '84532', '10', '11155420', '59144', '59141', '43114', '250',
321
- '4002', '25', '11297108109', '2020', '100', '10200', '88888', '88882',
322
- '369', '1284', '1285', '1287', '81457', '168587773', '324', '300',
323
- '5000', '5003', '1101', '2442', '7000', '7001'
324
- ];
@@ -45,16 +45,12 @@ class RpcBDSEthereum {
45
45
  txIdUrl: this._service.explorerService.buildTransactionUrl(hash),
46
46
  block: receipt.blockNumber,
47
47
  date: new Date(timestamp).toJSON(),
48
- networkFeeAmount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(fee.toString(), this._service.feeToken.decimals), {
49
- decimals: this._service.feeToken.decimals,
50
- }),
48
+ networkFeeAmount: new blockchain_service_1.BSBigUnitAmount(fee.toString(), token.decimals).toHuman().toFormatted(),
51
49
  view: 'default',
52
50
  events: [
53
51
  {
54
52
  eventType: 'token',
55
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(transaction.value.toString(), token.decimals), {
56
- decimals: token.decimals,
57
- }),
53
+ amount: new blockchain_service_1.BSBigUnitAmount(transaction.value.toString(), token.decimals).toHuman().toFormatted(),
58
54
  methodName: 'transfer',
59
55
  from: transaction.from,
60
56
  fromUrl,
@@ -96,9 +92,7 @@ class RpcBDSEthereum {
96
92
  const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
97
93
  return [
98
94
  {
99
- amount: blockchain_service_1.BSBigNumberHelper.format(blockchain_service_1.BSBigNumberHelper.fromDecimals(balance.toString(), token.decimals), {
100
- decimals: token.decimals,
101
- }),
95
+ amount: new blockchain_service_1.BSBigUnitAmount(balance.toString(), token.decimals).toHuman().toFormatted(),
102
96
  token,
103
97
  },
104
98
  ];
@@ -49,7 +49,7 @@ class MoralisFullTransactionsDataServiceEthereum {
49
49
  block: item.block,
50
50
  date: item.date,
51
51
  networkFeeAmount: networkFeeAmount
52
- ? blockchain_service_1.BSBigNumberHelper.format(networkFeeAmount, { decimals: nativeToken.decimals })
52
+ ? new blockchain_service_1.BSBigHumanAmount(networkFeeAmount, nativeToken.decimals).toFormatted()
53
53
  : undefined,
54
54
  view: 'default',
55
55
  events: [],
@@ -82,7 +82,7 @@ class MoralisFullTransactionsDataServiceEthereum {
82
82
  newItem.events.splice(eventIndex, 0, {
83
83
  eventType: 'token',
84
84
  amount: event.amount
85
- ? blockchain_service_1.BSBigNumberHelper.format(event.amount, { decimals: token?.decimals ?? event.tokenDecimals })
85
+ ? new blockchain_service_1.BSBigHumanAmount(event.amount, token?.decimals ?? event.tokenDecimals).toFormatted()
86
86
  : undefined,
87
87
  methodName,
88
88
  from,
@@ -105,7 +105,7 @@ class EthersLedgerSigner extends ethers_1.Signer {
105
105
  const signature = await __classPrivateFieldGet(this, _EthersLedgerSigner_ledgerApp, "f").signTransaction(__classPrivateFieldGet(this, _EthersLedgerSigner_bipPath, "f"), serializedUnsignedTransaction, resolution);
106
106
  __classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")?.emit('getSignatureEnd');
107
107
  return ethers_1.ethers.utils.serializeTransaction(tx, {
108
- v: ethers_1.ethers.BigNumber.from('0x' + signature.v).toNumber(),
108
+ v: blockchain_service_1.BSBigNumber.ensureNumber('0x' + signature.v),
109
109
  r: '0x' + signature.r,
110
110
  s: '0x' + signature.s,
111
111
  });
@@ -17,8 +17,8 @@ class GhostMarketNDSEthereum extends blockchain_service_1.GhostMarketNDS {
17
17
  const response = await contract.balanceOf(address);
18
18
  if (!response)
19
19
  return false;
20
- const parsedResponse = response;
21
- return parsedResponse.gt(0);
20
+ const parsedResponse = new blockchain_service_1.BSBigUnitAmount(response.toString(), 0);
21
+ return parsedResponse.isGreaterThan(0);
22
22
  }
23
23
  catch {
24
24
  return false;
@@ -0,0 +1,12 @@
1
+ import { type INftDataService, type TBSNetwork, type TBSNetworkId, type TGetNftParams, type TGetNftsByAddressParams, type THasTokenParams, type TNftResponse, type TNftsResponse } from '@cityofzion/blockchain-service';
2
+ import axios from 'axios';
3
+ import type { IBSEthereum, TBSEthereumNetworkId } from '../../types';
4
+ export declare class MoralisNDSEthereum<N extends string, A extends TBSNetworkId> implements INftDataService {
5
+ #private;
6
+ static readonly BASE_URL: string;
7
+ constructor(service: IBSEthereum<N, A>);
8
+ static getClient(network: TBSNetwork<TBSEthereumNetworkId>): axios.AxiosInstance;
9
+ getNftsByAddress({ address, nextPageParams }: TGetNftsByAddressParams): Promise<TNftsResponse>;
10
+ getNft({ collectionHash, tokenHash }: TGetNftParams): Promise<TNftResponse>;
11
+ hasToken({ address, collectionHash }: THasTokenParams): Promise<boolean>;
12
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _MoralisNDSEthereum_instances, _a, _MoralisNDSEthereum_service, _MoralisNDSEthereum_apiInstance, _MoralisNDSEthereum_nftsCacheMap, _MoralisNDSEthereum_api_get, _MoralisNDSEthereum_parseResponse, _MoralisNDSEthereum_buildNftCacheKey;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MoralisNDSEthereum = void 0;
19
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
20
+ const axios_1 = __importDefault(require("axios"));
21
+ class MoralisNDSEthereum {
22
+ constructor(service) {
23
+ _MoralisNDSEthereum_instances.add(this);
24
+ _MoralisNDSEthereum_service.set(this, void 0);
25
+ _MoralisNDSEthereum_apiInstance.set(this, void 0);
26
+ _MoralisNDSEthereum_nftsCacheMap.set(this, new Map());
27
+ __classPrivateFieldSet(this, _MoralisNDSEthereum_service, service, "f");
28
+ }
29
+ static getClient(network) {
30
+ return axios_1.default.create({
31
+ baseURL: _a.BASE_URL,
32
+ params: {
33
+ chain: `0x${Number(network.id).toString(16)}`,
34
+ },
35
+ });
36
+ }
37
+ async getNftsByAddress({ address, nextPageParams }) {
38
+ const { data } = await __classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "a", _MoralisNDSEthereum_api_get).get(`${address}/nft`, {
39
+ params: {
40
+ limit: 25,
41
+ cursor: nextPageParams,
42
+ },
43
+ });
44
+ const nfts = data.result || [];
45
+ const items = nfts.map(nft => {
46
+ const item = __classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "m", _MoralisNDSEthereum_parseResponse).call(this, nft);
47
+ __classPrivateFieldGet(this, _MoralisNDSEthereum_nftsCacheMap, "f").set(__classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "m", _MoralisNDSEthereum_buildNftCacheKey).call(this, nft.token_id, nft.token_address), item);
48
+ return item;
49
+ });
50
+ return { nextPageParams: data.cursor, items };
51
+ }
52
+ async getNft({ collectionHash, tokenHash }) {
53
+ if (!collectionHash) {
54
+ throw new blockchain_service_1.BSError('collectionHash is required to get NFT from MoralisNDSEthereum', 'REQUIRED_PARAMETER_MISSING');
55
+ }
56
+ const cacheKey = __classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "m", _MoralisNDSEthereum_buildNftCacheKey).call(this, tokenHash, collectionHash);
57
+ const nftFromCache = __classPrivateFieldGet(this, _MoralisNDSEthereum_nftsCacheMap, "f").get(cacheKey);
58
+ if (nftFromCache) {
59
+ return nftFromCache;
60
+ }
61
+ const { data } = await __classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "a", _MoralisNDSEthereum_api_get).get(`/nft/${collectionHash}/${tokenHash}`, {
62
+ params: { normalizeMetadata: true },
63
+ });
64
+ const nft = __classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "m", _MoralisNDSEthereum_parseResponse).call(this, data);
65
+ __classPrivateFieldGet(this, _MoralisNDSEthereum_nftsCacheMap, "f").set(cacheKey, nft);
66
+ return nft;
67
+ }
68
+ async hasToken({ address, collectionHash }) {
69
+ try {
70
+ if (!collectionHash)
71
+ return false;
72
+ const { data } = await __classPrivateFieldGet(this, _MoralisNDSEthereum_instances, "a", _MoralisNDSEthereum_api_get).get(`${address}/nft`, {
73
+ params: {
74
+ limit: 1,
75
+ token_addresses: [collectionHash],
76
+ },
77
+ });
78
+ return (data.result?.length ?? 0) > 0;
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ }
85
+ exports.MoralisNDSEthereum = MoralisNDSEthereum;
86
+ _a = MoralisNDSEthereum, _MoralisNDSEthereum_service = new WeakMap(), _MoralisNDSEthereum_apiInstance = new WeakMap(), _MoralisNDSEthereum_nftsCacheMap = new WeakMap(), _MoralisNDSEthereum_instances = new WeakSet(), _MoralisNDSEthereum_api_get = function _MoralisNDSEthereum_api_get() {
87
+ if (!__classPrivateFieldGet(this, _MoralisNDSEthereum_apiInstance, "f")) {
88
+ __classPrivateFieldSet(this, _MoralisNDSEthereum_apiInstance, _a.getClient(__classPrivateFieldGet(this, _MoralisNDSEthereum_service, "f").network), "f");
89
+ }
90
+ return __classPrivateFieldGet(this, _MoralisNDSEthereum_apiInstance, "f");
91
+ }, _MoralisNDSEthereum_parseResponse = function _MoralisNDSEthereum_parseResponse(data) {
92
+ let explorerUri;
93
+ let collectionUrl;
94
+ const contractHash = data.token_address;
95
+ if ((0, blockchain_service_1.hasExplorerService)(__classPrivateFieldGet(this, _MoralisNDSEthereum_service, "f"))) {
96
+ explorerUri = __classPrivateFieldGet(this, _MoralisNDSEthereum_service, "f").explorerService.buildNftUrl({
97
+ tokenHash: data.token_id,
98
+ collectionHash: contractHash,
99
+ });
100
+ collectionUrl = __classPrivateFieldGet(this, _MoralisNDSEthereum_service, "f").explorerService.buildContractUrl(contractHash);
101
+ }
102
+ let nftName;
103
+ let image;
104
+ if (data.normalized_metadata) {
105
+ nftName = data.normalized_metadata.name;
106
+ image = data.normalized_metadata.image;
107
+ }
108
+ return {
109
+ hash: data.token_id,
110
+ collection: {
111
+ hash: contractHash,
112
+ name: data.name,
113
+ url: collectionUrl,
114
+ },
115
+ symbol: data.symbol,
116
+ image,
117
+ name: nftName,
118
+ explorerUri,
119
+ };
120
+ }, _MoralisNDSEthereum_buildNftCacheKey = function _MoralisNDSEthereum_buildNftCacheKey(tokenHash, collectionHash) {
121
+ return `${tokenHash}-${collectionHash}`;
122
+ };
123
+ MoralisNDSEthereum.BASE_URL = `${blockchain_service_1.BSCommonConstants.COZ_API_URL}/api/v2/meta`;