From e799bdf91c2964eb3b1ff6c3dc3fb0923acea167 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 22 Jun 2023 15:34:45 +0200 Subject: [PATCH] Fix remote staking denom --- contracts/consumer/converter/src/contract.rs | 15 ++++++++++++++- contracts/consumer/converter/src/error.rs | 3 +++ contracts/consumer/converter/src/state.rs | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/contracts/consumer/converter/src/contract.rs b/contracts/consumer/converter/src/contract.rs index 0d37a610..12cb080f 100644 --- a/contracts/consumer/converter/src/contract.rs +++ b/contracts/consumer/converter/src/contract.rs @@ -1,4 +1,6 @@ -use cosmwasm_std::{to_binary, Addr, Coin, Decimal, Deps, DepsMut, Event, Response, WasmMsg}; +use cosmwasm_std::{ + ensure_eq, to_binary, Addr, Coin, Decimal, Deps, DepsMut, Event, Response, WasmMsg, +}; use cw2::set_contract_version; use cw_storage_plus::Item; use cw_utils::nonpayable; @@ -46,6 +48,7 @@ impl ConverterContract<'_> { ctx: InstantiateCtx, price_feed: String, discount: Decimal, + remote_denom: String, virtual_staking: String, // TODO: figure out to pass this in later ) -> Result { nonpayable(&ctx.info)?; @@ -54,6 +57,8 @@ impl ConverterContract<'_> { // TODO: better error if discount greater than 1 (this will panic) adjustment: Decimal::one() - discount, local_denom: ctx.deps.querier.query_bonded_denom()?, + // TODO: validation here? Just that it is non-empty? + remote_denom, }; self.config.save(ctx.deps.storage, &config)?; @@ -127,6 +132,14 @@ impl ConverterContract<'_> { fn normalize_price(&self, deps: Deps, amount: Coin) -> Result { // TODO: ensure the proper remote denom - set this in the instantiate let config = self.config.load(deps.storage)?; + ensure_eq!( + config.remote_denom, + amount.denom, + ContractError::WrongDenom { + sent: amount.denom.clone(), + expected: config.remote_denom.clone() + } + ); // get the price value (usage is a bit clunky, need use trait and cannot chain Remote::new() with .querier()) use price_feed_api::Querier; diff --git a/contracts/consumer/converter/src/error.rs b/contracts/consumer/converter/src/error.rs index 88798e49..6acaf214 100644 --- a/contracts/consumer/converter/src/error.rs +++ b/contracts/consumer/converter/src/error.rs @@ -22,4 +22,7 @@ pub enum ContractError { #[error("You must start the channel handshake on this side, it doesn't support OpenTry")] IbcOpenTryDisallowed, + + #[error("Sent wrong denom over IBC: {sent}, expected {expected}")] + WrongDenom { sent: String, expected: String }, } diff --git a/contracts/consumer/converter/src/state.rs b/contracts/consumer/converter/src/state.rs index f6d030ff..34882b06 100644 --- a/contracts/consumer/converter/src/state.rs +++ b/contracts/consumer/converter/src/state.rs @@ -15,5 +15,8 @@ pub struct Config { /// Staking denom used on this chain pub local_denom: String, - // TODO: expected remote denom for virtual staking + + /// Token being "virtually sent" over IBC. + /// use remote via, eg "uosmo", not "ibc/4EF183..." + pub remote_denom: String, }