@cityofzion/bs-ethereum 1.1.0 → 1.2.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.
Files changed (45) hide show
  1. package/dist/BSEthereum.d.ts +2 -2
  2. package/dist/BSEthereum.js +12 -7
  3. package/dist/BitqueryBDSEthereum.d.ts +2 -3
  4. package/dist/BitqueryBDSEthereum.js +34 -50
  5. package/dist/BitqueryEDSEthereum.d.ts +2 -3
  6. package/dist/BitqueryEDSEthereum.js +27 -27
  7. package/dist/GhostMarketNDSEthereum.d.ts +1 -1
  8. package/dist/GhostMarketNDSEthereum.js +23 -11
  9. package/dist/LedgerServiceEthereum.d.ts +4 -2
  10. package/dist/LedgerServiceEthereum.js +13 -5
  11. package/dist/RpcBDSEthereum.d.ts +1 -1
  12. package/dist/RpcBDSEthereum.js +21 -7
  13. package/dist/constants.d.ts +2 -2
  14. package/dist/constants.js +3 -3
  15. package/package.json +6 -5
  16. package/.eslintignore +0 -13
  17. package/.eslintrc.cjs +0 -22
  18. package/.rush/temp/operation/build/all.log +0 -1
  19. package/.rush/temp/operation/build/state.json +0 -3
  20. package/.rush/temp/package-deps_build.json +0 -30
  21. package/.rush/temp/shrinkwrap-deps.json +0 -531
  22. package/CHANGELOG.json +0 -126
  23. package/CHANGELOG.md +0 -68
  24. package/bs-ethereum.build.log +0 -1
  25. package/dist/graphql.d.ts +0 -124
  26. package/dist/graphql.js +0 -160
  27. package/jest.config.ts +0 -13
  28. package/jest.setup.ts +0 -1
  29. package/src/BSEthereum.ts +0 -208
  30. package/src/BitqueryBDSEthereum.ts +0 -231
  31. package/src/BitqueryEDSEthereum.ts +0 -67
  32. package/src/GhostMarketNDSEthereum.ts +0 -125
  33. package/src/LedgerServiceEthereum.ts +0 -44
  34. package/src/RpcBDSEthereum.ts +0 -88
  35. package/src/__tests__/BSEthereum.spec.ts +0 -172
  36. package/src/__tests__/BitqueryBDSEthereum.spec.ts +0 -106
  37. package/src/__tests__/BitqueryEDSEthereum.spec.ts +0 -55
  38. package/src/__tests__/GhostMarketNDSEthereum.spec.ts +0 -49
  39. package/src/__tests__/RpcBDSEthereum.spec.ts +0 -62
  40. package/src/assets/tokens/common.json +0 -8
  41. package/src/constants.ts +0 -36
  42. package/src/graphql.ts +0 -288
  43. package/src/index.ts +0 -6
  44. package/tsconfig.build.json +0 -4
  45. package/tsconfig.json +0 -15
@@ -1,17 +1,17 @@
1
1
  import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialBy, Token, TransferParam } from '@cityofzion/blockchain-service';
2
2
  import { LedgerServiceEthereum } from './LedgerServiceEthereum';
3
+ import Transport from '@ledgerhq/hw-transport';
3
4
  export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger {
4
5
  readonly blockchainName: BSCustomName;
5
6
  readonly feeToken: Token;
6
7
  readonly derivationPath: string;
7
- private readonly bitqueryApiKey;
8
8
  blockchainDataService: BlockchainDataService;
9
9
  exchangeDataService: ExchangeDataService;
10
10
  ledgerService: LedgerServiceEthereum;
11
11
  tokens: Token[];
12
12
  nftDataService: NftDataService;
13
13
  network: Network;
14
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, bitqueryApiKey: string);
14
+ constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, getLedgerTransport?: (account: Account) => Promise<Transport>);
15
15
  setNetwork(param: PartialBy<Network, 'url'>): void;
16
16
  validateAddress(address: string): boolean;
17
17
  validateEncrypted(json: string): boolean;
@@ -44,12 +44,11 @@ const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
44
44
  const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
45
45
  const LedgerServiceEthereum_1 = require("./LedgerServiceEthereum");
