# SpotManager

**Inherits:** Initializable, OwnableUpgradeable, ISpotManager

**Author:** Logarithm Labs

SpotManager is a dedicated smart contract that manages spot positions for a trading strategy, enabling it to buy or sell assets on a decentralized exchange (DEX) or other spot market. This manager operates in tandem with a basis strategy, allowing it to adjust the spot position dynamically based on the strategy’s target exposure. The primary objective is to provide liquidity for the basis trade, maintaining optimal spot exposure relative to the short hedge position.

*SpotManager is an upgradeable smart contract, deployed through the beacon proxy pattern.*

### State Variables

#### SpotManagerStorageLocation

```solidity
bytes32 private constant SpotManagerStorageLocation = 0x95ef178669169c185a874b31b21c7794e00401fe355c9bd013bddba6545f1000;
```

### Functions

#### \_getSpotManagerStorage

```solidity
function _getSpotManagerStorage() private pure returns (SpotManagerStorage storage $);
```

#### authCaller

*Authorizes a caller if it is the specified account.*

```solidity
modifier authCaller(address authorized);
```

#### initialize

```solidity
function initialize(address _owner, address _strategy, address[] calldata _assetToProductSwapPath)
    external
    initializer;
```

#### \_setManualSwapPath

```solidity
function _setManualSwapPath(address[] calldata _assetToProductSwapPath, address _asset, address _product) private;
```

#### buy

*Buys product in the spot market.*

```solidity
function buy(uint256 amount, SwapType swapType, bytes calldata swapData) external authCaller(strategy());
```

**Parameters**

| Name       | Type       | Description                                |
| ---------- | ---------- | ------------------------------------------ |
| `amount`   | `uint256`  | The asset amount to be swapped to product. |
| `swapType` | `SwapType` | The swap type.                             |
| `swapData` | `bytes`    | The data used in swapping if necessary.    |

#### sell

*Sells product in the spot market.*

```solidity
function sell(uint256 amount, SwapType swapType, bytes calldata swapData) external authCaller(strategy());
```

**Parameters**

| Name       | Type       | Description                                |
| ---------- | ---------- | ------------------------------------------ |
| `amount`   | `uint256`  | The product amount to be swapped to asset. |
| `swapType` | `SwapType` | The swap type.                             |
| `swapData` | `bytes`    | The data used in swapping if necessary.    |

#### exposure

*The spot exposure that is needed to be hedged by the perpetual positions.*

```solidity
function exposure() external view returns (uint256);
```

#### uniswapV3SwapCallback

```solidity
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;
```

#### \_verifyCallback

```solidity
function _verifyCallback() internal view;
```

#### strategy

The strategy address.

```solidity
function strategy() public view returns (address);
```

#### asset

The asset address.

```solidity
function asset() public view returns (address);
```

#### product

The product address.

```solidity
function product() public view returns (address);
```

### Events

#### SpotBuy

*Emitted when product is bought in spot markets.*

```solidity
event SpotBuy(uint256 assetDelta, uint256 productDelta);
```

#### SpotSell

*Emitted when product is sold in spot markets.*

```solidity
event SpotSell(uint256 assetDelta, uint256 productDelta);
```

### Structs

#### SpotManagerStorage

```solidity
struct SpotManagerStorage {
    address strategy;
    address asset;
    address product;
    mapping(address => bool) isSwapPool;
    address[] productToAssetSwapPath;
    address[] assetToProductSwapPath;
}
```
