-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script and task for migration (#208)
- Loading branch information
1 parent
3709707
commit c868680
Showing
52 changed files
with
26,334 additions
and
5,721 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ contractsInfo.json | |
|
||
# Gas reports | ||
gas-report.txt | ||
|
||
# Tenderly | ||
tenderly.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// BEFORE running the deployment reset the environment with this command/script | ||
// hh run scripts/tenderly_reset.ts --network tenderly | ||
|
||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts, ethers, network }) { | ||
const { log, get } = deployments; | ||
let token = null; | ||
|
||
// We ONLY use already deployed token for MAINNET FORKS | ||
if (!(token = await get('Token'))) { | ||
// we have problem as there is not token, error out | ||
} else { | ||
log('Using already deployed Token at', token.address); | ||
} | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['token', 'preparation']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { networkConfig } from '../../helper-hardhat-config'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) { | ||
const { deploy, log, get } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
const token = await get('Token'); | ||
const argsStamp = [token.address, 16]; | ||
|
||
await deploy('PostageStamp', { | ||
from: deployer, | ||
args: argsStamp, | ||
log: true, | ||
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6, | ||
}); | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['postageStamp', 'contracts']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { networkConfig } from '../../helper-hardhat-config'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) { | ||
const { deploy, get, log } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
const args = [(await get('PostageStamp')).address]; | ||
await deploy('PriceOracle', { | ||
from: deployer, | ||
args: args, | ||
log: true, | ||
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6, | ||
}); | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['oracle', 'contracts']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { networkConfig } from '../../helper-hardhat-config'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts, network, ethers }) { | ||
const { deploy, log, get, read } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
const swarmNetworkID = networkConfig[network.name]?.swarmNetworkId; | ||
const token = await get('Token'); | ||
let staking = null; | ||
|
||
if (!(staking = await get('StakeRegistry'))) { | ||
} else { | ||
log('Using already deployed Staking at', staking.address); | ||
} | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['staking', 'contracts']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { networkConfig } from '../../helper-hardhat-config'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) { | ||
const { deploy, get, log } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
const args = [ | ||
(await get('StakeRegistry')).address, | ||
(await get('PostageStamp')).address, | ||
(await get('PriceOracle')).address, | ||
]; | ||
|
||
await deploy('Redistribution', { | ||
from: deployer, | ||
args: args, | ||
log: true, | ||
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6, | ||
}); | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['redistribution', 'contracts']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts }) { | ||
const { get, read, execute, log } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
log('Setting PostageStamps roles'); | ||
|
||
const priceOracleRole = await read('PostageStamp', 'PRICE_ORACLE_ROLE'); | ||
await execute('PostageStamp', { from: deployer }, 'grantRole', priceOracleRole, (await get('PriceOracle')).address); | ||
|
||
const redistributorRole = await read('PostageStamp', 'REDISTRIBUTOR_ROLE'); | ||
await execute( | ||
'PostageStamp', | ||
{ from: deployer }, | ||
'grantRole', | ||
redistributorRole, | ||
( | ||
await get('Redistribution') | ||
).address | ||
); | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['postageStamp_roles', 'roles']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function ({}) { | ||
// Currently we dont need to set any roles on Redistribution contract, they are all set on Constructor | ||
// This is used just as placeholder for future possible settings | ||
}; | ||
|
||
export default func; | ||
func.tags = ['redistribution_roles', 'roles']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts }) { | ||
const { get, read, execute, log } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
log('Setting Staking roles'); | ||
// As currently we are reusing staking, and there is multisig wallet as ADMIN | ||
// we either need to add deployer temporarly as ADMIN or do this manually over multisig | ||
|
||
const redisAddress = (await get('Redistribution')).address; | ||
const adminRole = await read('StakeRegistry', 'DEFAULT_ADMIN_ROLE'); | ||
|
||
if (await read('StakeRegistry', { from: deployer }, 'hasRole', adminRole, deployer)) { | ||
const redisRole = await read('StakeRegistry', 'REDISTRIBUTOR_ROLE'); | ||
await execute('StakeRegistry', { from: deployer }, 'grantRole', redisRole, redisAddress); | ||
} else { | ||
log( | ||
'DEPLOYER NEEDS TO HAVE ADMIN ROLE TO ASSIGN THE REDISTRIBUTION ROLE, PLEASE ASSIGN IT AND/OR GRANT ROLE MANUALLY' | ||
); | ||
} | ||
|
||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['staking_roles', 'roles']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function ({ deployments, getNamedAccounts }) { | ||
const { get, read, execute, log } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
log('Setting Oracles roles'); | ||
|
||
const redisAddress = (await get('Redistribution')).address; | ||
|
||
const updaterRole = await read('PriceOracle', 'PRICE_UPDATER_ROLE'); | ||
await execute('PriceOracle', { from: deployer }, 'grantRole', updaterRole, redisAddress); | ||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['staking_roles', 'roles']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { networkConfig } from '../../helper-hardhat-config'; | ||
import * as fs from 'fs'; | ||
|
||
interface DeployedContract { | ||
abi: Array<unknown>; | ||
bytecode: string; | ||
address: string; | ||
block: number; | ||
url: string; | ||
} | ||
|
||
interface DeployedData { | ||
chainId: number; | ||
swarmNetworkId: number; | ||
contracts: { | ||
postageStamp: DeployedContract; | ||
redistribution: DeployedContract; | ||
staking: DeployedContract; | ||
priceOracle: DeployedContract; | ||
bzzToken: DeployedContract; | ||
}; | ||
} | ||
|
||
const func: DeployFunction = async function ({ deployments, network, config }) { | ||
const { get, log } = deployments; | ||
|
||
const deployedData = { | ||
chainId: network.config.chainId, | ||
swarmNetworkId: networkConfig[network.name]?.swarmNetworkId || 1, | ||
contracts: { | ||
bzzToken: {} as DeployedContract, | ||
staking: {} as DeployedContract, | ||
postageStamp: {} as DeployedContract, | ||
priceOracle: {} as DeployedContract, | ||
redistribution: {} as DeployedContract, | ||
}, | ||
} as DeployedData; | ||
|
||
async function writeResult(deployedData: DeployedData) { | ||
let fileName = ''; | ||
|
||
if (fileName.length == 0 || !fs.existsSync(fileName)) { | ||
fileName = network.name + '_deployed.json'; | ||
} | ||
|
||
fs.writeFileSync(fileName, JSON.stringify(deployedData, null, '\t') + '\n'); | ||
log('Data saved to ' + fileName); | ||
} | ||
|
||
const tokenContract = await get('Token'); | ||
const stampsContract = await get('PostageStamp'); | ||
const oracleContract = await get('PriceOracle'); | ||
const stakingContract = await get('StakeRegistry'); | ||
const redisContract = await get('Redistribution'); | ||
const browserURL = config.etherscan.customChains.find((chain) => chain.network === network.name)?.urls.browserURL; | ||
|
||
// Token data | ||
deployedData['contracts']['bzzToken']['abi'] = tokenContract.abi; | ||
deployedData['contracts']['bzzToken']['bytecode'] = tokenContract.bytecode ? tokenContract.bytecode : ''; | ||
deployedData['contracts']['bzzToken']['address'] = tokenContract.address; | ||
deployedData['contracts']['bzzToken']['block'] = | ||
tokenContract.receipt && tokenContract.receipt.blockNumber ? tokenContract.receipt.blockNumber : 16514506; | ||
deployedData['contracts']['bzzToken']['url'] = browserURL + tokenContract.address; | ||
|
||
// PostageStamp data | ||
deployedData['contracts']['postageStamp']['abi'] = stampsContract.abi; | ||
deployedData['contracts']['postageStamp']['bytecode'] = stampsContract.bytecode ? stampsContract.bytecode : ''; | ||
deployedData['contracts']['postageStamp']['address'] = stampsContract.address; | ||
deployedData['contracts']['postageStamp']['block'] = | ||
stampsContract.receipt && stampsContract.receipt.blockNumber ? stampsContract.receipt.blockNumber : 0; | ||
deployedData['contracts']['postageStamp']['url'] = browserURL + stampsContract.address; | ||
|
||
// Redistribution data | ||
deployedData['contracts']['redistribution']['abi'] = redisContract.abi; | ||
deployedData['contracts']['redistribution']['bytecode'] = redisContract.bytecode ? redisContract.bytecode : ''; | ||
deployedData['contracts']['redistribution']['address'] = redisContract.address; | ||
deployedData['contracts']['redistribution']['block'] = | ||
redisContract.receipt && redisContract.receipt.blockNumber ? redisContract.receipt.blockNumber : 0; | ||
deployedData['contracts']['redistribution']['url'] = browserURL + redisContract.address; | ||
|
||
// Staking data | ||
deployedData['contracts']['staking']['abi'] = stakingContract.abi; | ||
deployedData['contracts']['staking']['bytecode'] = stakingContract.bytecode ? stakingContract.bytecode : ''; | ||
deployedData['contracts']['staking']['address'] = stakingContract.address; | ||
deployedData['contracts']['staking']['block'] = | ||
stakingContract.receipt && stakingContract.receipt.blockNumber ? stakingContract.receipt.blockNumber : 25527075; | ||
deployedData['contracts']['staking']['url'] = browserURL + stakingContract.address; | ||
|
||
// Oracle data | ||
deployedData['contracts']['priceOracle']['abi'] = oracleContract.abi; | ||
deployedData['contracts']['priceOracle']['bytecode'] = oracleContract.bytecode ? oracleContract.bytecode : ''; | ||
deployedData['contracts']['priceOracle']['address'] = oracleContract.address; | ||
deployedData['contracts']['priceOracle']['block'] = | ||
oracleContract.receipt && oracleContract.receipt.blockNumber ? oracleContract.receipt.blockNumber : 0; | ||
deployedData['contracts']['priceOracle']['url'] = browserURL + oracleContract.address; | ||
|
||
await writeResult(deployedData); | ||
log('----------------------------------------------------'); | ||
}; | ||
|
||
export default func; | ||
func.tags = ['local']; |
Oops, something went wrong.