Redemption request
Create a redemption request on the shares contract to exit a fund.
function requestRedemption(
uint256 sharesIn, // amount of shares to redeem
uint256 minAssetsOut, // slippage protection, applied AFTER the redemption fee
address redemptionAsset,// must be approved for redemptions (canRedeem = true)
address receiver // who receives the assets
) external returns (uint256 requestId);Example
import { createWalletClient, createPublicClient, http, parseAbi, parseUnits } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
const SHARES = "0x..."; // fund shares contract
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const sharesAbi = parseAbi([
"function previewRedemption(uint256 shares, uint256 sharesPrice, address redemptionAsset) view returns (uint256)",
"function requestRedemption(uint256 sharesIn, uint256 minAssetsOut, address redemptionAsset, address receiver) returns (uint256)",
]);
const account = privateKeyToAccount("0x...");
const pub = createPublicClient({ chain: mainnet, transport: http() });
const wallet = createWalletClient({ account, chain: mainnet, transport: http() });
const sharesIn = parseUnits("500", 18); // 500 shares
// Estimate assets out (net of the redemption fee) at the last settled price, then apply slippage.
const expectedAssets = await pub.readContract({
address: SHARES, abi: sharesAbi, functionName: "previewRedemption",
args: [sharesIn, 0n, USDC],
});
const minAssetsOut = (expectedAssets * 9950n) / 10000n;
const hash = await wallet.writeContract({
address: SHARES, abi: sharesAbi, functionName: "requestRedemption",
args: [sharesIn, minAssetsOut, USDC, account.address],
});

Last updated