# Fixed Price Auctioneer (FPA)

Fixed Price Auctioneer is the simplest auction variant. It allows creators to buy/sell a set capacity of token at the quoted price for a certain amount of time. Because of this, it is similar to a limit order in an order book exchange. The goal of this auction variant is to sell as many tokens as possible at the set price. Unlike the SDA auction variants, it will not adjust price to sell out the capacity over the duration.

The Base FPA contract has the following data structures, variables, and methods.

## Data Structures (Structs)

### MarketParams

Parameters to create a new FPA market. Encoded as bytes and provided as input to `createMarket`.

```solidity
struct MarketParams {
    ERC20 payoutToken;
    ERC20 quoteToken;
    address callbackAddr;
    bool capacityInQuote;
    uint256 capacity;
    uint256 formattedPrice;
    uint48 depositInterval;
    uint48 vesting;
    uint48 start;
    uint48 duration;
    int8 scaleAdjustment;
}
```

| Field           | Type            | Description                                                                                                                                                                                             |
| --------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| payoutToken     | ERC20 (address) | Payout Token (token paid out by market and provided by creator)                                                                                                                                         |
| quoteToken      | ERC20 (address) | Quote Token (token to be received by the market and provided by purchaser)                                                                                                                              |
| callbackAddr    | address         | Callback contract address, should conform to `IBondCallback`. If 0x00, tokens will be transferred from market owner. Using a callback requires whitelisting by the protocol                             |
| capacityInQuote | bool            | Is Capacity in Quote Token?                                                                                                                                                                             |
| capacity        | uint256         | Capacity (amount in quote token decimals or amount in payout token decimals). Set `capacityInQuote` flag appropriately                                                                                  |
| formattedPrice  | uint256         | Initial price of the market as a ratio of quote tokens per payout token, see note below on formatting                                                                                                   |
| depositInterval | uint48          | Target deposit interval for purchases (in seconds). Determines the `maxPayout` of the market. Minimum is 1 hour (3600 seconds)                                                                          |
| vesting         | uint48          | Is fixed term ? Vesting length (seconds) : Vesting expiry (timestamp). A 'vesting' param longer than 50 years is considered a timestamp for fixed expiry                                                |
| start           | uint48          | Start time of the market as a timestamp. Allows starting a market in the future. If provided, the transaction must be sent prior to the start time. If not provided, the market will start immediately. |
| duration        | uint48          | Duration of the market in seconds.                                                                                                                                                                      |
| scaleAdjustment | int8            | Market scaling adjustment factor, ranges from -24 to +24. See note below on how to calculate                                                                                                            |

#### Calculating Formatted Price and Scale Adjustment

In order to support a broad range of tokens, with different decimal configurations and prices, we calculate an optimal scaling factor for each market. Specifically, the scale adjustment allows the FPA to support tokens with 6 to 18 configured decimals and with prices that differ by up to 24 decimal places (if the tokens have the configured decimals, less if not). To implement this, the market creator must provide a scale adjustment factor and format the price correctly.

First, you need the price of each token in a common unit, e.g. dollars or ether.

Then, if $$\Phi\_p$$ is the price of the payout token and $$\Phi\_q$$  is the price of quote token in the common unit, it can expressed in base 10 (or scientific) notation as:

$$
\Phi\_p = \phi\_p \times 10^{d\_{\phi p}}
$$

$$
\Phi\_q = \phi\_q \times 10^{d\_{\phi q}}
$$

where:

* $$\phi\_p$$ is the coefficient of the payout token price and ​$$d\_{\phi p}$$​ is the number of price decimals for the payout token (aka the significand of the price).
* $$\phi\_q$$​ is the coefficient of the quote token price and $$d\_{\phi q}$$​ is the number of price decimals for the quote token.

Example: If the price of WETH is $1,500, then we would deconstruct it as $$1.5 \times 10^3$$​. Therefore $$\phi = 1.5$$ and $$d\_{\phi} = 3$$.

Now, using the price values and the configured number of decimals for each token, we can calculate the scale adjustment.

$$
s = d\_p - d\_q - \left\lfloor\frac{d\_{\phi p} - d\_{\phi q}}{2}\right\rfloor
$$

where:

* $$d\_p$$ is the configured payout token decimals (e.g. WETH has 18 configured decimals)
* $$d\_q$$ is the configured quote token decimals.
* $$d\_{\phi p}$$ and $$d\_{\phi q}$$ are as defined above.

Example:&#x20;

