@tornado/tornado-oracles (3.0.0)

Published 2023-09-04 23:41:07 +03:00 by Theo in tornado-packages/tornado-oracles

Installation

@tornado:registry=
npm install @tornado/tornado-oracles@3.0.0
"@tornado/tornado-oracles": "3.0.0"

About this package

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

Dependencies

Dependencies

ID Version
@tornado/gas-price-oracle ^0.5.3
@tornado/tornado-config ^2.0.0
@types/node ^20.5.1
bignumber.js ^9.1.1
ethers 5.7

Development Dependencies

ID Version
@typechain/ethers-v5 ^11.1.1
nodemon ^3.0.1
prettier ^3.0.1
ts-node ^10.9.1
typechain ^8.3.1
typescript ^5.1.6

Keywords

Gas price Gas Gas limit Oracle
Details
npm
2023-09-04 23:41:07 +03:00
29
Theo
MIT
34 KiB
Assets (1)
Versions (23) View all
3.3.0 2023-09-07
3.2.0 2023-09-07
3.1.0 2023-09-04
3.0.0 2023-09-04
2.1.0 2023-08-30