Skip to content

Commit

Permalink
chore: sidechain deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase authored Feb 20, 2023
2 parents ead559c + 510fb6d commit 4f7b4e8
Show file tree
Hide file tree
Showing 144 changed files with 22,978 additions and 2,856 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ ENCRYPTED_PRIVATE_KEY=

# HTTPs providers
MAINNET_HTTPS_URL=
OPTIMISM_HTTPS_URL=
POLYGON_HTTPS_URL=
GOERLI_HTTPS_URL=
OP_GOERLI_HTTPS_URL=

# Account's private keys
MAINNET_PRIVATE_KEY=
OPTIMISM_PRIVATE_KEY=
POLYGON_PRIVATE_KEY=
GOERLI_PRIVATE_KEY=
OP_GOERLI_PRIVATE_KEY=

# Etherscan (optional, only for verifying smart contracts)
ETHERSCAN_API_KEY=
ETHEREUM_ETHERSCAN_API_KEY=
OPTIMISTIC_ETHERSCAN_API_KEY=
POLYGON_ETHERSCAN_API_KEY=
GOERLI_ETHERSCAN_API_KEY=
OP_GOERLI_ETHERSCAN_API_KEY=

Expand Down
2 changes: 1 addition & 1 deletion deploy/0-mainnet/001_keep3r_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import IERC20 from '../../artifacts/@openzeppelin/contracts/token/ERC20/IERC20.s
const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { kp3rV1 } = await hre.getNamedAccounts();

hre.deployments.save('KP3Rv1', {
await hre.deployments.save('KP3Rv1', {
address: kp3rV1,
abi: IERC20.abi,
});
Expand Down
4 changes: 2 additions & 2 deletions deploy/0-mainnet/003_create_pair_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, kp3rWethOracle } = await hre.getNamedAccounts();

await hre.deployments.execute('UniV3PairManagerFactory', { from: deployer, gasLimit: 3e6, log: true }, 'createPairManager', kp3rWethOracle);
await hre.deployments.execute('UniV3PairManagerFactory', { from: deployer, log: true }, 'createPairManager', kp3rWethOracle);

const pairManagerAddress = await hre.deployments.read('UniV3PairManagerFactory', 'pairManagers', kp3rWethOracle);

hre.deployments.save('UniV3PairManager', {
await hre.deployments.save('UniV3PairManager', {
address: pairManagerAddress,
abi: IUniV3PairManager.abi,
});
Expand Down
79 changes: 44 additions & 35 deletions deploy/1-mainnet-test/110_job_for_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,66 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const { deployer, kp3rV1 } = await hre.getNamedAccounts();
const kp3RForTest = await hre.deployments.get('KP3Rv1');
const keep3rV2 = await hre.deployments.get('Keep3rForTestnet');
const pairManager = await hre.deployments.get('UniV3PairManager');

await hre.deployments.delete('BasicJob');
const jobForTest = await hre.deployments.deploy('BasicJob', {
from: deployer,
contract: 'solidity/for-test/BasicJob.sol:BasicJob',
contract: 'solidity/for-test/JobForTest.sol:JobForTest',
args: [keep3rV2.address],
log: true,
});

// register job
await hre.deployments.execute('Keep3rForTestnet', { from: deployer, log: true }, 'addJob', jobForTest.address);

// mint kLPs
let klpBalance = await hre.deployments.read('UniV3PairManager', 'balanceOf', deployer);
if (klpBalance == 0) {
const wethBalance = await hre.deployments.read('WETH', 'balanceOf', deployer);
if (wethBalance < toUnit(0.1)) {
await hre.deployments.execute('WETH', { from: deployer, log: true, value: toUnit(0.1) }, 'deposit');
}
const kp3rBalance = await hre.deployments.read('KP3Rv1', 'balanceOf', deployer);
if (kp3rBalance < toUnit(1)) {
await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'mint(uint256)', toUnit(1));
}
if (jobForTest.newlyDeployed) {
await hre.deployments.execute('Keep3rForTestnet', { from: deployer, log: true }, 'addJob', jobForTest.address);
}

const LIQUIDITY = await hre.deployments.read('Keep3rForTestnet', 'liquidityAmount', jobForTest.address, pairManager.address);
if (LIQUIDITY == 0) {
// deployer needs to have KP3R and WETH balance
let klpBalance = await hre.deployments.read('UniV3PairManager', 'balanceOf', deployer);
if (klpBalance == 0) {
const wethBalance = await hre.deployments.read('WETH', 'balanceOf', deployer);
if (wethBalance < toUnit(1)) {
await hre.deployments.execute('WETH', { from: deployer, log: true, value: toUnit(0.1) }, 'deposit');
}
const kp3rBalance = await hre.deployments.read('KP3Rv1', 'balanceOf', deployer);
if (kp3rBalance < toUnit(100)) {
await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'mint(uint256)', toUnit(1));
}

await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'approve', pairManager.address, toUnit(100));
await hre.deployments.execute('WETH', { from: deployer, log: true }, 'approve', pairManager.address, toUnit(100));
await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'approve', pairManager.address, toUnit(100));
await hre.deployments.execute('WETH', { from: deployer, log: true }, 'approve', pairManager.address, toUnit(100));

const mintArguments: any[] = [toUnit(1), toUnit(0.1), 0, 0, deployer];
await hre.deployments.execute('UniV3PairManager', { from: deployer, log: true }, 'mint', ...mintArguments);
const mintArguments: any[] = [toUnit(1), toUnit(0.1), 0, 0, deployer];
await hre.deployments.execute('UniV3PairManager', { from: deployer, log: true }, 'mint', ...mintArguments);

klpBalance = await hre.deployments.read('UniV3PairManager', 'balanceOf', deployer);
}

// add liquidity to job
await hre.deployments.execute('UniV3PairManager', { from: deployer, log: true }, 'approve', keep3rV2.address, klpBalance);
await hre.deployments.execute(
'Keep3rForTestnet',
{ from: deployer, log: true },
'addLiquidityToJob',
jobForTest.address,
pairManager.address,
klpBalance
);
}

