Skip to content

Commit

Permalink
Add deploy script and expose hardhat node
Browse files Browse the repository at this point in the history
  • Loading branch information
shark0der committed Jul 28, 2022
1 parent 11da00b commit 1957537
Show file tree
Hide file tree
Showing 30 changed files with 8,964 additions and 12,423 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.idea/
.DS_Store
artifacts/
deploy/
/deploy/
cache/
build/
types/
Expand Down
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid",
"overrides": [
{
"files": "*.sol",
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/Disposables/DisposableTokenController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ contract DisposableTokenController is TokenController {

token = INXMToken(_tokenAddress);
token.changeOperator(address(this));
token.addToWhiteList(address(this));

changeMasterAddress(_masterAddress);
pooledStaking = IPooledStaking(_pooledStakingAddress);
assessment = IAssessment(_assessmentAddress);

}

function addToWhitelist(address _member) public override {
Expand Down
38 changes: 0 additions & 38 deletions contracts/mocks/TwapOracle/TOMockUniswapPair.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/modules/cover/ProductsV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../../interfaces/IProductsV1.sol";

contract ProductsV1 is IProductsV1 {
function getNewProductId(address legacyProductId) external pure override returns (uint) {

// Product: bZx v1
// Type: protocol
if (legacyProductId == 0x8B3d70d628Ebd30D4A2ea82DB95bA2e906c71633) {
Expand Down
9 changes: 2 additions & 7 deletions contracts/modules/legacy/LegacyPooledStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -938,19 +938,14 @@ contract LegacyPooledStaking is IPooledStaking, MasterAware {
}
}

function initialize() public {
require(!initialized, "Contract is already initialized");
tokenController.addToWhitelist(address(this));
initialized = true;
}

function changeDependentContractAddress() public {

token = INXMToken(master.tokenAddress());
tokenController = ITokenController(master.getLatestAddress("TC"));

if (!initialized) {
initialize();
tokenController.addToWhitelist(address(this));
initialized = true;
}
}

Expand Down
12 changes: 4 additions & 8 deletions contracts/modules/token/TokenController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ contract TokenController is ITokenController, LockHandler, LegacyMasterAware {
claimsReward = claimsRewardAddress;
}

function unlistClaimsReward() external {
token.removeFromWhiteList(claimsReward);
}

/**
* @dev Just for interface
*/
Expand Down Expand Up @@ -384,12 +388,4 @@ contract TokenController is ITokenController, LockHandler, LegacyMasterAware {

token.transfer(to, stakeToWithdraw + rewardsToWithdraw);
}

function initialize() external {
token.addToWhiteList(address(this));
token.removeFromWhiteList(claimsReward);
}

event Burned(address indexed member, bytes32 lockedUnder, uint256 amount);

}
23 changes: 21 additions & 2 deletions hardhat.config.js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ require('hardhat-contract-sizer');

require('./tasks');

module.exports = {
/** @type import('hardhat/config').HardhatUserConfig */
const config = {

contractSizer: {
alphaSort: true,
runOnCompile: false,
Expand All @@ -22,12 +24,29 @@ module.exports = {

mocha: {
exit: true,
bail: true,
bail: false,
recursive: false,
timeout: 0,
},

networks: require('./networks'),

solidity: require('./solidity'),

};

if (process.env.ENABLE_TENDERLY) {

const tenderly = require('@tenderly/hardhat-tenderly');
tenderly.setup({ automaticVerifications: false });

config.tenderly = {
username: 'NexusMutual',
project: 'nexusmutual',
forkNetwork: 'mainnet',
deploymentsDir: 'deployments',
// privateVerification: false,
};
}

module.exports = config;
4 changes: 2 additions & 2 deletions hardhat.config.js/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const ether = n => `${n}${'0'.repeat(18)}`;
const networks = {
hardhat: {
accounts: {
count: 100,
count: 10,
accountsBalance: ether(1000000000),
},
// TODO: fix tests with gasPrice = 0 and remove the hardfork param
Expand All @@ -26,7 +26,7 @@ const getenv = (network, key, fallback, parser = i => i) => {
return value ? parser(value) : fallback;
};

for (const network of ['MAINNET', 'KOVAN', 'RINKEBY', 'TENDERLY', 'LOCALHOST']) {
for (const network of ['MAINNET', 'GOERLI', 'KOVAN', 'RINKEBY', 'TENDERLY', 'LOCALHOST']) {
const url = getenv(network, 'PROVIDER_URL', false);
if (!url) continue;
const accounts = getenv(network, 'ACCOUNT_KEY', undefined, v => v.split(/[^0-9a-fx]+/i));
Expand Down
9 changes: 3 additions & 6 deletions hardhat.config.js/solidity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const compilerSettings = process.env.ENABLE_OPTIMIZER ? { optimizer: { enabled: true, runs: 200 } } : {};
const compilerSettings = process.env.ENABLE_OPTIMIZER
? { optimizer: { enabled: true, runs: 200 } }
: {};

const compilers = {
'0.5.7': { settings: compilerSettings, version: '0.5.7' }, // nexus mutual v1
Expand All @@ -8,11 +10,6 @@ const compilers = {

const contracts = {
'0.5.7': ['contracts/modules/governance/Governance.sol'],
'0.5.17': [
'@uniswap/lib/contracts/libraries/FixedPoint.sol',
'@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol',
'@uniswap/v2-periphery/contracts/libraries/UniswapV2OracleLibrary.sol',
],
};

const overrides = {};
Expand Down
76 changes: 2 additions & 74 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
const assert = require('assert');
const exec = require('child_process').execSync;

const { network, web3 } = require('hardhat');
const readline = require('readline');

const { BN, toBN } = web3.utils;
const { BN, toBN } = require('web3').utils;

const hex = string => '0x' + Buffer.from(string).toString('hex');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const formatJSON = json => JSON.stringify(json, null, 2);

function getEnv (key, fallback = undefined) {

const value = process.env[key] || fallback;

if (typeof value === 'undefined') {
throw new Error(`Missing env var: ${key}`);
}

return value;
}

async function getNetwork () {

const chainId = await web3.eth.getChainId();
const networks = {
1: 'mainnet',
42: 'kovan',
31337: 'hardhat',
};

if (!networks[chainId]) {
throw new Error(`Unknown network with id ${chainId}`);
}

return networks[chainId];
}

const filterArgsKeys = args => {
const params = {};
Expand All @@ -48,42 +16,6 @@ const filterArgsKeys = args => {
return params;
};

/**
* Export tx to tenderly. Accepts a tx hash string or a promise that resolves to a receipt.
* Returns the receipt if a promise was passed.
* @param {string|Promise} txPromise
* @return {function((string|Promise)): Promise<(undefined|{})>}
*/
const tenderly = async txPromise => {

let tx = txPromise;
let receipt;

if (typeof txPromise !== 'string') {
const [ok, err] = await to(txPromise);
receipt = (ok || err);
tx = receipt.tx;
}

assert(network.name !== 'hardhat', 'Tenderly: network provider required to export tx');
const providerURL = network.config.url.replace(/^http:\/\//, '');
const cmd = `tenderly export ${tx} --rpc ${providerURL} --debug`;

console.log(`Executing: ${cmd}`);
await exec(cmd, { stdio: 'inherit' });

return receipt;
};

const logEvents = receipt => {
receipt.logs.forEach(log => {
const { event, args } = log;
const params = filterArgsKeys(args);
console.log(`Event emitted: ${event}(${formatJSON(params)}`);
});
return receipt;
};

const to = promise => new Promise(resolve => {
promise
.then(r => resolve([r, null]))
Expand Down Expand Up @@ -129,13 +61,9 @@ function zeroPadRight (bytes, length) {
module.exports = {
bnEqual,
filterArgsKeys,
getEnv,
getNetwork,
hex,
logEvents,
sleep,
to,
tenderly,
waitForInput,
zeroPadRight
zeroPadRight,
};
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const constants = require('./constants');
const helpers = require('./helpers');
const proposalCategories = require('./proposal-categories');

module.exports = {
constants,
helpers,
proposalCategories,
};
Loading

0 comments on commit 1957537

Please sign in to comment.