46
46
  class BSEthereum {
47
- constructor(blockchainName, network, bitqueryApiKey) {
48
- this.ledgerService = new LedgerServiceEthereum_1.LedgerServiceEthereum();
47
+ constructor(blockchainName, network, getLedgerTransport) {
49
48
  this.blockchainName = blockchainName;
49
+ this.ledgerService = new LedgerServiceEthereum_1.LedgerServiceEthereum(getLedgerTransport);
50
50
  this.derivationPath = constants_1.DERIVATION_PATH;
51
51
  this.tokens = constants_1.TOKENS[network.type];
52
- this.bitqueryApiKey = bitqueryApiKey;
53
52
  this.feeToken = this.tokens.find(token => token.symbol === 'ETH');
54
53
  this.setNetwork(network);
55
54
  }
@@ -64,9 +63,9 @@ class BSEthereum {
64
63
  this.blockchainDataService = new RpcBDSEthereum_1.RpcBDSEthereum(network);
65
64
  }
66
65
  else {
67
- this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network, this.bitqueryApiKey);
66
+ this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network);
68
67
  }
69
- this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type, this.bitqueryApiKey);
68
+ this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type);
70
69
  this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network.type);
71
70
  }
72
71
  validateAddress(address) {
@@ -139,8 +138,14 @@ class BSEthereum {
139
138
  var _a;
140
139
  return __awaiter(this, void 0, void 0, function* () {
141
140
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
142
- const signTransactionFunction = param.isLedger
143
- ? yield this.ledgerService.getSignTransactionFunction(param.ledgerTransport)
141
+ let ledgerTransport;
142
+ if (param.isLedger) {
143
+ if (!this.ledgerService.getLedgerTransport)
144
+ throw new Error('You must provide getLedgerTransport function to use Ledger');
145
+ ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
146
+ }
147
+ const signTransactionFunction = ledgerTransport
148
+ ? yield this.ledgerService.getSignTransactionFunction(ledgerTransport)
144
149
  : new ethers_1.ethers.Wallet(param.senderAccount.key, provider).signTransaction;
145
150
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
146
151
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
@@ -1,10 +1,9 @@
1
1
  import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
2
2
  import { RpcBDSEthereum } from './RpcBDSEthereum';
3
3
  export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
4
- private readonly client;
5
- private readonly networkType;
4
+ #private;
6
5
  maxTimeToConfirmTransactionInMs: number;
7
- constructor(network: Network, apiKey: string);
6
+ constructor(network: Network);
8
7
  getTransaction(hash: string): Promise<TransactionResponse>;
9
8
  getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
10
9
  getContract(): Promise<ContractResponse>;
@@ -8,44 +8,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _BitqueryBDSEthereum_client, _BitqueryBDSEthereum_networkType;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.BitqueryBDSEthereum = void 0;
16
- const core_1 = require("@urql/core");
17
- const node_fetch_1 = __importDefault(require("node-fetch"));
18
28
  const constants_1 = require("./constants");
19
- const graphql_1 = require("./graphql");
20
29
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
30
+ const axios_1 = __importDefault(require("axios"));
21
31
  class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
22
- constructor(network, apiKey) {
32
+ constructor(network) {
23
33
  super(network);
34
+ _BitqueryBDSEthereum_client.set(this, void 0);
35
+ _BitqueryBDSEthereum_networkType.set(this, void 0);
24
36
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 8;
25
37
  if (network.type === 'custom')
26
38
  throw new Error('Custom network not supported');
27
- this.networkType = network.type;
28
- this.client = new core_1.Client({
29
- url: constants_1.BITQUERY_URL,
30
- exchanges: [core_1.fetchExchange],
31
- fetch: node_fetch_1.default,
32
- fetchOptions: {
33
- headers: {
34
- 'X-API-KEY': apiKey,
35
- },
36
- },
37
- });
39
+ __classPrivateFieldSet(this, _BitqueryBDSEthereum_networkType, network.type, "f");
40
+ __classPrivateFieldSet(this, _BitqueryBDSEthereum_client, axios_1.default.create({
41
+ baseURL: constants_1.BITQUERY_MIRROR_URL,
42
+ }), "f");
38
43
  }
39
44
  getTransaction(hash) {
40
45
  return __awaiter(this, void 0, void 0, function* () {
41
- const result = yield this.client
42
- .query(graphql_1.bitqueryGetTransactionQuery, {
43
- hash,
44
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
45
- })
46
- .toPromise();
47
- if (result.error)
48
- throw new Error(result.error.message);
46
+ 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")] },
48
+ });
49
49
  if (!result.data || !result.data.ethereum.transfers.length)
50
50
  throw new Error('Transaction not found');
51
51
  const transfers = result.data.ethereum.transfers.map(this.parseTransactionTransfer);
@@ -65,16 +65,9 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
66
  const limit = 10;
67
67
  const offset = limit * (page - 1);
68
- const result = yield this.client
69
- .query(graphql_1.bitqueryGetTransactionsByAddressQuery, {
70
- address,
71
- limit,
72
- offset,
73
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
74
- })
75
- .toPromise();
76
- if (result.error)
77
- throw new Error(result.error.message);
68
+ 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 },
70
+ });
78
71
  if (!result.data)
79
72
  throw new Error('Address does not have transactions');
80
73
  const totalCount = ((_a = result.data.ethereum.sentCount[0].count) !== null && _a !== void 0 ? _a : 0) + ((_b = result.data.ethereum.receiverCount[0].count) !== null && _b !== void 0 ? _b : 0);
@@ -110,17 +103,12 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
110
103
  }
111
104
  getTokenInfo(hash) {
112
105
  return __awaiter(this, void 0, void 0, function* () {
113
- const localToken = constants_1.TOKENS[this.networkType].find(token => token.hash === hash);
106
+ const localToken = constants_1.TOKENS[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")].find(token => token.hash === hash);
114
107
  if (localToken)
115
108
  return localToken;
116
- const result = yield this.client
117
- .query(graphql_1.bitqueryGetTokenInfoQuery, {
118
- hash,
119
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
120
- })
121
- .toPromise();
122
- if (result.error)
123
- throw new Error(result.error.message);
109
+ 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")] },
111
+ });
124
112
  if (!result.data || result.data.ethereum.smartContractCalls.length <= 0)
125
113
  throw new Error('Token not found');
126
114
  const { address: { address }, currency: { decimals, name, symbol, tokenType }, } = result.data.ethereum.smartContractCalls[0].smartContract;
@@ -137,14 +125,9 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
137
125
  getBalance(address) {
138
126
  var _a, _b, _c, _d;
139
127
  return __awaiter(this, void 0, void 0, function* () {
140
- const result = yield this.client
141
- .query(graphql_1.bitqueryGetBalanceQuery, {
142
- address,
143
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
144
- })
145
- .toPromise();
146
- if (result.error)
147
- throw new Error(result.error.message);
128
+ 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")] },
130
+ });
148
131
  const data = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.ethereum.address[0].balances) !== null && _b !== void 0 ? _b : [];
149
132
  const ethBalance = (_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.ethereum.address[0].balance) !== null && _d !== void 0 ? _d : 0;
150
133
  const ethToken = constants_1.NATIVE_ASSETS.find(asset => asset.symbol === 'ETH');
@@ -196,3 +179,4 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
196
179
  }
197
180
  }
198
181
  exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
182
+ _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_networkType = new WeakMap();
@@ -1,8 +1,7 @@
1
1
  import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
2
  export declare class BitqueryEDSEthereum implements ExchangeDataService {
3
- private readonly client;
4
- private readonly networkType;
5
- constructor(networkType: NetworkType, apiKey: string);
3
+ #private;
4
+ constructor(networkType: NetworkType);
6
5
  getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
6
  private getCurrencyRatio;
8
7
  }
@@ -8,43 +8,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _BitqueryEDSEthereum_client, _BitqueryEDSEthereum_networkType;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.BitqueryEDSEthereum = void 0;
16
- const core_1 = require("@urql/core");
17
- const node_fetch_1 = __importDefault(require("node-fetch"));
18
- const constants_1 = require("./constants");
28
+ const axios_1 = __importDefault(require("axios"));
19
29
  const dayjs_1 = __importDefault(require("dayjs"));
20
30
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
21
- const graphql_1 = require("./graphql");
31
+ const constants_1 = require("./constants");
22
32
  dayjs_1.default.extend(utc_1.default);
23
33
  class BitqueryEDSEthereum {
24
- constructor(networkType, apiKey) {
25
- this.networkType = networkType;
26
- this.client = new core_1.Client({
27
- url: constants_1.BITQUERY_URL,
28
- exchanges: [core_1.fetchExchange],
29
- fetch: node_fetch_1.default,
30
- fetchOptions: {
31
- headers: {
32
- 'X-API-KEY': apiKey,
33
- },
34
- },
35
- });
34
+ constructor(networkType) {
35
+ _BitqueryEDSEthereum_client.set(this, void 0);
36
+ _BitqueryEDSEthereum_networkType.set(this, void 0);
37
+ __classPrivateFieldSet(this, _BitqueryEDSEthereum_networkType, networkType, "f");
38
+ __classPrivateFieldSet(this, _BitqueryEDSEthereum_client, axios_1.default.create({
39
+ baseURL: constants_1.BITQUERY_MIRROR_URL,
40
+ }), "f");
36
41
  }
37
42
  getTokenPrices(currency) {
38
43
  return __awaiter(this, void 0, void 0, function* () {
39
- if (this.networkType !== 'mainnet')
44
+ if (__classPrivateFieldGet(this, _BitqueryEDSEthereum_networkType, "f") !== 'mainnet')
40
45
  throw new Error('Exchange is only available on mainnet');
41
46
  const twoDaysAgo = dayjs_1.default.utc().subtract(2, 'day').startOf('date').toISOString();
42
- const result = yield this.client
43
- .query(graphql_1.bitqueryGetPricesQuery, { after: twoDaysAgo, network: 'ethereum' })
44
- .toPromise();
45
- if (result.error) {
46
- throw new Error(result.error.message);
47
- }
47
+ const result = yield __classPrivateFieldGet(this, _BitqueryEDSEthereum_client, "f").get(`/get-price`, {
48
+ params: { network: constants_1.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryEDSEthereum_networkType, "f")], after: twoDaysAgo },
49
+ });
48
50
  if (!result.data) {
49
51
  throw new Error('There is no price data');
50
52
  }
@@ -62,12 +64,10 @@ class BitqueryEDSEthereum {
62
64
  }
63
65
  getCurrencyRatio(currency) {
64
66
  return __awaiter(this, void 0, void 0, function* () {
65
- const request = yield (0, node_fetch_1.default)(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`, {
66
- method: 'GET',
67
- });
68
- const data = yield request.json();
67
+ const { data } = yield axios_1.default.get(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`);
69
68
  return data;
70
69
  });
71
70
  }
72
71
  }
73
72
  exports.BitqueryEDSEthereum = BitqueryEDSEthereum;
73
+ _BitqueryEDSEthereum_client = new WeakMap(), _BitqueryEDSEthereum_networkType = new WeakMap();
@@ -1,6 +1,6 @@
1
1
  import { NftResponse, NftsResponse, NetworkType, NftDataService, GetNftParam, GetNftsByAddressParams } from '@cityofzion/blockchain-service';
2
2
  export declare class GhostMarketNDSEthereum implements NftDataService {
3
- private networkType;
3
+ #private;
4
4
  constructor(networkType: NetworkType);
5
5
  getNftsByAddress({ address, size, cursor }: GetNftsByAddressParams): Promise<NftsResponse>;
6
6
  getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
@@ -8,17 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _GhostMarketNDSEthereum_networkType;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.GhostMarketNDSEthereum = void 0;
16
28
  const query_string_1 = __importDefault(require("query-string"));
29
+ const axios_1 = __importDefault(require("axios"));
17
30
  const constants_1 = require("./constants");
18
- const node_fetch_1 = __importDefault(require("node-fetch"));
19
31
  class GhostMarketNDSEthereum {
20
32
  constructor(networkType) {
21
- this.networkType = networkType;
33
+ _GhostMarketNDSEthereum_networkType.set(this, void 0);
34
+ __classPrivateFieldSet(this, _GhostMarketNDSEthereum_networkType, networkType, "f");
22
35
  }
23
36
  getNftsByAddress({ address, size = 18, cursor }) {
24
37
  var _a;
@@ -28,10 +41,9 @@ class GhostMarketNDSEthereum {
28
41
  owners: [address],
29
42
  cursor: cursor,
30
43
  });
31
- const request = yield (0, node_fetch_1.default)(url, { method: 'GET' });
32
- const data = (yield request.json());
33
- const nfts = (_a = data.assets) !== null && _a !== void 0 ? _a : [];
34
- return { nextCursor: data.next, items: nfts.map(this.parse.bind(this)) };
44
+ const request = yield axios_1.default.get(url);
45
+ const nfts = (_a = request.data.assets) !== null && _a !== void 0 ? _a : [];
46
+ return { nextCursor: request.data.next, items: nfts.map(this.parse.bind(this)) };
35
47
  });
36
48
  }
37
49
  getNft({ contractHash, tokenId }) {
@@ -40,9 +52,8 @@ class GhostMarketNDSEthereum {
40
52
  contract: contractHash,
41
53
  tokenIds: [tokenId],
42
54
  });
43
- const request = yield (0, node_fetch_1.default)(url, { method: 'GET' });
44
- const data = (yield request.json());
45
- return this.parse(data.assets[0]);
55
+ const request = yield axios_1.default.get(url);
56
+ return this.parse(request.data.assets[0]);
46
57
  });
47
58
  }
