PaymentHelper

Introduction

This contract helps estimate various payments in the Superform Protocol.

Core Concepts

Chains are initiated with multiple variables to help with the estimation process by the PROTOCOL_ADMIN_ROLE. There are all updatable by the EMERGENCY_ADMIN_ROLE.

Config Data Type

struct PaymentHelperConfig {
        address nativeFeedOracle;
        address gasPriceOracle;
        uint256 swapGasUsed;
        uint256 updateGasUsed;
        uint256 depositGasUsed;
        uint256 withdrawGasUsed;
        uint256 defaultNativePrice;
        uint256 defaultGasPrice;
        uint256 dstGasPerByte;
        uint256 ackGasCost;
        uint256 timelockCost;
        uint256 emergencyCost;
}

addRemoteChain

This function allows for the addition of new chains, including setting same chain parameters, for use in estimation.

function addRemoteChain(
        uint64 chainId_,
        PaymentHelperConfig calldata config_
   )

updateRemoteChain

This function allows the EmergencyAdmin to update any of the above parameters at any given time for more accurate estimations. An event is emitted when any of these variables are updated.

function updateChainConfig(
        uint64 chainId_,
        uint256 configType_,
        bytes memory config_
    )

aERC20 Payments

updateRegisterAERC20Params

This function allows the EmergencyAdmin to adjust the cost required to create an an aERC20 position from a SuperPosition id.

function updateRegisterAERC20Params(
        uint256 totalTransmuterFees_,
        bytes memory extraDataForTransmuter_
)

calculateRegisterTransmuterAMBData

This function allows anyone to see the fees and data required to create a ERC20 position from a SuperPosition id.

function calculateRegisterTransmuterAMBData(
) external view returns (uint256 totalFees, bytes memory extraData)

AMB Fees

calculateAMBData

Function to return the cost and extraData needed for a given message sent through various AMBs supported on Superform.

function calculateAMBData(
    uint64 dstChainId_,
    uint8[] calldata ambIds_,
    bytes memory message_
) external view returns (uint256 totalFees, bytes memory extraData);

estimateAMBFees

Function to return the native tokens to be sent alongside the transaction in order for the transaction to properly process on destination.

function estimateAMBFees(
        uint8[] memory ambIds_,
        uint64 dstChainId_,
        bytes memory message_,
        bytes[] memory extraData_
    );

Estimating Native Token Payments

For each type of SuperformRouter transaction (6 total combinations of cross-chain/same chain, single and multi-vault, and single and multi-destination) as found in Datatypes -> Functionsthere is a specific estimation function.

These functions all return the following:

  • liqAmount: amount of native tokens contained in the liquidity request

  • srcAmount: total estimated gas expenditure on the source chain

  • dstAmount: total estimated gas expenditure on the destination chain

  • totalAmount: total amount of native tokens to be sent alongside transaction

estimateMultiDstMultiVault

This function returns the native token breakdown assuming a multiple destination, multiple vault deposit or withdrawal.

function estimateMultiDstMultiVault(
        MultiDstMultiVaultStateReq calldata req_,
        bool isDeposit_
    ) 

estimateMultiDstSingleVault

This function returns the native token breakdown assuming a multiple destination, single vault deposit or withdrawal.

function estimateMultiDstSingleVault(
        MultiDstSingleVaultStateReq calldata req_,
        bool isDeposit_
    ) 

estimateSingleXChainMultiVault

This function returns the native token breakdown assuming a single cross-chain transaction for a multiple vault deposit or withdrawal.

function estimateSingleXChainMultiVault(
        SingleXChainMultiVaultStateReq calldata req_,
        bool isDeposit_
    ) 

estimateSingleXChainSingleVault

This function returns the native token breakdown assuming a single cross-chain transaction for a single vault deposit or withdrawal.

function estimateSingleXChainSingleVault(
        SingleXChainSingleVaultStateReq calldata req_,
        bool isDeposit
    ) 

estimateSingleDirectSingleVault

This function returns the native token breakdown assuming a same-chain, single vault deposit or withdrawal.

function estimateSingleDirectSingleVault(
        SingleDirectSingleVaultStateReq calldata req_,
        bool isDeposit_
    ) 

estimateSingleDirectMultiVault

This function returns the native token breakdown assuming a same-chain, multiple vault deposit or withdrawal.

function estimateSingleDirectMultiVault(
        SingleDirectMultiVaultStateReq calldata req_,
        bool isDeposit_
    ) 

Last updated