diff --git a/.env.example b/.env.example index b404eb6..4c9d936 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,7 @@ POLYGON_HTTPS_URL= GOERLI_HTTPS_URL= SEPOLIA_HTTPS_URL= OP_GOERLI_HTTPS_URL= +OP_SEPOLIA_HTTPS_URL= # Account's private keys MAINNET_PRIVATE_KEY= @@ -17,6 +18,7 @@ POLYGON_PRIVATE_KEY= GOERLI_PRIVATE_KEY= SEPOLIA_PRIVATE_KEY= OP_GOERLI_PRIVATE_KEY= +OP_SEPOLIA_PRIVATE_KEY= # Etherscan (optional, only for verifying smart contracts) ETHERSCAN_API_KEY= @@ -25,5 +27,6 @@ OPTIMISTIC_ETHERSCAN_API_KEY= POLYGON_ETHERSCAN_API_KEY= GOERLI_ETHERSCAN_API_KEY= OP_GOERLI_ETHERSCAN_API_KEY= +OP_SEPOLIA_ETHERSCAN_API_KEY= HARDHAT_DEPLOY_LOG=TRUE diff --git a/deploy/1-mainnet-test/101_uni_v3_pool.ts b/deploy/1-mainnet-test/101_uni_v3_pool.ts index dd206ca..9e2b260 100644 --- a/deploy/1-mainnet-test/101_uni_v3_pool.ts +++ b/deploy/1-mainnet-test/101_uni_v3_pool.ts @@ -19,10 +19,10 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro abi: IUniswapV3Factory.abi, }); - let deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', weth, kp3RForTest.address, 10_000); + let deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', kp3RForTest.address, weth, 10_000); if (deployedPool == '0x0000000000000000000000000000000000000000') { - await hre.deployments.execute('UniV3Factory', { from: deployer, log: true }, 'createPool', weth, kp3RForTest.address, 10_000); + await hre.deployments.execute('UniV3Factory', { from: deployer, log: true }, 'createPool', kp3RForTest.address, weth, 10_000); deployedPool = await hre.deployments.read('UniV3Factory', 'getPool', weth, kp3RForTest.address, 10_000); // initialize pool diff --git a/deploy/1-mainnet-test/110_job_for_test.ts b/deploy/1-mainnet-test/110_job_for_test.ts index 763943f..0e5e463 100644 --- a/deploy/1-mainnet-test/110_job_for_test.ts +++ b/deploy/1-mainnet-test/110_job_for_test.ts @@ -1,3 +1,4 @@ +import { WETH_ADDRESS } from '@e2e/common'; import { toUnit } from '@utils/bn'; import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; @@ -40,7 +41,15 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro 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_000)); - const mintArguments: any[] = [toUnit(0.1), toUnit(100_000), 0, 0, deployer]; + let mintArguments: any[]; + + // Check if WETH is the first token in the pair + if (WETH_ADDRESS > kp3RForTest.address) { + mintArguments = [toUnit(0.1), toUnit(100_000), 0, 0, deployer]; + } else { + mintArguments = [toUnit(100_000), 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); diff --git a/deploy/3-sidechain-test/301_keep3r_helper_and_sidechain.ts b/deploy/3-sidechain-test/301_keep3r_helper_and_sidechain.ts index 0331a12..9596cdc 100644 --- a/deploy/3-sidechain-test/301_keep3r_helper_and_sidechain.ts +++ b/deploy/3-sidechain-test/301_keep3r_helper_and_sidechain.ts @@ -1,3 +1,4 @@ +import { getChainId } from 'hardhat'; import { DeployFunction } from 'hardhat-deploy/types'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { toUnit } from '../../test/utils/bn'; @@ -7,8 +8,19 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro const { deployer, governor, kp3rV1, kp3rWethOracle, wethUsdOracle, usdDecimals } = await hre.getNamedAccounts(); const keep3rEscrow = await hre.deployments.get('Keep3rEscrow'); - const mainnetKp3rV1 = addressRegistry.kp3rV1[11155111]; - const mainnetWeth = addressRegistry.weth[11155111]; + const chainId: number = Number(getChainId()); + + let mainnetKp3rV1: string; + let mainnetWeth: string; + let router: string; + + if (chainId in addressRegistry.kp3rV1 && chainId in addressRegistry.weth && chainId in addressRegistry.router) { + mainnetKp3rV1 = addressRegistry.kp3rV1[chainId as keyof typeof addressRegistry.kp3rV1]; + mainnetWeth = addressRegistry.weth[chainId as keyof typeof addressRegistry.weth]; + router = addressRegistry.router[chainId as keyof typeof addressRegistry.router]; + } else { + throw new Error('ChainId not found in addressRegistry'); + } // swap ABI const swapRouterABI = [ @@ -16,7 +28,8 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro ]; // swap router address - const swapRouter = await hre.ethers.getContractAt(swapRouterABI, '0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E'); + + const swapRouter = await hre.ethers.getContractAt(swapRouterABI, router); const exactInputSingleParams = { tokenIn: mainnetKp3rV1, diff --git a/solidity/for-test/BasicJob.sol b/solidity/for-test/BasicJob.sol index 4fad47c..62933b3 100644 --- a/solidity/for-test/BasicJob.sol +++ b/solidity/for-test/BasicJob.sol @@ -1,20 +1,40 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.4 <0.9.0; -import '../interfaces/IKeep3r.sol'; +import "../interfaces/IKeep3r.sol"; contract BasicJob { - error KeeperNotValid(); + error KeeperNotValid(); - address public keep3r; - uint256 public nonce; - uint256[] public array; + address public keep3r; + uint256 public nonce; + uint256[] public array; - constructor(address _keep3r) { - keep3r = _keep3r; - } + constructor(address _keep3r) { + keep3r = _keep3r; + } - function test() external { - array.push(1); - } + function work() external upkeep {} + + function workHard(uint256 _howHard) external upkeep { + for (uint256 i = nonce; i < _howHard; i++) { + nonce++; + } + } + + function workRefund(uint256 _howHard) external upkeep { + for (uint256 i; i < _howHard; i++) { + array.push(i); + } + + while (array.length > 0) { + array.pop(); + } + } + + modifier upkeep() { + if (!IKeep3r(keep3r).isKeeper(msg.sender)) revert KeeperNotValid(); + _; + IKeep3r(keep3r).worked(msg.sender); + } } diff --git a/utils/constants.ts b/utils/constants.ts index 3ba198f..297d498 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -79,4 +79,7 @@ export const addressRegistry = { 31337: '0x1f98431c8ad98523631ae4a59f267346ea31f984', 11155420: '0x8CE191193D15ea94e11d327b4c7ad8bbE520f6aF', }, + router: { + 11155111: '0x3bfa4769fb09eefc5a80d6e87c3b9c650f7ae48e', + }, };