From 85b057fbedad51a259f43873808c3d76c0beb46a Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 19 Aug 2023 10:44:07 -0700 Subject: [PATCH] Add specific Tornado transaction type - relayer_withdrawal_check_v4 - for backwards compatibility with old gas calculation algorithm --- package.json | 2 +- src/feeOracleV4.ts | 3 +++ src/types.ts | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 304e479..abd13e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tornado/tornado-oracles", - "version": "0.1.1", + "version": "0.2.0", "description": "Gas oracle for Tornado-specific transactions", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/feeOracleV4.ts b/src/feeOracleV4.ts index 4ce7069..04bd218 100644 --- a/src/feeOracleV4.ts +++ b/src/feeOracleV4.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 // 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); + // 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); return this.provider.estimateGas(tx); diff --git a/src/types.ts b/src/types.ts index 0f70e53..abdbe9a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,7 +9,13 @@ export type LegacyGasPrices = { [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 { to: string; @@ -54,6 +60,7 @@ export type TornadoPoolInstance = { 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 Token = { tokenAddress: string;