Skip to content

Commit

Permalink
add pyth lazer stable coin (#1463)
Browse files Browse the repository at this point in the history
* add pyth lazer stable coin

* update changelog
  • Loading branch information
NourAlharithi authored Feb 5, 2025
1 parent 3f6b24d commit 9303acd
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

- program: add posted slot tail to order struct, use it to determine vamm availability for high volume users ([#1459](https://github.com/drift-labs/protocol-v2/pull/1459))
- program: add pyth lazer stable coin oracle type ([#1463](https://github.com/drift-labs/protocol-v2/pull/1463))

### Fixes

Expand Down
12 changes: 12 additions & 0 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,18 @@ pub fn handle_initialize_perp_market(
.get_pyth_twap(&ctx.accounts.oracle, &OracleSource::PythLazer1M)?;
(oracle_price, oracle_delay, last_oracle_price_twap)
}
OracleSource::PythLazerStableCoin => {
let OraclePriceData {
price: oracle_price,
delay: oracle_delay,
..
} = get_pyth_price(
&ctx.accounts.oracle,
clock_slot,
&OracleSource::PythLazerStableCoin,
)?;
(oracle_price, oracle_delay, QUOTE_PRECISION_I64)
}
};

validate_margin(
Expand Down
7 changes: 6 additions & 1 deletion programs/drift/src/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub enum OracleSource {
PythLazer,
PythLazer1K,
PythLazer1M,
PythLazerStableCoin,
}

impl OracleSource {
Expand Down Expand Up @@ -157,7 +158,8 @@ impl OracleSource {
| OracleSource::PythPull
| OracleSource::PythLazer
| OracleSource::PythStableCoin
| OracleSource::PythStableCoinPull => 1,
| OracleSource::PythStableCoinPull
| OracleSource::PythLazerStableCoin => 1,
OracleSource::Pyth1K | OracleSource::Pyth1KPull | OracleSource::PythLazer1K => 1000,
OracleSource::Pyth1M | OracleSource::Pyth1MPull | OracleSource::PythLazer1M => 1000000,
_ => {
Expand Down Expand Up @@ -216,6 +218,9 @@ pub fn get_oracle_price(
OracleSource::PythLazer => get_pyth_price(price_oracle, clock_slot, oracle_source),
OracleSource::PythLazer1K => get_pyth_price(price_oracle, clock_slot, oracle_source),
OracleSource::PythLazer1M => get_pyth_price(price_oracle, clock_slot, oracle_source),
OracleSource::PythLazerStableCoin => {
get_pyth_stable_coin_price(price_oracle, clock_slot, oracle_source)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions programs/drift/src/state/perp_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ impl AMM {
OracleSource::PythLazer1M => Ok(Some(
self.get_pyth_twap(price_oracle, &OracleSource::PythLazer1M)?,
)),
OracleSource::PythLazerStableCoin => Ok(Some(
self.get_pyth_twap(price_oracle, &OracleSource::PythLazerStableCoin)?,
)),
}
}

Expand Down
4 changes: 4 additions & 0 deletions sdk/src/factory/oracleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,9 @@ export function getOracleClient(
return new PythLazerClient(connection, new BN(1000000));
}

if (isVariant(oracleSource, 'pythLazerStableCoin')) {
return new PythLazerClient(connection, undefined, true);
}

throw new Error(`Unknown oracle source ${oracleSource}`);
}
3 changes: 3 additions & 0 deletions sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
Expand Up @@ -11470,6 +11470,9 @@
},
{
"name": "PythLazer1M"
},
{
"name": "PythLazerStableCoin"
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/oracles/oracleId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export function getOracleSourceNum(source: OracleSource): number {
if ('pythLazer' in source) return OracleSourceNum.PYTH_LAZER;
if ('pythLazer1K' in source) return OracleSourceNum.PYTH_LAZER_1K;
if ('pythLazer1M' in source) return OracleSourceNum.PYTH_LAZER_1M;
if ('pythLazerStableCoin' in source)
return OracleSourceNum.PYTH_LAZER_STABLE_COIN;
throw new Error('Invalid oracle source');
}

Expand Down
6 changes: 4 additions & 2 deletions sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class OracleSource {
static readonly PYTH_LAZER = { pythLazer: {} };
static readonly PYTH_LAZER_1K = { pythLazer1K: {} };
static readonly PYTH_LAZER_1M = { pythLazer1M: {} };
static readonly PYTH_LAZER_STABLE_COIN = { pythLazerStableCoin: {} };
}

export class OracleSourceNum {
Expand All @@ -150,8 +151,9 @@ export class OracleSourceNum {
static readonly PRELAUNCH = 10;
static readonly SWITCHBOARD_ON_DEMAND = 11;
static readonly PYTH_LAZER = 12;
static readonly PYTH_LAZER_1K = 12;
static readonly PYTH_LAZER_1M = 12;
static readonly PYTH_LAZER_1K = 13;
static readonly PYTH_LAZER_1M = 14;
static readonly PYTH_LAZER_STABLE_COIN = 15;
}

export class OrderType {
Expand Down

0 comments on commit 9303acd

Please sign in to comment.