Given an amount of shares, we want to predict whether a withdrawal for this amount of shares will be queued or not under the current contract conditions.
We can satisfy this usecase by adding a query that simply outputs the number that's available for instant withdrawal.
unverified typescript sketch for reference, need to double-check against withdraw function on vault contract:
// 1. Vault queries
const availableForDeployment = await queryAvailableForDeployment(); // contract balance minus all queued
const queueInfo = await queryWithdrawalQueueInfo(); // for non_funded_withdrawal_amount
const { adapters } = await queryListAdapters(); // [(name, AdapterInfo)]
// 2. Query each Automated adapter for withdrawable amount
const adapterAvailable = await Promise.all(
adapters
.filter(([_, info]) => info.allocation_mode === "Automated")
.map(([_, info]) => queryAdapterAvailableForWithdraw(info.address, vaultAddress, denom))
);
const totalFromAdapters = adapterAvailable.reduce((sum, amt) => sum + BigInt(amt), 0n);
// 3. Mirror the contract's logic exactly
const availableFromContract =
BigInt(availableForDeployment) + BigInt(queueInfo.info.non_funded_withdrawal_amount);
const totalAvailable = availableFromContract + totalFromAdapters;
Given an amount of shares, we want to predict whether a withdrawal for this amount of shares will be queued or not under the current contract conditions.
We can satisfy this usecase by adding a query that simply outputs the number that's available for instant withdrawal.
unverified typescript sketch for reference, need to double-check against withdraw function on vault contract: