@drift-labs/sdk 2.4.0-beta.0 → 2.5.0
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.
- package/lib/dlob/DLOB.js +5 -2
- package/lib/driftClient.js +2 -1
- package/lib/idl/drift.json +1 -1
- package/lib/math/position.js +1 -3
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/dlob/DLOB.ts +6 -2
- package/src/driftClient.ts +6 -1
- package/src/idl/drift.json +1 -1
- package/src/math/position.ts +2 -4
- package/src/types.ts +1 -0
package/lib/dlob/DLOB.js
CHANGED
|
@@ -171,8 +171,11 @@ class DLOB {
|
|
|
171
171
|
if (order.baseAssetAmountFilled.eq(cumulativeBaseAssetAmountFilled)) {
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
const newOrder = {
|
|
175
|
+
...order,
|
|
176
|
+
};
|
|
177
|
+
newOrder.baseAssetAmountFilled = cumulativeBaseAssetAmountFilled;
|
|
178
|
+
(_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.update(newOrder, userAccount);
|
|
176
179
|
if (onUpdate) {
|
|
177
180
|
onUpdate();
|
|
178
181
|
}
|
package/lib/driftClient.js
CHANGED
|
@@ -358,9 +358,10 @@ class DriftClient {
|
|
|
358
358
|
});
|
|
359
359
|
}
|
|
360
360
|
async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0) {
|
|
361
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
361
362
|
return await this.program.rpc.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled, {
|
|
362
363
|
accounts: {
|
|
363
|
-
user:
|
|
364
|
+
user: userAccountPublicKey,
|
|
364
365
|
authority: this.wallet.publicKey,
|
|
365
366
|
},
|
|
366
367
|
});
|
package/lib/idl/drift.json
CHANGED
package/lib/math/position.js
CHANGED
|
@@ -87,9 +87,7 @@ function calculateClaimablePnl(market, spotMarket, perpPosition, oraclePriceData
|
|
|
87
87
|
let unsettledPnl = unrealizedPnl.add(fundingPnL);
|
|
88
88
|
if (unrealizedPnl.gt(numericConstants_1.ZERO)) {
|
|
89
89
|
const excessPnlPool = __1.BN.max(numericConstants_1.ZERO, (0, market_1.calculateNetUserPnlImbalance)(market, spotMarket, oraclePriceData).mul(new __1.BN(-1)));
|
|
90
|
-
const maxPositivePnl = __1.BN.max(perpPosition.quoteAssetAmount
|
|
91
|
-
.sub(perpPosition.quoteEntryAmount)
|
|
92
|
-
.add(excessPnlPool), numericConstants_1.ZERO);
|
|
90
|
+
const maxPositivePnl = __1.BN.max(perpPosition.quoteAssetAmount.sub(perpPosition.quoteEntryAmount), numericConstants_1.ZERO).add(excessPnlPool);
|
|
93
91
|
unsettledPnl = __1.BN.min(maxPositivePnl, unrealizedPnl);
|
|
94
92
|
}
|
|
95
93
|
return unsettledPnl;
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"prettier": "^2.4.1",
|
|
58
58
|
"ts-node": "^10.8.0"
|
|
59
59
|
},
|
|
60
|
-
"description": "SDK for Drift Protocol
|
|
60
|
+
"description": "SDK for Drift Protocol",
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=12"
|
|
63
63
|
}
|
package/src/dlob/DLOB.ts
CHANGED
|
@@ -270,8 +270,12 @@ export class DLOB {
|
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
const newOrder = {
|
|
274
|
+
...order,
|
|
275
|
+
};
|
|
276
|
+
newOrder.baseAssetAmountFilled = cumulativeBaseAssetAmountFilled;
|
|
277
|
+
|
|
278
|
+
this.getListForOrder(order)?.update(newOrder, userAccount);
|
|
275
279
|
|
|
276
280
|
if (onUpdate) {
|
|
277
281
|
onUpdate();
|
package/src/driftClient.ts
CHANGED
|
@@ -590,12 +590,17 @@ export class DriftClient {
|
|
|
590
590
|
marginTradingEnabled: boolean,
|
|
591
591
|
subAccountId = 0
|
|
592
592
|
): Promise<TransactionSignature> {
|
|
593
|
+
const userAccountPublicKey = getUserAccountPublicKeySync(
|
|
594
|
+
this.program.programId,
|
|
595
|
+
this.wallet.publicKey,
|
|
596
|
+
subAccountId
|
|
597
|
+
);
|
|
593
598
|
return await this.program.rpc.updateUserMarginTradingEnabled(
|
|
594
599
|
subAccountId,
|
|
595
600
|
marginTradingEnabled,
|
|
596
601
|
{
|
|
597
602
|
accounts: {
|
|
598
|
-
user:
|
|
603
|
+
user: userAccountPublicKey,
|
|
599
604
|
authority: this.wallet.publicKey,
|
|
600
605
|
},
|
|
601
606
|
}
|
package/src/idl/drift.json
CHANGED
package/src/math/position.ts
CHANGED
|
@@ -151,11 +151,9 @@ export function calculateClaimablePnl(
|
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
const maxPositivePnl = BN.max(
|
|
154
|
-
perpPosition.quoteAssetAmount
|
|
155
|
-
.sub(perpPosition.quoteEntryAmount)
|
|
156
|
-
.add(excessPnlPool),
|
|
154
|
+
perpPosition.quoteAssetAmount.sub(perpPosition.quoteEntryAmount),
|
|
157
155
|
ZERO
|
|
158
|
-
);
|
|
156
|
+
).add(excessPnlPool);
|
|
159
157
|
|
|
160
158
|
unsettledPnl = BN.min(maxPositivePnl, unrealizedPnl);
|
|
161
159
|
}
|