Skip to content

Commit

Permalink
refactoring deploy transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed Jun 2, 2022
1 parent 1308e23 commit 317f725
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 77 deletions.
111 changes: 34 additions & 77 deletions scripts/deploy/truffle-wrapper/deploy/setupContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@ const ZeroAddress = '0x0000000000000000000000000000000000000000'

const { ethers } = require('hardhat')

async function callContract(instance, f) {
console.log('Calling contract ...')
const contractOwner = await instance.owner()
console.log('Contract Owner: ', contractOwner)
try {
const signer = await ethers.provider.getSigner(contractOwner)
const tx = await f(instance.connect(signer).populateTransaction)
console.log('Got tx', tx)
const res = await signer.sendTransaction(tx)
await res.wait()
} catch (err) {
console.log('Warning: TX fail')
console.log(err)
}
}

async function approveTemplate({
TemplateStoreManagerInstance,
roles,
templateAddress
} = {}) {
await callContract(TemplateStoreManagerInstance, a => a.approveTemplate(templateAddress, { gasLimit: 100000 }))
/*
const contractOwner = await TemplateStoreManagerInstance.owner()
try {
const tx = await TemplateStoreManagerInstance.connect(ethers.provider.getSigner(contractOwner)).approveTemplate(
Expand All @@ -19,19 +36,7 @@ async function approveTemplate({
console.log(e)
console.log('Approve failed for', templateAddress, roles.deployer, TemplateStoreManagerInstance.address)
}
}

async function callContract(instance, f) {
console.log('Calling contract ...')
const contractOwner = await instance.owner()
console.log('Contract Owner: ', contractOwner)
try {
const tx = await f(instance.connect(ethers.provider.getSigner(contractOwner)))
await tx.wait()
} catch (err) {
console.log('Warning: TX fail')
console.log(err)
}
*/
}

