Skip to content

Commit

Permalink
bump client
Browse files Browse the repository at this point in the history
  • Loading branch information
binyebarwe committed Dec 5, 2023
1 parent 1899fa2 commit 71375c3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openbook-dex/openbook-v2",
"version": "0.0.17",
"version": "0.0.19",
"description": "Typescript Client for openbook-v2 program.",
"repository": "https://github.com/openbook-dex/openbook-v2/",
"author": {
Expand Down
58 changes: 42 additions & 16 deletions ts/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ export class OpenBookV2Client {
return address.publicKey;
}

public async createProgramAccountIx(
authority: PublicKey,
size: number,
): Promise<[TransactionInstruction, Signer]> {
const lamports = await this.connection.getMinimumBalanceForRentExemption(
size,
);
const address = Keypair.generate();

const ix = SystemProgram.createAccount({
fromPubkey: authority,
newAccountPubkey: address.publicKey,
lamports,
space: size,
programId: this.programId,
});
return [ix, address];
}

// Get the MarketAccount from the market publicKey
public async getMarketAccount(
publicKey: PublicKey,
Expand Down Expand Up @@ -218,7 +237,7 @@ export class OpenBookV2Client {
}

public async createMarket(
payer: Keypair,
payer: PublicKey,
name: string,
quoteMint: PublicKey,
baseMint: PublicKey,
Expand All @@ -238,10 +257,19 @@ export class OpenBookV2Client {
},
market = Keypair.generate(),
collectFeeAdmin?: PublicKey,
): Promise<PublicKey> {
const bids = await this.createProgramAccount(payer, BooksideSpace);
const asks = await this.createProgramAccount(payer, BooksideSpace);
const eventHeap = await this.createProgramAccount(payer, EventHeapSpace);
): Promise<[TransactionInstruction[], Signer[]]> {
const [bidIx, bidsKeypair] = await this.createProgramAccountIx(
payer,
BooksideSpace,
);
const [askIx, askKeypair] = await this.createProgramAccountIx(
payer,
BooksideSpace,
);
const [eventHeapIx, eventHeapKeypair] = await this.createProgramAccountIx(
payer,
EventHeapSpace,
);

const [marketAuthority] = PublicKey.findProgramAddressSync(
[Buffer.from('Market'), market.publicKey.toBuffer()],
Expand Down Expand Up @@ -278,10 +306,10 @@ export class OpenBookV2Client {
.accounts({
market: market.publicKey,
marketAuthority,
bids,
asks,
eventHeap,
payer: payer.publicKey,
bids: bidsKeypair.publicKey,
asks: askKeypair.publicKey,
eventHeap: eventHeapKeypair.publicKey,
payer,
marketBaseVault: baseVault,
marketQuoteVault: quoteVault,
baseMint,
Expand All @@ -291,8 +319,7 @@ export class OpenBookV2Client {
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
oracleA,
oracleB,
collectFeeAdmin:
collectFeeAdmin != null ? collectFeeAdmin : payer.publicKey,
collectFeeAdmin: collectFeeAdmin != null ? collectFeeAdmin : payer,
openOrdersAdmin,
consumeEventsAdmin,
closeMarketAdmin,
Expand All @@ -301,11 +328,10 @@ export class OpenBookV2Client {
})
.instruction();

await this.sendAndConfirmTransaction([ix], {
additionalSigners: [payer, market],
});

return market.publicKey;
return [
[bidIx, askIx, eventHeapIx, ix],
[market, bidsKeypair, askKeypair, eventHeapKeypair],
];
}

// Book and EventHeap must be empty before closing a market.
Expand Down

0 comments on commit 71375c3

Please sign in to comment.