Skip to content

Commit

Permalink
fix: hot patch of withdrawal requests admin
Browse files Browse the repository at this point in the history
  • Loading branch information
LilaRest committed Mar 6, 2024
1 parent 12d6829 commit ff3a51b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 110 deletions.
96 changes: 48 additions & 48 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"files.exclude": {
"renovate.json": true,
"tsconfig.json": true,
"vercel.json": true,
"postcss.config.js": true,
"next-env.d.ts": true,
"CHANGELOG.md": true,
".releaserc.json": true,
".next": true,
".github": true,
"node_modules": true,
".eslintrc.json": true,
"package.json": true,
".gitignore": true,
"next.config.mjs": true,
".env.local": true,
".env.local.template": true,
"README.md": true,
"LICENSE": true,
"hardhat.config.ts": true,
".prettierrc.js": true,
"typechain-types": true,
"hardhat/artifacts": true,
"hardhat/cache": true,
".graphclient": true,
".graphclientrc.yml": true,
"wagmi.config.ts": true,
"tailwind.config.js": true,
"hardhat/abis": true,
"build": true,
"foundry.toml": true,
".gitmodules": true,
"slither.config.json": true,
"slither.db.json": true,
"solc.json": true,
"contracts/foundry/cache": true,
"contracts/foundry/out": true,
"contracts/hardhat/artifacts": true,
"contracts/hardhat/cache": true,
"secrets.json": true,
".env": true,
"report.md": true,
"postcss.config.cjs": true,
"hardhat.config.cts": true,
"bun.lockb": true,
".prettierrc.cjs": true,
"env.mjs": true,
"docs/": true,
"scripts/": true
"renovate.json": false,
"tsconfig.json": false,
"vercel.json": false,
"postcss.config.js": false,
"next-env.d.ts": false,
"CHANGELOG.md": false,
".releaserc.json": false,
".next": false,
".github": false,
"node_modules": false,
".eslintrc.json": false,
"package.json": false,
".gitignore": false,
"next.config.mjs": false,
".env.local": false,
".env.local.template": false,
"README.md": false,
"LICENSE": false,
"hardhat.config.ts": false,
".prettierrc.js": false,
"typechain-types": false,
"hardhat/artifacts": false,
"hardhat/cache": false,
".graphclient": false,
".graphclientrc.yml": false,
"wagmi.config.ts": false,
"tailwind.config.js": false,
"hardhat/abis": false,
"build": false,
"foundry.toml": false,
".gitmodules": false,
"slither.config.json": false,
"slither.db.json": false,
"solc.json": false,
"contracts/foundry/cache": false,
"contracts/foundry/out": false,
"contracts/hardhat/artifacts": false,
"contracts/hardhat/cache": false,
"secrets.json": false,
".env": false,
"report.md": false,
"postcss.config.cjs": false,
"hardhat.config.cts": false,
"bun.lockb": false,
".prettierrc.cjs": false,
"env.mjs": false,
"docs/": false,
"scripts/": false
},
// Required because of a bug with pnpm and prettier plugins.
// See: https://github.com/prettier-solidity/prettier-plugin-solidity#pnpm
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@auth/prisma-adapter": "^1.0.11",
"@graphprotocol/client-add-source-name": "2.0.0",
"@graphprotocol/graph-cli": "^0.68.0",
"@graphql-mesh/transform-prefix": "^0.97.0",
"@graphql-tools/utils": "9.2.1",
"@prisma/client": "^5.7.0",
"@radix-ui/react-alert-dialog": "^1.0.5",
Expand Down
113 changes: 66 additions & 47 deletions src/components/admin/ltokens/AdminLTokenWithdrawalRequests.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Address, AllowanceTxButton, Amount, Card, Spinner, TxButton } from "@/components/ui";
import {
Address,
AllowanceTxButton,
Amount,
Button,
Card,
Spinner,
TxButton,
} from "@/components/ui";
import { useContractAddress } from "@/hooks/useContractAddress";
import { FC, useEffect, useState } from "react";
import { AdminBrick } from "../AdminBrick";
Expand All @@ -22,6 +30,9 @@ import {
useSimulateLTokenProcessBigQueuedRequest,
useSimulateLTokenProcessQueuedRequests,
useSimulateLTokenRepatriate,
useWriteLTokenProcessBigQueuedRequest,
writeGenericErc20Approve,
writeLTokenProcessBigQueuedRequest,
} from "@/generated";
import clsx from "clsx";
import { UseSimulateContractReturnType, useBlockNumber } from "wagmi";
Expand All @@ -37,27 +48,56 @@ const ProcessBigRequestButton: FC<ProcessBigRequestButtonProps> = ({
lTokenAddress,
requestId,
}) => {
const preparation = useSimulateLTokenProcessBigQueuedRequest({
address: lTokenAddress,
args: [requestId],
});
console.log("rendered");
// const preparation = useSimulateLTokenProcessBigQueuedRequest({
// address: lTokenAddress,
// args: [requestId],
// });

// const { writeContract } = useWriteLTokenProcessBigQueuedRequest({
// mutation: {},
// });
const { data: underlyingAddress } = useReadLTokenUnderlying({ address: lTokenAddress });
const { data: requestData } = useReadLTokenWithdrawalQueue({
address: lTokenAddress,
args: [requestId],
});

return (
<AllowanceTxButton
token={underlyingAddress!}
spender={lTokenAddress!}
amount={requestData ? requestData[1] : 0n}
size="tiny"
preparation={preparation as UseSimulateContractReturnType}
transactionSummary={`Process big request with ID = ${Number(requestId)}`}
>
Process
</AllowanceTxButton>
<div className="flex gap-3 justify-center items-center">
<Button
size="tiny"
onClick={() => {
writeGenericErc20Approve(config, {
address: underlyingAddress!,
args: [lTokenAddress, requestData ? requestData[1] : 0n],
});
}}
>
1. Allow
</Button>
<Button
size="tiny"
onClick={() => {
writeLTokenProcessBigQueuedRequest(config, {
address: lTokenAddress,
args: [requestId],
});
}}
>
2. Process
</Button>
</div>
// <AllowanceTxButton
// token={underlyingAddress!}
// spender={lTokenAddress!}
// amount={requestData ? requestData[1] : 0n}
// size="tiny"
// preparation={preparation as UseSimulateContractReturnType}
// transactionSummary={`Process big request with ID = ${Number(requestId)}`}
// >
// Process
// </AllowanceTxButton>
);
};

