Calculate refund in calculateWithdrawalFeeViaRelayer, if correct value didn't provided when calculating for user_withdrawal
transaction type & bump to 3.1.0
This commit is contained in:
parent
be7f911a17
commit
9ef88948d2
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tornado/tornado-oracles",
|
"name": "@tornado/tornado-oracles",
|
||||||
"version": "3.0.0",
|
"version": "3.1.0",
|
||||||
"description": "Oracles for Tornado-specific transactions & actions",
|
"description": "Oracles for Tornado-specific transactions & actions",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"types": "./lib/index.d.ts",
|
"types": "./lib/index.d.ts",
|
||||||
|
@ -224,7 +224,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|||||||
* @param {AvailableTokenSymbols | Uppercase<AvailableTokenSymbols>} params.currency Currency symbol
|
* @param {AvailableTokenSymbols | Uppercase<AvailableTokenSymbols>} params.currency Currency symbol
|
||||||
* @param {number | HexadecimalStringifiedNumber } params.amount Withdrawal amount in selected currency
|
* @param {number | HexadecimalStringifiedNumber } params.amount Withdrawal amount in selected currency
|
||||||
* @param {number | HexadecimalStringifiedNumber } params.decimals Token (currency) decimals
|
* @param {number | HexadecimalStringifiedNumber } params.decimals Token (currency) decimals
|
||||||
* @param {BigNumberish} [params.refundInEth=0] Refund in ETH, if withdrawed other tokens on Mainnet (not ETH)
|
* @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.tokenPriceInEth] If withdrawing other token on Mainnet or Goerli, need to provide token price in ETH (in WEI)
|
* @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.gasLimit] Predefined gas limit, if already calculated (no refetching)
|
||||||
* @param {number} [params.gasPrice] Predefined gas price, if already calculated (no refetching)
|
* @param {number} [params.gasPrice] Predefined gas price, if already calculated (no refetching)
|
||||||
@ -243,12 +243,13 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|||||||
decimals,
|
decimals,
|
||||||
refundInEth = 0,
|
refundInEth = 0,
|
||||||
tokenPriceInEth,
|
tokenPriceInEth,
|
||||||
gasLimit,
|
predefinedGasLimit,
|
||||||
gasPrice,
|
predefinedGasPrice,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const relayerFee = this.calculateRelayerFeeInWei(relayerFeePercent, amount, decimals);
|
const relayerFee = this.calculateRelayerFeeInWei(relayerFeePercent, amount, decimals);
|
||||||
const gasCosts = await this.getGas({ tx, txType, predefinedGasLimit: gasLimit, predefinedGasPrice: gasPrice });
|
const { gasPrice, gasLimit } = await this.getGasParams({ tx, txType, predefinedGasLimit, predefinedGasPrice });
|
||||||
|
const gasCosts = BigNumber.from(gasPrice).mul(gasLimit);
|
||||||
|
|
||||||
if ((this.chainId === ChainId.MAINNET || this.chainId === ChainId.GOERLI) && currency.toLowerCase() != 'eth') {
|
if ((this.chainId === ChainId.MAINNET || this.chainId === ChainId.GOERLI) && currency.toLowerCase() != 'eth') {
|
||||||
if (!tokenPriceInEth) {
|
if (!tokenPriceInEth) {
|
||||||
@ -256,6 +257,9 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (txType === 'user_withdrawal' && !refundInEth)
|
||||||
|
refundInEth = this.calculateRefundInETH(gasPrice, currency.toLowerCase() as InstanceTokenSymbol);
|
||||||
|
|
||||||
const feeInEth = BigNumber.from(gasCosts).add(refundInEth);
|
const feeInEth = BigNumber.from(gasCosts).add(refundInEth);
|
||||||
return convertETHToToken(feeInEth, decimals, tokenPriceInEth).add(relayerFee).toHexString();
|
return convertETHToToken(feeInEth, decimals, tokenPriceInEth).add(relayerFee).toHexString();
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,6 @@ export type GetWithdrawalFeeViaRelayerInput = {
|
|||||||
decimals: string | number; // Token (currency) decimal places
|
decimals: string | number; // Token (currency) decimal places
|
||||||
refundInEth?: HexadecimalStringifiedNumber; // Refund amount in ETH, if withdrawing non-native currency on ETH Mainnet or Goerli
|
refundInEth?: HexadecimalStringifiedNumber; // Refund amount in ETH, if withdrawing non-native currency on ETH Mainnet or Goerli
|
||||||
tokenPriceInEth?: HexadecimalStringifiedNumber | string; // Token (currency) price in ETH wei, if withdrawing non-native currency
|
tokenPriceInEth?: HexadecimalStringifiedNumber | string; // Token (currency) price in ETH wei, if withdrawing non-native currency
|
||||||
gasPrice?: HexadecimalStringifiedNumber; // Predefined gas price for withdrawal tx (wont be calculated again in function)
|
predefinedGasPrice?: HexadecimalStringifiedNumber; // Predefined gas price for withdrawal tx (wont be calculated again in function)
|
||||||
gasLimit?: number; // Predefined gas limit for withdrawal tx (wont be calculated again in function)
|
predefinedGasLimit?: number; // Predefined gas limit for withdrawal tx (wont be calculated again in function)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user