Skip to content

Oracle Adapter #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions framework/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions framework/packages/standards/oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
description = "The oracle adapter is a Abstract adapter for querying oracle prices. It provides a common interface for all oracles"
name = "abstract-oracle-standard"

authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
version = { workspace = true }

exclude = ["contract.wasm", "hash.txt"]
resolver = "2"


[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["export"]
export = []

# Keep as is until TendermintStake updates.
[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-asset = { workspace = true }
thiserror = { workspace = true }

abstract-adapter = { version = "0.26.0", path = "../../abstract-adapter" }
abstract-adapter-utils = { workspace = true }
abstract-sdk = { workspace = true }
abstract-std = { workspace = true }
cw-orch = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
workspace-hack = { version = "0.1", path = "../../../workspace-hack" }

[dev-dependencies]
abstract-interface = { workspace = true, features = ["daemon"] }
abstract-sdk = { workspace = true, features = ["test-utils"] }
abstract-testing = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true }
dotenv = "0.15.0"
env_logger = "0.11.3"
semver = { workspace = true }
5 changes: 5 additions & 0 deletions framework/packages/standards/oracle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Oracle Adapter Trait

A trait that defines a standard interface for Oracle interactions. This trait should be implemented for each Oracle that the adapter supports.

To implement this trait, create a new package, import this crate and implement the trait for your Oracle.
22 changes: 22 additions & 0 deletions framework/packages/standards/oracle/src/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use abstract_adapter_utils::identity::Identify;
use abstract_sdk::feature_objects::AnsHost;
use cosmwasm_std::{Deps, Env};

use crate::error::OracleError;
use crate::msg::{PriceResponse, Seconds};

/// # OracleCommand
/// ensures Oracle adapters support the expected functionality.
///
/// Implements the usual Oracle operations.
pub trait OracleCommand: Identify {
/// Return oracle price given pair id
fn price(
&self,
deps: Deps,
env: &Env,
ans_host: &AnsHost,
price_id: String,
no_older_than: Seconds,
) -> Result<PriceResponse, OracleError>;
}
60 changes: 60 additions & 0 deletions framework/packages/standards/oracle/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use abstract_adapter::AdapterError;
use abstract_sdk::AbstractSdkError;
use abstract_std::{objects::ans_host::AnsHostError, AbstractError};
use cosmwasm_std::StdError;
use cw_asset::AssetError;
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum OracleError {
#[error(transparent)]
Std(#[from] StdError),

#[error(transparent)]
AbstractOs(#[from] AbstractError),

#[error(transparent)]
AbstractSdk(#[from] AbstractSdkError),

#[error(transparent)]
Asset(#[from] AssetError),

#[error(transparent)]
AdapterError(#[from] AdapterError),

#[error(transparent)]
AnsHostError(#[from] AnsHostError),

#[error("Oracle {0} is not a known oracle on this network.")]
UnknownOracle(String),

#[error("Oracle {0} is not local to this network.")]
ForeignOracle(String),

#[error("Asset type: {0} is unsupported.")]
UnsupportedAssetType(String),

#[error("Can't provide liquidity with less than two assets")]
TooFewAssets {},

#[error("Can't provide liquidity with more than {0} assets")]
TooManyAssets(u8),

#[error("Provided asset {0} not in pool with assets {1:?}.")]
ArgumentMismatch(String, Vec<String>),

#[error("Not implemented for oracle {0}")]
NotImplemented(String),

#[error("Message generation for IBC queries not supported.")]
IbcMsgQuery,

#[error("Invalid Generate Message")]
InvalidGenerateMessage,

#[error("Pool address not specified. You need to specify it when using raw asset addresses or denom")]
PoolAddressEmpty,

#[error("Only account of abstract namespace can update configuration")]
Unauthorized {},
}
11 changes: 11 additions & 0 deletions framework/packages/standards/oracle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod command;
mod error;

pub mod msg;

// Export interface for use in SDK modules
pub use abstract_adapter_utils::{coins_in_assets, cw_approve_msgs, Identify};
pub use command::OracleCommand;
pub use error::OracleError;

pub const ORACLE_ADAPTER_ID: &str = "abstract:oracle";
48 changes: 48 additions & 0 deletions framework/packages/standards/oracle/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#![warn(missing_docs)]
//! # Oracle Adapter API
// re-export response types
use abstract_std::adapter;
use cosmwasm_schema::QueryResponses;
use cosmwasm_std::{Decimal, Empty};

/// The name of the oracle to query prices from.
pub type OracleName = String;

/// Top-level Abstract Adapter execute message. This is the message that is passed to the `execute` entrypoint of the smart-contract.
pub type ExecuteMsg = adapter::ExecuteMsg<Empty>;
/// Top-level Abstract Adapter instantiate message. This is the message that is passed to the `instantiate` entrypoint of the smart-contract.
pub type InstantiateMsg = adapter::InstantiateMsg<Empty>;
/// Top-level Abstract Adapter query message. This is the message that is passed to the `query` entrypoint of the smart-contract.
pub type QueryMsg = adapter::QueryMsg<OracleQueryMsg>;

impl adapter::AdapterQueryMsg for OracleQueryMsg {}

/// Query messages for the oracle adapter
#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses, cw_orch::QueryFns)]
pub enum OracleQueryMsg {
/// Query the latest price attached to the price source key
#[returns(PriceResponse)]
Price {
/// Identifier of the oracle value that you wish to query on the oracle
price_source_key: String,
/// Identifier of the oracle
oracle: OracleName,
/// Maximum age of the price
max_age: Seconds,
},
}

/// Alias to document time unit the oracle adapter expects data to be in.
pub type Seconds = u64;

/// Price Response returned by an adapter query
#[cosmwasm_schema::cw_serde]
pub struct PriceResponse {
/// Price response
pub price: Decimal,
}

/// No Config for this adapter
#[cosmwasm_schema::cw_serde]
pub struct Config {}
Loading
Loading