@cityofzion/bs-ethereum 2.2.0 → 2.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.
- package/dist/MoralisBDSEthereum.js +3 -2
- package/dist/MoralisEDSEthereum.js +51 -38
- package/package.json +1 -1
|
@@ -52,14 +52,15 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
52
52
|
];
|
|
53
53
|
const { data: erc20Balances } = yield client.get(`${address}/erc20`);
|
|
54
54
|
erc20Balances.forEach(balance => {
|
|
55
|
-
|
|
55
|
+
var _a;
|
|
56
|
+
if (balance.possible_spam || !balance.decimals || !balance.token_address || !balance.symbol)
|
|
56
57
|
return;
|
|
57
58
|
balances.push({
|
|
58
59
|
amount: ethers_1.ethers.utils.formatUnits(balance.balance, balance.decimals),
|
|
59
60
|
token: {
|
|
60
61
|
decimals: balance.decimals,
|
|
61
62
|
hash: balance.token_address,
|
|
62
|
-
name: balance.name,
|
|
63
|
+
name: (_a = balance.name) !== null && _a !== void 0 ? _a : '',
|
|
63
64
|
symbol: balance.symbol,
|
|
64
65
|
},
|
|
65
66
|
});
|
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
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
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var _MoralisEDSEthereum_instances, _MoralisEDSEthereum_network, _MoralisEDSEthereum_blockchainDataService, _MoralisEDSEthereum_numberOfBlockByHour, _MoralisEDSEthereum_numberOfBlockByDay, _MoralisEDSEthereum_getWrappedNativeToken;
|
|
22
|
+
var _MoralisEDSEthereum_instances, _MoralisEDSEthereum_network, _MoralisEDSEthereum_blockchainDataService, _MoralisEDSEthereum_numberOfBlockByHour, _MoralisEDSEthereum_numberOfBlockByDay, _MoralisEDSEthereum_maxTokenPricesPerCall, _MoralisEDSEthereum_getWrappedNativeToken;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.MoralisEDSEthereum = void 0;
|
|
25
25
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
@@ -33,6 +33,7 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
|
|
|
33
33
|
_MoralisEDSEthereum_blockchainDataService.set(this, void 0);
|
|
34
34
|
_MoralisEDSEthereum_numberOfBlockByHour.set(this, (15 / 60) * 60);
|
|
35
35
|
_MoralisEDSEthereum_numberOfBlockByDay.set(this, __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") * 24);
|
|
36
|
+
_MoralisEDSEthereum_maxTokenPricesPerCall.set(this, 24);
|
|
36
37
|
__classPrivateFieldSet(this, _MoralisEDSEthereum_network, network, "f");
|
|
37
38
|
__classPrivateFieldSet(this, _MoralisEDSEthereum_blockchainDataService, blockchainDataService, "f");
|
|
38
39
|
}
|
|
@@ -58,29 +59,37 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
|
|
|
58
59
|
token_address: wrappedNativeToken.hash,
|
|
59
60
|
};
|
|
60
61
|
});
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
token
|
|
73
|
-
|
|
74
|
-
hash:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
const splitTokensBody = [];
|
|
63
|
+
for (let i = 0; i < tokensBody.length; i += __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")) {
|
|
64
|
+
splitTokensBody.push(tokensBody.slice(i, i + __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")));
|
|
65
|
+
}
|
|
66
|
+
const response = [];
|
|
67
|
+
yield Promise.allSettled(splitTokensBody.slice(0, 1).map((body) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { data } = yield client.post('/erc20/prices', {
|
|
69
|
+
tokens: body,
|
|
70
|
+
});
|
|
71
|
+
data.forEach(item => {
|
|
72
|
+
var _a;
|
|
73
|
+
let token;
|
|
74
|
+
if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(item.tokenAddress) ===
|
|
75
|
+
BSEthereumHelper_1.BSEthereumHelper.normalizeHash((_a = wrappedNativeToken === null || wrappedNativeToken === void 0 ? void 0 : wrappedNativeToken.hash) !== null && _a !== void 0 ? _a : '')) {
|
|
76
|
+
token = nativeToken;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
token = {
|
|
80
|
+
decimals: Number(item.tokenDecimals),
|
|
81
|
+
hash: item.tokenAddress,
|
|
82
|
+
name: item.tokenName,
|
|
83
|
+
symbol: item.tokenSymbol,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
response.push({
|
|
87
|
+
usdPrice: item.usdPrice,
|
|
88
|
+
token,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
})));
|
|
92
|
+
return response;
|
|
84
93
|
});
|
|
85
94
|
}
|
|
86
95
|
getTokenPriceHistory(params) {
|
|
@@ -98,20 +107,24 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
|
|
|
98
107
|
token = params.token;
|
|
99
108
|
}
|
|
100
109
|
const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
101
|
-
const
|
|
110
|
+
const currentBlockNumber = (yield __classPrivateFieldGet(this, _MoralisEDSEthereum_blockchainDataService, "f").getBlockHeight()) - 1; // Last block is not included
|
|
111
|
+
const tokensBody = Array.from({ length: params.limit }).map((_, index) => ({
|
|
112
|
+
token_address: token.hash,
|
|
113
|
+
to_block: currentBlockNumber - index * (params.type === 'hour' ? __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByHour, "f") : __classPrivateFieldGet(this, _MoralisEDSEthereum_numberOfBlockByDay, "f")),
|
|
114
|
+
}));
|
|
115
|
+
const splitTokensBody = [];
|
|
116
|
+
for (let i = 0; i < tokensBody.length; i += __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")) {
|
|
117
|
+
splitTokensBody.push(tokensBody.slice(i, i + __classPrivateFieldGet(this, _MoralisEDSEthereum_maxTokenPricesPerCall, "f")));
|
|
118
|
+
}
|
|
102
119
|
const history = [];
|
|
103
|
-
yield Promise.allSettled(
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
history.push({
|
|
112
|
-
timestamp: new Date(blockResponse.data.timestamp).getTime(),
|
|
113
|
-
usdPrice: priceResponse.data.usdPrice,
|
|
114
|
-
token: params.token,
|
|
120
|
+
yield Promise.allSettled(splitTokensBody.map((body) => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const priceResponse = yield client.post('/erc20/prices', { tokens: body });
|
|
122
|
+
priceResponse.data.forEach(item => {
|
|
123
|
+
history.push({
|
|
124
|
+
timestamp: Number(item.blockTimestamp),
|
|
125
|
+
usdPrice: item.usdPrice,
|
|
126
|
+
token: params.token,
|
|
127
|
+
});
|
|
115
128
|
});
|
|
116
129
|
})));
|
|
117
130
|
return history;
|
|
@@ -119,7 +132,7 @@ class MoralisEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
|
|
|
119
132
|
}
|
|
120
133
|
}
|
|
121
134
|
exports.MoralisEDSEthereum = MoralisEDSEthereum;
|
|
122
|
-
_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() {
|
|
135
|
+
_MoralisEDSEthereum_network = new WeakMap(), _MoralisEDSEthereum_blockchainDataService = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByHour = new WeakMap(), _MoralisEDSEthereum_numberOfBlockByDay = new WeakMap(), _MoralisEDSEthereum_maxTokenPricesPerCall = new WeakMap(), _MoralisEDSEthereum_instances = new WeakSet(), _MoralisEDSEthereum_getWrappedNativeToken = function _MoralisEDSEthereum_getWrappedNativeToken() {
|
|
123
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
137
|
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|
|
125
138
|
const client = MoralisBDSEthereum_1.MoralisBDSEthereum.getClient(__classPrivateFieldGet(this, _MoralisEDSEthereum_network, "f"));
|