Expand All @@ -84,13 +124,12 @@ export const AdminLTokenWithdrawalRequests: FC<Props> = ({ lTokenSymbol }) => {
const columnHelper = createColumnHelper<WithdrawalRequest>();
const [requestsData, setRequestsData] = useState<WithdrawalRequest[]>([]);
const [isLoading, setIsLoading] = useState(false);
const { data: queueCursor, queryKey: queueCursorQueryKey } = useReadLTokenWithdrawalQueueCursor({
const { data: queueCursor } = useReadLTokenWithdrawalQueueCursor({
address: lTokenAddress,
});
const { data: expectedRetained } = useReadLTokenGetExpectedRetained({
address: lTokenAddress,
});
const { data: expectedRetained, queryKey: expectedRetainedQueryKey } =
useReadLTokenGetExpectedRetained({
address: lTokenAddress,
});
const { data: usableUnderlyings } = useReadLTokenUsableUnderlyings({
address: lTokenAddress,
});
Expand All @@ -106,29 +145,16 @@ export const AdminLTokenWithdrawalRequests: FC<Props> = ({ lTokenSymbol }) => {
});
const { data: underlyingAddress } = useReadLTokenUnderlying({ address: lTokenAddress });

// Refresh some data every 5 blocks
const queryKeys = [queueCursorQueryKey, expectedRetainedQueryKey];
const { data: blockNumber } = useBlockNumber({ watch: true });
const queryClient = useQueryClient();
useEffect(() => {
if (blockNumber && blockNumber % 5n === 0n)
queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
}, [blockNumber, ...queryKeys]);

//
const computeRequestsData = async () => {
setIsLoading(true);

// setIsLoading(true);
// If queue cursor is available
if (typeof queueCursor === "bigint") {
let endOfQueueEncountered = false;
const newRequestsData: WithdrawalRequest[] = [];
let readQueueCursor = queueCursor;

// Until we reach the end of the queue
while (!endOfQueueEncountered) {
const proms: Promise<readonly [`0x${string}`, bigint]>[] = [];

// Retrieve batch of 50 queued requests data
for (let i = readQueueCursor; i < readQueueCursor + 50n; i++) {
proms.push(
Expand All @@ -139,43 +165,36 @@ export const AdminLTokenWithdrawalRequests: FC<Props> = ({ lTokenSymbol }) => {
}),
);
}

// Wait for all data requests to settle
const requestsData = await Promise.allSettled(proms);

const _requestsData = await Promise.allSettled(proms);
// Add requests data to the new data array
for (let i = readQueueCursor; i < readQueueCursor + 50n; i++) {
const requestData = requestsData[Number(i - readQueueCursor)];
if (requestData.status === "fulfilled") {
const [account, amount] = requestData.value;

const _requestData = _requestsData[Number(i - readQueueCursor)];
if (_requestData.status === "fulfilled") {
const [account, amount] = _requestData.value;
// Skip already processed requests
if (Number(account) == 0) continue;

// Else, add request data to the new data array
console.log(typeof expectedRetained);
newRequestsData.push({
id: i,
account: account,
amount: amount,
isBig: amount > expectedRetained! / 2n,
});
}

// If an error occurred, we reached the end of the queue
else {
endOfQueueEncountered = true;
}
}

// Increment queue cursor for next batch
readQueueCursor += 50n;
}

// Set new data
setRequestsData(newRequestsData);
}

setIsLoading(false);
// setIsLoading(false);
};

useEffect(() => {
Expand Down
14 changes: 7 additions & 7 deletions src/components/ui/AllowanceTxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ export const AllowanceTxButton: FC<Props> = ({
}, [allowance]);

// Refresh some data every 5 blocks
const queryKeys = [allowanceQueryKey, balanceQueryKey];
const { data: blockNumber } = useBlockNumber({ watch: true });
const queryClient = useQueryClient();
useEffect(() => {
if (blockNumber && blockNumber % 5n === 0n)
queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
}, [blockNumber, ...queryKeys]);
// const queryKeys = [allowanceQueryKey, balanceQueryKey];
// const { data: blockNumber } = useBlockNumber({ watch: true });
// const queryClient = useQueryClient();
// useEffect(() => {
// if (blockNumber && blockNumber % 5n === 0n)
// queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
// }, [blockNumber, ...queryKeys]);

const hasEnoughAllowance = Boolean(allowance !== undefined && allowance >= amount);

Expand Down
9 changes: 1 addition & 8 deletions src/lib/dapp/config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { http } from "@wagmi/core";
import { chains } from "./chains";
import { createClient } from "viem";
// import { getDefaultConfig } from "@rainbow-me/rainbowkit";
import { env } from "../../../env.mjs";
import { wallets } from "./wallets";
import { getDefaultConfig } from "@rainbow-me/rainbowkit";

export const config = getDefaultConfig({
appName: "Ledgity Yield",
projectId: env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID,
ssr: true,
// ssr: true,
chains,
wallets,
// @ts-ignore
client({ chain }) {
return createClient({ chain, transport: http() });
},
});

0 comments on commit ff3a51b

Please sign in to comment.