klpBalance = await hre.deployments.read('UniV3PairManager', 'balanceOf', deployer);
const IS_KEEPER = await hre.deployments.read('Keep3rForTestnet', 'isKeeper', deployer);
if (!IS_KEEPER) {
// register deployer as keeper
await hre.deployments.execute('Keep3rForTestnet', { from: deployer, log: true }, 'bond', kp3RForTest.address, 0);
await hre.deployments.execute('Keep3rForTestnet', { from: deployer, log: true }, 'activate', kp3RForTest.address);
}

// add liquidity to job
await hre.deployments.execute('UniV3PairManager', { from: deployer, log: true }, 'approve', keep3rV2.address, klpBalance);
await hre.deployments.execute(
'Keep3rForTestnet',
{ from: deployer, log: true },
'addLiquidityToJob',
jobForTest.address,
pairManager.address,
klpBalance
);

// register deployer as keeper
await hre.deployments.execute('Keep3rForTestnet', { from: deployer, log: true }, 'bond', kp3RForTest.address, 0);
await hre.deployments.execute('Keep3rForTestnet', { from: deployer, log: true }, 'activate', kp3RForTest.address);
await hre.deployments.execute('BasicJob', { from: deployer, log: true, gasLimit: 1e6 }, 'work');
};

deployFunction.dependencies = ['testnet-keep3r'];
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, governor, kp3rV1, weth, kp3rWethOracle, wethUsdOracle } = await hre.getNamedAccounts();
const { deployer, governor, kp3rV1, weth, kp3rWethOracle, wethUsdOracle, usdDecimals } = await hre.getNamedAccounts();
const { kp3rV1: mainnetKp3rV1 } = await hre.companionNetworks['mainnet'].getNamedAccounts();

const keep3rEscrow = await hre.deployments.get('Keep3rEscrow');

