Skip to content
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

bigz/add-Pyth1M #375

Merged
merged 4 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,17 @@ pub fn handle_initialize_perp_market(
perp_market.amm.get_pyth_twap(&ctx.accounts.oracle, 1000)?;
(oracle_price, oracle_delay, last_oracle_price_twap)
}
OracleSource::Pyth1M => {
let OraclePriceData {
price: oracle_price,
delay: oracle_delay,
..
} = get_pyth_price(&ctx.accounts.oracle, clock_slot, 1000000)?;
let last_oracle_price_twap = perp_market
.amm
.get_pyth_twap(&ctx.accounts.oracle, 1000000)?;
(oracle_price, oracle_delay, last_oracle_price_twap)
}
OracleSource::Switchboard => {
msg!("Switchboard oracle cant be used for perp market");
return Err(ErrorCode::InvalidOracle.into());
Expand Down
2 changes: 2 additions & 0 deletions programs/drift/src/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl HistoricalIndexData {
pub enum OracleSource {
Pyth,
Pyth1000,
0xbigz marked this conversation as resolved.
Show resolved Hide resolved
Pyth1M,
Switchboard,
QuoteAsset,
}
Expand Down Expand Up @@ -131,6 +132,7 @@ pub fn get_oracle_price(
match oracle_source {
OracleSource::Pyth => get_pyth_price(price_oracle, clock_slot, 1),
OracleSource::Pyth1000 => get_pyth_price(price_oracle, clock_slot, 1000),
OracleSource::Pyth1M => get_pyth_price(price_oracle, clock_slot, 1000000),
OracleSource::Switchboard => {
msg!("Switchboard oracle not yet supported");
Err(crate::error::ErrorCode::InvalidOracle)
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/src/state/oracle_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'a> OracleMap<'a> {
let pubkey = account_info.key();

let oracle_source = if pubkey == bonk_oracle::id() {
OracleSource::Pyth1000
OracleSource::Pyth1M
} else {
OracleSource::Pyth
};
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<'a> OracleMap<'a> {
if account_info.owner == &pyth_program::id() {
let pubkey = account_info.key();
let oracle_source = if pubkey == bonk_oracle::id() {
OracleSource::Pyth1000
OracleSource::Pyth1M
} else {
OracleSource::Pyth
};
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/state/perp_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ impl AMM {
match self.oracle_source {
OracleSource::Pyth => Ok(Some(self.get_pyth_twap(price_oracle, 1)?)),
OracleSource::Pyth1000 => Ok(Some(self.get_pyth_twap(price_oracle, 1000)?)),
OracleSource::Pyth1M => Ok(Some(self.get_pyth_twap(price_oracle, 1000000)?)),
OracleSource::Switchboard => Ok(None),
OracleSource::QuoteAsset => {
msg!("Can't get oracle twap for quote asset");
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 @@ -18,6 +18,10 @@ export function getOracleClient(
return new PythClient(connection, new BN(1000));
}

if (isVariant(oracleSource, 'pyth1M')) {
return new PythClient(connection, new BN(1000000));
}

// if (isVariant(oracleSource, 'switchboard')) {
// return new SwitchboardClient(connection);
// }
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
Expand Up @@ -6240,6 +6240,9 @@
{
"name": "Pyth1000"
},
{
"name": "Pyth1M"
},
{
"name": "Switchboard"
},
Expand Down
1 change: 1 addition & 0 deletions sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class DepositDirection {
export class OracleSource {
static readonly PYTH = { pyth: {} };
static readonly PYTH_1000 = { pyth1000: {} };
static readonly PYTH_1M = { pyth1M: {} };
// static readonly SWITCHBOARD = { switchboard: {} };
static readonly QUOTE_ASSET = { quoteAsset: {} };
}
Expand Down