Module 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::pool_fee_manager

@title Fee Manager Module @author Aave @notice A fee module to add/manage a txn fee to mitigate the rounding error of integer arithmetic

use 0x1::account;
use 0x1::aptos_account;
use 0x1::aptos_coin;
use 0x1::coin;
use 0x1::event;
use 0x1::object;
use 0x1::signer;
use 0x1::smart_table;
use 0x24e01fa503119e76bf9eea69eec59884fc3da82f5ea23bf5f20f8ce358a4606::acl_manage;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::error_config;

Resource FeeConfigMetadata

@notice Metadata holding the address of the sticky object (used to access FeeConfig resource)

struct FeeConfigMetadata has key

Resource FeeConfig

@notice Configuration for fee management

struct FeeConfig has key

Struct FeeChanged

@notice Event emitted when the fee is updated via set_apt_fee @param caller Address who updated the fee @param asset The address of the underlying asset of the reserve @param old_fee Previous fee value (micro APT) @param new_fee New fee value (micro APT)

#[event]
struct FeeChanged has drop, store

Struct FeeCollected

@notice Event emitted when APT fees are collected @param from Who initiated the transfer @param recipient Address receiving the transferred fee @param asset The address of the underlying asset of the reserve @param amount Amount transferred in micro APT

#[event]
struct FeeCollected has drop, store

Struct FeeWithdrawn

@notice Event emitted when APT fees are withdrawn @param caller Who initiated the transfer @param recipient Address receiving the transferred fee @param amount Amount transferred in micro APT

#[event]
struct FeeWithdrawn has drop, store

Constants

@notice Default apt fee 0 APT

const DEFAULT_APT_FEE: u64 = 0;

@notice Seed value used to create a deterministic resource account for fee management. This seed is passed to account::create_resource_account to generate a unique resource account that will be used to collect and manage transaction fees. The resource account's address is deterministically derived from this seed and the source account's address.

const FEE_MANAGER: vector<u8> = [70, 69, 69, 95, 77, 65, 78, 65, 71, 69, 82];

@notice Maximum APT fee allowed (10 APT = 1_000_000_000 micro APT)

const MAX_APT_FEE: u64 = 1000000000;

Function get_apt_fee

@notice Returns the current configured APT fee (in micro APT) @param asset The address of the underlying asset of the reserve @return The fee in micro APT

#[view]
public fun get_apt_fee(asset: address): u64

Function get_fee_collector_address

@notice Returns the address of the fee collector resource account @return The address of the fee collector

#[view]
public fun get_fee_collector_address(): address

Function get_fee_collector_apt_balance

@notice Returns the current balance of APT held by the fee collection resource account @dev This represents the real-time available fees that have been collected but not yet distributed @return The balance in micro APT

#[view]
public fun get_fee_collector_apt_balance(): u64

Function get_total_fees

@notice Returns the total amount of fees collected historically @return The total fees in micro APT

#[view]
public fun get_total_fees(): u128

Function get_fee_config_object_address

@notice Returns the address of the sticky object that stores the fee configuration @return The address of the fee config object

#[view]
public fun get_fee_config_object_address(): address

Function withdraw_apt_fee

@notice Allows pool admin to transfer collected APT fees from the fee collector account to a target address @dev Can be used to withdraw accumulated fees to a treasury or reward distribution contract @dev Emits a FeeWithdrawn event on successful update @param from The signer of the pool admin account @param to The recipient address @param amount The amount to transfer in micro APT

public entry fun withdraw_apt_fee(from: &signer, to: address, amount: u128)

Function set_apt_fee

@notice Updates the global APT fee rate (in micro APT units) @dev Only callable by pool_configurator module @dev The new apt fee must be less than or equal to MAX_APT_FEE (10 APT) @dev Emits a FeeChanged event on successful update @param caller The signer of the pool admin or risk admin account @param asset The address of the underlying asset of the reserve @param new_apt_fee The new fee value in micro APT

public(friend) fun set_apt_fee(caller: &signer, asset: address, new_apt_fee: u64)

Function collect_apt_fee

@notice Charges the configured APT fee from the caller and transfers it to the fee collector account @dev Only callable by internal supply_logic, borrow_logic and flashloan_logic modules @dev Emits a FeeCollected event on successful update @dev Accumulates the fee into total_fees for historical auditing @param from The signer of the account paying the fee @param asset The address of the underlying asset of the reserve

public(friend) fun collect_apt_fee(from: &signer, asset: address)