Withdraw from a Pool
Enable the user to redeem their assets from a Teller ERC4626 pool.
The following code example is in typescript. These smart contract integrations can be generalized to any codebase.
WITHDRAW (vault.redeem)
Remember, if the user’s shares are staked, they must withdraw them from staking first, then redeemed to assets. Follow steps in previous page Unstake Pool Shares.
export async function redeem({
client, account, vault, staking, sharesStr, vaultShareDecimals,
}: {
client:any; account:`0x${string}`; vault:`0x${string}`; staking:`0x${string}`;
sharesStr:string; vaultShareDecimals:number;
}) {
const shares = parseUnits(sharesStr, vaultShareDecimals);
// Redeem shares → assets back to user
await client.writeContract({
address: vault, abi: erc4626Abi, functionName: 'redeem',
args: [shares, account, account],
});
}
If the user has both staked and unstaked shares and wants to exit fully, call
withdraw(stakedShares)
first, thenredeem(totalShares)
.
Last updated