Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

RedemptionPoolV0

Git Source

Inherits: IRedemptionPool, AccessManaged, Pausable, ReentrancyGuardTransient

Title: RedemptionPoolV0

Redeems asset tokens for reserve assets at a configurable exchange rate

Non-upgradeable. Uses AccessManager for role-based access; ROLE_REDEEMER for redeem(), ADMIN for deposit/withdraw/setExchangeRate/pause/unpause. Exchange rate is reserve asset per asset (1e18 = 1:1) in the precision of the asset token.

The asset MUST support burnFrom(address,uint256) as defined in ERC20Burnable.

State Variables

asset

Asset token to be redeemed (burned); e.g. apxUSD

ERC20Burnable public immutable asset

reserveAsset

Reserve asset paid out on redemption; e.g. USDC

IERC20 public immutable reserveAsset

assetHasMoreDecimals

True if asset has more decimals than reserve, false otherwise

bool private immutable assetHasMoreDecimals

decimalScalingFactor

Scaling factor for decimal conversion: 10^abs(assetDecimals - reserveDecimals)

uint256 private immutable decimalScalingFactor

exchangeRate

Exchange rate: reserve asset per asset, 1e18 = 1:1 (reserveAmount = assetsAmount * exchangeRate / 1e18)

uint256 public exchangeRate

Functions

constructor

Initializes the redemption pool

constructor(address initialAuthority, ERC20Burnable asset_, IERC20 reserveAsset_) AccessManaged(initialAuthority);

Parameters

NameTypeDescription
initialAuthorityaddressAddress of the AccessManager contract
asset_ERC20BurnableAsset token (e.g. apxUSD)
reserveAsset_IERC20Reserve asset token (e.g. USDC)

previewRedeem

Preview how much reserve assets would be received for a given assets amount

Does not consider pause state or reserve balance; callers should check paused() and reserveBalance() Rounding is downward in favor of the pool. Formula: reserveAmount = (assetsAmount * exchangeRate) / (1e18 * 10^(assetDecimals - reserveDecimals))

function previewRedeem(uint256 assetsAmount) public view override returns (uint256 reserveAmount);

Parameters

NameTypeDescription
assetsAmountuint256Amount of assets to preview

Returns

NameTypeDescription
reserveAmountuint256Amount of reserve assets that would be received

redeem

Redeem assets for reserve assets at the current exchange rate

Requires ROLE_REDEEMER. Burns/transfers assets and sends reserve assets

function redeem(uint256 assetsAmount, address receiver, uint256 minReserveAssetOut)
    external
    override
    restricted
    whenNotPaused
    nonReentrant
    returns (uint256 reserveAmount);

Parameters

NameTypeDescription
assetsAmountuint256Amount of assets to redeem
receiveraddressAddress to receive the reserve assets
minReserveAssetOutuint256Minimum reserve assets to receive (slippage protection)

Returns

NameTypeDescription
reserveAmountuint256Amount of reserve assets received

deposit

Deposit reserve assets into the contract to fund redemptions

function deposit(uint256 reserveAmount) external override restricted nonReentrant;

Parameters

NameTypeDescription
reserveAmountuint256Amount of reserve assets to deposit

withdraw

Withdraw excess reserve assets from the contract

Restricted to admin role

function withdraw(uint256 amount, address receiver) external override restricted;

Parameters

NameTypeDescription
amountuint256
receiveraddressAddress to receive the reserve assets

withdrawTokens

Withdraw excess assets from the contract

Use to recover tokens erroneously sent to the pool (e.g. asset or any other ERC20). Can also withdraw reserve asset; equivalent to withdraw() for that case.

function withdrawTokens(address withdrawAsset, uint256 amount, address receiver)
    public
    override
    restricted
    nonReentrant;

Parameters

NameTypeDescription
withdrawAssetaddressAddress of the asset to withdraw
amountuint256Amount of the asset to withdraw
receiveraddressAddress to receive the asset

setExchangeRate

Update the exchange rate (assets to reserve assets)

Restricted to admin role

function setExchangeRate(uint256 newRate) external override restricted;

Parameters

NameTypeDescription
newRateuint256Reserve asset per asset, 1e18 = 1:1

pause

Pause redemptions

Restricted to admin role

function pause() external restricted;

unpause

Unpause redemptions

Restricted to admin role

function unpause() external restricted;

reserveBalance

Get the current reserve asset balance

function reserveBalance() public view override returns (uint256);

Returns

NameTypeDescription
<none>uint256Reserve asset balance available for redemptions