Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: smol update #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# OpenBook V2 scripts

Different script with examples showcasing @openbook-dex/openbook-v2
Different script with examples showcasing @openbook-dex/openbook-v2
18 changes: 10 additions & 8 deletions cancelAndPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
OpenBookV2Client,
PlaceOrderArgs,
Side,
OrderType,
SelfTradeBehavior,
PlaceMultipleOrdersArgs,
Market,
} from "@openbook-dex/openbook-v2";
import { MintUtils } from "./mint_utils";

Expand All @@ -32,21 +31,21 @@ async function main() {
}
const openOrdersPublicKey = ooa[0];

const market = await client.deserializeMarketAccount(marketPublicKey);
const market = await Market.load(client, marketPublicKey);
if (!market) {
throw "No market";
}

let mintUtils = new MintUtils(provider.connection, authority);

const userQuoteAcc = await mintUtils.getOrCreateTokenAccount(
market?.quoteMint,
market?.account.quoteMint,
authority,
client.walletPk
);

const userBaseAcc = await mintUtils.getOrCreateTokenAccount(
market?.baseMint,
market?.account.baseMint,
authority,
client.walletPk
);
Expand All @@ -69,22 +68,25 @@ async function main() {
});
}

let ImmediateOrCancel = { decrementTake: {} };

const [ix, signers] = await client.cancelAllAndPlaceOrdersIx(
openOrdersPublicKey,
marketPublicKey,
market,
market.account,
userBaseAcc.address,
userQuoteAcc.address,
null,
OrderType.ImmediateOrCancel,
ImmediateOrCancel,
bids,
asks
);

const tx = await client.sendAndConfirmTransaction([ix], {
additionalSigners: [signers],
});

console.log("Cancel and place order ", tx);
}

main();
main().catch((err) => console.error(err));
15 changes: 9 additions & 6 deletions close_market.ts → closeMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
OpenBookV2Client,
PlaceOrderArgs,
Side,
Market,
} from "@openbook-dex/openbook-v2";
import { MintUtils } from "./mint_utils";

Expand All @@ -19,25 +20,27 @@ async function main() {
const marketPublicKey = new PublicKey(
"BLr5UmvkfoVC4yth5CX2jBT5X75Z61gkLPMbJRNxiRqa"
);
const market = await client.deserializeMarketAccount(marketPublicKey);
const market = await Market.load(client, marketPublicKey);
if (!market) {
throw "No market";
}

const eventHeap = await client.deserializeEventHeapAccount(market.eventHeap);
const eventHeap = await client.deserializeEventHeapAccount(
market.account.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);
const accounts = await client.getAccountsToConsume(market.account);
if (accounts) {
console.log("accounts lenght", accounts.length);

const ix = await client.consumeEventsIx(
marketPublicKey,
market,
market.account,
new BN(8),
accounts
);
Expand All @@ -52,7 +55,7 @@ async function main() {

const [ix, signers] = await client.closeMarketIx(
marketPublicKey,
market,
market.account,
wallet.publicKey,
wallet.payer
);
Expand All @@ -62,4 +65,4 @@ async function main() {
console.log("Closed market ", tx);
}

main();
main().catch((err) => console.error(err));
2 changes: 1 addition & 1 deletion closeOpenOrdersAcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ async function main() {
});
console.log("close open orders acc", tx);
}
main();
main().catch((err) => console.error(err));
2 changes: 1 addition & 1 deletion create_ltu.ts → createLtu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ async function main() {
);
}

main();
main().catch((err) => console.error(err));
2 changes: 1 addition & 1 deletion createMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ async function main() {
);
}

main();
main().catch((err) => console.error(err));
5 changes: 3 additions & 2 deletions createOpenOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async function main() {
);

const tx = await client.createOpenOrders(wallet.payer, market, "name");
console.log("created open orders acc", tx);
console.log("created open orders acc", tx.toBase58());
}
main();

main().catch((err) => console.error(err));
2 changes: 1 addition & 1 deletion createPermissionedMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ async function main() {
);
}

main();
main().catch((err) => console.error(err));
2 changes: 1 addition & 1 deletion getMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ async function main() {
console.log(markets);
}

main();
main().catch((err) => console.error(err));
9 changes: 5 additions & 4 deletions getTotalAmounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PlaceOrderArgs,
Side,
IDL,
Market,
} from "@openbook-dex/openbook-v2";
import { toUiDecimals } from "@openbook-dex/openbook-v2";
import { quoteLotsToUi } from "@openbook-dex/openbook-v2";
Expand All @@ -24,7 +25,7 @@ async function main() {
);
const owner = new PublicKey("J9zjCmmGBfv6wDSwmRW43vVJ6vooCftXjQYtc7uhETdr");

const market = await client.deserializeMarketAccount(marketPubkey);
const market = await Market.load(client, marketPubkey);

if (market === null) {
throw "No market";
Expand All @@ -36,8 +37,8 @@ async function main() {
const openOrder = await client.deserializeOpenOrderAccount(openOrderPubkey);

if (openOrder) {
if (openOrder.version != 1){
throw "using an old open orders account, please close it"
if (openOrder.version != 1) {
throw "using an old open orders account, please close it";
}
console.log("bidsQuoteLots", openOrder.position.bidsQuoteLots.toNumber());
console.log("asksBaseLots", openOrder.position.asksBaseLots.toNumber());
Expand All @@ -52,4 +53,4 @@ function priceData(key: BN) {
return shiftedValue.toNumber(); // Convert BN to a regular number
}

main();
main().catch((err) => console.error(err));
Loading