Skip to content

Commit

Permalink
fix: fixed low level call and hardhat fork issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GabiDev45 committed Aug 19, 2024
1 parent 58b50c8 commit 201762e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
11 changes: 4 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0",
"@typechain/ethers-v6": "^0.5.1",
Expand Down
15 changes: 8 additions & 7 deletions scripts/arbitrage.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { ethers, parseEther } from "ethers"
import { ethers, parseEther, parseUnits } from "ethers"
import { Protocols, Routers, dodoV2Pool, factories } from "../constants"
import { ERC20Token } from "../constants/tokens"
import { getPriceInUSDC } from "../utils/getPriceInUSDC"
import flashloan from "../artifacts/contracts/FlashLoan.sol/Flashloan.json";
import { FlashLoanParams } from "../types";
import { findRouterByProtocol } from "../utils/findRouterByProtocol";
import { executeFlashloan } from "./executeFlashloan";
import * as helpers from "@nomicfoundation/hardhat-network-helpers";

const MIN_PRICE_DIFF = 1000000 // $10;

async function main() {
// WETH / USDC POOLS
const checkArbitrage = async () => {
// This line is a temporary fix for https://github.com/NomicFoundation/hardhat/issues/5511
await helpers.mine()

const provider = new ethers.JsonRpcProvider(process.env.PROVIDER_URL!);

Expand Down Expand Up @@ -49,20 +51,19 @@ async function main() {
// execute arbitrage flashloan
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const Flashloan = new ethers.Contract(process.env.FLASHLOAN_ADDRESS!, flashloan.abi, provider);

const params: FlashLoanParams = {
flashLoanContractAddress: Flashloan.target.toString(),
flashLoanPool: dodoV2Pool.WETH_USDC,
loanAmount: parseEther("1"), // Loaning 1 WETH
loanAmountDecimals: 18,
loanAmount: parseUnits("0.0001", 18), // Loaning 0.0001 WETH
hops: [
{
protocol: max.protocol,
data: ethers.AbiCoder.defaultAbiCoder().encode(
["address"],
[findRouterByProtocol(min.protocol)]
),
path: [ERC20Token.USDC?.address, ERC20Token.WETH?.address],
path: [ERC20Token.WETH?.address, ERC20Token.USDC?.address],
amountOutMinV3: 0,
sqrtPriceLimitX96: 0
},
Expand All @@ -72,7 +73,7 @@ async function main() {
["address"],
[findRouterByProtocol(min.protocol)]
),
path: [ERC20Token.WETH?.address, ERC20Token.USDC?.address],
path: [ERC20Token.USDC?.address, ERC20Token.WETH?.address],
amountOutMinV3: 0,
sqrtPriceLimitX96: 0
},
Expand Down
1 change: 0 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe("DODO Flashloan", () => {
flashLoanContractAddress: Flashloan.target.toString(),
flashLoanPool: dodoV2Pool.WETH_ULT,
loanAmount: ethers.parseEther("0.1"),
loanAmountDecimals: 18,
hops: [
{
protocol: Protocols.QUICKSWAP,
Expand Down
1 change: 0 additions & 1 deletion types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type FlashLoanParams = {
flashLoanContractAddress: string;
flashLoanPool: string;
loanAmount: number | ethers.BigNumberish;
loanAmountDecimals: number;
hops: Hop[];
gasLimit: number;
gasPrice: number | bigint;
Expand Down

0 comments on commit 201762e

Please sign in to comment.