The redeemFromPosition function allows users to withdraw collateral from an existing position.
redeemFromPosition
redeemFromPosition( pcpId: string, collateralToken: string, indexToken: string, amount: number, long: boolean ): Promise<TransactionBlock>
pcpId: The ID of the position to redeem from
pcpId
collateralToken: The token used as collateral (e.g., "USDC")
collateralToken
indexToken: The token used as the market index (e.g., "BTC")
indexToken
amount: The amount of collateral to withdraw
amount
long: Boolean indicating if this is a long (true) or short (false) position
long
Returns a Promise that resolves to a TransactionBlock object.
Promise
TransactionBlock
const tx = await sudoAPI.redeemFromPosition( '0x123...', // pcpId 'USDC', // collateralToken 'BTC', // indexToken 500000, // amount (0.5 USDC if USDC has 6 decimals) true // long position );