Module 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::borrow_logic

@title Borrow Logic Module @author Aave @notice Implements the base logic for all the actions related to borrowing

use 0x1::event;
use 0x1::object;
use 0x1::signer;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::error_config;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::reserve_config;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::user_config;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::a_token_factory;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::emode_logic;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::events;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::fungible_asset_manager;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::isolation_mode_logic;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::pool;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::pool_fee_manager;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::pool_logic;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::validation_logic;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::variable_debt_token_factory;
use 0xd63343bff7977cb364b17dcdcdeb64e77b7bc9b4ec252f481ace51b6de3bbd96::math_utils;

Struct Borrow

@notice Emitted when a borrow occurs @dev Emitted on borrow() and flash_loan() when debt needs to be opened @param reserve The address of the underlying asset being borrowed @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just initiator of the transaction on flash_loan() @param on_behalf_of The address that will be getting the debt @param amount The amount borrowed out @param interest_rate_mode The rate mode: 2 for Variable @param borrow_rate The numeric rate at which the user has borrowed, expressed in ray @param referral_code The referral code used

#[event]
struct Borrow has drop, store

Struct Repay

@notice Emitted when a repayment occurs @dev Emitted on repay() @param reserve The address of the underlying asset of the reserve @param user The beneficiary of the repayment, getting his debt reduced @param repayer The address of the user initiating the repay(), providing the funds @param amount The amount repaid @param use_a_tokens True if the repayment is done using aTokens, false if done with underlying asset directly

#[event]
struct Repay has drop, store

Function borrow

@notice Allows users to borrow a specific amount of the reserve underlying asset, provided that the borrower already supplied enough collateral - E.g. User borrows 100 USDC passing as on_behalf_of his own address, receiving the 100 USDC in his wallet and 100 variable debt tokens, depending on the interest_rate_mode @dev Emits the Borrow() event @param account The signer account of the caller @param asset The address of the underlying asset to borrow @param amount The amount to be borrowed @param interest_rate_mode The interest rate mode at which the user wants to borrow: 2 for Variable @param referral_code The code used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-man @param on_behalf_of The address of the user who will receive the debt. Should be the address of the borrower itself

public entry fun borrow(account: &signer, asset: address, amount: u256, interest_rate_mode: u8, referral_code: u16, on_behalf_of: address)

Function repay

@notice Repays a borrowed amount on a specific reserve, burning the equivalent debt tokens owned - E.g. User repays 100 USDC, burning 100 variable debt tokens of the on_behalf_of address @param account The signer account of the caller @param asset The address of the borrowed underlying asset previously borrowed @param amount The amount to repay - Send the value math_utils::u256_max() in order to repay the whole debt for asset on the specific interest_rate_mode @param interest_rate_mode The interest rate mode at of the debt the user wants to repay: 2 for Variable @param on_behalf_of The address of the user who will get his debt reduced/removed. Should be the address of the user calling the function if he wants to reduce/remove his own debt, or the address of any other other borrower whose debt should be removed

public entry fun repay(account: &signer, asset: address, amount: u256, interest_rate_mode: u8, on_behalf_of: address)

Function repay_with_a_tokens

@notice Repays a borrowed amount on a specific reserve using the reserve aTokens, burning the equivalent debt tokens - E.g. User repays 100 USDC using 100 aUSDC, burning 100 variable debt tokens @dev Passing math_utils::u256_max() as amount will clean up any residual aToken dust balance, if the user aToken balance is not enough to cover the whole debt @param account The signer account of the caller @param asset The address of the borrowed underlying asset previously borrowed @param amount The amount to repay @param interest_rate_mode The interest rate mode at of the debt the user wants to repay: 2 for Variable

public entry fun repay_with_a_tokens(account: &signer, asset: address, amount: u256, interest_rate_mode: u8)

Function internal_borrow

@notice Implements the borrow feature. Borrowing allows users that provided collateral to draw liquidity from the Aave protocol proportionally to their collateralization power. For isolated positions, it also increases the isolated debt. @dev Only callable by the borrow_logic and flashloan_logic module @dev Emits the Borrow() event @param user The address of the caller @param asset The address of the underlying asset to borrow @param amount The amount to be borrowed @param interest_rate_mode The interest rate mode at which the user wants to borrow: 2 for Variable @param referral_code The code used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle @param on_behalf_of The address of the user who will receive the debt. Should be the address of the borrower itself @param release_underlying If true, the underlying asset will be transferred to the user, otherwise it will stay

public(friend) fun internal_borrow(user: address, asset: address, amount: u256, interest_rate_mode: u8, referral_code: u16, on_behalf_of: address, release_underlying: bool)