Skip to content

Commit

Permalink
Improve cancelAllMarketOrders for big txs (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Feb 21, 2024
1 parent 7d3b8e6 commit 6d3435a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.
Version changes are pinned to SDK releases.

## [1.21.4]

- Improve cancelAllMarketOrders for big transactions. ([#356](https://github.com/zetamarkets/sdk/pull/356))
- Add txSig to return args of edit trigger order functions. ([#356](https://github.com/zetamarkets/sdk/pull/356))

## [1.21.3]

- Bugfix devnet loading assets in Exchange.load(). ([#355](https://github.com/zetamarkets/sdk/pull/354))
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.21.3",
"version": "1.21.4",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export const CHAINLINK_PID: PublicKey = new PublicKey(
export const MAX_SETTLE_AND_CLOSE_PER_TX = 4;
export const MAX_CANCELS_PER_TX = 3;
export const MAX_CANCELS_PER_TX_LUT = 13;
export const MAX_PRUNE_CANCELS_PER_TX = 3;
export const MAX_PRUNE_CANCELS_PER_TX_LUT = 5;
export const MAX_GREEK_UPDATES_PER_TX = 20;
export const MAX_TRIGGER_CANCELS_PER_TX = 10;
export const MAX_SETTLEMENT_ACCOUNTS = 20;
Expand Down
42 changes: 26 additions & 16 deletions src/cross-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,8 @@ export class CrossClient {
newSide: types.Side,
newOrderType: types.OrderType,
newOptions: types.TriggerOrderOptions = types.defaultTriggerOrderOptions()
) {
await this.editTriggerOrder(
): Promise<TransactionSignature> {
return await this.editTriggerOrder(
orderIndex,
newOrderPrice,
newSize,
Expand All @@ -1482,8 +1482,8 @@ export class CrossClient {
newDirection: types.TriggerDirection,
newOrderType: types.OrderType,
newOptions: types.TriggerOrderOptions = types.defaultTriggerOrderOptions()
) {
await this.editTriggerOrder(
): Promise<TransactionSignature> {
return await this.editTriggerOrder(
orderIndex,
newOrderPrice,
newSize,
Expand All @@ -1506,7 +1506,7 @@ export class CrossClient {
newTriggerTimestamp: anchor.BN,
newOrderType: types.OrderType,
newOptions: types.TriggerOrderOptions = types.defaultTriggerOrderOptions()
) {
): Promise<TransactionSignature> {
let triggerAccount = utils.getTriggerOrder(
Exchange.programId,
this._accountAddress,
Expand Down Expand Up @@ -1611,16 +1611,19 @@ export class CrossClient {
);
}

public async cancelAllMarketOrders(): Promise<TransactionSignature> {
let tx = new Transaction();
public async cancelAllMarketOrders(): Promise<TransactionSignature[]> {
let ixs = [];

for (var asset of Exchange.assets) {
let assetIndex = assetToIndex(asset);
if (this._openOrdersAccounts[assetIndex].equals(PublicKey.default)) {
if (
this.getOrders(asset).length < 1 ||
this._openOrdersAccounts[assetIndex].equals(PublicKey.default)
) {
continue;
}

tx.add(
ixs.push(
instructions.cancelAllMarketOrdersIx(
asset,
this.provider.wallet.publicKey,
Expand All @@ -1629,14 +1632,21 @@ export class CrossClient {
)
);
}
return await utils.processTransaction(
this._provider,
tx,
undefined,
undefined,
undefined,
this._useVersionedTxs ? utils.getZetaLutArr() : undefined

let txs = utils.splitIxsIntoTx(
ixs,
this.useVersionedTxs
? constants.MAX_PRUNE_CANCELS_PER_TX_LUT
: constants.MAX_PRUNE_CANCELS_PER_TX
);
let txIds: string[] = [];
await Promise.all(
txs.map(async (tx) => {
txIds.push(await utils.processTransaction(this._provider, tx));
})
);

return txIds;
}

public createCancelAllMarketOrdersInstruction(
Expand Down

0 comments on commit 6d3435a

Please sign in to comment.