# Event Table

## Fixed Rate Market

| Role | Event          | Contract            | Purpose                                    |
| ---- | -------------- | ------------------- | ------------------------------------------ |
| BFR  | Borrow         | LendingMarket       | Position increase                          |
| BFR  | Repay          | LendingMarket       | Position decrease                          |
| BFR  | Liquidate      | LendingMarket       | Forced position closure                    |
| BFR  | Swap           | FiraMarket          | BFR qualification check                    |
| BT   | Transfer       | BondToken           | All balance changes (mint, burn, transfer) |
| BT   | Borrow         | LendingMarket       | For "subtract borrowed" rule               |
| BT   | Repay          | LendingMarket       | For "subtract borrowed" adjustment         |
| CT   | Transfer       | CouponToken (ERC20) | All balance changes (mint, burn, transfer) |
| CT   | RedeemInterest | CouponToken         | Interest redemption                        |
| LP   | Mint           | FiraMarket          | LP creation                                |
| LP   | Burn           | FiraMarket          | LP destruction                             |
| LP   | Transfer       | FiraMarket          | LP token transfers                         |

## Variable Rate Market

| Role | Event          | Contract      | Purpose                          |
| ---- | -------------- | ------------- | -------------------------------- |
| VRB  | Borrow         | LendingMarket | Position increase                |
| VRB  | Repay          | LendingMarket | Position decrease                |
| VRB  | AccrueInterest | LendingMarket | Shares-to-USDC conversion update |
| VRB  | Liquidate      | LendingMarket | Forced position closure          |
| VRL  | Deposit        | SisuVault     | Position increase (ERC4626)      |
| VRL  | Withdraw       | SisuVault     | Position decrease (ERC4626)      |
| VRL  | Transfer       | SisuVault     | Vault share transfers            |

## USL Migrator

| Role | Event              | Contract      | Purpose                 |
| ---- | ------------------ | ------------- | ----------------------- |
| USLC | SupplyCollateral   | LendingMarket | Position increase       |
| USLC | WithdrawCollateral | LendingMarket | Position decrease       |
| USLC | Liquidate          | LendingMarket | Collateral seizure      |
| USLL | Borrow             | LendingMarket | Position increase       |
| USLL | Repay              | LendingMarket | Position decrease       |
| USLL | Liquidate          | LendingMarket | Forced position closure |

## Issues found and corrected

| Change      | Detail                                                                    |
| ----------- | ------------------------------------------------------------------------- |
| **Removed** | BT / Mint / FiraMarket — wrong contract; FiraMarket.Mint is for LP tokens |
| **Removed** | BT / Burn / FiraMarket — wrong contract; same reason                      |
| **Removed** | CT / Mint / CouponToken — redundant with CT Transfer (from=0x0)           |
| **Removed** | CT / Burn / CouponToken — redundant with CT Transfer (to=0x0)             |
| **Added**   | BFR / Swap / FiraMarket — required for BFR qualification per spec         |
| **Added**   | BFR / Liquidate / LendingMarket                                           |
| **Added**   | LP / Transfer / FiraMarket                                                |
| **Added**   | VRB / Liquidate / LendingMarket                                           |
| **Added**   | VRL / Transfer / SisuVault                                                |
| **Added**   | USLC / Liquidate / LendingMarket                                          |
| **Added**   | USLL / Liquidate / LendingMarket                                          |

### Key corrections explained

**BT Mint/Burn: Wrong contract (Critical)** — The original table listed BT Mint/Burn on FiraMarket, but BT is created/destroyed by `CouponToken.mintBC()` / `CouponToken.redeemBC()`. FiraMarket `Mint`/`Burn` events are about LP tokens, not BT. The ERC20 `Transfer` event on BondToken already captures mints (`from = address(0)`), burns (`to = address(0)`), and transfers.

**BFR qualification requires Swap** — The spec states borrowers must be verified by tracking both the borrow event and a swap event plus USDC transfer. The `Swap` event from FiraMarket confirms the borrower actually swapped BT for USDC.

**Liquidate event missing** — `EventsLib.Liquidate` fires on forced position closure and impacts BFR, VRB, USLC, and USLL. Without it, the TWAP will be incorrect for liquidated users.

## Event signatures reference

### LendingMarket (EventsLib)

```solidity
event Borrow(Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 assets, uint256 shares);
event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares);
event SupplyCollateral(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets);
event WithdrawCollateral(Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 assets);
event AccrueInterest(Id indexed id, uint256 prevBorrowRate, uint256 interest, uint256 feeShares);
event Liquidate(Id indexed id, address indexed caller, address indexed borrower, uint256 repaidAssets, uint256 repaidShares, uint256 seizedAssets, uint256 badDebtAssets, uint256 badDebtShares);
```

### BondToken / CouponToken (ERC20)

```solidity
event Transfer(address indexed from, address indexed to, uint256 value);
```

### CouponToken (IBCToken)

```solidity
event RedeemInterest(address indexed user, uint256 interestOut);
```

### FiraMarket (IPMarket)

```solidity
event Mint(address indexed receiver, uint256 netLpMinted, uint256 netFwUsed, uint256 netBtUsed);
event Burn(address indexed receiverFw, address indexed receiverBt, uint256 netLpBurned, uint256 netFwOut, uint256 netBtOut);
event Swap(address indexed caller, address indexed receiver, int256 netBtOut, int256 netFwOut, uint256 netFwFee, uint256 netFwToReserve);
```

### SisuVault (ERC4626)

```solidity
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
event Transfer(address indexed from, address indexed to, uint256 value);
```

## Implementation notes

* **Market ID filtering**: All LendingMarket events carry `Id indexed id`. The indexer must filter by the correct market IDs to distinguish BFR vs VRB vs USLL markets.
* **No double counting**: BT/CT held inside LP pool addresses or router addresses must be excluded from BT/CT buckets. Maintain a set of excluded addresses.
* **AccrueInterest for BFR/USLL**: If position value must reflect accrued interest (not just principal), add AccrueInterest to those roles.
* **CT in LP pools**: If external AMM pools exist for CT (not FiraMarket), additional pool-specific events would be needed.
