# Primary Market

## Getting PrimaryMarket Info

#### `PrimaryMarket.fund() → address`

The address of the fund contract.

```bash
>>> primaryMarket.fund()
'0x69c53679EC1C06f3275b64C428e8Cd069a2d3966'
```

## Creating/Redeeming Tranches

#### `PrimaryMarket.getCreation(uint256 underlying) → uint256`

Get the amount of QUEEN created by `underlying` amount of the underlying asset.

```bash
>>> primaryMarket.getCreation(1000000000000000000)
'998239992407933623'
```

#### `PrimaryMarket.getCreationForQ(uint256 minOutQ) → uint256`

Get the amount of the underlying asset to create at least `minOutQ` amount of QUEEN.

* Note that this only works with non-empty fund for simplicity.

```bash
>>> primaryMarket.getCreationForQ(1000000000000000000)
'1001763110680249269'
>>> primaryMarket.getCreation(1001763110680249269)
'1000000000000000000'
```

#### `PrimaryMarket.getRedemption(uint256 inQ) → uint256, uint256`

Get the amount of the underlying asset redeemed by `inQ` amount of QUEEN.

```bash
>>> primaryMarket.getRedemption(1000000000000000000)
underlying: '1001763110680249268'
feeQ: '0'
```

#### `PrimaryMarket.getRedemptionForUnderlying(uint256 minUnderlying) → uint256`

Get the amount of QUEEN to redeem at least `minUnderlying` amount of the underlying asset.

```bash
>>> primaryMarket.getRedemptionForUnderlying(1000000000000000000)
'998239992407933624'
>>> primaryMarket.getRedemption(998239992407933624)
underlying: '1000000000000000000'
feeQ: '0'
```

#### `PrimaryMarket.redeem(address recipient, uint256 inQ, uint256 minUnderlying, uint256 version) → uint256`

Redeem `inQ` amount of QUEEN and transfer the resulting underlying asset to `recipient`. It enforces the resulting underlying asset to be at least `minUnderlying` and the `version` to be the current rebalance version.

* Note that the function would revert if there were queued redemptions that cannot be claimed at the moment.

#### `PrimaryMarket.redeemAndUnwrap(address recipient, uint256 inQ, uint256 minUnderlying, uint256 version) → uint256`

Redeem `inQ` amount of QUEEN, unwrap the underlying asset to its native currency, and transfer the resulting underlying asset to `recipient`. It enforces the resulting underlying asset to be at least `minUnderlying` and the `version` to be the current rebalance version. The underlying asset must be a wrapped token of the native currency.

* Note that the function would revert if there were queued redemptions that cannot be claimed at the moment.

#### `PrimaryMarket.queueRedemption(address recipient, uint256 inQ, uint256 minUnderlying, uint256 version) → uint256, uint256`

Submit a redemption request for `inQ` amount of QUEEN. The resulting underlying asset will be claimable when the fund has enough balance to pay this redemption and all the previous ones in the queue. It enforces the resulting underlying asset to be at least `minUnderlying` and the `version` to be the current rebalance version.

#### `PrimaryMarket.claimRedemptions(address account, uint256[] calldata indices) → uint256`

Claim the underlying asset of an array of queued redemption requests by `account` and transfer the underlying asset to `account`.

#### `PrimaryMarket.claimRedemptionsAndUnwrap(address account, uint256[] calldata indices) → uint256`

Claim the underlying asset of an array of queued redemption requests by `account`, unwrap the underlying asset to its native currency, and transfer the underlying asset to `account`. The underlying asset must be a wrapped token of the native currency.

## Splitting/Merging Tranches

#### `PrimaryMarket.getSplit(uint256 inQ) → uint256`

Get the amount of BISHOP and ROOK split from `inQ` amount of QUEEN.

```bash
>>> primaryMarket.getSplit(1000000000000000000)
'594418130555555555274'
```

#### `PrimaryMarket.getSplitForB(uint256 minOutB) → uint256`

Get the amount of QUEEN to split at least `minOutB` amount of BISHOP and ROOK.

```bash
>>> primaryMarket.getSplitForB(1000000000000000000)
'1682317460716381'
>>> primaryMarket.getSplit(1682317460716381)
'000000000000000465'
```

#### `PrimaryMarket.getMerge(uint256 inB) → uint256, uint256`

Get the amount of QUEEN merged from `inB` amount of BISHOP and ROOK.

```bash
>>> primaryMarket.getMerge(1000000000000000000)
outQ: '1680635143255664'
feeQ: '1682317460716'
```

#### `PrimaryMarket.getMergeForQ(uint256 minOutQ) → uint256`

Get the amount of BISHOP and ROOK to merge into at least `minOutQ` amount of QUEEN.

```bash
>>> primaryMarket.getMergeForQ(1000000000000000000)
'595013143699254810084'
>>> primaryMarket.getMerge(595013143699254810084)
outQ: '1000000000000000000'
feeQ: '1001001001001001'
```

#### `PrimaryMarket.split(address recipient, uint256 inQ, uint256 version) → uint256`

Split `inQ` amount of QUEEN into BISHOP and ROOK and send the resulting shares to `recipient`. It enforces the `version` to be the current rebalance version.

#### `PrimaryMarket.merge(address recipient, uint256 inB, uint256 version) → uint256`

Merge `inB` amount of BISHOP and ROOK into QUEEN and send the resulting shares to `recipient`. It enforces the `version` to be the current rebalance version.
