# Layerbank Integration

## Overview

The `layerbank_block::layerbank_block` module contains the block implementation for LayerBank's Aave integration. This module provides convenience functions to interact with Aave's lending protocol, handling supply operations, withdrawals, and rewards claiming. These block functions are used by concrete strategy implementations to interact with the Aave protocol, instead of interacting with it directly.

## Constants

* **MAX\_U64**: `u256 = 18446744073709551615u256` - Maximum value for a u64, used in rewards claiming operations

## Public Functions

### Lending Operations

* `supply(account: &signer, asset: address, amount: u256, recipient: address, referral_code: u16)`: Wraps the Aave `supply_logic::supply` function. Supplies an asset to the Aave lending pool and mints aTokens to the specified recipient. The account must have sufficient balance of the asset.
* `withdraw(account: &signer, asset: address, amount: u256, recipient: address)`: Wraps the Aave `supply_logic::withdraw` function. Withdraws an asset from the Aave lending pool. The account must have sufficient aToken balance. The withdrawn assets are sent to the specified recipient. Note: This function does not claim rewards - reward claiming should be handled separately.

### Rewards Operations

* `claim_all_rewards(caller: &signer, asset: Object<Metadata>, rewards_controller_address: address)`: Claims all available rewards for a supplied asset. Claims rewards for a single supplied asset and sends rewards to the caller's address.
* `claim_all_non_base_asset_rewards(caller: &signer, base_asset: Object<Metadata>, rewards_controller_address: address)`: Claims all rewards except those denominated in the base asset. Retrieves the list of all reward assets, claims rewards for each reward asset except the base asset, and sends all claimed rewards to the caller's address.
* `claim_base_asset_rewards(caller: &signer, base_asset: Object<Metadata>, rewards_controller_address: address): u256`: Claims only the rewards denominated in the base asset. Returns the total amount of base asset rewards claimed. The claimed rewards are sent to the caller's address. Returns 0 if no base asset rewards are available.

### View Functions

* `get_user_supply_with_interest(user: address, asset: address): u256`: Returns the total amount of underlying asset supplied by a user including accrued interest. Calculated by multiplying the user's scaled aToken balance by the normalized income (liquidity index). Returns the total supply balance in the underlying asset's decimals.
* `reserve_exists(asset: address)`: Verifies if a reserve exists for the specified asset by attempting to get its reserve data. Aborts if the reserve doesn't exist.


---

# 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.canopyhub.xyz/canopys-four-layers/protocol-layer/layerbank-integration.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.
