Skip to content

Commit

Permalink
refactor this
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Damer committed May 18, 2023
1 parent 29a9b99 commit e4705ae
Showing 1 changed file with 94 additions and 217 deletions.
311 changes: 94 additions & 217 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,75 @@ import { utils } from 'ethers'
import { version } from '../package.json'
import prompt from 'prompt'

const regexes = {
ethereumAddress: /^0x[a-fA-F0-9]{40}$/,
const ethereumRegex = /^0x[a-fA-F0-9]{40}$/

function parseError(error: unknown) {
error instanceof Error ? error.message : error
}

async function deployContact({
constructorArguments,
contractName,
chainName,
initializer = 'initialize',
}: {
constructorArguments: string[]
contractName: string
chainName: string
initializer?: string
}) {
console.log('---------------')
console.log(
`Deploying ${contractName} with arguments ${constructorArguments}...`
)
const contractFactory = await ethers.getContractFactory(contractName)
const contract = await upgrades.deployProxy(
contractFactory,
constructorArguments,
{ initializer }
)
console.log(
'Deploy tx gas price:',
utils.formatEther(contract.deployTransaction.gasPrice || 0)
)
console.log(
'Deploy tx gas limit:',
utils.formatEther(contract.deployTransaction.gasLimit)
)
await contract.deployed()

const contractImplementationAddress =
await upgrades.erc1967.getImplementationAddress(contract.address)
const contractAdminAddress = await upgrades.erc1967.getAdminAddress(
contract.address
)

console.log(`${contractName} Proxy address: `, contract.address)
console.log('Implementation address: ', contractImplementationAddress)
console.log('Admin address: ', contractAdminAddress)

console.log('Wait for 1 minute to make sure blockchain is updated')
await new Promise((resolve) => setTimeout(resolve, 15 * 1000))

console.log(`Verifying ${contractName} contract`)
try {
await run('verify:verify', { address: contractImplementationAddress })
} catch (err) {
console.error('Error verifying contract on Etherscan:', parseError(err))
}

// Print out the information
console.log(`${contractName} deployed and verified!`)
console.log(`${contractName} contract address: `, contract.address)
console.log(
'Scanner URL:',
`https://${
chainName === 'polygon' ? '' : `${chainName}.`
}polygonscan.com/address/${contract.address}`
)
console.log('---------------')

return contract
}

async function main() {
Expand All @@ -22,12 +89,12 @@ async function main() {
properties: {
forwarder: {
required: true,
pattern: regexes.ethereumAddress,
pattern: ethereumRegex,
default: GSN_MUMBAI_FORWARDER_CONTRACT_ADDRESS,
},
ketlAttestation: {
required: true,
pattern: regexes.ethereumAddress,
pattern: ethereumRegex,
default: '0xc98cD68E59D8C25Fc2FaF1A09Ea8010Ad4D6D52f',
},
},
Expand All @@ -50,233 +117,43 @@ async function main() {
string,
string
]
const profilesContract = await deployContact({
constructorArguments: profilesConstructorArguments,
contractName: 'Profiles',
chainName,
})

const profilesContractName = 'Profiles'
console.log(`Deploying ${profilesContractName}...`)
const profilesFactory = await ethers.getContractFactory(profilesContractName)
const profilesContract = await upgrades.deployProxy(
profilesFactory,
profilesConstructorArguments,
{
initializer: 'initialize',
}
)
console.log(
'Deploy tx gas price:',
utils.formatEther(profilesContract.deployTransaction.gasPrice || 0)
)
console.log(
'Deploy tx gas limit:',
utils.formatEther(profilesContract.deployTransaction.gasLimit)
)
await profilesContract.deployed()

const profilesImplementationAddress =
await upgrades.erc1967.getImplementationAddress(profilesContract.address)
const profilesAdminAddress = await upgrades.erc1967.getAdminAddress(
profilesContract.address
)

console.log('Profiles Proxy address:', profilesContract.address)
console.log('Implementation address:', profilesImplementationAddress)
console.log('Admin address:', profilesAdminAddress)

console.log('Wait for 1 minute to make sure blockchain is updated')
await new Promise((resolve) => setTimeout(resolve, 15 * 1000))

// Try to verify the contract on Etherscan
console.log('Verifying contract on Etherscan')
try {
await run('verify:verify', {
address: profilesImplementationAddress,
})
} catch (err) {
console.log(
'Error verifiying contract on Etherscan:',
err instanceof Error ? err.message : err
)
}

// Print out the information
console.log(`${profilesContractName} deployed and verified on Etherscan!`)
console.log('Karma contract address:', profilesContract.address)

// Karma

const karmaConstructorArguments = ['Kekl', 'KEK', deployer.address] as [
string,
string,
string
]

const karmaContractName = 'Karma'
console.log(`Deploying ${karmaContractName}...`)
const karmaFactory = await ethers.getContractFactory(karmaContractName)
const karmaContract = await upgrades.deployProxy(
karmaFactory,
karmaConstructorArguments,
{
initializer: 'initializeKarma',
}
)
console.log(
'Deploy tx gas price:',
utils.formatEther(karmaContract.deployTransaction.gasPrice || 0)
)
console.log(
'Deploy tx gas limit:',
utils.formatEther(karmaContract.deployTransaction.gasLimit)
)
await karmaContract.deployed()

const karmaImplementationAddress =
await upgrades.erc1967.getImplementationAddress(karmaContract.address)
const karmaAdminAddress = await upgrades.erc1967.getAdminAddress(
karmaContract.address
)

console.log('Karma Proxy address:', karmaContract.address)
console.log('Implementation address:', karmaImplementationAddress)
console.log('Admin address:', karmaAdminAddress)

console.log('Wait for 1 minute to make sure blockchain is updated')
await new Promise((resolve) => setTimeout(resolve, 15 * 1000))

// Try to verify the contract on Etherscan
console.log('Verifying contract on Etherscan')
try {
await run('verify:verify', {
address: karmaImplementationAddress,
})
} catch (err) {
console.log(
'Error verifiying contract on Etherscan:',
err instanceof Error ? err.message : err
)
}

// Print out the information
console.log(`${karmaContractName} deployed and verified on Etherscan!`)
console.log('Karma contract address:', karmaContract.address)

// Feeds
const karmaConstructorArguments = ['Kekl', 'KEK', deployer.address]
const karmaContract = await deployContact({
constructorArguments: karmaConstructorArguments,
contractName: 'Karma',
chainName,
initializer: 'initializeKarma',
})

const feedsConstructorArguments = [ketlAttestation, deployer.address] as [
string,
string
]
const feedsContract = await deployContact({
constructorArguments: feedsConstructorArguments,
contractName: 'Feeds',
chainName,
})

const feedsContractName = 'Feeds'
console.log(`Deploying ${feedsContractName}...`)
const feedsFactory = await ethers.getContractFactory(feedsContractName)
const feedsContract = await upgrades.deployProxy(
feedsFactory,
feedsConstructorArguments,
{
initializer: 'initialize',
}
)
console.log(
'Deploy tx gas price:',
utils.formatEther(feedsContract.deployTransaction.gasPrice || 0)
)
console.log(
'Deploy tx gas limit:',
utils.formatEther(feedsContract.deployTransaction.gasLimit)
)
await feedsContract.deployed()

const feedsImplementationAddress =
await upgrades.erc1967.getImplementationAddress(feedsContract.address)
const feedsAdminAddress = await upgrades.erc1967.getAdminAddress(
feedsContract.address
)

console.log('Feeds Proxy address:', feedsContract.address)
console.log('Implementation address:', feedsImplementationAddress)
console.log('Admin address:', feedsAdminAddress)

console.log('Wait for 1 minute to make sure blockchain is updated')
await new Promise((resolve) => setTimeout(resolve, 15 * 1000))

// Try to verify the contract on Etherscan
console.log('Verifying contract on Etherscan')
try {
await run('verify:verify', {
address: feedsImplementationAddress,
})
} catch (err) {
console.log(
'Error verifiying contract on Etherscan:',
err instanceof Error ? err.message : err
)
}

// Print out the information
console.log(`${karmaContractName} deployed and verified on Etherscan!`)
console.log('Karma contract address:', karmaContract.address)

// OBSS

const constructorArguments = [
// OBSSStorage
const obssConstructorArguments = [
forwarder,
version,
karmaContract.address,
profilesContract.address,
feedsContract.address,
] as [string, string, string, string, string]

const contractName = 'OBSSStorage'
console.log(`Deploying ${contractName}...`)
const factory = await ethers.getContractFactory(contractName)
const contract = await upgrades.deployProxy(factory, constructorArguments, {
initializer: 'initialize',
await deployContact({
constructorArguments: obssConstructorArguments,
contractName: 'OBSSStorage',
chainName,
})

console.log(
'Deploy tx gas price:',
utils.formatEther(contract.deployTransaction.gasPrice || 0)
)
console.log(
'Deploy tx gas limit:',
utils.formatEther(contract.deployTransaction.gasLimit)
)
await contract.deployed()

const implementationAddress = await upgrades.erc1967.getImplementationAddress(
contract.address
)
const adminAddress = await upgrades.erc1967.getAdminAddress(contract.address)

console.log('OBSSStorage Proxy address:', contract.address)
console.log('Implementation address:', implementationAddress)
console.log('Admin address:', adminAddress)

console.log('Wait for 1 minute to make sure blockchain is updated')
await new Promise((resolve) => setTimeout(resolve, 15 * 1000))

// Try to verify the contract on Etherscan
console.log('Verifying contract on Etherscan')
try {
await run('verify:verify', {
address: implementationAddress,
})
} catch (err) {
console.log(
'Error verifiying contract on Etherscan:',
err instanceof Error ? err.message : err
)
}

// Print out the information
console.log(`${contractName} deployed and verified on Etherscan!`)
console.log('Contract address:', contract.address)
console.log(
'Etherscan URL:',
`https://${
chainName !== 'polygon' ? `${chainName}.` : ''
}polygonscan.com/address/${contract.address}`
)
}

main().catch((error) => {
Expand Down

0 comments on commit e4705ae

Please sign in to comment.