Skip to content

Commit

Permalink
use Decimal256 for price math (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
GadAlmighty authored Jun 24, 2023
1 parent b565bd2 commit 09a8d43
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
8176c2def61ee98c1ccac03e7133712699a0937c8157e224cf3fa1075c7d4e18 dca.wasm
5d26718b58db2fd17b79e8ce80b3575639d67f403c173f77a5f8c045d61d7d4e dca.wasm
82349334afdc60e4ce6b812d830cdb174396c9f02c64d8d1ef3c46370c6ecb16 fin.wasm
7dfbd4ad52105a1ff5172895f0e5eaebef6d348a0b6c224c72dc11d64005655d osmosis.wasm
2 changes: 1 addition & 1 deletion artifacts/checksums_intermediate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
06fee1cc1cb7520e4e3d49c4a0403518d1e323184cb09daebef63b3e32adf730 target/wasm32-unknown-unknown/release/fin.wasm
9d41d0cf47a7ebbd1575ba3423a7c9db3c6b6a9e357fa907ec38cdf8f2075611 target/wasm32-unknown-unknown/release/osmosis.wasm
e90bd0861ae289767a7bedcc6e519dab60cc52e672a5d3a01d12fcea5257f9c3 target/wasm32-unknown-unknown/release/dca.wasm
1835bcbf0327721127671e4105eb00c870f5344ce7cb0ffde63645b728061c8d target/wasm32-unknown-unknown/release/dca.wasm
Binary file modified artifacts/dca.wasm
Binary file not shown.
9 changes: 5 additions & 4 deletions contracts/dca/src/types/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
};
use crate::helpers::time::get_total_execution_duration;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Coin, Decimal, StdResult, Timestamp, Uint128};
use cosmwasm_std::{Addr, Coin, Decimal, Decimal256, StdResult, Timestamp, Uint128, Uint256};
use std::cmp::max;

#[cw_serde]
Expand Down Expand Up @@ -81,14 +81,15 @@ impl Vault {
pub fn price_threshold_exceeded(&self, belief_price: Decimal) -> StdResult<bool> {
self.minimum_receive_amount
.map_or(Ok(false), |minimum_receive_amount| {
let swap_amount_as_decimal = Decimal::from_ratio(self.swap_amount, Uint128::one());
let swap_amount_as_decimal =
Decimal256::from_ratio(self.swap_amount, Uint256::one());

let expected_receive_amount_at_price = swap_amount_as_decimal
.checked_div(belief_price)
.checked_div(belief_price.into())
.expect("belief price should be larger than 0");

let minimum_receive_amount_as_decimal =
Decimal::from_ratio(minimum_receive_amount, Uint128::one());
Decimal256::from_ratio(minimum_receive_amount, Uint256::one());

Ok(expected_receive_amount_at_price < minimum_receive_amount_as_decimal)
})
Expand Down

0 comments on commit 09a8d43

Please sign in to comment.