Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/pages/Actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
COMPOUNDING_CONTRACT_ADDRESS,
WITHDRAWAL_CONTRACT_ADDRESS,
TICKER_NAME,
EXCESS_INHIBITOR,
} from '../../utils/envVars';

export type Queue = {
Expand Down Expand Up @@ -35,13 +36,23 @@ const getRequiredFee = (queueLength: BigNumber): BigNumber => {
export const getCompoundingQueueLength = async (
web3: Web3
): Promise<BigNumber> => {
const queueLengthHex = await web3.eth.getStorageAt(
COMPOUNDING_CONTRACT_ADDRESS!,
0 // EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT
);

if (!queueLengthHex)
throw new Error('Unable to get compounding queue length');
let queueLengthHex;
try {
queueLengthHex = await web3.eth.getStorageAt(
COMPOUNDING_CONTRACT_ADDRESS!,
0 // EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT
);

if (!queueLengthHex) {
throw new Error('Unable to get compounding queue length');
}
if (queueLengthHex === EXCESS_INHIBITOR) {
throw new Error('Compounding queue is disabled');
}
} catch (error) {
console.error(error);
queueLengthHex = '0x0';
}

return new BigNumber(queueLengthHex);
};
Expand All @@ -58,13 +69,22 @@ export const getCompoundingQueue = async (web3: Web3): Promise<Queue> => {
export const getWithdrawalQueueLength = async (
web3: Web3
): Promise<BigNumber> => {
const queueLengthHex = await web3.eth.getStorageAt(
WITHDRAWAL_CONTRACT_ADDRESS!,
0 // EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT
);

if (!queueLengthHex) {
throw new Error('Unable to get withdrawal queue length');
let queueLengthHex;
try {
queueLengthHex = await web3.eth.getStorageAt(
WITHDRAWAL_CONTRACT_ADDRESS!,
0 // EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT
);

if (!queueLengthHex) {
throw new Error('Unable to get withdrawal queue length');
}
if (queueLengthHex === EXCESS_INHIBITOR) {
throw new Error('Withdrawal queue is disabled');
}
} catch (error) {
console.error(error);
queueLengthHex = '0x0';
}

return new BigNumber(queueLengthHex);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/envVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ if(process.env.REACT_APP_MAX_QUERY_LIMIT && Number.isNaN(Number(process.env.REAC
throw new Error("REACT_APP_MAX_QUERY_LIMIT must be of type: number")
}
export const MAX_QUERY_LIMIT = Number(process.env.REACT_APP_MAX_QUERY_LIMIT) || 100;

export const EXCESS_INHIBITOR = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";