Skip to content

Commit

Permalink
sub tasks not working
Browse files Browse the repository at this point in the history
  • Loading branch information
okwme committed Oct 3, 2019
1 parent 1274914 commit 1146e6b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 39 deletions.
35 changes: 26 additions & 9 deletions helpers/deployAllContracts.js
Expand Up @@ -23,6 +23,7 @@ const _overwrites = {
async function deployAllContracts({overwrites, accounts, artifacts, web3, chainId, networks, verbose}) {
overwrites = overwrites || _overwrites
networks = networks || _networks
chainId = chainId || await web3.eth.net.getId()

var Reversi = artifacts.require('./Reversi.sol')
var Clovers = artifacts.require('./Clovers.sol')
Expand All @@ -41,8 +42,24 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
clubToken,
tx

function alreadyDeployed(contractName) {
return networks && networks[contractName] && networks[contractName][chainId] && networks[contractName][chainId].address
async function alreadyDeployed(contractName) {
let address = networks && networks[contractName] && networks[contractName][chainId] && networks[contractName][chainId].address
if (!address) {
// console.log('no address')
return false
}
let code = await web3.eth.getCode(address)
if (code === '0x') {
// console.log('no code')
return false
}
// let contract = eval(contractName)
// console.log(contractName, contract._json.bytecode.length, code.length, contract._json.bytecode === code)
// if (code !== contract._json.bytecode) {
// console.log('code doeesnt match')
// return false
// }
return address
}

try {
Expand All @@ -51,7 +68,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
// Deploy Clovers.sol (NFT)
// -w NFT name
// -w NFT symbol
let cloversAddress = alreadyDeployed('Clovers')
let cloversAddress = await alreadyDeployed('Clovers')
if (overwrites['Clovers'] || !cloversAddress) {
clovers = await Clovers.new('Clovers', 'CLVR')
tx = await web3.eth.getTransactionReceipt(clovers.transactionHash)
Expand All @@ -64,7 +81,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI

// Deploy CloversMetadata.sol
// -w Clovers address
let cloversMetadataAddress = alreadyDeployed('CloversMetadata')
let cloversMetadataAddress = await alreadyDeployed('CloversMetadata')
if (overwrites['CloversMetadata'] || !cloversMetadataAddress){
cloversMetadata = await CloversMetadata.new(clovers.address)
tx = await web3.eth.getTransactionReceipt(cloversMetadata.transactionHash)
Expand All @@ -79,7 +96,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
// -w ERC20 name
// -w ERC20 symbol
// -w ERC20 decimals
let clubTokenAddress = alreadyDeployed('ClubToken')
let clubTokenAddress = await alreadyDeployed('ClubToken')
if (overwrites['ClubToken'] || !clubTokenAddress) {
clubToken = await ClubToken.new('CloverCoin', 'CLC', decimals)
tx = await web3.eth.getTransactionReceipt(clubToken.transactionHash)
Expand All @@ -91,7 +108,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
}

// Deploy Reversi.sol
let reversiAddress = alreadyDeployed('Reversi')
let reversiAddress = await alreadyDeployed('Reversi')
if (overwrites['Reversi'] || overwrites['CloversController'] || !reversiAddress){
reversi = await Reversi.new()
tx = await web3.eth.getTransactionReceipt(reversi.transactionHash)
Expand All @@ -103,7 +120,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
}
// Deploy ClubTokenController.sol
// -w ClubToken address
let clubTokenControllerAddress = alreadyDeployed('ClubTokenController')
let clubTokenControllerAddress = await alreadyDeployed('ClubTokenController')
if (overwrites['ClubTokenController'] || !clubTokenControllerAddress){
clubTokenController = await ClubTokenController.new(clubToken.address)
tx = await web3.eth.getTransactionReceipt(clubTokenController.transactionHash)
Expand All @@ -115,7 +132,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
}

// Deploy CloversController.sol
let cloversControllerAdress = alreadyDeployed('CloversController')
let cloversControllerAdress = await alreadyDeployed('CloversController')
if (overwrites['CloversController'] || overwrites['Reversi'] || !cloversControllerAdress) {
// -link w cloversController
// CloversController.network.links["__5b17bcb97970e1ce5ed9096dcff7f451d7_+"] = reversi.address;
Expand Down Expand Up @@ -144,7 +161,7 @@ async function deployAllContracts({overwrites, accounts, artifacts, web3, chainI
// -w ClubToken address
// -w ClubTokenController address
// -w CloversController address
let simpleCloversMarketAddress = alreadyDeployed('SimpleCloversMarket')
let simpleCloversMarketAddress = await alreadyDeployed('SimpleCloversMarket')
if (overwrites['SimpleCloversMarket'] || !simpleCloversMarketAddress){
simpleCloversMarket = await SimpleCloversMarket.new(
clovers.address,
Expand Down
12 changes: 6 additions & 6 deletions helpers/migVals.js
Expand Up @@ -88,7 +88,7 @@ async function updateCloversController({
}

var currentPayMultiplier = await cloversController.payMultiplier()
if (!currentPayMultiplier.eq(vals.payMultiplier)) {
if (!currentPayMultiplier.eq(utils.toBN(vals.payMultiplier))) {
verbose && console.log(_ + `cloversController.updatePayMultipier from ${currentPayMultiplier} to ${vals.payMultiplier}`)
var tx = await cloversController.updatePayMultipier(vals.payMultiplier)
verbose && gasToCash(tx.receipt.gasUsed)
Expand All @@ -99,7 +99,7 @@ async function updateCloversController({


var currentPriceMultiplier = await cloversController.priceMultiplier()
if (!currentPriceMultiplier.eq(vals.priceMultiplier)) {
if (!currentPriceMultiplier.eq(utils.toBN(vals.priceMultiplier))) {
verbose && console.log(_ + `cloversController.updatePriceMultipier from ${currentPriceMultiplier} to ${vals.priceMultiplier}`)
var tx = await cloversController.updatePriceMultipier(vals.priceMultiplier)
verbose && gasToCash(tx.receipt.gasUsed)
Expand All @@ -110,7 +110,7 @@ async function updateCloversController({


var currentBasePrice = await cloversController.basePrice()
if (!currentBasePrice.eq(vals.basePrice)) {
if (!currentBasePrice.eq(utils.toBN(vals.basePrice))) {
verbose && console.log(_ + `cloversController.updateBasePrice from ${currentBasePrice} to ${vals.basePrice}`)
var tx = await cloversController.updateBasePrice(vals.basePrice)
verbose && gasToCash(tx.receipt.gasUsed)
Expand Down Expand Up @@ -169,7 +169,7 @@ async function updateClubTokenController({
// )

var currentReserveRatio = await clubTokenController.reserveRatio()
if (!currentReserveRatio.eq(vals.reserveRatio)) {
if (!currentReserveRatio.eq(utils.toBN(vals.reserveRatio))) {
verbose && console.log(_ + `clubTokenController.updateReserveRatio from ${currentReserveRatio} to ${vals.reserveRatio}`)
var tx = await clubTokenController.updateReserveRatio(vals.reserveRatio)
verbose && gasToCash(tx.receipt.gasUsed)
Expand All @@ -179,7 +179,7 @@ async function updateClubTokenController({
}

var currentVirtualSupply = await clubTokenController.virtualSupply()
if (!currentVirtualSupply.eq(vals.virtualSupply)) {
if (!currentVirtualSupply.eq(utils.toBN(vals.virtualSupply))) {
verbose && console.log(_ + `clubTokenController.updateVirtualSupply from ${currentVirtualSupply.toString()} to ${vals.virtualSupply.toString()}`)
var tx = await clubTokenController.updateVirtualSupply(vals.virtualSupply)
verbose && gasToCash(tx.receipt.gasUsed)
Expand All @@ -189,7 +189,7 @@ async function updateClubTokenController({
}

var currentVirtualBalance = await clubTokenController.virtualBalance()
if (!currentVirtualBalance.eq(vals.virtualBalance)) {
if (!currentVirtualBalance.eq(utils.toBN(vals.virtualBalance))) {
verbose && console.log(_ + `clubTokenController.updateVirtualBalance from ${currentVirtualBalance.toString()} to ${vals.virtualBalance.toString()}`)
var tx = await clubTokenController.updateVirtualBalance(vals.virtualBalance)
verbose && gasToCash(tx.receipt.gasUsed)
Expand Down
6 changes: 4 additions & 2 deletions helpers/updateAllContracts.js
Expand Up @@ -108,15 +108,17 @@ async function updateAllContracts({
totalGas = await updateCloversController({
cloversController,
clubTokenController,
simpleCloversMarket
simpleCloversMarket,
verbose
})

/* ----------------------------------------------------------------------------------------------------------- */
// Update ClubTokenController.sol
totalGas = await updateClubTokenController({
clubTokenController,
simpleCloversMarket,
accounts
accounts,
verbose
})

/* ----------------------------------------------------------------------------------------------------------- */
Expand Down
32 changes: 16 additions & 16 deletions networks.json
Expand Up @@ -394,8 +394,8 @@
"transactionHash": null
},
"1234": {
"address": "0xDB7DF1b23B47AD6349Ee8149a7FBc8e1644C35Ae",
"transactionHash": "0x34a6130b120f18af6ffa7c3c639bfe010731af53fb187a7c7a47d0cb0a42d9ad"
"address": "0x007446Aa60789901216cB34a4c44914197459A65",
"transactionHash": "0xbf69e4ff03e8418c15bc6ee405f6e676ed248aa15300dd9a05af5d09e011e635"
},
"1569787081442": {
"events": {
Expand Down Expand Up @@ -665,11 +665,11 @@
}
},
"links": {
"\\$b2fca45de5ef9c5a18731e56fbc51add96\\$": "0x233e059333C1fFD31EA5625ACd79e4Bad72d4293",
"Reversi": "0x233e059333C1fFD31EA5625ACd79e4Bad72d4293"
"\\$b2fca45de5ef9c5a18731e56fbc51add96\\$": "0x6A72818BB8C844664678b8f47ee84F75753Fa2e2",
"Reversi": "0x6A72818BB8C844664678b8f47ee84F75753Fa2e2"
},
"address": "0xDE2426bC3970bc49977148980fb5851263763c27",
"transactionHash": "0x75fa8881266c826bcda94286ec03ac7ea9f470821150728bb467f5760d629f59"
"address": "0x72C5D60cbD966dBD7dbCD494bce6985D161D3172",
"transactionHash": "0xc93b58084c3144ffdd6aea238198b829873982d45c308871cd29acfe93ad69a9"
},
"1569787081442": {
"events": {},
Expand Down Expand Up @@ -700,8 +700,8 @@
"transactionHash": null
},
"1234": {
"address": "0xc93Dbed8F19Ccf8c8533fBb90add06522ed173B2",
"transactionHash": "0x6baa0152822d34ddc27c506f9c4e3539f3cf520759df154ef129aa7b9d24da93"
"address": "0xcA80c7dAE21DF90820927Ee75d779b5347706876",
"transactionHash": "0x3da4960129f8815e433c1e4533fccd0064ffdd7895c581c91ffa6034fc491e27"
},
"1569787081442": {
"events": {},
Expand Down Expand Up @@ -730,8 +730,8 @@
"transactionHash": null
},
"1234": {
"address": "0x40Ab34CD8acf2DEd490e9C6299007CbbAFA44B8e",
"transactionHash": "0xc439694a1ac8495e2d0154585f13f72f32ed7ddb2618ebec279134c0ba6e0c50"
"address": "0xb21E0aa4E481e50FCaaFcdf09FFAB38CF90292eB",
"transactionHash": "0x0f001edd28591510eb462b9f98bc60e0665322124e1adfe6f2ed107d03a8b75a"
},
"1569787081442": {
"events": {},
Expand Down Expand Up @@ -1129,8 +1129,8 @@
"transactionHash": null
},
"1234": {
"address": "0x13796C0Eeb50eFE4fE068CFfd224f8C24F2C856B",
"transactionHash": "0xc1fc23543c34c85ef0ebdc4f0f25016c678bf1bee6fced72112aac46e4577116"
"address": "0x368227359CB6CB3FC8c30057B7ffc8Dda817B675",
"transactionHash": "0x8c287f21424860d504c82c73c90f38d3140311a765796ed0b96df496bab3736c"
},
"1569787081442": {
"events": {
Expand Down Expand Up @@ -1308,8 +1308,8 @@
"transactionHash": null
},
"1234": {
"address": "0x233e059333C1fFD31EA5625ACd79e4Bad72d4293",
"transactionHash": "0x282c6a84a71a7ac8102493ddf18530eebfc992b88988271dcd33447722d21f7f"
"address": "0x6A72818BB8C844664678b8f47ee84F75753Fa2e2",
"transactionHash": "0x1193a56253fad05e29fdccb5db5f9f844a1a6b1514405f450266e0c66d220070"
},
"1569787081442": {
"events": {},
Expand Down Expand Up @@ -1566,8 +1566,8 @@
"transactionHash": null
},
"1234": {
"address": "0x034F318E8C96e666F80b582060047dE1F2bb9107",
"transactionHash": "0x0d40b499c687b765ac6ed3a34fae034661593193cbcb3ab3ab59239933797a77"
"address": "0xfc33a6aCc6AF169B390efb8228F5BF8DD8f7557E",
"transactionHash": "0x5749d4d7bd99dc89ecd011975db7aeb5db660836a038c06f23256b088760962d"
},
"1569787081442": {
"events": {
Expand Down
9 changes: 9 additions & 0 deletions tasks/deploy-update.js
@@ -0,0 +1,9 @@
usePlugin("@nomiclabs/buidler-truffle5");
// import { internalTask, task, types } from "../internal/core/config/config-env";

task("deployUpdate", "Deploy and Update Contracts")
.setAction(async (taskArgs, env) => {
console.log({internalTask})
await internalTask('deploy')
await internalTask('update')
})
3 changes: 1 addition & 2 deletions tasks/deploy.js
Expand Up @@ -21,7 +21,6 @@ const overwrites = {
task("deploy", "Deploys contracts")
.setAction(async (taskArgs, env) => {
const accounts = await web3.eth.getAccounts();
const chainId = await web3.eth.net.getId()
var {
reversi,
clovers,
Expand All @@ -30,7 +29,7 @@ task("deploy", "Deploys contracts")
clubTokenController,
simpleCloversMarket,
clubToken
} = await deployAllContracts({overwrites, accounts, artifacts, web3, chainId, verbose})
} = await deployAllContracts({overwrites, accounts, artifacts, web3, verbose})
// save contract info inside of ./truffle/
await saveNetworks([reversi,
clovers,
Expand Down
1 change: 1 addition & 0 deletions tasks/index.js
Expand Up @@ -2,3 +2,4 @@
require('./deploy.js')
require('./update.js')
require('./try-sign.js')
require('./deploy-update.js')
10 changes: 6 additions & 4 deletions tasks/update.js
@@ -1,12 +1,13 @@
usePlugin("@nomiclabs/buidler-truffle5");
var networks =require('../networks.json')
var { deployAllContracts } = require('../helpers/deployAllContracts')
var { updateAllContracts } = require('../helpers/updateAllContracts')

const verbose = true

task('update', 'Updates contract values').
setAction(async (taskArgs, env) => {
const accounts = await web3.eth.getAccounts()
const chainId = env.config.networks.chainId

var {
reversi,
clovers,
Expand All @@ -15,7 +16,7 @@ setAction(async (taskArgs, env) => {
clubTokenController,
simpleCloversMarket,
clubToken
} = await deployAllContracts({accounts, artifacts, web3, chainId, networks})
} = await deployAllContracts({accounts, artifacts, web3})

await updateAllContracts({
clovers,
Expand All @@ -24,7 +25,8 @@ setAction(async (taskArgs, env) => {
clubTokenController,
simpleCloversMarket,
clubToken,
accounts
accounts,
verbose
})

})

0 comments on commit 1146e6b

Please sign in to comment.