Skip to content

Commit

Permalink
sdk-add-market-index-27
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbigz committed Mar 14, 2024
1 parent 71811c8 commit dde26e7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
73 changes: 56 additions & 17 deletions programs/drift/src/controller/spot_balance/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::create_account_info;
use crate::create_anchor_account_info;
use crate::math::constants::{
AMM_RESERVE_PRECISION, BASE_PRECISION_I128, BASE_PRECISION_I64, LIQUIDATION_FEE_PRECISION,
PEG_PRECISION, PRICE_PRECISION_I64, QUOTE_PRECISION, QUOTE_PRECISION_I128, QUOTE_PRECISION_I64,
QUOTE_PRECISION_U64, SPOT_BALANCE_PRECISION, SPOT_BALANCE_PRECISION_U64,
PEG_PRECISION, PRICE_PRECISION_I64, PRICE_PRECISION_U64, QUOTE_PRECISION, QUOTE_PRECISION_I128,
QUOTE_PRECISION_I64, QUOTE_PRECISION_U64, SPOT_BALANCE_PRECISION, SPOT_BALANCE_PRECISION_U64,
SPOT_CUMULATIVE_INTEREST_PRECISION, SPOT_RATE_PRECISION_U32, SPOT_UTILIZATION_PRECISION,
SPOT_UTILIZATION_PRECISION_U32, SPOT_WEIGHT_PRECISION, PRICE_PRECISION_U64
SPOT_UTILIZATION_PRECISION_U32, SPOT_WEIGHT_PRECISION,
};
use crate::math::margin::{
calculate_margin_requirement_and_total_collateral_and_liability_info, MarginRequirementType,
Expand Down Expand Up @@ -1610,23 +1610,62 @@ fn check_usdc_spot_market_twap() {
.unwrap();
assert_eq!(wa_res2, PRICE_PRECISION_I64 + 1);

assert_eq!(
spot_market.historical_index_data.last_index_price_twap_ts,
0
);

assert_eq!(spot_market.historical_index_data.last_index_price_twap_ts, 0);

spot_market.update_historical_index_price(None, None, 7898).unwrap();
assert_eq!(spot_market.historical_index_data.last_index_price_twap_ts, 7898);
spot_market
.update_historical_index_price(None, None, 7898)
.unwrap();
assert_eq!(
spot_market.historical_index_data.last_index_price_twap_ts,
7898
);
assert_eq!(spot_market.historical_index_data.last_index_price_twap, 0);
assert_eq!(spot_market.historical_index_data.last_index_price_twap_5min, 0);

spot_market.update_historical_index_price(Some(PRICE_PRECISION_U64 - 79083), Some(PRICE_PRECISION_U64 + 9174), 1710344006).unwrap();
assert_eq!(spot_market.historical_index_data.last_index_price_twap_ts, 1710344006);
assert_eq!(spot_market.historical_index_data.last_index_price_twap_5min, 965044);
assert_eq!(spot_market.historical_index_data.last_index_price_twap, 965044);
assert_eq!(
spot_market.historical_index_data.last_index_price_twap_5min,
0
);

spot_market.update_historical_index_price(Some(PRICE_PRECISION_U64 - 7), Some(PRICE_PRECISION_U64 + 9), 1710344006 + 150).unwrap();
spot_market
.update_historical_index_price(
Some(PRICE_PRECISION_U64 - 79083),
Some(PRICE_PRECISION_U64 + 9174),
1710344006,
)
.unwrap();
assert_eq!(
spot_market.historical_index_data.last_index_price_twap_ts,
1710344006
);
assert_eq!(
spot_market.historical_index_data.last_index_price_twap_5min,
965044
);
assert_eq!(
spot_market.historical_index_data.last_index_price_twap,
965044
);

assert_eq!(spot_market.historical_index_data.last_index_price_twap_ts, 1710344006 + 150);
assert_eq!(spot_market.historical_index_data.last_index_price_twap_5min, 982521);
assert_eq!(spot_market.historical_index_data.last_index_price_twap, 966501);
spot_market
.update_historical_index_price(
Some(PRICE_PRECISION_U64 - 7),
Some(PRICE_PRECISION_U64 + 9),
1710344006 + 150,
)
.unwrap();

assert_eq!(
spot_market.historical_index_data.last_index_price_twap_ts,
1710344006 + 150
);
assert_eq!(
spot_market.historical_index_data.last_index_price_twap_5min,
982521
);
assert_eq!(
spot_market.historical_index_data.last_index_price_twap,
966501
);
}
10 changes: 10 additions & 0 deletions sdk/src/constants/perpMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
launchTs: 1709136669000,
oracleSource: OracleSource.PYTH,
},
{
fullName: 'Wormhole',
category: ['Bridge'],
symbol: 'W-PERP',
baseAssetSymbol: 'W',
marketIndex: 27,
oracle: new PublicKey('GU6CA7a2KCyhpfqZNb36UAfc9uzKBM8jHjGdt245QhYX'),
launchTs: 1710418343000,
oracleSource: OracleSource.Prelaunch,
},
];

export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
Expand Down

0 comments on commit dde26e7

Please sign in to comment.