Add specific Tornado transaction type - relayer_withdrawal_check_v4 - for backwards compatibility with old gas calculation algorithm

This commit is contained in:
Theo 2023-08-19 10:44:07 -07:00
parent 6bff5b560f
commit 85b057fbed
3 changed files with 12 additions and 2 deletions

@ -1,6 +1,6 @@
{ {
"name": "@tornado/tornado-oracles", "name": "@tornado/tornado-oracles",
"version": "0.1.1", "version": "0.2.0",
"description": "Gas oracle for Tornado-specific transactions", "description": "Gas oracle for Tornado-specific transactions",
"main": "./lib/index.js", "main": "./lib/index.js",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",

@ -23,6 +23,9 @@ export class TornadoFeeOracleV4 extends TornadoFeeOracle implements ITornadoFeeO
// Need to bump relayer gas limit for transaction, because predefined gas limit to small to be 100% sure that transaction will be sent // Need to bump relayer gas limit for transaction, because predefined gas limit to small to be 100% sure that transaction will be sent
// This leads to fact that relayer often pays extra for gas from his own funds, however, this was designed by previous developers // This leads to fact that relayer often pays extra for gas from his own funds, however, this was designed by previous developers
if (type === 'relayer_withdrawal') return bump(defaultWithdrawalGasLimit[this.chainId], bumpPercent || 20); if (type === 'relayer_withdrawal') return bump(defaultWithdrawalGasLimit[this.chainId], bumpPercent || 20);
// For compatibility reasons, when wee check user-provided fee for V4 withdrawal transaction, we need dump gas limit
// for about 20 percent,so that the transaction will be sent, even if it results in some loss for the relayer
if (type === 'relayer_withdrawal_check_v4') return bump(defaultWithdrawalGasLimit[this.chainId], -20);
if (!tx) return BigNumber.from(21_000); if (!tx) return BigNumber.from(21_000);
return this.provider.estimateGas(tx); return this.provider.estimateGas(tx);

@ -9,7 +9,13 @@ export type LegacyGasPrices = {
[gasPriceType in LegacyGasPriceKey]: number; [gasPriceType in LegacyGasPriceKey]: number;
}; };
export type TxType = 'user_withdrawal' | 'relayer_withdrawal' | 'other'; /* Tornado-specific transaction types:
- 'user_withdrawal' - Fee calculation on user side, when user withdraw funds itself or via relayer on site
- 'relayer_withdrawal' - Fee calculation on relayer side, when relayer sends withdrawal transaction
- 'relayer_withdrawal_check_v4' - Fee calculation on relayer side, when V4 relayer checks user-provided fee. For compatibility reasons
- 'other' - Any other non-specific transaction
*/
export type TxType = 'user_withdrawal' | 'relayer_withdrawal' | 'relayer_withdrawal_check_v4' | 'other';
export interface TransactionData { export interface TransactionData {
to: string; to: string;
@ -54,6 +60,7 @@ export type TornadoPoolInstance = {
decimals: number; decimals: number;
}; };
// All non-native tokens from Tornado instances on ETH mainnet and TORN itself
export type TokenSymbol = 'dai' | 'cdai' | 'usdc' | 'usdt' | 'wbtc' | 'torn'; export type TokenSymbol = 'dai' | 'cdai' | 'usdc' | 'usdt' | 'wbtc' | 'torn';
export type Token = { export type Token = {
tokenAddress: string; tokenAddress: string;