48
59
  treatGhostMarketImage(srcImage) {
@@ -56,8 +67,8 @@ class GhostMarketNDSEthereum {
56
67
  return srcImage;
57
68
  }
58
69
  getUrlWithParams(params) {
59
- const parameters = query_string_1.default.stringify(Object.assign({ chain: constants_1.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[this.networkType] }, params), { arrayFormat: 'bracket' });
60
- return `${constants_1.GHOSTMARKET_URL_BY_NETWORK_TYPE[this.networkType]}/assets?${parameters}`;
70
+ const parameters = query_string_1.default.stringify(Object.assign({ chain: constants_1.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _GhostMarketNDSEthereum_networkType, "f")] }, params), { arrayFormat: 'bracket' });
71
+ return `${constants_1.GHOSTMARKET_URL_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _GhostMarketNDSEthereum_networkType, "f")]}/assets?${parameters}`;
61
72
  }
62
73
  parse(data) {
63
74
  var _a, _b;
@@ -79,3 +90,4 @@ class GhostMarketNDSEthereum {
79
90
  }
80
91
  }
81
92
  exports.GhostMarketNDSEthereum = GhostMarketNDSEthereum;
93
+ _GhostMarketNDSEthereum_networkType = new WeakMap();
@@ -1,8 +1,10 @@
1
- import { LedgerService } from '@cityofzion/blockchain-service';
1
+ import { Account, LedgerService } from '@cityofzion/blockchain-service';
2
2
  import Transport from '@ledgerhq/hw-transport';
