Skip to main content

PegStabilityModule

Functions

constructor

function constructor(
struct PegStabilityModule.OracleParams params,
uint256 _mintFeeBasisPoints,
uint256 _redeemFeeBasisPoints,
uint256 _reservesThreshold,
uint256 _feiLimitPerSecond,
uint256 _mintingBufferCap,
contract IERC20 _underlyingToken,
contract IPCVDeposit _surplusTarget
) public

constructor

Parameters

NameTypeDescription
paramsstruct PegStabilityModule.OracleParamsPSM constructor parameter struct
_mintFeeBasisPointsuint256
_redeemFeeBasisPointsuint256
_reservesThresholduint256
_feiLimitPerSeconduint256
_mintingBufferCapuint256
_underlyingTokencontract IERC20
_surplusTargetcontract IPCVDeposit

pauseRedeem

function pauseRedeem() external

set secondary pausable methods to paused

unpauseRedeem

function unpauseRedeem() external

set secondary pausable methods to unpaused

pauseMint

function pauseMint() external

set secondary pausable methods to paused

unpauseMint

function unpauseMint() external

set secondary pausable methods to unpaused

withdraw

function withdraw(
address to,
uint256 amount
) external

withdraw assets from PSM to an external address

Parameters

NameTypeDescription
toaddress
amountuint256

setMintFee

function setMintFee(
uint256 newMintFeeBasisPoints
) external

set the mint fee vs oracle price in basis point terms

Parameters

NameTypeDescription
newMintFeeBasisPointsuint256

setRedeemFee

function setRedeemFee(
uint256 newRedeemFeeBasisPoints
) external

set the redemption fee vs oracle price in basis point terms

Parameters

NameTypeDescription
newRedeemFeeBasisPointsuint256

setReservesThreshold

function setReservesThreshold(
uint256 newReservesThreshold
) external

set the ideal amount of reserves for the contract to hold for redemptions

Parameters

NameTypeDescription
newReservesThresholduint256

setSurplusTarget

function setSurplusTarget(
contract IPCVDeposit newTarget
) external

set the target for sending surplus reserves

Parameters

NameTypeDescription
newTargetcontract IPCVDeposit

_setMintFee

function _setMintFee(
uint256 newMintFeeBasisPoints
) internal

set the mint fee vs oracle price in basis point terms

Parameters

NameTypeDescription
newMintFeeBasisPointsuint256

_setRedeemFee

function _setRedeemFee(
uint256 newRedeemFeeBasisPoints
) internal

internal helper function to set the redemption fee

Parameters

NameTypeDescription
newRedeemFeeBasisPointsuint256

_setReservesThreshold

function _setReservesThreshold(
uint256 newReservesThreshold
) internal

helper function to set reserves threshold

Parameters

NameTypeDescription
newReservesThresholduint256

_setSurplusTarget

function _setSurplusTarget(
contract IPCVDeposit newSurplusTarget
) internal

helper function to set the surplus target

Parameters

NameTypeDescription
newSurplusTargetcontract IPCVDeposit

allocateSurplus

function allocateSurplus() external

send any surplus reserves to the PCV allocation

deposit

function deposit() external

function to receive ERC20 tokens from external contracts

_redeem

function _redeem(
address to,
uint256 amountFeiIn,
uint256 minAmountOut
) internal returns (uint256 amountOut)

internal helper method to redeem fei in exchange for an external asset

Parameters

NameTypeDescription
toaddress
amountFeiInuint256
minAmountOutuint256

_mint

function _mint(
address to,
uint256 amountIn,
uint256 minAmountOut
) internal returns (uint256 amountFeiOut)

internal helper method to mint fei in exchange for an external asset

Parameters

NameTypeDescription
toaddress
amountInuint256
minAmountOutuint256

redeem

function redeem(
address to,
uint256 amountFeiIn,
uint256 minAmountOut
) external returns (uint256 amountOut)

function to redeem FEI for an underlying asset We do not burn Fei; this allows the contract's balance of Fei to be used before the buffer is used In practice, this helps prevent artificial cycling of mint-burn cycles and prevents a griefing vector.