async function setupTemplate({ verbose, TemplateStoreManagerInstance, templateName, addressBook, roles } = {}) {
Expand Down Expand Up @@ -298,15 +303,9 @@ async function setupContracts({
}

if (addressBook.NFTUpgradeable && addressBook.DIDRegistry && addresses.stage < 3) {
const NFTInstance = artifacts.NFTUpgradeable

console.log('Set NFT minter : ' + addressBook.NFTUpgradeable)
const tx = await NFTInstance.connect(ethers.provider.getSigner(roles.deployer)).addMinter(
addressBook.DIDRegistry, { from: roles.deployer })
await tx.wait()
const tx2 = await NFTInstance.connect(ethers.provider.getSigner(roles.deployer)).setProxyApproval(
addressBook.DIDRegistry, true, { from: roles.deployer })
await tx2.wait()
await callContract(artifacts.NFTUpgradeable, a => a.addMinter(addressBook.DIDRegistry))
await callContract(artifacts.NFTUpgradeable, a => a.setProxyApproval(addressBook.DIDRegistry, true))
addresses.stage = 3
}

Expand Down Expand Up @@ -339,8 +338,7 @@ async function setupContracts({
}

if (addressBook.LockPaymentCondition && addresses.stage < 6) {
const tx = await artifacts.LockPaymentCondition.connect(ethers.provider.getSigner(roles.deployer)).reinitialize()
await tx.wait()
await callContract(artifacts.LockPaymentCondition, a => a.reinitialize())
await transferOwnership({
ContractInstance: artifacts.LockPaymentCondition,
name: 'LockPaymentCondition',
Expand All @@ -361,60 +359,34 @@ async function setupContracts({
}

if (addressBook.NFT721Upgradeable && addressBook.DIDRegistry && addresses.stage < 8) {
const NFT721Instance = artifacts.NFT721Upgradeable

console.log('Set NFT721 minter : ' + addressBook.NFT721Upgradeable)
const tx = await NFT721Instance.connect(ethers.provider.getSigner(roles.deployer)).addMinter(
addressBook.DIDRegistry, { from: roles.deployer })
await tx.wait()
await callContract(artifacts.NFT721Upgradeable, a => a.addMinter(addressBook.DIDRegistry))
addresses.stage = 8
}

if (addressBook.TransferDIDOwnershipCondition && addressBook.DIDRegistry && addresses.stage < 9) {
const DIDRegistryInstance = artifacts.DIDRegistry

console.log('TransferDIDOwnershipCondition : ' + addressBook.TransferDIDOwnershipCondition)
const tx = await DIDRegistryInstance.connect(ethers.provider.getSigner(roles.deployer)).setManager(
addressBook.TransferDIDOwnershipCondition, { from: roles.deployer })
await tx.wait()
await callContract(artifacts.DIDRegistry, a => a.setManager(addressBook.TransferDIDOwnershipCondition))
addresses.stage = 9
}

if (addressBook.TransferNFTCondition && addressBook.NFTUpgradeable && addresses.stage < 10) {
const NFTInstance = artifacts.NFTUpgradeable

console.log('TransferNFTCondition : ' + addressBook.TransferNFTCondition)
const tx = await NFTInstance.connect(ethers.provider.getSigner(roles.deployer)).setProxyApproval(
addressBook.TransferNFTCondition, true, { from: roles.deployer })
await tx.wait()
await callContract(artifacts.NFTUpgradeable, a => a.setProxyApproval(addressBook.TransferNFTCondition, true))
addresses.stage = 10
}

if (addressBook.TransferNFTCondition && addressBook.DIDRegistry && addresses.stage < 11) {
const NFTInstance = artifacts.NFTUpgradeable

console.log('DIDRegistry : ' + addressBook.DIDRegistry)
const tx = await NFTInstance.connect(ethers.provider.getSigner(roles.deployer)).setProxyApproval(
addressBook.DIDRegistry, true, { from: roles.deployer })
await tx.wait()

const tx2 = await NFTInstance.connect(ethers.provider.getSigner(roles.deployer)).addMinter(
addressBook.TransferNFTCondition, { from: roles.deployer })
await tx2.wait()
await callContract(artifacts.NFTUpgradeable, a => a.setProxyApproval(addressBook.DIDRegistry, true))
await callContract(artifacts.NFTUpgradeable, a => a.addMinter(addressBook.TransferNFTCondition))
addresses.stage = 11
}

if (addressBook.TransferNFT721Condition && addressBook.NFT721Upgradeable && addresses.stage < 12) {
const NFT721Instance = artifacts.NFT721Upgradeable

console.log('TransferNFT721Condition : ' + addressBook.TransferNFT721Condition)
const tx = await NFT721Instance.connect(ethers.provider.getSigner(roles.deployer)).setProxyApproval(
addressBook.TransferNFT721Condition, true, { from: roles.deployer })
await tx.wait()

const tx2 = await NFT721Instance.connect(ethers.provider.getSigner(roles.deployer)).addMinter(
addressBook.TransferNFT721Condition, { from: roles.deployer })
await tx2.wait()
await callContract(artifacts.NFT721Upgradeable, a => a.setProxyApproval(addressBook.TransferNFT721Condition, true))
await callContract(artifacts.NFT721Upgradeable, a => a.addMinter(addressBook.TransferNFT721Condition))
addresses.stage = 12
}

Expand Down Expand Up @@ -478,14 +450,10 @@ async function setupContracts({
const configMarketplaceFee = Number(process.env.NVM_MARKETPLACE_FEE || '0')
const configFeeReceiver = process.env.NVM_RECEIVER_FEE || ZeroAddress

const tx = await nvmConfig.connect(ethers.provider.getSigner(roles.deployer)).setMarketplaceFees(
configMarketplaceFee, configFeeReceiver, { from: roles.deployer }
)
await tx.wait()
await callContract(nvmConfig, a => a.setMarketplaceFees(configMarketplaceFee, configFeeReceiver))
console.log('[NeverminedConfig] Marketplace Fees set to : ' + configMarketplaceFee)

const tx2 = await nvmConfig.connect(ethers.provider.getSigner(roles.deployer)).setGovernor(roles.governorWallet, { from: roles.deployer })
await tx2.wait()
await callContract(nvmConfig, a => a.setGovernor(roles.governorWallet))

const isGovernor = await nvmConfig.isGovernor(roles.governorWallet)
console.log('Is governorWallet NeverminedConfig governor? ' + isGovernor)
Expand All @@ -499,24 +467,15 @@ async function setupContracts({

addresses.stage = 15
}
// const tx = await token.connect(ethers.provider.getSigner(roles.deployer)).revokeRole(
// web3.utils.toHex('minter').padEnd(66, '0'),
// roles.deployer,
// { from: roles.deployer }
// )
// await tx.wait()

if (addressBook.TransferNFTCondition && addressBook.AgreementStoreManager && addresses.stage < 16) {
const TransferNFTCondition = artifacts.TransferNFTCondition
console.log('Set TransferNFTCondition proxy : ' + addressBook.TransferNFTCondition)
console.log('Grant proxy role to AgreementStoreManager: ' + addressBook.AgreementStoreManager)

const tx = await TransferNFTCondition.connect(ethers.provider.getSigner(roles.deployer)).grantProxyRole(
addressBook.AgreementStoreManager, { from: roles.deployer })
await tx.wait()
await callContract(artifacts.TransferNFTCondition, a => a.grantProxyRole(addressBook.AgreementStoreManager))

await transferOwnership({
ContractInstance: TransferNFTCondition,
ContractInstance: artifacts.TransferNFTCondition,
name: 'TransferNFTCondition',
roles,
verbose
Expand All @@ -527,9 +486,7 @@ async function setupContracts({

if (addressBook.TransferNFT721Condition && addressBook.AgreementStoreManager && addresses.stage < 17) {
console.log('Set transfer nft721 condition proxy : ' + addressBook.TransferNFT721Condition)
const tx = await artifacts.TransferNFT721Condition.connect(ethers.provider.getSigner(roles.deployer)).grantProxyRole(
addressBook.AgreementStoreManager, { from: roles.deployer })
await tx.wait()
await callContract(artifacts.TransferNFT721Condition, a => a.grantProxyRole(addressBook.AgreementStoreManager))
await transferOwnership({
ContractInstance: artifacts.TransferNFT721Condition,
name: 'TransferNFT721Condition',
Expand Down
2 changes: 2 additions & 0 deletions scripts/deploy/truffle-wrapper/deployContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ async function deployContracts({ contracts: origContracts, verbose, testnet, mak
addresses
})

console.log('dssdsdsd')

await setupContracts({
web3,
addressBook,
Expand Down

0 comments on commit 317f725

Please sign in to comment.