# WCurveGauge

This is the technical documentation for the WCurveGauge Solidity contract. The WCurveGauge contract is a wrapped Curve Gauge position that leverages LP tokens to be held in the BlueberryBank and does not generate yields. LP tokens are identified by tokenIds encoded from the LP token address.

### Imports

The contract imports several OpenZeppelin contracts and other utility contracts and interfaces.

```solidity
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import "../utils/BlueBerryErrors.sol" as Errors;
import "../utils/EnsureApprove.sol";
import "../interfaces/IERC20Wrapper.sol";
import "../interfaces/IWCurveGauge.sol";
import "../interfaces/curve/ILiquidityGauge.sol";
```

### Contract Inheritance

The WCurveGauge contract inherits from the following contracts:

* ERC1155Upgradeable
* ReentrancyGuardUpgradeable
* OwnableUpgradeable
* EnsureApprove
* IERC20Wrapper
* IWCurveGauge

{% code overflow="wrap" %}

```solidity
contract WCurveGauge is
    ERC1155Upgradeable,
    ReentrancyGuardUpgradeable,
    OwnableUpgradeable,
    EnsureApprove,
    IERC20Wrapper,
    IWCurveGauge
```

{% endcode %}

### State Variables

The contract maintains the following state variables:

* `registry`: Address of Curve Registry
* `gaugeController`: Address of Curve Gauge Controller
* `CRV`: Address of CRV token
* `accCrvPerShares`: Mapping from gauge id to accCrvPerShare

```solidity
ICurveRegistry public registry;
ICurveGaugeController public gaugeController;
IERC20Upgradeable public CRV;
mapping(uint256 => uint256) public accCrvPerShares;
```

### Functions

#### initialize

This function initializes the contract with the addresses of the CRV token, Curve Registry, and Curve Gauge Controller.

{% code overflow="wrap" %}

```solidity
function initialize(
    address crv_,
    address crvRegistry_,
    address gaugeController_
) external initializer
```

{% endcode %}

#### encodeId

This function encodes the given pool id and CRV amount per share to an ERC1155 token id.

{% code overflow="wrap" %}

```solidity
function encodeId(
    uint256 pid,
    uint256 crvPerShare
) public pure returns (uint256 id)
```

{% endcode %}

#### decodeId

This function decodes the given ERC1155 token id to a pool id and CRV amount per share.

{% code overflow="wrap" %}

```solidity
function decodeId(
    uint256 id
) public pure returns (uint256 gid, uint256 crvPerShare)
```

{% endcode %}

#### getUnderlyingToken

This function returns the underlying ERC20 token of the given ERC1155 token id.

{% code overflow="wrap" %}

```solidity
function getUnderlyingToken(
    uint256 id
) external view override returns (address)
```

{% endcode %}

#### getLpFromGaugeId

This function returns the LP token address from the given gauge id.

{% code overflow="wrap" %}

```solidity
function getLpFromGaugeId(uint256 gid) public view returns (address)
```

{% endcode %}

#### pendingRewards

This function returns the pending rewards from the farming pool.

{% code overflow="wrap" %}

```solidity
function pendingRewards(
    uint256 tokenId,
    uint256 amount
)
    public
    view
    override
    returns (address[] memory tokens, uint256[] memory rewards)

```

{% endcode %}

#### mint

This function mints an ERC1155 token for the given LP token.

{% code overflow="wrap" %}

```solidity
function burn(
    uint256 id,
    uint256 amount
) external nonReentrant returns (uint256 rewards)
```

{% endcode %}

#### \_mintCrv

This internal function mints CRV rewards for the Curve gauge.

{% code overflow="wrap" %}

```solidity
function _mintCrv(ILiquidityGauge gauge, uint256 gid) internal
```

{% endcode %}


---

# 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/wrapper/wcurvegauge.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.
