PoolTrade

Git Source

Inherits: IPoolTrade, PoolInternal, ReentrancyGuard

State Variables

FLASH_LOAN_FEE

UD60x18 internal constant FLASH_LOAN_FEE = UD60x18.wrap(0.0009e18);

FLASH_LOAN_CALLBACK_SUCCESS

bytes32 internal constant FLASH_LOAN_CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan");

Functions

constructor

constructor(
    address factory,
    address router,
    address wrappedNativeToken,
    address feeReceiver,
    address referral,
    address settings,
    address vaultRegistry,
    address vxPremia
) PoolInternal(factory, router, wrappedNativeToken, feeReceiver, referral, settings, vaultRegistry, vxPremia);

getQuoteAMM

Gives a quote for an AMM trade

function getQuoteAMM(address taker, UD60x18 size, bool isBuy)
    external
    view
    returns (uint256 premiumNet, uint256 takerFee);

Parameters

NameTypeDescription
takeraddressThe taker of the trade
sizeUD60x18The number of contracts being traded (18 decimals)
isBuyboolWhether the taker is buying or selling

Returns

NameTypeDescription
premiumNetuint256The premium which has to be paid to complete the trade (Net of fees) (poolToken decimals)
takerFeeuint256The taker fees to pay (Included in premiumNet) (poolToken decimals)

fillQuoteOB

Functionality to support the OB / OTC system. An LP can create a OB quote for which he will do an OTC trade through the exchange. Takers can buy from / sell to the LP partially or fully while having the price guaranteed.

function fillQuoteOB(QuoteOB calldata quoteOB, UD60x18 size, Signature calldata signature, address referrer)
    external
    nonReentrant
    returns (uint256 premiumTaker, Position.Delta memory delta);

Parameters

NameTypeDescription
quoteOBQuoteOBThe OB quote given by the provider
sizeUD60x18The size to fill from the OB quote (18 decimals)
signatureSignaturesecp256k1 'r', 's', and 'v' value
referreraddressThe referrer of the user filling the OB quote

Returns

NameTypeDescription
premiumTakeruint256The premium paid or received by the taker for the trade (poolToken decimals)
deltaPosition.DeltaThe net collateral / longs / shorts change for taker of the trade.

trade

Completes a trade of size on side via the AMM using the liquidity in the Pool. Tx will revert if total premium is above totalPremium when buying, or below totalPremium when selling.

function trade(UD60x18 size, bool isBuy, uint256 premiumLimit, address referrer)
    external
    nonReentrant
    returns (uint256 totalPremium, Position.Delta memory delta);

Parameters

NameTypeDescription
sizeUD60x18The number of contracts being traded (18 decimals)
isBuyboolWhether the taker is buying or selling
premiumLimituint256Tx will revert if total premium is above this value when buying, or below this value when selling. (poolToken decimals)
referreraddressThe referrer of the user doing the trade

Returns

NameTypeDescription
totalPremiumuint256The premium paid or received by the taker for the trade (poolToken decimals)
deltaPosition.DeltaThe net collateral / longs / shorts change for taker of the trade.

cancelQuotesOB

Cancel given OB quotes

No check is done to ensure the given hash correspond to a OB quote provider by msg.sender, but as we register the cancellation in a mapping provider -> hash, it is not possible to cancel a OB quote created by another provider

function cancelQuotesOB(bytes32[] calldata hashes) external nonReentrant;

Parameters

NameTypeDescription
hashesbytes32[]The hashes of the OB quotes to cancel

isQuoteOBValid

Returns whether or not an OB quote is valid, given a fill size

function isQuoteOBValid(address user, QuoteOB calldata quoteOB, UD60x18 size, Signature calldata sig)
    external
    view
    returns (bool, InvalidQuoteOBError);

Parameters

NameTypeDescription
useraddressThe address of the user that will call the fillQuoteOB function to fill the OB quote
quoteOBQuoteOBThe OB quote to check
sizeUD60x18Size to fill from the OB quote (18 decimals)
sigSignaturesecp256k1 Signature

getQuoteOBFilledAmount

Returns the size already filled for a given OB quote

function getQuoteOBFilledAmount(address provider, bytes32 quoteOBHash) external view returns (UD60x18);

Parameters

NameTypeDescription
provideraddressProvider of the OB quote
quoteOBHashbytes32Hash of the OB quote

Returns

NameTypeDescription
<none>UD60x18The size already filled (18 decimals)

maxFlashLoan

The amount of currency available to be lent.

function maxFlashLoan(address token) external view returns (uint256);

Parameters

NameTypeDescription
tokenaddressThe loan currency.

Returns

NameTypeDescription
<none>uint256The amount of token that can be borrowed.

flashFee

The fee to be charged for a given loan.

function flashFee(address token, uint256 amount) external view returns (uint256);

Parameters

NameTypeDescription
tokenaddressThe loan currency.
amountuint256The amount of tokens lent.

Returns

NameTypeDescription
<none>uint256The amount of token to be charged for the loan, on top of the returned principal.

_flashFee

Returns the fee required for a flash loan of amount

function _flashFee(uint256 amount) internal view returns (UD60x18);

flashLoan

Initiate a flash loan.

function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data)
    external
    nonReentrant
    returns (bool);

Parameters

NameTypeDescription
receiverIERC3156FlashBorrowerThe receiver of the tokens in the loan, and the receiver of the callback.
tokenaddressThe loan currency.
amountuint256The amount of tokens lent.
databytesArbitrary data structure, intended to contain user-defined parameters.

_revertIfNotPoolToken

Revert if token is not the pool token

function _revertIfNotPoolToken(address token) internal view;