Skip to content

Commit

Permalink
Bugfix orderloss anchor.BN/number conversion (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Apr 23, 2024
1 parent 3d1bcf9 commit 53e73e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
All notable changes to this project will be documented in this file.
Version changes are pinned to SDK releases.

## [1.28.2]
## [1.29.2]

- Bugfix orderloss anchor.BN/number conversion ([#390](https://github.com/zetamarkets/sdk/pull/390))

## [1.29.1]

- Bump placeorder CU units to 400k ([#389](https://github.com/zetamarkets/sdk/pull/389))

## [1.29.0]

- Add airdrop communities ([#386](https://github.com/zetamarkets/sdk/pull/386))

## [1.28.1]

- Trim trailing \0s on referral IDs ([#388](https://github.com/zetamarkets/sdk/pull/388))
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.29.1",
"version": "1.29.2",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/risk-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,14 @@ export function addFakeCancelToAccount(
marginAccount.productLedgers[assetIndex].orderState.openingOrders[1];

if (totalOrders == nativeOrderSize) {
marginAccount.potentialOrderLoss[assetIndex] = 0;
marginAccount.potentialOrderLoss[assetIndex] = new anchor.BN(0);
} else {
let totalMaxLoss = marginAccount.potentialOrderLoss[assetIndex];
let maxLossPerLot = totalMaxLoss / totalOrders;
let averageMaxLoss = maxLossPerLot * nativeOrderSize;
marginAccount.potentialOrderLoss[assetIndex] -= averageMaxLoss;
marginAccount.potentialOrderLoss[assetIndex].sub(
new anchor.BN(averageMaxLoss)
);
}

const cancelOpening = Math.min(
Expand Down

0 comments on commit 53e73e9

Please sign in to comment.