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

chore: testnet deployments #5

Merged
merged 16 commits into from
Aug 26, 2024
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ MAINNET_HTTPS_URL=
OPTIMISM_HTTPS_URL=
POLYGON_HTTPS_URL=
GOERLI_HTTPS_URL=
SEPOLIA_HTTPS_URL=
OP_GOERLI_HTTPS_URL=

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

# Etherscan (optional, only for verifying smart contracts)
Expand Down
4 changes: 2 additions & 2 deletions deploy/0-mainnet/001_keep3r_v1.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import IERC20 from '../../artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json';
import ERC20ForTest from '../../artifacts/solidity/for-test/ERC20ForTest.sol/ERC20ForTest.json';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { kp3rV1 } = await hre.getNamedAccounts();

await hre.deployments.save('KP3Rv1', {
address: kp3rV1,
abi: IERC20.abi,
abi: ERC20ForTest.abi,
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved
});
};

Expand Down
10 changes: 5 additions & 5 deletions deploy/1-mainnet-test/101_uni_v3_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import IUniswapV3Factory from '../../artifacts/@uniswap/v3-core/contracts/interf
import IUniswapV3Pool from '../../artifacts/@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, weth } = await hre.getNamedAccounts();
const { deployer, weth, uniV3Factory } = await hre.getNamedAccounts();

const kp3RForTest = await hre.deployments.get('KP3Rv1');
const uniV3Factory = '0x1f98431c8ad98523631ae4a59f267346ea31f984';

await hre.deployments.save('WETH', {
address: weth,
Expand All @@ -20,10 +19,11 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
abi: IUniswapV3Factory.abi,
});

let deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', kp3RForTest.address, weth, 10_000);
let deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', weth, kp3RForTest.address, 10_000);
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved

if (deployedPool == '0x0000000000000000000000000000000000000000') {
await hre.deployments.execute('UniV3Factory', { from: deployer, log: true }, 'createPool', kp3RForTest.address, weth, 10_000);
deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', kp3RForTest.address, weth, 10_000);
await hre.deployments.execute('UniV3Factory', { from: deployer, log: true }, 'createPool', weth, kp3RForTest.address, 10_000);
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved
deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', weth, kp3RForTest.address, 10_000);

// initialize pool
const initializeArgs: any[] = ['79228802809028250921140']; // close to 1-1
Expand Down
37 changes: 22 additions & 15 deletions deploy/1-mainnet-test/110_job_for_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,52 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

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

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

// register job
if (jobForTest.newlyDeployed) {
const jobs = await hre.deployments.read('Keep3rForTestnet', 'jobs');

if (!jobs.includes(jobForTest.address)) {
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) {
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)) {
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(100)) {
await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'mint(uint256)', toUnit(1));
if (kp3rBalance < toUnit(10)) {
await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'mint(uint256)', toUnit(100_000));
}

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('WETH', { from: deployer, log: true }, 'approve', pairManager.address, toUnit(100_000));

const mintArguments: any[] = [toUnit(1), toUnit(0.1), 0, 0, deployer];
const mintArguments: any[] = [toUnit(0.1), toUnit(100_000), 0, 0, deployer];
await hre.deployments.execute('UniV3PairManager', { from: deployer, log: true }, 'mint', ...mintArguments);
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved

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 },
Expand All @@ -55,14 +59,17 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
);
}

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

// wait for bond to be processed
console.log('waiting for bond to be processed');
await new Promise((resolve) => setTimeout(resolve, 10_000));
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved

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
2 changes: 1 addition & 1 deletion deploy/2-sidechain/203_keep3r_helper_and_sidechain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro

const keep3rV2Args = [governor, keep3rHelper.address, kp3rV1, keep3rEscrow.address];

