Skip to content
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

Asset group #34

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

26 changes: 13 additions & 13 deletions contracts/transmuter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
authors = ["Supanat Potiwarakorn <supanat.ptk@gmail.com>"]
edition = "2021"
name = "transmuter"
version = "3.2.0"
version = "4.0.0"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down Expand Up @@ -42,25 +42,25 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["cosmwasm_1_1"] }
cosmwasm-schema = {workspace = true}
cosmwasm-std = {workspace = true, features = ["cosmwasm_1_1"]}
cosmwasm-storage = "1.3.1"
cw-storage-plus = "1.1.0"
cw2 = "1.1.0"
osmosis-std = "0.22.0"
schemars = "0.8.12"
serde = { version = "1.0.183", default-features = false, features = ["derive"] }
serde = {version = "1.0.183", default-features = false, features = ["derive"]}
sylvia = "0.10.1"
thiserror = { version = "1.0.44" }
transmuter_math = { version = "1.0.0", path = "../../packages/transmuter_math" }
thiserror = {version = "1.0.44"}
transmuter_math = {version = "1.0.0", path = "../../packages/transmuter_math"}

[dev-dependencies]
itertools = "0.12.0"
osmosis-test-tube = "22.1.0"
rstest = "0.18.2"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(tarpaulin)',
'cfg(tarpaulin_include)',
] }
unexpected_cfgs = {level = "warn", check-cfg = [
'cfg(tarpaulin)',
'cfg(tarpaulin_include)',
]}
32 changes: 17 additions & 15 deletions contracts/transmuter/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{ensure, Coin, Deps, StdError, Uint128, Uint256};

use crate::ContractError;
use crate::{corruptable::Corruptable, ContractError};

#[derive(PartialEq)]
pub enum Rounding {
Expand Down Expand Up @@ -121,16 +121,6 @@ impl Asset {
Ok(self)
}

pub fn mark_as_corrupted(&'_ mut self) -> &'_ Self {
self.is_corrupted = true;
self
}

pub fn unmark_as_corrupted(&'_ mut self) -> &'_ Self {
self.is_corrupted = false;
self
}

pub fn denom(&self) -> &str {
&self.denom
}
Expand All @@ -143,10 +133,6 @@ impl Asset {
self.normalization_factor
}

pub fn is_corrupted(&self) -> bool {
self.is_corrupted
}

pub fn config(&self) -> AssetConfig {
AssetConfig {
denom: self.denom.clone(),
Expand Down Expand Up @@ -188,6 +174,22 @@ impl Asset {
}
}

impl Corruptable for Asset {
fn is_corrupted(&self) -> bool {
self.is_corrupted
}

fn mark_as_corrupted(&mut self) -> &mut Self {
self.is_corrupted = true;
self
}

fn unmark_as_corrupted(&mut self) -> &mut Self {
self.is_corrupted = false;
self
}
}

/// Convert amount to target asset's amount with the same value
///
/// target_amount / target_normalization_factor = amount / source_normalization_factor
Expand Down
Loading
Loading