Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jun 12, 2024
1 parent 562e2cf commit 72c0a07
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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
4 changes: 2 additions & 2 deletions deploy/1-mainnet-test/101_uni_v3_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion deploy/1-mainnet-test/110_job_for_test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 16 additions & 3 deletions deploy/3-sidechain-test/301_keep3r_helper_and_sidechain.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -7,16 +8,28 @@ 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 = [
'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');

const swapRouter = await hre.ethers.getContractAt(swapRouterABI, router);

const exactInputSingleParams = {
tokenIn: mainnetKp3rV1,
Expand Down
42 changes: 31 additions & 11 deletions solidity/for-test/BasicJob.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
3 changes: 3 additions & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ export const addressRegistry = {
31337: '0x1f98431c8ad98523631ae4a59f267346ea31f984',
11155420: '0x8CE191193D15ea94e11d327b4c7ad8bbE520f6aF',
},
router: {
11155111: '0x3bfa4769fb09eefc5a80d6e87c3b9c650f7ae48e',
},
};

0 comments on commit 72c0a07

Please sign in to comment.