@drift-labs/sdk 2.61.0-beta.2 → 2.61.0-beta.4
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/VERSION +1 -1
- package/lib/driftClient.d.ts +1 -0
- package/lib/driftClient.js +10 -0
- package/lib/idl/drift.json +28 -0
- package/lib/math/exchangeStatus.js +20 -6
- package/lib/math/orders.js +0 -11
- package/lib/types.d.ts +4 -1
- package/lib/types.js +1 -0
- package/package.json +1 -1
- package/src/driftClient.ts +19 -0
- package/src/idl/drift.json +28 -0
- package/src/math/exchangeStatus.ts +22 -9
- package/src/math/orders.ts +0 -16
- package/src/types.ts +4 -0
- package/tests/dlob/test.ts +0 -55
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.61.0-beta.
|
|
1
|
+
2.61.0-beta.4
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -129,6 +129,7 @@ export declare class DriftClient {
|
|
|
129
129
|
subAccountId: number;
|
|
130
130
|
}[]): Promise<TransactionSignature>;
|
|
131
131
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
132
|
+
updateUserAdvancedLp(advancedLp: boolean, subAccountId?: number): Promise<TransactionSignature>;
|
|
132
133
|
fetchAllUserAccounts(includeIdle?: boolean): Promise<ProgramAccount<UserAccount>[]>;
|
|
133
134
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
134
135
|
getUserAccountsAndAddressesForAuthority(authority: PublicKey): Promise<ProgramAccount<UserAccount>[]>;
|
package/lib/driftClient.js
CHANGED
|
@@ -600,6 +600,16 @@ class DriftClient {
|
|
|
600
600
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
601
601
|
return txSig;
|
|
602
602
|
}
|
|
603
|
+
async updateUserAdvancedLp(advancedLp, subAccountId = 0) {
|
|
604
|
+
const tx = await this.program.transaction.updateUserAdvancedLp(subAccountId, advancedLp, {
|
|
605
|
+
accounts: {
|
|
606
|
+
user: await this.getUserAccountPublicKey(),
|
|
607
|
+
authority: this.wallet.publicKey,
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
611
|
+
return txSig;
|
|
612
|
+
}
|
|
603
613
|
async fetchAllUserAccounts(includeIdle = true) {
|
|
604
614
|
let filters = undefined;
|
|
605
615
|
if (!includeIdle) {
|
package/lib/idl/drift.json
CHANGED
|
@@ -1147,6 +1147,31 @@
|
|
|
1147
1147
|
}
|
|
1148
1148
|
]
|
|
1149
1149
|
},
|
|
1150
|
+
{
|
|
1151
|
+
"name": "updateUserAdvancedLp",
|
|
1152
|
+
"accounts": [
|
|
1153
|
+
{
|
|
1154
|
+
"name": "user",
|
|
1155
|
+
"isMut": true,
|
|
1156
|
+
"isSigner": false
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
"name": "authority",
|
|
1160
|
+
"isMut": false,
|
|
1161
|
+
"isSigner": true
|
|
1162
|
+
}
|
|
1163
|
+
],
|
|
1164
|
+
"args": [
|
|
1165
|
+
{
|
|
1166
|
+
"name": "subAccountId",
|
|
1167
|
+
"type": "u16"
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
"name": "advancedLp",
|
|
1171
|
+
"type": "bool"
|
|
1172
|
+
}
|
|
1173
|
+
]
|
|
1174
|
+
},
|
|
1150
1175
|
{
|
|
1151
1176
|
"name": "deleteUser",
|
|
1152
1177
|
"accounts": [
|
|
@@ -8925,6 +8950,9 @@
|
|
|
8925
8950
|
},
|
|
8926
8951
|
{
|
|
8927
8952
|
"name": "ReduceOnly"
|
|
8953
|
+
},
|
|
8954
|
+
{
|
|
8955
|
+
"name": "AdvancedLp"
|
|
8928
8956
|
}
|
|
8929
8957
|
]
|
|
8930
8958
|
}
|
|
@@ -7,15 +7,29 @@ function exchangePaused(state) {
|
|
|
7
7
|
}
|
|
8
8
|
exports.exchangePaused = exchangePaused;
|
|
9
9
|
function fillPaused(state, market) {
|
|
10
|
-
|
|
11
|
-
types_1.ExchangeStatus.FILL_PAUSED
|
|
12
|
-
|
|
10
|
+
if ((state.exchangeStatus & types_1.ExchangeStatus.FILL_PAUSED) ===
|
|
11
|
+
types_1.ExchangeStatus.FILL_PAUSED) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (market.hasOwnProperty('amm')) {
|
|
15
|
+
return isOperationPaused(market.pausedOperations, types_1.PerpOperation.FILL);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return isOperationPaused(market.pausedOperations, types_1.SpotOperation.FILL);
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
exports.fillPaused = fillPaused;
|
|
15
22
|
function ammPaused(state, market) {
|
|
16
|
-
|
|
17
|
-
types_1.ExchangeStatus.AMM_PAUSED
|
|
18
|
-
|
|
23
|
+
if ((state.exchangeStatus & types_1.ExchangeStatus.AMM_PAUSED) ===
|
|
24
|
+
types_1.ExchangeStatus.AMM_PAUSED) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (market.hasOwnProperty('amm')) {
|
|
28
|
+
return isOperationPaused(market.pausedOperations, types_1.PerpOperation.AMM_FILL);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
19
33
|
}
|
|
20
34
|
exports.ammPaused = ammPaused;
|
|
21
35
|
function isOperationPaused(pausedOperations, operation) {
|
package/lib/math/orders.js
CHANGED
|
@@ -207,17 +207,6 @@ function isRestingLimitOrder(order, slot) {
|
|
|
207
207
|
if (!isLimitOrder(order)) {
|
|
208
208
|
return false;
|
|
209
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
210
|
return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
|
|
222
211
|
}
|
|
223
212
|
exports.isRestingLimitOrder = isRestingLimitOrder;
|
package/lib/types.d.ts
CHANGED
|
@@ -56,7 +56,8 @@ export declare enum SpotOperation {
|
|
|
56
56
|
export declare enum UserStatus {
|
|
57
57
|
BEING_LIQUIDATED = 1,
|
|
58
58
|
BANKRUPT = 2,
|
|
59
|
-
REDUCE_ONLY = 4
|
|
59
|
+
REDUCE_ONLY = 4,
|
|
60
|
+
ADVANCED_LP = 8
|
|
60
61
|
}
|
|
61
62
|
export declare class ContractType {
|
|
62
63
|
static readonly PERPETUAL: {
|
|
@@ -689,6 +690,7 @@ export type PerpMarketAccount = {
|
|
|
689
690
|
};
|
|
690
691
|
quoteSpotMarketIndex: number;
|
|
691
692
|
feeAdjustment: number;
|
|
693
|
+
pausedOperations: number;
|
|
692
694
|
};
|
|
693
695
|
export type HistoricalOracleData = {
|
|
694
696
|
lastOraclePrice: BN;
|
|
@@ -766,6 +768,7 @@ export type SpotMarketAccount = {
|
|
|
766
768
|
flashLoanAmount: BN;
|
|
767
769
|
flashLoanInitialTokenAmount: BN;
|
|
768
770
|
ordersEnabled: boolean;
|
|
771
|
+
pausedOperations: number;
|
|
769
772
|
};
|
|
770
773
|
export type PoolBalance = {
|
|
771
774
|
scaledBalance: BN;
|
package/lib/types.js
CHANGED
|
@@ -46,6 +46,7 @@ var UserStatus;
|
|
|
46
46
|
UserStatus[UserStatus["BEING_LIQUIDATED"] = 1] = "BEING_LIQUIDATED";
|
|
47
47
|
UserStatus[UserStatus["BANKRUPT"] = 2] = "BANKRUPT";
|
|
48
48
|
UserStatus[UserStatus["REDUCE_ONLY"] = 4] = "REDUCE_ONLY";
|
|
49
|
+
UserStatus[UserStatus["ADVANCED_LP"] = 8] = "ADVANCED_LP";
|
|
49
50
|
})(UserStatus = exports.UserStatus || (exports.UserStatus = {}));
|
|
50
51
|
class ContractType {
|
|
51
52
|
}
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -1024,6 +1024,25 @@ export class DriftClient {
|
|
|
1024
1024
|
return txSig;
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
|
+
public async updateUserAdvancedLp(
|
|
1028
|
+
advancedLp: boolean,
|
|
1029
|
+
subAccountId = 0
|
|
1030
|
+
): Promise<TransactionSignature> {
|
|
1031
|
+
const tx = await this.program.transaction.updateUserAdvancedLp(
|
|
1032
|
+
subAccountId,
|
|
1033
|
+
advancedLp,
|
|
1034
|
+
{
|
|
1035
|
+
accounts: {
|
|
1036
|
+
user: await this.getUserAccountPublicKey(),
|
|
1037
|
+
authority: this.wallet.publicKey,
|
|
1038
|
+
},
|
|
1039
|
+
}
|
|
1040
|
+
);
|
|
1041
|
+
|
|
1042
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1043
|
+
return txSig;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1027
1046
|
public async fetchAllUserAccounts(
|
|
1028
1047
|
includeIdle = true
|
|
1029
1048
|
): Promise<ProgramAccount<UserAccount>[]> {
|
package/src/idl/drift.json
CHANGED
|
@@ -1147,6 +1147,31 @@
|
|
|
1147
1147
|
}
|
|
1148
1148
|
]
|
|
1149
1149
|
},
|
|
1150
|
+
{
|
|
1151
|
+
"name": "updateUserAdvancedLp",
|
|
1152
|
+
"accounts": [
|
|
1153
|
+
{
|
|
1154
|
+
"name": "user",
|
|
1155
|
+
"isMut": true,
|
|
1156
|
+
"isSigner": false
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
"name": "authority",
|
|
1160
|
+
"isMut": false,
|
|
1161
|
+
"isSigner": true
|
|
1162
|
+
}
|
|
1163
|
+
],
|
|
1164
|
+
"args": [
|
|
1165
|
+
{
|
|
1166
|
+
"name": "subAccountId",
|
|
1167
|
+
"type": "u16"
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
"name": "advancedLp",
|
|
1171
|
+
"type": "bool"
|
|
1172
|
+
}
|
|
1173
|
+
]
|
|
1174
|
+
},
|
|
1150
1175
|
{
|
|
1151
1176
|
"name": "deleteUser",
|
|
1152
1177
|
"accounts": [
|
|
@@ -8925,6 +8950,9 @@
|
|
|
8925
8950
|
},
|
|
8926
8951
|
{
|
|
8927
8952
|
"name": "ReduceOnly"
|
|
8953
|
+
},
|
|
8954
|
+
{
|
|
8955
|
+
"name": "AdvancedLp"
|
|
8928
8956
|
}
|
|
8929
8957
|
]
|
|
8930
8958
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ExchangeStatus,
|
|
3
|
-
isOneOfVariant,
|
|
4
3
|
PerpMarketAccount,
|
|
5
4
|
PerpOperation,
|
|
6
5
|
SpotMarketAccount,
|
|
@@ -16,22 +15,36 @@ export function fillPaused(
|
|
|
16
15
|
state: StateAccount,
|
|
17
16
|
market: PerpMarketAccount | SpotMarketAccount
|
|
18
17
|
): boolean {
|
|
19
|
-
|
|
18
|
+
if (
|
|
20
19
|
(state.exchangeStatus & ExchangeStatus.FILL_PAUSED) ===
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
ExchangeStatus.FILL_PAUSED
|
|
21
|
+
) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (market.hasOwnProperty('amm')) {
|
|
26
|
+
return isOperationPaused(market.pausedOperations, PerpOperation.FILL);
|
|
27
|
+
} else {
|
|
28
|
+
return isOperationPaused(market.pausedOperations, SpotOperation.FILL);
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export function ammPaused(
|
|
27
33
|
state: StateAccount,
|
|
28
34
|
market: PerpMarketAccount | SpotMarketAccount
|
|
29
35
|
): boolean {
|
|
30
|
-
|
|
36
|
+
if (
|
|
31
37
|
(state.exchangeStatus & ExchangeStatus.AMM_PAUSED) ===
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
ExchangeStatus.AMM_PAUSED
|
|
39
|
+
) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (market.hasOwnProperty('amm')) {
|
|
44
|
+
return isOperationPaused(market.pausedOperations, PerpOperation.AMM_FILL);
|
|
45
|
+
} else {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
export function isOperationPaused(
|
package/src/math/orders.ts
CHANGED
|
@@ -331,22 +331,6 @@ export function isRestingLimitOrder(order: Order, slot: number): boolean {
|
|
|
331
331
|
return false;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
if (isVariant(order.orderType, 'triggerLimit')) {
|
|
335
|
-
if (
|
|
336
|
-
isVariant(order.direction, 'long') &&
|
|
337
|
-
order.triggerPrice.lt(order.price)
|
|
338
|
-
) {
|
|
339
|
-
return false;
|
|
340
|
-
} else if (
|
|
341
|
-
isVariant(order.direction, 'short') &&
|
|
342
|
-
order.triggerPrice.gt(order.price)
|
|
343
|
-
) {
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return isAuctionComplete(order, slot);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
334
|
return order.postOnly || isAuctionComplete(order, slot);
|
|
351
335
|
}
|
|
352
336
|
|
package/src/types.ts
CHANGED
|
@@ -45,6 +45,7 @@ export enum UserStatus {
|
|
|
45
45
|
BEING_LIQUIDATED = 1,
|
|
46
46
|
BANKRUPT = 2,
|
|
47
47
|
REDUCE_ONLY = 4,
|
|
48
|
+
ADVANCED_LP = 8,
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export class ContractType {
|
|
@@ -609,6 +610,7 @@ export type PerpMarketAccount = {
|
|
|
609
610
|
};
|
|
610
611
|
quoteSpotMarketIndex: number;
|
|
611
612
|
feeAdjustment: number;
|
|
613
|
+
pausedOperations: number;
|
|
612
614
|
};
|
|
613
615
|
|
|
614
616
|
export type HistoricalOracleData = {
|
|
@@ -700,6 +702,8 @@ export type SpotMarketAccount = {
|
|
|
700
702
|
flashLoanInitialTokenAmount: BN;
|
|
701
703
|
|
|
702
704
|
ordersEnabled: boolean;
|
|
705
|
+
|
|
706
|
+
pausedOperations: number;
|
|
703
707
|
};
|
|
704
708
|
|
|
705
709
|
export type PoolBalance = {
|
package/tests/dlob/test.ts
CHANGED
|
@@ -28,7 +28,6 @@ import {
|
|
|
28
28
|
|
|
29
29
|
import { mockPerpMarkets, mockSpotMarkets, mockStateAccount } from './helpers';
|
|
30
30
|
import { DLOBOrdersCoder } from '../../src/dlob/DLOBOrders';
|
|
31
|
-
import { isAuctionComplete, isRestingLimitOrder } from '../../lib';
|
|
32
31
|
|
|
33
32
|
function insertOrderToDLOB(
|
|
34
33
|
dlob: DLOB,
|
|
@@ -2698,60 +2697,6 @@ describe('DLOB Perp Tests', () => {
|
|
|
2698
2697
|
}
|
|
2699
2698
|
});
|
|
2700
2699
|
|
|
2701
|
-
it('Test trigger limit isnt maker', () => {
|
|
2702
|
-
const vAsk = new BN(15);
|
|
2703
|
-
const vBid = new BN(8);
|
|
2704
|
-
|
|
2705
|
-
const user0 = Keypair.generate();
|
|
2706
|
-
|
|
2707
|
-
const dlob = new DLOB();
|
|
2708
|
-
const marketIndex = 0;
|
|
2709
|
-
|
|
2710
|
-
const slot = 20;
|
|
2711
|
-
const oracle = {
|
|
2712
|
-
price: vBid.add(vAsk).div(new BN(2)),
|
|
2713
|
-
slot: new BN(slot),
|
|
2714
|
-
confidence: new BN(1),
|
|
2715
|
-
hasSufficientNumberOfDataPoints: true,
|
|
2716
|
-
};
|
|
2717
|
-
|
|
2718
|
-
// should trigger limit buy with above condition
|
|
2719
|
-
insertTriggerOrderToDLOB(
|
|
2720
|
-
dlob,
|
|
2721
|
-
user0.publicKey,
|
|
2722
|
-
OrderType.TRIGGER_LIMIT,
|
|
2723
|
-
MarketType.PERP,
|
|
2724
|
-
1, //orderId
|
|
2725
|
-
marketIndex, // marketIndex
|
|
2726
|
-
oracle.price.add(new BN(1)), // price
|
|
2727
|
-
BASE_PRECISION, // baseAssetAmount: BN,
|
|
2728
|
-
PositionDirection.LONG,
|
|
2729
|
-
oracle.price.sub(new BN(1)), // triggerPrice: BN,
|
|
2730
|
-
OrderTriggerCondition.TRIGGERED_ABOVE, // triggerCondition: OrderTriggerCondition,
|
|
2731
|
-
vBid,
|
|
2732
|
-
vAsk,
|
|
2733
|
-
new BN(1) // slot
|
|
2734
|
-
);
|
|
2735
|
-
|
|
2736
|
-
const restingLimitBids = Array.from(
|
|
2737
|
-
dlob.getRestingLimitBids(marketIndex, slot, MarketType.PERP, oracle)
|
|
2738
|
-
);
|
|
2739
|
-
expect(restingLimitBids.length).to.equal(0);
|
|
2740
|
-
|
|
2741
|
-
const takingBids = Array.from(
|
|
2742
|
-
dlob.getTakingBids(marketIndex, MarketType.PERP, slot, oracle)
|
|
2743
|
-
);
|
|
2744
|
-
expect(takingBids.length).to.equal(1);
|
|
2745
|
-
const triggerLimitBid = takingBids[0];
|
|
2746
|
-
expect(triggerLimitBid !== undefined);
|
|
2747
|
-
expect(isAuctionComplete(triggerLimitBid.order as Order, slot)).to.equal(
|
|
2748
|
-
true
|
|
2749
|
-
);
|
|
2750
|
-
expect(isRestingLimitOrder(triggerLimitBid.order as Order, slot)).to.equal(
|
|
2751
|
-
false
|
|
2752
|
-
);
|
|
2753
|
-
});
|
|
2754
|
-
|
|
2755
2700
|
it('Test will return expired market orders to fill', () => {
|
|
2756
2701
|
const vAsk = new BN(15);
|
|
2757
2702
|
const vBid = new BN(8);
|