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

SelfPeggingAssetFactory

Git Source

Inherits: UUPSUpgradeable, OwnableUpgradeable

Author: Nuts Finance Developer

The StableSwap Application provides an interface for users to interact with StableSwap pool contracts

The StableSwap Application contract allows users to mint pool tokens, swap between different tokens, and redeem pool tokens to underlying tokens. This contract should never store assets.

State Variables

governor

This is the account that has governor control over the protocol.

address public governor;

mintFee

Default mint fee for the pool.

uint256 public mintFee;

swapFee

Default swap fee for the pool.

uint256 public swapFee;

redeemFee

Default redeem fee for the pool.

uint256 public redeemFee;

offPegFeeMultiplier

Default off peg fee multiplier for the pool.

uint256 public offPegFeeMultiplier;

A

Default A parameter for the pool.

uint256 public A;

selfPeggingAssetBeacon

Beacon for the SelfPeggingAsset implementation.

address public selfPeggingAssetBeacon;

spaTokenBeacon

Beacon for the SPAToken implementation.

address public spaTokenBeacon;

wspaTokenBeacon

Beacon for the WSPAToken implementation.

address public wspaTokenBeacon;

rampAControllerBeacon

Beacon for the RampAController implementation.

address public rampAControllerBeacon;

constantExchangeRateProvider

Constant exchange rate provider.

address public constantExchangeRateProvider;

keeperImplementation

address public keeperImplementation;

minRampTime

Minimum ramp time for the A parameter.

uint256 public minRampTime;

exchangeRateFeeFactor

The exchange rate fee factor.

uint256 public exchangeRateFeeFactor;

bufferPercent

The buffer percent for the SPAToken.

uint256 public bufferPercent;

Functions

constructor

constructor();

initialize

Initializes the StableSwap Application contract.

function initialize(InitializeArgument memory argument) public initializer;

setGovernor

Set the govenance address.

function setGovernor(address _governor) external onlyOwner;

setMintFee

Set the mint fee.

function setMintFee(uint256 _mintFee) external onlyOwner;

setSwapFee

Set the swap fee.

function setSwapFee(uint256 _swapFee) external onlyOwner;

setRedeemFee

Set the redeem fee.

function setRedeemFee(uint256 _redeemFee) external onlyOwner;

setOffPegFeeMultiplier

Set the off peg fee multiplier.

function setOffPegFeeMultiplier(uint256 _offPegFeeMultiplier) external onlyOwner;

setA

Set the A parameter.

function setA(uint256 _A) external onlyOwner;

setMinRampTime

Set the minimum ramp time.

function setMinRampTime(uint256 _minRampTime) external onlyOwner;

setExchangeRateFeeFactor

Set the exchange rate fee factor.

function setExchangeRateFeeFactor(uint256 _exchangeRateFeeFactor) external onlyOwner;

setBufferPercent

Set the buffer percentage.

function setBufferPercent(uint256 _bufferPercent) external onlyOwner;

setKeeperImplementation

Set the keeper implementation.

function setKeeperImplementation(address _keeperImplementation) external onlyOwner;

createPool

Create a new pool.

function createPool(CreatePoolArgument memory argument)
    external
    returns (WSPAToken wspaToken, Keeper keeper, ParameterRegistry parameterRegistry);

_authorizeUpgrade

Authorisation to upgrade the implementation of the contract.

function _authorizeUpgrade(address) internal override onlyOwner;

Events

GovernorModified

This event is emitted when the governor is modified.

event GovernorModified(address governor);

Parameters

NameTypeDescription
governoraddressis the new value of the governor.

PoolCreated

This event is emitted when a new pool is created.

event PoolCreated(
    address poolToken,
    address selfPeggingAsset,
    address wrappedPoolToken,
    address rampAController,
    address parameterRegistry,
    address keeper
);

Parameters

NameTypeDescription
poolTokenaddressis the pool token created.
selfPeggingAssetaddressis the self pegging asset created.
wrappedPoolTokenaddressis the wrapped pool token created.
rampAControlleraddressis the ramp A controller created.
parameterRegistryaddressis the parameter registry created.
keeperaddressis the keeper created.

MintFeeModified

This event is emitted when the mint fee is updated.

event MintFeeModified(uint256 mintFee);

Parameters

NameTypeDescription
mintFeeuint256is the new value of the mint fee.

SwapFeeModified

This event is emitted when the swap fee is updated.

event SwapFeeModified(uint256 swapFee);

Parameters

NameTypeDescription
swapFeeuint256is the new value of the swap fee.

RedeemFeeModified

This event is emitted when the redeem fee is updated.

event RedeemFeeModified(uint256 redeemFee);

Parameters

NameTypeDescription
redeemFeeuint256is the new value of the redeem fee.

OffPegFeeMultiplierModified

This event is emitted when the off peg fee multiplier is updated.

event OffPegFeeMultiplierModified(uint256 offPegFeeMultiplier);

Parameters

NameTypeDescription
offPegFeeMultiplieruint256is the new value of the off peg fee multiplier.

AModified

This event is emitted when the A parameter is updated.

event AModified(uint256 A);

Parameters

NameTypeDescription
Auint256is the new value of the A parameter.

ExchangeRateFeeFactorModified

This event is emitted when the exchange rate fee factor is updated.

event ExchangeRateFeeFactorModified(uint256 exchangeRateFeeFactor);

Parameters

NameTypeDescription
exchangeRateFeeFactoruint256is the new value of the exchange rate fee factor.

MinRampTimeUpdated

This event is emitted when the min ramp time is updated.

event MinRampTimeUpdated(uint256 minRampTime);

Parameters

NameTypeDescription
minRampTimeuint256is the new value of the min ramp time.

BufferPercentUpdated

This event is emitted when the buffer percent is updated.

event BufferPercentUpdated(uint256 bufferPercent);

Parameters

NameTypeDescription
bufferPercentuint256is the new value of the buffer percent.

KeeperImplementationUpdated

This event is emitted when the keeper contract implementation is updated.

event KeeperImplementationUpdated(address keeperImplementation);

Parameters

NameTypeDescription
keeperImplementationaddressis the new address of keeper implementation.

Errors

InvalidAddress

Error thrown when the address is invalid

error InvalidAddress();

InvalidValue

Error thrown when the value is invalid

error InvalidValue();

InvalidOracle

Error thrown when the oracle is invalid

error InvalidOracle();

InvalidFunctionSig

Error thrown when the function signature is invalid

error InvalidFunctionSig();

Structs

InitializeArgument

Parameters for initailizing the factory

struct InitializeArgument {
    address owner;
    address governor;
    uint256 mintFee;
    uint256 swapFee;
    uint256 redeemFee;
    uint256 offPegFeeMultiplier;
    uint256 A;
    uint256 minRampTime;
    address selfPeggingAssetBeacon;
    address spaTokenBeacon;
    address wspaTokenBeacon;
    address rampAControllerBeacon;
    address keeperImplementation;
    address constantExchangeRateProvider;
    uint256 exchangeRateFeeFactor;
    uint256 bufferPercent;
}

CreatePoolArgument

Parameters for creating a new pool

struct CreatePoolArgument {
    address tokenA;
    address tokenB;
    TokenType tokenAType;
    address tokenAOracle;
    bytes tokenARateFunctionSig;
    bytes tokenADecimalsFunctionSig;
    TokenType tokenBType;
    address tokenBOracle;
    bytes tokenBRateFunctionSig;
    bytes tokenBDecimalsFunctionSig;
}

Enums

TokenType

Token type enum

enum TokenType {
    Standard,
    Oracle,
    Rebasing,
    ERC4626
}