From 8510a35239078a6e1fd021ad89d990ef542dee7e Mon Sep 17 00:00:00 2001 From: 0xbigz <83473873+0xbigz@users.noreply.github.com> Date: Wed, 12 Mar 2025 14:54:27 -0400 Subject: [PATCH 1/4] program: increase stable coin oracle threshold --- programs/drift/src/state/oracle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index b1b328dba7..19bbe98489 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -321,9 +321,9 @@ pub fn get_pyth_stable_coin_price( let price = oracle_price_data.price; let confidence = oracle_price_data.confidence; - let five_bps = 500_i64; + let twenty_bps = 2000_i64; - if price.safe_sub(PRICE_PRECISION_I64)?.abs() <= five_bps.min(confidence.cast()?) { + if price.safe_sub(PRICE_PRECISION_I64)?.abs() <= twenty_bps.min(confidence.cast::()?.saturating_mul(5)) { oracle_price_data.price = PRICE_PRECISION_I64; } From 601d8ff2ca089c9733fdd48a593c600a5a6beeac Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Thu, 13 Mar 2025 17:20:24 -0400 Subject: [PATCH 2/4] cargo fmt -- --- programs/drift/src/state/oracle.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index 19bbe98489..218ac42d3c 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -323,7 +323,9 @@ pub fn get_pyth_stable_coin_price( let confidence = oracle_price_data.confidence; let twenty_bps = 2000_i64; - if price.safe_sub(PRICE_PRECISION_I64)?.abs() <= twenty_bps.min(confidence.cast::()?.saturating_mul(5)) { + if price.safe_sub(PRICE_PRECISION_I64)?.abs() + <= twenty_bps.min(confidence.cast::()?.saturating_mul(5)) + { oracle_price_data.price = PRICE_PRECISION_I64; } From ddaf223cd6b954de18248eb3c8462661bd6030bc Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Thu, 13 Mar 2025 17:21:06 -0400 Subject: [PATCH 3/4] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57137e6687..618d224a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features +- program: increase stable coin oracle threshold ([#1526](https://github.com/drift-labs/protocol-v2/pull/1526)) + ### Fixes ### Breaking From 2a86042d717f72050e954385e3a5a84cee65e8ae Mon Sep 17 00:00:00 2001 From: 0xbigz <83473873+0xbigz@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:45:48 -0400 Subject: [PATCH 4/4] sdk: update getStableCoinPrice --- sdk/src/oracles/pythClient.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/src/oracles/pythClient.ts b/sdk/src/oracles/pythClient.ts index 464b975e9a..011612464b 100644 --- a/sdk/src/oracles/pythClient.ts +++ b/sdk/src/oracles/pythClient.ts @@ -75,9 +75,14 @@ function convertPythPrice(price: number, exponent: number, multiple: BN): BN { .div(pythPrecision); } -const fiveBPS = new BN(500); +const twentyBPS = new BN(2000); function getStableCoinPrice(price: BN, confidence: BN): BN { - if (price.sub(QUOTE_PRECISION).abs().lt(BN.min(confidence, fiveBPS))) { + if ( + price + .sub(QUOTE_PRECISION) + .abs() + .lt(BN.min(confidence.muln(5), twentyBPS)) + ) { return QUOTE_PRECISION; } else { return price;