// precalculate the address of Keep3rV2 contract
const currentNonce: number = await hre.ethers.provider.getTransactionCount(deployer);
const keeperV2Address: string = hre.ethers.utils.getContractAddress({ from: deployer, nonce: currentNonce + 1 });

const keep3rHelperArgs = [keeperV2Address, governor, kp3rV1, weth, kp3rWethOracle, wethUsdOracle];
const keep3rHelperArgs = [keeperV2Address, governor, mainnetKp3rV1, weth, kp3rWethOracle, wethUsdOracle, usdDecimals];

const keep3rHelper = await hre.deployments.deploy('Keep3rHelperSidechain', {
from: deployer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, governor, kp3rV1, weth, kp3rWethOracle, wethUsdOracle } = await hre.getNamedAccounts();
const { deployer, governor, kp3rV1, kp3rWethOracle, wethUsdOracle, usdDecimals } = await hre.getNamedAccounts();
const { kp3rV1: mainnetKp3rV1, weth: mainnetWeth } = await hre.companionNetworks['mainnet'].getNamedAccounts();

const keep3rEscrow = await hre.deployments.get('Keep3rEscrow');

// precalculate the address of Keep3rV2 contract
const currentNonce: number = await hre.ethers.provider.getTransactionCount(deployer);
const keeperV2Address: string = hre.ethers.utils.getContractAddress({ from: deployer, nonce: currentNonce + 1 });

const keep3rHelperArgs = [keeperV2Address, governor, kp3rV1, weth, kp3rWethOracle, wethUsdOracle];
const keep3rHelperArgs = [keeperV2Address, governor, mainnetKp3rV1, mainnetWeth, kp3rWethOracle, wethUsdOracle, usdDecimals];

const keep3rHelper = await hre.deployments.deploy('Keep3rHelperSidechainForTestnet', {
const keep3rHelper = await hre.deployments.deploy('Keep3rHelperSidechain', {
from: deployer,
contract: 'solidity/for-test/testnet/Keep3rHelperSidechainForTestnet.sol:Keep3rHelperSidechainForTestnet',
contract: 'solidity/contracts/sidechain/Keep3rHelperSidechain.sol:Keep3rHelperSidechain',
args: keep3rHelperArgs,
log: true,
});
Expand All @@ -27,8 +28,6 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
args: keep3rV2Args,
log: true,
});

await hre.deployments.execute('Keep3rEscrow', { from: deployer, log: true }, 'setMinter', keep3r.address);
};

deployFunction.dependencies = ['keep3r-escrow', 'save-oracles'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, kp3rWethOracle, kp3rV1 } = await hre.getNamedAccounts();
const { deployer, kp3rWethOracle, wkLP } = await hre.getNamedAccounts();
const keep3rEscrow = await hre.deployments.get('Keep3rEscrow');
const keep3r = await hre.deployments.get('Keep3rSidechainForTestnet');

await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'approve', keep3rEscrow.address, toUnit(100));
await hre.deployments.execute('Keep3rEscrow', { from: deployer, log: true, gasLimit: 2e6 }, 'deposit', toUnit(100));
await hre.deployments.execute('Keep3rEscrow', { from: deployer, log: true }, 'deposit', toUnit(100));
await hre.deployments.execute('Keep3rEscrow', { from: deployer, log: true }, 'setMinter', keep3r.address);

await hre.deployments.execute('Keep3rHelperSidechainForTestnet', { from: deployer, log: true }, 'setOracle', kp3rV1, kp3rWethOracle);
await hre.deployments.execute('Keep3rSidechainForTestnet', { from: deployer, log: true }, 'approveLiquidity', kp3rV1);
await hre.deployments.execute('Keep3rHelperSidechain', { from: deployer, log: true }, 'setOracle', wkLP, kp3rWethOracle);
await hre.deployments.execute('Keep3rSidechainForTestnet', { from: deployer, log: true }, 'approveLiquidity', wkLP);
};

