@drift-labs/sdk 2.16.0-beta.0 → 2.16.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -366,11 +366,16 @@ class DriftClient {
366
366
  }
367
367
  async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0) {
368
368
  const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
369
+ await this.addUser(subAccountId);
370
+ const remainingAccounts = this.getRemainingAccounts({
371
+ userAccounts: [this.getUserAccount(subAccountId)],
372
+ });
369
373
  const tx = await this.program.transaction.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled, {
370
374
  accounts: {
371
375
  user: userAccountPublicKey,
372
376
  authority: this.wallet.publicKey,
373
377
  },
378
+ remainingAccounts,
374
379
  });
375
380
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
376
381
  return txSig;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.16.0-beta.0",
2
+ "version": "2.16.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -8569,6 +8569,11 @@
8569
8569
  "code": 6225,
8570
8570
  "name": "InvalidOracleForSettlePnl",
8571
8571
  "msg": "InvalidOracleForSettlePnl"
8572
+ },
8573
+ {
8574
+ "code": 6226,
8575
+ "name": "MarginOrdersOpen",
8576
+ "msg": "MarginOrdersOpen"
8572
8577
  }
8573
8578
  ]
8574
8579
  }
@@ -12,9 +12,7 @@ imfFactor, liabilityWeight, precision) {
12
12
  return liabilityWeight;
13
13
  }
14
14
  const sizeSqrt = utils_1.squareRootBN(size.abs().mul(new anchor_1.BN(10)).add(new anchor_1.BN(1))); //1e9 -> 1e10 -> 1e5
15
- const denom0 = anchor_1.BN.max(new anchor_1.BN(1), numericConstants_1.SPOT_MARKET_IMF_PRECISION.div(imfFactor));
16
- assert_1.assert(denom0.gt(numericConstants_1.ZERO));
17
- const liabilityWeightNumerator = liabilityWeight.sub(liabilityWeight.div(anchor_1.BN.max(new anchor_1.BN(1), numericConstants_1.SPOT_MARKET_IMF_PRECISION.div(imfFactor))));
15
+ const liabilityWeightNumerator = liabilityWeight.sub(liabilityWeight.div(new anchor_1.BN(5)));
18
16
  const denom = new anchor_1.BN(100000).mul(numericConstants_1.SPOT_MARKET_IMF_PRECISION).div(precision);
19
17
  assert_1.assert(denom.gt(numericConstants_1.ZERO));
20
18
  const sizePremiumLiabilityWeight = liabilityWeightNumerator.add(sizeSqrt // 1e5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.16.0-beta.0",
3
+ "version": "2.16.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -612,6 +612,12 @@ export class DriftClient {
612
612
  this.wallet.publicKey,
613
613
  subAccountId
614
614
  );
615
+
616
+ await this.addUser(subAccountId);
617
+ const remainingAccounts = this.getRemainingAccounts({
618
+ userAccounts: [this.getUserAccount(subAccountId)],
619
+ });
620
+
615
621
  const tx = await this.program.transaction.updateUserMarginTradingEnabled(
616
622
  subAccountId,
617
623
  marginTradingEnabled,
@@ -620,6 +626,7 @@ export class DriftClient {
620
626
  user: userAccountPublicKey,
621
627
  authority: this.wallet.publicKey,
622
628
  },
629
+ remainingAccounts,
623
630
  }
624
631
  );
625
632
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.16.0-beta.0",
2
+ "version": "2.16.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -8569,6 +8569,11 @@
8569
8569
  "code": 6225,
8570
8570
  "name": "InvalidOracleForSettlePnl",
8571
8571
  "msg": "InvalidOracleForSettlePnl"
8572
+ },
8573
+ {
8574
+ "code": 6226,
8575
+ "name": "MarginOrdersOpen",
8576
+ "msg": "MarginOrdersOpen"
8572
8577
  }
8573
8578
  ]
8574
8579
  }
@@ -24,12 +24,8 @@ export function calculateSizePremiumLiabilityWeight(
24
24
 
25
25
  const sizeSqrt = squareRootBN(size.abs().mul(new BN(10)).add(new BN(1))); //1e9 -> 1e10 -> 1e5
26
26
 
27
- const denom0 = BN.max(new BN(1), SPOT_MARKET_IMF_PRECISION.div(imfFactor));
28
- assert(denom0.gt(ZERO));
29
27
  const liabilityWeightNumerator = liabilityWeight.sub(
30
- liabilityWeight.div(
31
- BN.max(new BN(1), SPOT_MARKET_IMF_PRECISION.div(imfFactor))
32
- )
28
+ liabilityWeight.div(new BN(5))
33
29
  );
34
30
 
35
31
  const denom = new BN(100_000).mul(SPOT_MARKET_IMF_PRECISION).div(precision);