# AtomicSolverV2

[Git Source](https://github.com/Ion-Protocol/nucleus-boring-vault/blob/cc0b494b83e17b9b169a73b96050d2810b690477/src/atomic-queue/AtomicSolverV2.sol)

**Inherits:** IAtomicSolver, Auth

**Author:** crispymangoes

## State Variables

### eETH

```solidity
ERC20 internal constant eETH = ERC20(0x35fA164735182de50811E8e2E824cFb9B6118ac2);
```

### weETH

```solidity
ERC20 internal constant weETH = ERC20(0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee);
```

## Functions

### constructor

```solidity
constructor(address _owner, Authority _authority) Auth(_owner, _authority);
```

### p2pSolve

Solver wants to exchange p2p share.asset() for withdraw queue shares.

*Solver should approve this contract to spend share.asset().*

```solidity
function p2pSolve(
    AtomicQueue queue,
    ERC20 offer,
    ERC20 want,
    address[] calldata users,
    uint256 minOfferReceived,
    uint256 maxAssets
)
    external
    requiresAuth;
```

### redeemSolve

Solver wants to redeem withdraw offer shares, to help cover withdraw.

*`offer` MUST be an ERC4626 vault.*

```solidity
function redeemSolve(
    AtomicQueue queue,
    ERC20 offer,
    ERC20 want,
    address[] calldata users,
    uint256 minAssetDelta,
    uint256 maxAssets
)
    external
    requiresAuth;
```

### redeemLiquidSolve

Solver wants to redeem withdraw offer shares, to help cover withdraw.

*`offer` MUST be an ERC4626 vault.*

```solidity
function redeemLiquidSolve(
    AtomicQueue queue,
    ERC20 offer,
    ERC20 want,
    address[] calldata users,
    uint256 minAssetDelta,
    uint256 maxAssets
)
    external
    requiresAuth;
```

### finishSolve

Implement the finishSolve function WithdrawQueue expects to call.

*nonReentrant is not needed on this function because it is impossible to reenter, because the above solve functions have the nonReentrant modifier. The only way to have the first 2 checks pass is if the msg.sender is the queue, and this contract is msg.sender of `Queue.solve()`, which is only called in the above functions.*

```solidity
function finishSolve(
    bytes calldata runData,
    address initiator,
    ERC20 offer,
    ERC20 want,
    uint256 offerReceived,
    uint256 wantApprovalAmount
)
    external
    requiresAuth;
```

### \_p2pSolve

Helper function containing the logic to handle p2p solves.

```solidity
function _p2pSolve(
    address queue,
    bytes memory runData,
    ERC20 offer,
    ERC20 want,
    uint256 offerReceived,
    uint256 wantApprovalAmount
)
    internal;
```

### \_redeemSolve

Helper function containing the logic to handle redeem solves.

```solidity
function _redeemSolve(
    address queue,
    bytes memory runData,
    ERC20 offer,
    ERC20 want,
    uint256 offerReceived,
    uint256 wantApprovalAmount
)
    internal;
```

### \_redeemLiquidSolve

Helper function containing the logic to handle redeem solves.

```solidity
function _redeemLiquidSolve(
    address queue,
    bytes memory runData,
    ERC20 offer,
    ERC20 want,
    uint256 offerReceived,
    uint256 wantApprovalAmount
)
    internal;
```

## Errors

### AtomicSolverV2\_\_\_WrongInitiator

```solidity
error AtomicSolverV2___WrongInitiator();
```

### AtomicSolverV2\_\_\_AlreadyInSolveContext

```solidity
error AtomicSolverV2___AlreadyInSolveContext();
```

### AtomicSolverV2\_\_\_FailedToSolve

```solidity
error AtomicSolverV2___FailedToSolve();
```

### AtomicSolverV2\_\_\_SolveMaxAssetsExceeded

```solidity
error AtomicSolverV2___SolveMaxAssetsExceeded(uint256 actualAssets, uint256 maxAssets);
```

### AtomicSolverV2\_\_\_P2PSolveMinSharesNotMet

```solidity
error AtomicSolverV2___P2PSolveMinSharesNotMet(uint256 actualShares, uint256 minShares);
```

### AtomicSolverV2\_\_\_RedeemSolveMinAssetDeltaNotMet

```solidity
error AtomicSolverV2___RedeemSolveMinAssetDeltaNotMet(uint256 actualDelta, uint256 minDelta);
```

## Enums

### SolveType

The Solve Type, used in `finishSolve` to determine the logic used.

P2P Solver wants to swap share.asset() for user(s) shares

REDEEM Solver needs to redeem shares, then can cover user(s) required assets.

```solidity
enum SolveType {
    P2P,
    REDEEM,
    REDEEM_LIQUID
}
```


---

# 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://docs.nucleusearn.io/nucleus-architecture/smart-contracts/contracts/atomic-queue/atomicsolverv2.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.
