@openbook-dex/openbook-v2
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -58,3 +58,5 @@ /// <reference types="bn.js" /> | ||
createOpenOrdersIndexerInstruction(openOrdersIndexer: PublicKey, owner?: PublicKey): Promise<TransactionInstruction>; | ||
findOpenOrders(market: PublicKey, accountIndex: BN, owner: PublicKey): PublicKey; | ||
findAllOpenOrders(owner?: PublicKey): Promise<PublicKey[]>; | ||
findOpenOrderAtIndex(owner: PublicKey | undefined, accountIndex: BN): PublicKey; | ||
findOpenOrdersForMarket(owner: PublicKey | undefined, market: PublicKey): Promise<PublicKey[]>; | ||
createOpenOrdersInstruction(market: PublicKey, accountIndex: BN, name: string, owner: PublicKey | undefined, delegateAccount: PublicKey | null, openOrdersIndexer?: PublicKey): Promise<[TransactionInstruction[], PublicKey]>; | ||
@@ -74,2 +76,3 @@ createOpenOrders(payer: Keypair, market: PublicKey, accountIndex: BN, name: string, owner?: Keypair, openOrdersIndexer?: PublicKey | null): Promise<PublicKey>; | ||
consumeEvents(marketPublicKey: PublicKey, market: MarketAccount, limit: BN, remainingAccounts: PublicKey[]): Promise<TransactionSignature>; | ||
consumeEventsForAccount(marketPublicKey: PublicKey, market: MarketAccount, openOrdersAccount: PublicKey): Promise<TransactionSignature>; | ||
consumeGivenEvents(marketPublicKey: PublicKey, market: MarketAccount, slots: BN[], remainingAccounts: PublicKey[]): Promise<TransactionSignature>; | ||
@@ -76,0 +79,0 @@ pruneOrders(marketPublicKey: PublicKey, market: MarketAccount, openOrdersPublicKey: PublicKey, limit: number, closeMarketAdmin?: Keypair | null): Promise<TransactionSignature>; |
@@ -231,3 +231,8 @@ "use strict"; | ||
} | ||
findOpenOrders(market, accountIndex, owner) { | ||
async findAllOpenOrders(owner = this.walletPk) { | ||
const indexer = this.findOpenOrdersIndexer(owner); | ||
const indexerAccount = await this.getOpenOrdersIndexer(indexer); | ||
return indexerAccount?.addresses ?? []; | ||
} | ||
findOpenOrderAtIndex(owner = this.walletPk, accountIndex) { | ||
const [openOrders] = web3_js_1.PublicKey.findProgramAddressSync([ | ||
@@ -240,2 +245,13 @@ Buffer.from('OpenOrders'), | ||
} | ||
async findOpenOrdersForMarket(owner = this.walletPk, market) { | ||
const openOrdersForMarket = []; | ||
const allOpenOrders = await this.findAllOpenOrders(owner); | ||
allOpenOrders.filter(async (x) => { | ||
const openOrdersAccount = await this.getOpenOrders(x); | ||
if (openOrdersAccount?.market === market) { | ||
openOrdersForMarket.push(x); | ||
} | ||
}); | ||
return allOpenOrders; | ||
} | ||
async createOpenOrdersInstruction(market, accountIndex, name, owner = this.walletPk, delegateAccount, openOrdersIndexer) { | ||
@@ -260,3 +276,3 @@ const ixs = []; | ||
} | ||
const openOrdersAccount = this.findOpenOrders(market, accountIndex, owner); | ||
const openOrdersAccount = this.findOpenOrderAtIndex(owner, accountIndex); | ||
ixs.push(await this.program.methods | ||
@@ -576,2 +592,26 @@ .createOpenOrdersAccount(name) | ||
} | ||
// Consume events for one specific account. Add other extra accounts as it's "free". | ||
async consumeEventsForAccount(marketPublicKey, market, openOrdersAccount) { | ||
const slots = await this.getSlotsToConsume(openOrdersAccount, market); | ||
const allAccounts = await this.getAccountsToConsume(market); | ||
// Create a set to remove duplicates | ||
const uniqueAccounts = new Set([openOrdersAccount, ...allAccounts]); | ||
// Limit extra accounts to 10 due tx limit and add openOrdersAccount | ||
const remainingAccounts = [...uniqueAccounts].slice(0, 10); | ||
const accountsMeta = remainingAccounts.map((remaining) => ({ | ||
pubkey: remaining, | ||
isSigner: false, | ||
isWritable: true, | ||
})); | ||
const ix = await this.program.methods | ||
.consumeGivenEvents(slots) | ||
.accounts({ | ||
eventHeap: market.eventHeap, | ||
market: marketPublicKey, | ||
consumeEventsAdmin: market.consumeEventsAdmin.key, | ||
}) | ||
.remainingAccounts(accountsMeta) | ||
.instruction(); | ||
return await this.sendAndConfirmTransaction([ix]); | ||
} | ||
// In order to get slots for certain key use getSlotsToConsume and include the key in the remainingAccounts | ||
@@ -578,0 +618,0 @@ async consumeGivenEvents(marketPublicKey, market, slots, remainingAccounts) { |
@@ -227,3 +227,8 @@ import { BN, Program, } from '@coral-xyz/anchor'; | ||
} | ||
findOpenOrders(market, accountIndex, owner) { | ||
async findAllOpenOrders(owner = this.walletPk) { | ||
const indexer = this.findOpenOrdersIndexer(owner); | ||
const indexerAccount = await this.getOpenOrdersIndexer(indexer); | ||
return indexerAccount?.addresses ?? []; | ||
} | ||
findOpenOrderAtIndex(owner = this.walletPk, accountIndex) { | ||
const [openOrders] = PublicKey.findProgramAddressSync([ | ||
@@ -236,2 +241,13 @@ Buffer.from('OpenOrders'), | ||
} | ||
async findOpenOrdersForMarket(owner = this.walletPk, market) { | ||
const openOrdersForMarket = []; | ||
const allOpenOrders = await this.findAllOpenOrders(owner); | ||
allOpenOrders.filter(async (x) => { | ||
const openOrdersAccount = await this.getOpenOrders(x); | ||
if (openOrdersAccount?.market === market) { | ||
openOrdersForMarket.push(x); | ||
} | ||
}); | ||
return allOpenOrders; | ||
} | ||
async createOpenOrdersInstruction(market, accountIndex, name, owner = this.walletPk, delegateAccount, openOrdersIndexer) { | ||
@@ -256,3 +272,3 @@ const ixs = []; | ||
} | ||
const openOrdersAccount = this.findOpenOrders(market, accountIndex, owner); | ||
const openOrdersAccount = this.findOpenOrderAtIndex(owner, accountIndex); | ||
ixs.push(await this.program.methods | ||
@@ -572,2 +588,26 @@ .createOpenOrdersAccount(name) | ||
} | ||
// Consume events for one specific account. Add other extra accounts as it's "free". | ||
async consumeEventsForAccount(marketPublicKey, market, openOrdersAccount) { | ||
const slots = await this.getSlotsToConsume(openOrdersAccount, market); | ||
const allAccounts = await this.getAccountsToConsume(market); | ||
// Create a set to remove duplicates | ||
const uniqueAccounts = new Set([openOrdersAccount, ...allAccounts]); | ||
// Limit extra accounts to 10 due tx limit and add openOrdersAccount | ||
const remainingAccounts = [...uniqueAccounts].slice(0, 10); | ||
const accountsMeta = remainingAccounts.map((remaining) => ({ | ||
pubkey: remaining, | ||
isSigner: false, | ||
isWritable: true, | ||
})); | ||
const ix = await this.program.methods | ||
.consumeGivenEvents(slots) | ||
.accounts({ | ||
eventHeap: market.eventHeap, | ||
market: marketPublicKey, | ||
consumeEventsAdmin: market.consumeEventsAdmin.key, | ||
}) | ||
.remainingAccounts(accountsMeta) | ||
.instruction(); | ||
return await this.sendAndConfirmTransaction([ix]); | ||
} | ||
// In order to get slots for certain key use getSlotsToConsume and include the key in the remainingAccounts | ||
@@ -574,0 +614,0 @@ async consumeGivenEvents(marketPublicKey, market, slots, remainingAccounts) { |
@@ -58,3 +58,5 @@ /// <reference types="bn.js" /> | ||
createOpenOrdersIndexerInstruction(openOrdersIndexer: PublicKey, owner?: PublicKey): Promise<TransactionInstruction>; | ||
findOpenOrders(market: PublicKey, accountIndex: BN, owner: PublicKey): PublicKey; | ||
findAllOpenOrders(owner?: PublicKey): Promise<PublicKey[]>; | ||
findOpenOrderAtIndex(owner: PublicKey | undefined, accountIndex: BN): PublicKey; | ||
findOpenOrdersForMarket(owner: PublicKey | undefined, market: PublicKey): Promise<PublicKey[]>; | ||
createOpenOrdersInstruction(market: PublicKey, accountIndex: BN, name: string, owner: PublicKey | undefined, delegateAccount: PublicKey | null, openOrdersIndexer?: PublicKey): Promise<[TransactionInstruction[], PublicKey]>; | ||
@@ -74,2 +76,3 @@ createOpenOrders(payer: Keypair, market: PublicKey, accountIndex: BN, name: string, owner?: Keypair, openOrdersIndexer?: PublicKey | null): Promise<PublicKey>; | ||
consumeEvents(marketPublicKey: PublicKey, market: MarketAccount, limit: BN, remainingAccounts: PublicKey[]): Promise<TransactionSignature>; | ||
consumeEventsForAccount(marketPublicKey: PublicKey, market: MarketAccount, openOrdersAccount: PublicKey): Promise<TransactionSignature>; | ||
consumeGivenEvents(marketPublicKey: PublicKey, market: MarketAccount, slots: BN[], remainingAccounts: PublicKey[]): Promise<TransactionSignature>; | ||
@@ -76,0 +79,0 @@ pruneOrders(marketPublicKey: PublicKey, market: MarketAccount, openOrdersPublicKey: PublicKey, limit: number, closeMarketAdmin?: Keypair | null): Promise<TransactionSignature>; |
{ | ||
"name": "@openbook-dex/openbook-v2", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Typescript Client for openbook-v2 program.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/openbook-dex/openbook-v2/", |
@@ -28,5 +28,5 @@ # OpenBook V2 | ||
| ---- | ------- | ------------------------------------------- | | ||
| v1.0 | mainnet | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb | | ||
| v1.0 | devnet | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb | | ||
| v1.0 | testnet | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb | | ||
| v1.1 | mainnet | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb | | ||
| v1.1 | devnet | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb | | ||
| v1.1 | testnet | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb | | ||
@@ -33,0 +33,0 @@ ## Building & testing |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
634947
16860