Skip to content

Commit

Permalink
Fix Defender Action to claim requests (#14)
Browse files Browse the repository at this point in the history
* Fix autoClaimWithdraw

* Upgrade ethers to v6

* Update Defender Actions
  • Loading branch information
naddison36 authored Aug 24, 2024
1 parent 8af08d0 commit de6d201
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require("dotenv").config();

require("@nomiclabs/hardhat-ethers");
require("@nomicfoundation/hardhat-ethers");
require("@nomicfoundation/hardhat-foundry");

require("./src/js/tasks/tasks");
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/js/actions/autoClaimWithdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const handler = async (event) => {
weth,
oethARM,
vault,
confirm: false,
confirm: true,
});
} catch (error) {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions src/js/actions/autoRequestWithdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions src/js/tasks/liquidity.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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,
});

Expand All @@ -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`
);
}
Expand All @@ -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)}%`
Expand Down
2 changes: 1 addition & 1 deletion src/js/tasks/swap.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/js/tasks/tokens.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/js/tasks/vault.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { parseUnits } = require("ethers").utils;
const { parseUnits } = require("ethers");

const { resolveAsset } = require("../utils/assets");
const { getSigner } = require("../utils/signers");
Expand Down Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/tasks/weth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { parseUnits } = require("ethers").utils;
const { parseUnits } = require("ethers");

const { logTxDetails } = require("../utils/txLogger");

Expand Down
9 changes: 4 additions & 5 deletions src/js/utils/queue.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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`
);
Expand Down
7 changes: 5 additions & 2 deletions src/js/utils/signers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/txLogger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { formatUnits } = require("ethers").utils;
const { formatUnits } = require("ethers");

const log = require("./logger")("utils:txLogger");

Expand Down

0 comments on commit de6d201

Please sign in to comment.