Calculate refund on user side only if no value provided (strictly undefined)

This commit is contained in:
Theo 2023-09-06 14:21:12 -07:00
parent 394d6cab5c
commit 2ce8cafdbd
2 changed files with 5 additions and 5 deletions

@ -1,6 +1,6 @@
{
"name": "@tornado/tornado-oracles",
"version": "3.2.0",
"version": "3.2.1",
"description": "Oracles for Tornado-specific transactions & actions",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",

@ -225,7 +225,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
* @param {AvailableTokenSymbols | Uppercase<AvailableTokenSymbols>} params.currency Currency symbol
* @param {number | HexadecimalStringifiedNumber } params.amount Withdrawal amount in selected currency
* @param {number | HexadecimalStringifiedNumber } params.decimals Token (currency) decimals
* @param {BigNumberish} [params.refundInEth=0] Refund in ETH, if withdrawed other tokens on Mainnet (not ETH). Can not be provided, if user-side calculation
* @param {BigNumberish} [params.refundInEth] Refund in ETH, if withdrawed other tokens on Mainnet (not ETH). Can not be provided, if user-side calculation
* @param {BigNumberish} [params.tokenPriceInEth] If withdrawing other token on Mainnet or Goerli, need to provide token price in ETH (in WEI)
* @param {number} [params.gasLimit] Predefined gas limit, if already calculated (no refetching)
* @param {number} [params.gasPrice] Predefined gas price, if already calculated (no refetching)
@ -242,7 +242,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
currency,
amount,
decimals,
refundInEth = 0,
refundInEth,
tokenPriceInEth,
predefinedGasLimit,
predefinedGasPrice,
@ -258,10 +258,10 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
return '0';
}
if (txType === 'user_withdrawal' && !refundInEth)
if (txType === 'user_withdrawal' && refundInEth === undefined)
refundInEth = this.calculateRefundInETH(gasPrice, currency.toLowerCase() as InstanceTokenSymbol);
const feeInEth = BigNumber.from(gasCosts).add(refundInEth);
const feeInEth = BigNumber.from(gasCosts).add(refundInEth || 0);
return convertETHToToken(feeInEth, decimals, tokenPriceInEth).add(relayerFee).toHexString();
}