RegisterSerumMarket: pass market_index explicitly

This commit is contained in:
Christian Kamm 2022-03-14 13:47:34 +01:00
parent 07c9b9de7e
commit 0b2f691f5b
5 changed files with 13 additions and 5 deletions

View File

@ -18,7 +18,7 @@ pub struct RegisterSerumMarket<'info> {
#[account(
init,
// TODO: possibly use the market index instead of serum_market in the seed
// using the serum_market_external in the seed guards against registering the same market twice
seeds = [group.key().as_ref(), b"SerumMarket".as_ref(), serum_market_external.key().as_ref()],
bump,
payer = payer,
@ -35,17 +35,19 @@ pub struct RegisterSerumMarket<'info> {
// TODO: should this be "configure_serum_market", which allows reconfiguring?
pub fn register_serum_market(
ctx: Context<RegisterSerumMarket>,
market_index: SerumMarketIndex,
base_token_index: TokenIndex,
quote_token_index: TokenIndex,
) -> Result<()> {
//let mut group = ctx.accounts.group.load_mut()?;
// TODO: must guard against accidentally using the same market_index twice!
// TODO: verify that base_token_index and quote_token_index are correct!
let mut serum_market = ctx.accounts.serum_market.load_init()?;
*serum_market = SerumMarket {
group: ctx.accounts.group.key(),
serum_program: ctx.accounts.serum_program.key(),
serum_market_external: ctx.accounts.serum_market_external.key(),
market_index: 0, // TODO: likely globally tracked in the group?
market_index,
base_token_index,
quote_token_index,
bump: *ctx.bumps.get("serum_market").ok_or(MangoError::SomeError)?,

View File

@ -23,6 +23,7 @@ pub struct RegisterToken<'info> {
#[account(
init,
// using the token_index in this seed guards against reusing it
seeds = [group.key().as_ref(), b"Bank".as_ref(), &token_index.to_le_bytes()],
bump,
payer = payer,
@ -42,6 +43,7 @@ pub struct RegisterToken<'info> {
#[account(
init,
// using the mint in this seed guards against registering the same mint twice
seeds = [group.key().as_ref(), b"MintInfo".as_ref(), mint.key().as_ref()],
bump,
payer = payer,

View File

@ -14,7 +14,7 @@ pub mod error;
pub mod instructions;
pub mod state;
use state::TokenIndex;
use state::{SerumMarketIndex, TokenIndex};
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
@ -79,10 +79,11 @@ pub mod mango_v4 {
pub fn register_serum_market(
ctx: Context<RegisterSerumMarket>,
market_index: SerumMarketIndex,
base_token_index: TokenIndex,
quote_token_index: TokenIndex,
) -> Result<()> {
instructions::register_serum_market(ctx, base_token_index, quote_token_index)
instructions::register_serum_market(ctx, market_index, base_token_index, quote_token_index)
}
pub fn create_serum_open_orders(ctx: Context<CreateSerumOpenOrders>) -> Result<()> {

View File

@ -611,6 +611,7 @@ pub struct RegisterSerumMarketInstruction<'keypair> {
pub serum_program: Pubkey,
pub serum_market_external: Pubkey,
pub market_index: SerumMarketIndex,
pub base_token_index: TokenIndex,
pub quote_token_index: TokenIndex,
}
@ -624,6 +625,7 @@ impl<'keypair> ClientInstruction for RegisterSerumMarketInstruction<'keypair> {
) -> (Self::Accounts, instruction::Instruction) {
let program_id = mango_v4::id();
let instruction = Self::Instruction {
market_index: self.market_index,
base_token_index: self.base_token_index,
quote_token_index: self.quote_token_index,
};

View File

@ -113,6 +113,7 @@ async fn test_serum() -> Result<(), TransportError> {
admin,
serum_program: context.serum.program_id,
serum_market_external: serum_market_cookie.market,
market_index: 0,
base_token_index,
quote_token_index,
payer,