Perp tests: Helper for market creation
This commit is contained in:
parent
bb962c6781
commit
45025a1145
|
@ -2097,6 +2097,7 @@ impl ClientInstruction for LiqTokenBankruptcyInstruction {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PerpCreateMarketInstruction {
|
||||
pub group: Pubkey,
|
||||
pub admin: TestKeypair,
|
||||
|
@ -2118,6 +2119,28 @@ pub struct PerpCreateMarketInstruction {
|
|||
pub maker_fee: f32,
|
||||
pub taker_fee: f32,
|
||||
}
|
||||
impl PerpCreateMarketInstruction {
|
||||
pub async fn with_new_book_and_queue(
|
||||
solana: &SolanaCookie,
|
||||
base: &crate::mango_setup::Token,
|
||||
) -> Self {
|
||||
PerpCreateMarketInstruction {
|
||||
asks: solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await,
|
||||
oracle: base.oracle,
|
||||
base_token_index: base.index,
|
||||
base_token_decimals: base.mint.decimals,
|
||||
..PerpCreateMarketInstruction::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl ClientInstruction for PerpCreateMarketInstruction {
|
||||
type Accounts = mango_v4::accounts::PerpCreateMarket;
|
||||
|
|
|
@ -197,7 +197,6 @@ async fn test_health_compute_perp() -> Result<(), TransportError> {
|
|||
//
|
||||
// SETUP: Create perp markets
|
||||
//
|
||||
let quote_token = &tokens[0];
|
||||
let mut perp_markets = vec![];
|
||||
for (perp_market_index, token) in tokens[1..].iter().enumerate() {
|
||||
let mango_v4::accounts::PerpCreateMarket {
|
||||
|
@ -211,25 +210,8 @@ async fn test_health_compute_perp() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: token.oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: perp_market_index as PerpMarketIndex,
|
||||
base_token_index: quote_token.index,
|
||||
base_token_decimals: quote_token.mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.975,
|
||||
|
@ -239,6 +221,11 @@ async fn test_health_compute_perp() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.012,
|
||||
maker_fee: 0.0002,
|
||||
taker_fee: 0.000,
|
||||
// HACK: Currently the base_token_index token needs to be active on the account.
|
||||
// Using token[0] for each market allows us to have multiple perp positions with
|
||||
// just a single token position.
|
||||
base_token_index: tokens[0].index,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, &token).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -48,25 +48,8 @@ async fn test_liq_perps_force_cancel() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: base_token.oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: 0,
|
||||
base_token_index: base_token.index,
|
||||
base_token_decimals: base_token.mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.8,
|
||||
|
@ -76,6 +59,7 @@ async fn test_liq_perps_force_cancel() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.05,
|
||||
maker_fee: 0.0,
|
||||
taker_fee: 0.0,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, base_token).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -72,25 +72,8 @@ async fn test_perp() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: tokens[0].oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: 0,
|
||||
base_token_index: tokens[0].index,
|
||||
base_token_decimals: tokens[0].mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.975,
|
||||
|
@ -100,6 +83,7 @@ async fn test_perp() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.012,
|
||||
maker_fee: -0.0001,
|
||||
taker_fee: 0.0002,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, &tokens[0]).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -138,25 +138,8 @@ async fn test_perp_settle_pnl() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: tokens[0].oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: 0,
|
||||
base_token_index: tokens[0].index,
|
||||
base_token_decimals: tokens[0].mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.975,
|
||||
|
@ -166,6 +149,7 @@ async fn test_perp_settle_pnl() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.012,
|
||||
maker_fee: 0.0002,
|
||||
taker_fee: 0.000,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, &tokens[0]).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
@ -182,25 +166,8 @@ async fn test_perp_settle_pnl() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: tokens[1].oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: 1,
|
||||
base_token_index: tokens[1].index,
|
||||
base_token_decimals: tokens[1].mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.975,
|
||||
|
@ -210,6 +177,7 @@ async fn test_perp_settle_pnl() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.012,
|
||||
maker_fee: 0.0002,
|
||||
taker_fee: 0.000,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, &tokens[1]).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -138,25 +138,8 @@ async fn test_perp_settle_fees() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: tokens[0].oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: 0,
|
||||
base_token_index: tokens[0].index,
|
||||
base_token_decimals: tokens[0].mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.975,
|
||||
|
@ -166,6 +149,7 @@ async fn test_perp_settle_fees() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.012,
|
||||
maker_fee: 0.0002,
|
||||
taker_fee: 0.000,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, &tokens[0]).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
@ -182,25 +166,8 @@ async fn test_perp_settle_fees() -> Result<(), TransportError> {
|
|||
PerpCreateMarketInstruction {
|
||||
group,
|
||||
admin,
|
||||
oracle: tokens[1].oracle,
|
||||
asks: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
bids: context
|
||||
.solana
|
||||
.create_account_for_type::<BookSide>(&mango_v4::id())
|
||||
.await,
|
||||
event_queue: {
|
||||
context
|
||||
.solana
|
||||
.create_account_for_type::<EventQueue>(&mango_v4::id())
|
||||
.await
|
||||
},
|
||||
payer,
|
||||
perp_market_index: 1,
|
||||
base_token_index: tokens[1].index,
|
||||
base_token_decimals: tokens[1].mint.decimals,
|
||||
quote_lot_size: 10,
|
||||
base_lot_size: 100,
|
||||
maint_asset_weight: 0.975,
|
||||
|
@ -210,6 +177,7 @@ async fn test_perp_settle_fees() -> Result<(), TransportError> {
|
|||
liquidation_fee: 0.012,
|
||||
maker_fee: 0.0002,
|
||||
taker_fee: 0.000,
|
||||
..PerpCreateMarketInstruction::with_new_book_and_queue(&solana, &tokens[1]).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
Loading…
Reference in New Issue