ERC20 abi Torn token

This commit is contained in:
smart_ex 2022-05-26 17:48:01 +10:00
parent fecac18687
commit 3279eeaf08
8 changed files with 387 additions and 33 deletions

256
abis/ERC20.abi.json Normal file

@ -0,0 +1,256 @@
[
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "_totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "who",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "nonces",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "permit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]

@ -1,9 +1,10 @@
/* Autogenerated file. Do not edit manually. */ /* Autogenerated file. Do not edit manually. */
/* tslint:disable */ /* tslint:disable */
/* eslint-disable */ /* eslint-disable */
export { AggregatorAbi__factory } from './AggregatorAbi__factory'; export { AggregatorAbi__factory } from "./AggregatorAbi__factory";
export { MulticallAbi__factory } from './MulticallAbi__factory'; export { ERC20Abi__factory } from "./ERC20Abi__factory";
export { OffchainOracleAbi__factory } from './OffchainOracleAbi__factory'; export { MulticallAbi__factory } from "./MulticallAbi__factory";
export { ProxyLightABI__factory } from './ProxyLightABI__factory'; export { OffchainOracleAbi__factory } from "./OffchainOracleAbi__factory";
export { TornadoABI__factory } from './TornadoABI__factory'; export { ProxyLightABI__factory } from "./ProxyLightABI__factory";
export { TornadoProxyABI__factory } from './TornadoProxyABI__factory'; export { TornadoABI__factory } from "./TornadoABI__factory";
export { TornadoProxyABI__factory } from "./TornadoProxyABI__factory";

@ -1,16 +1,18 @@
/* Autogenerated file. Do not edit manually. */ /* Autogenerated file. Do not edit manually. */
/* tslint:disable */ /* tslint:disable */
/* eslint-disable */ /* eslint-disable */
export type { AggregatorAbi } from './AggregatorAbi'; export type { AggregatorAbi } from "./AggregatorAbi";
export type { MulticallAbi } from './MulticallAbi'; export type { ERC20Abi } from "./ERC20Abi";
export type { OffchainOracleAbi } from './OffchainOracleAbi'; export type { MulticallAbi } from "./MulticallAbi";
export type { ProxyLightABI } from './ProxyLightABI'; export type { OffchainOracleAbi } from "./OffchainOracleAbi";
export type { TornadoABI } from './TornadoABI'; export type { ProxyLightABI } from "./ProxyLightABI";
export type { TornadoProxyABI } from './TornadoProxyABI'; export type { TornadoABI } from "./TornadoABI";
export * as factories from './factories'; export type { TornadoProxyABI } from "./TornadoProxyABI";
export { AggregatorAbi__factory } from './factories/AggregatorAbi__factory'; export * as factories from "./factories";
export { MulticallAbi__factory } from './factories/MulticallAbi__factory'; export { AggregatorAbi__factory } from "./factories/AggregatorAbi__factory";
export { OffchainOracleAbi__factory } from './factories/OffchainOracleAbi__factory'; export { ERC20Abi__factory } from "./factories/ERC20Abi__factory";
export { ProxyLightABI__factory } from './factories/ProxyLightABI__factory'; export { MulticallAbi__factory } from "./factories/MulticallAbi__factory";
export { TornadoABI__factory } from './factories/TornadoABI__factory'; export { OffchainOracleAbi__factory } from "./factories/OffchainOracleAbi__factory";
export { TornadoProxyABI__factory } from './factories/TornadoProxyABI__factory'; export { ProxyLightABI__factory } from "./factories/ProxyLightABI__factory";
export { TornadoABI__factory } from "./factories/TornadoABI__factory";
export { TornadoProxyABI__factory } from "./factories/TornadoProxyABI__factory";

