Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script and task for migration #208

Merged
merged 67 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e420562
add script and task for migration
0xCardinalError Oct 11, 2023
0339c93
add task and hre for ethers
0xCardinalError Oct 12, 2023
b95b2cd
update info on migration
0xCardinalError Oct 12, 2023
ede46cd
Merge branch 'master' of https://github.com/ethersphere/storage-incen…
0xCardinalError Oct 24, 2023
89a4480
do it on main fork
0xCardinalError Oct 24, 2023
0f679c2
add migration to root, add it to task, working copy of migration
0xCardinalError Oct 24, 2023
f9000a3
add tyep check
0xCardinalError Oct 24, 2023
972f675
remove erc20 transfers
0xCardinalError Oct 24, 2023
a4e1a4d
remove tests for ERC20 as we will not be transfering it
0xCardinalError Oct 26, 2023
4b4df09
Merge branch 'master' of https://github.com/ethersphere/storage-incen…
0xCardinalError Oct 31, 2023
b34717b
install tenderly hh plugin for verifications
0xCardinalError Oct 31, 2023
17c43a5
add tenderly config and init data
0xCardinalError Oct 31, 2023
362bdde
add tenderly configs
0xCardinalError Oct 31, 2023
68ce454
final config for mainfork and tenderly
0xCardinalError Nov 2, 2023
4ba73da
move migrations to folder
0xCardinalError Nov 2, 2023
1452c6d
fix stamp scripts, remove tenderly as it breaks tests
0xCardinalError Nov 2, 2023
d8784a6
remove flat
0xCardinalError Nov 3, 2023
e2e5ec2
remove tenderly as it breaks tests
0xCardinalError Nov 3, 2023
4c1abb0
add steps
0xCardinalError Nov 6, 2023
e650ddb
refine steps
0xCardinalError Nov 6, 2023
a1b1257
add current command
0xCardinalError Nov 6, 2023
b360ddb
change end
0xCardinalError Nov 6, 2023
c8f88fc
block info
0xCardinalError Nov 6, 2023
872c670
add snapshot from current state
0xCardinalError Nov 6, 2023
40e2923
add stamp var
0xCardinalError Nov 7, 2023
821173d
Replace mainfork with tenderly as in that case verifications will work
0xCardinalError Nov 7, 2023
6b1ef6f
disable verification
0xCardinalError Nov 7, 2023
097f3fe
add batch script
0xCardinalError Nov 8, 2023
c3b446a
working bulk migration script
0xCardinalError Nov 8, 2023
d05f6f7
latest migration test
0xCardinalError Nov 8, 2023
31cb676
add comments and info
0xCardinalError Nov 8, 2023
504b34e
add some automations for tenderly fork deployments
0xCardinalError Nov 8, 2023
982a218
refactor tenderly with mainnet
0xCardinalError Nov 9, 2023
e5ef1eb
modify tenderly parts for proper workflow
0xCardinalError Nov 9, 2023
789ee96
make oracle unpaused by default
0xCardinalError Nov 9, 2023
79bf910
tags
0xCardinalError Nov 9, 2023
35b7f11
cleanup messages, try again with non signer to set roles
0xCardinalError Nov 10, 2023
6d3f92b
remove simulation as it breaks deployment
0xCardinalError Nov 11, 2023
16eddd1
cleanup tenderly
0xCardinalError Nov 11, 2023
7f66d06
proper order for reset script
0xCardinalError Nov 12, 2023
7f970e9
comment out tenderly as it breaks tests
0xCardinalError Nov 12, 2023
b5d868e
fix lint
0xCardinalError Nov 13, 2023
b80d42e
reset fix for TS
0xCardinalError Nov 13, 2023
250f212
add pause so test doesnt fail
0xCardinalError Nov 17, 2023
e02b4c1
Merge branch 'master' of github.com:ethersphere/storage-incentives in…
0xCardinalError Nov 20, 2023
540aebb
add all the changes per review
0xCardinalError Nov 20, 2023
0397b16
fix type assertion
0xCardinalError Nov 22, 2023
f8ffa3a
cleanup more
0xCardinalError Nov 22, 2023
172b45c
migration of goerlis stamps
0xCardinalError Nov 27, 2023
930d1cc
add fail event for batch loop so we get info but continue looping
0xCardinalError Nov 27, 2023
0c22ae4
change const
0xCardinalError Nov 28, 2023
aa47989
unionize migration scripts
0xCardinalError Nov 28, 2023
68f3904
use id
0xCardinalError Nov 28, 2023
63b9985
change event name
0xCardinalError Nov 28, 2023
8a7305c
Set 70 as sweet spot, add buffer for gas limit
0xCardinalError Nov 28, 2023
e12092e
add buffer for single batch
0xCardinalError Nov 28, 2023
b003db8
change names
0xCardinalError Nov 29, 2023
122a7a4
create admin role withs script
0xCardinalError Nov 29, 2023
ba980b4
add fetch and bump up newer ethers
0xCardinalError Nov 29, 2023
1221324
use older ethers version
0xCardinalError Nov 29, 2023
0dfd1df
add todos
0xCardinalError Nov 29, 2023
000b851
remove fetch test
0xCardinalError Nov 30, 2023
20abebe
add admin role check to bulk batch
0xCardinalError Dec 1, 2023
ce2e319
add new contracts deployment
0xCardinalError Dec 6, 2023
ff37a16
100 is mainnet swarm id
0xCardinalError Dec 6, 2023
487cd78
it is 1 after all
0xCardinalError Dec 6, 2023
4a776ec
latest batches and import
0xCardinalError Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2,16 +2,16 @@
import { networkConfig } from '../../helper-hardhat-config';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {
const { deploy, log, get } = deployments;

Check warning on line 5 in deploy/main/003_deploy_staking.ts

View workflow job for this annotation

GitHub Actions / check

'deploy' is assigned a value but never used
const { deployer } = await getNamedAccounts();

Check warning on line 6 in deploy/main/003_deploy_staking.ts

View workflow job for this annotation

GitHub Actions / check

'deployer' is assigned a value but never used
const swarmNetworkID = networkConfig[network.name]?.swarmNetworkId;

Check warning on line 7 in deploy/main/003_deploy_staking.ts

View workflow job for this annotation

GitHub Actions / check

'swarmNetworkID' is assigned a value but never used
const token = await get('Token');

Check warning on line 8 in deploy/main/003_deploy_staking.ts

View workflow job for this annotation

GitHub Actions / check

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

// 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/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
2 changes: 1 addition & 1 deletion deploy/main/011_deploy_multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
};

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 }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use some import from already existing deployment scripts that do the same?

Copy link
Contributor Author

@0xCardinalError 0xCardinalError Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. we should, not have gotten to that yet.

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'];
13 changes: 13 additions & 0 deletions deploy/tenderly/010_deploy_verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, network }) {
const { log } = deployments;

// We verified all the contracts automtically with setup and Hardhat plugin, for any additional changes look here
// https://docs.tenderly.co/monitoring/smart-contract-verification/verifying-contracts-using-the-tenderly-hardhat-plugin/automatic-contract-verification

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

export default func;
func.tags = ['verify'];
Loading
Loading