3
3
  import { ethers } from 'ethers';
4
4
  export declare class LedgerServiceEthereum implements LedgerService {
5
- private readonly defaultPath;
5
+ #private;
6
+ getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined;
7
+ constructor(getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined);
6
8
  getAddress(transport: Transport): Promise<string>;
7
9
  getPublicKey(transport: Transport): Promise<string>;
8
10
  getSignTransactionFunction(transport: Transport): Promise<(transaction: ethers.providers.TransactionRequest) => Promise<string>>;
@@ -31,25 +31,32 @@ 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 _LedgerServiceEthereum_defaultPath;
34
40
  Object.defineProperty(exports, "__esModule", { value: true });
35
41
  exports.LedgerServiceEthereum = void 0;
36
42
  const hw_app_eth_1 = __importStar(require("@ledgerhq/hw-app-eth"));
37
43
  const ethers_1 = require("ethers");
38
44
  class LedgerServiceEthereum {
39
- constructor() {
40
- this.defaultPath = "44'/60'/0'/0/0";
45
+ constructor(getLedgerTransport) {
46
+ this.getLedgerTransport = getLedgerTransport;
47
+ _LedgerServiceEthereum_defaultPath.set(this, "44'/60'/0'/0/0");
41
48
  }
42
49
  getAddress(transport) {
43
50
  return __awaiter(this, void 0, void 0, function* () {
44
51
  const ledgerApp = new hw_app_eth_1.default(transport);
45
- const { address } = yield ledgerApp.getAddress(this.defaultPath);
52
+ const { address } = yield ledgerApp.getAddress(__classPrivateFieldGet(this, _LedgerServiceEthereum_defaultPath, "f"));
46
53
  return address;
47
54
  });
48
55
  }
49
56
  getPublicKey(transport) {
50
57
  return __awaiter(this, void 0, void 0, function* () {
51
58
  const ledgerApp = new hw_app_eth_1.default(transport);
52
- const { publicKey } = yield ledgerApp.getAddress(this.defaultPath);
59
+ const { publicKey } = yield ledgerApp.getAddress(__classPrivateFieldGet(this, _LedgerServiceEthereum_defaultPath, "f"));
53
60
  return '0x' + publicKey;
54
61
  });
55
62
  }
@@ -60,7 +67,7 @@ class LedgerServiceEthereum {
60
67
  const unsignedTransaction = Object.assign(Object.assign({}, transaction), { nonce: transaction.nonce ? ethers_1.ethers.BigNumber.from(transaction.nonce).toNumber() : undefined });
61
68
  const serializedUnsignedTransaction = ethers_1.ethers.utils.serializeTransaction(unsignedTransaction).substring(2);
62
69
  const resolution = yield hw_app_eth_1.ledgerService.resolveTransaction(serializedUnsignedTransaction, {}, {});
63
- const signature = yield ledgerApp.signTransaction(this.defaultPath, serializedUnsignedTransaction, resolution);
70
+ const signature = yield ledgerApp.signTransaction(__classPrivateFieldGet(this, _LedgerServiceEthereum_defaultPath, "f"), serializedUnsignedTransaction, resolution);
64
71
  return ethers_1.ethers.utils.serializeTransaction(unsignedTransaction, {
65
72
  v: ethers_1.ethers.BigNumber.from('0x' + signature.v).toNumber(),
66
73
  r: '0x' + signature.r,
@@ -71,3 +78,4 @@ class LedgerServiceEthereum {
71
78
  }
72
79
  }
73
80
  exports.LedgerServiceEthereum = LedgerServiceEthereum;
81
+ _LedgerServiceEthereum_defaultPath = new WeakMap();
@@ -1,6 +1,6 @@
1
1
  import { BalanceResponse, BlockchainDataService, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
2
2
  export declare class RpcBDSEthereum implements BlockchainDataService {
3
- private readonly network;
3
+ #private;
4
4
  maxTimeToConfirmTransactionInMs: number;
5
5
  constructor(network: Network);
6
6
  getTransaction(hash: string): Promise<TransactionResponse>;
@@ -8,25 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _RpcBDSEthereum_network;
11
23
  Object.defineProperty(exports, "__esModule", { value: true });
12
24
  exports.RpcBDSEthereum = void 0;
13
25
  const ethers_1 = require("ethers");
14
26
  const constants_1 = require("./constants");
15
27
  class RpcBDSEthereum {
16
28
  constructor(network) {
29
+ _RpcBDSEthereum_network.set(this, void 0);
17
30
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5;
18
- this.network = network;
31
+ __classPrivateFieldSet(this, _RpcBDSEthereum_network, network, "f");
19
32
  }
20
33
  getTransaction(hash) {
21
34
  return __awaiter(this, void 0, void 0, function* () {
22
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
35
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
23
36
  const transaction = yield provider.getTransaction(hash);
24
37
  if (!transaction || !transaction.blockHash || !transaction.to)
25
38
  throw new Error('Transaction not found');
26
39
  const block = yield provider.getBlock(transaction.blockHash);
27
40
  if (!block)
28
41
  throw new Error('Block not found');
29
- const tokens = constants_1.TOKENS[this.network.type];
42
+ const tokens = constants_1.TOKENS[__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").type];
30
43
  const token = tokens.find(token => token.symbol === 'ETH');
31
44
  return {
32
45
  block: block.number,
@@ -58,7 +71,7 @@ class RpcBDSEthereum {
58
71
  }
59
72
  getTokenInfo(hash) {
60
73
  return __awaiter(this, void 0, void 0, function* () {
61
- const tokens = constants_1.TOKENS[this.network.type];
74
+ const tokens = constants_1.TOKENS[__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").type];
62
75
  const token = tokens.find(token => token.hash === hash);
63
76
  if (!token)
64
77
  throw new Error('Token not found');
@@ -67,9 +80,9 @@ class RpcBDSEthereum {
67
80
  }
68
81
  getBalance(address) {
69
82
  return __awaiter(this, void 0, void 0, function* () {
70
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
83
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
71
84
  const balance = yield provider.getBalance(address);
72
- const tokens = constants_1.TOKENS[this.network.type];
85
+ const tokens = constants_1.TOKENS[__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").type];
73
86
  const token = tokens.find(token => token.symbol === 'ETH');
74
87
  return [
75
88
  {
@@ -81,9 +94,10 @@ class RpcBDSEthereum {
81
94
  }
82
95
  getBlockHeight() {
83
96
  return __awaiter(this, void 0, void 0, function* () {
84
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
97
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
85
98
  return yield provider.getBlockNumber();
86
99
  });
87
100
  }
88
101
  }
89
102
  exports.RpcBDSEthereum = RpcBDSEthereum;
103
+ _RpcBDSEthereum_network = new WeakMap();
@@ -8,8 +8,8 @@ export declare const NATIVE_ASSETS: {
8
8
  decimals: number;
9
9
  }[];
10
10
  export declare const DEFAULT_URL_BY_NETWORK_TYPE: Record<NetworkType, string>;
11
- export declare const BITQUERY_URL = "https://graphql.bitquery.io";
12
- export declare const BITQUERY_NETWORK_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, BitqueryNetwork>;
11
+ export declare const BITQUERY_MIRROR_URL = "https://i4l7kcg43c.execute-api.us-east-1.amazonaws.com/production/";
12
+ export declare const BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, BitqueryNetwork>;
13
13
  export declare const GHOSTMARKET_URL_BY_NETWORK_TYPE: Partial<Record<NetworkType, string>>;
14
14
  export declare const GHOSTMARKET_CHAIN_BY_NETWORK_TYPE: Partial<Record<NetworkType, string>>;
15
15
  export declare const DERIVATION_PATH = "m/44'/60'/0'/0/?";
package/dist/constants.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DERIVATION_PATH = exports.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE = exports.GHOSTMARKET_URL_BY_NETWORK_TYPE = exports.BITQUERY_NETWORK_BY_NETWORK_TYPE = exports.BITQUERY_URL = exports.DEFAULT_URL_BY_NETWORK_TYPE = exports.NATIVE_ASSETS = exports.TOKENS = void 0;
6
+ exports.DERIVATION_PATH = exports.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE = exports.GHOSTMARKET_URL_BY_NETWORK_TYPE = exports.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE = exports.BITQUERY_MIRROR_URL = exports.DEFAULT_URL_BY_NETWORK_TYPE = exports.NATIVE_ASSETS = exports.TOKENS = void 0;
7
7
  const common_json_1 = __importDefault(require("./assets/tokens/common.json"));
8
8
  exports.TOKENS = {
9
9
  mainnet: [...common_json_1.default],
@@ -16,8 +16,8 @@ exports.DEFAULT_URL_BY_NETWORK_TYPE = {
16
16
  testnet: 'https://ethereum-sepolia-rpc.publicnode.com',
17
17
  custom: 'http://127.0.0.1:8545',
18
18
  };
19
- exports.BITQUERY_URL = 'https://graphql.bitquery.io';
20
- exports.BITQUERY_NETWORK_BY_NETWORK_TYPE = {
19
+ exports.BITQUERY_MIRROR_URL = 'https://i4l7kcg43c.execute-api.us-east-1.amazonaws.com/production/';
20
+ exports.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE = {
21
21
  mainnet: 'ethereum',
22
22
  testnet: 'goerli',
23
23
  };
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
7
7
  "author": "Coz",
8
8
  "license": "MIT",
9
+ "files": [
10
+ "/dist"
11
+ ],
9
12
  "dependencies": {
13
+ "axios": "1.5.1",
10
14
  "ethers": "5.7.2",
11
- "@urql/core": "~4.1.1",
12
15
  "graphql": "~16.8.0",
13
- "node-fetch": "2.6.4",
14
16
  "dayjs": "~1.11.9",
15
17
  "query-string": "7.1.3",
16
18
  "@ethersproject/json-wallets": "5.7.0",
@@ -19,11 +21,10 @@
19
21
  "@ledgerhq/hw-transport-node-hid": "~6.28.5",
20
22
  "@ledgerhq/hw-transport": "~6.30.5",
21
23
  "@ledgerhq/hw-app-eth": "~6.35.7",
22
- "@cityofzion/blockchain-service": "0.10.0"
24
+ "@cityofzion/blockchain-service": "0.11.0"
23
25
  },
24
26
  "devDependencies": {
25
27
  "@types/jest": "29.5.3",
26
- "@types/node-fetch": "2.6.4",
27
28
  "@typescript-eslint/eslint-plugin": "^6.5.0",
28
29
  "@typescript-eslint/parser": "^6.5.0",
29
30
  "dotenv": "16.3.1",
package/.eslintignore DELETED
@@ -1,13 +0,0 @@
1
- .DS_Store
2
- node_modules
3
- /build
4
- /dist
5
- /package
6
- .env
7
- .env.*
8
- !.env.example
9
- *.md
10
- *.html
11
-
12
- # Ignore files for NPM lock file
13
- package-lock.json