@ -6,7 +6,7 @@ require('dotenv').config();
export const netId = <availableIds>Number(process.env.NET_ID || 1); export const netId = <availableIds>Number(process.env.NET_ID || 1);
export const redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379'; export const redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379';
export const rpcUrl = process.env.RPC_URL; export const rpcUrl = process.env.RPC_URL;
export const oracleRpcUrl = process.env.ORACLE_RPC_URL || 'https://mainnet.infura.io/'; export const mainnetRpcUrl = process.env.ORACLE_RPC_URL || 'https://mainnet.infura.io/';
export const offchainOracleAddress = '0x07D91f5fb9Bf7798734C3f606dB065549F6893bb'; export const offchainOracleAddress = '0x07D91f5fb9Bf7798734C3f606dB065549F6893bb';
export const multiCallAddress = '0xda3c19c6fe954576707fa24695efb830d9cca1ca'; export const multiCallAddress = '0xda3c19c6fe954576707fa24695efb830d9cca1ca';
export const aggregatorAddress = process.env.AGGREGATOR; export const aggregatorAddress = process.env.AGGREGATOR;
@ -25,6 +25,7 @@ export const gasLimits = {
[RelayerJobType.MINING_WITHDRAW]: 400000, [RelayerJobType.MINING_WITHDRAW]: 400000,
}; };
export const minimumBalance = '1000000000000000000'; export const minimumBalance = '1000000000000000000';
export const minimumTornBalance = '50000000000000000000';
export const baseFeeReserve = Number(process.env.BASE_FEE_RESERVE_PERCENTAGE); export const baseFeeReserve = Number(process.env.BASE_FEE_RESERVE_PERCENTAGE);
export const tornToken = { export const tornToken = {
tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C', tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',

@ -1,15 +1,16 @@
import { import {
ERC20Abi__factory,
MulticallAbi__factory, MulticallAbi__factory,
OffchainOracleAbi__factory, OffchainOracleAbi__factory,
ProxyLightABI__factory, ProxyLightABI__factory,
TornadoProxyABI__factory, TornadoProxyABI__factory,
} from '../../contracts'; } from '../../contracts';
import { providers } from 'ethers'; import { providers } from 'ethers';
import { rpcUrl, multiCallAddress, netId, offchainOracleAddress, oracleRpcUrl } from '../config'; import { multiCallAddress, netId, offchainOracleAddress, mainnetRpcUrl, rpcUrl } from '../config';
export function getProvider(isStatic = true, customRpcUrl?: string) { export function getProvider(isStatic = true, customRpcUrl?: string, chainId = netId) {
if (isStatic) return new providers.StaticJsonRpcProvider(customRpcUrl || rpcUrl, netId); if (isStatic) return new providers.StaticJsonRpcProvider(customRpcUrl || rpcUrl, chainId);
else return new providers.JsonRpcProvider(customRpcUrl || rpcUrl, netId); else return new providers.JsonRpcProvider(customRpcUrl || rpcUrl, chainId);
} }
@ -22,13 +23,16 @@ export const getTornadoProxyLightContract = (proxyAddress: string) => {
export const getOffchainOracleContract = () => { export const getOffchainOracleContract = () => {
return OffchainOracleAbi__factory.connect(offchainOracleAddress, getProvider(true, oracleRpcUrl)); return OffchainOracleAbi__factory.connect(offchainOracleAddress, getProvider(true, mainnetRpcUrl));
}; };
export const getMultiCallContract = () => { export const getMultiCallContract = () => {
return MulticallAbi__factory.connect(multiCallAddress, getProvider(true, oracleRpcUrl)); return MulticallAbi__factory.connect(multiCallAddress, getProvider(true, mainnetRpcUrl));
}; };
export const getTornTokenContract = (tokenAddress: string) => {
return ERC20Abi__factory.connect(tokenAddress, getProvider(true, mainnetRpcUrl));
};
// export const getAggregatorContract = () => { // export const getAggregatorContract = () => {
// return AggregatorAbi__factory.connect(aggregatorAddress, getProvider()); // return AggregatorAbi__factory.connect(aggregatorAddress, getProvider());
// }; // };

@ -1,10 +1,12 @@
import { getProvider } from './contracts'; import { getProvider } from './contracts';
import { mainnetRpcUrl } from '../config';
import { ChainIds } from '../types';
const addresses = new Map<string, string>(); const addresses = new Map<string, string>();
const provider = getProvider();
async function resolve(domain: string) { async function resolve(domain: string) {
try { try {
const provider = getProvider(true, mainnetRpcUrl, ChainIds.ethereum);
if (!addresses.has(domain)) { if (!addresses.has(domain)) {
const resolved = await provider.resolveName(domain); const resolved = await provider.resolveName(domain);
addresses.set(domain, resolved); addresses.set(domain, resolved);

@ -1,6 +1,7 @@
import { import {
instances, instances,
minimumBalance, minimumBalance,
minimumTornBalance,
netId, netId,
networkConfig, networkConfig,
privateKey, privateKey,
@ -10,14 +11,20 @@ import {
tornToken, tornToken,
} from '../config'; } from '../config';
import { Token } from '../types'; import { Token } from '../types';
import { getProvider, getTornadoProxyContract, getTornadoProxyLightContract } from '../modules/contracts'; import {
getProvider,
getTornadoProxyContract,
getTornadoProxyLightContract,
getTornTokenContract,
} from '../modules/contracts';
import { resolve } from '../modules'; import { resolve } from '../modules';
import { ProxyLightABI, TornadoProxyABI } from '../../contracts'; import { ERC20Abi, ProxyLightABI, TornadoProxyABI } from '../../contracts';
import { availableIds, netIds, NetInstances } from '../../../torn-token'; import { availableIds, netIds, NetInstances } from '../../../torn-token';
import { getAddress } from 'ethers/lib/utils'; import { formatEther, getAddress } from 'ethers/lib/utils';
import { providers, Wallet } from 'ethers'; import { providers, Wallet } from 'ethers';
import { container, singleton } from 'tsyringe'; import { container, singleton } from 'tsyringe';
import { GasPrice } from 'gas-price-oracle/lib/types'; import { GasPrice } from 'gas-price-oracle/lib/types';
import { configService } from './index';
type relayerQueueName = `relayer_${availableIds}` type relayerQueueName = `relayer_${availableIds}`
@ -39,6 +46,8 @@ export class ConfigService {
isInit: boolean; isInit: boolean;
nativeCurrency: string; nativeCurrency: string;
fallbackGasPrices: GasPrice; fallbackGasPrices: GasPrice;
private _tokenAddress: string;
private _tokenContract: ERC20Abi;
constructor() { constructor() {
@ -85,8 +94,10 @@ export class ConfigService {
try { try {
if (this.isInit) return; if (this.isInit) return;
await this._checkNetwork(); await this._checkNetwork();
this._tokenAddress = await resolve(torn.torn.address);
this._tokenContract = await getTornTokenContract(this._tokenAddress);
if (this.isLightMode) { if (this.isLightMode) {
this._proxyAddress = await resolve(torn.tornadoProxyLight.address); this._proxyAddress = torn.tornadoProxyLight.address;
this._proxyContract = getTornadoProxyLightContract(this._proxyAddress); this._proxyContract = getTornadoProxyLightContract(this._proxyAddress);
const { gasPrices, nativeCurrency } = networkConfig[this.netIdKey]; const { gasPrices, nativeCurrency } = networkConfig[this.netIdKey];
this.nativeCurrency = nativeCurrency; this.nativeCurrency = nativeCurrency;
@ -106,10 +117,19 @@ export class ConfigService {
decimals: el.decimals, decimals: el.decimals,
symbol: el.symbol, symbol: el.symbol,
})).filter(Boolean); })).filter(Boolean);
const { balance } = await configService.getBalance();
const { balance: tornBalance } = await configService.getTornBalance();
console.log( console.log(
`Configuration completed\n-- netId: ${this.netId}\n-- rpcUrl: ${this.rpcUrl}`); 'Configuration completed\n',
`-- netId: ${this.netId}\n`,
`-- rpcUrl: ${this.rpcUrl}\n`,
`-- relayer Address: ${this.wallet.address}\n`,
`-- relayer Balance: ${formatEther(balance)}\n`,
`-- relayer Torn balance: ${formatEther(tornBalance)}\n`,
);
this.isInit = true; this.isInit = true;
console.log(this);
} catch (e) { } catch (e) {
console.error(`${this.constructor.name} Error:`, e.message); console.error(`${this.constructor.name} Error:`, e.message);
} }
@ -125,6 +145,12 @@ export class ConfigService {
return { balance, isEnougth }; return { balance, isEnougth };
} }
async getTornBalance() {
const balance = await this._tokenContract.balanceOf(this.wallet.address);
const isEnougth = balance.gt(minimumTornBalance);
return { balance, isEnougth };
}
} }
type InstanceProps = { type InstanceProps = {

@ -14,4 +14,66 @@ export enum JobStatus {
FAILED = 'FAILED', FAILED = 'FAILED',
} }
export type Token = { address: string, decimals: number, symbol?: string } export type Token = { address: string, decimals: number, symbol?: string }
export enum ChainIds {
'kardia' = 0,
'ethereum' = 1,
'ubiq' = 8,
'optimism' = 10,
'songbird' = 19,
'elastos' = 20,
'cronos' = 25,
'rsk' = 30,
'telos' = 40,
'csc' = 52,
'zyx' = 55,
'binance' = 56,
'syscoin' = 57,
'gochain' = 60,
'ethclassic' = 61,
'okexchain' = 66,
'hoo' = 70,
'meter' = 82,
'tomochain' = 88,
'xdai' = 100,
'velas' = 106,
'thundercore' = 108,
'fuse' = 122,
'heco' = 128,
'polygon' = 137,
'xdaiarb' = 200,
'energyweb' = 246,
'fantom' = 250,
'hpb' = 269,
'boba' = 288,
'kucoin' = 321,
'shiden' = 336,
'theta' = 361,
'candle' = 534,
'astar' = 592,
'callisto' = 820,
'wanchain' = 888,
'metis' = 1088,
'moonbeam' = 1284,
'moonriver' = 1285,
'ronin' = 2020,
'ezchain' = 2612,
'iotex' = 4689,
'xlc' = 5050,
'nahmii' = 5551,
'klaytn' = 8217,
'smartbch' = 10000,
'fusion' = 32659,
'arbitrum' = 42161,
'celo' = 42220,
'oasis' = 42262,
'avalanche' = 43114,
'godwoken' = 71394,
'polis' = 333999,
'aurora' = 1313161554,
'harmony' = 1666600000,
'palm' = 11297108109,
'curio' = 836542336838601,
}