Skip to content

Commit

Permalink
Remove throw if no open orders account (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Feb 6, 2024
1 parent 10f0e00 commit 6070e90
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 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.20.2]

- Relax throwing if no open orders account is detected in some client functions. ([#349](https://github.com/zetamarkets/sdk/pull/349))

## [1.20.1]

- Improve tx confirmations by polling. ([#347](https://github.com/zetamarkets/sdk/pull/347))
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.20.1",
"version": "1.20.2",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
27 changes: 20 additions & 7 deletions src/cross-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,11 +1253,17 @@ export class CrossClient {
options: types.TriggerOrderOptions = types.defaultTriggerOrderOptions()
): TransactionInstruction {
let assetIndex = assets.assetToIndex(asset);

let openOrdersAccount = this._openOrdersAccounts[assetIndex];
if (this._openOrdersAccounts[assetIndex].equals(PublicKey.default)) {
throw Error("User has no open orders account.");
// This account won't be created unless explicitly done so before this instruction
// Purposely don't throw because there are some frontend cases which do more complicated tx building
openOrdersAccount = utils.getCrossOpenOrders(
Exchange.programId,
Exchange.getPerpMarket(asset).address,
this._accountAddress
)[0];
console.warn(`No open orders account for ${assetToName(asset)}`);
}
let openOrdersPda = this._openOrdersAccounts[assetIndex];

return instructions.placeTriggerOrderIx(
asset,
Expand All @@ -1273,7 +1279,7 @@ export class CrossClient {
options.tag,
this.accountAddress,
this._provider.wallet.publicKey,
openOrdersPda
openOrdersAccount
);
}

Expand Down Expand Up @@ -1716,9 +1722,16 @@ export class CrossClient {
options: types.OrderOptions = types.defaultOrderOptions()
): TransactionInstruction {
let assetIndex = assetToIndex(asset);
let openOrdersAccount = this._openOrdersAccounts[assetIndex];
if (this._openOrdersAccounts[assetIndex].equals(PublicKey.default)) {
console.log(`No open orders account for ${assetToName(asset)}`);
throw Error("User does not have an open orders account.");
// This account won't be created unless explicitly done so before this instruction
// Purposely don't throw because there are some frontend cases which do more complicated tx building
openOrdersAccount = utils.getCrossOpenOrders(
Exchange.programId,
Exchange.getPerpMarket(asset).address,
this._accountAddress
)[0];
console.warn(`No open orders account for ${assetToName(asset)}`);
}

let market = Exchange.getPerpMarket(asset);
Expand All @@ -1738,7 +1751,7 @@ export class CrossClient {
tifOffset,
this.accountAddress,
this._provider.wallet.publicKey,
this._openOrdersAccounts[assetIndex],
openOrdersAccount,
this._whitelistTradingFeesAddress
);
}
Expand Down

0 comments on commit 6070e90

Please sign in to comment.