Skip to content
Open
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
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ coverage/
node_modules/
*.yaml
*.json

# CommonJS runtime sibling of mine-worker.ts; loaded directly by worker_threads
# so it must stay as plain CJS (require() etc.).
test/util/mine-worker.js
11 changes: 9 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"extends": "solhint:default",
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
"prettier/prettier": "error",
"compiler-version": ["off"],
"func-visibility": ["warn", { "ignoreConstructors": true }],
"no-empty-blocks": "warn",
"max-line-length": ["warn", 120],
"no-inline-assembly": "off",
"reason-string": ["warn", { "maxLength": 64 }],
"not-rely-on-time": "off"
}
}
13 changes: 10 additions & 3 deletions deploy/local/001_deploy_postage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne

const token = await get('TestToken');

const argsStamp = [token.address, 16];

await deploy('PostageStamp', {
from: deployer,
args: argsStamp,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [token.address, 16],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});
Expand Down
14 changes: 12 additions & 2 deletions deploy/local/002_deploy_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deploy, get, log } = deployments;
const { deployer } = await getNamedAccounts();

const args = [(await get('PostageStamp')).address];
const postageStamp = await get('PostageStamp');

await deploy('PriceOracle', {
from: deployer,
args: args,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [postageStamp.address],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});
Expand Down
14 changes: 11 additions & 3 deletions deploy/local/003_deploy_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const swarmNetworkID = networkConfig[network.name]?.swarmNetworkId;

const token = await get('TestToken');
const oracleAddress = (await get('PriceOracle')).address;
const oracle = await get('PriceOracle');

const args = [token.address, swarmNetworkID, oracleAddress];
await deploy('StakeRegistry', {
from: deployer,
args: args,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [token.address, swarmNetworkID, oracle.address],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});
Expand Down
19 changes: 13 additions & 6 deletions deploy/local/004_deploy_redistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deploy, get, log } = deployments;
const { deployer } = await getNamedAccounts();

const args = [
(await get('StakeRegistry')).address,
(await get('PostageStamp')).address,
(await get('PriceOracle')).address,
];
const staking = await get('StakeRegistry');
const postage = await get('PostageStamp');
const oracle = await get('PriceOracle');

await deploy('Redistribution', {
from: deployer,
args: args,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [staking.address, postage.address, oracle.address],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 1,
});
Expand Down
7 changes: 4 additions & 3 deletions deploy/local/005_deploy_roles_postage.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';

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

log('Setting PostageStamps roles');

const priceOracleRole = await read('PostageStamp', 'PRICE_ORACLE_ROLE');
const priceOracleRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_ORACLE_ROLE'));
await execute('PostageStamp', { from: deployer }, 'grantRole', priceOracleRole, (await get('PriceOracle')).address);

const redistributorRole = await read('PostageStamp', 'REDISTRIBUTOR_ROLE');
const redistributorRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('REDISTRIBUTOR_ROLE'));
await execute(
'PostageStamp',
{ from: deployer },
Expand Down
5 changes: 3 additions & 2 deletions deploy/local/007_deploy_roles_staking.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';

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

log('Setting Staking roles');

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

const redisRole = await read('StakeRegistry', 'REDISTRIBUTOR_ROLE');
const redisRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('REDISTRIBUTOR_ROLE'));
await execute('StakeRegistry', { from: deployer }, 'grantRole', redisRole, redisAddress);
log('----------------------------------------------------');
};
Expand Down
5 changes: 3 additions & 2 deletions deploy/local/008_deploy_roles_oracle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';

const func: DeployFunction = async function ({ deployments, getNamedAccounts }) {
const { get, read, execute, log } = deployments;
const { get, 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');
const updaterRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_UPDATER_ROLE'));
await execute('PriceOracle', { from: deployer }, 'grantRole', updaterRole, redisAddress);
log('----------------------------------------------------');
};
Expand Down
2 changes: 1 addition & 1 deletion deploy/local/010_deploy_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, et
log('----------------------------------------------------');
}

if (network.name == 'hardhat') {
if (network.name == 'hardhat' && process.env.HARDHAT_INTERVAL_MINING === 'true') {
await network.provider.send('evm_setIntervalMining', [5000]);
log('Mining blocks in localcluster config, 5 second delay for each block');
log('----------------------------------------------------');
Expand Down
51 changes: 51 additions & 0 deletions deploy/local/011_deploy_registry_router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';

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

const proxyAdmin = await get('DefaultProxyAdmin');

await deploy('VersionedRegistryRouter', {
from: deployer,
args: [proxyAdmin.address],
log: true,
});

const contractNames = ['PostageStamp', 'PriceOracle', 'StakeRegistry', 'Redistribution'];

for (const name of contractNames) {
const proxyId = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(name));
const proxy = await get(name);
log(`Registering proxy ${name} (${proxy.address})`);
await execute('VersionedRegistryRouter', { from: deployer }, 'registerProxy', proxyId, proxy.address);
}

for (const name of contractNames) {
const proxy = await get(name);
const implAddress = await ethers
.getContractAt('ProxyAdmin', proxyAdmin.address)
.then((pa) => pa.getProxyImplementation(proxy.address));

const codehash = ethers.utils.keccak256(await ethers.provider.getCode(implAddress));
const versionId = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`${name}@1.0.0`));

