@drift-labs/sdk 2.45.0-beta.5 → 2.46.0-beta.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/README.md +1 -1
- package/VERSION +1 -1
- package/lib/adminClient.d.ts +1 -0
- package/lib/adminClient.js +8 -0
- package/lib/idl/drift.json +28 -3
- package/lib/math/orders.js +15 -1
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/adminClient.ts +14 -0
- package/src/idl/drift.json +29 -4
- package/src/math/orders.ts +21 -3
- package/src/types.ts +1 -0
- package/tests/dlob/helpers.ts +1 -0
- package/tests/dlob/test.ts +47 -0
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ The Drift SDK uses some common precisions, which are available as constants to i
|
|
|
57
57
|
|
|
58
58
|
**Important Note for BigNum division**
|
|
59
59
|
|
|
60
|
-
Because BN only supports integers, you need to be conscious of the numbers you are using when dividing. BN will return the floor when using the regular division function; if you want to get the exact
|
|
60
|
+
Because BN only supports integers, you need to be conscious of the numbers you are using when dividing. BN will return the floor when using the regular division function; if you want to get the exact division, you need to add the modulus of the two numbers as well. There is a helper function `convertToNumber` in the SDK which will do this for you.
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
import {convertToNumber} from @drift-labs/sdk
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.46.0-beta.0
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare class AdminClient extends DriftClient {
|
|
|
36
36
|
updateLiquidationMarginBufferRatio(updateLiquidationMarginBufferRatio: number): Promise<TransactionSignature>;
|
|
37
37
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
38
38
|
updateStateSettlementDuration(settlementDuration: number): Promise<TransactionSignature>;
|
|
39
|
+
updateStateMaxNumberOfSubAccounts(maxNumberOfSubAccounts: number): Promise<TransactionSignature>;
|
|
39
40
|
updateWithdrawGuardThreshold(spotMarketIndex: number, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
|
|
40
41
|
updateSpotMarketIfFactor(spotMarketIndex: number, userIfFactor: BN, totalIfFactor: BN): Promise<TransactionSignature>;
|
|
41
42
|
updateSpotMarketRevenueSettlePeriod(spotMarketIndex: number, revenueSettlePeriod: BN): Promise<TransactionSignature>;
|
package/lib/adminClient.js
CHANGED
|
@@ -447,6 +447,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
447
447
|
},
|
|
448
448
|
});
|
|
449
449
|
}
|
|
450
|
+
async updateStateMaxNumberOfSubAccounts(maxNumberOfSubAccounts) {
|
|
451
|
+
return await this.program.rpc.updateStateMaxNumberOfSubAccounts(maxNumberOfSubAccounts, {
|
|
452
|
+
accounts: {
|
|
453
|
+
admin: this.wallet.publicKey,
|
|
454
|
+
state: await this.getStatePublicKey(),
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
}
|
|
450
458
|
async updateWithdrawGuardThreshold(spotMarketIndex, withdrawGuardThreshold) {
|
|
451
459
|
const tx = await this.program.transaction.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
|
|
452
460
|
accounts: {
|
package/lib/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.45.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -4163,6 +4163,27 @@
|
|
|
4163
4163
|
}
|
|
4164
4164
|
]
|
|
4165
4165
|
},
|
|
4166
|
+
{
|
|
4167
|
+
"name": "updateStateMaxNumberOfSubAccounts",
|
|
4168
|
+
"accounts": [
|
|
4169
|
+
{
|
|
4170
|
+
"name": "admin",
|
|
4171
|
+
"isMut": false,
|
|
4172
|
+
"isSigner": true
|
|
4173
|
+
},
|
|
4174
|
+
{
|
|
4175
|
+
"name": "state",
|
|
4176
|
+
"isMut": true,
|
|
4177
|
+
"isSigner": false
|
|
4178
|
+
}
|
|
4179
|
+
],
|
|
4180
|
+
"args": [
|
|
4181
|
+
{
|
|
4182
|
+
"name": "maxNumberOfSubAccounts",
|
|
4183
|
+
"type": "u16"
|
|
4184
|
+
}
|
|
4185
|
+
]
|
|
4186
|
+
},
|
|
4166
4187
|
{
|
|
4167
4188
|
"name": "updatePerpMarketOracle",
|
|
4168
4189
|
"accounts": [
|
|
@@ -5722,12 +5743,16 @@
|
|
|
5722
5743
|
"name": "initialPctToLiquidate",
|
|
5723
5744
|
"type": "u16"
|
|
5724
5745
|
},
|
|
5746
|
+
{
|
|
5747
|
+
"name": "maxNumberOfSubAccounts",
|
|
5748
|
+
"type": "u16"
|
|
5749
|
+
},
|
|
5725
5750
|
{
|
|
5726
5751
|
"name": "padding",
|
|
5727
5752
|
"type": {
|
|
5728
5753
|
"array": [
|
|
5729
5754
|
"u8",
|
|
5730
|
-
|
|
5755
|
+
12
|
|
5731
5756
|
]
|
|
5732
5757
|
}
|
|
5733
5758
|
}
|
|
@@ -10898,7 +10923,7 @@
|
|
|
10898
10923
|
{
|
|
10899
10924
|
"code": 6221,
|
|
10900
10925
|
"name": "SpotFulfillmentConfigDisabled",
|
|
10901
|
-
"msg": "Spot
|
|
10926
|
+
"msg": "Spot Fulfillment Config Disabled"
|
|
10902
10927
|
},
|
|
10903
10928
|
{
|
|
10904
10929
|
"code": 6222,
|
package/lib/math/orders.js
CHANGED
|
@@ -204,7 +204,21 @@ function isTriggered(order) {
|
|
|
204
204
|
}
|
|
205
205
|
exports.isTriggered = isTriggered;
|
|
206
206
|
function isRestingLimitOrder(order, slot) {
|
|
207
|
-
|
|
207
|
+
if (!isLimitOrder(order)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
if ((0, types_1.isVariant)(order.orderType, 'triggerLimit')) {
|
|
211
|
+
if ((0, types_1.isVariant)(order.direction, 'long') &&
|
|
212
|
+
order.triggerPrice.lt(order.price)) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
else if ((0, types_1.isVariant)(order.direction, 'short') &&
|
|
216
|
+
order.triggerPrice.gt(order.price)) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
return (0, auction_1.isAuctionComplete)(order, slot);
|
|
220
|
+
}
|
|
221
|
+
return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
|
|
208
222
|
}
|
|
209
223
|
exports.isRestingLimitOrder = isRestingLimitOrder;
|
|
210
224
|
function isTakingOrder(order, slot) {
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/adminClient.ts
CHANGED
|
@@ -832,6 +832,20 @@ export class AdminClient extends DriftClient {
|
|
|
832
832
|
);
|
|
833
833
|
}
|
|
834
834
|
|
|
835
|
+
public async updateStateMaxNumberOfSubAccounts(
|
|
836
|
+
maxNumberOfSubAccounts: number
|
|
837
|
+
): Promise<TransactionSignature> {
|
|
838
|
+
return await this.program.rpc.updateStateMaxNumberOfSubAccounts(
|
|
839
|
+
maxNumberOfSubAccounts,
|
|
840
|
+
{
|
|
841
|
+
accounts: {
|
|
842
|
+
admin: this.wallet.publicKey,
|
|
843
|
+
state: await this.getStatePublicKey(),
|
|
844
|
+
},
|
|
845
|
+
}
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
|
|
835
849
|
public async updateWithdrawGuardThreshold(
|
|
836
850
|
spotMarketIndex: number,
|
|
837
851
|
withdrawGuardThreshold: BN
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.45.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -4163,6 +4163,27 @@
|
|
|
4163
4163
|
}
|
|
4164
4164
|
]
|
|
4165
4165
|
},
|
|
4166
|
+
{
|
|
4167
|
+
"name": "updateStateMaxNumberOfSubAccounts",
|
|
4168
|
+
"accounts": [
|
|
4169
|
+
{
|
|
4170
|
+
"name": "admin",
|
|
4171
|
+
"isMut": false,
|
|
4172
|
+
"isSigner": true
|
|
4173
|
+
},
|
|
4174
|
+
{
|
|
4175
|
+
"name": "state",
|
|
4176
|
+
"isMut": true,
|
|
4177
|
+
"isSigner": false
|
|
4178
|
+
}
|
|
4179
|
+
],
|
|
4180
|
+
"args": [
|
|
4181
|
+
{
|
|
4182
|
+
"name": "maxNumberOfSubAccounts",
|
|
4183
|
+
"type": "u16"
|
|
4184
|
+
}
|
|
4185
|
+
]
|
|
4186
|
+
},
|
|
4166
4187
|
{
|
|
4167
4188
|
"name": "updatePerpMarketOracle",
|
|
4168
4189
|
"accounts": [
|
|
@@ -5722,12 +5743,16 @@
|
|
|
5722
5743
|
"name": "initialPctToLiquidate",
|
|
5723
5744
|
"type": "u16"
|
|
5724
5745
|
},
|
|
5746
|
+
{
|
|
5747
|
+
"name": "maxNumberOfSubAccounts",
|
|
5748
|
+
"type": "u16"
|
|
5749
|
+
},
|
|
5725
5750
|
{
|
|
5726
5751
|
"name": "padding",
|
|
5727
5752
|
"type": {
|
|
5728
5753
|
"array": [
|
|
5729
5754
|
"u8",
|
|
5730
|
-
|
|
5755
|
+
12
|
|
5731
5756
|
]
|
|
5732
5757
|
}
|
|
5733
5758
|
}
|
|
@@ -10898,7 +10923,7 @@
|
|
|
10898
10923
|
{
|
|
10899
10924
|
"code": 6221,
|
|
10900
10925
|
"name": "SpotFulfillmentConfigDisabled",
|
|
10901
|
-
"msg": "Spot
|
|
10926
|
+
"msg": "Spot Fulfillment Config Disabled"
|
|
10902
10927
|
},
|
|
10903
10928
|
{
|
|
10904
10929
|
"code": 6222,
|
|
@@ -11071,4 +11096,4 @@
|
|
|
11071
11096
|
"msg": "InvalidMarginCalculation"
|
|
11072
11097
|
}
|
|
11073
11098
|
]
|
|
11074
|
-
}
|
|
11099
|
+
}
|
package/src/math/orders.ts
CHANGED
|
@@ -322,9 +322,27 @@ export function isTriggered(order: Order): boolean {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
export function isRestingLimitOrder(order: Order, slot: number): boolean {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
325
|
+
if (!isLimitOrder(order)) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (isVariant(order.orderType, 'triggerLimit')) {
|
|
330
|
+
if (
|
|
331
|
+
isVariant(order.direction, 'long') &&
|
|
332
|
+
order.triggerPrice.lt(order.price)
|
|
333
|
+
) {
|
|
334
|
+
return false;
|
|
335
|
+
} else if (
|
|
336
|
+
isVariant(order.direction, 'short') &&
|
|
337
|
+
order.triggerPrice.gt(order.price)
|
|
338
|
+
) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return isAuctionComplete(order, slot);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return order.postOnly || isAuctionComplete(order, slot);
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
export function isTakingOrder(order: Order, slot: number): boolean {
|
package/src/types.ts
CHANGED
package/tests/dlob/helpers.ts
CHANGED
package/tests/dlob/test.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
|
|
28
28
|
import { mockPerpMarkets, mockSpotMarkets, mockStateAccount } from './helpers';
|
|
29
29
|
import { DLOBOrdersCoder } from '../../src/dlob/DLOBOrders';
|
|
30
|
+
import {isAuctionComplete, isRestingLimitOrder} from "../../lib";
|
|
30
31
|
|
|
31
32
|
function insertOrderToDLOB(
|
|
32
33
|
dlob: DLOB,
|
|
@@ -2504,6 +2505,52 @@ describe('DLOB Perp Tests', () => {
|
|
|
2504
2505
|
}
|
|
2505
2506
|
});
|
|
2506
2507
|
|
|
2508
|
+
it('Test trigger limit isnt maker', () => {
|
|
2509
|
+
const vAsk = new BN(15);
|
|
2510
|
+
const vBid = new BN(8);
|
|
2511
|
+
|
|
2512
|
+
const user0 = Keypair.generate();
|
|
2513
|
+
|
|
2514
|
+
const dlob = new DLOB();
|
|
2515
|
+
const marketIndex = 0;
|
|
2516
|
+
|
|
2517
|
+
const slot = 20;
|
|
2518
|
+
const oracle = {
|
|
2519
|
+
price: vBid.add(vAsk).div(new BN(2)),
|
|
2520
|
+
slot: new BN(slot),
|
|
2521
|
+
confidence: new BN(1),
|
|
2522
|
+
hasSufficientNumberOfDataPoints: true,
|
|
2523
|
+
};
|
|
2524
|
+
|
|
2525
|
+
// should trigger limit buy with above condition
|
|
2526
|
+
insertTriggerOrderToDLOB(
|
|
2527
|
+
dlob,
|
|
2528
|
+
user0.publicKey,
|
|
2529
|
+
OrderType.TRIGGER_LIMIT,
|
|
2530
|
+
MarketType.PERP,
|
|
2531
|
+
1, //orderId
|
|
2532
|
+
marketIndex, // marketIndex
|
|
2533
|
+
oracle.price.add(new BN(1)), // price
|
|
2534
|
+
BASE_PRECISION, // baseAssetAmount: BN,
|
|
2535
|
+
PositionDirection.LONG,
|
|
2536
|
+
oracle.price.sub(new BN(1)), // triggerPrice: BN,
|
|
2537
|
+
OrderTriggerCondition.TRIGGERED_ABOVE, // triggerCondition: OrderTriggerCondition,
|
|
2538
|
+
vBid,
|
|
2539
|
+
vAsk,
|
|
2540
|
+
new BN(1), // slot
|
|
2541
|
+
);
|
|
2542
|
+
|
|
2543
|
+
const restingLimitBids = Array.from(dlob.getRestingLimitBids(marketIndex, slot, MarketType.PERP, oracle));
|
|
2544
|
+
expect(restingLimitBids.length).to.equal(0);
|
|
2545
|
+
|
|
2546
|
+
const takingBids = Array.from(dlob.getTakingBids(marketIndex, MarketType.PERP, slot, oracle));
|
|
2547
|
+
expect(takingBids.length).to.equal(1);
|
|
2548
|
+
const triggerLimitBid = takingBids[0];
|
|
2549
|
+
expect(isAuctionComplete(triggerLimitBid.order, slot)).to.equal(true);
|
|
2550
|
+
expect(isRestingLimitOrder(triggerLimitBid.order, slot)).to.equal(false);
|
|
2551
|
+
|
|
2552
|
+
});
|
|
2553
|
+
|
|
2507
2554
|
it('Test will return expired market orders to fill', () => {
|
|
2508
2555
|
const vAsk = new BN(15);
|
|
2509
2556
|
const vBid = new BN(8);
|