Skip to content

Commit

Permalink
F/injective-math improvements (#186)
Browse files Browse the repository at this point in the history
* fix a bug in must_from_str, add _ln_robust which has a smaller error in when x is small

* added newton's method, discrete newton's method, halley's methods

* improved function visibility

* added more unit tests

* added more constants

* log, power return FPDecimalError now

---------

Co-authored-by: DrunkRandomWalker <[email protected]>
  • Loading branch information
DrunkenRandomWalker and DrunkRandomWalker authored Nov 2, 2023
1 parent 3d90788 commit 466a3c7
Show file tree
Hide file tree
Showing 19 changed files with 2,789 additions and 1,639 deletions.
253 changes: 241 additions & 12 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/injective-cosmwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cosmwasm-std = { version = "1.4.1" }
cw-storage-plus = { version = "0.15.0" }
ethereum-types = "0.5.2"
hex = { version = "0.4.3", features = [ "serde" ] }
injective-math = { path = "../injective-math", version = "0.1.4" }
injective-math = { path = "../injective-math", version = "0.2.0" }
schemars = "0.8.8"
serde = { version = "1.0.136", default-features = false, features = [ "derive" ] }
serde_repr = "0.1"
Expand Down
16 changes: 8 additions & 8 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn default_derivative_market_response_handler(market_id: MarketId) -> QuerierRes
min_quantity_tick_size: FPDecimal::from_str("0.0001").unwrap(),
}),
info: None,
mark_price: FPDecimal::one(),
mark_price: FPDecimal::ONE,
}),
};
SystemResult::Ok(ContractResult::from(to_binary(&response)))
Expand Down Expand Up @@ -153,7 +153,7 @@ fn default_perpetual_market_funding_response_handler() -> QuerierResult {

fn default_market_volatility_response_handler() -> QuerierResult {
let response = MarketVolatilityResponse {
volatility: Some(FPDecimal::one()),
volatility: Some(FPDecimal::ONE),
history_metadata: None,
raw_history: None,
};
Expand Down Expand Up @@ -222,7 +222,7 @@ fn default_denom_decimals_handler() -> QuerierResult {

fn default_oracle_volatility_response_handler() -> QuerierResult {
let response = OracleVolatilityResponse {
volatility: Some(FPDecimal::one()),
volatility: Some(FPDecimal::ONE),
history_metadata: None,
raw_history: None,
};
Expand All @@ -233,13 +233,13 @@ fn default_pyth_price_response_handler() -> QuerierResult {
let response = PythPriceResponse {
price_state: Some(PythPriceState {
price_id: "0xff0ec26442c57d7456695b843694e7379b15cf1b250b27e0e47e657f1955aaff".to_string(),
ema_price: FPDecimal::one(),
ema_conf: FPDecimal::one(),
conf: FPDecimal::one(),
ema_price: FPDecimal::ONE,
ema_conf: FPDecimal::ONE,
conf: FPDecimal::ONE,
publish_time: 1i64,
price_state: PriceState {
price: FPDecimal::one(),
cumulative_price: FPDecimal::one(),
price: FPDecimal::ONE,
cumulative_price: FPDecimal::ONE,
timestamp: 1i64,
},
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/injective-math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "injective-math"
readme = "README.md"
repository = "https://github.com/InjectiveLabs/cw-injective/tree/master/packages/injective-math"
version = "0.1.23"
version = "0.2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -15,7 +15,7 @@ version = "0.1.23"
backtraces = [ "cosmwasm-std/backtraces" ]

[dependencies]
bigint = "4"
primitive-types = "0.12.2"
cosmwasm-std = { version = "1.4.1" }
ethereum-types = "0.5.2"
schemars = "0.8.8"
Expand Down
Loading

0 comments on commit 466a3c7

Please sign in to comment.