Skip to content

Commit

Permalink
use transmuter math crate in transmuter
Browse files Browse the repository at this point in the history
  • Loading branch information
iboss-ptk committed Sep 10, 2024
1 parent 630ead2 commit 13b8ae5
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 1,243 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/transmuter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ schemars = "0.8.12"
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"}

[dev-dependencies]
itertools = "0.12.0"
Expand Down
16 changes: 8 additions & 8 deletions contracts/transmuter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod key {
#[sv::error(ContractError)]
impl Transmuter<'_> {
/// Create a Transmuter instance.
pub const fn new() -> Self {
pub const fn default() -> Self {
Self {
active_status: Item::new(key::ACTIVE_STATUS),
pool: Item::new(key::POOL),
Expand Down Expand Up @@ -1069,7 +1069,7 @@ mod tests {
for denom in ["uosmo", "uion"] {
assert_dirty_change_limiters_by_denom!(
denom,
Transmuter::new().limiters,
Transmuter::default().limiters,
deps.as_ref().storage
);
}
Expand Down Expand Up @@ -1135,7 +1135,7 @@ mod tests {
execute(deps.as_mut(), env.clone(), info, add_assets_msg).unwrap();

let reset_at = env.block.time;
let transmuter = Transmuter::new();
let transmuter = Transmuter::default();

// Reset change limiter states if new assets are added
for denom in ["uosmo", "uion"] {
Expand Down Expand Up @@ -1611,7 +1611,7 @@ mod tests {
);

assert_eq!(
Transmuter::new()
Transmuter::default()
.limiters
.list_limiters_by_denom(&deps.storage, "wbtc")
.unwrap(),
Expand All @@ -1622,7 +1622,7 @@ mod tests {
assert_reset_change_limiters_by_denom!(
denom,
env.block.time,
Transmuter::new(),
Transmuter::default(),
deps.as_ref().storage
);
}
Expand Down Expand Up @@ -1717,7 +1717,7 @@ mod tests {

// still has all the limiters
assert_eq!(
Transmuter::new()
Transmuter::default()
.limiters
.list_limiters_by_denom(&deps.storage, "tbtc")
.unwrap()
Expand All @@ -1739,7 +1739,7 @@ mod tests {
}

fn total_liquidity_of(denom: &str, storage: &dyn Storage) -> Coin {
Transmuter::new()
Transmuter::default()
.pool
.load(storage)
.unwrap()
Expand Down Expand Up @@ -1779,7 +1779,7 @@ mod tests {
// Manually set alloyed denom
let alloyed_denom = "uosmo".to_string();

let transmuter = Transmuter::new();
let transmuter = Transmuter::default();
transmuter
.alloyed_asset
.set_alloyed_denom(&mut deps.storage, &alloyed_denom)
Expand Down
3 changes: 3 additions & 0 deletions contracts/transmuter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ pub enum ContractError {
#[error("{0}")]
MathError(#[from] MathError),

#[error("{0}")]
TrasnmuterMathError(#[from] transmuter_math::TransmuterMathError),

/// This error should never occur
#[error("")]
Never,
Expand Down
2 changes: 1 addition & 1 deletion contracts/transmuter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod entry_points {
use crate::migrations;
use crate::sudo::SudoMsg;

const CONTRACT: Transmuter = Transmuter::new();
const CONTRACT: Transmuter = Transmuter::default();

macro_rules! ensure_active_status {
($msg:expr, $deps:expr, $env:expr, except: $pattern:pat) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::collections::HashMap;

use crate::ContractError;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{ensure, Decimal, StdError, Storage, Timestamp, Uint64};
use cw_storage_plus::Map;

use crate::ContractError;

use super::division::Division;
use transmuter_math::Division;

/// Maximum number of divisions allowed in a window.
/// This limited so that the contract can't be abused by setting a large division count,
Expand Down Expand Up @@ -617,7 +615,7 @@ macro_rules! assert_reset_change_limiters_by_denom {
let value = *weights.get($denom).unwrap();
assert_eq!(
limiter.divisions(),
&[$crate::limiter::Division::new($reset_at, $reset_at, value, value).unwrap()]
&[transmuter_math::Division::new($reset_at, $reset_at, value, value).unwrap()]
)
};
}
Expand Down
Loading

0 comments on commit 13b8ae5

Please sign in to comment.