Verified contractPartialBUSL-1.1
VaultBTC
Address0x69712d713fd30abef48b5d14ec2a9fb834d2c341
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- BUSL-1.1
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,388,186
- Creation transaction
- 0x349d7d546d…b517c5c103
9 files
- src/applications/aave/VaultBTC.solmain4.4 KB
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.8 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- src/applications/aave/lib/types/Errors.sol7.47 KB
- src/applications/aave/lib/types/Events.sol8.05 KB
- src/applications/aave/lib/types/TokenAmountLib.sol2.23 KB
src/applications/aave/VaultBTC.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {ERC20} from "../../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {Errors as AdapterErrors} from "./lib/types/Errors.sol";
import {Events as AdapterEvents} from "./lib/types/Events.sol";
/// @title VaultBTC (vaultBTC) - Aave v4 Integration ERC-20 Token
/// @notice ERC-20 token with destination restrictions that prevent direct EOA holdings
/// @dev Mints and transfers must land on the Hub, the adapter, or a registered user proxy.
/// Enforced in `_update`, so it covers every balance-increasing path.
contract VaultBTC is ERC20 {
/// @notice Immutable address of the AaveAdapter proxy
address public immutable adapter;
/// @notice Address of the Aave Hub that holds supplied vaultBTC
address public immutable HUB;
/// @notice Mapping to keep track of valid user proxy addresses
mapping(address => bool) private validProxies;
/// @notice Deploy the token with its permanent Hub and adapter addresses
/// @dev The adapter may be a predicted proxy address whose code is deployed later.
/// @param name Token name
/// @param symbol Token symbol
/// @param _hub Aave Hub address
/// @param _adapter AaveAdapter proxy address
constructor(string memory name, string memory symbol, address _hub, address _adapter) ERC20(name, symbol) {
if (_hub == address(0) || _adapter == address(0)) revert AdapterErrors.ZeroAddress();
HUB = _hub;
adapter = _adapter;
}
/// @notice Returns the number of decimals used to get user representation
/// @dev Overrides ERC20 default of 18 to match Bitcoin's 8 decimals
/// @return uint8 The number of decimals (8)
function decimals() public pure override returns (uint8) {
return 8;
}
/// @notice Mint tokens to specified address
/// @dev Reverts with `UnauthorizedTransferDestination` unless `to` is an authorized destination
/// @param to Address to mint tokens to
/// @param amount Amount of tokens to mint
function mint(address to, uint256 amount) external onlyAdapter {
if (to == address(0)) revert AdapterErrors.ZeroAddress();
_mint(to, amount);
}
/// @notice Burn tokens from specified address
/// @param from Address to burn tokens from
/// @param amount Amount of tokens to burn
function burn(address from, uint256 amount) external onlyAdapter {
if (from == address(0)) revert AdapterErrors.ZeroAddress();
_burn(from, amount);
}
/// @notice Add a valid user proxy address
/// @param proxyAddress Address to add as valid proxy
function addValidProxy(address proxyAddress) external onlyAdapter {
if (proxyAddress == address(0)) revert AdapterErrors.ZeroAddress();
validProxies[proxyAddress] = true;
emit AdapterEvents.ProxyAdded(proxyAddress);
}
/// @notice Check if an address is a valid user proxy
/// @param proxyAddress Address to check
/// @return isValid Whether the address is a valid proxy
function isValidUserProxy(address proxyAddress) public view returns (bool isValid) {
return validProxies[proxyAddress];
}
/// @notice Enforce the destination allowlist on every balance movement
/// @dev Hooked at `_update` so mints and transfers share one gate. Burns are exempt because
/// their destination is `address(0)`; the adapter restricts who may burn instead.
/// @param from Address the balance moves from, or `address(0)` on mint
/// @param to Address the balance moves to, or `address(0)` on burn
/// @param value Amount moved
function _update(address from, address to, uint256 value) internal virtual override {
if (to != address(0) && !_isAuthorizedDestination(to)) {
revert AdapterErrors.UnauthorizedTransferDestination();
}
super._update(from, to, value);
}
/// @notice Check if an address is an authorized destination for vaultBTC transfers
/// @param to The destination address
/// @return True if the address is authorized
function _isAuthorizedDestination(address to) internal view returns (bool) {
return to == HUB || to == adapter || isValidUserProxy(to);
}
modifier onlyAdapter() {
if (msg.sender != adapter) revert AdapterErrors.OnlyAdapter();
_;
}
}
lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-721.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/// @inheritdoc IERC20
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/// @inheritdoc IERC20
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/// @inheritdoc IERC20
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation sets the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the `transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/applications/aave/lib/types/Errors.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
library Errors {
/// @notice Error thrown when zero address is provided where not allowed
error ZeroAddress();
/// @notice Error thrown when zero amount is provided
error ZeroAmount();
/// @notice Error thrown when caller is not authorized
error Unauthorized();
/// @notice Error thrown when invalid amount is provided
error InvalidAmount();
/// @notice Error thrown when caller is not the configured adapter
error OnlyAdapter();
/// @notice Error thrown when a BTC vault has an invalid usage status
error InvalidBTCVaultUsageStatus();
/// @notice Error thrown when address is not a contract
error NotContract();
/// @notice Error thrown when a token transfer targets an unauthorized destination
error UnauthorizedTransferDestination();
/// @notice Error thrown when input array length is zero
error EmptyArray();
/// @notice Error thrown when invalid proxy contract is provided
error InvalidProxyContract();
/// @notice Error thrown when withdrawal did not recall the full vault amount
/// @param expected The expected vault amount to be withdrawn
/// @param actual The actual amount withdrawn
error IncompleteWithdrawal(uint256 expected, uint256 actual);
/// @notice Error thrown when a position resolver is invalid for the target application
error InvalidPositionResolver();
/// @notice Error thrown when spoke oracle returns zero price for a required reserve
error InvalidOraclePrice();
/// @notice Error thrown when a position does not satisfy Aave liquidation conditions
error PositionNotLiquidatable();
/// @notice Error thrown when collateral is left over on the proxy while debt remains outstanding, so no
/// fairness payment can be settled for the excess
error InvalidPostLiquidationState();
/// @notice Error thrown when LLP address is not registered
/// @param llp The unregistered LLP address
error LLPNotRegistered(address llp);
/// @notice Error thrown when attempting to register an LLP that is already registered
/// @param llp The already-registered LLP address
error LLPAlreadyRegistered(address llp);
/// @notice Error thrown when LLP is disabled for new settlements
error LLPDisabled();
/// @notice Error thrown when position sizes are invalid (e.g., exceeding number of vaults or total amount)
error InvalidPositionSizes();
/// @notice Error thrown when a vault removal request contains missing or invalid vaults
error InvalidVaultsArray();
/// @notice Error thrown when the configured proxy implementation is invalid
error InvalidImplementation();
/// @notice Error thrown when activationMetadata specifies an unsupported version
error InvalidActivationMetadataVersion();
/// @notice Error thrown when a delegated position account already exists for a user and delegatee pair
error PositionAccountAlreadyExists();
/// @notice Error thrown when deployment of a delegated position account fails
error PositionAccountCreationFailed();
/// @notice Error thrown when no delegated position account exists for a user and delegatee pair
error PositionAccountDoesNotExist();
/// @notice Error thrown when a delegated borrow exceeds the remaining reserve allowance
error InsufficientBorrowAllowance();
/// @notice Error thrown when a delegated borrow specifies an invalid receiver
error InvalidReceiver();
/// @notice Error thrown when position account creation or borrowing uses an unverified delegatee
error DelegateeNotVerified();
/// @notice Error thrown when a curator that the resolver has not approved is appointed or borrows
error CuratorNotApproved();
/// @notice Error thrown when a depositor outside an enabled resolver allowlist creates or activates a position
error DepositorNotAllowed();
/// @notice Error thrown when a curator borrow leaves the position below the resolver's minimum health factor
/// @param healthFactor Position health factor after the borrow, in WAD
/// @param minimum Minimum health factor the resolver requires after a curator borrow, in WAD
error BorrowHealthFactorTooLow(uint256 healthFactor, uint256 minimum);
/// @notice Error thrown when a minimum borrow health factor does not exceed the liquidation threshold
error InvalidMinBorrowHealthFactor();
/// @notice Error thrown when a resolver's ERC4626 yield vault does not take its debt reserve's underlying token
error YieldVaultAssetMismatch();
/// @notice Error thrown when a resolver's ERC4626 yield vault has fewer shares than the resolver's minimum supply
error YieldVaultSupplyTooLow();
/// @notice Error thrown when a curator borrow's yield vault deposit mints fewer shares than the owner's
/// minimum deposit rate requires
/// @param assets Amount of the underlying token deposited
/// @param shares Yield vault shares the deposit minted
error YieldVaultDepositRateTooLow(uint256 assets, uint256 shares);
/// @notice Error thrown when a curator repay's yield vault withdrawal burns more shares than the owner's
/// maximum withdraw rate allows
/// @param assets Amount of the underlying token withdrawn
/// @param shares Yield vault shares the withdrawal burned
error YieldVaultWithdrawRateTooHigh(uint256 assets, uint256 shares);
/// @notice Error thrown when a yield vault deposit or withdrawal reports a share count that the position
/// account's share balance change does not back: fewer shares received or more shares burned
/// @param reportedShares Shares the yield vault call returned
/// @param balanceChange Shares the account's balance actually gained (deposit) or lost (withdrawal)
error YieldVaultShareBalanceMismatch(uint256 reportedShares, uint256 balanceChange);
/// @notice Error thrown when a curator borrows before the owner has set the yield vault rates
error YieldVaultRatesNotSet();
/// @notice Error thrown when the owner sets a zero yield vault rate
error InvalidYieldVaultRates();
/// @notice Error thrown when a resolver is configured with a debt reserve ID that is out of range or is the
/// vaultBTC reserve
error InvalidReserveId();
/// @notice Error thrown when the Hub's vBTC added shares and added assets diverge, breaking the 1:1 assumption
/// that liquidation collateral accounting relies on
error VaultBTCSharesAssetsMismatch();
/// @notice Error thrown when the exitBTC a liquidation charges the liquidator exceeds the cap they supplied
error ExcessiveExitBtcPayment();
/// @notice Error thrown when a liquidation targets a borrower holding no collateralized vaults
error NoCollateralizedVaults();
/// @notice Error thrown when a resolved position account does not report the expected resolver
error InvalidPositionAccount();
/// @notice Error thrown when a borrower attempts to reorder vaults on a liquidatable position
error PositionNotHealthy();
/// @notice Error thrown when the adapter is initialized behind a proxy whose address is not the Core Spoke's
/// immutable `LIQUIDATION_MANAGER`, which would leave every liquidation call rejected by the Spoke
error SpokeLiquidationManagerNotSetProperly();
}
src/applications/aave/lib/types/Events.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {TokenAmountLib} from "./TokenAmountLib.sol";
library Events {
/// @notice Event emitted when a proxy is added to the valid list
event ProxyAdded(address indexed proxy);
/// @notice Emitted when the recipient of liquidation fees and failed fairness payments is updated
event AdapterApplicationRecipientUpdated(address applicationFeeRecipient);
/// @notice Emitted when the borrower interest fee recipient is updated
event AdapterInterestFeeRecipientUpdated(address interestFeeRecipient);
/// @notice Emitted when the liquidation fee is updated
event AdapterLiquidationFeeUpdated(uint256 liquidationFeeBps);
/// @notice Emitted when a position resolver is registered on the adapter
/// @param positionResolver The resolver contract that can map depositors to position accounts
event AdapterPositionResolverAdded(address indexed positionResolver);
/// @notice Emitted when a position resolver is removed from the adapter
/// @param positionResolver The resolver contract that was removed
event AdapterPositionResolverRemoved(address indexed positionResolver);
/// @notice Emitted when collateral is added to a position
/// @param positionAccount The positionAccount address
/// @param vaultId The vault id of the collateral added
event CollateralAdded(address indexed positionAccount, bytes32 indexed vaultId);
/// @notice Emitted when assets are borrowed from a position
/// @param borrower The borrower address
/// @param debtReserveId Borrowed reserve identifier
/// @param receiver The receiver of the borrowed assets
/// @param borrowAmount Amount of assets borrowed
event BorrowedFromPosition(
address indexed borrower, uint256 indexed debtReserveId, address indexed receiver, uint256 borrowAmount
);
/// @notice Emitted when debt is repaid from a position
/// @param borrower The borrower repaying the debt
/// @param debtReserveId Debt reserve identifier
/// @param repayAmount Amount of assets repaid
event RepaidFromPosition(address indexed borrower, uint256 indexed debtReserveId, uint256 repayAmount);
/// @notice Event emitted when the core spoke proxy implementation is updated
/// @param newImpl The new implementation address
event CoreSpokeProxyImplUpdated(address indexed newImpl);
/// @notice Event emitted when a proxy is deployed for a user
/// @param user The user for whom the proxy is deployed
/// @param proxy The address of the deployed proxy
event ProxyDeployed(address indexed user, address indexed proxy);
/// @notice Event emitted when a new user proxy is created
/// @param user The user for whom the proxy is created
/// @param proxy The address of the newly created proxy
event UserProxyCreated(address indexed user, address indexed proxy);
/// @notice Event emitted when all collateral is withdrawn from a position
/// @param positionAccount The positionAccount address
/// @param vaultId The vault id of the collateral withdrawn
event CollateralWithdrawn(address indexed positionAccount, bytes32 indexed vaultId);
/// @notice Event emitted when vault ownership is changed
/// @param vaultId The vault identifier
/// @param newOwner The new owner address
event VaultOwnershipChanged(bytes32 indexed vaultId, address indexed newOwner);
/// @notice Event emitted when fairness payment is transferred from liquidator to depositor
/// @param positionAccount The positionAccount receiving the payment
/// @param liquidator The liquidator paying the fairness amount
/// @param amount The amount transferred in the configured fairness payment token
event FairnessPaymentPaid(address indexed positionAccount, address indexed liquidator, uint256 amount);
/// @notice Event emitted when fairness payment transfer fails
/// @param positionAccount The positionAccount that should have received the payment
/// @param liquidator The liquidator who attempted to pay
/// @param protocolRecipient The protocol fee recipient
/// @param amount The amount that failed to transfer
event FairnessPaymentFailed(
address indexed positionAccount, address indexed liquidator, address protocolRecipient, uint256 amount
);
/// @notice Event emitted when a user's collateralized vaults are reordered
/// @param borrower The borrower whose vaults were reordered
/// @param newVaults The new order of vault IDs after reordering
event VaultsReordered(address indexed borrower, bytes32[] newVaults);
/// @notice Event emitted when interest fee basis points are updated
/// @param newInterestFeeBps The new interest fee in basis points
event InterestFeeUpdated(uint256 newInterestFeeBps);
/// @notice Event emitted when an LLP is registered
/// @param llp The LLP contract address
event LLPRegistered(address indexed llp);
/// @notice Event emitted when an LLP's enabled status changes
/// @param llp The LLP address
/// @param enabled Whether the LLP is now enabled
event LLPStatusChanged(address indexed llp, bool enabled);
/// @notice Event emitted when vaults are settled via an LLP
/// @param llp The LLP address used for settlement
/// @param liquidator The liquidator receiving settlement
/// @param borrower The liquidated borrower
/// @param vaultId The seized vault transferred to the LLP
event LiquidationSettledViaLLP(
address indexed llp, address indexed liquidator, address indexed borrower, bytes32 vaultId
);
/// @notice Event emitted when the liquidation fee is collected during a liquidation
/// @param token The address of the token in which the fee was collected
/// @param amount The amount of the fee collected
event LiquidationFeeCollected(address indexed token, uint256 amount);
/// @notice Event emitted when the interest fee is collected during a repayment
/// @param token The address of the token in which the fee was collected
/// @param borrower The address of the borrower who paid the fee
/// @param amount The amount of the fee collected
event InterestFeeCollected(address indexed token, address indexed borrower, uint256 amount);
/// @notice Emitted when a position account is bound to its resolver during its first resolver-based activation
/// @dev Emitted once per position account; the binding is never cleared or rewritten
/// @param resolver The registered resolver the position account is bound to
/// @param positionAccount The position account that was bound
event ResolverPositionAccountBound(address indexed resolver, address indexed positionAccount);
/// @notice Event emitted for each vault liquidated in a BTCVaultCoreSpoke liquidation
/// @param proxyContract The liquidated borrower's position proxy
/// @param vaultId The vault ID that was liquidated
/// @param debtReserveId Spoke reserve ID of the debt that was repaid
/// @param liquidator The liquidator that executed the liquidation call
/// @param amountDebtTokenConsumed Debt token the Spoke consumed; unspent input was refunded
/// @param amountCollateralSeized VaultBTC seized, always the vault's full BTC amount
/// @param liquidationBonus Bonus the Spoke applied, in BPS where 100_00 is no bonus
/// @param liquidationFee Liquidation fee owed to the application recipient
/// @param fairnessPayment Fairness payment owed to the borrower; zero amount if the Spoke seized the
/// full vault
event VaultLiquidated(
address indexed proxyContract,
bytes32 indexed vaultId,
uint256 indexed debtReserveId,
address liquidator,
uint256 amountDebtTokenConsumed,
uint256 amountCollateralSeized,
uint256 liquidationBonus,
TokenAmountLib.TokenAmount liquidationFee,
TokenAmountLib.TokenAmount fairnessPayment
);
}
src/applications/aave/lib/types/TokenAmountLib.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
/**
* @title TokenAmountLib
* @notice Library providing the TokenAmount struct for internal debt snapshots, and the
* accumulator used to collapse per-reserve amounts into per-token totals
*/
library TokenAmountLib {
/// @notice Represents a token address paired with an amount
/// @param token The ERC-20 token address
/// @param amount The token amount (in the token's native decimals)
struct TokenAmount {
address token;
uint256 amount;
}
/// @notice Accumulate `amount` under `token`, merging into the existing entry when present
/// @dev Appends at the end, so entries stay in first-appearance order. Callers must use the
/// returned array: the append path allocates a new one, while the merge path returns `arr`
/// itself. `arr` is never left stale, but it is not left untouched either — both paths
/// write through to the caller's structs, since memory-to-memory struct assignment copies
/// the pointer rather than the value. Reassign in place (`x = x.add(...)`) and do not keep
/// a second reference to `arr` expecting it to hold the pre-call amounts.
/// Each new token reallocates and copies, so this is quadratic in the number of distinct
/// tokens; it is sized for the handful of reserves one liquidation selects.
/// @param arr Entries accumulated so far
/// @param token The ERC-20 token to accumulate under
/// @param amount Amount to add to that token's running total
/// @return The accumulated entries, including `token`
function add(TokenAmount[] memory arr, address token, uint256 amount) internal pure returns (TokenAmount[] memory) {
for (uint256 i = 0; i < arr.length; ++i) {
if (arr[i].token == token) {
arr[i].amount += amount;
return arr;
}
}
TokenAmount[] memory result = new TokenAmount[](arr.length + 1);
for (uint256 i = 0; i < arr.length; ++i) {
result[i] = arr[i];
}
result[result.length - 1] = TokenAmount({token: token, amount: amount});
return result;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"vault-contracts/=src/",
"aave-v4/=lib/aave-v4/src/",
"lib/aave-v4/:src/=lib/aave-v4/src/",
"lib/aave-v4/:src/=lib/aave-v4/src/",
"src/access/=lib/aave-v4/src/access/",
"src/config-engine/=lib/aave-v4/src/config-engine/",
"src/dependencies/=lib/aave-v4/src/dependencies/",
"src/deployments/=lib/aave-v4/src/deployments/",
"src/hub/=lib/aave-v4/src/hub/",
"src/libraries/=lib/aave-v4/src/libraries/",
"src/position-manager/=lib/aave-v4/src/position-manager/",
"src/spoke/=lib/aave-v4/src/spoke/",
"src/utils/=lib/aave-v4/src/utils/",
"src/interfaces/IExtSload.sol=lib/aave-v4/src/interfaces/IExtSload.sol",
"src/interfaces/IIntentConsumer.sol=lib/aave-v4/src/interfaces/IIntentConsumer.sol",
"src/interfaces/IMulticall.sol=lib/aave-v4/src/interfaces/IMulticall.sol",
"src/interfaces/INoncesKeyed.sol=lib/aave-v4/src/interfaces/INoncesKeyed.sol",
"src/interfaces/IRescuable.sol=lib/aave-v4/src/interfaces/IRescuable.sol",
"elliptic-curve-solidity/=lib/elliptic-curve-solidity/",
"erc4626-tests/=lib/aave-v4/lib/erc4626-tests/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.