# Connector Contracts

You can find the contract address [here](https://docs.polynomial.fi/developer-documentation/api/addresses) . If you are using AA wallets according to previous guide, calling these contract functions will be the quickest way to integrate with Perps trading.&#x20;

* **unit128 accountId**
* **bool weiToSend**
* **bytes memory updateOracle**

### Create Account

```solidity
function createAccountAddCollateral(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 spotSynthMarketId,
        uint128 perpSynthMarketId,
        uint256 collateralAmount
    ) public payable
```

* **updateOracle:  Oracle data to be updated. For more details pyth-oracle \<TODO>**
* **spotSynthMarketId**
  * &#x20;USDC  1n
* **perpSynthMarketId**
  * **USDC** 0n
* **collaeralAmount**
  * Amount to be send as collateral

### Add collateral to trade

```solidity
function addCollateralFromSCW(
        uint128 accountId,
        uint128 spotSynthMarketId,
        uint128 perpSynthMarketId,
        uint256 collateralAmount,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData
    ) public payable
```

### Remove collateral from trade

```solidity
function removeCollateralToSCW(
        uint128 accountId,
        uint128 spotSynthMarketId,
        uint128 perpSynthMarketId,
        uint256 collateralAmount,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData
    ) public payable
```

### Long Market Order

```solidity
function long(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        uint256 size,
        uint256 acceptablePrice,
        bytes calldata vipUpgradeData
    ) public payable
```

* **size**
  * Market order size
* vipUpgradeData
  * 0x

### Short Market Order

```solidity
function short(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        uint256 size,
        uint256 acceptablePrice,
        bytes calldata vipUpgradeData
    ) public payable
```

### Reduce Position Size

```solidity
  function reduceSize(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        int128 sizeDelta,
        uint256 acceptablePrice,
        bytes calldata vipUpgradeData
    ) public
```

* acceptablePrice
  * You can pass any minimum required price for closing the position on market price. For the order to always pass through, you can pass worst case prices. For example&#x20;

    ```typescript
    position.long ? 1n : 10000000000000000000000000000000000000n
    ```
* **sizeDelta**
  * Use any size less than or equal to the position size

### Close a Position&#x20;

```solidity
    function close(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        uint256 acceptablePrice,
        uint256 limitOrderId,
        bytes calldata vipUpgradeData
    ) public
```

* **limitOrderId**
  * Pass in the full position TP/SL order Id

### Reverse Trade Position

```solidity
function reversePosition(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        uint256 acceptablePrice,
        uint256 limitOrderId,
        bytes calldata vipUpgradeData
    ) public
```

### Manuall Settle Trade

```solidity
function settleTrade(uint128 accountId, uint8 weiToSend, bytes memory oracleData) public
```

### Short with TPSL

```solidity
function shortAddTPSL(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        uint256 size,
        uint256 acceptablePrice,
        IFxAutomationsProxy.OrderRequest memory tpslOrder,
        bytes calldata vipUpgradeData
    ) public payable
```

* tpslOrder&#x20;
  * &#x20;ILimitOrder

```typescript
export interface IPriceRange {
	priceA: bigint;
	priceB: bigint;
	acceptablePrice: bigint;
}

export interface ILimitOrder {
	user: Address;
	price: IPriceRange;
	tpPrice: IPriceRange;
	slPrice: IPriceRange;
	accountId: bigint;
	marketId: bigint;
	size: bigint;
	expiry: bigint;
}
```

### Long with TPSL

```solidity
function longAddTPSL(
        uint128 accountId,
        bool updateOracle,
        uint8 weiToSend,
        bytes memory oracleData,
        uint128 marketId,
        uint256 size,
        uint256 acceptablePrice,
        IFxAutomationsProxy.OrderRequest memory tpslOrder,
        bytes calldata vipUpgradeData
    ) public payable
```

### Create Limit Order

```solidity
function placeLimitOrder(uint128 accountId, IFxAutomationsProxy.OrderRequest memory order) public
```

### Modify Limit Order

```

function modifyLimitOrder(uint128 accountId, uint256 oldOrderId, IFxAutomationsProxy.OrderRequest memory order)
        public
```

### Cancel Limit Order