Parameters

NameTypeDescription
toaddress
amountFeiInuint256
minAmountOutuint256

mint

function mint(
address to,
uint256 amountIn,
uint256 minAmountOut
) external returns (uint256 amountFeiOut)

function to buy FEI for an underlying asset We first transfer any contract-owned fei, then mint the remaining if necessary

Parameters

NameTypeDescription
toaddress
amountInuint256
minAmountOutuint256

getMintAmountOut

function getMintAmountOut(
uint256 amountIn
) public returns (uint256 amountFeiOut)

calculate the amount of FEI out for a given amountIn of underlying First get oracle price of token Then figure out how many dollars that amount in is worth by multiplying price * amount. ensure decimals are normalized if on underlying they are not 18

Parameters

NameTypeDescription
amountInuint256

getRedeemAmountOut

function getRedeemAmountOut(
uint256 amountFeiIn
) public returns (uint256 amountTokenOut)

calculate the amount of underlying out for a given amountFeiIn of FEI First get oracle price of token Then figure out how many dollars that amount in is worth by multiplying price * amount. ensure decimals are normalized if on underlying they are not 18

Parameters

NameTypeDescription
amountFeiInuint256

getMaxMintAmountOut

function getMaxMintAmountOut() external returns (uint256)

the maximum mint amount out

hasSurplus

function hasSurplus() external returns (bool)

a flag for whether the current balance is above (true) or below (false) the reservesThreshold

reservesSurplus

function reservesSurplus() public returns (int256)

an integer representing the positive surplus or negative deficit of contract balance vs reservesThreshold

balance

function balance() public returns (uint256)

function from PCVDeposit that must be overriden

balanceReportedIn

function balanceReportedIn() external returns (address)

returns address of token this contracts balance is reported in

resistantBalanceAndFei

function resistantBalanceAndFei() public returns (uint256, uint256)

override default behavior of not checking fei balance

_getMintAmountOut

function _getMintAmountOut(
uint256 amountIn
) internal returns (uint256 amountFeiOut)

helper function to get mint amount out based on current market prices

will revert if price is outside of bounds and bounded PSM is being used

Parameters

NameTypeDescription
amountInuint256

_getRedeemAmountOut

function _getRedeemAmountOut(
uint256 amountFeiIn
) internal returns (uint256 amountTokenOut)

helper function to get redeem amount out based on current market prices

will revert if price is outside of bounds and bounded PSM is being used

Parameters

NameTypeDescription
amountFeiInuint256

_allocate

function _allocate(
uint256 amount
) internal

Allocates a portion of escrowed PCV to a target PCV deposit

Parameters

NameTypeDescription
amountuint256

_transfer

function _transfer(
address to,
uint256 amount
) internal

transfer ERC20 token

Parameters

NameTypeDescription
toaddress
amountuint256

_transferFrom

function _transferFrom(
address from,
address to,
uint256 amount
) internal

transfer assets from user to this contract

Parameters

NameTypeDescription
fromaddress
toaddress
amountuint256

_mintFei

function _mintFei(
address to,
uint256 amount
) internal

mint amount of FEI to the specified user on a rate limit

Parameters

NameTypeDescription
toaddress
amountuint256

_validatePriceRange

function _validatePriceRange(
struct Decimal.D256 price
) internal

overriden function in the bounded PSM

Parameters

NameTypeDescription
pricestruct Decimal.D256

Events

RedemptionsPaused

event RedemptionsPaused(
address account
)

event that is emitted when redemptions are paused

Parameters

NameTypeDescription
accountaddress

RedemptionsUnpaused

event RedemptionsUnpaused(
address account
)

event that is emitted when redemptions are unpaused

Parameters

NameTypeDescription
accountaddress

MintingPaused

event MintingPaused(
address account
)

event that is emitted when minting is paused

Parameters

NameTypeDescription
accountaddress

MintingUnpaused

event MintingUnpaused(
address account
)

event that is emitted when minting is unpaused

Parameters

NameTypeDescription
accountaddress