Skip to content

Commit

Permalink
Fix remote staking denom
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jun 22, 2023
1 parent 400dfac commit e799bdf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion contracts/consumer/converter/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Response, ContractError> {
nonpayable(&ctx.info)?;
Expand All @@ -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)?;

Expand Down Expand Up @@ -127,6 +132,14 @@ impl ConverterContract<'_> {
fn normalize_price(&self, deps: Deps, amount: Coin) -> Result<Coin, ContractError> {
// 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;
Expand Down
3 changes: 3 additions & 0 deletions contracts/consumer/converter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
5 changes: 4 additions & 1 deletion contracts/consumer/converter/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit e799bdf

Please sign in to comment.