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

Add crank generation ix #383

Merged
merged 2 commits into from
Apr 11, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
Version changes are pinned to SDK releases.

## [1.26.3]

- Add crank market generation util. ([#383](https://github.com/zetamarkets/sdk/pull/383))

## [1.26.2]

- Spam sendRawTransaction() in utils.processTransaction(). ([#381](https://github.com/zetamarkets/sdk/pull/381))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zetamarkets/sdk",
"repository": "https://github.com/zetamarkets/sdk/",
"version": "1.26.2",
"version": "1.26.3",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
45 changes: 26 additions & 19 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,28 @@ export async function crankMarket(
openOrdersToMargin?: Map<PublicKey, PublicKey>,
crankLimit?: number
): Promise<boolean> {
let ix = await createCrankMarketIx(asset, openOrdersToMargin, crankLimit);
if (ix == null) return true;
let tx = new Transaction()
.add(
ComputeBudgetProgram.setComputeUnitLimit({
units: 250_000,
})
)
.add(ix);
await processTransaction(Exchange.provider, tx);
return false;
}

export async function createCrankMarketIx(
asset: Asset,
openOrdersToMargin?: Map<PublicKey, PublicKey>,
crankLimit?: number
): Promise<TransactionInstruction | null> {
let market = Exchange.getPerpMarket(asset);
let eventQueue = await market.serumMarket.loadEventQueue(Exchange.connection);
if (eventQueue.length == 0) {
return true;
return null;
}
const openOrdersSet = new Set();
// We pass in a couple of extra accounts for perps so the limit is lower
Expand All @@ -1353,7 +1371,6 @@ export async function crankMarket(

let remainingAccounts: any[] = new Array(uniqueOpenOrders.length * 2);

// TODO test support for both crossmargin and marginaccounts
await Promise.all(
uniqueOpenOrders.map(async (openOrders, index) => {
let marginAccount: PublicKey;
Expand All @@ -1380,23 +1397,13 @@ export async function crankMarket(
})
);

let tx = new Transaction()
.add(
ComputeBudgetProgram.setComputeUnitLimit({
units: 250_000,
})
)
.add(
instructions.crankMarketIx(
asset,
market.address,
market.serumMarket.eventQueueAddress,
constants.DEX_PID[Exchange.network],
remainingAccounts
)
);
await processTransaction(Exchange.provider, tx);
return false;
return instructions.crankMarketIx(
asset,
market.address,
market.serumMarket.eventQueueAddress,
constants.DEX_PID[Exchange.network],
remainingAccounts
);
}

/*
Expand Down