* Let WETH be the quote token and OHM be the payout token. WETH has 18 configured decimals   and OHM has 9 configured decimals. Assume the market price of WETH is $1,500 -> $$1.5 \times 10^3$$and the market price of OHM is $10 -> $$1 \times 10^1$$.​
* Then, the scale adjustment is $$s = 9 - 18 - \left\lfloor\frac{1-3}{2}\right\rfloor = -9 + 1 = -8$$​

Once we have the scale adjustment, we can format the price using the variables defined above. Here we assume the auction will use the current market price. If selling vesting tokens, a discount to the current market price may be appropriate.

$$
\Phi\_0 = \frac{\phi\_p}{\phi\_q} \times 10^{36 + s + d\_q - d\_p +d\_{\phi p} - d\_{\phi q}}
$$

Example: Continuing with the WETH and OHM example from above, we format the price as:

$$
\Phi\_0 = \frac{1}{1.5} \times 10^{36+(-8)+18-9+1-3} = 0.666.. \times 10^{35} = 0.0666.. \times 10^{36}
$$

The above price example can be interpreted as 0.0666.. WETH per OHM.

### BondMarket

BondMarket contains the core data, such as tokens, capacity, owner, price, etc., for a Fixed Price Market.

```solidity
struct BondMarket {
    address owner; // market owner. sends payout tokens, receives quote tokens (defaults to creator)
    ERC20 payoutToken; // token to pay depositors with
    ERC20 quoteToken; // token to accept as payment
    address callbackAddr; // address to call for any operations on bond purchase. Must inherit to IBondCallback.
    bool capacityInQuote; // capacity limit is in payment token (true) or in payout (false, default)
    uint256 capacity; // capacity remaining
    uint256 maxPayout; // max payout tokens out in one order
    uint256 price; // fixed price of the market (see MarketParams struct)
    uint256 scale; // scaling factor for the market (see MarketParams struct)
    uint256 sold; // payout tokens out
    uint256 purchased; // quote tokens in
}
```

### BondTerms

BondTerms contains the time parameters of a Fixed Price Market.

<pre class="language-solidity"><code class="lang-solidity">struct BondTerms {
<strong>    uint48 start; // timestamp when market starts
</strong>    uint48 conclusion; // timestamp when market no longer offered
    uint48 vesting; // length of time from deposit to expiry if fixed-term, vesting timestamp if fixed-expiry
}
</code></pre>

## Public Variables and View Methods

### allowNewMarkets

```solidity
function allowNewMarkets() external view returns (bool)
```

Whether or not the auctioneer allows new markets to be created

*Changing to false will sunset the auctioneer after all active markets end*

### authority

```solidity
function authority() external view returns (contract Authority)
```

### callbackAuthorized

```solidity
function callbackAuthorized(address) external view returns (bool)
```

Whether or not the market creator is authorized to use a callback address

### currentCapacity

```solidity
function currentCapacity(uint256 id_) external view returns (uint256)
```

Returns current capacity of a market

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### getAggregator

```solidity
function getAggregator() external view returns (contract IBondAggregator)
```

Returns the Aggregator that services the Auctioneer

### getMarketInfoForPurchase

```solidity
function getMarketInfoForPurchase(uint256 id_) external view returns (address owner, address callbackAddr, contract ERC20 payoutToken, contract ERC20 quoteToken, uint48 vesting, uint256 maxPayout_)
```

Provides information for the Teller to execute purchases on a Market

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

#### Returns

| Name         | Type           | Description                                                                       |
| ------------ | -------------- | --------------------------------------------------------------------------------- |
| owner        | address        | Address of the market owner (tokens transferred from this address if no callback) |
| callbackAddr | address        | Address of the callback contract to get tokens for payouts                        |
| payoutToken  | contract ERC20 | Payout Token (token paid out) for the Market                                      |
| quoteToken   | contract ERC20 | Quote Token (token received) for the Market                                       |
| vesting      | uint48         | Timestamp or duration for vesting, implementation-dependent                       |
| maxPayout\_  | uint256        | Maximum amount of payout tokens you can purchase in one transaction               |

### getTeller

```solidity
function getTeller() external view returns (contract IBondTeller)
```

Returns the Teller that services the Auctioneer

### isInstantSwap

```solidity
function isInstantSwap(uint256 id_) external view returns (bool)
```

Returns whether the market sends payout immediately (true = no vesting) or not (false = vesting)

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### isLive

```solidity
function isLive(uint256 id_) external view returns (bool)
```

Returns whether the market is currently accepting deposits (true) or not (false)

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### marketPrice

```solidity
function marketPrice(uint256 id_) external view returns (uint256)
```

