diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index a9d96df97..71c973a0d 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -37,6 +37,8 @@ export type OracleConfigParams = IdlTypes['OracleConfigParams']; export type OracleConfig = IdlTypes['OracleConfig']; export type MarketAccount = IdlAccounts['market']; export type OpenOrdersAccount = IdlAccounts['openOrdersAccount']; +export type OpenOrdersIndexerAccount = + IdlAccounts['openOrdersIndexer']; export type EventHeapAccount = IdlAccounts['eventHeap']; export type BookSideAccount = IdlAccounts['bookSide']; export type LeafNode = IdlTypes['LeafNode']; @@ -151,6 +153,16 @@ export class OpenBookV2Client { } } + public async getOpenOrdersIndexer( + publicKey: PublicKey, + ): Promise { + try { + return await this.program.account.openOrdersIndexer.fetch(publicKey); + } catch { + return null; + } + } + public async getEventHeap( publicKey: PublicKey, ): Promise { @@ -196,8 +208,8 @@ export class OpenBookV2Client { name: string, quoteMint: PublicKey, baseMint: PublicKey, - quoteLoteSize: BN, - baseLoteSize: BN, + quoteLotSize: BN, + baseLotSize: BN, makerFee: BN, takerFee: BN, timeExpiry: BN, @@ -247,8 +259,8 @@ export class OpenBookV2Client { .createMarket( name, oracleConfigParams, - quoteLoteSize, - baseLoteSize, + quoteLotSize, + baseLotSize, makerFee, takerFee, timeExpiry, @@ -314,7 +326,7 @@ export class OpenBookV2Client { Buffer.from('OpenOrders'), this.walletPk.toBuffer(), market.toBuffer(), - accountIndex.toBuffer('le', 4), + accountIndex.toArrayLike(Buffer, 'le', 4), ], this.programId, ); diff --git a/ts/client/src/market.ts b/ts/client/src/market.ts index 801628b72..efbd67caf 100644 --- a/ts/client/src/market.ts +++ b/ts/client/src/market.ts @@ -1,4 +1,9 @@ -import { PublicKey, type Connection, type AccountInfo } from '@solana/web3.js'; +import { + PublicKey, + type Connection, + type AccountInfo, + type Message, +} from '@solana/web3.js'; import { getFilteredProgramAccounts } from './client'; import { utils, Program, type Provider, getProvider } from '@coral-xyz/anchor'; @@ -27,7 +32,6 @@ export async function findAccountsByMints( ]; return await getFilteredProgramAccounts(connection, programId, filters); } - interface Market { market: string; baseMint: string; @@ -55,12 +59,13 @@ export async function findAllMarkets( await connection.getSignaturesForAddress(eventAuthority) ).map((x) => x.signature); const batchSignatures: [string[]] = [[]]; - for (var i = 0; i < signatures.length; i += BATCH_TX_SIZE) { + for (let i = 0; i < signatures.length; i += BATCH_TX_SIZE) { batchSignatures.push(signatures.slice(0, BATCH_TX_SIZE)); } for (const batch of batchSignatures) { const allTxs = await connection.getTransactions(batch, { commitment: 'confirmed', + maxSupportedTransactionVersion: 0, }); for (const tx of allTxs) { if ( @@ -68,38 +73,41 @@ export async function findAllMarkets( tx?.meta?.innerInstructions !== undefined ) for (const innerIns of tx.meta.innerInstructions) { - // validate key and program key - const eventAuthorityKey = innerIns.instructions[1].accounts[0]; - const programKey = innerIns.instructions[1].programIdIndex; - - if ( - tx.transaction.message.accountKeys[eventAuthorityKey].toString() !== - eventAuthority.toString() || - tx.transaction.message.accountKeys[programKey].toString() !== - programId.toString() - ) { - continue; - } else { - const ixData = utils.bytes.bs58.decode( - innerIns.instructions[1].data, - ); - const eventData = utils.bytes.base64.encode(ixData.slice(8)); - const event = program.coder.events.decode(eventData); + if (innerIns.instructions?.[1]?.accounts?.[0] !== undefined) { + console.log('err'); + // validate key and program key + const eventAuthorityKey = innerIns.instructions[1].accounts[0]; + const programKey = innerIns.instructions[1].programIdIndex; + if ( + (tx.transaction.message as Message).staticAccountKeys[ + eventAuthorityKey + ].toString() !== eventAuthority.toString() || + (tx.transaction.message as Message).staticAccountKeys[ + programKey + ].toString() !== programId.toString() + ) { + continue; + } else { + const ixData = utils.bytes.bs58.decode( + innerIns.instructions[1].data, + ); + const eventData = utils.bytes.base64.encode(ixData.slice(8)); + const event = program.coder.events.decode(eventData); - if (event != null) { - const market: Market = { - market: (event.data.market as PublicKey).toString(), - baseMint: (event.data.baseMint as PublicKey).toString(), - quoteMint: (event.data.quoteMint as PublicKey).toString(), - name: event.data.name as string, - timestamp: tx.blockTime, - }; - marketsAll.push(market); + if (event != null) { + const market: Market = { + market: (event.data.market as PublicKey).toString(), + baseMint: (event.data.baseMint as PublicKey).toString(), + quoteMint: (event.data.quoteMint as PublicKey).toString(), + name: event.data.name as string, + timestamp: tx.blockTime, + }; + marketsAll.push(market); + } } } } } } - return marketsAll; }