# Conduit

WasabiConduit is a smart contract that allows users to interact with all WasabiPools simultaneously while only giving NFT and token permissions once (to the conduit).

Check this Twitter thread which explains the Conduit purpose: <https://twitter.com/wasabi_dev/status/1614026446321729538>

## Buying Options

### Buy Single Option

```solidity
function buyOption(
        WasabiStructs.PoolAsk calldata _request,
        bytes calldata _signature
) external payable returns (uint256)
```

You can buy a single option given the PoolAsk and it's signature signed by the owner or admin of the pool issuing the option.

* If the pool is an ETH pool, then ETH equaling the premium of the ask needs to be supplied in the function call.
* If the pool is an ERC20 pool, then you'll need to give ERC20 approval equaling the premium before this function is called.

### Accept Ask

```solidity
function acceptAsk(
        WasabiStructs.Ask calldata _ask,
        bytes calldata _signature
) external payable returns (uint256)
```

You can buy a single option given an Ask. This will allow you to buy a WasabiOption from another user instead of a pool.

* If the `ask.tokenAddress` is `0x00..000` then ETH equaling the price of the ask needs to be supplied in the function call.
* Otherwise, you'll need to give ERC20 approval equaling the price of the ask before this function is called.

### Buy Multiple Options

```solidity
function buyOptions(
        WasabiStructs.PoolAsk[] calldata _requests,
        WasabiStructs.Ask[] calldata _asks,
        bytes[] calldata _signatures
) external payable returns (uint256[] memory)
```

You can buy multiple options by providing a list of PoolAsks and Asks. This function will call `buyOption` and `acceptAsk` functions in a loop to buy all the specified options. If a purchase of any option fails, the whole transaction will revert.

{% hint style="info" %}
The provided signatures need to be in the order of all the pool asks and asks provided respectively.
{% endhint %}

Example:

```
conduit.buyOptions(
    [poolAsk1, poolAsk2],
    [ask1, ask2, ask3],
    [poolAsk1_sig, poolAsk2_sig, ask1_sig, ask2_sig, ask3_sig]
```

## Selling Options

### Accepting Bids

```solidity
function acceptBid(
        uint256 _optionId,
        address _poolAddress,
        WasabiStructs.Bid calldata _bid,
        bytes calldata _signature
) external payable
```

You can sell your existing options for a bid that matches the parameters of the option. You'll need to own the option and supply

* the id of the option
* the address of the pool which issued the option originally
* the bid data
* the signature for the bid signed by the potential buyer

## Canceling Orders

```solidity
function cancelAsk(
        WasabiStructs.Ask calldata _ask,
        bytes calldata _signature
) external;
```

You can cancel an ask by calling the `cancelAsk` function. Only the signer can cancel the ask.

```solidity
function cancelBid(
        WasabiStructs.Bid calldata _bid,
        bytes calldata _signature
) external;
```

You can cancel a bid by calling the `cancelBid` function. Only the signer can cancel the bid.
