Skip to content

Commit

Permalink
feat: add script and task for migration (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCardinalError authored Dec 6, 2023
1 parent 3709707 commit c868680
Show file tree
Hide file tree
Showing 52 changed files with 26,334 additions and 5,721 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ contractsInfo.json

# Gas reports
gas-report.txt

# Tenderly
tenderly.log
6 changes: 3 additions & 3 deletions deploy/main/000_deploy_token.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts }) {
const func: DeployFunction = async function ({ deployments, getNamedAccounts, ethers, network }) {

Check warning on line 3 in deploy/main/000_deploy_token.ts

View workflow job for this annotation

GitHub Actions / check

'ethers' is defined but never used

Check warning on line 3 in deploy/main/000_deploy_token.ts

View workflow job for this annotation

GitHub Actions / check

'network' is defined but never used
const { log, get } = deployments;
const { deployer } = await getNamedAccounts();

Check warning on line 5 in deploy/main/000_deploy_token.ts

View workflow job for this annotation

GitHub Actions / check

'deployer' is assigned a value but never used
let token = null;

// We ONLY use already deployed token
// We ONLY use already deployed token for MAINNET
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('Using already deployed Token at', token.address);
}

log('----------------------------------------------------');
Expand Down
2 changes: 1 addition & 1 deletion deploy/main/003_deploy_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
// We use legacy token that was migrated, until we deploy new one with this framework
if (!(staking = await get('StakeRegistry'))) {
} else {
log('Using already deployed token at', staking.address);
log('Using already deployed Staking at', staking.address);
}

log('----------------------------------------------------');
Expand Down
13 changes: 11 additions & 2 deletions deploy/main/007_deploy_roles_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ const func: DeployFunction = async function ({ deployments, 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)) {
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'
);
}

const redisRole = await read('StakeRegistry', 'REDISTRIBUTOR_ROLE');
await execute('StakeRegistry', { from: deployer }, 'grantRole', redisRole, redisAddress);
log('----------------------------------------------------');
};

Expand Down
2 changes: 1 addition & 1 deletion deploy/main/009_deploy_local_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ const func: DeployFunction = async function ({ deployments, network, config }) {
};

export default func;
func.tags = ['local'];
func.tags = ['data'];
2 changes: 1 addition & 1 deletion deploy/main/010_deploy_verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import verify from '../../utils/verify';
const func: DeployFunction = async function ({ deployments, network }) {
const { log, get } = deployments;

if (network.name == 'mainnet' && process.env.MAINNET_ETHERSCAN_KEY) {
if (network.name == 'mainnet' && process.env.MAINNET_ETHERSCAN_KEY) {
const swarmNetworkID = networkConfig[network.name]?.swarmNetworkId;
const token = await get('Token');

Expand Down
10 changes: 5 additions & 5 deletions deploy/main/011_deploy_multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
await execute('Redistribution', { from: deployer }, 'grantRole', adminRole, networkConfig['mainnet'].multisig);

// REMOVE Roles from deployer
await execute('PostageStamp', { from: deployer }, 'renounceRole', adminRole, deployer);
await execute('PriceOracle', { from: deployer }, 'renounceRole', adminRole, deployer);
await execute('StakeRegistry', { from: deployer }, 'renounceRole', adminRole, deployer);
await execute('Redistribution', { from: deployer }, 'renounceRole', adminRole, deployer);
// await execute('PostageStamp', { from: deployer }, 'renounceRole', adminRole, deployer);
// await execute('PriceOracle', { from: deployer }, 'renounceRole', adminRole, deployer);
// await execute('StakeRegistry', { from: deployer }, 'renounceRole', adminRole, deployer);
// await execute('Redistribution', { from: deployer }, 'renounceRole', adminRole, deployer);

log('----------------------------------------------------');
}
};

export default func;
func.tags = ['state_changes'];
func.tags = ['multisig', 'roles'];
21 changes: 21 additions & 0 deletions deploy/tenderly/000_deploy_token.ts
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'];
22 changes: 22 additions & 0 deletions deploy/tenderly/001_deploy_postage.ts
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'];
20 changes: 20 additions & 0 deletions deploy/tenderly/002_deploy_oracle.ts
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'];
20 changes: 20 additions & 0 deletions deploy/tenderly/003_deploy_staking.ts
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'];
25 changes: 25 additions & 0 deletions deploy/tenderly/004_deploy_redistribution.ts
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'];
27 changes: 27 additions & 0 deletions deploy/tenderly/005_deploy_roles_postage.ts
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'];
9 changes: 9 additions & 0 deletions deploy/tenderly/006_deploy_roles_redistribution.ts
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'];
27 changes: 27 additions & 0 deletions deploy/tenderly/007_deploy_roles_staking.ts
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'];
17 changes: 17 additions & 0 deletions deploy/tenderly/008_deploy_roles_oracle.ts
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'];
103 changes: 103 additions & 0 deletions deploy/tenderly/009_deploy_local_data.ts
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'];
Loading

0 comments on commit c868680

Please sign in to comment.