# BasicSpell

The BasicSpell contract is an abstract contract that provides a set of functions to be implemented by its inheriting contracts. This contract is designed to facilitate borrowing, lending, and collateral management functionalities for other contracts in the BlueBerry Protocol

### Variables

#### bank

* Type: `IBank`
* Description: The bank contract that provides borrowing, lending, and collateral management functionalities

#### werc20

* Type: `IWERC20`
* Description: The wrapped ERC20 contract that is used as collateral for borrowing and lending operations

#### weth

* Type: `address`&#x20;
* Description: The address of the WETH contract

### Functions

#### \_\_BasicSpell\_init

{% code overflow="wrap" %}

```solidity
function __BasicSpell_init(IBank _bank, address _werc20, address _weth) internal onlyInitializing 
```

{% endcode %}

Initializes the contract by setting the parameters

**Parameters**

<table><thead><tr><th width="161.33333333333331">Name</th><th width="184">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>_bank</code></td><td><code>IBank</code></td><td>The address of the bank contract</td></tr><tr><td><code>_werc20</code></td><td><code>address</code></td><td>The address of the wrapped ERC20 contract</td></tr><tr><td><code>_weth</code></td><td><code>address</code></td><td>The address of the WETH contract</td></tr></tbody></table>

#### \_addStrategy

```solidity
function _addStrategy(address vault, uint256 maxPosSize) internal
```

Adds a strategy to the specific spell

**Parameters**

<table><thead><tr><th width="158.33333333333331">Name</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>vault</code></td><td>address</td><td>The address of the vault to add</td></tr><tr><td><code>maxPosSize</code></td><td>uint256</td><td>the USD price of the maximum position size for the given strategy based 1e18 </td></tr></tbody></table>

#### setMaxPosSize

{% code overflow="wrap" %}

```solidity
function setMaxPosSize(uint256 strategyID, uint256 maxPosSize) external existingStrategy(strategyId) onlyOWner
```

{% endcode %}

**Parameters**

<table><thead><tr><th width="158.33333333333331">Name</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>strategyId</code></td><td>uint256</td><td>The strategy ID to be adjusted</td></tr><tr><td><code>maxPosSize</code></td><td>uint256</td><td>the new USD price of the maximum position size for the given strategy based 1e18 </td></tr></tbody></table>

#### setCollateralsMaxLTVs

{% code overflow="wrap" %}

```solidity
function setCollateralsMaxLTVs(uint256 strategyId, address[] memory collaterals, uint256[] memory maxLTVs) external existingStrategy(strategyId) onlyOwner
```

{% endcode %}

Allows the owner to set the maxLTV values of a specific collateral type for the given strategy

**Parameters**

<table><thead><tr><th width="170.33333333333331">Name</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>strategyId</code></td><td>uint256</td><td>The strategy ID to be adjusted</td></tr><tr><td><code>collaterals</code></td><td>array</td><td>An array of addresses of the collaterals to have their max values set</td></tr><tr><td><code>maxLTVs</code></td><td>array</td><td>An array of the values for the given collaterals to set their maximums.</td></tr></tbody></table>

#### \_validateMaxLTV

```solidity
function _validateMaxLTV(uint256 strategyId) internal view
```

An internal function to ensure that the ltv of a strategy is within the maximum value bounds.

* `strategyId` (uint256) - The given ID to be checked and validated

#### \_validateMaxPosSize

```solidity
function _validateMaxPosSize(uint256 strategyId) internal view
```

An internal function to ensure that the max Position Size of a strategy is within the maximum value bounds.

`strategyId` (uint256) - The given ID to be checked and validated

#### \_doRefund

```solidity
function _doRefund(address token) internal
```

Refunds any remaining balance of the specified token to the current bank executor.

**Parameters**

* `token` (address): The address of the token to refund

#### \_doCutRewardsFee

{% code overflow="wrap" %}

```solidity
function _doCutRewardsFee(address token) internal
```

{% endcode %}

