Onchain.Aave.Oracle (onchain_aave v0.2.0)

Copy Markdown View Source

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.

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:

SourceError 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

FunctionPurpose
get_asset_price/2Price of one asset in base currency units
get_asset_price!/2Same, raises on error
get_asset_prices/2Batch prices for multiple assets
get_asset_prices!/2Same, raises on error
get_source_of_asset/2Chainlink aggregator address for an asset
get_source_of_asset!/2Same, raises on error
get_base_currency/1Base currency token address
get_base_currency!/1Same, raises on error
get_base_currency_unit/1Base currency unit (10^decimals)
get_base_currency_unit!/1Same, raises on error
get_fallback_oracle/1Fallback oracle address
get_fallback_oracle!/1Same, raises on error
get_latest_round_data/2Chainlink aggregator latest round
get_latest_round_data!/2Same, raises on error

API Functions

FunctionArityDescriptionParam Kinds
get_latest_round_data!2Get the latest Chainlink round data. Raises on error.aggregator: value, opts: value
get_latest_round_data2Get the latest round data from a Chainlink aggregator.aggregator: value, opts: value
get_fallback_oracle!1Get the fallback oracle address. Raises on error.opts: value
get_fallback_oracle1Get the fallback oracle address.opts: value
get_base_currency_unit!1Get the base currency unit. Raises on error.opts: value
get_base_currency_unit1Get the base currency unit (10^decimals).opts: value
get_base_currency!1Get the base currency token address. Raises on error.opts: value
get_base_currency1Get the base currency token address.opts: value
get_source_of_asset!2Get the Chainlink aggregator address. Raises on error.asset: value, opts: value
get_source_of_asset2Get the Chainlink aggregator address for an asset.asset: value, opts: value
get_asset_prices!2Get prices for multiple assets. Raises on error.assets: value, opts: value
get_asset_prices2Get prices for multiple assets in one call.assets: value, opts: value
get_asset_price!2Get the price of an asset. Raises on error.asset: value, opts: value
get_asset_price2Get 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

get_asset_price(asset, opts \\ [])

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

get_asset_price!(asset, opts \\ [])

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

get_asset_prices(assets, opts \\ [])

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

get_asset_prices!(assets, opts \\ [])

@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_base_currency(opts \\ [])

@spec get_base_currency(keyword()) :: {:ok, String.t()} | {:error, term()}

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_base_currency!(opts \\ [])

@spec get_base_currency!(keyword()) :: String.t()

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

get_base_currency_unit(opts \\ [])

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

get_base_currency_unit!(opts \\ [])

@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_fallback_oracle(opts \\ [])

@spec get_fallback_oracle(keyword()) :: {:ok, String.t()} | {:error, term()}

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_fallback_oracle!(opts \\ [])

@spec get_fallback_oracle!(keyword()) :: String.t()

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_latest_round_data(aggregator, opts \\ [])

@spec get_latest_round_data(
  String.t() | binary(),
  keyword()
) :: {:ok, map()} | {:error, term()}

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_latest_round_data!(aggregator, opts \\ [])

@spec get_latest_round_data!(
  String.t() | binary(),
  keyword()
) :: map()

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

get_source_of_asset(asset, opts \\ [])

@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_source_of_asset!(asset, opts \\ [])

@spec get_source_of_asset!(
  String.t() | binary(),
  keyword()
) :: String.t()

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