Skip to content

Commit

Permalink
Add crank generation ix (#383)
Browse files Browse the repository at this point in the history
* Add crank generation ix

* Push
  • Loading branch information
xjcaa authored Apr 11, 2024
1 parent 624177a commit 52ef1c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
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

0 comments on commit 52ef1c2

Please sign in to comment.