Withdraw helper hook.

Max withdrawable amount

availableWithdraw - The maximum balance that can be withdrawn at this moment (without having to settle PnL).

Available Balance

availableBalance - The available balance of the account, which is equal to the amount that can be withdrawn after settling all oustanding unsettled PnL.

Unsettled PnL

unsettledPnL - Amount of PnL that has not been settled into the account balance yet. Balance will be available to withdraw once PnL has been settled (if positive).

All of the above data can be retrieved through useWithdraw.

const { withdraw, isLoading, availableWithdraw, unsettledPnL } = useWithdraw();

Example

const { withdraw, availableWithdraw, isLoading } = useWithdraw();
const account = useAccountInstance();

const res = await withdraw();
return (
  <button
    onClick={async () => {
      await withdraw({
        chainId: Number(account.chainId),
        amount: availableWithdraw.toString(),
        token: "USDC",
        allowCrossChainWithdraw: false
      });
    }}
  >
    Withdraw all
  </button>
);