fix steps

This commit is contained in:
Roman Storm 2020-11-04 17:33:56 -08:00
parent ee9fb9dcde
commit a23fd6faba
No known key found for this signature in database
GPG Key ID: 522F2A785F34E71F
4 changed files with 199 additions and 194 deletions

View File

@ -3,6 +3,12 @@
<diamond :active="!!data.deployerAddress" /> <diamond :active="!!data.deployerAddress" />
<div class="step-body"> <div class="step-body">
<h4>{{ data.title }}</h4> <h4>{{ data.title }}</h4>
<h6 v-if="data.domain">
ENS:
<a :href="domainUrl(data.expectedAddress)" target="_blank">{{
data.domain
}}</a>
</h6>
<i18n <i18n
v-if="data.deployerAddress" v-if="data.deployerAddress"
class="deployed" class="deployed"
@ -10,7 +16,9 @@
path="deployedBy" path="deployedBy"
> >
<template v-slot:link> <template v-slot:link>
<a href="#">{{ data.deployerAddress }}</a> <a :href="txHash(data.deployTransaction)" target="_blank">{{
data.deployerAddress
}}</a>
</template> </template>
</i18n> </i18n>
</div> </div>
@ -24,7 +32,7 @@
type="is-primary" type="is-primary"
outlined outlined
icon-left="tool" icon-left="tool"
:disabled="isNotLoggedIn" :disabled="isNotLoggedIn || !canDeploy(data.domain)"
@mousedown="(e) => e.preventDefault()" @mousedown="(e) => e.preventDefault()"
@click="onDeploy" @click="onDeploy"
> >
@ -50,6 +58,7 @@ export default {
}, },
computed: { computed: {
...mapGetters('provider', ['getProviderName']), ...mapGetters('provider', ['getProviderName']),
...mapGetters('steps', ['canDeploy']),
isNotLoggedIn() { isNotLoggedIn() {
return !this.getProviderName return !this.getProviderName
}, },
@ -59,7 +68,13 @@ export default {
// todo pass ens domain here // todo pass ens domain here
onDeploy(/* domain */) { onDeploy(/* domain */) {
// console.log('this.props', this.data) // console.log('this.props', this.data)
this.deployContract({ domain: this.data.domain }) this.deployContract({ action: this.data })
},
domainUrl(address) {
return `https://etherscan.io/address/${address}`
},
txHash(txHash) {
return `https://etherscan.io/tx/${txHash}`
}, },
}, },
} }

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import Web3 from 'web3' import Web3 from 'web3'
import { numberToHex } from 'web3-utils' import { hexToNumber, numberToHex } from 'web3-utils'
import deployerABI from '../abi/deployer.abi.json' import deployerABI from '../abi/deployer.abi.json'
import deploymentActions from '../static/deploymentActions.json' import deploymentActions from '../static/deploymentActions.json'
@ -9,10 +9,15 @@ const state = () => {
} }
const getters = { const getters = {
deployerContract: (state, getters, rootState, rootGetters) => { deployerContract: (state, getters, rootState, rootGetters) => (isProxy) => {
const { rpcUrls } = rootGetters['provider/getNetwork'] const { rpcUrls } = rootGetters['provider/getNetwork']
const web3 = new Web3(rpcUrls.Infura.url) const web3 = new Web3(rpcUrls.Infura.url)
return new web3.eth.Contract(deployerABI, deploymentActions.deployer) return new web3.eth.Contract(
deployerABI,
isProxy
? deploymentActions.deployer
: deploymentActions.actions[0].expectedAddress
)
}, },
} }
@ -21,20 +26,15 @@ const mutations = {}
const actions = { const actions = {
async deployContract( async deployContract(
{ state, dispatch, getters, rootGetters, commit, rootState }, { state, dispatch, getters, rootGetters, commit, rootState },
{ domain } { action }
) { ) {
try { try {
dispatch('loading/enable', {}, { root: true }) dispatch('loading/enable', {}, { root: true })
const isProxy = action.domain === 'deployer.deploy.tornadocash.eth'
const ethAccount = rootGetters['provider/getAccount'] const ethAccount = rootGetters['provider/getAccount']
const web3 = rootGetters['provider/getWeb3'] const web3 = rootGetters['provider/getWeb3']
const { salt } = deploymentActions
const { bytecode, expectedAddress } = deploymentActions.actions.filter(
(action) => {
return action.domain === domain
}
)[0]
const code = await web3.eth.getCode(expectedAddress) const code = await web3.eth.getCode(action.expectedAddress)
console.log('code', code) console.log('code', code)
if (code !== '0x') { if (code !== '0x') {
dispatch( dispatch(
@ -52,17 +52,39 @@ const actions = {
const gasPrice = rootGetters['gasPrice/fastGasPrice'] const gasPrice = rootGetters['gasPrice/fastGasPrice']
const data = getters.deployerContract.methods const data = getters
.deploy(bytecode, salt) .deployerContract(isProxy)
.methods.deploy(action.bytecode, deploymentActions.salt)
.encodeABI() .encodeABI()
const callParamsEstimate = {
method: 'eth_estimateGas',
params: [
{
from: ethAccount,
to: getters.deployerContract(isProxy)._address,
// gas: numberToHex(6e6),
gasPrice,
value: `0x0`,
data,
},
],
from: ethAccount,
}
const gasEstimate =
action.domain === 'deployer.deploy.tornadocash.eth'
? numberToHex(1e6)
: await dispatch('provider/sendRequest', callParamsEstimate, {
root: true,
})
const gasWithBuffer = Math.ceil(hexToNumber(gasEstimate) * 1.1)
console.log('xyu', gasWithBuffer)
const callParams = { const callParams = {
method: 'eth_sendTransaction', method: 'eth_sendTransaction',
params: [ params: [
{ {
from: ethAccount, from: ethAccount,
to: getters.deployerContract._address, to: getters.deployerContract(isProxy)._address,
gas: numberToHex(6e6), gas: numberToHex(gasWithBuffer),
gasPrice, gasPrice,
value: 0, value: 0,
data, data,

View File

@ -1,163 +1,59 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import Web3 from 'web3'
import deploymentActions from '../static/deploymentActions.json' import deploymentActions from '../static/deploymentActions.json'
const state = () => { const state = () => {
return { return {
steps: [ steps: deploymentActions.actions,
{
title: 'TORN token',
domain: 'torn.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Governance Implementation',
domain: 'governance-impl.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Governance Upgradable Proxy',
domain: 'governance.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Anonymity mining: Verifier (1/3)',
domain: 'reward-verifier.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Anonymity mining: Verifier (2/3)',
domain: 'withdraw-verifier.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Anonymity mining: Verifier (3/3)',
domain: 'tree-update-verifier.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Anonymity mining: Swap contract for private points',
domain: 'reward-swap.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Poseidon hasher for two arguments',
domain: 'poseidon2.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Poseidon hasher for three arguments',
domain: 'poseidon3.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'A proxy contract for ETH Tornado.cash instances',
domain: 'tornado-proxy.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Anonymity mining: TornadoTrees contract',
domain: 'tornado-trees.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Anonymity mining: Miner contract',
domain: 'mining-v2.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Airdrop contract',
domain: 'voucher.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Team vestings (1/5)',
domain: 'team1.vesting.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Team vestings (2/5)',
domain: 'team2.vesting.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Team vestings (3/5)',
domain: 'team2.vesting.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Team vestings (4/5)',
domain: 'team2.vesting.deploy.tornadocash.eth',
deployerAddress: null,
},
{
title: 'Team vestings (5/5)',
domain: 'team2.vesting.deploy.tornadocash.eth',
deployerAddress: null,
},
{
domain: 'mining-v3.vesting.deploy.tornadocash.eth',
deployerAddress: null,
title: 'Vesting for the future anonymity mining (V3 release)',
},
{
domain: 'governance.vesting.deploy.tornadocash.eth',
deployerAddress: null,
title: 'Vesting for the governance itself',
},
],
} }
} }
const getters = { const getters = {
deployedCount: (state) => { deployedCount: (state) => {
const deployed = state.steps.filter((step) => { const deployed = state.steps.filter((step) => !!step.deployerAddress).length
return !!step.deployerAddress
}).length
const all = state.steps.length const all = state.steps.length
return `${deployed}/${all}` return `${deployed}/${all}`
}, },
canDeploy: (state) => (domain) => {
const { dependsOn } = state.steps.find((s) => s.domain === domain)
return dependsOn.every(
(d) => !!state.steps.find((s) => s.domain === d).deployerAddress
)
},
} }
const SET_DEPLOYER = 'SET_DEPLOYER' const SET_DEPLOYER = 'SET_DEPLOYER'
const mutations = { const mutations = {
[SET_DEPLOYER](state, { stepIndex, deployerAddress }) { [SET_DEPLOYER](state, { stepIndex, deployerAddress, deployTransaction }) {
this._vm.$set(state.steps[stepIndex], 'deployerAddress', deployerAddress) this._vm.$set(state.steps[stepIndex], 'deployerAddress', deployerAddress)
this._vm.$set(
state.steps[stepIndex],
'deployTransaction',
deployTransaction
)
}, },
} }
const actions = { const actions = {
async fetchDeploymentStatus({ state, dispatch, commit, rootGetters }) { async fetchDeploymentStatus({ state, dispatch, commit, rootGetters }) {
// const deployContract = rootGetters['deploy/deployerContract'] const deployContract = rootGetters['deploy/deployerContract'](false)
// const events = await deployContract.getPastEvents('Deployed', { const events = await deployContract.getPastEvents('Deployed', {
// // filter: { fromBlock: 21895260,
// // addr: ['0xd51154a046d2af2c572e850a4ed5bd65db2d83f0'], toBlock: 'latest',
// // }, })
// fromBlock: 21895260, for (const event of events) {
// toBlock: 'latest', const step = state.steps.find(
// }) (s) => s.expectedAddress === event.returnValues.addr
// console.log('events', events) )
const { rpcUrls } = rootGetters['provider/getNetwork']
const web3 = new Web3(rpcUrls.Infura.url)
try { if (!step) {
for (const [stepIndex, step] of state.steps.entries()) { continue
const { expectedAddress } = deploymentActions.actions.find((action) => {
return action.domain === step.domain
})
const code = await web3.eth.getCode(expectedAddress)
if (code !== '0x') {
// todo collect deployerAddress from chain
commit(SET_DEPLOYER, {
stepIndex,
deployerAddress: '0x03Ebd0748Aa4D1457cF479cce56309641e0a98F5',
})
}
} }
} catch (e) { console.log('event', event)
console.error('fetchDeploymentStatus', e.message) commit(SET_DEPLOYER, {
stepIndex: state.steps.indexOf(step),
deployerAddress: event.returnValues.sender,
deployTransaction: event.transactionHash,
})
} }
}, },
} }