Onchain.Aave.Pool (onchain_aave v0.2.0)

Copy Markdown View Source

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:

SourceError 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

FunctionPurpose
get_user_account_data/2Full position summary as UserAccountData struct
get_user_account_data!/2Same, raises on error
get_user_account_data_many/2Batch many users' positions in one Multicall3 round-trip
get_user_account_data_many!/2Same, raises on error
supply/4Supply asset to pool (returns tx hash)
supply!/4Same, raises on error
withdraw/4Withdraw asset from pool (returns tx hash)
withdraw!/4Same, raises on error
borrow/4Borrow asset from pool (returns tx hash)
borrow!/4Same, raises on error
repay/4Repay borrowed asset (returns tx hash)
repay!/4Same, raises on error

API Functions

FunctionArityDescriptionParam Kinds
repay!4Repay a borrowed asset to the Aave V3 Pool. Raises on error.asset: value, amount: value, on_behalf_of: value, opts: value
repay4Repay a borrowed asset to the Aave V3 Pool.asset: value, amount: value, on_behalf_of: value, opts: value
borrow!4Borrow an asset from the Aave V3 Pool. Raises on error.asset: value, amount: value, on_behalf_of: value, opts: value
borrow4Borrow an asset from the Aave V3 Pool.asset: value, amount: value, on_behalf_of: value, opts: value
withdraw!4Withdraw an asset from the Aave V3 Pool. Raises on error.asset: value, amount: value, to: value, opts: value
withdraw4Withdraw an asset from the Aave V3 Pool.asset: value, amount: value, to: value, opts: value
supply!4Supply an asset to the Aave V3 Pool. Raises on error.asset: value, amount: value, on_behalf_of: value, opts: value
supply4Supply an asset to the Aave V3 Pool.asset: value, amount: value, on_behalf_of: value, opts: value
get_user_account_data_many!2Batch-fetch many users' Aave V3 positions in one round-trip. Raises on error.user_addresses: value, opts: value
get_user_account_data_many2Batch-fetch many users' Aave V3 positions in a single Multicall3 round-trip.user_addresses: value, opts: value
get_user_account_data!2Fetch a user's full Aave V3 position. Raises on error.user_address: value, opts: value
get_user_account_data2Fetch 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

borrow(asset, amount, on_behalf_of, opts)

@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"
  }
}

borrow!(asset, amount, on_behalf_of, opts)

@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"}
}

get_user_account_data(user_address, opts \\ [])

@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\"), ...}"
  }
}

get_user_account_data!(user_address, opts \\ [])

@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"
  }
}

get_user_account_data_many(user_addresses, opts \\ [])

@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."
  }
}

get_user_account_data_many!(user_addresses, opts \\ [])

@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"
  }
}

repay(asset, amount, on_behalf_of, opts)

@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"
  }
}

repay!(asset, amount, on_behalf_of, opts)

@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"}
}

supply(asset, amount, on_behalf_of, opts)

@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"
  }
}

supply!(asset, amount, on_behalf_of, opts)

@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"}
}

withdraw(asset, amount, to, opts)

@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"
  }
}

withdraw!(asset, amount, to, opts)

@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"}
}