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

fix: add deployed, add scripts, add comments to deploy steps #203

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 1 deletion deploy/006_deploy_roles_redistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts })
log('Setting Redistribution roles');

const redisAddress = (await get('Redistribution')).address;

// This Role executions are also done in other steps, but tests will fail as currently round numbers are coded with this
// transactions happening, each transaction mines one block, so some tests fail as they are bounded by mining of this trx/blocks
const redistributorRoleStakeRegistry = await read('StakeRegistry', 'REDISTRIBUTOR_ROLE');
await execute('StakeRegistry', { from: deployer }, 'grantRole', redistributorRoleStakeRegistry, redisAddress);

Expand Down
8 changes: 4 additions & 4 deletions scripts/deploy_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ async function main() {
let waitTime = 6;
let currentRedis = '';
if (network.name == 'mainnet') {
//Stamps, Multisig
// Postagestamp, Multisig
args = ['0x30d155478eF27Ab32A1D578BE7b84BC5988aF381', '0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe'];
currentRedis = '0xDF64aed195102E644ad6A0204eD5377589b29618';
} else if (network.name == 'testnet') {
args = ['0x1f87FEDa43e6ABFe1058E96A07d0ea182e7dc9BD', '0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe'];
args = ['0xF5147D56502C80004f91FB4112d6812CddE8eDE3', '0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe'];
currentRedis = '0x9e3BDb0c69838CC06D85409d4AD6245e54F70F1d';
} else if (network.name == 'localhost') {
args = ['0x9A2F29598CB0787Aa806Bbfb65B82A9e558945E7', '0x3c8F39EE625fCF97cB6ee22bCe25BE1F1E5A5dE8'];
Expand All @@ -113,8 +113,8 @@ async function main() {
deployed['contracts']['priceOracle']['url'] = config.url + oracle.address;

// Change roles on current oracle contract
const redistributorRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_UPDATER_ROLE'));
const tx2 = await oracle.grantRole(redistributorRole, currentRedis);
const updaterRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_UPDATER_ROLE'));
const tx2 = await oracle.grantRole(updaterRole, currentRedis);
console.log('Changed PRICE UPDATER ROLE at : ', tx2.hash);

// TODO Needs to be unpaused to be running, either here with trx on through etherscan or something like that
Expand Down
8 changes: 4 additions & 4 deletions scripts/deploy_redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ async function main() {
let args: string[] = [];
let waitTime = 6;
if (network.name == 'mainnet') {
// Staking, Stamps, Oracle args, multisig
// Staking, Stamps, Oracle, multisig
args = [
'0x781c6D1f0eaE6F1Da1F604c6cDCcdB8B76428ba7',
'0x781c6D1f0eaE6F1Da1F604c6cDCcdB8B76428ba7', // old staking
'0x30d155478eF27Ab32A1D578BE7b84BC5988aF381',
'0x344A2CC7304B32A87EfDC5407cD4bEC7cf98F035',
'0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe',
];
} else if (network.name == 'testnet') {
args = [
'0xCb07bf0603da228C8ec602bf12b973b8A94f9bac',
'0x1f87FEDa43e6ABFe1058E96A07d0ea182e7dc9BD',
'0xCb07bf0603da228C8ec602bf12b973b8A94f9bac', // old staking
'0xF5147D56502C80004f91FB4112d6812CddE8eDE3',
'0xefC5Ead3188402eCC951DB45827F6e0F99B67a25',
'0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe',
];
Expand Down
40 changes: 40 additions & 0 deletions scripts/deploy_roles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'hardhat-deploy-ethers';
import '@nomiclabs/hardhat-etherscan';
import { ethers, network } from 'hardhat';

Check warning on line 3 in scripts/deploy_roles.ts

View workflow job for this annotation

GitHub Actions / check

'network' is defined but never used
import hre from 'hardhat';

Check warning on line 4 in scripts/deploy_roles.ts

View workflow job for this annotation

GitHub Actions / check

'hre' is defined but never used

async function main() {
// Order of contracts and how should they be deployed, testnet addresses
const currentPostage = '0xF5147D56502C80004f91FB4112d6812CddE8eDE3';
const currentOracle = '0xd41A47fCaa67945A11a398F00D5f7F130aF03733';
const currentStaking = '0xCb07bf0603da228C8ec602bf12b973b8A94f9bac'; // old staking
const currentRedis = '0x264079eeF0CE42D790e3FA7DF8D0cfA675ef6504';

// Change roles on current stamp contract
const stamp = await ethers.getContractAt('PostageStamp', currentPostage);
const redistributorRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('REDISTRIBUTOR_ROLE'));
const tx = await stamp.grantRole(redistributorRole, currentRedis);
console.log('Changed REDISTRIBUTOR ROLE at : ', tx.hash);

const oracleRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_ORACLE_ROLE'));
const tx2 = await stamp.grantRole(oracleRole, currentOracle);
console.log('Changed ORACLE ROLE at : ', tx2.hash);

// Change roles on current oracle contract
const oracle = await ethers.getContractAt('PriceOracle', currentOracle);
const updaterRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_UPDATER_ROLE'));
const tx3 = await oracle.grantRole(updaterRole, currentRedis);
console.log('Changed UPDATER ROLE at : ', tx3.hash);

// Change roles on current staking contract
const stake = await ethers.getContractAt('StakeRegistry', currentStaking);
const tx4 = await stake.grantRole(redistributorRole, currentRedis);
console.log('Changed REDISTRIBUTOR ROLE at : ', tx4.hash);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
2 changes: 1 addition & 1 deletion scripts/deploy_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function main() {
let waitTime = 6;
let currentRedis = '';
if (network.name == 'mainnet') {
//SwarmNetworkId, BZZ token, Multisig
// BZZ token, SwarmNetworkId, Multisig
args = ['0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe', '1', '0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe'];
currentRedis = '';
} else if (network.name == 'testnet') {
Expand Down
144 changes: 144 additions & 0 deletions scripts/deploy_stamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import 'hardhat-deploy-ethers';
import '@nomiclabs/hardhat-etherscan';
import { ethers, network } from 'hardhat';
import verify from '../utils/verify';
import hre from 'hardhat';
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: {
bzzToken: DeployedContract;
staking: DeployedContract;
postageStamp: DeployedContract;
priceOracle: DeployedContract;
redistribution: DeployedContract;
};
}

interface ChainConfig {
chainId?: number;
swarmNetworkId?: number;
networkName: string;
deployedData: DeployedData;
url: string;
}

let networkDeployedData: DeployedData;
try {
networkDeployedData = require('../' + network.name + '_deployed.json');
} catch (e) {
networkDeployedData = {
chainId: 0,
swarmNetworkId: 0,
contracts: {
bzzToken: {} as DeployedContract,
staking: {} as DeployedContract,
postageStamp: {} as DeployedContract,
priceOracle: {} as DeployedContract,
redistribution: {} as DeployedContract,
},
} as DeployedData;
}

const configs: Record<string, ChainConfig> = {
testnet: {
chainId: network.config.chainId,
swarmNetworkId: networkDeployedData.swarmNetworkId ? networkDeployedData.swarmNetworkId : 10,
networkName: network.name,
deployedData: networkDeployedData,
url: hre.config.etherscan.customChains[1]['urls']['browserURL'].toString(),
},
mainnet: {
chainId: network.config.chainId,
swarmNetworkId: networkDeployedData.swarmNetworkId ? networkDeployedData.swarmNetworkId : 1,
networkName: network.name,
deployedData: networkDeployedData,
url: hre.config.etherscan.customChains[2]['urls']['browserURL'].toString(),
},
};

const config: ChainConfig = configs[network.name]
? configs[network.name]
: ({
chainId: network.config.chainId,
swarmNetworkId: networkDeployedData.swarmNetworkId ? networkDeployedData.swarmNetworkId : network.config.chainId,
networkName: network.name,
deployedData: networkDeployedData,
url: '',
} as ChainConfig);

async function main() {
// This is deployer script for emergency deployment of only the postagestamp contract with some quick fixes
let args: string[] = [];
let waitTime = 6;
let currentRedis = '';
let currentOracle = '';
if (network.name == 'mainnet') {
// BZZ Token address, minimumBucketDepth, multisig
args = ['0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe', '16', '0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe'];
currentRedis = '';
currentOracle = '';
} else if (network.name == 'testnet') {
args = ['0x0b2bbcbe94d5d4bb782713b137c85d29aa609a13', '16', '0xb1C7F17Ed88189Abf269Bf68A3B2Ed83C5276aAe'];
currentRedis = '0x9e3BDb0c69838CC06D85409d4AD6245e54F70F1d';
currentOracle = '0xefC5Ead3188402eCC951DB45827F6e0F99B67a25';
} else if (network.name == 'localhost') {
args = ['0x942C6684eB9874C63d4ed26Ab0623F951D253081', '16', '0x3c8F39EE625fCF97cB6ee22bCe25BE1F1E5A5dE8'];
currentRedis = '0xDF64aed195102E644ad6A0204eD5377589b29618';
currentOracle = '0xF52458e65b8e3B69d93DD3803d8ef934c75E0022';
waitTime = 1;
}

// Deploy the contract
const stampFactory = await ethers.getContractFactory('PostageStamp');
console.log('Deploying contract...');
const stamp = await stampFactory.deploy(...args);
await stamp.deployed();
console.log(`Deployed contract to: ${stamp.address}`);
const deploymentReceipt = await stamp.deployTransaction.wait(waitTime);

// Add metadata for Bee Node
const deployed = await JSON.parse(JSON.stringify(config.deployedData).toString());
const stampABI = await require('../artifacts/src/PostageStamp.sol/PostageStamp.json');
deployed['contracts']['postageStamp']['abi'] = stampABI.abi;
deployed['contracts']['postageStamp']['bytecode'] = stampABI.bytecode.toString();
deployed['contracts']['postageStamp']['address'] = stamp.address;
deployed['contracts']['postageStamp']['block'] = deploymentReceipt.blockNumber;
deployed['contracts']['postageStamp']['url'] = config.url + stamp.address;

// We need to first deploy this contract and then use this address and deploy with it redistribution
// After that we can add here redis role

// Change roles on current staking contract
const redistributorRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('REDISTRIBUTOR_ROLE'));
const tx2 = await stamp.grantRole(redistributorRole, currentRedis);
console.log('Changed REDISTRIBUTOR ROLE at : ', tx2.hash);

const oracleRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_ORACLE_ROLE'));
const tx3 = await stamp.grantRole(oracleRole, currentOracle);
console.log('Changed ORACLE ROLE at : ', tx3.hash);

fs.writeFileSync(config.networkName + '_deployed.json', JSON.stringify(deployed, null, '\t'));

if ((process.env.MAINNET_ETHERSCAN_KEY || process.env.TESTNET_ETHERSCAN_KEY) && network.name != 'localhost') {
console.log('Verifying...');
await verify(stamp.address, args);
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading
Loading