# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://v1.docs.blueberry.garden/developer-guides/contracts/spell/convexspell.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
