PoolTrade
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
Name | Type | Description |
---|---|---|
taker | address | The taker of the trade |
size | UD60x18 | The number of contracts being traded (18 decimals) |
isBuy | bool | Whether the taker is buying or selling |
Returns
Name | Type | Description |
---|---|---|
premiumNet | uint256 | The premium which has to be paid to complete the trade (Net of fees) (poolToken decimals) |
takerFee | uint256 | The 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
Name | Type | Description |
---|---|---|
quoteOB | QuoteOB | The OB quote given by the provider |
size | UD60x18 | The size to fill from the OB quote (18 decimals) |
signature | Signature | secp256k1 'r', 's', and 'v' value |
referrer | address | The referrer of the user filling the OB quote |
Returns
Name | Type | Description |
---|---|---|
premiumTaker | uint256 | The premium paid or received by the taker for the trade (poolToken decimals) |
delta | Position.Delta | The 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
Name | Type | Description |
---|---|---|
size | UD60x18 | The number of contracts being traded (18 decimals) |
isBuy | bool | Whether the taker is buying or selling |
premiumLimit | uint256 | Tx will revert if total premium is above this value when buying, or below this value when selling. (poolToken decimals) |
referrer | address | The referrer of the user doing the trade |
Returns
Name | Type | Description |
---|---|---|
totalPremium | uint256 | The premium paid or received by the taker for the trade (poolToken decimals) |
delta | Position.Delta | The 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
Name | Type | Description |
---|---|---|
hashes | bytes32[] | 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
Name | Type | Description |
---|---|---|
user | address | The address of the user that will call the fillQuoteOB function to fill the OB quote |
quoteOB | QuoteOB | The OB quote to check |
size | UD60x18 | Size to fill from the OB quote (18 decimals) |
sig | Signature | secp256k1 Signature |
getQuoteOBFilledAmount
Returns the size already filled for a given OB quote
function getQuoteOBFilledAmount(address provider, bytes32 quoteOBHash) external view returns (UD60x18);
Parameters
Name | Type | Description |
---|---|---|
provider | address | Provider of the OB quote |
quoteOBHash | bytes32 | Hash of the OB quote |
Returns
Name | Type | Description |
---|---|---|
<none> | UD60x18 | The size already filled (18 decimals) |
maxFlashLoan
The amount of currency available to be lent.
function maxFlashLoan(address token) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
token | address | The loan currency. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
token | address | The loan currency. |
amount | uint256 | The amount of tokens lent. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
receiver | IERC3156FlashBorrower | The receiver of the tokens in the loan, and the receiver of the callback. |
token | address | The loan currency. |
amount | uint256 | The amount of tokens lent. |
data | bytes | Arbitrary data structure, intended to contain user-defined parameters. |
_revertIfNotPoolToken
Revert if token
is not the pool token
function _revertIfNotPoolToken(address token) internal view;