log(`Registering release ${name}@1.0.0 (impl=${implAddress})`);
await execute(
'VersionedRegistryRouter',
{ from: deployer },
'registerRelease',
versionId,
`${name}@1.0.0`,
implAddress,
codehash
);
}

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

export default func;
func.tags = ['registry', 'contracts'];
func.dependencies = ['postageStamp', 'priceOracle', 'staking', 'redistribution'];
12 changes: 10 additions & 2 deletions deploy/main/001_deploy_postage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deployer } = await getNamedAccounts();

const token = await get('Token');
const argsStamp = [token.address, 16];

await deploy('PostageStamp', {
from: deployer,
args: argsStamp,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [token.address, 16],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6,
});
Expand Down
16 changes: 12 additions & 4 deletions deploy/main/002_deploy_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deploy, get, read, execute, log, getOrNull } = deployments;
const { deployer } = await getNamedAccounts();

// Check if PriceOracle already exists to preserve its price
const existingOracle = await getOrNull('PriceOracle');
let oldOraclePrice;
if (existingOracle) {
oldOraclePrice = await read('PriceOracle', 'currentPrice');
}

const args = [(await get('PostageStamp')).address];
const postageStamp = await get('PostageStamp');

await deploy('PriceOracle', {
from: deployer,
args: args,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [postageStamp.address],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6,
});

// Only set the old price if there was an existing deployment
if (existingOracle && oldOraclePrice) {
await execute('PriceOracle', { from: deployer }, 'setPrice', oldOraclePrice);
}
Expand Down
17 changes: 13 additions & 4 deletions deploy/main/003_deploy_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ 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 { deploy, get, log } = deployments;
const { deployer } = await getNamedAccounts();
const swarmNetworkID = networkConfig[network.name]?.swarmNetworkId;

const token = await get('Token');
const oracleAddress = (await get('PriceOracle')).address;
const oracle = await get('PriceOracle');

const args = [token.address, swarmNetworkID, oracleAddress];
await deploy('StakeRegistry', {
from: deployer,
args: args,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [token.address, swarmNetworkID, oracle.address],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6,
});
Expand Down
19 changes: 13 additions & 6 deletions deploy/main/004_deploy_redistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deploy, get, log } = deployments;
const { deployer } = await getNamedAccounts();

const args = [
(await get('StakeRegistry')).address,
(await get('PostageStamp')).address,
(await get('PriceOracle')).address,
];
const staking = await get('StakeRegistry');
const postage = await get('PostageStamp');
const oracle = await get('PriceOracle');

await deploy('Redistribution', {
from: deployer,
args: args,
proxy: {
proxyContract: 'TransparentUpgradeableProxy',
viaAdminContract: 'DefaultProxyAdmin',
execute: {
init: {
methodName: 'initialize',
args: [staking.address, postage.address, oracle.address],
},
},
},
log: true,
waitConfirmations: networkConfig[network.name]?.blockConfirmations || 6,
});
Expand Down
14 changes: 8 additions & 6 deletions deploy/main/005_deploy_roles_postage.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';

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

log('Setting PostageStamps roles');
const adminRole = await read('PostageStamp', 'DEFAULT_ADMIN_ROLE');
log('Setting PostageStamp roles');

const adminRole = '0x0000000000000000000000000000000000000000000000000000000000000000';

if (await read('PostageStamp', 'hasRole', adminRole, deployer)) {
const priceOracleRole = await read('PostageStamp', 'PRICE_ORACLE_ROLE');
const priceOracleRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('PRICE_ORACLE_ROLE'));
await execute('PostageStamp', { from: deployer }, 'grantRole', priceOracleRole, (await get('PriceOracle')).address);

const redisRole = await read('PostageStamp', 'REDISTRIBUTOR_ROLE');
const redisRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('REDISTRIBUTOR_ROLE'));
const redisAddress = (await get('Redistribution')).address;
await execute('PostageStamp', { from: deployer }, 'grantRole', redisRole, redisAddress);
} else {
log('DEPLOYER NEEDS TO HAVE ADMIN ROLE TO ASSIGN THE REDISTRIBUTION ROLE, PLEASE ASSIGN IT OR GRANT ROLE MANUALLY');
log('DEPLOYER NEEDS TO HAVE ADMIN ROLE TO ASSIGN ROLES, PLEASE GRANT ROLE MANUALLY');
}

log('----------------------------------------------------');
Expand Down
Loading
Loading