@cityofzion/bs-ethereum 2.0.3 → 2.1.0
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/dist/BSEthereum.js +4 -6
- package/dist/MoralisBDSEthereum.d.ts +15 -0
- package/dist/MoralisBDSEthereum.js +323 -0
- package/dist/MoralisEDSEthereum.d.ts +8 -0
- package/dist/MoralisEDSEthereum.js +139 -0
- package/dist/RpcBDSEthereum.d.ts +3 -2
- package/dist/RpcBDSEthereum.js +17 -25
- package/dist/assets/abis/ERC271.d.ts +44 -0
- package/dist/assets/abis/ERC271.js +349 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +2 -4
- package/dist/BitqueryBDSEthereum.d.ts +0 -15
- package/dist/BitqueryBDSEthereum.js +0 -228
- package/dist/BitqueryEDSEthereum.d.ts +0 -9
- package/dist/BitqueryEDSEthereum.js +0 -90
package/dist/BSEthereum.js
CHANGED
|
@@ -43,12 +43,11 @@ const ethers_1 = require("ethers");
|
|
|
43
43
|
const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
|
|
44
44
|
const ethersBytes = __importStar(require("@ethersproject/bytes"));
|
|
45
45
|
const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
|
|
46
|
-
const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
|
|
47
46
|
const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
|
|
48
|
-
const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
|
|
49
|
-
const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
|
|
50
47
|
const EthersLedgerServiceEthereum_1 = require("./EthersLedgerServiceEthereum");
|
|
51
48
|
const BSEthereumHelper_1 = require("./BSEthereumHelper");
|
|
49
|
+
const MoralisBDSEthereum_1 = require("./MoralisBDSEthereum");
|
|
50
|
+
const MoralisEDSEthereum_1 = require("./MoralisEDSEthereum");
|
|
52
51
|
class BSEthereum {
|
|
53
52
|
constructor(blockchainName, network, getLedgerTransport) {
|
|
54
53
|
_BSEthereum_instances.add(this);
|
|
@@ -61,9 +60,8 @@ class BSEthereum {
|
|
|
61
60
|
setNetwork(network) {
|
|
62
61
|
__classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_setTokens).call(this, network);
|
|
63
62
|
this.network = network;
|
|
64
|
-
|
|
65
|
-
this.
|
|
66
|
-
this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network, this.tokens);
|
|
63
|
+
this.blockchainDataService = new MoralisBDSEthereum_1.MoralisBDSEthereum(network);
|
|
64
|
+
this.exchangeDataService = new MoralisEDSEthereum_1.MoralisEDSEthereum(network, this.blockchainDataService);
|
|
67
65
|
this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network);
|
|
68
66
|
}
|
|
69
67
|
validateAddress(address) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BalanceResponse, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { RpcBDSEthereum } from './RpcBDSEthereum';
|
|
3
|
+
import { BSEthereumNetworkId } from './BSEthereumHelper';
|
|
4
|
+
export declare class MoralisBDSEthereum extends RpcBDSEthereum {
|
|
5
|
+
static BASE_URL: string;
|
|
6
|
+
static SUPPORTED_CHAINS: string[];
|
|
7
|
+
static getClient(network: Network<BSEthereumNetworkId>): import("axios").AxiosInstance;
|
|
8
|
+
static isSupported(network: Network<BSEthereumNetworkId>): boolean;
|
|
9
|
+
constructor(network: Network<BSEthereumNetworkId>);
|
|
10
|
+
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
11
|
+
getTokenInfo(hash: string): Promise<Token>;
|
|
12
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
13
|
+
getTransactionsByAddress(params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
14
|
+
getContract(hash: string): Promise<ContractResponse>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
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.MoralisBDSEthereum = void 0;
|
|
16
|
+
const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
|
|
17
|
+
const BSEthereumHelper_1 = require("./BSEthereumHelper");
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const ethers_1 = require("ethers");
|
|
20
|
+
const ERC20_1 = require("./assets/abis/ERC20");
|
|
21
|
+
class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
22
|
+
static getClient(network) {
|
|
23
|
+
return axios_1.default.create({
|
|
24
|
+
baseURL: MoralisBDSEthereum.BASE_URL,
|
|
25
|
+
params: {
|
|
26
|
+
chain: `0x${Number(network.id).toString(16)}`,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static isSupported(network) {
|
|
31
|
+
return MoralisBDSEthereum.SUPPORTED_CHAINS.includes(network.id);
|
|
32
|
+
}
|
|
33
|
+
constructor(network) {
|
|
34
|
+
super(network);
|
|
35
|
+
}
|
|
36
|
+
getBalance(address) {
|
|
37
|
+
const _super = Object.create(null, {
|
|
38
|
+
getBalance: { get: () => super.getBalance }
|
|
39
|
+
});
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (!MoralisBDSEthereum.isSupported(this._network)) {
|
|
42
|
+
return _super.getBalance.call(this, address);
|
|
43
|
+
}
|
|
44
|
+
const client = MoralisBDSEthereum.getClient(this._network);
|
|
45
|
+
const { data: { balance: nativeBalance }, } = yield client.get(`${address}/balance`);
|
|
46
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
47
|
+
const balances = [
|
|
48
|
+
{
|
|
49
|
+
amount: nativeBalance,
|
|
50
|
+
token: nativeToken,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
const { data: erc20Balances } = yield client.get(`${address}/erc20`);
|
|
54
|
+
erc20Balances.forEach(balance => {
|
|
55
|
+
if (balance.possible_spam)
|
|
56
|
+
return;
|
|
57
|
+
balances.push({
|
|
58
|
+
amount: balance.balance,
|
|
59
|
+
token: {
|
|
60
|
+
decimals: balance.decimals,
|
|
61
|
+
hash: balance.token_address,
|
|
62
|
+
name: balance.name,
|
|
63
|
+
symbol: balance.symbol,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
return balances;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getTokenInfo(hash) {
|
|
71
|
+
const _super = Object.create(null, {
|
|
72
|
+
getTokenInfo: { get: () => super.getTokenInfo }
|
|
73
|
+
});
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
if (!MoralisBDSEthereum.isSupported(this._network)) {
|
|
76
|
+
return _super.getTokenInfo.call(this, hash);
|
|
77
|
+
}
|
|
78
|
+
const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
79
|
+
if (nativeAsset.hash === hash)
|
|
80
|
+
return nativeAsset;
|
|
81
|
+
if (this._tokenCache.has(hash)) {
|
|
82
|
+
return this._tokenCache.get(hash);
|
|
83
|
+
}
|
|
84
|
+
const client = MoralisBDSEthereum.getClient(this._network);
|
|
85
|
+
const response = yield client.get(`/erc20/metadata`, {
|
|
86
|
+
params: {
|
|
87
|
+
addresses: [hash],
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const data = response.data[0];
|
|
91
|
+
const token = {
|
|
92
|
+
decimals: Number(data.decimals),
|
|
93
|
+
symbol: data.symbol,
|
|
94
|
+
hash,
|
|
95
|
+
name: data.name,
|
|
96
|
+
};
|
|
97
|
+
this._tokenCache.set(hash, token);
|
|
98
|
+
return token;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getTransaction(hash) {
|
|
102
|
+
const _super = Object.create(null, {
|
|
103
|
+
getTransaction: { get: () => super.getTransaction }
|
|
104
|
+
});
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
if (!MoralisBDSEthereum.isSupported(this._network)) {
|
|
107
|
+
return _super.getTransaction.call(this, hash);
|
|
108
|
+
}
|
|
109
|
+
const client = MoralisBDSEthereum.getClient(this._network);
|
|
110
|
+
const { data } = yield client.get(`/transaction/${hash}/verbose`);
|
|
111
|
+
const transfers = [];
|
|
112
|
+
if (data.value && Number(data.value) > 0) {
|
|
113
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
114
|
+
transfers.push({
|
|
115
|
+
amount: data.value,
|
|
116
|
+
from: data.from_address,
|
|
117
|
+
to: data.to_address,
|
|
118
|
+
type: 'token',
|
|
119
|
+
token: nativeToken,
|
|
120
|
+
contractHash: nativeToken.hash,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (data.logs) {
|
|
124
|
+
const promises = data.logs.map((log) => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a, _b, _c, _d;
|
|
126
|
+
if (!log.decoded_event)
|
|
127
|
+
return;
|
|
128
|
+
if (log.decoded_event.label.toLowerCase() !== 'transfer')
|
|
129
|
+
return;
|
|
130
|
+
const contractHash = log.address;
|
|
131
|
+
const amount = (_a = log.decoded_event.params.find((param) => param.name === 'value')) === null || _a === void 0 ? void 0 : _a.value;
|
|
132
|
+
const from = (_b = log.decoded_event.params.find((param) => param.name === 'from')) === null || _b === void 0 ? void 0 : _b.value;
|
|
133
|
+
const to = (_c = log.decoded_event.params.find((param) => param.name === 'to')) === null || _c === void 0 ? void 0 : _c.value;
|
|
134
|
+
if (!from || !to)
|
|
135
|
+
return;
|
|
136
|
+
if (amount) {
|
|
137
|
+
const token = yield this.getTokenInfo(contractHash);
|
|
138
|
+
transfers.push({
|
|
139
|
+
contractHash,
|
|
140
|
+
amount: ethers_1.ethers.utils.formatUnits(amount, token.decimals),
|
|
141
|
+
from,
|
|
142
|
+
to,
|
|
143
|
+
type: 'token',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const tokenId = (_d = log.decoded_event.params.find((param) => param.name === 'tokenId')) === null || _d === void 0 ? void 0 : _d.value;
|
|
147
|
+
if (!tokenId)
|
|
148
|
+
return;
|
|
149
|
+
transfers.push({
|
|
150
|
+
contractHash,
|
|
151
|
+
tokenId,
|
|
152
|
+
from,
|
|
153
|
+
to,
|
|
154
|
+
type: 'nft',
|
|
155
|
+
});
|
|
156
|
+
}));
|
|
157
|
+
yield Promise.allSettled(promises);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
block: Number(data.block_number),
|
|
161
|
+
hash,
|
|
162
|
+
notifications: [],
|
|
163
|
+
time: new Date(data.block_timestamp).getTime(),
|
|
164
|
+
transfers,
|
|
165
|
+
fee: data.transaction_fee,
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
getTransactionsByAddress(params) {
|
|
170
|
+
const _super = Object.create(null, {
|
|
171
|
+
getTransactionsByAddress: { get: () => super.getTransactionsByAddress }
|
|
172
|
+
});
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
if (!MoralisBDSEthereum.isSupported(this._network)) {
|
|
175
|
+
return _super.getTransactionsByAddress.call(this, params);
|
|
176
|
+
}
|
|
177
|
+
const client = MoralisBDSEthereum.getClient(this._network);
|
|
178
|
+
const { data } = yield client.get(`/wallets/${params.address}/history`, {
|
|
179
|
+
params: {
|
|
180
|
+
limit: 15,
|
|
181
|
+
cursor: params.cursor,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
const transactions = [];
|
|
185
|
+
const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
186
|
+
const promises = data.result.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const transfers = [];
|
|
188
|
+
item.native_transfers.forEach(transfer => {
|
|
189
|
+
transfers.push({
|
|
190
|
+
amount: ethers_1.ethers.utils.formatUnits(transfer.value, nativeAsset.decimals),
|
|
191
|
+
from: transfer.from_address,
|
|
192
|
+
to: transfer.to_address,
|
|
193
|
+
type: 'token',
|
|
194
|
+
token: nativeAsset,
|
|
195
|
+
contractHash: nativeAsset.hash,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
item.erc20_transfers.forEach(transfer => {
|
|
199
|
+
if (transfer.possible_spam)
|
|
200
|
+
return;
|
|
201
|
+
transfers.push({
|
|
202
|
+
amount: ethers_1.ethers.utils.formatUnits(transfer.value, transfer.token_decimals),
|
|
203
|
+
from: transfer.from_address,
|
|
204
|
+
to: transfer.to_address,
|
|
205
|
+
type: 'token',
|
|
206
|
+
token: {
|
|
207
|
+
decimals: Number(transfer.token_decimals),
|
|
208
|
+
hash: transfer.address,
|
|
209
|
+
name: transfer.token_name,
|
|
210
|
+
symbol: transfer.token_symbol,
|
|
211
|
+
},
|
|
212
|
+
contractHash: transfer.address,
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
item.nft_transfers.forEach(transfer => {
|
|
216
|
+
transfers.push({
|
|
217
|
+
contractHash: transfer.token_address,
|
|
218
|
+
tokenId: transfer.token_id,
|
|
219
|
+
from: transfer.from_address,
|
|
220
|
+
to: transfer.to_address,
|
|
221
|
+
type: 'nft',
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
transactions.push({
|
|
225
|
+
block: Number(item.block_number),
|
|
226
|
+
hash: item.hash,
|
|
227
|
+
notifications: [],
|
|
228
|
+
time: new Date(item.block_timestamp).getTime(),
|
|
229
|
+
transfers,
|
|
230
|
+
fee: item.transaction_fee,
|
|
231
|
+
});
|
|
232
|
+
}));
|
|
233
|
+
yield Promise.allSettled(promises);
|
|
234
|
+
return {
|
|
235
|
+
nextCursor: data.cursor,
|
|
236
|
+
transactions,
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
getContract(hash) {
|
|
241
|
+
const _super = Object.create(null, {
|
|
242
|
+
getContract: { get: () => super.getContract }
|
|
243
|
+
});
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
if (!MoralisBDSEthereum.isSupported(this._network)) {
|
|
246
|
+
return _super.getContract.call(this, hash);
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const client = MoralisBDSEthereum.getClient(this._network);
|
|
250
|
+
const { data } = yield client.get(`erc20/metadata`, {
|
|
251
|
+
params: {
|
|
252
|
+
addresses: [hash],
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
const methods = [];
|
|
256
|
+
ERC20_1.ERC20_ABI.forEach(abi => {
|
|
257
|
+
var _a, _b;
|
|
258
|
+
if (abi.type !== 'function')
|
|
259
|
+
return;
|
|
260
|
+
const parameters = (_a = abi.inputs) === null || _a === void 0 ? void 0 : _a.map(param => ({
|
|
261
|
+
name: param.name,
|
|
262
|
+
type: param.type,
|
|
263
|
+
}));
|
|
264
|
+
methods.push({
|
|
265
|
+
name: (_b = abi.name) !== null && _b !== void 0 ? _b : '',
|
|
266
|
+
parameters: parameters !== null && parameters !== void 0 ? parameters : [],
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
hash,
|
|
271
|
+
name: data[0].name,
|
|
272
|
+
methods,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
catch (_a) {
|
|
276
|
+
throw new Error('Contract not found or not an ERC20 token');
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.MoralisBDSEthereum = MoralisBDSEthereum;
|
|
282
|
+
MoralisBDSEthereum.BASE_URL = 'https://nxlrja2d1a.execute-api.us-east-1.amazonaws.com/production';
|
|
283
|
+
MoralisBDSEthereum.SUPPORTED_CHAINS = [
|
|
284
|
+
'1',
|
|
285
|
+
'11155111',
|
|
286
|
+
'17000',
|
|
287
|
+
'137',
|
|
288
|
+
'80002',
|
|
289
|
+
'56',
|
|
290
|
+
'97',
|
|
291
|
+
'42161',
|
|
292
|
+
'421614',
|
|
293
|
+
'8453',
|
|
294
|
+
'84532',
|
|
295
|
+
'10',
|
|
296
|
+
'11155420',
|
|
297
|
+
'59144',
|
|
298
|
+
'59141',
|
|
299
|
+
'43114',
|
|
300
|
+
'250',
|
|
301
|
+
'4002',
|
|
302
|
+
'25',
|
|
303
|
+
'11297108109',
|
|
304
|
+
'2020',
|
|
305
|
+
'100',
|
|
306
|
+
'10200',
|
|
307
|
+
'88888',
|
|
308
|
+
'88882',
|
|
309
|
+
'369',
|
|
310
|
+
'1284',
|
|
311
|
+
'1285',
|
|
312
|
+
'1287',
|
|
313
|
+
'81457',
|
|
314
|
+
'168587773',
|
|
315
|
+
'324',
|
|
316
|
+
'300',
|
|
317
|
+
'5000',
|
|
318
|
+
'5003',
|
|
319
|
+
'1101',
|
|
320
|
+
'2442',
|
|
321
|
+
'7000',
|
|
322
|
+
'7001',
|
|
323
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BlockchainDataService, CryptoCompareEDS, ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, Network, TokenPricesHistoryResponse, TokenPricesResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { BSEthereumNetworkId } from './BSEthereumHelper';
|
|
3
|
+
export declare class MoralisEDSEthereum extends CryptoCompareEDS implements ExchangeDataService {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(network: Network<BSEthereumNetworkId>, blockchainDataService: BlockchainDataService);
|
|
6
|
+
getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
7
|
+
getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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 __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 _MoralisEDSEthereum_instances, _MoralisEDSEthereum_network, _MoralisEDSEthereum_blockchainDataService, _MoralisEDSEthereum_numberOfBlockByHour, _MoralisEDSEthereum_numberOfBlockByDay, _MoralisEDSEthereum_getWrappedNativeToken;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.MoralisEDSEthereum = void 0;
|
|
25
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
26
|
+
const BSEthereumHelper_1 = require("./BSEthereumHelper");
|
|
27
|
+
const MoralisBDSEthereum_1 = require("./MoralisBDSEthereum");
|
|
28
|
+
class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
|
|
29
|
+
constructor(network, blockchainDataService) {
|
|
30
|
+
super();
|
|
31
|
+
_MoralisEDSEthereum_instances.add(this);
|
|
32
|
+
_MoralisEDSEthereum_network.set(this, void 0);
|
|
33
|
+
_MoralisEDSEthereum_blockchainDataService.set(this, void 0);
|
|
34
|
+
_MoralisEDSEthereum_numberOfBlockByHour.set(this, (15 / 60) * 60);
|
|
35
|
+
_MoralisEDSEthereum_numberOfBlockByDay.set(this, __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") * 24);
|
|
36
|
+
__classPrivateFieldSet(this, _MoralisEDSEthereum_network, network, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _MoralisEDSEthereum_blockchainDataService, blockchainDataService, "f");
|
|
38
|
+
}
|
|
39
|
+
getTokenPrices(params) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
|
|
42
|
+
throw new Error('Exchange is only available on mainnet');
|
|
43
|
+
if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
|
|
44
|
+
throw new Error('Exchange is not supported on this network');
|
|
45
|
+
const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
46
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
47
|
+
let wrappedNativeToken;
|
|
48
|
+
if (params.tokens.some(token => token.symbol === nativeToken.symbol)) {
|
|
49
|
+
wrappedNativeToken = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
|
|
50
|
+
}
|
|
51
|
+
const tokensBody = params.tokens.map(token => {
|
|
52
|
+
if (token.symbol !== nativeToken.symbol) {
|
|
53
|
+
return {
|
|
54
|
+
token_address: token.hash,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
token_address: wrappedNativeToken.hash,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
const { data } = yield client.post(`/erc20/prices`, {
|
|
62
|
+
tokens: tokensBody,
|
|
63
|
+
});
|
|
64
|
+
return data.map(item => {
|
|
65
|
+
let token;
|
|
66
|
+
if (item.tokenAddress === (wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash)) {
|
|
67
|
+
token = nativeToken;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
token = {
|
|
71
|
+
decimals: Number(item.tokenDecimals),
|
|
72
|
+
hash: item.tokenAddress,
|
|
73
|
+
name: item.tokenName,
|
|
74
|
+
symbol: item.tokenSymbol,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
usdPrice: item.usdPrice,
|
|
79
|
+
token,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
getTokenPriceHistory(params) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
if (!BSEthereumHelper_1.BSEthereumHelper.isMainnet(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
|
|
87
|
+
throw new Error('Exchange is only available on mainnet');
|
|
88
|
+
if (!MoralisBDSEthereum_1.MoralisBDSEthereum.isSupported(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f")))
|
|
89
|
+
throw new Error('Exchange is not supported on this network');
|
|
90
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
91
|
+
let token;
|
|
92
|
+
if (params.token.hash === nativeToken.hash) {
|
|
93
|
+
token = yield __classPrivateFieldGet(this, _MoralisEDSEthereum_instances, "m", _MoralisEDSEthereum_getWrappedNativeToken).call(this);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
token = params.token;
|
|
97
|
+
}
|
|
98
|
+
const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
99
|
+
const actualBlockNumber = (yield __classPrivateFieldGet(this, _MoralisEDSEthereum_blockchainDataService, "f").getBlockHeight()) - 1; // Last block is not included
|
|
100
|
+
const history = [];
|
|
101
|
+
yield Promise.allSettled(Array.from({ length: params.limit }).map((_, index) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const block = actualBlockNumber - index * (params.type === 'hour' ? __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") : __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByDay, "f"));
|
|
103
|
+
const priceResponse = yield client.get(`/erc20/${token.hash}/price`, {
|
|
104
|
+
params: {
|
|
105
|
+
to_block: block,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
const blockResponse = yield client.get(`/block/${block}`);
|
|
109
|
+
history.push({
|
|
110
|
+
timestamp: new Date(blockResponse.data.timestamp).getTime(),
|
|
111
|
+
usdPrice: priceResponse.data.usdPrice,
|
|
112
|
+
token: params.token,
|
|
113
|
+
});
|
|
114
|
+
})));
|
|
115
|
+
return history;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.MoralisEDSEthereum = MoralisEDSEthereum;
|
|
120
|
+
_MoralisEDSEthereum_network = new WeakMap(), _MoralisEDSEthereum_blockchainDataService = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByHour = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByDay = new WeakMap(), _MoralisEDSEthereum_instances = new WeakSet(), _MoralisEDSEthereum_getWrappedNativeToken = function _MoralisEDSEthereum_getWrappedNativeToken() {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
123
|
+
const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
124
|
+
const { data } = yield client.get('/erc20/metadata/symbols', {
|
|
125
|
+
params: {
|
|
126
|
+
symbols: [`W${nativeToken.symbol}`],
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
const wrapperToken = data.find(token => token.verified_contract && !token.possible_spam);
|
|
130
|
+
if (!wrapperToken)
|
|
131
|
+
throw new Error('Wrapper token not found');
|
|
132
|
+
return {
|
|
133
|
+
decimals: Number(wrapperToken.decimals),
|
|
134
|
+
hash: wrapperToken.address,
|
|
135
|
+
name: wrapperToken.name,
|
|
136
|
+
symbol: wrapperToken.symbol,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
};
|
package/dist/RpcBDSEthereum.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { BalanceResponse, BlockchainDataService, ContractResponse, Network, RpcResponse, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { BSEthereumNetworkId } from './BSEthereumHelper';
|
|
3
3
|
export declare class RpcBDSEthereum implements BlockchainDataService {
|
|
4
|
-
|
|
4
|
+
_network: Network<BSEthereumNetworkId>;
|
|
5
|
+
_tokenCache: Map<string, Token>;
|
|
5
6
|
maxTimeToConfirmTransactionInMs: number;
|
|
6
7
|
constructor(network: Network<BSEthereumNetworkId>);
|
|
7
8
|
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
8
9
|
getTransactionsByAddress(_params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
9
|
-
getContract(): Promise<ContractResponse>;
|
|
10
|
+
getContract(_hash: string): Promise<ContractResponse>;
|
|
10
11
|
getTokenInfo(hash: string): Promise<Token>;
|
|
11
12
|
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
12
13
|
getBlockHeight(): Promise<number>;
|
package/dist/RpcBDSEthereum.js
CHANGED
|
@@ -8,18 +8,6 @@ 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;
|
|
23
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
12
|
exports.RpcBDSEthereum = void 0;
|
|
25
13
|
const ethers_1 = require("ethers");
|
|
@@ -27,20 +15,20 @@ const ERC20_1 = require("./assets/abis/ERC20");
|
|
|
27
15
|
const BSEthereumHelper_1 = require("./BSEthereumHelper");
|
|
28
16
|
class RpcBDSEthereum {
|
|
29
17
|
constructor(network) {
|
|
30
|
-
|
|
18
|
+
this._tokenCache = new Map();
|
|
31
19
|
this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5;
|
|
32
|
-
|
|
20
|
+
this._network = network;
|
|
33
21
|
}
|
|
34
22
|
getTransaction(hash) {
|
|
35
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const provider = new ethers_1.ethers.providers.JsonRpcProvider(
|
|
24
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
|
|
37
25
|
const transaction = yield provider.getTransaction(hash);
|
|
38
26
|
if (!transaction || !transaction.blockHash || !transaction.to)
|
|
39
27
|
throw new Error('Transaction not found');
|
|
40
28
|
const block = yield provider.getBlock(transaction.blockHash);
|
|
41
29
|
if (!block)
|
|
42
30
|
throw new Error('Block not found');
|
|
43
|
-
const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(
|
|
31
|
+
const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
44
32
|
return {
|
|
45
33
|
block: block.number,
|
|
46
34
|
time: block.timestamp,
|
|
@@ -64,33 +52,38 @@ class RpcBDSEthereum {
|
|
|
64
52
|
throw new Error("RPC doesn't support get transactions history of address");
|
|
65
53
|
});
|
|
66
54
|
}
|
|
67
|
-
getContract() {
|
|
55
|
+
getContract(_hash) {
|
|
68
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
57
|
throw new Error("RPC doesn't support contract info");
|
|
70
58
|
});
|
|
71
59
|
}
|
|
72
60
|
getTokenInfo(hash) {
|
|
73
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(
|
|
62
|
+
const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
75
63
|
if (nativeAsset.hash === hash)
|
|
76
64
|
return nativeAsset;
|
|
77
|
-
|
|
65
|
+
if (this._tokenCache.has(hash)) {
|
|
66
|
+
return this._tokenCache.get(hash);
|
|
67
|
+
}
|
|
68
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
|
|
78
69
|
const contract = new ethers_1.ethers.Contract(hash, ERC20_1.ERC20_ABI, provider);
|
|
79
70
|
const decimals = yield contract.decimals();
|
|
80
71
|
const symbol = yield contract.symbol();
|
|
81
|
-
|
|
72
|
+
const token = {
|
|
82
73
|
decimals,
|
|
83
74
|
symbol,
|
|
84
75
|
hash,
|
|
85
76
|
name: symbol,
|
|
86
77
|
};
|
|
78
|
+
this._tokenCache.set(hash, token);
|
|
79
|
+
return token;
|
|
87
80
|
});
|
|
88
81
|
}
|
|
89
82
|
getBalance(address) {
|
|
90
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const provider = new ethers_1.ethers.providers.JsonRpcProvider(
|
|
84
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
|
|
92
85
|
const balance = yield provider.getBalance(address);
|
|
93
|
-
const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(
|
|
86
|
+
const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
94
87
|
return [
|
|
95
88
|
{
|
|
96
89
|
amount: ethers_1.ethers.utils.formatEther(balance),
|
|
@@ -101,14 +94,14 @@ class RpcBDSEthereum {
|
|
|
101
94
|
}
|
|
102
95
|
getBlockHeight() {
|
|
103
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
const provider = new ethers_1.ethers.providers.JsonRpcProvider(
|
|
97
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
|
|
105
98
|
return yield provider.getBlockNumber();
|
|
106
99
|
});
|
|
107
100
|
}
|
|
108
101
|
getRpcList() {
|
|
109
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
103
|
const list = [];
|
|
111
|
-
const urls = BSEthereumHelper_1.BSEthereumHelper.getRpcList(
|
|
104
|
+
const urls = BSEthereumHelper_1.BSEthereumHelper.getRpcList(this._network);
|
|
112
105
|
const promises = urls.map(url => {
|
|
113
106
|
// eslint-disable-next-line no-async-promise-executor
|
|
114
107
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -141,4 +134,3 @@ class RpcBDSEthereum {
|
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
136
|
exports.RpcBDSEthereum = RpcBDSEthereum;
|
|
144
|
-
_RpcBDSEthereum_network = new WeakMap();
|