deployFunction.dependencies = ['testnet-keep3r-sidechain'];
Expand Down
54 changes: 54 additions & 0 deletions deploy/3-sidechain-test/311_job_rated_for_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { toUnit } from '@utils/bn';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import IERC20 from '../../artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, kp3rV1, wkLP } = await hre.getNamedAccounts();
const keep3rV2 = await hre.deployments.get('Keep3rSidechainForTestnet');
await hre.deployments.save('wkLP', {
address: wkLP,
abi: IERC20.abi,
});

const jobForTest = await hre.deployments.deploy('BasicJob', {
from: deployer,
contract: 'solidity/for-test/JobRatedForTest.sol:JobRatedForTest',
args: [keep3rV2.address],
log: true,
});

// register job
if (jobForTest.newlyDeployed) {
await hre.deployments.execute('Keep3rSidechainForTestnet', { from: deployer, log: true }, 'addJob', jobForTest.address);
}

const LIQUIDITY = await hre.deployments.read('Keep3rSidechainForTestnet', 'liquidityAmount', jobForTest.address, wkLP);
if (LIQUIDITY == 0) {
// deployer needs to have kLP balance
const keep3rSidechain = await hre.deployments.get('Keep3rSidechainForTestnet');
await hre.deployments.execute('wkLP', { from: deployer, log: true }, 'approve', keep3rSidechain.address, toUnit(10));
await hre.deployments.execute(
'Keep3rSidechainForTestnet',
{ from: deployer, log: true },
'addLiquidityToJob',
jobForTest.address,
wkLP,
toUnit(1)
);
}

const IS_KEEPER = await hre.deployments.read('Keep3rSidechainForTestnet', 'isKeeper', deployer);
if (!IS_KEEPER) {
// register deployer as keeper
await hre.deployments.execute('Keep3rSidechainForTestnet', { from: deployer, log: true }, 'bond', kp3rV1, 0);
await hre.deployments.execute('Keep3rSidechainForTestnet', { from: deployer, log: true, gasLimit: 1e6 }, 'activate', kp3rV1);
}

await hre.deployments.execute('BasicJob', { from: deployer, log: true, gasLimit: 1e6 }, 'work');
};

deployFunction.dependencies = ['approve-testnet-liquidity'];
deployFunction.tags = ['job-rated-for-test'];

export default deployFunction;
38 changes: 0 additions & 38 deletions deploy/3-sidechain-test/411_job_rated_for_test.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions deploy/4-verify/410_verify_sidechain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { verifyContract } from 'utils/deploy';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const keep3rEscrow = await hre.deployments.get('Keep3rEscrow');
await verifyContract(hre, keep3rEscrow);

const keep3rHelper = await hre.deployments.get('Keep3rHelperSidechain');
await verifyContract(hre, keep3rHelper);

const keep3rV2 = await hre.deployments.get('Keep3rSidechain');
await verifyContract(hre, keep3rV2);
};

deployFunction.tags = ['verify-sidechain'];

export default deployFunction;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
const pairManager = await hre.deployments.get('UniV3PairManager');
await verifyContract(hre, pairManager);

const keep3rHelper = await hre.deployments.get('Keep3rHelperForTestnet');
const keep3rHelper = await hre.deployments.get('Keep3rHelper');
await verifyContract(hre, keep3rHelper);

const keep3rV2 = await hre.deployments.get('Keep3rForTestnet');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
const keep3rEscrow = await hre.deployments.get('Keep3rEscrow');
await verifyContract(hre, keep3rEscrow);

const keep3rHelper = await hre.deployments.get('Keep3rHelperSidechainForTestnet');
const keep3rHelper = await hre.deployments.get('Keep3rHelperSidechain');
await verifyContract(hre, keep3rHelper);

const keep3rV2 = await hre.deployments.get('Keep3rSidechainForTestnet');
Expand Down
Loading

0 comments on commit 4f7b4e8

Please sign in to comment.