Skip to content

Commit

Permalink
Use gas price from truffle config file (#228)
Browse files Browse the repository at this point in the history
* Use gas price from truffle config file

* Fix lint
  • Loading branch information
izqui committed Oct 23, 2018
1 parent 5aa4a65 commit 7f10200
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
},
"aragon": {
"clientVersion": "526a1966d547f719030dcdd7867a5f5ea3808312",
"clientPort": "3000"
"clientPort": "3000",
"defaultGasPrice": "10000000000"
}
}
6 changes: 4 additions & 2 deletions src/acl/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = (web3) => {
const DEFAULT_GAS_PRICE = require('../../package.json').aragon.defaultGasPrice

module.exports = ({ web3, network }) => {
const getACL = async (repoAddr) => {
const repo = new web3.eth.Contract(require('@aragon/os/build/contracts/AragonApp').abi, repoAddr)
const daoAddr = await repo.methods.kernel().call()
Expand All @@ -24,7 +26,7 @@ module.exports = (web3) => {
to: acl.options.address,
data: call.encodeABI(),
gas: web3.utils.toHex(5e5),
gasPrice: web3.utils.toHex(web3.utils.toWei('15', 'gwei'))
gasPrice: network.gasPrice || DEFAULT_GAS_PRICE
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apm_cmds/grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.handler = async function ({
apmOptions.ensRegistryAddress = apmOptions['ens-registry']

const apm = await APM(web3, apmOptions)
const acl = ACL(web3)
const acl = ACL({ web3, network })

const repo = await apm.getRepository(module.appName).catch(() => null)
if (repo === null) {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/apm_cmds/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const deploy = require('../deploy')
const startIPFS = require('../ipfs')
const getRepoTask = require('../dao_cmds/utils/getRepoTask')

const DEFAULT_GAS_PRICE = require('../../../package.json').aragon.defaultGasPrice
const MANIFEST_FILE = 'manifest.json'
const ARTIFACT_FILE = 'artifact.json'
const SOLIDITY_FILE = 'code.sol'
Expand Down Expand Up @@ -504,7 +505,7 @@ exports.task = function ({
)

transaction.from = from
transaction.gasPrice = '19000000000' // 19 gwei
transaction.gasPrice = network.gasPrice || DEFAULT_GAS_PRICE

ctx.receipt = await web3.eth.sendTransaction(transaction)
} catch (e) {
Expand Down
14 changes: 12 additions & 2 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { compileContracts } = require('../helpers/truffle-runner')
const { findProjectRoot } = require('../util')
const { ensureWeb3 } = require('../helpers/web3-fallback')
const deployArtifacts = require('../helpers/truffle-deploy-artifacts')
const DEFAULT_GAS_PRICE = require('../../package.json').aragon.defaultGasPrice

exports.command = 'deploy [contract]'

Expand Down Expand Up @@ -75,11 +76,20 @@ exports.task = async ({ reporter, network, cwd, contract, init, web3, apmOptions

const contract = new web3.eth.Contract(abi, { data: bytecode })
const accounts = await web3.eth.getAccounts()

const deployTx = contract.deploy({ arguments: processedInit })
const gas = await deployTx.estimateGas()

const deployPromise = deployTx.send({ from: accounts[0], gas, gasPrice: '19000000000' }) // 19 gwei
deployPromise.on('transactionHash', (transactionHash) => ctx.transactionHash = transactionHash)
const args = {
from: accounts[0],
gasPrice: network.gasPrice || DEFAULT_GAS_PRICE,
gas
}

const deployPromise = deployTx.send(args)
deployPromise.on('transactionHash', (transactionHash) => {
ctx.transactionHash = transactionHash
})
const instance = await deployPromise

if (!instance.options.address) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/truffle-deploy-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ module.exports = async (contractArtifacts) => {
compiler,
flattenedCode
}
}
}

0 comments on commit 7f10200

Please sign in to comment.