1

I'm trying to create a new MarketId using makeCreateMarketInstrucrion in '@raydium-io/raydium-sdk-v2'. But the program gives an error:

Error: Transaction instruction index 0 has undefined program id
async function create_market_id(token, mainKeypair, connection) {
    let transaction = new Transaction();

    const dexProgramId =  DEVNET_PROGRAM_ID.OPENBOOK_MARKET;
    const wallet = mainKeypair.publicKey;
    const basemint = token;
    const quotemint = SOLMint;

    const market = new generatePubKey({ fromPublicKey: wallet, programId: dexProgramId });
    const baseVault = new generatePubKey({ fromPublicKey: wallet, programId: dexProgramId });
    const quoteVault = new generatePubKey({ fromPublicKey: wallet, programId: TOKEN_PROGRAM_ID });
    const requestQueue = new generatePubKey({ fromPublicKey: wallet, programId: dexProgramId });
    const eventQueue = new generatePubKey({ fromPublicKey: wallet, programId: dexProgramId });
    const bids = new generatePubKey({ fromPublicKey: wallet, programId: dexProgramId });
    const asks = new generatePubKey({ fromPublicKey: wallet, programId: dexProgramId });
    const feeRateBps = 0;
    const quoteDustThreshold = new BN(100);
    const baseLotSize = new BN(Math.round(10 ** 9 * 1));
    const quoteLotSize = new BN(Math.round(1 * 10 ** 9 * 0.01));
    function getVaultOwnerAndNonce() {
      const vaultSignerNonce = new BN(0);
      // eslint-disable-next-line no-constant-condition
      while (true) {
        try {
          const vaultOwner = PublicKey.createProgramAddressSync(
            [market.publicKey.toBuffer(), vaultSignerNonce.toArrayLike(Buffer, "le", 8)],
            dexProgramId,
          );
          return { vaultOwner, vaultSignerNonce };
        } catch (e) {
          vaultSignerNonce.iaddn(1);
          if (vaultSignerNonce.gt(new BN(25555))) throw Error("find vault owner error");
        }
      }
    };
    const { vaultOwner, vaultSignerNonce } = getVaultOwnerAndNonce();

   
    const instruction = await makeCreateMarketInstruction({
      connection: connection,
      wallet: wallet,
      marketInfo: {
        programId: dexProgramId,
        id: market,
        baseMint: basemint,
        quoteMint: quotemint,
        baseVault,
        quoteVault,
        vaultOwner,
        requestQueue,
        eventQueue,
        bids,
        asks,

        feeRateBps,
        quoteDustThreshold,
        vaultSignerNonce,
        baseLotSize,
        quoteLotSize,
      }
    });
    transaction.add(instruction);
    const marketId = await connection.sendTransaction(transaction, [mainKeypair])

    console.log("market_id: ", marketId);
    
}

1 Answer 1

3

I think you use the API of the SDK in "a wrong" way. The instruction object you get from the makeCreateMarketInstruction(...) is not a set of instructions that can be passed to Transaction.add(). I believe there is a type mismatch.

Consider the structure of the returned object https://github.com/raydium-io/raydium-sdk-V2/blob/master/src/raydium/marketV2/instrument.ts#L219

And consider checking how the SDK is used and integrated into other Solana clients https://github.com/Shiny0805/Solana-Token-Dist/blob/main/src/create_market.js#L17-L30

or

https://github.com/blockworks-foundation/mango-v4-ui/blob/3394732869731b4f06f2b3dea18b90471e6ab0d9/utils/governance/market/createOpenBookMarket.ts#L19 https://github.com/blockworks-foundation/mango-v4-ui/blob/3394732869731b4f06f2b3dea18b90471e6ab0d9/components/modals/CreateOpenbookMarketModal.tsx#L107

3
  • If I use one of these clients, where will I need to pass the instruction that I will receive using one of these methods?
    – nyslxj
    Commented Jun 18 at 12:45
  • I meant to check how the SDK is used at other places, in other projects, in other clients. I think you can check the code and copy and paste part of it to get your example working.
    – chalda
    Commented Jun 19 at 8:37
  • 1
    Thanks, I've solved this with your help!
    – nyslxj
    Commented Jun 19 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.