Skip to content

Commit

Permalink
Add optional startIndex to findAvailableTriggerOrderBit (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Jan 30, 2024
1 parent 6a49cd3 commit b505c0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 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.19.1]

- Add optional startIndex to findAvailableTriggerOrderBit(). ([#345](https://github.com/zetamarkets/sdk/pull/345))

## [1.19.0]

- Add instruction to update maker fee percentage. ([#334](https://github.com/zetamarkets/sdk/pull/334))
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.19.0",
"version": "1.19.1",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 7 additions & 2 deletions src/cross-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,12 +1094,17 @@ export class CrossClient {
return txId;
}

public findAvailableTriggerOrderBit(): number {
/**
* Find the next available bit to store a trigger order (0 to 127)
* @param startIndex optional, the index from which to start looking (0 to 127)
* @returns the first available bit (0 to 127)
*/
public findAvailableTriggerOrderBit(startIndex: number = 0): number {
// If we haven't loaded properly for whatever reason just use the last index to minimise the chance of collisions
if (!this.account || !this.account.triggerOrderBits) {
return 127;
}
for (var i = 0; i < 128; i++) {
for (var i = startIndex; i < 128; i++) {
let mask: BN = new BN(1).shln(i); // 1 << i
if (this.account.triggerOrderBits.and(mask).isZero()) {
return i;
Expand Down

0 comments on commit b505c0d

Please sign in to comment.