Cuts the rewards from the current bank executor to the protocols treasury.

**Parameters**

* `token` (address): The address of the token to cut

#### \_doRefundRewards

```solidity
function _doRefundRewards(address token) internal
```

Cut rewards fee and refund the rewards tokens from spell to the current bank executor

**Parameters**

`token` (address): The address of the token to refund

#### \_doLend

{% code overflow="wrap" %}

```solidity
function _doLend(address token, uint256 amount) internal 
```

{% endcode %}

Lends the specified amount of the token to the bank on behalf of the current executor

**Parameters**

<table><thead><tr><th width="242">Name</th><th width="177.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to lend</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to lend</td></tr></tbody></table>

#### \_doWithdraw

{% code overflow="wrap" %}

```solidity
function _doWithdraw(address token, uint256 amount) internal
```

{% endcode %}

Withdraws the specified amount of the token from the bank on behalf of the current executor

**Parameters**

<table><thead><tr><th width="242">Name</th><th width="177.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to withdraw</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to withdraw</td></tr></tbody></table>

#### \_doBorrow

{% code overflow="wrap" %}

```solidity
function _doBorrow(address token, uint256 amount) internal returns (uint256 borrowedAmount)
```

{% endcode %}

Borrows the specified amount of the token from the bank on behalf of the current executor

**Parameters**

<table><thead><tr><th width="242">Name</th><th width="177.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to borrow</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to borrow</td></tr></tbody></table>

**Returns**

* `borrowedAmount` : The number of tokens actually borrowed

#### \_doRepay

{% code overflow="wrap" %}

```solidity
function _doRepay(address token, uint256 amount) internal
```

{% endcode %}

Repays the specified amount of the token to the bank on behalf of the current executor

**Parameters**

<table><thead><tr><th width="242">Name</th><th width="177.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to repay</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to repay</td></tr></tbody></table>

#### \_doPutCollateral

```solidity
function _doPutCollateral(address token, uint256 amount) internal
```

This function puts collateral tokens inside the bank

**Parameters**

<table><thead><tr><th width="242">Name</th><th width="134.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to put in the bank</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to put in the bank</td></tr></tbody></table>

#### \_doTakeCollateral

{% code overflow="wrap" %}

```solidity
function _doTakeCollateral(address token, uint256 amount) internal
```

{% endcode %}

This function takes collateral tokens out of the bank by burning the equivalent amount of wrapped ERC20 tokens (wERC20) using the `burn` function of the wERC20 token contract.

**Parameters**

<table><thead><tr><th width="209">Name</th><th width="134.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to take out of the bank</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to take out of the bank</td></tr></tbody></table>

#### increasePosition

```solidity
function increasePosition(address token, uint256 amount) external
```

This function allows for the user to increase their isolated collateral to support their position

**Parameters**

<table><thead><tr><th width="209">Name</th><th width="134.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td><code>address</code></td><td>The address of the token to put in the bank</td></tr><tr><td><code>amount</code></td><td><code>uint256</code></td><td>The amount of token to put in the bank</td></tr></tbody></table>

#### reducePosition

{% code overflow="wrap" %}

```solidity
function reducePosition(uint256 strategyID, address collToken, uint256 collShareAmount) external
```

{% endcode %}

This function allows for the user to reduce their isolated collateral in a given position

**Parameters**

<table><thead><tr><th width="209.33333333333331">Name</th><th width="134">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>strategyId</code></td><td><code>uint256</code></td><td>The strategy to be targeted</td></tr><tr><td><code>collToken</code></td><td><code>address</code></td><td>The address of the isolated collateral token</td></tr><tr><td><code>collShareAmount</code></td><td><code>uint256</code></td><td>The amount of isolated collateral to be removed</td></tr></tbody></table>

#### receive

```solidity
receive() external payable
```

This is a fallback function that is used to receive Ether only from the Wrapped Ether (WETH) contract. If the function receives Ether from an address other than the WETH contract, it reverts with an error.


---

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