-
Notifications
You must be signed in to change notification settings - Fork 17
/
close_market.ts
65 lines (57 loc) · 1.77 KB
/
close_market.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { AnchorProvider, BN, Wallet } from "@coral-xyz/anchor";
import { PublicKey, Connection } from "@solana/web3.js";
import { authority } from "./utils";
import { RPC, programId } from "./utils";
import {
OpenBookV2Client,
PlaceOrderArgs,
Side,
} from "@openbook-dex/openbook-v2";
import { MintUtils } from "./mint_utils";
async function main() {
const wallet = new Wallet(authority);
const provider = new AnchorProvider(new Connection(RPC), wallet, {
commitment: "confirmed",
});
const client = new OpenBookV2Client(provider);
const marketPublicKey = new PublicKey(
"BLr5UmvkfoVC4yth5CX2jBT5X75Z61gkLPMbJRNxiRqa"
);
const market = await client.deserializeMarketAccount(marketPublicKey);
if (!market) {
throw "No market";
}
const eventHeap = await client.deserializeEventHeapAccount(market.eventHeap);
if (!eventHeap) {
throw "No event heap";
}
console.log("event heap length", eventHeap.header.count);
if (eventHeap.header.count > 0) {
const accounts = await client.getAccountsToConsume(market);
if (accounts) {
console.log("accounts lenght", accounts.length);
const ix = await client.consumeEventsIx(
marketPublicKey,
market,
new BN(8),
accounts
);
const tx = await client.sendAndConfirmTransaction([ix], {
additionalSigners: [],
});
console.log("Consumed events ", tx);
}
}
// // const tx2= await client.pruneOrders(marketPublicKey, market, openOrdersPublicKey, 5, wallet.payer)
const [ix, signers] = await client.closeMarketIx(
marketPublicKey,
market,
wallet.publicKey,
wallet.payer
);
const tx = await client.sendAndConfirmTransaction([ix], {
additionalSigners: [signers],
});
console.log("Closed market ", tx);
}
main();