Skip to content

program: increase stable coin oracle threshold #1526

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

Open
wants to merge 5 commits into
base: master
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions programs/drift/src/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ 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::<i64>()?.saturating_mul(5))
{
oracle_price_data.price = PRICE_PRECISION_I64;
}

Expand Down
9 changes: 7 additions & 2 deletions sdk/src/oracles/pythClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down