Aave V3 Oracle and Chainlink price feed reads.
Composes Contracts, Contract, and Address into single-call functions
for fetching asset prices, Chainlink aggregator addresses, and base currency info.
Chainlink Direct Read
get_latest_round_data/2 reads directly from a Chainlink aggregator contract
(obtained via get_source_of_asset/2), bypassing the Aave oracle.
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.Contract.call/5 | {:error, {:encode_error, ...}}, {:error, {:rpc_error, ...}}, {:error, {:decode_error, ...}} |
Functions
| Function | Purpose |
|---|---|
get_asset_price/2 | Price of one asset in base currency units |
get_asset_price!/2 | Same, raises on error |
get_asset_prices/2 | Batch prices for multiple assets |
get_asset_prices!/2 | Same, raises on error |
get_source_of_asset/2 | Chainlink aggregator address for an asset |
get_source_of_asset!/2 | Same, raises on error |
get_base_currency/1 | Base currency token address |
get_base_currency!/1 | Same, raises on error |
get_base_currency_unit/1 | Base currency unit (10^decimals) |
get_base_currency_unit!/1 | Same, raises on error |
get_fallback_oracle/1 | Fallback oracle address |
get_fallback_oracle!/1 | Same, raises on error |
get_latest_round_data/2 | Chainlink aggregator latest round |
get_latest_round_data!/2 | Same, raises on error |
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
get_latest_round_data! | 2 | Get the latest Chainlink round data. Raises on error. | aggregator: value, opts: value |
get_latest_round_data | 2 | Get the latest round data from a Chainlink aggregator. | aggregator: value, opts: value |
get_fallback_oracle! | 1 | Get the fallback oracle address. Raises on error. | opts: value |
get_fallback_oracle | 1 | Get the fallback oracle address. | opts: value |
get_base_currency_unit! | 1 | Get the base currency unit. Raises on error. | opts: value |
get_base_currency_unit | 1 | Get the base currency unit (10^decimals). | opts: value |
get_base_currency! | 1 | Get the base currency token address. Raises on error. | opts: value |
get_base_currency | 1 | Get the base currency token address. | opts: value |
get_source_of_asset! | 2 | Get the Chainlink aggregator address. Raises on error. | asset: value, opts: value |
get_source_of_asset | 2 | Get the Chainlink aggregator address for an asset. | asset: value, opts: value |
get_asset_prices! | 2 | Get prices for multiple assets. Raises on error. | assets: value, opts: value |
get_asset_prices | 2 | Get prices for multiple assets in one call. | assets: value, opts: value |
get_asset_price! | 2 | Get the price of an asset. Raises on error. | asset: value, opts: value |
get_asset_price | 2 | Get the price of an asset in base currency units. | asset: value, opts: value |
Summary
Functions
Get the price of an asset in base currency units.
Get the price of an asset. Raises on error.
Get prices for multiple assets in one call.
Get prices for multiple assets. Raises on error.
Get the base currency token address.
Get the base currency token address. Raises on error.
Get the base currency unit (10^decimals).
Get the base currency unit. Raises on error.
Get the fallback oracle address.
Get the fallback oracle address. Raises on error.
Get the latest round data from a Chainlink aggregator.
Get the latest Chainlink round data. Raises on error.
Get the Chainlink aggregator address for an asset.
Get the Chainlink aggregator address. Raises on error.
Functions
@spec get_asset_price( String.t() | binary(), keyword() ) :: {:ok, non_neg_integer()} | {:error, term()}
Get the price of an asset in base currency units.
Parameters
asset- Asset address as 0x hex string or 20-byte binary (value)opts- Options: :network (default :ethereum), :rpc_url, :timeout, :block (default:[], value)
Returns
Price in base currency units (8 decimals for Aave V3 USD) ({:ok, non_neg_integer()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
kind: :value
},
asset: %{
description: "Asset address as 0x hex string or 20-byte binary",
kind: :value
}
},
returns: %{
type: "{:ok, non_neg_integer()} | {:error, term()}",
description: "Price in base currency units (8 decimals for Aave V3 USD)"
}
}
@spec get_asset_price!( String.t() | binary(), keyword() ) :: non_neg_integer()
Get the price of an asset. Raises on error.
Parameters
asset- Asset address (value)opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Price in base currency units (non_neg_integer)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
},
asset: %{description: "Asset address", kind: :value}
},
returns: %{
type: :non_neg_integer,
description: "Price in base currency units"
}
}
@spec get_asset_prices( [String.t() | binary()], keyword() ) :: {:ok, [non_neg_integer()]} | {:error, term()}
Get prices for multiple assets in one call.
Parameters
assets- List of asset addresses (value)opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
List of prices in base currency units ({:ok, [non_neg_integer()]} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
},
assets: %{description: "List of asset addresses", kind: :value}
},
returns: %{
type: "{:ok, [non_neg_integer()]} | {:error, term()}",
description: "List of prices in base currency units"
}
}
@spec get_asset_prices!( [String.t() | binary()], keyword() ) :: [non_neg_integer()]
Get prices for multiple assets. Raises on error.
Parameters
assets- List of asset addresses (value)opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
List of prices ([non_neg_integer()])
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
},
assets: %{description: "List of asset addresses", kind: :value}
},
returns: %{type: "[non_neg_integer()]", description: "List of prices"}
}
Get the base currency token address.
Parameters
opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Checksummed base currency address ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Checksummed base currency address"
}
}
Get the base currency token address. Raises on error.
Parameters
opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Checksummed base currency address (string)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
}
},
returns: %{type: :string, description: "Checksummed base currency address"}
}
@spec get_base_currency_unit(keyword()) :: {:ok, non_neg_integer()} | {:error, term()}
Get the base currency unit (10^decimals).
Parameters
opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Base currency unit (e.g. 100000000 for 8-decimal USD) ({:ok, non_neg_integer()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
}
},
returns: %{
type: "{:ok, non_neg_integer()} | {:error, term()}",
description: "Base currency unit (e.g. 100000000 for 8-decimal USD)"
}
}
@spec get_base_currency_unit!(keyword()) :: non_neg_integer()
Get the base currency unit. Raises on error.
Parameters
opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Base currency unit (non_neg_integer)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
}
},
returns: %{type: :non_neg_integer, description: "Base currency unit"}
}
Get the fallback oracle address.
Parameters
opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Checksummed fallback oracle address ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Checksummed fallback oracle address"
}
}
Get the fallback oracle address. Raises on error.
Parameters
opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Checksummed fallback oracle address (string)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
}
},
returns: %{type: :string, description: "Checksummed fallback oracle address"}
}
Get the latest round data from a Chainlink aggregator.
Parameters
aggregator- Chainlink aggregator address (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Map with :round_id, :answer, :started_at, :updated_at, :answered_in_round ({:ok, map()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
aggregator: %{description: "Chainlink aggregator address", kind: :value}
},
returns: %{
type: "{:ok, map()} | {:error, term()}",
description: "Map with :round_id, :answer, :started_at, :updated_at, :answered_in_round"
}
}
Get the latest Chainlink round data. Raises on error.
Parameters
aggregator- Chainlink aggregator address (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Round data map (map)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
aggregator: %{description: "Chainlink aggregator address", kind: :value}
},
returns: %{type: :map, description: "Round data map"}
}
@spec get_source_of_asset( String.t() | binary(), keyword() ) :: {:ok, String.t()} | {:error, term()}
Get the Chainlink aggregator address for an asset.
Parameters
asset- Asset address (value)opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Checksummed Chainlink aggregator address ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
},
asset: %{description: "Asset address", kind: :value}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Checksummed Chainlink aggregator address"
}
}
Get the Chainlink aggregator address. Raises on error.
Parameters
asset- Asset address (value)opts- Options: :network, :rpc_url, :timeout, :block (default:[], value)
Returns
Checksummed Chainlink aggregator address (string)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :network, :rpc_url, :timeout, :block",
kind: :value
},
asset: %{description: "Asset address", kind: :value}
},
returns: %{
type: :string,
description: "Checksummed Chainlink aggregator address"
}
}