# Base Teller

The Base Teller implements standard functionality shared by both types of Bond Tellers, including the core purchase logic, fee handling, and helper functions for generating token names for bond positions.&#x20;

Logic for handling payouts and tokenizing bond positions is left to contract implementations.

## Methods

### claimFees

```solidity
function claimFees(contract ERC20[] tokens_, address to_) external nonpayable
```

Claim fees accrued for input tokens and sends to protocolMust be guardian

#### Parameters

| Name     | Type              | Description                       |
| -------- | ----------------- | --------------------------------- |
| tokens\_ | contract ERC20\[] | Array of tokens to claim fees for |
| to\_     | address           | Address to send fees to           |

### createFeeDiscount

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

'Create' function fee discount. Amount standard fee is reduced by for partners who just want to use the 'create' function to issue bond tokens. Configurable by policy.

#### Returns

| Name        | Type   | Description                                                                          |
| ----------- | ------ | ------------------------------------------------------------------------------------ |
| feeDiscount | uint48 | Discount from base protocol purchase fee  when creating bond tokens for external use |

### getFee

```solidity
function getFee(address referrer_) external view returns (uint48)
```

Get current fee charged by the teller based on the combined protocol and referrer fee

#### Parameters

| Name       | Type    | Description             |
| ---------- | ------- | ----------------------- |
| referrer\_ | address | Address of the referrer |

#### Returns

| Name | Type   | Description                            |
| ---- | ------ | -------------------------------------- |
| fee  | uint48 | Fee in basis points (3 decimal places) |

### protocolFee

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

Fee paid to protocol. Configurable by policy, must be greater than 30 bps.

#### Returns

| Name        | Type   | Description |
| ----------- | ------ | ----------- |
| protocolFee | uint48 | undefined   |

### purchase

```solidity
function purchase(address recipient_, address referrer_, uint256 id_, uint256 amount_, uint256 minAmountOut_) external nonpayable returns (uint256, uint48)
```

Exchange quote tokens for a bond in a specified market

#### Parameters

| Name           | Type    | Description                                                                                                                          |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| recipient\_    | address | Address of recipient of bond. Allows deposits for other addresses                                                                    |
| referrer\_     | address | Address of referrer who will receive referral fee. For frontends to fill. Direct calls can use the zero address for no referrer fee. |
| id\_           | uint256 | ID of the Market the bond is being purchased from                                                                                    |
| amount\_       | uint256 | Amount to deposit in exchange for bond                                                                                               |
| minAmountOut\_ | uint256 | Minimum acceptable amount of bond to receive. Prevents frontrunning                                                                  |

#### Returns

| Name   | Type    | Description                                                                |
| ------ | ------- | -------------------------------------------------------------------------- |
| payout | uint256 | Amount of payout token to be received from the bond                        |
| expiry | uint48  | Timestamp at which the bond token can be redeemed for the underlying token |

### referrerFees

```solidity
function referrerFees(address) external view returns (uint48)
```

Fee paid to a front end operator. Set by the referrer, must be less than or equal to 5e4.

*There are some situations where the fees may round down to zero if quantity of baseToken is < 1e5 wei (can happen with big price differences on small decimal tokens). This is purely a theoretical edge case, as the bond amount would not be practical.*

#### Parameters

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| referrer | address | undefined   |

#### Returns

| Name | Type   | Description |
| ---- | ------ | ----------- |
| fee  | uint48 | undefined   |

### rewards

```solidity
function rewards(address, contract ERC20) external view returns (uint256)
```

Fees earned by an address, by token

#### Parameters

| Name     | Type           | Description |
| -------- | -------------- | ----------- |
| referrer | address        | undefined   |
| token    | contract ERC20 | undefined   |

#### Returns

| Name       | Type    | Description |
| ---------- | ------- | ----------- |
| feeBalance | uint256 | undefined   |

### setProtocolFee

```solidity
function setProtocolFee(uint48 fee_) external nonpayable
```

Set protocol feeMust be guardian

#### Parameters

| Name  | Type   | Description                                     |
| ----- | ------ | ----------------------------------------------- |
| fee\_ | uint48 | Protocol fee in basis points (3 decimal places) |

### setReferrerFee

```solidity
function setReferrerFee(uint48 fee_) external nonpayable
```

Set your fee as a referrer to the protocolFee is set for sending address

#### Parameters

| Name  | Type   | Description                                     |
| ----- | ------ | ----------------------------------------------- |
| fee\_ | uint48 | Referrer fee in basis points (3 decimal places) |

## Events

### Bonded

```solidity
event Bonded(uint256 indexed id, address indexed referrer, uint256 amount, uint256 payout)
```

#### Parameters

| Name               | Type    | Description                 |
| ------------------ | ------- | --------------------------- |
| id `indexed`       | uint256 | Market ID                   |
| referrer `indexed` | address | Referrer address            |
| amount             | uint256 | Amount of quote tokens in   |
| payout             | uint256 | Amount of payout tokens out |

## Errors

### Teller\_InvalidCallback

```solidity
error Teller_InvalidCallback()
```

### Teller\_InvalidParams

```solidity
error Teller_InvalidParams()
```

### Teller\_NotAuthorized

```solidity
error Teller_NotAuthorized()
```

### Teller\_TokenDoesNotExist

```solidity
error Teller_TokenDoesNotExist(contract ERC20 underlying, uint48 expiry)
```

#### Parameters

| Name       | Type           | Description |
| ---------- | -------------- | ----------- |
| underlying | contract ERC20 | undefined   |
| expiry     | uint48         | undefined   |

### Teller\_TokenNotMatured

```solidity
error Teller_TokenNotMatured(uint48 maturesOn)
```

#### Parameters

| Name      | Type   | Description |
| --------- | ------ | ----------- |
| maturesOn | uint48 | undefined   |

### Teller\_UnsupportedToken

```solidity
error Teller_UnsupportedToken()
```
