@cityofzion/bs-ethereum 0.8.2 → 0.9.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.
- package/.eslintignore +13 -0
- package/.eslintrc.cjs +22 -0
- package/.rush/temp/operation/build/all.log +1 -1
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/package-deps_build.json +12 -8
- package/.rush/temp/shrinkwrap-deps.json +84 -2
- package/CHANGELOG.json +39 -0
- package/CHANGELOG.md +22 -0
- package/bs-ethereum.build.log +1 -1
- package/dist/BSEthereum.d.ts +24 -23
- package/dist/BSEthereum.js +184 -178
- package/dist/BitqueryBDSEthereum.d.ts +14 -14
- package/dist/BitqueryBDSEthereum.js +198 -197
- package/dist/BitqueryEDSEthereum.d.ts +8 -8
- package/dist/BitqueryEDSEthereum.js +73 -73
- package/dist/GhostMarketNDSEthereum.d.ts +10 -10
- package/dist/GhostMarketNDSEthereum.js +77 -77
- package/dist/RpcBDSEthereum.d.ts +12 -12
- package/dist/RpcBDSEthereum.js +89 -89
- package/dist/assets/tokens/common.json +8 -8
- package/dist/constants.d.ts +16 -16
- package/dist/constants.js +33 -33
- package/dist/graphql.d.ts +124 -124
- package/dist/graphql.js +163 -163
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/jest.config.ts +13 -13
- package/jest.setup.ts +1 -1
- package/package.json +39 -34
- package/src/BSEthereum.ts +189 -184
- package/src/BitqueryBDSEthereum.ts +231 -230
- package/src/BitqueryEDSEthereum.ts +67 -67
- package/src/GhostMarketNDSEthereum.ts +121 -122
- package/src/RpcBDSEthereum.ts +88 -88
- package/src/__tests__/BDSEthereum.spec.ts +123 -123
- package/src/__tests__/BSEthereum.spec.ts +129 -123
- package/src/__tests__/BitqueryEDSEthereum.spec.ts +49 -49
- package/src/__tests__/GhostMarketNDSEthereum.spec.ts +45 -45
- package/src/assets/tokens/common.json +8 -8
- package/src/constants.ts +37 -37
- package/src/graphql.ts +291 -291
- package/src/index.ts +6 -6
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +15 -15
|
@@ -1,197 +1,198 @@
|
|
|
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
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
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, _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 ethToken = constants_1.NATIVE_ASSETS.find(asset => asset.symbol === 'ETH');
|
|
151
|
+
const balances = [
|
|
152
|
+
{
|
|
153
|
+
amount: ethBalance.toString(),
|
|
154
|
+
token: ethToken,
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
data.forEach(({ value, currency: { address, decimals, name, symbol } }) => {
|
|
158
|
+
if (value < 0 || address === ethToken.hash)
|
|
159
|
+
return;
|
|
160
|
+
balances.push({
|
|
161
|
+
amount: value.toString(),
|
|
162
|
+
token: {
|
|
163
|
+
hash: address,
|
|
164
|
+
symbol,
|
|
165
|
+
name,
|
|
166
|
+
decimals,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
return balances;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
parseTransactionTransfer({ amount, currency: { tokenType, address, decimals, name, symbol }, entityId, sender, receiver, }) {
|
|
174
|
+
if (tokenType === 'ERC721') {
|
|
175
|
+
return {
|
|
176
|
+
from: sender.address,
|
|
177
|
+
to: receiver.address,
|
|
178
|
+
tokenId: entityId,
|
|
179
|
+
contractHash: address,
|
|
180
|
+
type: 'nft',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
from: sender.address,
|
|
185
|
+
to: receiver.address,
|
|
186
|
+
contractHash: address,
|
|
187
|
+
amount: amount.toString(),
|
|
188
|
+
token: {
|
|
189
|
+
decimals: decimals,
|
|
190
|
+
hash: address,
|
|
191
|
+
name: name,
|
|
192
|
+
symbol: symbol,
|
|
193
|
+
},
|
|
194
|
+
type: 'token',
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
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
|
|
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 }: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
6
|
+
getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
|
|
7
|
+
private treatGhostMarketImage;
|
|
8
|
+
private getUrlWithParams;
|
|
9
|
+
private parse;
|
|
10
|
+
}
|