diff --git a/hardhat.config.js b/hardhat.config.js index 1b52b1a..3f6508a 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -2,7 +2,7 @@ require("dotenv").config(); -require("@nomiclabs/hardhat-ethers"); +require("@nomicfoundation/hardhat-ethers"); require("@nomicfoundation/hardhat-foundry"); require("./src/js/tasks/tasks"); diff --git a/package.json b/package.json index 798dc4e..1cad10a 100644 --- a/package.json +++ b/package.json @@ -13,24 +13,25 @@ "license": "MIT", "devDependencies": { "@apollo/client": "^3.11.4", - "@nomiclabs/hardhat-ethers": "2.0.2", + "@ethersproject/providers": "^5.7.2", + "@nomicfoundation/hardhat-ethers": "3.0.7", "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-network-helpers": "^1.0.10", "@openzeppelin/defender-autotask-client": "^1.54.1", - "@openzeppelin/defender-sdk": "1.13.1", + "@openzeppelin/defender-sdk": "1.14.3", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", "@solidity-parser/parser": "^0.18.0", - "axios": "^1.6.2", + "axios": "^1.7.5", "builtin-modules": "^3.3.0", "chai": "^4.3.10", "dayjs": "^1.11.12", "dotenv": "^16.4.5", "eslint": "^8.55.0", - "ethers": "5.7.2", + "ethers": "6.13.2", "graphql": "^16.9.0", - "hardhat": "^2.19.2", + "hardhat": "^2.22.9", "rollup": "^4.9.1" } } diff --git a/src/js/actions/autoClaimWithdraw.js b/src/js/actions/autoClaimWithdraw.js index d5df381..1ed39b4 100644 --- a/src/js/actions/autoClaimWithdraw.js +++ b/src/js/actions/autoClaimWithdraw.js @@ -31,7 +31,7 @@ const handler = async (event) => { weth, oethARM, vault, - confirm: false, + confirm: true, }); } catch (error) { console.error(error); diff --git a/src/js/actions/autoRequestWithdraw.js b/src/js/actions/autoRequestWithdraw.js index 03f26ab..ffbb70b 100644 --- a/src/js/actions/autoRequestWithdraw.js +++ b/src/js/actions/autoRequestWithdraw.js @@ -28,8 +28,8 @@ const handler = async (event) => { signer, oeth, oethARM, - minAmount: 0.001, - confirm: false, + minAmount: 1, + confirm: true, }); } catch (error) { console.error(error); diff --git a/src/js/tasks/liquidity.js b/src/js/tasks/liquidity.js index 96f336c..fea79b2 100644 --- a/src/js/tasks/liquidity.js +++ b/src/js/tasks/liquidity.js @@ -1,4 +1,4 @@ -const { formatUnits, parseUnits } = require("ethers").utils; +const { formatUnits, parseUnits } = require("ethers"); const { parseAddress } = require("../utils/addressParser"); const { resolveAsset } = require("../utils/assets"); @@ -37,7 +37,7 @@ const autoRequestWithdraw = async ({ minAmount, confirm, }) => { - const oethBalance = await oeth.balanceOf(oethARM.address); + const oethBalance = await oeth.balanceOf(await oethARM.getAddress()); log(`${formatUnits(oethBalance)} OETH in ARM`); const minAmountBI = parseUnits(minAmount.toString(), 18); @@ -62,18 +62,18 @@ const autoClaimWithdraw = async ({ signer, weth, oethARM, vault, confirm }) => { const { claimed } = await vault.withdrawalQueueMetadata(); // Get WETH balance in OETH Vault - const wethBalance = await weth.balanceOf(oethARM.address); + const wethVaultBalance = await weth.balanceOf(await vault.getAddress()); - const queuedAmountClaimable = claimed.add(wethBalance); + const queuedAmountClaimable = claimed + wethVaultBalance; log( `Claimable queued amount is ${formatUnits(claimed)} claimed + ${formatUnits( - wethBalance + wethVaultBalance )} WETH in vault = ${formatUnits(queuedAmountClaimable)}` ); // get claimable withdrawal requests let requestIds = await claimableRequests({ - withdrawer: oethARM.address, + withdrawer: await oethARM.getAddress(), queuedAmountClaimable, }); @@ -94,7 +94,7 @@ const withdrawRequestStatus = async ({ id, oethARM, vault }) => { } else { console.log( `Withdrawal request ${id} is ${formatUnits( - request.queued.sub(queue.claimable) + request.queued - queue.claimable )} WETH short` ); } @@ -107,19 +107,19 @@ const logLiquidity = async () => { const oethARM = await ethers.getContractAt("OethARM", oethArmAddress); const weth = await resolveAsset("WETH"); - const liquidityWeth = await weth.balanceOf(oethARM.address); + const liquidityWeth = await weth.balanceOf(await oethARM.getAddress()); const oeth = await resolveAsset("OETH"); - const liquidityOeth = await oeth.balanceOf(oethARM.address); + const liquidityOeth = await oeth.balanceOf(await oethARM.getAddress()); const liquidityOethWithdraws = await outstandingWithdrawalAmount({ - withdrawer: oethARM.address, + withdrawer: await oethARM.getAddress(), }); - const total = liquidityWeth.add(liquidityOeth).add(liquidityOethWithdraws); - const wethPercent = total == 0 ? 0 : liquidityWeth.mul(10000).div(total); + const total = liquidityWeth + liquidityOeth + liquidityOethWithdraws; + const wethPercent = total == 0 ? 0 : (liquidityWeth * 10000n) / total; const oethWithdrawsPercent = - total == 0 ? 0 : liquidityOethWithdraws.mul(10000).div(total); - const oethPercent = total == 0 ? 0 : liquidityOeth.mul(10000).div(total); + total == 0 ? 0 : (liquidityOethWithdraws * 10000n) / total; + const oethPercent = total == 0 ? 0 : (liquidityOeth * 10000n) / total; console.log( `${formatUnits(liquidityWeth, 18)} WETH ${formatUnits(wethPercent, 2)}%` diff --git a/src/js/tasks/swap.js b/src/js/tasks/swap.js index 3056b26..4e64178 100644 --- a/src/js/tasks/swap.js +++ b/src/js/tasks/swap.js @@ -1,4 +1,4 @@ -const { parseUnits, MaxInt256 } = require("ethers").utils; +const { parseUnits, MaxInt256 } = require("ethers"); const { resolveAddress } = require("../utils/assets"); const { getSigner } = require("../utils/signers"); diff --git a/src/js/tasks/tokens.js b/src/js/tasks/tokens.js index 373260f..acdfe93 100644 --- a/src/js/tasks/tokens.js +++ b/src/js/tasks/tokens.js @@ -1,4 +1,4 @@ -const { parseUnits, formatUnits } = require("ethers").utils; +const { parseUnits, formatUnits } = require("ethers"); const { resolveAsset } = require("../utils/assets"); const { getSigner } = require("../utils/signers"); diff --git a/src/js/tasks/vault.js b/src/js/tasks/vault.js index 1f4103d..500ddcf 100644 --- a/src/js/tasks/vault.js +++ b/src/js/tasks/vault.js @@ -1,4 +1,4 @@ -const { parseUnits } = require("ethers").utils; +const { parseUnits } = require("ethers"); const { resolveAsset } = require("../utils/assets"); const { getSigner } = require("../utils/signers"); @@ -73,14 +73,14 @@ async function mint({ amount, asset, min, approve }) { if (approve) { const approveTx = await cAsset .connect(signer) - .approve(vault.address, assetUnits); + .approve(await vault.getAddress(), assetUnits); await logTxDetails(approveTx, "approve"); } log(`About to mint OETH from ${amount} ${asset}`); const tx = await vault .connect(signer) - .mint(cAsset.address, assetUnits, minUnits); + .mint(await cAsset.getAddress(), assetUnits, minUnits); await logTxDetails(tx, "mint"); } diff --git a/src/js/tasks/weth.js b/src/js/tasks/weth.js index b9f3539..ca94c65 100644 --- a/src/js/tasks/weth.js +++ b/src/js/tasks/weth.js @@ -1,4 +1,4 @@ -const { parseUnits } = require("ethers").utils; +const { parseUnits } = require("ethers"); const { logTxDetails } = require("../utils/txLogger"); diff --git a/src/js/utils/queue.js b/src/js/utils/queue.js index 81697b2..5bf78bf 100644 --- a/src/js/utils/queue.js +++ b/src/js/utils/queue.js @@ -1,8 +1,7 @@ const { ApolloClient, InMemoryCache, gql } = require("@apollo/client/core"); const dayjs = require("dayjs"); const utc = require("dayjs/plugin/utc"); -const { BigNumber } = require("ethers"); -const { formatUnits } = require("ethers").utils; +const { formatUnits } = require("ethers"); // Extend Day.js with the UTC plugin dayjs.extend(utc); @@ -46,8 +45,8 @@ const outstandingWithdrawalAmount = async ({ withdrawer }) => { ); const amount = data.oethWithdrawalRequests.reduce( - (acc, request) => acc.add(request.amount), - BigNumber.from(0) + (acc, request) => acc + BigInt(request.amount), + 0n ); return amount; @@ -65,7 +64,7 @@ const claimableRequests = async ({ withdrawer, queuedAmountClaimable }) => { }); log( - `About to get claimable withdrawal requests for ${withdrawer} up to ${formatUnits( + `About to get claimable withdrawal requests for withdrawer ${withdrawer} up to ${formatUnits( queuedAmountClaimable )} WETH` ); diff --git a/src/js/utils/signers.js b/src/js/utils/signers.js index fadb5e0..eddea43 100644 --- a/src/js/utils/signers.js +++ b/src/js/utils/signers.js @@ -76,9 +76,12 @@ const getDefenderSigner = async () => { relayerApiSecret: process.env.DEFENDER_RELAYER_SECRET, }; const client = new Defender(credentials); - const provider = client.relaySigner.getProvider(); + const provider = client.relaySigner.getProvider({ ethersVersion: "v6" }); - const signer = await client.relaySigner.getSigner(provider, { speed }); + const signer = await client.relaySigner.getSigner(provider, { + speed, + ethersVersion: "v6", + }); log( `Using Defender Relayer account ${await signer.getAddress()} from env vars DEFENDER_RELAYER_KEY and DEFENDER_RELAYER_SECRET` ); diff --git a/src/js/utils/txLogger.js b/src/js/utils/txLogger.js index d15e265..54aa2ac 100644 --- a/src/js/utils/txLogger.js +++ b/src/js/utils/txLogger.js @@ -1,4 +1,4 @@ -const { formatUnits } = require("ethers").utils; +const { formatUnits } = require("ethers"); const log = require("./logger")("utils:txLogger");