High-level Aave V3 Pool read and write operations.
Read operations compose Address, Contracts, ABI, RPC, and Math
into single-call functions that return converted Decimal values.
Write operations validate inputs, ABI-encode calldata, and delegate to
Signer.send_transaction/3. Gas limits are NOT defaulted per operation —
Aave ops typically need more than Signer's default 100k (supply ~200k,
borrow ~300k). Specify via :gas_limit in opts.
Error Format
Errors pass through from the underlying module that failed:
| Source | Error Shape |
|---|---|
Onchain.Address.validate/1 | {:error, {:invalid_address, input}} |
Onchain.Aave.Contracts.address/2 | {:error, {:unsupported_network, network}} |
Onchain.ABI.encode_call/2 | {:error, {:encode_error, reason}} |
Onchain.RPC.eth_call/3 | {:error, {:rpc_error, map}} |
Onchain.ABI.decode_response/2 | {:error, {:decode_error, reason}} |
Onchain.Signer.send_transaction/3 | {:error, {:missing_option, ...}}, {:error, {:sign_error, ...}}, etc. |
| Interest rate mode validation | {:error, {:invalid_interest_rate_mode, value}} |
Functions
| Function | Purpose |
|---|---|
get_user_account_data/2 | Full position summary as UserAccountData struct |
get_user_account_data!/2 | Same, raises on error |
get_user_account_data_many/2 | Batch many users' positions in one Multicall3 round-trip |
get_user_account_data_many!/2 | Same, raises on error |
supply/4 | Supply asset to pool (returns tx hash) |
supply!/4 | Same, raises on error |
withdraw/4 | Withdraw asset from pool (returns tx hash) |
withdraw!/4 | Same, raises on error |
borrow/4 | Borrow asset from pool (returns tx hash) |
borrow!/4 | Same, raises on error |
repay/4 | Repay borrowed asset (returns tx hash) |
repay!/4 | Same, raises on error |
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
repay! | 4 | Repay a borrowed asset to the Aave V3 Pool. Raises on error. | asset: value, amount: value, on_behalf_of: value, opts: value |
repay | 4 | Repay a borrowed asset to the Aave V3 Pool. | asset: value, amount: value, on_behalf_of: value, opts: value |
borrow! | 4 | Borrow an asset from the Aave V3 Pool. Raises on error. | asset: value, amount: value, on_behalf_of: value, opts: value |
borrow | 4 | Borrow an asset from the Aave V3 Pool. | asset: value, amount: value, on_behalf_of: value, opts: value |
withdraw! | 4 | Withdraw an asset from the Aave V3 Pool. Raises on error. | asset: value, amount: value, to: value, opts: value |
withdraw | 4 | Withdraw an asset from the Aave V3 Pool. | asset: value, amount: value, to: value, opts: value |
supply! | 4 | Supply an asset to the Aave V3 Pool. Raises on error. | asset: value, amount: value, on_behalf_of: value, opts: value |
supply | 4 | Supply an asset to the Aave V3 Pool. | asset: value, amount: value, on_behalf_of: value, opts: value |
get_user_account_data_many! | 2 | Batch-fetch many users' Aave V3 positions in one round-trip. Raises on error. | user_addresses: value, opts: value |
get_user_account_data_many | 2 | Batch-fetch many users' Aave V3 positions in a single Multicall3 round-trip. | user_addresses: value, opts: value |
get_user_account_data! | 2 | Fetch a user's full Aave V3 position. Raises on error. | user_address: value, opts: value |
get_user_account_data | 2 | Fetch a user's full Aave V3 position as converted Decimal values. | user_address: value, opts: value |
Summary
Functions
Borrow an asset from the Aave V3 Pool.
Borrow an asset from the Aave V3 Pool. Raises on error.
Fetch a user's full Aave V3 position as converted Decimal values.
Fetch a user's full Aave V3 position. Raises on error.
Batch-fetch many users' Aave V3 positions in a single Multicall3 round-trip.
Batch-fetch many users' Aave V3 positions in one round-trip. Raises on error.
Repay a borrowed asset to the Aave V3 Pool.
Repay a borrowed asset to the Aave V3 Pool. Raises on error.
Supply an asset to the Aave V3 Pool.
Supply an asset to the Aave V3 Pool. Raises on error.
Withdraw an asset from the Aave V3 Pool.
Withdraw an asset from the Aave V3 Pool. Raises on error.
Functions
@spec borrow( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: {:ok, String.t()} | {:error, term()}
Borrow an asset from the Aave V3 Pool.
Parameters
asset- ERC-20 token contract address to borrow (value)amount- Amount to borrow (raw integer, not decimal-adjusted) (value)on_behalf_of- Address that incurs the debt (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~300k for borrow) (value)
Returns
Transaction hash hex string ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~300k for borrow)",
kind: :value
},
amount: %{
description: "Amount to borrow (raw integer, not decimal-adjusted)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to borrow",
kind: :value
},
on_behalf_of: %{description: "Address that incurs the debt", kind: :value}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Transaction hash hex string"
}
}
@spec borrow!( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: String.t()
Borrow an asset from the Aave V3 Pool. Raises on error.
Parameters
asset- ERC-20 token contract address to borrow (value)amount- Amount to borrow (raw integer, not decimal-adjusted) (value)on_behalf_of- Address that incurs the debt (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~300k for borrow) (value)
Returns
Transaction hash hex string (string)
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~300k for borrow)",
kind: :value
},
amount: %{
description: "Amount to borrow (raw integer, not decimal-adjusted)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to borrow",
kind: :value
},
on_behalf_of: %{description: "Address that incurs the debt", kind: :value}
},
returns: %{type: :string, description: "Transaction hash hex string"}
}
@spec get_user_account_data( String.t() | binary(), keyword() ) :: {:ok, Onchain.Aave.Types.UserAccountData.t()} | {:error, term()}
Fetch a user's full Aave V3 position as converted Decimal values.
Parameters
user_address- User address as 0x hex string or 20-byte binary (value)opts- Options: :network (default :ethereum), :rpc_url, :timeout, :block (default:[], value)
Returns
UserAccountData struct with Decimal values for collateral, debt, borrows, thresholds, and health factor ({:ok, UserAccountData.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
kind: :value
},
user_address: %{
description: "User address as 0x hex string or 20-byte binary",
kind: :value
}
},
returns: %{
type: "{:ok, UserAccountData.t()} | {:error, term()}",
description: "UserAccountData struct with Decimal values for collateral, debt, borrows, thresholds, and health factor",
example: "%UserAccountData{total_collateral_base: Decimal.new(\"1234.56\"), health_factor: Decimal.new(\"1.5\"), ...}"
}
}
@spec get_user_account_data!( String.t() | binary(), keyword() ) :: Onchain.Aave.Types.UserAccountData.t()
Fetch a user's full Aave V3 position. Raises on error.
Parameters
user_address- User address as 0x hex string or 20-byte binary (value)opts- Options: :network (default :ethereum), :rpc_url, :timeout, :block (default:[], value)
Returns
UserAccountData struct with Decimal values for collateral, debt, borrows, thresholds, and health factor (UserAccountData.t())
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
kind: :value
},
user_address: %{
description: "User address as 0x hex string or 20-byte binary",
kind: :value
}
},
returns: %{
type: "UserAccountData.t()",
description: "UserAccountData struct with Decimal values for collateral, debt, borrows, thresholds, and health factor"
}
}
@spec get_user_account_data_many( [String.t() | binary()], keyword() ) :: {:ok, [Onchain.Aave.Types.UserAccountData.t()]} | {:error, term()}
Batch-fetch many users' Aave V3 positions in a single Multicall3 round-trip.
Parameters
user_addresses- List of user addresses as 0x hex strings or 20-byte binaries (value)opts- Options: :network (default :ethereum), :rpc_url, :timeout, :block (default:[], value)
Returns
List of UserAccountData structs aligned positionally with the input. Empty input returns {:ok, []} with no RPC call. ({:ok, [UserAccountData.t()]} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
kind: :value
},
user_addresses: %{
description: "List of user addresses as 0x hex strings or 20-byte binaries",
kind: :value
}
},
returns: %{
type: "{:ok, [UserAccountData.t()]} | {:error, term()}",
description: "List of UserAccountData structs aligned positionally with the input. Empty input returns {:ok, []} with no RPC call."
}
}
@spec get_user_account_data_many!( [String.t() | binary()], keyword() ) :: [Onchain.Aave.Types.UserAccountData.t()]
Batch-fetch many users' Aave V3 positions in one round-trip. Raises on error.
Parameters
user_addresses- List of user addresses as 0x hex strings or 20-byte binaries (value)opts- Options: :network (default :ethereum), :rpc_url, :timeout, :block (default:[], value)
Returns
List of UserAccountData structs aligned positionally with the input ([UserAccountData.t()])
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
kind: :value
},
user_addresses: %{
description: "List of user addresses as 0x hex strings or 20-byte binaries",
kind: :value
}
},
returns: %{
type: "[UserAccountData.t()]",
description: "List of UserAccountData structs aligned positionally with the input"
}
}
@spec repay( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: {:ok, String.t()} | {:error, term()}
Repay a borrowed asset to the Aave V3 Pool.
Parameters
asset- ERC-20 token contract address to repay (value)amount- Amount to repay (raw integer, or max uint256 for full debt) (value)on_behalf_of- Address whose debt is being repaid (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~200k for repay) (value)
Returns
Transaction hash hex string ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~200k for repay)",
kind: :value
},
amount: %{
description: "Amount to repay (raw integer, or max uint256 for full debt)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to repay",
kind: :value
},
on_behalf_of: %{
description: "Address whose debt is being repaid",
kind: :value
}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Transaction hash hex string"
}
}
@spec repay!( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: String.t()
Repay a borrowed asset to the Aave V3 Pool. Raises on error.
Parameters
asset- ERC-20 token contract address to repay (value)amount- Amount to repay (raw integer, or max uint256 for full debt) (value)on_behalf_of- Address whose debt is being repaid (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~200k for repay) (value)
Returns
Transaction hash hex string (string)
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :interest_rate_mode (:variable default, :stable), :gas_limit (recommend ~200k for repay)",
kind: :value
},
amount: %{
description: "Amount to repay (raw integer, or max uint256 for full debt)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to repay",
kind: :value
},
on_behalf_of: %{
description: "Address whose debt is being repaid",
kind: :value
}
},
returns: %{type: :string, description: "Transaction hash hex string"}
}
@spec supply( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: {:ok, String.t()} | {:error, term()}
Supply an asset to the Aave V3 Pool.
Parameters
asset- ERC-20 token contract address to supply (value)amount- Amount to supply (raw integer, not decimal-adjusted) (value)on_behalf_of- Address that receives the aTokens (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for supply) (value)
Returns
Transaction hash hex string ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for supply)",
kind: :value
},
amount: %{
description: "Amount to supply (raw integer, not decimal-adjusted)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to supply",
kind: :value
},
on_behalf_of: %{
description: "Address that receives the aTokens",
kind: :value
}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Transaction hash hex string"
}
}
@spec supply!( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: String.t()
Supply an asset to the Aave V3 Pool. Raises on error.
Parameters
asset- ERC-20 token contract address to supply (value)amount- Amount to supply (raw integer, not decimal-adjusted) (value)on_behalf_of- Address that receives the aTokens (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for supply) (value)
Returns
Transaction hash hex string (string)
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for supply)",
kind: :value
},
amount: %{
description: "Amount to supply (raw integer, not decimal-adjusted)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to supply",
kind: :value
},
on_behalf_of: %{
description: "Address that receives the aTokens",
kind: :value
}
},
returns: %{type: :string, description: "Transaction hash hex string"}
}
@spec withdraw( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: {:ok, String.t()} | {:error, term()}
Withdraw an asset from the Aave V3 Pool.
Parameters
asset- ERC-20 token contract address to withdraw (value)amount- Amount to withdraw (raw integer, or max uint256 for full balance) (value)to- Address that receives the withdrawn tokens (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for withdraw) (value)
Returns
Transaction hash hex string ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for withdraw)",
kind: :value
},
to: %{
description: "Address that receives the withdrawn tokens",
kind: :value
},
amount: %{
description: "Amount to withdraw (raw integer, or max uint256 for full balance)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to withdraw",
kind: :value
}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Transaction hash hex string"
}
}
@spec withdraw!( String.t() | binary(), non_neg_integer(), String.t() | binary(), keyword() ) :: String.t()
Withdraw an asset from the Aave V3 Pool. Raises on error.
Parameters
asset- ERC-20 token contract address to withdraw (value)amount- Amount to withdraw (raw integer, or max uint256 for full balance) (value)to- Address that receives the withdrawn tokens (value)opts- Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for withdraw) (value)
Returns
Transaction hash hex string (string)
# descripex:contract
%{
params: %{
opts: %{
description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (recommend ~200k for withdraw)",
kind: :value
},
to: %{
description: "Address that receives the withdrawn tokens",
kind: :value
},
amount: %{
description: "Amount to withdraw (raw integer, or max uint256 for full balance)",
kind: :value
},
asset: %{
description: "ERC-20 token contract address to withdraw",
kind: :value
}
},
returns: %{type: :string, description: "Transaction hash hex string"}
}