Calculates current market price, value returned is the number of quote tokens per payout token, scaled according to the logic described in [#calculating-formatted-price-and-scale-adjustment](#calculating-formatted-price-and-scale-adjustment "mention")

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### marketScale

```solidity
function marketScale(uint256 id_) external view returns (uint256)
```

Scale value to use when converting between quote token and payout token amounts with marketPrice()

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### markets

```solidity
function markets(uint256) external view returns (address owner, contract ERC20 payoutToken, contract ERC20 quoteToken, address callbackAddr, bool capacityInQuote, uint256 capacity, uint256 maxPayout, uint256 price, uint256 scale, uint256 sold, uint256 purchased)
```

Returns the core information pertaining to a bond market, see [#bondmarket](#bondmarket "mention")

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### maxAmountAccepted

```solidity
function maxAmountAccepted(uint256 id_, address referrer_) external view returns (uint256)
```

Returns maximum amount of quote token accepted by the market

#### Parameters

| Name       | Type    | Description                                                                                                                                         |
| ---------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| id\_       | uint256 | ID of market                                                                                                                                        |
| referrer\_ | address | Address of referrer, used to get fees to calculate accurate payout amount. Inputting the zero address will take into account just the protocol fee. |

### maxPayout

```solidity
function maxPayout(uint256 id_) external view returns (uint256)
```

Calculate max payout of the market in payout tokens

*Returns a dynamically calculated payout or the maximum set by the creator, whichever is less. If the remaining capacity is less than the max payout, then that amount will be returned.*

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### minDepositInterval

```solidity
function minDepositInterval() external view returns (uint48)
```

Minimum deposit interval for a market

### minMarketDuration

```solidity
function minMarketDuration() external view returns (uint48)
```

Minimum market duration in seconds

### newOwners

```solidity
function newOwners(uint256) external view returns (address)
```

New address to designate as market owner. They must accept ownership to transfer permissions.

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### ownerOf

```solidity
function ownerOf(uint256 id_) external view returns (address)
```

Returns the address of the market owner

#### Parameters

| Name | Type    | Description  |
| ---- | ------- | ------------ |
| id\_ | uint256 | ID of market |

### payoutFor

```solidity
function payoutFor(uint256 amount_, uint256 id_, address referrer_) external view returns (uint256)
```

Payout due for amount of quote tokens

#### Parameters

| Name       | Type    | Description                                                                                                                                         |
| ---------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| amount\_   | uint256 | Amount of quote tokens to spend                                                                                                                     |
| id\_       | uint256 | ID of market                                                                                                                                        |
| referrer\_ | address | Address of referrer, used to get fees to calculate accurate payout amount. Inputting the zero address will take into account just the protocol fee. |

### terms

```solidity
function terms(uint256) external view returns (uint48 start, uint48 conclusion, uint48 vesting)
```

Information pertaining to market time parameters, see [#bondterms](#bondterms "mention")

#### Parameters

| Name | Type    | Description      |
| ---- | ------- | ---------------- |
| id\_ | uint256 | ID of the market |

## State-Mutating Methods

### closeMarket

```solidity
function closeMarket(uint256 id_) external nonpayable
```

Disable existing bond marketMust be market owner

#### Parameters

| Name | Type    | Description           |
| ---- | ------- | --------------------- |
| id\_ | uint256 | ID of market to close |

### createMarket

```solidity
function createMarket(bytes params_) external nonpayable returns (uint256)
```

Creates a new bond market

*See* [#marketparams](#marketparams "mention") for the required formatting for the abi-encoded input params.

#### Parameters

| Name     | Type  | Description                                                             |
| -------- | ----- | ----------------------------------------------------------------------- |
| params\_ | bytes | Configuration data needed for market creation, encoded in a bytes array |

#### Returns

|    |         |                           |
| -- | ------- | ------------------------- |
| id | uint256 | ID of the new bond market |

### pullOwnership

```solidity
function pullOwnership(uint256 id_) external nonpayable
```

Accept ownership of a marketMust be market newOwner

*The existing owner must call pushOwnership prior to the newOwner calling this function*

#### Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id\_ | uint256 | Market ID   |

### purchaseBond

```solidity
function purchaseBond(uint256 id_, uint256 amount_, uint256 minAmountOut_) external nonpayable returns (uint256 payout)
```

Execute a purchase on the auctioneer. Only callable by the configured [Teller](/smart-contracts/bond-system/teller.md). Users must interact with the Teller to make purchases.

#### Parameters

| Name           | Type    | Description                                                          |
| -------------- | ------- | -------------------------------------------------------------------- |
| id\_           | uint256 | ID of the Market the bond is being purchased from                    |
| amount\_       | uint256 | Amount to deposit in exchange for bond (after fee has been deducted) |
| minAmountOut\_ | uint256 | Minimum acceptable amount of bond to receive. Prevents front-running |

#### Returns

| Name   | Type    | Description                                         |
| ------ | ------- | --------------------------------------------------- |
| payout | uint256 | Amount of payout token to be received from the bond |

### pushOwnership

```solidity
function pushOwnership(uint256 id_, address newOwner_) external nonpayable
```

Designate a new owner of a marketMust be market owner

*Doesn't change permissions until newOwner calls pullOwnership*

#### Parameters

| Name       | Type    | Description                      |
| ---------- | ------- | -------------------------------- |
| id\_       | uint256 | Market ID                        |
| newOwner\_ | address | New address to give ownership to |

### setAllowNewMarkets

```solidity
function setAllowNewMarkets(bool status_) external nonpayable
```

Change the status of the auctioneer to allow creation of new markets

*Setting to false and allowing active markets to end will sunset the auctioneer*

#### Parameters

| Name     | Type | Description                                                     |
| -------- | ---- | --------------------------------------------------------------- |
| status\_ | bool | Allow market creation (true) : Disallow market creation (false) |

### setCallbackAuthStatus

```solidity
function setCallbackAuthStatus(address creator_, bool status_) external nonpayable
```

Change whether a market creator is allowed to use a callback address in their markets or notMust be guardian

*Callback is believed to be safe, but a whitelist is implemented to prevent abuse*

#### Parameters

| Name      | Type    | Description                                       |
| --------- | ------- | ------------------------------------------------- |
| creator\_ | address | Address of market creator                         |
| status\_  | bool    | Allow callback (true) : Disallow callback (false) |

### setMinDepositInterval

```solidity
function setMinDepositInterval(uint48 depositInterval_) external nonpayable
```

Set the minimum deposit intervalAccess controlled

#### Parameters

| Name              | Type   | Description                         |
| ----------------- | ------ | ----------------------------------- |
| depositInterval\_ | uint48 | Minimum deposit interval in seconds |

### setMinMarketDuration

```solidity
function setMinMarketDuration(uint48 duration_) external nonpayable
```

Set the minimum market durationAccess controlled

#### Parameters

| Name       | Type   | Description                        |
| ---------- | ------ | ---------------------------------- |
| duration\_ | uint48 | Minimum market duration in seconds |

## Events

### MarketClosed

```solidity
event MarketClosed(uint256 indexed id)
```

#### Parameters

| Name         | Type    | Description      |
| ------------ | ------- | ---------------- |
| id `indexed` | uint256 | ID of the market |

### MarketCreated

```solidity
event MarketCreated(uint256 indexed id, address indexed payoutToken, address indexed quoteToken, uint48 vesting, uint256 fixedPrice)
```

#### Parameters

| Name                  | Type    | Description                   |
| --------------------- | ------- | ----------------------------- |
| id `indexed`          | uint256 | ID of the market              |
| payoutToken `indexed` | address | Address of the payout token   |
| quoteToken `indexed`  | address | Address of the quote token    |
| vesting               | uint48  | Vesting duration or timestamp |
| fixedPrice            | uint256 | Fixed price of the market     |

## Errors

### Auctioneer\_AmountLessThanMinimum

```solidity
error Auctioneer_AmountLessThanMinimum()
```

### Auctioneer\_BadExpiry

```solidity
error Auctioneer_BadExpiry()
```

### Auctioneer\_InvalidCallback

```solidity
error Auctioneer_InvalidCallback()
```

### Auctioneer\_InvalidParams

```solidity
error Auctioneer_InvalidParams()
```

### Auctioneer\_MarketNotActive

```solidity
error Auctioneer_MarketNotActive()
```

### Auctioneer\_MaxPayoutExceeded

```solidity
error Auctioneer_MaxPayoutExceeded()
```

### Auctioneer\_NewMarketsNotAllowed

```solidity
error Auctioneer_NewMarketsNotAllowed()
```

### Auctioneer\_NotAuthorized

```solidity
error Auctioneer_NotAuthorized()
```

### Auctioneer\_NotEnoughCapacity

```solidity
error Auctioneer_NotEnoughCapacity()
```

### Auctioneer\_OnlyMarketOwner

```solidity
error Auctioneer_OnlyMarketOwner()
```


---

# 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://dev.bondprotocol.finance/smart-contracts/bond-system/auctioneer/fixed-price-auctioneer-fpa.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.
