pub fn redeem<T: Config>(
internal_asset: T::AssetId,
external_asset: T::AssetId,
internal_amount: <<T as Config>::Fungibles as FungiblesInspect<<T as Config>::AccountId>>::Balance,
max_fee: Permill,
)Expand description
Swap internal for external asset on a specific PSM instance.
§Dispatch Origin
Must be Signed by the user performing the swap.
§Details
Burns internal_amount of internal_asset from the caller minus fee (transferred
to the instance’s PsmInfo::fee_destination), then transfers the resulting
amount in external_asset from the PSM reserve to the caller. The fee is
calculated using ceiling rounding (mul_ceil), ensuring the protocol never
undercharges. Redemptions use the decimals snapshotted when the PSM/external pair
was registered, allowing existing positions to unwind even if live metadata later
changes.
§Parameters
internal_asset: The internal stablecoin that identifies the PSM instance.external_asset: The external asset to receive (must be approved oninternal_asset).internal_amount: Amount ofinternal_assetto redeem.max_fee: Maximum redemption fee rate accepted by the caller.
§Errors
Error::PsmNotFound: If no PSM is registered forinternal_asset.Error::UnsupportedAsset: Ifexternal_assetis not approved on this PSM.Error::AllSwapsStopped: If the per-external circuit breaker is atAllDisabled.Error::BelowMinimumSwap: Ifinternal_amountis below the instance’smin_swap_amount.Error::FeeTooHigh: If the configured redemption fee exceedsmax_fee.Error::InsufficientReserve: If the PSM holds less ofexternal_assetthan the redemption requires.Error::AmountTooSmallAfterConversion: If the conversion to the counter-asset rounds to zero; swap would transfer nothing.
§Events
Event::Redeemed: Emitted on successful redemption.
§Warning: Doc-Only
This function is an automatically generated, and is doc-only, uncallable
stub. See the real version in
Pallet::redeem.