const keep3r = await hre.deployments.deploy('Keep3rSidechain', {
await hre.deployments.deploy('Keep3rSidechain', {
contract: 'solidity/contracts/sidechain/Keep3rSidechain.sol:Keep3rSidechain',
from: deployer,
args: keep3rV2Args,
Expand Down
29 changes: 26 additions & 3 deletions deploy/3-sidechain-test/301_keep3r_helper_and_sidechain.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { toUnit } from '../../test/utils/bn';
import { addressRegistry } from '../../utils/constants';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
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');

const mainnetKp3rV1 = addressRegistry.kp3rV1[11155111];
const mainnetWeth = addressRegistry.weth[11155111];
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved

// swap ABI
const swapRouterABI = [
'function exactInputSingle(tuple tokenIn,uint256 amountIn,uint256 amountOutMinimum,uint256 sqrtPriceLimitX96,address to,uint256 deadline) external payable returns (uint256 amountOut)',
];

// swap router address
const swapRouter = await hre.ethers.getContractAt(swapRouterABI, '0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E');
wei3erHase marked this conversation as resolved.
Show resolved Hide resolved

const exactInputSingleParams = {
tokenIn: mainnetKp3rV1,
tokenOut: mainnetWeth,
fee: 10000,
recipient: deployer,
deadline: 2_000_000_000,
amountIn: toUnit(100),
amountOutMinimum: 0,
sqrtPriceLimitX96: 0,
};
await swapRouter.exactInputSingle(exactInputSingleParams, { from: deployer });

// 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 });
Expand All @@ -22,7 +45,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro

const keep3rV2Args = [governor, keep3rHelper.address, kp3rV1, keep3rEscrow.address];

const keep3r = await hre.deployments.deploy('Keep3rSidechainForTestnet', {
await hre.deployments.deploy('Keep3rSidechainForTestnet', {
contract: 'solidity/for-test/testnet/Keep3rSidechainForTestnet.sol:Keep3rSidechainForTestnet',
from: deployer,
args: keep3rV2Args,
Expand Down
4 changes: 2 additions & 2 deletions deploy/3-sidechain-test/310_fund_and_approve_liq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
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 }, 'deposit', toUnit(100));
await hre.deployments.execute('KP3Rv1', { from: deployer, log: true }, 'approve', keep3rEscrow.address, toUnit(100_000));
await hre.deployments.execute('Keep3rEscrow', { from: deployer, log: true }, 'deposit', toUnit(100_000));
await hre.deployments.execute('Keep3rEscrow', { from: deployer, log: true }, 'setMinter', keep3r.address);

await hre.deployments.execute('Keep3rHelperSidechain', { from: deployer, log: true }, 'setOracle', wkLP, kp3rWethOracle);
Expand Down
21 changes: 14 additions & 7 deletions deploy/3-sidechain-test/311_job_rated_for_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,37 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
log: true,
});

// register job
if (jobForTest.newlyDeployed) {
const jobs = await hre.deployments.read('Keep3rSidechainForTestnet', 'jobs');

if (!jobs.includes(jobForTest.address)) {
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) {
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)
toUnit(10)
);
}

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

// wait for bond to be processed
console.log('waiting for bond to be processed');
await new Promise((resolve) => setTimeout(resolve, 10_000));

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

Expand Down
3 changes: 3 additions & 0 deletions deploy/4-verify/410_verify_sidechain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro

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

const kp3rV1 = await hre.deployments.get('KP3Rv1');
await verifyContract(hre, kp3rV1);
};

deployFunction.tags = ['verify-sidechain'];
Expand Down
3 changes: 3 additions & 0 deletions deploy/4-verify/421_verify_testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
const keep3rV2 = await hre.deployments.get('Keep3rForTestnet');
await verifyContract(hre, keep3rV2);

const keep3rV1 = await hre.deployments.get('KP3Rv1');
await verifyContract(hre, keep3rV1);

const jobForTest = await hre.deployments.getOrNull('BasicJob');
if (jobForTest) {
await verifyContract(hre, jobForTest);
Expand Down
3 changes: 3 additions & 0 deletions deploy/4-verify/422_verify_testnet_sidechain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro
const keep3rV2 = await hre.deployments.get('Keep3rSidechainForTestnet');
await verifyContract(hre, keep3rV2);

const keep3rV1 = await hre.deployments.get('KP3Rv1OP');
await verifyContract(hre, keep3rV1);

const jobForTest = await hre.deployments.getOrNull('BasicJob');
if (jobForTest) {
await verifyContract(hre, jobForTest);
Expand Down
1 change: 1 addition & 0 deletions deployments/optimisticSepolia/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11155420
154 changes: 154 additions & 0 deletions deployments/optimisticSepolia/BasicJob.json

Large diffs are not rendered by default.

Loading
Loading