Skip to content

Commit

Permalink
fix: Deploy folders (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCardinalError authored Oct 17, 2023
1 parent 60aa0ab commit daa7171
Show file tree
Hide file tree
Showing 43 changed files with 6,606 additions and 1,141 deletions.
21 changes: 21 additions & 0 deletions deploy/local/000_deploy_test_token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DeployFunction } from 'hardhat-deploy/types';

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

let token = null;

const argsToken = ['TEST', 'TST', '1249989122910552325012092', deployer];

token = await deploy('TestToken', {

Check warning on line 11 in deploy/local/000_deploy_test_token.ts

View workflow job for this annotation

GitHub Actions / check

'token' is assigned a value but never used
from: deployer,
args: argsToken,
log: true,
});

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

export default func;
func.tags = ['testToken', 'contracts'];
23 changes: 23 additions & 0 deletions deploy/local/001_deploy_postage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig } from '../../helper-hardhat-config';

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

Check warning on line 4 in deploy/local/001_deploy_postage.ts

View workflow job for this annotation

GitHub Actions / check

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

const token = await get('TestToken');

const argsStamp = [token.address, 16, networkConfig[network.name]?.multisig];

await deploy('PostageStamp', {
from: deployer,
args: argsStamp,
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});

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

export default func;
func.tags = ['postageStamp', 'contracts'];
20 changes: 20 additions & 0 deletions deploy/local/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, networkConfig[network.name]?.multisig];
await deploy('PriceOracle', {
from: deployer,
args: args,
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});

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

export default func;
func.tags = ['oracle', 'contracts'];
23 changes: 23 additions & 0 deletions deploy/local/003_deploy_staking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig } from '../../helper-hardhat-config';

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

Check warning on line 4 in deploy/local/003_deploy_staking.ts

View workflow job for this annotation

GitHub Actions / check

'ethers' is defined but never used
const { deploy, get, log } = deployments;
const { deployer } = await getNamedAccounts();
const swarmNetworkID = networkConfig[network.name]?.swarmNetworkId;

const token = await get('TestToken');

const args = [token.address, swarmNetworkID, networkConfig[network.name]?.multisig];
await deploy('StakeRegistry', {
from: deployer,
args: args,
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});

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

export default func;
func.tags = ['staking', 'contracts'];
26 changes: 26 additions & 0 deletions deploy/local/004_deploy_redistribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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,
networkConfig[network.name]?.multisig,
];

await deploy('Redistribution', {
from: deployer,
args: args,
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});

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

export default func;
func.tags = ['redistribution', 'contracts'];
27 changes: 27 additions & 0 deletions deploy/local/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/local/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'];
17 changes: 17 additions & 0 deletions deploy/local/007_deploy_roles_staking.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 Staking roles');

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

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

export default func;
func.tags = ['staking_roles', 'roles'];
17 changes: 17 additions & 0 deletions deploy/local/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 = ['oracle_roles', 'roles'];
103 changes: 103 additions & 0 deletions deploy/local/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 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 for dev chains
const tokenContract = await get('TestToken');
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 : 0;
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 : 0;
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 = ['data'];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { developmentChains, networkConfig } from '../helper-hardhat-config';
import verify from '../utils/verify';
import { developmentChains, networkConfig } from '../../helper-hardhat-config';
import verify from '../../utils/verify';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {
const { deploy, log } = deployments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig, developmentChains, deployedBzzData } from '../helper-hardhat-config';
import { networkConfig, developmentChains, deployedBzzData } from '../../helper-hardhat-config';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network, ethers }) {
const { deploy, log, get } = deployments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig } from '../helper-hardhat-config';
import { networkConfig } from '../../helper-hardhat-config';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {
const { deploy, get, log } = deployments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig, developmentChains, deployedBzzData } from '../helper-hardhat-config';
import { networkConfig, developmentChains, deployedBzzData } from '../../helper-hardhat-config';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network, ethers }) {
const { deploy, get, log } = deployments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig } from '../helper-hardhat-config';
import { networkConfig } from '../../helper-hardhat-config';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {
const { deploy, get, log } = deployments;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { developmentChains, deployedBzzData, networkConfig } from '../helper-hardhat-config';
import { developmentChains, deployedBzzData, networkConfig } from '../../helper-hardhat-config';
import * as fs from 'fs';

interface DeployedContract {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { deployedBzzData, networkConfig } from '../helper-hardhat-config';
import verify from '../utils/verify';
import { deployedBzzData, networkConfig } from '../../helper-hardhat-config';
import verify from '../../utils/verify';

const func: DeployFunction = async function ({ deployments, network, ethers }) {
const { log, get } = deployments;
Expand Down
29 changes: 29 additions & 0 deletions deploy/test/000_deploy_test_token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { networkConfig } from '../../helper-hardhat-config';

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

let token = null;

if (network.name == 'testnet') {
// We deploy new token if there is no token
if (!(token = await getOrNull('TestToken'))) {
const argsToken = ['gBZZ', 'gBZZ', '1250000000000000000000000', networkConfig[network.name]?.multisig];
token = await deploy('TestToken', {
from: deployer,
args: argsToken,
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6,
});
} else {
log('Using already deployed token at', token.address);
}
}

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

export default func;
func.tags = ['testToken', 'contracts'];
Loading

0 comments on commit daa7171

Please sign in to comment.