Walkthroughs

Check Pool Info

1. Find out all online pools

All Pool contracts are linked with PoolGuardian’s state variables, 4 identity status of Pool: RUNNING/LIQUIDATING/RECOVER/ENDED

Copy IPoolGuardian(0x...{1}).getPoolsByState(PoolStatus.RUNNING)

The address of strPool is an indicator of one identity pool.

2. Get details about the specific pool

Copy IStrPool(0x...{1}).getPoolInfo()

Head to Pool Lifecycle for more insights about Pool.

Deal with Positions

1. Query all positions created by a user

Copy ITradingHub(0x...{1}).getPositions(0x...{2})
  • 0x...{1} Address of TradingHub contract
  • 0x...{2} User’s account

2. Get infos of a position in a specific pool

Copy IStrPool(0x...{1}).positionInfoMap(0x...{2})
  • 0x...{1} Address of StrPool contract
  • 0x...{2} Address of the position

An alternative way of getting ideal result by wildcard matching,

Copy ITradingHub(0x...{1}).getPositionInfo(0x...{2})
  • 0x...{1} Address of TradingHub contract
  • 0x...{2} Address of the position

or filter them by state, there are 4 identity status of Position: OPEN/CLOSING/OVERDRAWN/CLOSED:

Copy ITradingHub(0x...{1}).getPositionsByState(PositionState.CLOSING)
  • 0x...{1} Address of TradingHub contract

Trading

1. Sell Short

Before setting up a position, estimateMargin is a prerequisite to spare the trader from Sandwich attacks. A key involved number to quantify the terminology: Slippage.

Copy uint256 margin = ITradingHub(0x...{1}).estimateMargin( uint256 poolId, uint256 amount, uint256 slippage, address[] calldata path )
  • 0x...{1} Address of TradingHub contract

Then pass the margin calculated as a parameter of sellShort

Copy ITradingHub(0x...{1}).sellShort( uint256 poolId, uint256 amount, uint256 estimatedMargin, address[] calldata path )

Notice: All positions opened within one pool have the exact meters, so the linkage between Pool and Position is one-on-one. That means the actions of increasing or decreasing position size would NOT create another position for one user.

After the on-chain confirmation of sellShort transaction, the position’s data fields can be located somewhere in the Pool contract.

2. Buy to Cover

buyCover is the opposite side of sellShort, as the literal meaning:

Copy ITradingHub(0x...{1}).buyCover( uint256 poolId, uint256 amount, uint256 amountInMax, address[] calldata path )