upgrade config structure
This commit is contained in:
parent
fd458d4b19
commit
ced0b6a738
@ -1,8 +1,6 @@
|
||||
NET_ID=42
|
||||
RPC_URL=https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51
|
||||
PRIVATE_KEY=
|
||||
ETH_MIXER_ADDRESS=0x1Cea940cA15a303A0E01B7F8589F39fF34308DB2
|
||||
DAI_MIXER_ADDRESS=0x7ed3fC8042e18db889A0466F49c438bB1410b3c7
|
||||
# 2.5 means 2.5%
|
||||
RELAYER_FEE=2.5
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
1. `npm i`
|
||||
2. `cp .env.example .env`
|
||||
3. Modify `.env` as needed
|
||||
4. If you want to change contracts' addresses go to [config.js](./config.js) file.
|
||||
|
||||
## Deploy Kovan
|
||||
1. `cp .env.example deploy/kovan/.env`
|
||||
|
54
config.js
54
config.js
@ -4,20 +4,52 @@ module.exports = {
|
||||
netId: Number(process.env.NET_ID) || 42,
|
||||
rpcUrl: process.env.RPC_URL || 'https://kovan.infura.io/v3/a3f4d001c1fc4a359ea70dd27fd9cb51',
|
||||
privateKey: process.env.PRIVATE_KEY,
|
||||
mixers: [ {
|
||||
address: process.env.ETH_MIXER_ADDRESS,
|
||||
currency: 'eth',
|
||||
amount: '0.1'
|
||||
mixers: {
|
||||
netId1: {
|
||||
dai: {
|
||||
mixerAddress: {
|
||||
'100': undefined,
|
||||
'500': undefined,
|
||||
'1000': undefined,
|
||||
'5000': undefined
|
||||
},
|
||||
tokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f',
|
||||
decimals: 18
|
||||
},
|
||||
eth: {
|
||||
mixerAddress: {
|
||||
'0.1': undefined,
|
||||
'1': undefined,
|
||||
'10': undefined,
|
||||
'100': undefined
|
||||
},
|
||||
decimals: 18
|
||||
}
|
||||
},
|
||||
netId42: {
|
||||
dai: {
|
||||
mixerAddress: {
|
||||
'100': '0x5D4538D2b07cD8Eb7b93c33B327f3E01A42e68d8',
|
||||
'500': undefined,
|
||||
'1000': undefined,
|
||||
'5000': undefined
|
||||
},
|
||||
tokenAddress: '0x8c158c7e57161dd4d3cb02bf1a3a97fcc78b75fd',
|
||||
decimals: 18
|
||||
},
|
||||
eth: {
|
||||
mixerAddress: {
|
||||
'0.1': '0xB7F60Bf8b969CE4B95Bb50a671860D99478C81Ee',
|
||||
'1': '0x27e94B8cfa33EA2b47E209Ba69804d44642B3545',
|
||||
'10': undefined,
|
||||
'100': undefined
|
||||
},
|
||||
decimals: 18
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
address: process.env.DAI_MIXER_ADDRESS,
|
||||
currency: 'dai',
|
||||
amount: '100'
|
||||
} ],
|
||||
defaultGasPrice: 2,
|
||||
gasOracleUrls: ['https://www.etherchain.org/api/gasPriceOracle', 'https://gasprice.poa.network/'],
|
||||
port: process.env.APP_PORT,
|
||||
//dai
|
||||
tokens: ['0x6b175474e89094c44da98b954eedeac495271d0f'],
|
||||
relayerServiceFee: Number(process.env.RELAYER_FEE)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
const CoinGecko = require('coingecko-api')
|
||||
const fetch = require('node-fetch')
|
||||
const { gasOracleUrls, defaultGasPrice } = require('../config')
|
||||
const { toWei } = require('web3-utils')
|
||||
const { tokens } = require('../config')
|
||||
const { gasOracleUrls, defaultGasPrice } = require('../config')
|
||||
const { getMainnetTokens } = require('./utils')
|
||||
|
||||
|
||||
class Fetcher {
|
||||
@ -16,19 +16,17 @@ class Fetcher {
|
||||
}
|
||||
}
|
||||
async fetchPrices() {
|
||||
const { tokenAddresses, currencyLookup } = getMainnetTokens()
|
||||
try {
|
||||
const CoinGeckoClient = new CoinGecko()
|
||||
const price = await CoinGeckoClient.simple.fetchTokenPrice({
|
||||
contract_addresses: tokens,
|
||||
contract_addresses: tokenAddresses,
|
||||
vs_currencies: 'eth',
|
||||
assetPlatform: 'ethereum'
|
||||
})
|
||||
const addressToSymbol = {
|
||||
'0x6b175474e89094c44da98b954eedeac495271d0f': 'dai'
|
||||
}
|
||||
this.ethPrices = Object.entries(price.data).reduce((acc, token) => {
|
||||
if (token[1].eth) {
|
||||
acc[addressToSymbol[token[0]]] = toWei(token[1].eth.toString())
|
||||
acc[currencyLookup[token[0]]] = toWei(token[1].eth.toString())
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
@ -1,7 +1,9 @@
|
||||
const express = require('express')
|
||||
const { netId, mixers, port, relayerServiceFee } = require('../config')
|
||||
const { netId, port, relayerServiceFee } = require('../config')
|
||||
const relayController = require('./relayController')
|
||||
const { fetcher, web3 } = require('./instances')
|
||||
const { getMixers } = require('./utils')
|
||||
const mixers = getMixers()
|
||||
|
||||
const app = express()
|
||||
app.use(express.json())
|
||||
|
30
src/utils.js
30
src/utils.js
@ -1,5 +1,5 @@
|
||||
const { isHexStrict, toBN, toWei } = require('web3-utils')
|
||||
const { mixers, relayerServiceFee } = require('../config')
|
||||
const { netId, mixers, relayerServiceFee } = require('../config')
|
||||
|
||||
function isValidProof(proof) {
|
||||
// validator expects `websnarkUtils.toSolidityInput(proof)` output
|
||||
@ -44,9 +44,12 @@ function isValidArgs(args) {
|
||||
}
|
||||
|
||||
function isKnownContract(contract) {
|
||||
for (let i = 0; i < mixers.length; i++) {
|
||||
if (mixers[i].address === contract) {
|
||||
return { valid: true, currency: mixers[i].currency, amount: mixers[i].amount }
|
||||
const mixers = getMixers()
|
||||
for (let currency of Object.keys(mixers)) {
|
||||
for (let amount of Object.keys(mixers[currency].mixerAddress)) {
|
||||
if (mixers[currency].mixerAddress[amount] === contract) {
|
||||
return { valid: true, currency, amount }
|
||||
}
|
||||
}
|
||||
}
|
||||
return { valid: false }
|
||||
@ -82,4 +85,21 @@ function isEnoughFee({ gas, gasPrices, currency, amount, refund, ethPrices, fee
|
||||
return { isEnough: true }
|
||||
}
|
||||
|
||||
module.exports = { isValidProof, isValidArgs, sleep, isKnownContract, isEnoughFee }
|
||||
function getMainnetTokens() {
|
||||
const tokens = mixers['netId1']
|
||||
const tokenAddresses = []
|
||||
const currencyLookup = {}
|
||||
Object.entries(tokens).map(([currency, data]) => {
|
||||
if (currency !== 'eth') {
|
||||
tokenAddresses.push(data.tokenAddress)
|
||||
currencyLookup[data.tokenAddress] = currency
|
||||
}
|
||||
})
|
||||
return { tokenAddresses, currencyLookup }
|
||||
}
|
||||
|
||||
function getMixers() {
|
||||
return mixers[`netId${netId}`]
|
||||
}
|
||||
|
||||
module.exports = { isValidProof, isValidArgs, sleep, isKnownContract, isEnoughFee, getMixers, getMainnetTokens }
|
||||
|
Loading…
Reference in New Issue
Block a user