# BloomPool

## Overview

The core smart contract of the Bloom Ecosystem. Acting as the main entry point for users accessing permissionless RWA yield.

It is made up of three components.&#x20;

* The core logic of handling market maker swaps, `TBY` yield and redemptions.
* The `Orderbook`
* Global `PoolStorage`

This page will break down the first of the three with the `Orderbook` and `PoolStorage` being covered extensively within the following subsections.

## Contract API

### `getRate`

```solidity
function getRate(uint256 id) public view override returns (uint256);
```

Returns the current rate of a `TBY` in terms of USD.

### `redeemLender`

```solidity
function redeemLender(uint256 id, uint256 amount) external returns (uint256 reward);
```

Redeems the callers `TBY` . Burning the token and sending the user their share of rewards generated during the tokens lifecycle.

{% hint style="info" %}
Lenders can only redeem if market makers have done their job swapping the `rwa` for the `asset`.&#x20;
{% endhint %}

### `redeemBorrower`

```solidity
function redeemBorrower(uint256 id) external returns (uint256 reward);
```

Redeem the borrowers's share of rewards generated from the `rwa` at the time of maturity.

{% hint style="info" %}
Borrowers can only redeem if market makers have done their job swapping the `rwa` for the `asset`.&#x20;
{% endhint %}

### `borrowerAmount`

```solidity
function borrowerAmount(address account, uint256 id) external view returns (uint256);
```

Returns the total amount of assets a borrower has contributed for a given `TbyId`

### `swapIn`

```solidity
function swapIn(address[] memory accounts, uint256 assetAmount)
    external
    KycMarketMaker
    returns (uint256 id, uint256 amountSwapped);
```

Swaps in `asset`s for `rwa` tokens, starting the `TBY` minting process. If interacted with multiple times in a `48 hour` period the `TBY`s that get minted will have the same token `id`, `start` , and `end` time. For system efficiency it is recommended that market makers batch as many matched orders as possible.

Returns the `id` of the `TBY` the swap was for, as well as `amountSwapped` , representing the total amount of `asset`s swapped out of the pool.

{% hint style="info" %}
This is a permissioned function. Only fully KYCed Market Makers can call this function.
{% endhint %}

### `swapOut`

{% hint style="info" %}
This is a permissioned function. Only fully KYCed Market Makers can call this function.
{% endhint %}

```solidity
function swapOut(uint256 id, uint256 rwaAmount) external KycMarketMaker returns (uint256 assetAmount);
```

Swaps `asset` tokens in and `rwa` tokens out, ending the TBY life cycle.

Returns `assetAmount`, representing the total amount of `asset`s swapped into the pool.
