Different oracles api for Tornado-specific purposes
Go to file
2024-05-12 20:59:47 +00:00
abis Using ES6, Multicall3, and latest OffchainOracle ABI and regenerate typechain definitions 2024-05-12 17:46:35 +00:00
src Fixed token symbol formatting 2024-05-12 20:52:26 +00:00
.gitignore Set function to get optimism l1 fee as public & bump version to 1.1.0 2023-08-22 11:23:25 -07:00
.npmrc Initial commit 2023-08-17 14:39:57 -07:00
.nvmrc Change node version to 14.21.3 2023-08-21 09:23:12 -07:00
.prettierignore Don't prettify service files, abis and autogenerated contracts by typechain 2023-08-22 06:23:12 -07:00
.prettierrc Initial commit 2023-08-17 14:39:57 -07:00
LICENSE Initial commit 2023-08-17 14:39:57 -07:00
package.json Mark version as 4 2024-05-12 20:59:47 +00:00
README.md Update package to version 3.0.0: 2023-09-04 13:40:29 -07:00
tsconfig.esm.json Using ES6, Multicall3, and latest OffchainOracle ABI and regenerate typechain definitions 2024-05-12 17:46:35 +00:00
tsconfig.json Using ES6, Multicall3, and latest OffchainOracle ABI and regenerate typechain definitions 2024-05-12 17:46:35 +00:00
yarn.lock Using ES6, Multicall3, and latest OffchainOracle ABI and regenerate typechain definitions 2024-05-12 17:46:35 +00:00

Tornado oracles

This is a library providing convenient and fast access to oracles for Tornado-specific transactions, for example, withdrawal via relayer or getting rate to ETH for tokens that used in Tornado pools

Installation


  • Create .npmrc file in project root with content @tornado:registry=https://git.tornado.ws/api/packages/tornado-packages/npm/
  • Run npm i @tornado/tornado-oracles

Import


const { TornadoFeeOracleV5, TornadoFeeOracleV5, TokenPriceOracle } = require('@tornado/tornado-oracles');
or
import { TornadoFeeOracleV5, TornadoFeeOracleV5, TokenPriceOracle } from '@tornado/tornado-oracles';

Usage


Estimate withdrawal gas costs
import { TornadoFeeOracleV5 } from '@tornado/tornado-oracles';

const tx: TransactionData = {
  to: tornadoProxyLightAddress,
  data: poolInstance.methods.withdraw(...params).encodeABI(),
  value: withdrawalProofArgs[5],
};

const feeOracle = new TornadoFeeOracleV5(1, 'https://eth.llamarpc.com'); // First parameter - chain ID
const withdrawalGas = await feeOracle.getGas({tx, txType: 'relayer_withdrawal'});
Estimate gas price and gas limit to send transaction
import { TornadoFeeOracleV5 } from '@tornado/tornado-oracles';

const incompleteTx: TransactionData = {
  to: tornadoProxyLightAddress,
  data: poolInstance.methods.withdraw(...params).encodeABI(),
  value: withdrawalProofArgs[5],
};

const feeOracle = new TornadoFeeOracleV5(1, 'https://eth.llamarpc.com');
const transactionType: TxType = 'relayer_withdrawal';
const { gasPrice, gasLimit } = await feeOracle.getGasParams({tx: incompleteTx, txType: transactionType});

const tx: TransactionData = {...incompleteTx, gasPrice, gasLimit}
Get token prices (rate to ETH) for tokens that used in Tornado
import { TokenPriceOracle } from '@tornado/tornado-oracles';

const priceOracle = new TokenPriceOracle('https://eth.llamarpc.com');
const tokenPrices = await priceOracle.fetchPrices();

console.log(tokenPrices); // All prices in WEI
/* 
{
  torn: '1653773547906175', 
  dai: '603108348359886',
  cdai: '13487984643748',
  usdc: '601311723569085',
  usdt: '602058974373161',
  wbtc: '15696224089898846959'
}
*/

License

MIT