๐Ÿ—ƒ๏ธ Types, structs and enums

Documentation on types, structs and enums used across different contracts.

Types

MarketId

Alias for bytes32. It's a hash of the properties of MarketKey struct.

struct MarketKey {
    string sourceName;
    string instrumentName;
    string tag;
    uint16 version;
    address underlying;
}

function id(MarketKey memory self) internal pure returns (MarketId) {
    return
      MarketId.wrap(
        keccak256(abi.encode(self.sourceName, self.instrumentName, self.tag, self.version, self.underlying))
      );
}

Property name
Property Type
Description

sourceName

string

Source of interest rate. E.g: Binance or Lido

instrumentName

string

Instrument name. E.g 'BTCUSDT Perpetual' or 'stEth'

tag

string

Identifier to group rates. E.g: 'funding rate' or 'staking'

version

uint16

Counter for differentiating multiple markets of the same source and instrument

underlying

address

Address of the underlying ERC20 token


FutureId

Alias for bytes32. It's a hash of the properties of FutureKey struct.

struct FutureKey {
    MarketId marketId;
    uint64 termStart;
    uint64 termLength;
}

function id(FutureKey memory self) internal pure returns (FutureId) {
    return FutureId.wrap(keccak256(abi.encode(self.marketId, self.termStart, self.termLength)));
}
Property name
Property Type
Description

marketId

Market Identifier

termStart

uint64

Timestamp in seconds of the start of the future

termLength

uint64

Number of seconds until maturity


Structs

OraclePackage

Defines the format for passing an updated index value from the oracle for a given market.

struct OraclePackage {
  MarketId marketId;
  uint64 timestamp;
  bytes signature;
  SD59x18 indexValue;
}
Property name
Property Type
Description

marketId

Market Identifier

timestamp

uint64

Timestamp in seconds

signature

bytes

Oracle signature validated on-chain

indexValue

int256

New index value for a market


Margin.Value

struct Value {
    ProfitAndLoss.Value profitAndLoss;
    SD59x18 collateral;
}
Property name
Property Type
Description

profitAndLoss

User's P&L

collateral

int256

Amount of collateral deposited by user


ProfitAndLoss.Value

struct Value {
    SD59x18 netFutureValue;
    UD60x18 accruedLPFee;
    UD60x18 incurredFee;
}
Property name
Property Type
Description

netFutureValue

int256

Amount of P&L gained or lost by an user across all futures

accruedLPFee

uint256

Amount of fees accrued by user by providing liquidity

incurredFee

uint256

Amount of fees incurred to a user by trading


FixedAndFloatTokensPair.Value

Struct for passing the amount of fixed and float tokes in a future's vAMM.

struct Value {
    SD59x18 fixedTokenAmount;
    SD59x18 floatTokenAmount;
}
Property name
Property Type
Description

fixedTokenAmount

int256

Amount of fixed tokens

floatTokenAmount

int256

Amount of floating tokens


TradeInfo

Provides detailed insights into the outcome of a trade

struct TradeInfo {
  RiskDirection.Value direction;
  FixedAndFloatTokensPair.Value tokensPair;
  SD59x18 marketRateBefore;
  SD59x18 marketRateAfter;
  SD59x18 tradeRate;
  UD60x18 lpFee;
  UD60x18 protocolFee;
  SD59x18 floatIndex;
  SD59x18 floatTradeValue;
}
Property name
Property Type
Description

direction

RiskDirection.Value

Direction of the trade

tokensPair

FixedAndFloatTokensPair.Value

Fixed and float token amounts corresponding to the trade

marketRateBefore

int256

Prevailing market rate right before the trade

marketRateAfter

int256

Prevailing market rate right after the trade

tradeRate

int256

Specific rate, at which the trade was executed

lpFee

uint256

Amount of fees incurred that will to to makers

protocolFee

uint256

Amount of fees incurred that will go to the protocol

floatIndex

int256

Index value used for calculations for the trade

floatTradeValue

int256

The value of the floating leg of a trade using its latest available index. Used for P&L calculations.


ProvisionDistribution

Struct to show how liquidity is distributed between payer and receiver sides

struct ProvisionDistribution {
  UD60x18 total;
  UD60x18 payer;
  UD60x18 receiver;
}
Property name
Property Type
Description

total

uint256

Total liquidity

payer

uint256

Liquidity on payer side

receiver

uint256

Liquidity on receiver side


Enums

RiskDirection.Value

Indicates the direction of a trader, whether the user is a receiver or payer of fixed rates.

enum Value {
    RECEIVER,
    PAYER
}

Last updated