# Interactions

### Governance Functions

#### **setBuffer**

Sets the buffer rate percentage that determines how much of each reward goes to the buffer.

```solidity
function setBuffer(uint256 _buffer) external;

```

**Parameters**

| Name      | Type      | Description                                                   |
| --------- | --------- | ------------------------------------------------------------- |
| `_buffer` | `uint256` | The buffer percentage (must be less than BUFFER\_DENOMINATOR) |

**Access Control:** only Owner (Keeper)

#### **setSymbol**

Updates the token symbol.

```solidity
function setSymbol(string memory _symbol) external;

```

**Parameters**

| Name      | Type     | Description          |
| --------- | -------- | -------------------- |
| `_symbol` | `string` | The new token symbol |

**Access Control:** only Owner (Keeper)\
\
**withdrawBuffer**

Withdraw `_amount` from Buffer and mint SPAToken shares to `_to`

```solidity
function withdrawBuffer(address _to, uint256 _amount) external;
```

**Parameters**

| Name      | Type      | Description                                             |
| --------- | --------- | ------------------------------------------------------- |
| `_to`     | `address` | Recipient address that will receive newly-minted shares |
| `_amount` | `uint256` | Token amount to withdraw                                |

**Access:** only Owner (via Keeper)

**transferShares**

Moves `_sharesAmount` token shares from the caller's account to the `_recipient` account.

*Note: The `_sharesAmount` argument is the amount of shares, not tokens.*

```solidity
function transferShares(address _recipient, uint256 _sharesAmount)
    external
    returns (uint256);

```

**Parameters**

| Name            | Type      | Description                                   |
| --------------- | --------- | --------------------------------------------- |
| `_recipient`    | `address` | The address to receive the shares             |
| `_sharesAmount` | `uint256` | The amount of shares to transfer (not tokens) |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The amount of tokens transferred |

**transferSharesFrom**

Moves `_sharesAmount` token shares from the `_sender` account to the `_recipient` account using the allowance mechanism.

```solidity
function transferSharesFrom(
    address _sender,
    address _recipient,
    uint256 _sharesAmount
)
    external
    returns (uint256);

```

**Parameters**

| Name            | Type      | Description                         |
| --------------- | --------- | ----------------------------------- |
| `_sender`       | `address` | The address to transfer shares from |
| `_recipient`    | `address` | The address to receive the shares   |
| `_sharesAmount` | `uint256` | The amount of shares to transfer    |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The amount of tokens transferred |

**Requirements:** The caller must have sufficient allowance for the sender's tokens.

**mintShares**

Mints shares for the specified account and transfers them to that account.

```solidity
function mintShares(address _account, uint256 _tokenAmount)
    external;

```

**Parameters**

| Name           | Type      | Description                                               |
| -------------- | --------- | --------------------------------------------------------- |
| `_account`     | `address` | The address to mint shares to                             |
| `_tokenAmount` | `uint256` | The token amount to mint (converted to shares internally) |

**Access Control:** Only callable by the pool contract.

**burnShares**

Burns shares from the caller's account.

```solidity
function burnShares(uint256 _tokenAmount)
    external;

```

**Parameters**

| Name           | Type      | Description                                               |
| -------------- | --------- | --------------------------------------------------------- |
| `_tokenAmount` | `uint256` | The token amount to burn (converted to shares internally) |

**burnSharesFrom**

Burns shares from the specified account using the allowance mechanism.

```solidity
function burnSharesFrom(address _account, uint256 _tokenAmount)
    external;

```

**Parameters**

| Name           | Type      | Description                     |
| -------------- | --------- | ------------------------------- |
| `_account`     | `address` | The address to burn shares from |
| `_tokenAmount` | `uint256` | The token amount to burn        |

**Requirements:** The caller must have sufficient allowance for the account's tokens.

#### Supply Management

**addTotalSupply**

Increases the total supply of SPAToken by staking rewards and swap fees, with automatic buffer allocation.

```solidity
function addTotalSupply(uint256 _amount)
    external;

```

**Parameters**

| Name      | Type      | Description                       |
| --------- | --------- | --------------------------------- |
| `_amount` | `uint256` | The amount to add to total supply |

**Access Control:** Only callable by the pool contract.

**Behavior:**

* payFirst pays down any existing buffer bad debt
* Allocates a percentage to the buffer based on `bufferPercent`
* Remainder increases the actual total supply

**removeTotalSupply**

Decreases the total supply of SPAToken due to losses, with options for buffer usage and debt tracking.

```solidity
function removeTotalSupply(uint256 _amount, bool isBuffer, bool withDebt)
    external;

```

**Parameters**

| Name       | Type      | Description                                         |
| ---------- | --------- | --------------------------------------------------- |
| `_amount`  | `uint256` | The amount to remove from total supply              |
| `isBuffer` | `bool`    | Whether to use buffer funds instead of total supply |
| `withDebt` | `bool`    | Whether to add the amount to buffer bad debt        |

**Access Control:** Only callable by the pool contract.

**addBuffer**

Directly increases the buffer amount without affecting total supply.

```solidity
function addBuffer(uint256 _amount)
    external;

```

**Parameters**

| Name      | Type      | Description                     |
| --------- | --------- | ------------------------------- |
| `_amount` | `uint256` | The amount to add to the buffer |

**Access Control:** Only callable by the pool contract.

### View Functions

**sharesOf**

Returns the amount of shares owned by an account.

```solidity
function sharesOf(address _account)
    external
    view
    returns (uint256);

```

**Parameters**

| Name       | Type      | Description                     |
| ---------- | --------- | ------------------------------- |
| `_account` | `address` | The account to query shares for |

**Returns**

| Name     | Type      | Description                               |
| -------- | --------- | ----------------------------------------- |
| `<none>` | `uint256` | The amount of shares owned by the account |

**getPeggedTokenByShares**

Converts a share amount to the corresponding token amount.

```solidity
function getPeggedTokenByShares(uint256 _sharesAmount)
    public
    view
    returns (uint256);

```

**Parameters**

| Name            | Type      | Description                     |
| --------------- | --------- | ------------------------------- |
| `_sharesAmount` | `uint256` | The amount of shares to convert |

**Returns**

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `<none>` | `uint256` | The corresponding token amount |

**getSharesByPeggedToken**

Converts a token amount to the corresponding share amount.

```solidity
function getSharesByPeggedToken(uint256 _spaTokenAmount)
    public
    view
    returns (uint256);

```

**Parameters**

| Name              | Type      | Description                 |
| ----------------- | --------- | --------------------------- |
| `_spaTokenAmount` | `uint256` | The token amount to convert |

**Returns**

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `<none>` | `uint256` | The corresponding share amount |


---

# 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://docs.tapio.finance/smart-contracts/spatoken/interactions.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.
