@cityofzion/bs-ethereum 2.2.6 → 2.2.8
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.
|
@@ -2,6 +2,7 @@ import { Network, NetworkId } from '@cityofzion/blockchain-service';
|
|
|
2
2
|
export type BSEthereumNetworkId = NetworkId<'1' | '10' | '25' | '56' | '137' | '250' | '1101' | '8453' | '80002' | '42161' | '42220' | '43114' | '59144' | '11155111' | '47763' | '12227332'>;
|
|
3
3
|
export declare class BSEthereumHelper {
|
|
4
4
|
#private;
|
|
5
|
+
static DEFAULT_DECIMALS: number;
|
|
5
6
|
static DERIVATION_PATH: string;
|
|
6
7
|
static DEFAULT_PATH: string;
|
|
7
8
|
static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId;
|
package/dist/BSEthereumHelper.js
CHANGED
|
@@ -2,7 +2,6 @@ import { BalanceResponse, ContractResponse, Network, Token, TransactionResponse,
|
|
|
2
2
|
import { RpcBDSEthereum } from './RpcBDSEthereum';
|
|
3
3
|
import { BSEthereumNetworkId } from './BSEthereumHelper';
|
|
4
4
|
export declare class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum {
|
|
5
|
-
#private;
|
|
6
5
|
static BASE_URL_BY_CHAIN_ID: Partial<Record<BSEthereumNetworkId, string>>;
|
|
7
6
|
static isSupported(network: Network<BSEthereumNetworkId>): boolean;
|
|
8
7
|
static getClient(network: Network<BSEthereumNetworkId>): import("axios").AxiosInstance;
|
|
@@ -8,21 +8,16 @@ 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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
-
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");
|
|
14
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
-
};
|
|
16
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
13
|
};
|
|
19
|
-
var _BlockscoutNeoXBDSEthereum_instances, _BlockscoutNeoXBDSEthereum_parseTransfers;
|
|
20
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
15
|
exports.BlockscoutNeoXBDSEthereum = void 0;
|
|
22
16
|
const axios_1 = __importDefault(require("axios"));
|
|
23
17
|
const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
|
|
24
18
|
const BSEthereumHelper_1 = require("./BSEthereumHelper");
|
|
25
19
|
const ethers_1 = require("ethers");
|
|
20
|
+
const ERC20_1 = require("./assets/abis/ERC20");
|
|
26
21
|
class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
27
22
|
static isSupported(network) {
|
|
28
23
|
return !!BlockscoutNeoXBDSEthereum.BASE_URL_BY_CHAIN_ID[network.id];
|
|
@@ -38,7 +33,6 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
38
33
|
}
|
|
39
34
|
constructor(network) {
|
|
40
35
|
super(network);
|
|
41
|
-
_BlockscoutNeoXBDSEthereum_instances.add(this);
|
|
42
36
|
this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5;
|
|
43
37
|
}
|
|
44
38
|
getTransaction(txid) {
|
|
@@ -55,7 +49,48 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
55
49
|
throw new Error('Transaction not found');
|
|
56
50
|
}
|
|
57
51
|
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
58
|
-
const transfers =
|
|
52
|
+
const transfers = [];
|
|
53
|
+
const hasNativeTokenBeingTransferred = data.value !== '0';
|
|
54
|
+
if (hasNativeTokenBeingTransferred) {
|
|
55
|
+
transfers.push({
|
|
56
|
+
amount: ethers_1.ethers.utils.formatUnits(data.value, nativeToken.decimals),
|
|
57
|
+
from: data.from.hash,
|
|
58
|
+
to: data.to.hash,
|
|
59
|
+
type: 'token',
|
|
60
|
+
contractHash: nativeToken.hash,
|
|
61
|
+
token: nativeToken,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const hasTokenTransfers = data.token_transfers && data.token_transfers.length > 0;
|
|
65
|
+
if (hasTokenTransfers) {
|
|
66
|
+
for (const tokenTransfer of data.token_transfers) {
|
|
67
|
+
if (tokenTransfer.token.type === 'ERC-20') {
|
|
68
|
+
transfers.push({
|
|
69
|
+
amount: ethers_1.ethers.utils.formatUnits(tokenTransfer.total.value, tokenTransfer.total.decimals),
|
|
70
|
+
from: tokenTransfer.from.hash,
|
|
71
|
+
to: tokenTransfer.to.hash,
|
|
72
|
+
type: 'token',
|
|
73
|
+
contractHash: tokenTransfer.token.address,
|
|
74
|
+
token: {
|
|
75
|
+
symbol: tokenTransfer.token.symbol,
|
|
76
|
+
name: tokenTransfer.token.name,
|
|
77
|
+
hash: tokenTransfer.token.address,
|
|
78
|
+
decimals: Number(tokenTransfer.total.decimals),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (tokenTransfer.token.type === 'ERC-721') {
|
|
84
|
+
transfers.push({
|
|
85
|
+
tokenId: tokenTransfer.total.token_id,
|
|
86
|
+
from: tokenTransfer.from.hash,
|
|
87
|
+
to: tokenTransfer.to.hash,
|
|
88
|
+
type: 'nft',
|
|
89
|
+
contractHash: tokenTransfer.token.address,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
59
94
|
return {
|
|
60
95
|
block: data.block,
|
|
61
96
|
hash: data.hash,
|
|
@@ -85,8 +120,42 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
85
120
|
}
|
|
86
121
|
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
87
122
|
const transactions = [];
|
|
88
|
-
data.items.
|
|
89
|
-
const transfers =
|
|
123
|
+
const promises = data.items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const transfers = [];
|
|
125
|
+
const hasNativeTokenBeingTransferred = item.value !== '0';
|
|
126
|
+
if (hasNativeTokenBeingTransferred) {
|
|
127
|
+
transfers.push({
|
|
128
|
+
amount: ethers_1.ethers.utils.formatUnits(item.value, nativeToken.decimals),
|
|
129
|
+
from: item.from.hash,
|
|
130
|
+
to: item.to.hash,
|
|
131
|
+
type: 'token',
|
|
132
|
+
contractHash: nativeToken.hash,
|
|
133
|
+
token: nativeToken,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (item.raw_input) {
|
|
137
|
+
try {
|
|
138
|
+
const ERC20Interface = new ethers_1.ethers.utils.Interface(ERC20_1.ERC20_ABI);
|
|
139
|
+
const result = ERC20Interface.decodeFunctionData('transfer', item.raw_input);
|
|
140
|
+
if (!result)
|
|
141
|
+
throw new Error('Invalid ERC20 transfer');
|
|
142
|
+
const contractHash = item.to.hash;
|
|
143
|
+
const token = yield this.getTokenInfo(contractHash);
|
|
144
|
+
const to = result[0];
|
|
145
|
+
const value = result[1];
|
|
146
|
+
transfers.push({
|
|
147
|
+
amount: ethers_1.ethers.utils.formatUnits(value, token.decimals),
|
|
148
|
+
from: item.from.hash,
|
|
149
|
+
to,
|
|
150
|
+
type: 'token',
|
|
151
|
+
contractHash: item.to.hash,
|
|
152
|
+
token,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
/* empty */
|
|
157
|
+
}
|
|
158
|
+
}
|
|
90
159
|
transactions.push({
|
|
91
160
|
block: item.block,
|
|
92
161
|
hash: item.hash,
|
|
@@ -95,7 +164,8 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
95
164
|
notifications: [],
|
|
96
165
|
transfers,
|
|
97
166
|
});
|
|
98
|
-
});
|
|
167
|
+
}));
|
|
168
|
+
yield Promise.allSettled(promises);
|
|
99
169
|
return {
|
|
100
170
|
transactions,
|
|
101
171
|
nextPageParams: data.next_page_params,
|
|
@@ -161,8 +231,11 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
161
231
|
if (!data || 'message' in data) {
|
|
162
232
|
throw new Error('Token not found');
|
|
163
233
|
}
|
|
234
|
+
if (data.type !== 'ERC-20') {
|
|
235
|
+
throw new Error('Token is not an ERC-20 token');
|
|
236
|
+
}
|
|
164
237
|
return {
|
|
165
|
-
decimals: parseInt(data.decimals),
|
|
238
|
+
decimals: data.decimals ? parseInt(data.decimals) : BSEthereumHelper_1.BSEthereumHelper.DEFAULT_DECIMALS,
|
|
166
239
|
hash: tokenHash,
|
|
167
240
|
name: data.name,
|
|
168
241
|
symbol: data.symbol,
|
|
@@ -182,10 +255,11 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
182
255
|
if (!nativeBalance || 'message' in nativeBalance) {
|
|
183
256
|
throw new Error('Native balance not found');
|
|
184
257
|
}
|
|
258
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
185
259
|
const balances = [
|
|
186
260
|
{
|
|
187
|
-
amount: ethers_1.ethers.utils.formatUnits(nativeBalance.coin_balance,
|
|
188
|
-
token:
|
|
261
|
+
amount: ethers_1.ethers.utils.formatUnits(nativeBalance.coin_balance, nativeToken.decimals),
|
|
262
|
+
token: nativeToken,
|
|
189
263
|
},
|
|
190
264
|
];
|
|
191
265
|
const { data: erc20Balances } = yield client.get(`/addresses/${address}/token-balances`);
|
|
@@ -193,16 +267,24 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
193
267
|
throw new Error('ERC20 balance not found');
|
|
194
268
|
}
|
|
195
269
|
erc20Balances.forEach(balance => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
270
|
+
try {
|
|
271
|
+
if (balance.token.type !== 'ERC-20') {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const token = {
|
|
275
|
+
decimals: balance.token.decimals ? parseInt(balance.token.decimals) : BSEthereumHelper_1.BSEthereumHelper.DEFAULT_DECIMALS,
|
|
276
|
+
hash: balance.token.address,
|
|
277
|
+
name: balance.token.symbol,
|
|
278
|
+
symbol: balance.token.symbol,
|
|
279
|
+
};
|
|
280
|
+
balances.push({
|
|
281
|
+
amount: ethers_1.ethers.utils.formatUnits(balance.value, token.decimals),
|
|
282
|
+
token,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
catch (_a) {
|
|
286
|
+
/* empty */
|
|
287
|
+
}
|
|
206
288
|
});
|
|
207
289
|
return balances;
|
|
208
290
|
});
|
|
@@ -225,51 +307,6 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
225
307
|
}
|
|
226
308
|
}
|
|
227
309
|
exports.BlockscoutNeoXBDSEthereum = BlockscoutNeoXBDSEthereum;
|
|
228
|
-
_BlockscoutNeoXBDSEthereum_instances = new WeakSet(), _BlockscoutNeoXBDSEthereum_parseTransfers = function _BlockscoutNeoXBDSEthereum_parseTransfers(item, nativeToken) {
|
|
229
|
-
const transfers = [];
|
|
230
|
-
const hasNativeTokenBeingTransferred = item.value !== '0';
|
|
231
|
-
if (hasNativeTokenBeingTransferred) {
|
|
232
|
-
transfers.push({
|
|
233
|
-
amount: ethers_1.ethers.utils.formatUnits(item.value, nativeToken.decimals),
|
|
234
|
-
from: item.from.hash,
|
|
235
|
-
to: item.to.hash,
|
|
236
|
-
type: 'token',
|
|
237
|
-
contractHash: nativeToken.hash,
|
|
238
|
-
token: nativeToken,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
const hasTokenTransfers = item.token_transfers && item.token_transfers.length > 0;
|
|
242
|
-
if (hasTokenTransfers) {
|
|
243
|
-
for (const tokenTransfer of item.token_transfers) {
|
|
244
|
-
if (tokenTransfer.token.type === 'ERC-20') {
|
|
245
|
-
transfers.push({
|
|
246
|
-
amount: ethers_1.ethers.utils.formatUnits(tokenTransfer.total.value, tokenTransfer.total.decimals),
|
|
247
|
-
from: tokenTransfer.from.hash,
|
|
248
|
-
to: tokenTransfer.to.hash,
|
|
249
|
-
type: 'token',
|
|
250
|
-
contractHash: tokenTransfer.token.address,
|
|
251
|
-
token: {
|
|
252
|
-
symbol: tokenTransfer.token.symbol,
|
|
253
|
-
name: tokenTransfer.token.name,
|
|
254
|
-
hash: tokenTransfer.token.address,
|
|
255
|
-
decimals: Number(tokenTransfer.total.decimals),
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
if (tokenTransfer.token.type === 'ERC-721') {
|
|
261
|
-
transfers.push({
|
|
262
|
-
tokenId: tokenTransfer.total.token_id,
|
|
263
|
-
from: tokenTransfer.from.hash,
|
|
264
|
-
to: tokenTransfer.to.hash,
|
|
265
|
-
type: 'nft',
|
|
266
|
-
contractHash: tokenTransfer.token.address,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return transfers;
|
|
272
|
-
};
|
|
273
310
|
BlockscoutNeoXBDSEthereum.BASE_URL_BY_CHAIN_ID = {
|
|
274
311
|
'12227332': 'https://dora-stage.coz.io/api/neox/testnet',
|
|
275
312
|
'47763': 'https://dora.coz.io/api/neox/mainnet',
|