@cityofzion/bs-ethereum 0.8.0 → 0.8.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 (41) hide show
  1. package/.rush/temp/operation/build/all.log +1 -1
  2. package/.rush/temp/operation/build/state.json +1 -1
  3. package/.rush/temp/package-deps_build.json +4 -6
  4. package/bs-ethereum.build.log +1 -1
  5. package/dist/BSEthereum.d.ts +23 -23
  6. package/dist/BSEthereum.js +178 -178
  7. package/dist/BitqueryBDSEthereum.d.ts +14 -14
  8. package/dist/BitqueryBDSEthereum.js +197 -186
  9. package/dist/BitqueryEDSEthereum.d.ts +8 -8
  10. package/dist/BitqueryEDSEthereum.js +73 -73
  11. package/dist/GhostMarketNDSEthereum.d.ts +10 -10
  12. package/dist/GhostMarketNDSEthereum.js +77 -77
  13. package/dist/RpcBDSEthereum.d.ts +12 -12
  14. package/dist/RpcBDSEthereum.js +89 -89
  15. package/dist/assets/tokens/common.json +8 -8
  16. package/dist/constants.d.ts +16 -16
  17. package/dist/constants.js +33 -33
  18. package/dist/graphql.d.ts +124 -123
  19. package/dist/graphql.js +163 -162
  20. package/dist/index.d.ts +6 -6
  21. package/dist/index.js +22 -22
  22. package/jest.config.ts +13 -13
  23. package/jest.setup.ts +1 -1
  24. package/package.json +34 -34
  25. package/src/BSEthereum.ts +184 -184
  26. package/src/BitqueryBDSEthereum.ts +230 -220
  27. package/src/BitqueryEDSEthereum.ts +67 -67
  28. package/src/GhostMarketNDSEthereum.ts +122 -122
  29. package/src/RpcBDSEthereum.ts +88 -88
  30. package/src/__tests__/BDSEthereum.spec.ts +123 -123
  31. package/src/__tests__/BSEthereum.spec.ts +123 -123
  32. package/src/__tests__/BitqueryEDSEthereum.spec.ts +49 -49
  33. package/src/__tests__/GhostMarketNDSEthereum.spec.ts +45 -45
  34. package/src/assets/tokens/common.json +7 -7
  35. package/src/constants.ts +37 -37
  36. package/src/graphql.ts +291 -289
  37. package/src/index.ts +6 -6
  38. package/tsconfig.build.json +4 -4
  39. package/tsconfig.json +15 -15
  40. package/CHANGELOG.json +0 -22
  41. package/CHANGELOG.md +0 -11
