Skip to content

Commit

Permalink
Add price orable utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
dowlandaiello committed Jun 28, 2024
1 parent b79a9ca commit 5114992
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 19 deletions.
6 changes: 3 additions & 3 deletions examples/configs/logs.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"start_time": 1719561389,
"start_time": 1719573012,
"chains": [
{
"chain_id": "localcosmos-1",
"chain_name": "localcosmos-1",
"rpc_address": "http://0.0.0.0:26658",
"rest_address": "http://0.0.0.0:1318",
"grpc_address": "0.0.0.0:9091",
"p2p_address": "0.0.0.0:35399",
"p2p_address": "0.0.0.0:45505",
"ibc_paths": []
},
{
Expand All @@ -16,7 +16,7 @@
"rpc_address": "http://0.0.0.0:26657",
"rest_address": "http://0.0.0.0:1317",
"grpc_address": "0.0.0.0:9090",
"p2p_address": "0.0.0.0:37205",
"p2p_address": "0.0.0.0:45843",
"ibc_paths": []
}
],
Expand Down
Binary file added examples/contracts/price_oracle.wasm
Binary file not shown.
31 changes: 20 additions & 11 deletions examples/neutron.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cosmwasm_std::Decimal;
use localic_utils::{types::contract::MinAmount, ConfigChainBuilder, TestContextBuilder};
use std::error::Error;

Expand All @@ -23,6 +24,15 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_subdenom("amoguscoin")
.send()?;

let bruhtoken = ctx.get_tokenfactory_denom(
"neutron1kuf2kxwuv2p8k3gnpja7mzf05zvep0cyuy7mxg",
"bruhtoken",
);
let amoguscoin = ctx.get_tokenfactory_denom(
"neutron1kuf2kxwuv2p8k3gnpja7mzf05zvep0cyuy7mxg",
"amoguscoin",
);

// Deploy valence auctions
ctx.build_tx_create_auctions_manager()
.with_min_auction_amount(&[(
Expand All @@ -32,16 +42,15 @@ fn main() -> Result<(), Box<dyn Error>> {
start_auction: "0".into(),
},
)])
.with_server_addr("neutron1kuf2kxwuv2p8k3gnpja7mzf05zvep0cyuy7mxg")
.send()?;

let bruhtoken = ctx.get_tokenfactory_denom(
"neutron1kuf2kxwuv2p8k3gnpja7mzf05zvep0cyuy7mxg",
"bruhtoken",
);
let amoguscoin = ctx.get_tokenfactory_denom(
"neutron1kuf2kxwuv2p8k3gnpja7mzf05zvep0cyuy7mxg",
"amoguscoin",
);
ctx.build_tx_create_price_oracle().send()?;
ctx.build_tx_manual_oracle_price_update()
.with_offer_asset("untrn")
.with_ask_asset(amoguscoin.as_str())
.with_price(Decimal::percent(10))
.send()?;
ctx.build_tx_update_auction_oracle().send()?;

ctx.build_tx_mint_tokenfactory_token()
.with_denom(bruhtoken.as_str())
Expand Down Expand Up @@ -124,8 +133,8 @@ fn main() -> Result<(), Box<dyn Error>> {
ctx.build_tx_fund_pool()
.with_denom_a("untrn")
.with_denom_b(amoguscoin)
.with_amount_denom_a(1000)
.with_amount_denom_b(1000)
.with_amount_denom_a(10000)
.with_amount_denom_b(10000)
.with_liq_token_receiver("neutron1kuf2kxwuv2p8k3gnpja7mzf05zvep0cyuy7mxg")
.send()?;

Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum Error {
MissingContextVariable(String),
#[error("the builder is missing a parameter `{0}`")]
MissingBuilderParam(String),
#[error("the transaction failed: `{0}`")]
TxFailed(String),
#[error("the transaction {hash:?} failed: {error:?}")]
TxFailed { hash: String, error: String },
#[error("the transaction has no logs")]
TxMissingLogs,
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const PAIR_NAME: &str = "astroport_pair";
pub const STABLE_PAIR_NAME: &str = "astroport_pair_stable";
pub const TOKEN_NAME: &str = "cw20_base";
pub const WHITELIST_NAME: &str = "astroport_whitelist";
pub const PRICE_ORACLE_NAME: &str = "price_oracle";

/// Local ic info
pub const LOCAL_IC_API_URL: &str = "http://localhost:42069/";
Expand Down
37 changes: 35 additions & 2 deletions src/utils/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
super::{
error::Error, AUCTION_CONTRACT_NAME, FACTORY_NAME, NEUTRON_CHAIN_ID, PAIR_NAME,
STABLE_PAIR_NAME,
PRICE_ORACLE_NAME, STABLE_PAIR_NAME,
},
test_context::TestContext,
};
Expand All @@ -16,10 +16,25 @@ impl TestContext {
let chain = self.get_chain(chain_id);
let logs = chain.rb.query_tx_hash(hash);

let raw_log = logs
.get("raw_log")
.and_then(|raw_log| raw_log.as_str())
.ok_or(Error::TxMissingLogs)?;

if serde_json::from_str::<Value>(raw_log).is_err() {
return Err(Error::TxFailed {
hash: hash.to_owned(),
error: raw_log.to_owned(),
});
}

let logs = logs.get("events").ok_or(Error::TxMissingLogs)?;

if let Some(err) = logs.as_str() {
return Err(Error::TxFailed(err.to_owned()));
return Err(Error::TxFailed {
hash: hash.to_owned(),
error: err.to_owned(),
});
}

logs.as_array().cloned().ok_or(Error::TxMissingLogs)
Expand Down Expand Up @@ -63,6 +78,24 @@ impl TestContext {
))
}

/// Get a new CosmWasm instance for the existing deployed auctions manager.
pub fn get_price_oracle(&self) -> Result<CosmWasm, Error> {
let neutron = self.get_chain(NEUTRON_CHAIN_ID);

let mut contract = self.get_contract(PRICE_ORACLE_NAME)?;
let contract_addr = neutron
.contract_addrs
.get(PRICE_ORACLE_NAME)
.and_then(|addrs| addrs.get(0))
.cloned()
.ok_or(Error::MissingContextVariable(String::from(
"contract_addrs::price_oracle",
)))?;
contract.contract_addr = Some(contract_addr);

Ok(contract)
}

/// Gets a CosmWasm instance for an auction with a given pair.
pub fn get_auction<TDenomA: AsRef<str>, TDenomB: AsRef<str>>(
&self,
Expand Down
Loading

0 comments on commit 5114992

Please sign in to comment.