Function: closeTradeMarket(uint16 pairIndex, uint8 index)
This closes a trade using market execution.
Inputs
pairIndex
Control: Fully controlled by the caller.
Constraints: None.
Impact: The index of the trading pair for the open trade.
index
Control: Fully controlled by the caller.
Constraints: None.
Impact: The index of the open trade.
Branches and code coverage
Intended branches
Generates an new
orderId
for the close trade market and stores the pending order.
Negative behavior
Revert if pending orders are more than or equal to the max pending market order value.
Revert if the market order is already closed.
Revert if the leverage of the trade is zero.
Function call analysis
this.registry.getContractAddress("tradingStorage")
What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returned value is the TradingStorage contract address.
What happens if it reverts, reenters or does other unusual control flow? N/A.
storageT.getOpenTrade(sender, pairIndex, index)
What is controllable?
sender
,pairIndex
, andindex
.If the return value is controllable, how is it used and how can it go wrong? Checks the existence of the open trade; incorrect values may lead to incorrect trade-information retrieval.
What happens if it reverts, reenters or does other unusual control flow? If it reverts, the entire call will revert — no reentrancy scenarios.
storageT.pendingOrderIdsCount(sender)
What is controllable?
sender
.If the return value is controllable, how is it used and how can it go wrong? Returns the count of pending orders for the user.
What happens if it reverts, reenters or does other unusual control flow? If it reverts, the entire call will revert — no reentrancy scenarios.
storageT.maxPendingMarketOrders()
What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returns the max pending market orders.
What happens if it reverts, reenters or does other unusual control flow? N/A.
storageT.getOpenTradeInfo(sender, pairIndex, index)
What is controllable?
sender
,pairIndex
, andindex
.If the return value is controllable, how is it used and how can it go wrong? Retrieves additional information about the open trade; incorrect values may lead to incorrect information retrieval.
What happens if it reverts, reenters or does other unusual control flow? If it reverts, the entire call will revert — no reentrancy scenarios.
IOstiumPriceRouter(this.registry.getContractAddress("priceRouter")).getPrice(pairIndex, OrderType.MARKET_CLOSE, block.timestamp)
What is controllable?
pairIndex
.If the return value is controllable, how is it used and how can it go wrong? Returns the
orderId
of the current order.What happens if it reverts, reenters or does other unusual control flow? If it reverts, the entire call will revert — no reentrancy scenarios.
this.registry.getContractAddress("priceRouter")
What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returned value is the priceRouter contract address.
What happens if it reverts, reenters or does other unusual control flow? N/A.
storageT.storePendingMarketOrder(PendingMarketOrder(0, 0, 0, Trade(0, 0, 0, 0, sender, 0, pairIndex, index, False)), orderId, False)
What is controllable?
pairIndex
,sender
, andindex
.If the return value is controllable, how is it used and how can it go wrong? Stores the pending market order — no return value.
What happens if it reverts, reenters or does other unusual control flow? N/A.