API
YFX is currently deployed on Arbitrum One, you can directly call the smart contract to trade, buy YLP, sell YLP.
- Markets:
To add liquidity to a pool:
- 1.Approve the Router contract for the base token and amount you would like to add for liquidity
- 2.Call Router.addLiquidity with parameters to add USDC pools or other ERC20 pools
- _pool: pool address
- _amount: base token amount you would like to spend
- isStakeLp: true if automatically to stake LP for earn (to be online)
- _deadline: request deadline timestamp
- 3.Call Router.addLiquidityETH with parameters to add ETH pools
- _pool: pool address
- _amount: base token amount you would like to spend, should be less than transaction value
- isStakeLp: true if automatically to stake LP for earn (to be online)
- _deadline: request deadline timestamp for price protection
To remove liquidity from a pool:
- 1.Call Router.removeLiquidity with parameters to remove liquidity from USDC pools or other ERC20 pools:
- _pool: pool address
- _liquidity: how much liquidity you would like to remove
- isUnstake: should unstake staked LP from earn (to be online)
- _deadline: request deadline timestamp for price protection
- 2.Call Router.removeLiquidityETH to remove liquidity from ETH pools, parameters are the same as above.
To open a position:
- 1.Approve the Router contract for the margin asset token and amount you would like to spend as the initial margin
- 2.Call Router.takerOpen or takerOpenETH with parameters:struct TakerOpenParams {address _market; // market contract addressbytes32 inviterCode; // inviter codeuint128 minPrice; // min price for the slippageuint128 maxPrice; // max price for the slippageuint256 margin; // margin of this orderuint16 leverage; // leverageint8 direction; // order direction, 1: long, -1: shortint8 triggerDirection; // trigger flag {1: index price >= trigger price, -1: index price <= trigger price}uint256 triggerPrice; // trigger priceuint256 deadline; // request deadline timestamp for price protection}
To Close a position:
- Call Router.takerClose with parameters:struct TakerCloseParams {address _market; // market contract addressuint256 id; // position idbytes32 inviterCode; // inviter codeuint128 minPrice; // min price for the slippageuint128 maxPrice; // max price for the slippageuint256 amount; // position amount to closeint8 triggerDirection; // trigger flag {1: index price >= trigger price, -1: index price <= trigger price}uint256 triggerPrice; // trigger priceuint256 deadline; // request deadline timestamp for price protection}
Everyone can liquidate other positions that should be liquidated. Liquidation keeper can get 2USDC reward each time.
To run a liquidation keeper, you should:
- 1.Trace positions. You can trace positions by our subgraph or listen contract event.
- 2.Call Periphery.getPositionStatus to check if the position can be liquidated. Return value with
true
means this position can be liquidated. - 3.Call Router.liquidateByCommunity to execute liquidation.
- 4.Call Vault.collectExecutedFee to get liquidation bonus.
To get your position information:
- Call Market.getPositionId to get position id
- _taker: position owner address
- _direction: 1: long, -1: short
- Call Market.getPosition with the position id
Dernière mise à jour 1mo ago