Trade
The Core Set of Functions to Place a Trade
If on testnet, you can acquire test USDC and Arb ETH on Arbitrum by joining the Futureswap Discord and sending your address in the #testnet-usdc channel.
Approve USDC
Open Zeppelin Docs (link)
Trading
Change Position
changePosition( ) is used to open and close trades, as well as add and remove collateral. To fully close a trade, set both collateral and asset to zero. See a trade flow diagram for details.
Definitions:
deltaAsset: The amount of asset to long(if positive) or short(if negative) to change/create your position. Denomination: Same as Asset currency's denomination
Example #1: To go long 5 ETH from not having a positions open deltaAsset would be: 5 ether (5000000000000000000).
Example #2: To go short 5 ETH from not having a positions open deltaAsset would be: -5 ether (-5000000000000000000).
Example #3: To go short 5 ETH from being long 12 ETH, a positions open deltaAsset would be: -17 ether (-17000000000000000000).
deltaStable: Is the amount of collateral to add if positive, no change if zero, or remove if negative. Denomination: Same as Stable currency's denomination
Example #1: To add 123 stable collateral, deltaStable would be: 123 mWei(6 decimals) (123000000).
Example #2: To remove 65 stable collateral, deltaStable would be: -65 mWei(6 decimals) (-65000000).
stableBound: This bound is for the final execution quantity inclusive of slippage, and any fees. If this is violated the trade will be reverted and collateral returned. Denomination: Same as stable currency's denomination
Example #1: If trying to go long 2 ETH at 100 USDC per ETH or lower, your stableBound would be -200 * 10^6 (-200000000). Negative because you are selling(losing) a maximum of 200 USDC to receive 2 ETH long.
Example #2: If trying to go short 2 ETH at 110 USDC per ETH or higher, your stableBound would be 220 *10^6 (220000000). Positive because you are selling(losing) 2 ETH for a minimum gain of 220 of USDC.
To fully close a position it is recommended to set deltaStable and deltaAsset both to zero. This is a unique identifier that will fully close the trade and return the collateral + profit/loss.
Inputs:
Outputs:
Get Position
Exchange specific trade position details for a user
Return Value: Object with the following parameters in order
Estimate Execution Price
Get Asset Pool Size
From the exchange address call assetToken().
This will return the address of the asset token for this exchange. Once you have the address of the token you can use the balanceOf() to find the asset pool size using the token address balanceOf
and the account as the exchange.
This return the amount of asset token available in the Futureswap pool for trading against the uniswap exchange.
Get Stable Pool Size
From the exchange address call stableToken().
This will return the address of the stable token for this exchange. Once you have the address of the token you can use the balanceOf() to find the stable pool size.
This return the amount of stable token available in the Futureswap pool for trading against the uniswap exchange. This value is also the max trade size.
Get Funding Rate
To get the funding rate of an exchange first pull the current funding rate constant from the exchange config exchangeConfig2()
.
From this object you will get dfrRate
Futureswap's funding rate is based on the balance between longs and shorts in an exchange. Next, you'll need to get the total long and short trade amounts. Call the following.
and
This is what is continuously being paid at the current time. Now you'll want to do the following math...
From this you get the Pay Asset Rate (the current funding rate). If you multiple this by a period of time (timeDelta) you'll get how much asset needs to be paid over that period of time.
Events
Auto Deleveraging (ADL) events
Exchanges emit a TrancheAutoDeleveraged() event every time ADL occurs. Traders should subscribe to this event to see if their position got ADL'd.
Traders can get their trancheId and shareClass from IExchange.getPosition.
If this event is emitted a trader's position with a matching tranceId and shareClass will have changed
Returns
More details can be found in the ADL section.
DFRCharged
Emitted when the dynamic funding rate is charged to all traders
Returns
Calc Liquidation Price:
This will be available from the Graph but while that is down due to Arbitrum (they are working on a fix) you will need to calculate it manually:
maxLeverage being 30 ether
Last updated