> For the complete documentation index, see [llms.txt](https://v1.docs.blueberry.garden/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://v1.docs.blueberry.garden/developer-guides/contracts/spell/convexspell.md).

# ConvexSpell

The `ConvexSpell` contract is a factory contract that defines how the Blueberry Protocol interacts with Convex pools. This contract handles adding strategies, opening and closing positions, and managing collateral tokens. It inherits from the `BasicSpell` contract and utilizes the OpenZeppelin's SafeERC20Upgradeable library.

### Variables

* `wConvexPools`: Address of Wrapped Convex Pools.
* `crvOracle`: Address of the Curve Oracle.
* `CVX`: Address of the CVX token.

### Functions

**`initialize`**

Initializes the contract with the necessary parameters.

Parameters:

* `bank_`: Address of the Bank contract.
* `werc20_`: Address of the WERC20 contract.
* `weth_`: Address of the WETH contract.
* `wConvexPools_`: Address of the Wrapped Convex Pools contract.
* `crvOracle_`: Address of the Curve Oracle contract.

**`addStrategy`**

Adds a new strategy to the spell.

Parameters:

* `crvLp`: Address of the CRV LP token for the given strategy.
* `maxPosSize`: The maximum position size in USD (1e18-based) for the given strategy.

**`openPositionFarm`**

Opens a position and adds liquidity to a Curve pool with two underlying tokens while staking to the Curve gauge.

Parameters:

* `param`: An `OpenPosParam` struct containing parameters for the position.
* `minLPMint`: Minimum LP token amount to be minted for slippage control.

**`closePositionFarm`**

Closes a position, removes liquidity from the Curve pool, and repays the debt.

Parameters:

* `param`: A `ClosePosParam` struct containing parameters for the position.
* `swapRouter`: An instance of the UniswapV2Router02 contract.
* `swapPath`: A 2D array of addresses representing the path to swap reward tokens for debt tokens.

### Structs

#### OpenPosParam

Struct containing parameters for opening a position.

Fields:

* `strategyId`: The ID of the strategy.
* `collToken`: Address of the collateral token.
* `collAmount`: The amount of collateral tokens.
* `borrowToken`: Address of the borrowed token.
* `borrowAmount`: The amount of borrowed tokens.
* `farmingPoolId`: The ID of the farming pool.

#### ClosePosParam

Struct containing parameters for closing a position.

Fields:

* `strategyId`: The ID of the strategy.
* `collToken`: Address of the collateral token.
* `amountPosRemove`: The amount of position to be removed.
* `amountShareWithdraw`: The amount of shares to be withdrawn.
* `borrowToken`: Address of the borrowed token.
* `amountRepay`: The amount of debt to be repaid.
