@cityofzion/bs-ethereum 2.2.5 → 2.2.7
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
CHANGED
|
@@ -157,21 +157,21 @@ class BSEthereum {
|
|
|
157
157
|
}
|
|
158
158
|
const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
159
159
|
const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
|
|
160
|
-
|
|
160
|
+
const gasPrice = yield provider.getGasPrice();
|
|
161
|
+
let transactionParams = {
|
|
162
|
+
gasPrice,
|
|
163
|
+
};
|
|
161
164
|
const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
|
|
162
165
|
if (isNative) {
|
|
163
|
-
|
|
164
|
-
transactionParams =
|
|
165
|
-
to: param.intent.receiverAddress,
|
|
166
|
-
value: amount,
|
|
167
|
-
gasPrice,
|
|
168
|
-
};
|
|
166
|
+
transactionParams.to = param.intent.receiverAddress;
|
|
167
|
+
transactionParams.value = amount;
|
|
169
168
|
}
|
|
170
169
|
else {
|
|
171
170
|
const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, [
|
|
172
171
|
'function transfer(address to, uint amount) returns (bool)',
|
|
173
172
|
]);
|
|
174
|
-
|
|
173
|
+
const populatedTransaction = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
|
|
174
|
+
transactionParams = Object.assign(Object.assign({}, populatedTransaction), transactionParams);
|
|
175
175
|
}
|
|
176
176
|
const transaction = yield signer.sendTransaction(transactionParams);
|
|
177
177
|
return transaction.hash;
|
|
@@ -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,43 @@ 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
|
+
console.log(error);
|
|
157
|
+
/* empty */
|
|
158
|
+
}
|
|
159
|
+
}
|
|
90
160
|
transactions.push({
|
|
91
161
|
block: item.block,
|
|
92
162
|
hash: item.hash,
|
|
@@ -95,7 +165,8 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
95
165
|
notifications: [],
|
|
96
166
|
transfers,
|
|
97
167
|
});
|
|
98
|
-
});
|
|
168
|
+
}));
|
|
169
|
+
yield Promise.allSettled(promises);
|
|
99
170
|
return {
|
|
100
171
|
transactions,
|
|
101
172
|
nextPageParams: data.next_page_params,
|
|
@@ -161,8 +232,11 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
161
232
|
if (!data || 'message' in data) {
|
|
162
233
|
throw new Error('Token not found');
|
|
163
234
|
}
|
|
235
|
+
if (data.type !== 'ERC-20') {
|
|
236
|
+
throw new Error('Token is not an ERC-20 token');
|
|
237
|
+
}
|
|
164
238
|
return {
|
|
165
|
-
decimals: parseInt(data.decimals),
|
|
239
|
+
decimals: data.decimals ? parseInt(data.decimals) : BSEthereumHelper_1.BSEthereumHelper.DEFAULT_DECIMALS,
|
|
166
240
|
hash: tokenHash,
|
|
167
241
|
name: data.name,
|
|
168
242
|
symbol: data.symbol,
|
|
@@ -182,10 +256,11 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
182
256
|
if (!nativeBalance || 'message' in nativeBalance) {
|
|
183
257
|
throw new Error('Native balance not found');
|
|
184
258
|
}
|
|
259
|
+
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
|
|
185
260
|
const balances = [
|
|
186
261
|
{
|
|
187
|
-
amount: ethers_1.ethers.utils.formatUnits(nativeBalance.coin_balance,
|
|
188
|
-
token:
|
|
262
|
+
amount: ethers_1.ethers.utils.formatUnits(nativeBalance.coin_balance, nativeToken.decimals),
|
|
263
|
+
token: nativeToken,
|
|
189
264
|
},
|
|
190
265
|
];
|
|
191
266
|
const { data: erc20Balances } = yield client.get(`/addresses/${address}/token-balances`);
|
|
@@ -193,16 +268,24 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
193
268
|
throw new Error('ERC20 balance not found');
|
|
194
269
|
}
|
|
195
270
|
erc20Balances.forEach(balance => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
271
|
+
try {
|
|
272
|
+
if (balance.token.type !== 'ERC-20') {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const token = {
|
|
276
|
+
decimals: balance.token.decimals ? parseInt(balance.token.decimals) : BSEthereumHelper_1.BSEthereumHelper.DEFAULT_DECIMALS,
|
|
277
|
+
hash: balance.token.address,
|
|
278
|
+
name: balance.token.symbol,
|
|
279
|
+
symbol: balance.token.symbol,
|
|
280
|
+
};
|
|
281
|
+
balances.push({
|
|
282
|
+
amount: ethers_1.ethers.utils.formatUnits(balance.value, token.decimals),
|
|
283
|
+
token,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (_a) {
|
|
287
|
+
/* empty */
|
|
288
|
+
}
|
|
206
289
|
});
|
|
207
290
|
return balances;
|
|
208
291
|
});
|
|
@@ -225,51 +308,6 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
225
308
|
}
|
|
226
309
|
}
|
|
227
310
|
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
311
|
BlockscoutNeoXBDSEthereum.BASE_URL_BY_CHAIN_ID = {
|
|
274
312
|
'12227332': 'https://dora-stage.coz.io/api/neox/testnet',
|
|
275
313
|
'47763': 'https://dora.coz.io/api/neox/mainnet',
|