@@ -1,186 +1,197 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.BitqueryBDSEthereum = void 0;
16
- const core_1 = require("@urql/core");
17
- const node_fetch_1 = __importDefault(require("node-fetch"));
18
- const constants_1 = require("./constants");
19
- const graphql_1 = require("./graphql");
20
- const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
21
- class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
22
- constructor(network) {
23
- super(network);
24
- this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 8;
25
- if (network.type === 'custom')
26
- 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': constants_1.BITQUERY_API_KEY,
35
- },
36
- },
37
- });
38
- }
39
- getTransaction(hash) {
40
- 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);
49
- if (!result.data || !result.data.ethereum.transfers.length)
50
- throw new Error('Transaction not found');
51
- const transfers = result.data.ethereum.transfers.map(this.parseTransactionTransfer);
52
- const { block: { height, timestamp: { unixtime }, }, transaction: { gasValue, hash: transactionHash }, } = result.data.ethereum.transfers[0];
53
- return {
54
- block: height,
55
- time: unixtime,
56
- hash: transactionHash,
57
- fee: String(gasValue),
58
- transfers,
59
- notifications: [],
60
- };
61
- });
62
- }
63
- getTransactionsByAddress({ address, page = 1, }) {
64
- var _a, _b, _c, _d, _e, _f, _g, _h;
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const limit = 10;
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);
78
- if (!result.data)
79
- throw new Error('Address does not have transactions');
80
- 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);
81
- const mixedTransfers = [...((_e = (_d = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.ethereum) === null || _d === void 0 ? void 0 : _d.sent) !== null && _e !== void 0 ? _e : []), ...((_h = (_g = (_f = result === null || result === void 0 ? void 0 : result.data) === null || _f === void 0 ? void 0 : _f.ethereum) === null || _g === void 0 ? void 0 : _g.received) !== null && _h !== void 0 ? _h : [])];
82
- const transactions = new Map();
83
- mixedTransfers.forEach(transfer => {
84
- const transactionTransfer = this.parseTransactionTransfer(transfer);
85
- const existingTransaction = transactions.get(transfer.transaction.hash);
86
- if (existingTransaction) {
87
- existingTransaction.transfers.push(transactionTransfer);
88
- return;
89
- }
90
- transactions.set(transfer.transaction.hash, {
91
- block: transfer.block.height,
92
- hash: transfer.transaction.hash,
93
- time: transfer.block.timestamp.unixtime,
94
- fee: String(transfer.transaction.gasValue),
95
- transfers: [transactionTransfer],
96
- notifications: [],
97
- });
98
- });
99
- return {
100
- totalCount,
101
- limit: limit * 2,
102
- transactions: Array.from(transactions.values()),
103
- };
104
- });
105
- }
106
- getContract() {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- throw new Error("Bitquery doesn't support contract info");
109
- });
110
- }
111
- getTokenInfo(hash) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const localToken = constants_1.TOKENS[this.networkType].find(token => token.hash === hash);
114
- if (localToken)
115
- 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);
124
- if (!result.data || result.data.ethereum.smartContractCalls.length <= 0)
125
- throw new Error('Token not found');
126
- const { address: { address }, currency: { decimals, name, symbol, tokenType }, } = result.data.ethereum.smartContractCalls[0].smartContract;
127
- if (tokenType !== 'ERC20')
128
- throw new Error('Token is not ERC20');
129
- return {
130
- hash: address,
131
- name,
132
- symbol,
133
- decimals,
134
- };
135
- });
136
- }
137
- getBalance(address) {
138
- var _a, _b;
139
- 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);
148
- const data = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.ethereum.address[0].balances) !== null && _b !== void 0 ? _b : [];
149
- const balances = data.map(({ value, currency: { address, decimals, name, symbol } }) => ({
150
- amount: value.toString(),
151
- token: {
152
- hash: address,
153
- symbol,
154
- name,
155
- decimals,
156
- },
157
- }));
158
- return balances;
159
- });
160
- }
161
- parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, name, symbol }, entityId, sender, receiver, }) {
162
- if (tokenType === 'ERC721') {
163
- return {
164
- from: sender.address,
165
- to: receiver.address,
166
- tokenId: entityId,
167
- contractHash: address,
168
- type: 'nft',
169
- };
170
- }
171
- return {
172
- from: sender.address,
173
- to: receiver.address,
174
- contractHash: address,
175
- amount: amount.toString(),
176
- token: {
177
- decimals: decimals,
178
- hash: address,
179
- name: name,
180
- symbol: symbol,
181
- },
182
- type: 'token',
183
- };
184
- }
185
- }
186
- exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BitqueryBDSEthereum = void 0;
16
+ const core_1 = require("@urql/core");
17
+ const node_fetch_1 = __importDefault(require("node-fetch"));
18
+ const constants_1 = require("./constants");
19
+ const graphql_1 = require("./graphql");
20
+ const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
21
+ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
22
+ constructor(network) {
23
+ super(network);
24
+ this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 8;
25
+ if (network.type === 'custom')
26
+ 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': constants_1.BITQUERY_API_KEY,
35
+ },
36
+ },
37
+ });
38
+ }
39
+ getTransaction(hash) {
40
+ 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);
49
+ if (!result.data || !result.data.ethereum.transfers.length)
50
+ throw new Error('Transaction not found');
51
+ const transfers = result.data.ethereum.transfers.map(this.parseTransactionTransfer);
52
+ const { block: { height, timestamp: { unixtime }, }, transaction: { gasValue, hash: transactionHash }, } = result.data.ethereum.transfers[0];
53
+ return {
54
+ block: height,
55
+ time: unixtime,
56
+ hash: transactionHash,
57
+ fee: String(gasValue),
58
+ transfers,
59
+ notifications: [],
60
+ };
61
+ });
62
+ }
63
+ getTransactionsByAddress({ address, page = 1, }) {
64
+ var _a, _b, _c, _d, _e, _f, _g, _h;
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const limit = 10;
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);
78
+ if (!result.data)
79
+ throw new Error('Address does not have transactions');
80
+ 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);
81
+ const mixedTransfers = [...((_e = (_d = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.ethereum) === null || _d === void 0 ? void 0 : _d.sent) !== null && _e !== void 0 ? _e : []), ...((_h = (_g = (_f = result === null || result === void 0 ? void 0 : result.data) === null || _f === void 0 ? void 0 : _f.ethereum) === null || _g === void 0 ? void 0 : _g.received) !== null && _h !== void 0 ? _h : [])];
82
+ const transactions = new Map();
83
+ mixedTransfers.forEach(transfer => {
84
+ const transactionTransfer = this.parseTransactionTransfer(transfer);
85
+ const existingTransaction = transactions.get(transfer.transaction.hash);
86
+ if (existingTransaction) {
87
+ existingTransaction.transfers.push(transactionTransfer);
88
+ return;
89
+ }
90
+ transactions.set(transfer.transaction.hash, {
91
+ block: transfer.block.height,
92
+ hash: transfer.transaction.hash,
93
+ time: transfer.block.timestamp.unixtime,
94
+ fee: String(transfer.transaction.gasValue),
95
+ transfers: [transactionTransfer],
96
+ notifications: [],
97
+ });
98
+ });
99
+ return {
100
+ totalCount,
101
+ limit: limit * 2,
102
+ transactions: Array.from(transactions.values()),
103
+ };
104
+ });
105
+ }
106
+ getContract() {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ throw new Error("Bitquery doesn't support contract info");
109
+ });
110
+ }
111
+ getTokenInfo(hash) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const localToken = constants_1.TOKENS[this.networkType].find(token => token.hash === hash);
114
+ if (localToken)
115
+ 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);
124
+ if (!result.data || result.data.ethereum.smartContractCalls.length <= 0)
125
+ throw new Error('Token not found');
126
+ const { address: { address }, currency: { decimals, name, symbol, tokenType }, } = result.data.ethereum.smartContractCalls[0].smartContract;
127
+ if (tokenType !== 'ERC20')
128
+ throw new Error('Token is not ERC20');
129
+ return {
130
+ hash: address,
131
+ name,
132
+ symbol,
133
+ decimals,
134
+ };
135
+ });
136
+ }
137
+ getBalance(address) {
138
+ var _a, _b, _c, _d;
139
+ 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);
148
+ const data = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.ethereum.address[0].balances) !== null && _b !== void 0 ? _b : [];
149
+ const ethBalance = (_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.ethereum.address[0].balance) !== null && _d !== void 0 ? _d : 0;
150
+ const balances = [
151
+ {
152
+ amount: ethBalance.toString(),
153
+ token: constants_1.NATIVE_ASSETS.find(asset => asset.symbol === 'ETH'),
154
+ },
155
+ ];
156
+ data.forEach(({ value, currency: { address, decimals, name, symbol } }) => {
157
+ if (value < 0)
158
+ return;
159
+ balances.push({
160
+ amount: value.toString(),
161
+ token: {
162
+ hash: address,
163
+ symbol,
164
+ name,
165
+ decimals,
166
+ },
167
+ });
168
+ });
169
+ return balances;
170
+ });
171
+ }
172
+ parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, name, symbol }, entityId, sender, receiver, }) {
173
+ if (tokenType === 'ERC721') {
174
+ return {
175
+ from: sender.address,
176
+ to: receiver.address,
177
+ tokenId: entityId,
178
+ contractHash: address,
179
+ type: 'nft',
180
+ };
181
+ }
182
+ return {
183
+ from: sender.address,
184
+ to: receiver.address,
185
+ contractHash: address,
186
+ amount: amount.toString(),
187
+ token: {
188
+ decimals: decimals,
189
+ hash: address,
190
+ name: name,
191
+ symbol: symbol,
192
+ },
193
+ type: 'token',
194
+ };
195
+ }
196
+ }
197
+ exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
@@ -1,8 +1,8 @@
1
- import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
- export declare class BitqueryEDSEthereum implements ExchangeDataService {
3
- private readonly client;
4
- private readonly networkType;
5
- constructor(networkType: NetworkType);
6
- getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
- private getCurrencyRatio;
8
- }
1
+ import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ export declare class BitqueryEDSEthereum implements ExchangeDataService {
3
+ private readonly client;
4
+ private readonly networkType;
5
+ constructor(networkType: NetworkType);
6
+ getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
+ private getCurrencyRatio;
8
+ }
@@ -1,73 +1,73 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- 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");
19
- const dayjs_1 = __importDefault(require("dayjs"));
20
- const utc_1 = __importDefault(require("dayjs/plugin/utc"));
21
- const graphql_1 = require("./graphql");
22
- dayjs_1.default.extend(utc_1.default);
23
- class BitqueryEDSEthereum {
24
- constructor(networkType) {
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': constants_1.BITQUERY_API_KEY,
33
- },
34
- },
35
- });
36
- }
37
- getTokenPrices(currency) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- if (this.networkType !== 'mainnet')
40
- throw new Error('Exchange is only available on mainnet');
41
- 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
- }
48
- if (!result.data) {
49
- throw new Error('There is no price data');
50
- }
51
- let currencyRatio = 1;
52
- if (currency !== 'USD') {
53
- currencyRatio = yield this.getCurrencyRatio(currency);
54
- }
55
- const prices = result.data.ethereum.dexTrades.map((trade) => ({
56
- symbol: trade.baseCurrency.symbol,
57
- price: trade.quotePrice * currencyRatio,
58
- hash: trade.baseCurrency.address,
59
- }));
60
- return prices;
61
- });
62
- }
63
- getCurrencyRatio(currency) {
64
- 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();
69
- return data;
70
- });
71
- }
72
- }
73
- exports.BitqueryEDSEthereum = BitqueryEDSEthereum;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ 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");
19
+ const dayjs_1 = __importDefault(require("dayjs"));
20
+ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
21
+ const graphql_1 = require("./graphql");
22
+ dayjs_1.default.extend(utc_1.default);
23
+ class BitqueryEDSEthereum {
24
+ constructor(networkType) {
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': constants_1.BITQUERY_API_KEY,
33
+ },
34
+ },
35
+ });
36
+ }
37
+ getTokenPrices(currency) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (this.networkType !== 'mainnet')
40
+ throw new Error('Exchange is only available on mainnet');
41
+ 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
+ }
48
+ if (!result.data) {
49
+ throw new Error('There is no price data');
50
+ }
51
+ let currencyRatio = 1;
52
+ if (currency !== 'USD') {
53
+ currencyRatio = yield this.getCurrencyRatio(currency);
54
+ }
55
+ const prices = result.data.ethereum.dexTrades.map((trade) => ({
56
+ symbol: trade.baseCurrency.symbol,
57
+ price: trade.quotePrice * currencyRatio,
58
+ hash: trade.baseCurrency.address,
59
+ }));
60
+ return prices;
61
+ });
62
+ }
63
+ getCurrencyRatio(currency) {
64
+ 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();
69
+ return data;
70
+ });
71
+ }
72
+ }
73
+ exports.BitqueryEDSEthereum = BitqueryEDSEthereum;
@@ -1,10 +1,10 @@
1
- import { NftResponse, NftsResponse, NetworkType, NftDataService, GetNftParam, GetNftsByAddressParams } from '@cityofzion/blockchain-service';
2
- export declare class GhostMarketNDSEthereum implements NftDataService {
3
- private networkType;
4
- constructor(networkType: NetworkType);
5
- getNftsByAddress({ address, size, cursor, page }: GetNftsByAddressParams): Promise<NftsResponse>;
6
- getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
7
- private treatGhostMarketImage;
8
- private getUrlWithParams;
9
- private parse;
10
- }
1
+ import { NftResponse, NftsResponse, NetworkType, NftDataService, GetNftParam, GetNftsByAddressParams } from '@cityofzion/blockchain-service';
2
+ export declare class GhostMarketNDSEthereum implements NftDataService {
3
+ private networkType;
4
+ constructor(networkType: NetworkType);
5
+ getNftsByAddress({ address, size, cursor, page }: GetNftsByAddressParams): Promise<NftsResponse>;
6
+ getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
7
+ private treatGhostMarketImage;
8
+ private getUrlWithParams;
9
+ private parse;
10
+ }