/* Copyright 2021 Set Labs Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. SPDX-License-Identifier: Apache License, Version 2.0 */ pragma solidity 0.6.10; pragma experimental ABIEncoderV2; interface IClearingHouse { struct OpenPositionParams { address baseToken; bool isBaseToQuote; bool isExactInput; uint256 amount; // B2Q + exact input, want more output quote as possible, so we set a lower bound of output quote // B2Q + exact output, want less input base as possible, so we set a upper bound of input base // Q2B + exact input, want more output base as possible, so we set a lower bound of output base // Q2B + exact output, want less input quote as possible, so we set a upper bound of input quote // when it's 0 in exactInput, means ignore slippage protection // when it's maxUint in exactOutput = ignore // when it's over or under the bound, it will be reverted uint256 oppositeAmountBound; uint256 deadline; // B2Q: the price cannot be less than this value after the swap // Q2B: The price cannot be greater than this value after the swap // it will fill the trade until it reach the price limit instead of reverted uint160 sqrtPriceLimitX96; bytes32 referralCode; } struct ClosePositionParams { address baseToken; uint160 sqrtPriceLimitX96; uint256 oppositeAmountBound; uint256 deadline; bytes32 referralCode; } function openPosition(OpenPositionParams memory params) external returns (uint256 deltaBase, uint256 deltaQuote); function closePosition(ClosePositionParams calldata params) external returns (uint256 deltaBase, uint256 deltaQuote); function getAccountValue(address trader) external view returns (int256); function getPositionSize(address trader, address baseToken) external view returns (int256); function getPositionValue(address trader, address baseToken) external view returns (int256); function getOpenNotional(address trader, address baseToken) external view returns (int256); function getOwedRealizedPnl(address trader) external view returns (int256); function getTotalInitialMarginRequirement(address trader) external view returns (uint256); function getNetQuoteBalance(address trader) external view returns (int256); function getTotalUnrealizedPnl(address trader) external view returns (int256); }