@bitpay-labs/bitcore-wallet-service 11.11.0 → 11.11.2
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/Dockerfile +1 -1
- package/package.json +5 -5
- package/src/config.ts +0 -20
- package/src/externalservices/banxa.ts +51 -10
- package/src/externalservices/changelly.ts +54 -6
- package/src/externalservices/moonpay.ts +85 -19
- package/src/externalservices/oneInch.ts +13 -5
- package/src/externalservices/ramp.ts +42 -8
- package/src/externalservices/sardine.ts +51 -10
- package/src/externalservices/simplex.ts +58 -11
- package/src/externalservices/thorswap.ts +46 -11
- package/src/externalservices/transak.ts +53 -11
- package/src/lib/chain/btc/index.ts +3 -2
- package/src/lib/chain/eth/index.ts +134 -117
- package/src/lib/chain/sol/index.ts +1 -1
- package/src/lib/chain/xrp/index.ts +1 -1
- package/src/lib/routes/services.ts +0 -12
- package/src/lib/routes/wallets.ts +3 -1
- package/src/lib/server.ts +136 -91
- package/src/lib/storage.ts +90 -20
- package/src/types/externalservices.d.ts +0 -1
- package/test/chain/eth.test.ts +70 -0
- package/test/chain/sol.test.ts +1 -1
- package/test/chain/xrp.test.ts +1 -1
- package/test/expressapp.test.ts +144 -0
- package/test/integration/addressReads.test.ts +503 -0
- package/test/integration/bcmonitor.test.ts +44 -0
- package/test/integration/externalservices/banxa.test.ts +95 -5
- package/test/integration/externalservices/changelly.test.ts +118 -6
- package/test/integration/externalservices/coinGecko.test.ts +4 -0
- package/test/integration/externalservices/moonpay.test.ts +178 -9
- package/test/integration/externalservices/oneInch.test.ts +28 -1
- package/test/integration/externalservices/ramp.test.ts +126 -4
- package/test/integration/externalservices/sardine.test.ts +95 -5
- package/test/integration/externalservices/simplex.test.ts +95 -5
- package/test/integration/externalservices/thorswap.test.ts +81 -5
- package/test/integration/externalservices/transak.test.ts +98 -6
- package/test/integration/helpers.ts +1 -1
- package/test/integration/server.test.ts +254 -136
- package/test/integration/walletReads.test.ts +488 -0
- package/ts_build/package.json +3 -3
- package/ts_build/src/config.d.ts.map +1 -1
- package/ts_build/src/config.js +0 -4
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/externalservices/banxa.d.ts.map +1 -1
- package/ts_build/src/externalservices/banxa.js +51 -10
- package/ts_build/src/externalservices/banxa.js.map +1 -1
- package/ts_build/src/externalservices/changelly.d.ts.map +1 -1
- package/ts_build/src/externalservices/changelly.js +54 -6
- package/ts_build/src/externalservices/changelly.js.map +1 -1
- package/ts_build/src/externalservices/moonpay.d.ts.map +1 -1
- package/ts_build/src/externalservices/moonpay.js +85 -19
- package/ts_build/src/externalservices/moonpay.js.map +1 -1
- package/ts_build/src/externalservices/oneInch.d.ts.map +1 -1
- package/ts_build/src/externalservices/oneInch.js +13 -5
- package/ts_build/src/externalservices/oneInch.js.map +1 -1
- package/ts_build/src/externalservices/ramp.d.ts.map +1 -1
- package/ts_build/src/externalservices/ramp.js +42 -8
- package/ts_build/src/externalservices/ramp.js.map +1 -1
- package/ts_build/src/externalservices/sardine.d.ts.map +1 -1
- package/ts_build/src/externalservices/sardine.js +51 -10
- package/ts_build/src/externalservices/sardine.js.map +1 -1
- package/ts_build/src/externalservices/simplex.d.ts.map +1 -1
- package/ts_build/src/externalservices/simplex.js +55 -11
- package/ts_build/src/externalservices/simplex.js.map +1 -1
- package/ts_build/src/externalservices/thorswap.d.ts.map +1 -1
- package/ts_build/src/externalservices/thorswap.js +45 -11
- package/ts_build/src/externalservices/thorswap.js.map +1 -1
- package/ts_build/src/externalservices/transak.d.ts.map +1 -1
- package/ts_build/src/externalservices/transak.js +53 -11
- package/ts_build/src/externalservices/transak.js.map +1 -1
- package/ts_build/src/lib/chain/btc/index.d.ts.map +1 -1
- package/ts_build/src/lib/chain/btc/index.js +3 -2
- package/ts_build/src/lib/chain/btc/index.js.map +1 -1
- package/ts_build/src/lib/chain/eth/index.d.ts +8 -1
- package/ts_build/src/lib/chain/eth/index.d.ts.map +1 -1
- package/ts_build/src/lib/chain/eth/index.js +114 -102
- package/ts_build/src/lib/chain/eth/index.js.map +1 -1
- package/ts_build/src/lib/chain/sol/index.js +1 -1
- package/ts_build/src/lib/chain/sol/index.js.map +1 -1
- package/ts_build/src/lib/chain/xrp/index.js +1 -1
- package/ts_build/src/lib/chain/xrp/index.js.map +1 -1
- package/ts_build/src/lib/routes/services.d.ts.map +1 -1
- package/ts_build/src/lib/routes/services.js +0 -10
- package/ts_build/src/lib/routes/services.js.map +1 -1
- package/ts_build/src/lib/routes/wallets.d.ts.map +1 -1
- package/ts_build/src/lib/routes/wallets.js +2 -1
- package/ts_build/src/lib/routes/wallets.js.map +1 -1
- package/ts_build/src/lib/server.d.ts +1 -3
- package/ts_build/src/lib/server.d.ts.map +1 -1
- package/ts_build/src/lib/server.js +128 -96
- package/ts_build/src/lib/server.js.map +1 -1
- package/ts_build/src/lib/storage.d.ts +17 -10
- package/ts_build/src/lib/storage.d.ts.map +1 -1
- package/ts_build/src/lib/storage.js +73 -20
- package/ts_build/src/lib/storage.js.map +1 -1
- package/ts_build/test/chain/eth.test.js +59 -0
- package/ts_build/test/chain/eth.test.js.map +1 -1
- package/ts_build/test/chain/sol.test.js +1 -1
- package/ts_build/test/chain/sol.test.js.map +1 -1
- package/ts_build/test/chain/xrp.test.js +1 -1
- package/ts_build/test/chain/xrp.test.js.map +1 -1
- package/ts_build/test/expressapp.test.js +132 -0
- package/ts_build/test/expressapp.test.js.map +1 -1
- package/ts_build/test/integration/addressReads.test.d.ts +2 -0
- package/ts_build/test/integration/addressReads.test.d.ts.map +1 -0
- package/ts_build/test/integration/addressReads.test.js +465 -0
- package/ts_build/test/integration/addressReads.test.js.map +1 -0
- package/ts_build/test/integration/bcmonitor.test.js +40 -0
- package/ts_build/test/integration/bcmonitor.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/banxa.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/banxa.test.js +93 -5
- package/ts_build/test/integration/externalservices/banxa.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/changelly.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/changelly.test.js +111 -6
- package/ts_build/test/integration/externalservices/changelly.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/coinGecko.test.js +4 -0
- package/ts_build/test/integration/externalservices/coinGecko.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/moonpay.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/moonpay.test.js +169 -9
- package/ts_build/test/integration/externalservices/moonpay.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/oneInch.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/oneInch.test.js +26 -1
- package/ts_build/test/integration/externalservices/oneInch.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/ramp.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/ramp.test.js +115 -4
- package/ts_build/test/integration/externalservices/ramp.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/sardine.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/sardine.test.js +94 -5
- package/ts_build/test/integration/externalservices/sardine.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/simplex.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/simplex.test.js +89 -5
- package/ts_build/test/integration/externalservices/simplex.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/thorswap.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/thorswap.test.js +76 -5
- package/ts_build/test/integration/externalservices/thorswap.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/transak.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/transak.test.js +93 -6
- package/ts_build/test/integration/externalservices/transak.test.js.map +1 -1
- package/ts_build/test/integration/helpers.js +1 -1
- package/ts_build/test/integration/helpers.js.map +1 -1
- package/ts_build/test/integration/server.test.js +225 -124
- package/ts_build/test/integration/server.test.js.map +1 -1
- package/ts_build/test/integration/walletReads.test.d.ts +2 -0
- package/ts_build/test/integration/walletReads.test.d.ts.map +1 -0
- package/ts_build/test/integration/walletReads.test.js +436 -0
- package/ts_build/test/integration/walletReads.test.js.map +1 -0
- package/src/externalservices/wyre.ts +0 -131
- package/test/integration/externalservices/wyre.test.ts +0 -270
- package/ts_build/src/externalservices/wyre.d.ts +0 -7
- package/ts_build/src/externalservices/wyre.d.ts.map +0 -1
- package/ts_build/src/externalservices/wyre.js +0 -144
- package/ts_build/src/externalservices/wyre.js.map +0 -1
- package/ts_build/test/integration/externalservices/wyre.test.d.ts +0 -2
- package/ts_build/test/integration/externalservices/wyre.test.d.ts.map +0 -1
- package/ts_build/test/integration/externalservices/wyre.test.js +0 -281
- package/ts_build/test/integration/externalservices/wyre.test.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import util from 'util';
|
|
2
|
+
import { Constants as CWCConstants, Transactions, Utils, Validation, Web3 } from '@bitpay-labs/crypto-wallet-core';
|
|
2
3
|
import _ from 'lodash';
|
|
3
4
|
import { IWallet } from 'src/lib/model';
|
|
4
5
|
import { IAddress } from 'src/lib/model/address';
|
|
@@ -23,6 +24,9 @@ function requireUncached(module) {
|
|
|
23
24
|
return require(module);
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
// the effect type bitcore-node gives ERC20 transfers in tx events
|
|
28
|
+
const ERC20_TRANSFER_EFFECT = 'ERC20:transfer';
|
|
29
|
+
|
|
26
30
|
const Erc20Decoder = requireUncached('abi-decoder');
|
|
27
31
|
Erc20Decoder.addABI(ERC20Abi);
|
|
28
32
|
|
|
@@ -118,7 +122,7 @@ export class EthChain implements IChain {
|
|
|
118
122
|
// TODO support big int
|
|
119
123
|
const lockedSum = Number(amounts + fees) || 0; // previously set to 0 if opts.multisigContractAddress
|
|
120
124
|
const convertedBalance = this.convertBitcoreBalance(balance, lockedSum);
|
|
121
|
-
server.storage.
|
|
125
|
+
server.storage.fetchAddressesPage(server.walletId, { limit: 1 }, (err, addresses: IAddress[]) => {
|
|
122
126
|
if (err) return cb(err);
|
|
123
127
|
if (addresses.length > 0) {
|
|
124
128
|
const byAddress = [
|
|
@@ -170,121 +174,134 @@ export class EthChain implements IChain {
|
|
|
170
174
|
|
|
171
175
|
checkScriptOutput(_output) { }
|
|
172
176
|
|
|
173
|
-
getFee(server, wallet, opts) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const value = opts.tokenAddress || opts.multisigContractAddress ? 0 : output.amount;
|
|
215
|
-
// output.gasLimit used as the gasLimit in getBitcoreTx for non multisend transactions
|
|
216
|
-
const gasLimitEstimate = await server.estimateGas({
|
|
217
|
-
coin,
|
|
218
|
-
chain: this.chain,
|
|
219
|
-
network,
|
|
220
|
-
from,
|
|
221
|
-
to,
|
|
222
|
-
value,
|
|
223
|
-
data: output.data,
|
|
224
|
-
gasPrice
|
|
225
|
-
});
|
|
226
|
-
output.gasLimit = gasLimitEstimate || defaultGasLimit;
|
|
227
|
-
} catch {
|
|
228
|
-
output.gasLimit = defaultGasLimit;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
inGasLimit += output.gasLimit;
|
|
232
|
-
logger.info(`[${from}][${output?.toAddress || opts?.tokenAddress}] Output level gas limit: ${output.gasLimit}`);
|
|
233
|
-
// Add gas Limit buffer to output level gasLimit
|
|
234
|
-
if (gasLimitBuffer) {
|
|
235
|
-
const gasBuffer = Math.ceil(output.gasLimit * (gasLimitBuffer / 100));
|
|
236
|
-
output.gasLimit += gasBuffer;
|
|
237
|
-
inGasLimit += gasBuffer;
|
|
238
|
-
logger.info(`[${from}][${output?.toAddress || opts?.tokenAddress}] Output gas limit with buffer: ${output.gasLimit}`);
|
|
239
|
-
}
|
|
240
|
-
if (_.isNumber(opts.fee)) {
|
|
241
|
-
// This is used for sendmax
|
|
242
|
-
gasPrice = feePerKb = Number((opts.fee / (inGasLimit || defaultGasLimit)).toFixed());
|
|
243
|
-
}
|
|
244
|
-
fee += feePerKb * output.gasLimit;
|
|
245
|
-
}
|
|
246
|
-
// gasLimit == sum of internal gasLimits (for non Multisend)
|
|
247
|
-
gasLimit = inGasLimit;
|
|
248
|
-
logger.info(`[${from}] Current top level gas limit: ${gasLimit}`);
|
|
249
|
-
if (opts.multiSendContractAddress) {
|
|
250
|
-
// Calculate gas limit for top level of txp based on multisend tx
|
|
251
|
-
let _gasLimit;
|
|
252
|
-
try {
|
|
253
|
-
const data = this.encodeContractParameters(
|
|
254
|
-
Constants.BITPAY_CONTRACTS.MULTISEND,
|
|
255
|
-
{ addresses: outputAddresses, amounts: outputAmounts },
|
|
256
|
-
opts
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
_gasLimit = await server.estimateGas({
|
|
260
|
-
coin,
|
|
261
|
-
chain: this.chain,
|
|
262
|
-
network,
|
|
263
|
-
from,
|
|
264
|
-
to: opts.multiSendContractAddress,
|
|
265
|
-
value: totalValue.toString(),
|
|
266
|
-
data,
|
|
267
|
-
gasPrice
|
|
268
|
-
});
|
|
269
|
-
logger.info(`[${from}] Estimated multisend gas limit: ${_gasLimit}`);
|
|
270
|
-
} catch (error) {
|
|
271
|
-
logger.error('Error estimating gas for MultiSend contract: %o', error);
|
|
272
|
-
}
|
|
273
|
-
// Add gas limit buffer to top level gas limit
|
|
274
|
-
const buffer = gasLimitBuffer ? gasLimitBuffer / 100 : Defaults.MS_GAS_LIMIT_BUFFER_PERCENT;
|
|
275
|
-
// If gas estimation fails, fallback to sum of internal gasLimits
|
|
276
|
-
gasLimit = _gasLimit || gasLimit;
|
|
277
|
-
gasLimit += Math.ceil(gasLimit * buffer); // add gas limit buffer
|
|
278
|
-
fee += feePerKb * gasLimit;
|
|
279
|
-
logger.info(`[${from}] Top level gas limit with buffer: ${gasLimit}`);
|
|
177
|
+
async getFee(server, wallet, opts) {
|
|
178
|
+
const hasType2FeeOverride = opts.maxGasFee != null || opts.priorityGasFee != null;
|
|
179
|
+
let { maxGasFee, priorityGasFee } = opts;
|
|
180
|
+
if (hasType2FeeOverride) {
|
|
181
|
+
const chain = wallet.chain || wallet.coin;
|
|
182
|
+
// Keep overrides consistent with CWC's chain-specific minimum priority fee.
|
|
183
|
+
const minimum = CWCConstants.FEE_MINIMUMS[chain.toUpperCase()]?.priority ?? 0;
|
|
184
|
+
if (priorityGasFee < minimum) {
|
|
185
|
+
throw new ClientError(`priorityGasFee must be at least ${minimum} wei for ${chain}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Use the explicit rate for both construction and the fee reserved from the wallet balance.
|
|
189
|
+
const feeOpts = opts.gasPrice != null || hasType2FeeOverride
|
|
190
|
+
? { ...opts, feePerKb: opts.gasPrice ?? maxGasFee }
|
|
191
|
+
: opts;
|
|
192
|
+
// Fixed fees are converted to a gas price below, once the gas limits are known.
|
|
193
|
+
const fixedFee = Common.Utils.isNumber(opts.fee) ? Number(opts.fee) : undefined;
|
|
194
|
+
const inFeePerKb = fixedFee != null
|
|
195
|
+
? undefined
|
|
196
|
+
: await util.promisify(server._getFeePerKb).call(server, wallet, feeOpts);
|
|
197
|
+
let feePerKb = inFeePerKb;
|
|
198
|
+
let gasPrice = inFeePerKb;
|
|
199
|
+
const { from, txType, priorityFeePercentile, gasLimitBuffer } = opts;
|
|
200
|
+
const { coin, network, chain } = wallet;
|
|
201
|
+
let inGasLimit = 0; // Per recepient gas limit
|
|
202
|
+
let gasLimit = 0; // Gas limit for all recepients. used for contract interactions that rollup recepients
|
|
203
|
+
let fee = 0;
|
|
204
|
+
const defaultGasLimit = this.getDefaultGasLimit(opts);
|
|
205
|
+
const outputAddresses = []; // Parameter for MuliSend contract
|
|
206
|
+
const outputAmounts: bigint[] = []; // Parameter for MuliSend contract
|
|
207
|
+
let totalValue = 0n; // Parameter for MuliSend contract
|
|
208
|
+
logger.info(`getFee for address ${from} on network ${network} and chain ${chain}`);
|
|
209
|
+
logger.info('getFee.opts: %o', { from, txType, priorityFeePercentile, gasLimitBuffer });
|
|
210
|
+
logger.info(`[${from}] Add gas limit buffer?: ${!!gasLimitBuffer}`);
|
|
211
|
+
for (const output of opts.outputs) {
|
|
212
|
+
// Multisend txs build contract fn parameters (addresses, amounts) and bypass output level gas estimations
|
|
213
|
+
if (opts.multiSendContractAddress) {
|
|
214
|
+
outputAddresses.push(output.toAddress);
|
|
215
|
+
outputAmounts.push(BigInt(output.amount));
|
|
216
|
+
if (!opts.tokenAddress) {
|
|
217
|
+
totalValue += BigInt(output.amount);
|
|
280
218
|
}
|
|
281
|
-
if
|
|
282
|
-
|
|
283
|
-
|
|
219
|
+
// Used as a fallback value if estimateGas fails for multisend
|
|
220
|
+
inGasLimit += output.gasLimit ? output.gasLimit : defaultGasLimit;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
// Estimate a standard transfer
|
|
224
|
+
if (!output.gasLimit) {
|
|
225
|
+
try {
|
|
226
|
+
const to = opts.payProUrl
|
|
227
|
+
? output.toAddress
|
|
228
|
+
: opts.tokenAddress
|
|
229
|
+
? opts.tokenAddress
|
|
230
|
+
: opts.multisigContractAddress
|
|
231
|
+
? opts.multisigContractAddress
|
|
232
|
+
: output.toAddress;
|
|
233
|
+
const value = opts.tokenAddress || opts.multisigContractAddress ? 0 : output.amount;
|
|
234
|
+
// output.gasLimit used as the gasLimit in getBitcoreTx for non multisend transactions
|
|
235
|
+
const gasLimitEstimate = await server.estimateGas({
|
|
236
|
+
coin,
|
|
237
|
+
chain: this.chain,
|
|
238
|
+
network,
|
|
239
|
+
from,
|
|
240
|
+
to,
|
|
241
|
+
value,
|
|
242
|
+
data: output.data,
|
|
243
|
+
gasPrice
|
|
244
|
+
});
|
|
245
|
+
output.gasLimit = gasLimitEstimate || defaultGasLimit;
|
|
246
|
+
} catch {
|
|
247
|
+
output.gasLimit = defaultGasLimit;
|
|
284
248
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
249
|
+
}
|
|
250
|
+
inGasLimit += output.gasLimit;
|
|
251
|
+
logger.info(`[${from}][${output?.toAddress || opts?.tokenAddress}] Output level gas limit: ${output.gasLimit}`);
|
|
252
|
+
// Add gas Limit buffer to output level gasLimit
|
|
253
|
+
if (gasLimitBuffer) {
|
|
254
|
+
const gasBuffer = Math.ceil(output.gasLimit * (gasLimitBuffer / 100));
|
|
255
|
+
output.gasLimit += gasBuffer;
|
|
256
|
+
inGasLimit += gasBuffer;
|
|
257
|
+
logger.info(`[${from}][${output?.toAddress || opts?.tokenAddress}] Output gas limit with buffer: ${output.gasLimit}`);
|
|
258
|
+
}
|
|
259
|
+
if (fixedFee != null) {
|
|
260
|
+
// This is used for sendmax
|
|
261
|
+
gasPrice = feePerKb = Number((fixedFee / (inGasLimit || defaultGasLimit)).toFixed());
|
|
262
|
+
}
|
|
263
|
+
fee += feePerKb * output.gasLimit;
|
|
264
|
+
}
|
|
265
|
+
// gasLimit == sum of internal gasLimits (for non Multisend)
|
|
266
|
+
gasLimit = inGasLimit;
|
|
267
|
+
logger.info(`[${from}] Current top level gas limit: ${gasLimit}`);
|
|
268
|
+
if (opts.multiSendContractAddress) {
|
|
269
|
+
// Calculate gas limit for top level of txp based on multisend tx
|
|
270
|
+
let _gasLimit;
|
|
271
|
+
try {
|
|
272
|
+
const data = this.encodeContractParameters(
|
|
273
|
+
Constants.BITPAY_CONTRACTS.MULTISEND,
|
|
274
|
+
{ addresses: outputAddresses, amounts: outputAmounts },
|
|
275
|
+
opts
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
_gasLimit = await server.estimateGas({
|
|
279
|
+
coin,
|
|
280
|
+
chain: this.chain,
|
|
281
|
+
network,
|
|
282
|
+
from,
|
|
283
|
+
to: opts.multiSendContractAddress,
|
|
284
|
+
value: totalValue.toString(),
|
|
285
|
+
data,
|
|
286
|
+
gasPrice
|
|
287
|
+
});
|
|
288
|
+
logger.info(`[${from}] Estimated multisend gas limit: ${_gasLimit}`);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
logger.error('Error estimating gas for MultiSend contract: %o', error);
|
|
291
|
+
}
|
|
292
|
+
// Add gas limit buffer to top level gas limit
|
|
293
|
+
const buffer = gasLimitBuffer ? gasLimitBuffer / 100 : Defaults.MS_GAS_LIMIT_BUFFER_PERCENT;
|
|
294
|
+
// If gas estimation fails, fallback to sum of internal gasLimits
|
|
295
|
+
gasLimit = _gasLimit || gasLimit;
|
|
296
|
+
gasLimit += Math.ceil(gasLimit * buffer); // add gas limit buffer
|
|
297
|
+
fee += feePerKb * gasLimit;
|
|
298
|
+
logger.info(`[${from}] Top level gas limit with buffer: ${gasLimit}`);
|
|
299
|
+
}
|
|
300
|
+
if (Number(txType) === 2 && !hasType2FeeOverride) {
|
|
301
|
+
maxGasFee = await server.estimateFee({ network, chain: wallet.chain || coin, txType: 2 });
|
|
302
|
+
priorityGasFee = await server.estimatePriorityFee({ network, chain: wallet.chain || coin, percentile: priorityFeePercentile || 15 });
|
|
303
|
+
}
|
|
304
|
+
return { feePerKb, gasPrice, gasLimit, maxGasFee, priorityGasFee, fee };
|
|
288
305
|
}
|
|
289
306
|
|
|
290
307
|
isPrePublishRawBound(txp: TxProposal) {
|
|
@@ -613,7 +630,7 @@ export class EthChain implements IChain {
|
|
|
613
630
|
if (tx.effects && tx.effects.length) {
|
|
614
631
|
const multisigConfirm = tx.effects.findIndex(e => e.type === 'MULTISIG:confirmTransaction');
|
|
615
632
|
const multisigSubmit = tx.effects.findIndex(e => e.type === 'MULTISIG:submitTransaction');
|
|
616
|
-
const erc20Transfer = tx.effects.findIndex(e => e.type ===
|
|
633
|
+
const erc20Transfer = tx.effects.findIndex(e => e.type === ERC20_TRANSFER_EFFECT);
|
|
617
634
|
const internalTransfer = tx.effects.findIndex(e => !e.type && !e.contractAddress);
|
|
618
635
|
|
|
619
636
|
const exists = [multisigConfirm, multisigSubmit, erc20Transfer, internalTransfer].filter(i => i > -1);
|
|
@@ -625,7 +642,7 @@ export class EthChain implements IChain {
|
|
|
625
642
|
multisigContractAddress = best.contractAddress;
|
|
626
643
|
address = best.to;
|
|
627
644
|
amount = best.amount;
|
|
628
|
-
} else if (best.type ==
|
|
645
|
+
} else if (best.type == ERC20_TRANSFER_EFFECT) {
|
|
629
646
|
tokenAddress = best.contractAddress;
|
|
630
647
|
address = best.to;
|
|
631
648
|
amount = best.amount;
|
|
@@ -73,7 +73,7 @@ export class SolChain implements IChain {
|
|
|
73
73
|
const lockedSum = Number(amounts + fees) || 0; // previously set to 0 if opts.multisigContractAddress
|
|
74
74
|
const reserveAmount = opts.tokenAddress ? 0 : reserve;
|
|
75
75
|
const convertedBalance = this.convertBitcoreBalance(balance, lockedSum, reserveAmount);
|
|
76
|
-
server.storage.
|
|
76
|
+
server.storage.fetchAddressesPage(server.walletId, { limit: 1 }, (err, addresses: IAddress[]) => {
|
|
77
77
|
if (err) return cb(err);
|
|
78
78
|
if (addresses.length > 0) {
|
|
79
79
|
const byAddress = [
|
|
@@ -69,7 +69,7 @@ export class XrpChain implements IChain {
|
|
|
69
69
|
return sum + BigInt(txp.amount || 0) + BigInt(txp.fee || 0);
|
|
70
70
|
}, 0n) || 0n;
|
|
71
71
|
const convertedBalance = this.convertBitcoreBalance(balance, Number(lockedSum), reserve);
|
|
72
|
-
server.storage.
|
|
72
|
+
server.storage.fetchAddressesPage(server.walletId, { limit: 1 }, (err, addresses: IAddress[]) => {
|
|
73
73
|
if (err) return cb(err);
|
|
74
74
|
if (addresses.length > 0) {
|
|
75
75
|
const byAddress = [
|
|
@@ -459,18 +459,6 @@ export function registerServiceRoutes(router: express.Router, context: RouteCont
|
|
|
459
459
|
});
|
|
460
460
|
});
|
|
461
461
|
|
|
462
|
-
router.post('/v1/service/wyre/walletOrderQuotation', (req, res) => {
|
|
463
|
-
respondWithAuthServer(req, res, context, server => {
|
|
464
|
-
return server.externalServices.wyre.wyreWalletOrderQuotation(req);
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
router.post('/v1/service/wyre/walletOrderReservation', (req, res) => {
|
|
469
|
-
respondWithAuthServer(req, res, context, server => {
|
|
470
|
-
return server.externalServices.wyre.wyreWalletOrderReservation(req);
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
|
|
474
462
|
router.post('/v1/service/changelly/getCurrencies', (req, res) => {
|
|
475
463
|
respondWithPublicServer(req, res, context, server => {
|
|
476
464
|
return server.externalServices.changelly.changellyGetCurrencies(req);
|
|
@@ -228,8 +228,10 @@ export function registerWalletRoutes(router: express.Router, context: RouteConte
|
|
|
228
228
|
return res.json([]);
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
// a copayer that isn't an object with a string id can't exist, so it isn't looked up
|
|
232
|
+
const wellFormed = copayers.filter(c => typeof c?.copayerId === 'string');
|
|
231
233
|
const storage = WalletService.getStorage();
|
|
232
|
-
const existing = await Promise.all<{ copayerId: string; verified: boolean }>(
|
|
234
|
+
const existing = await Promise.all<{ copayerId: string; verified: boolean }>(wellFormed.map(async c => {
|
|
233
235
|
const copayer = await storage.fetchCopayerLookup(c.copayerId).catch(() => null);
|
|
234
236
|
if (!copayer) {
|
|
235
237
|
return { copayerId: c.copayerId, verified: false };
|