# Base Callback

The [Base Callback](https://github.com/Bond-Protocol/bond-contracts/blob/master/src/bases/BondBaseCallback.sol) contract is an optional feature of the Bond system. Callbacks allow issuers (market creators) to apply custom logic on receipt and payout of tokens.&#x20;

In addition to the [Callback Interface](/smart-contracts/bond-system/callback/callback-interface.md), the Base Callback is also implemented to provide a secure starting point for creating a Callback contract.&#x20;

The base handles permissioning of Tellers (*and specific markets served by the Teller*) to avoid unauthorized contracts from accessing the callback function.&#x20;

Additionally, the setup and data storage for getting data from an Aggregator.&#x20;

Finally, the external callback function is implemented to ensure the Teller is providing the stated amount of Quote Tokens prior to disbursing Payout Tokens. Issuer-specific logic can be implemented in the `_callback` internal function which is called by the external one.

The Callback must be created prior to market creation and the address passed in as an argument. The Callback depends on the Aggregator contract for the Auctioneer that the market is created to get market data. Without a Callback contract, payout tokens are transferred directly from the market owner on each bond purchase (market owners must approve the Teller serving that market for the amount of Payout Tokens equivalent to the capacity of a market when created.

## Methods

### amountsForMarket

```solidity
function amountsForMarket(uint256 id_) external view returns (uint256 in_, uint256 out_)
```

Returns the number of quote tokens received and payout tokens paid out for a market

#### Parameters

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

#### Returns

| Name  | Type    | Description                                    |
| ----- | ------- | ---------------------------------------------- |
| in\_  | uint256 | Amount of quote tokens bonded to the market    |
| out\_ | uint256 | Amount of payout tokens paid out to the market |

### approvedMarkets

```solidity
function approvedMarkets(address, uint256) external view returns (bool)
```

#### Parameters

| Name     | Type    | Description                    |
| -------- | ------- | ------------------------------ |
| teller\_ | address | Address of the Teller contract |
| id\_     | uint256 | ID of the market               |

#### Returns

| Name     | Type | Description                                                               |
| -------- | ---- | ------------------------------------------------------------------------- |
| approved | bool | Whether the Teller and Market ID combination are approved on the callback |

### callback

```solidity
function callback(uint256 id_, uint256 inputAmount_, uint256 outputAmount_) external nonpayable
```

Send payout tokens to Teller while allowing market owners to perform custom logic on received or paid out tokensMarket ID on Teller must be whitelisted

*Must transfer the output amount of payout tokens back to the TellerShould check that the quote tokens have been transferred to the contract in the \_callback function*

#### Parameters

| Name           | Type    | Description                                          |
| -------------- | ------- | ---------------------------------------------------- |
| id\_           | uint256 | ID of the market                                     |
| inputAmount\_  | uint256 | Amount of quote tokens bonded to the market          |
| outputAmount\_ | uint256 | Amount of payout tokens to be paid out to the market |

### deposit

```solidity
function deposit(contract ERC20 token_, uint256 amount_) external nonpayable
```

Deposit tokens to the callback and update balancesOnly callback owner

#### Parameters

| Name     | Type           | Description                     |
| -------- | -------------- | ------------------------------- |
| token\_  | contract ERC20 | Address of the token to deposit |
| amount\_ | uint256        | Amount of tokens to deposit     |

### owner

```solidity
function owner() external view returns (address)
```

*Returns the address of the current owner.*

#### Returns

| Name  | Type    | Description                                 |
| ----- | ------- | ------------------------------------------- |
| owner | address | Owner of the callback with admin privileges |

### renounceOwnership

```solidity
function renounceOwnership() external nonpayable
```

*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*

### transferOwnership

```solidity
function transferOwnership(address newOwner) external nonpayable
```

*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*

#### Parameters

| Name     | Type    | Description                      |
| -------- | ------- | -------------------------------- |
| newOwner | address | Address to transfer ownership to |

### whitelist

```solidity
function whitelist(address teller_, uint256 id_) external nonpayable
```

Whitelist a teller and market ID combinationMust be callback owner

#### Parameters

| Name     | Type    | Description                                            |
| -------- | ------- | ------------------------------------------------------ |
| teller\_ | address | Address of the Teller contract which serves the market |
| id\_     | uint256 | ID of the market                                       |

### withdraw

```solidity
function withdraw(address to_, contract ERC20 token_, uint256 amount_) external nonpayable
```

Withdraw tokens from the callback and update balancesOnly callback owner

#### Parameters

| Name     | Type           | Description                      |
| -------- | -------------- | -------------------------------- |
| to\_     | address        | Address of the recipient         |
| token\_  | contract ERC20 | Address of the token to withdraw |
| amount\_ | uint256        | Amount of tokens to withdraw     |

## Events

### OwnershipTransferred

```solidity
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
```

#### Parameters

| Name                    | Type    | Description               |
| ----------------------- | ------- | ------------------------- |
| previousOwner `indexed` | address | Address of previous owner |
| newOwner `indexed`      | address | Address of new owner      |

## Errors

### Callback\_MarketNotSupported

```solidity
error Callback_MarketNotSupported(uint256 id)
```

#### Parameters

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

### Callback\_TokensNotReceived

```solidity
error Callback_TokensNotReceived()
```


---

# 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/callback/base-callback.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.
