⚖️Multipool

This section describes the Multipool core contract.

Visit GitHub to see full implementation

Multipool

State Variables

assets

mapping(address => MpAsset) internal assets;

prices

mapping(address => FeedInfo) internal prices;

deviationParam

uint64 internal deviationParam;

deviationLimit

uint64 internal deviationLimit;

depegBaseFee

uint64 internal depegBaseFee;

baseFee

uint64 internal baseFee;

totalTargetShares

uint public totalTargetShares;

totalCollectedCashbacks

uint public totalCollectedCashbacks;

collectedFees

uint public collectedFees;

initialSharePrice

uint128 internal initialSharePrice;

sharePriceValidityDuration

uint128 internal sharePriceValidityDuration;

isPriceSetter

mapping(address => bool) public isPriceSetter;

isTargetShareSetter

mapping(address => bool) public isTargetShareSetter;

developerAddress

address internal developerAddress;

developerBaseFee

uint64 internal developerBaseFee;

collectedDeveloperFees

uint public collectedDeveloperFees;

isPaused

bool public isPaused;

signatureThershold

uint internal signatureThershold;

Functions

constructor

constructor();

initialize

function initialize(
    string memory name,
    string memory symbol,
    uint128 startSharePrice
)
    public
    initializer;

_authorizeUpgrade

function _authorizeUpgrade(address newImplementation) internal override onlyOwner;

notPaused

modifier notPaused();

getSharePriceParams

Gets several share prive params

Fetches data by reading a single slot

function getSharePriceParams()
    external
    view
    override
    returns (
        uint128 _sharePriceValidityDuration,
        uint128 _initialSharePrice,
        uint _signatureThershold
    );

Returns

getPriceFeed

Gets price feed data

function getPriceFeed(address asset) external view override returns (FeedInfo memory priceFeed);

Parameters

Returns

getPrice

Gets current asset price

function getPrice(address asset) public view override returns (uint price);

Parameters

Returns

getFeeParams

function getFeeParams()
    public
    view
    override
    returns (
        uint64 _deviationParam,
        uint64 _deviationLimit,
        uint64 _depegBaseFee,
        uint64 _baseFee,
        uint64 _developerBaseFee,
        address _developerAddress
    );

getAsset

Gets asset related info

Reads exacly two storage slots

function getAsset(address assetAddress) public view override returns (MpAsset memory asset);

Parameters

Returns

getContext

Assembles context for swappping

tries to apply force pushed share price if provided address matches otherwhise ignores struct

function getContext(ForcePushArgs calldata forcePushArgs)
    internal
    view
    returns (MpContext memory ctx);

Parameters

Returns

getPricesAndSumQuotes

Assembles context for swappping

Also checks that assets are unique via asserting that they are sorted and each element address is stricly bigger

function getPricesAndSumQuotes(
    MpContext memory ctx,
    AssetArgs[] memory selectedAssets
)
    internal
    view
    returns (uint[] memory fetchedPrices);

Parameters

Returns

transferAsset

Proceeses asset transfer

Handles multipool share with no contract calls

function transferAsset(address asset, uint quantity, address to) internal;

Parameters

receiveAsset

Asserts there is enough token balance and makes left value refund

Handles multipool share with no contract calls

function receiveAsset(
    MpAsset memory asset,
    address assetAddress,
    uint requiredAmount,
    address refundAddress
)
    internal;

Parameters

swap

Method that executes every trading in multipool

This is a low level method that works via direct token transfer on contract and method execution. Should be used in other contracts only Fees are charged in native token equivalend via transferring them before invocation or in msg.value

function swap(
    ForcePushArgs calldata forcePushArgs,
    AssetArgs[] calldata assetsToSwap,
    bool isExactInput,
    address receiverAddress,
    bool refundEthToReceiver,
    address refundAddress
)
    external
    payable
    override
    notPaused
    nonReentrant;

Parameters

checkSwap

Method that dry runs swap execution and provides estimated fees and amounts

To avoid calculation errors don't provide small values to amount

function checkSwap(
    ForcePushArgs calldata forcePushArgs,
    AssetArgs[] calldata assetsToSwap,
    bool isExactInput
)
    external
    view
    override
    returns (int fee, int[] memory amounts);

Parameters

Returns

increaseCashback

Method that dry runs swap execution and provides estimated fees and amounts

Method is permissionless so anyone can boos incentives. Native token value can be transferred directly if used iva contract or via msg.value with any method

function increaseCashback(address assetAddress)
    external
    payable
    override
    notPaused
    nonReentrant
    returns (uint128 amount);

Parameters

Returns

updatePrices

Updates price feeds for multiple tokens.

Values in each of these arrays should match with indexes (e.g. index 1 contains all data for asset 1)

function updatePrices(
    address[] calldata assetAddresses,
    FeedType[] calldata kinds,
    bytes[] calldata feedData
)
    external
    onlyOwner
    nonReentrant
    notPaused;

Parameters

updateTargetShares

Updates target shares for multiple tokens.

Values in each of these arrays should match with indexes (e.g. index 1 contains all data for asset 1)

function updateTargetShares(
    address[] calldata assetAddresses,
    uint[] calldata targetShares
)
    external
    override
    nonReentrant
    notPaused;

Parameters

withdrawFees

Method that allows to withdraw collected to owner fees. May be only called by owner

Sends all collected values at once

function withdrawFees(address to) external override onlyOwner nonReentrant returns (uint fees);

Parameters

Returns

withdrawDeveloperFees

Method that allows to withdraw developer fees from contract

Can be invoked by anyone but is still safe as recepient is always developer address

function withdrawDeveloperFees() external override notPaused nonReentrant returns (uint fees);

Returns

togglePause

Method that stops or launches contract. Used in case of freezing (e.g hacks or temprorary stopping contract)

function togglePause() external override onlyOwner;

setFeeParams

Method to change fee charging rules. All ratios are Q32 values.

Remember to always update every value as this function overrides all variables

function setFeeParams(
    uint64 newDeviationLimit,
    uint64 newHalfDeviationFee,
    uint64 newDepegBaseFee,
    uint64 newBaseFee,
    uint64 newDeveloperBaseFee,
    address newDeveloperAddress
)
    external
    override
    onlyOwner;

Parameters

setSharePriceParams

This method allows to chenge time for wich force pushed share price is valid and minimal number of unique signatures required for price force push

Called only by owner. This mechanism allow you to manage price volatility by changing valid price timeframes

function setSharePriceParams(
    uint128 newValidityDuration,
    uint newSignatureThershold
)
    external
    override
    onlyOwner;

Parameters

setAuthorityRights

Method that changes permissions of accounts

Remember to always update every value as this function overrides all variables

function setAuthorityRights(
    address authority,
    bool forcePushSettlement,
    bool targetShareSettlement
)
    external
    override
    onlyOwner;

Parameters

Last updated