diff --git a/CHANGELOG.md b/CHANGELOG.md index 91f5734ee..ae006c8e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/package.json b/package.json index 050de25da..02fbac6e6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/constants.ts b/src/constants.ts index d247221b3..f9889424e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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; diff --git a/src/cross-client.ts b/src/cross-client.ts index bc87db7a6..1da9873c7 100644 --- a/src/cross-client.ts +++ b/src/cross-client.ts @@ -1459,8 +1459,8 @@ export class CrossClient { newSide: types.Side, newOrderType: types.OrderType, newOptions: types.TriggerOrderOptions = types.defaultTriggerOrderOptions() - ) { - await this.editTriggerOrder( + ): Promise { + return await this.editTriggerOrder( orderIndex, newOrderPrice, newSize, @@ -1482,8 +1482,8 @@ export class CrossClient { newDirection: types.TriggerDirection, newOrderType: types.OrderType, newOptions: types.TriggerOrderOptions = types.defaultTriggerOrderOptions() - ) { - await this.editTriggerOrder( + ): Promise { + return await this.editTriggerOrder( orderIndex, newOrderPrice, newSize, @@ -1506,7 +1506,7 @@ export class CrossClient { newTriggerTimestamp: anchor.BN, newOrderType: types.OrderType, newOptions: types.TriggerOrderOptions = types.defaultTriggerOrderOptions() - ) { + ): Promise { let triggerAccount = utils.getTriggerOrder( Exchange.programId, this._accountAddress, @@ -1611,16 +1611,19 @@ export class CrossClient { ); } - public async cancelAllMarketOrders(): Promise { - let tx = new Transaction(); + public async cancelAllMarketOrders(): Promise { + 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, @@ -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(