@drift-labs/sdk 0.1.36-master.4 → 0.1.36-master.5
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/clearingHouse.d.ts +4 -2
- package/lib/clearingHouse.js +40 -4
- package/lib/idl/clearing_house.json +72 -1
- package/package.json +1 -1
- package/src/clearingHouse.ts +69 -4
- package/src/idl/clearing_house.json +72 -1
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -126,8 +126,10 @@ export declare class ClearingHouse {
|
|
|
126
126
|
getCancelOrderIx(orderId: BN, oracle?: PublicKey): Promise<TransactionInstruction>;
|
|
127
127
|
cancelOrderByUserId(userOrderId: number, oracle?: PublicKey): Promise<TransactionSignature>;
|
|
128
128
|
getCancelOrderByUserIdIx(userOrderId: number, oracle?: PublicKey): Promise<TransactionInstruction>;
|
|
129
|
-
cancelAllOrders(oracles?: PublicKey[]): Promise<TransactionSignature>;
|
|
130
|
-
getCancelAllOrdersIx(oracles: PublicKey[]): Promise<TransactionInstruction>;
|
|
129
|
+
cancelAllOrders(oracles?: PublicKey[], bestEffort?: boolean): Promise<TransactionSignature>;
|
|
130
|
+
getCancelAllOrdersIx(oracles: PublicKey[], bestEffort?: boolean): Promise<TransactionInstruction>;
|
|
131
|
+
cancelOrdersByMarketAndSide(oracles?: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
|
|
132
|
+
getCancelOrdersByMarketAndSideIx(oracles: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
|
|
131
133
|
fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
|
|
132
134
|
getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
|
|
133
135
|
initializeUserOrdersThenPlaceAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
package/lib/clearingHouse.js
CHANGED
|
@@ -622,12 +622,12 @@ class ClearingHouse {
|
|
|
622
622
|
});
|
|
623
623
|
});
|
|
624
624
|
}
|
|
625
|
-
cancelAllOrders(oracles) {
|
|
625
|
+
cancelAllOrders(oracles, bestEffort) {
|
|
626
626
|
return __awaiter(this, void 0, void 0, function* () {
|
|
627
|
-
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelAllOrdersIx(oracles)), [], this.opts);
|
|
627
|
+
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelAllOrdersIx(oracles, bestEffort)), [], this.opts);
|
|
628
628
|
});
|
|
629
629
|
}
|
|
630
|
-
getCancelAllOrdersIx(oracles) {
|
|
630
|
+
getCancelAllOrdersIx(oracles, bestEffort) {
|
|
631
631
|
return __awaiter(this, void 0, void 0, function* () {
|
|
632
632
|
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
633
633
|
const userAccount = yield this.getUserAccount();
|
|
@@ -641,7 +641,43 @@ class ClearingHouse {
|
|
|
641
641
|
isSigner: false,
|
|
642
642
|
});
|
|
643
643
|
}
|
|
644
|
-
return yield this.program.instruction.cancelAllOrders({
|
|
644
|
+
return yield this.program.instruction.cancelAllOrders(bestEffort, {
|
|
645
|
+
accounts: {
|
|
646
|
+
state: yield this.getStatePublicKey(),
|
|
647
|
+
user: userAccountPublicKey,
|
|
648
|
+
authority: this.wallet.publicKey,
|
|
649
|
+
markets: state.markets,
|
|
650
|
+
userOrders: yield this.getUserOrdersAccountPublicKey(),
|
|
651
|
+
userPositions: userAccount.positions,
|
|
652
|
+
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
653
|
+
fundingRateHistory: state.fundingRateHistory,
|
|
654
|
+
orderState: yield this.getOrderStatePublicKey(),
|
|
655
|
+
orderHistory: orderState.orderHistory,
|
|
656
|
+
},
|
|
657
|
+
remainingAccounts,
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
cancelOrdersByMarketAndSide(oracles, bestEffort, marketIndexOnly, directionOnly) {
|
|
662
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
663
|
+
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelOrdersByMarketAndSideIx(oracles, bestEffort, marketIndexOnly, directionOnly)), [], this.opts);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
getCancelOrdersByMarketAndSideIx(oracles, bestEffort, marketIndexOnly, directionOnly) {
|
|
667
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
668
|
+
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
669
|
+
const userAccount = yield this.getUserAccount();
|
|
670
|
+
const state = this.getStateAccount();
|
|
671
|
+
const orderState = this.getOrderStateAccount();
|
|
672
|
+
const remainingAccounts = [];
|
|
673
|
+
for (const oracle of oracles) {
|
|
674
|
+
remainingAccounts.push({
|
|
675
|
+
pubkey: oracle,
|
|
676
|
+
isWritable: false,
|
|
677
|
+
isSigner: false,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
return yield this.program.instruction.cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly, {
|
|
645
681
|
accounts: {
|
|
646
682
|
state: yield this.getStatePublicKey(),
|
|
647
683
|
user: userAccountPublicKey,
|
|
@@ -726,7 +726,78 @@
|
|
|
726
726
|
"isSigner": false
|
|
727
727
|
}
|
|
728
728
|
],
|
|
729
|
-
"args": [
|
|
729
|
+
"args": [
|
|
730
|
+
{
|
|
731
|
+
"name": "bestEffort",
|
|
732
|
+
"type": "bool"
|
|
733
|
+
}
|
|
734
|
+
]
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
"name": "cancelOrdersByMarketAndSide",
|
|
738
|
+
"accounts": [
|
|
739
|
+
{
|
|
740
|
+
"name": "state",
|
|
741
|
+
"isMut": false,
|
|
742
|
+
"isSigner": false
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"name": "orderState",
|
|
746
|
+
"isMut": false,
|
|
747
|
+
"isSigner": false
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
"name": "user",
|
|
751
|
+
"isMut": false,
|
|
752
|
+
"isSigner": false
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
"name": "authority",
|
|
756
|
+
"isMut": false,
|
|
757
|
+
"isSigner": true
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
"name": "markets",
|
|
761
|
+
"isMut": false,
|
|
762
|
+
"isSigner": false
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
"name": "userPositions",
|
|
766
|
+
"isMut": true,
|
|
767
|
+
"isSigner": false
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
"name": "userOrders",
|
|
771
|
+
"isMut": true,
|
|
772
|
+
"isSigner": false
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
"name": "fundingPaymentHistory",
|
|
776
|
+
"isMut": true,
|
|
777
|
+
"isSigner": false
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
"name": "orderHistory",
|
|
781
|
+
"isMut": true,
|
|
782
|
+
"isSigner": false
|
|
783
|
+
}
|
|
784
|
+
],
|
|
785
|
+
"args": [
|
|
786
|
+
{
|
|
787
|
+
"name": "bestEffort",
|
|
788
|
+
"type": "bool"
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
"name": "marketIndexOnly",
|
|
792
|
+
"type": "u64"
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
"name": "directionOnly",
|
|
796
|
+
"type": {
|
|
797
|
+
"defined": "PositionDirection"
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
]
|
|
730
801
|
},
|
|
731
802
|
{
|
|
732
803
|
"name": "expireOrders",
|
package/package.json
CHANGED
package/src/clearingHouse.ts
CHANGED
|
@@ -917,17 +917,19 @@ export class ClearingHouse {
|
|
|
917
917
|
}
|
|
918
918
|
|
|
919
919
|
public async cancelAllOrders(
|
|
920
|
-
oracles?: PublicKey[]
|
|
920
|
+
oracles?: PublicKey[],
|
|
921
|
+
bestEffort?: boolean
|
|
921
922
|
): Promise<TransactionSignature> {
|
|
922
923
|
return await this.txSender.send(
|
|
923
|
-
wrapInTx(await this.getCancelAllOrdersIx(oracles)),
|
|
924
|
+
wrapInTx(await this.getCancelAllOrdersIx(oracles, bestEffort)),
|
|
924
925
|
[],
|
|
925
926
|
this.opts
|
|
926
927
|
);
|
|
927
928
|
}
|
|
928
929
|
|
|
929
930
|
public async getCancelAllOrdersIx(
|
|
930
|
-
oracles: PublicKey[]
|
|
931
|
+
oracles: PublicKey[],
|
|
932
|
+
bestEffort?: boolean
|
|
931
933
|
): Promise<TransactionInstruction> {
|
|
932
934
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
933
935
|
const userAccount = await this.getUserAccount();
|
|
@@ -944,7 +946,7 @@ export class ClearingHouse {
|
|
|
944
946
|
});
|
|
945
947
|
}
|
|
946
948
|
|
|
947
|
-
return await this.program.instruction.cancelAllOrders({
|
|
949
|
+
return await this.program.instruction.cancelAllOrders(bestEffort, {
|
|
948
950
|
accounts: {
|
|
949
951
|
state: await this.getStatePublicKey(),
|
|
950
952
|
user: userAccountPublicKey,
|
|
@@ -961,6 +963,69 @@ export class ClearingHouse {
|
|
|
961
963
|
});
|
|
962
964
|
}
|
|
963
965
|
|
|
966
|
+
public async cancelOrdersByMarketAndSide(
|
|
967
|
+
oracles?: PublicKey[],
|
|
968
|
+
bestEffort?: boolean,
|
|
969
|
+
marketIndexOnly?: BN,
|
|
970
|
+
directionOnly?: PositionDirection
|
|
971
|
+
): Promise<TransactionSignature> {
|
|
972
|
+
return await this.txSender.send(
|
|
973
|
+
wrapInTx(
|
|
974
|
+
await this.getCancelOrdersByMarketAndSideIx(
|
|
975
|
+
oracles,
|
|
976
|
+
bestEffort,
|
|
977
|
+
marketIndexOnly,
|
|
978
|
+
directionOnly
|
|
979
|
+
)
|
|
980
|
+
),
|
|
981
|
+
[],
|
|
982
|
+
this.opts
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
public async getCancelOrdersByMarketAndSideIx(
|
|
987
|
+
oracles: PublicKey[],
|
|
988
|
+
bestEffort?: boolean,
|
|
989
|
+
marketIndexOnly?: BN,
|
|
990
|
+
directionOnly?: PositionDirection
|
|
991
|
+
): Promise<TransactionInstruction> {
|
|
992
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
993
|
+
const userAccount = await this.getUserAccount();
|
|
994
|
+
|
|
995
|
+
const state = this.getStateAccount();
|
|
996
|
+
const orderState = this.getOrderStateAccount();
|
|
997
|
+
|
|
998
|
+
const remainingAccounts = [];
|
|
999
|
+
for (const oracle of oracles) {
|
|
1000
|
+
remainingAccounts.push({
|
|
1001
|
+
pubkey: oracle,
|
|
1002
|
+
isWritable: false,
|
|
1003
|
+
isSigner: false,
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
return await this.program.instruction.cancelOrdersByMarketAndSide(
|
|
1008
|
+
bestEffort,
|
|
1009
|
+
marketIndexOnly,
|
|
1010
|
+
directionOnly,
|
|
1011
|
+
{
|
|
1012
|
+
accounts: {
|
|
1013
|
+
state: await this.getStatePublicKey(),
|
|
1014
|
+
user: userAccountPublicKey,
|
|
1015
|
+
authority: this.wallet.publicKey,
|
|
1016
|
+
markets: state.markets,
|
|
1017
|
+
userOrders: await this.getUserOrdersAccountPublicKey(),
|
|
1018
|
+
userPositions: userAccount.positions,
|
|
1019
|
+
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
1020
|
+
fundingRateHistory: state.fundingRateHistory,
|
|
1021
|
+
orderState: await this.getOrderStatePublicKey(),
|
|
1022
|
+
orderHistory: orderState.orderHistory,
|
|
1023
|
+
},
|
|
1024
|
+
remainingAccounts,
|
|
1025
|
+
}
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
964
1029
|
public async fillOrder(
|
|
965
1030
|
userAccountPublicKey: PublicKey,
|
|
966
1031
|
userOrdersAccountPublicKey: PublicKey,
|
|
@@ -726,7 +726,78 @@
|
|
|
726
726
|
"isSigner": false
|
|
727
727
|
}
|
|
728
728
|
],
|
|
729
|
-
"args": [
|
|
729
|
+
"args": [
|
|
730
|
+
{
|
|
731
|
+
"name": "bestEffort",
|
|
732
|
+
"type": "bool"
|
|
733
|
+
}
|
|
734
|
+
]
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
"name": "cancelOrdersByMarketAndSide",
|
|
738
|
+
"accounts": [
|
|
739
|
+
{
|
|
740
|
+
"name": "state",
|
|
741
|
+
"isMut": false,
|
|
742
|
+
"isSigner": false
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"name": "orderState",
|
|
746
|
+
"isMut": false,
|
|
747
|
+
"isSigner": false
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
"name": "user",
|
|
751
|
+
"isMut": false,
|
|
752
|
+
"isSigner": false
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
"name": "authority",
|
|
756
|
+
"isMut": false,
|
|
757
|
+
"isSigner": true
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
"name": "markets",
|
|
761
|
+
"isMut": false,
|
|
762
|
+
"isSigner": false
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
"name": "userPositions",
|
|
766
|
+
"isMut": true,
|
|
767
|
+
"isSigner": false
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
"name": "userOrders",
|
|
771
|
+
"isMut": true,
|
|
772
|
+
"isSigner": false
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
"name": "fundingPaymentHistory",
|
|
776
|
+
"isMut": true,
|
|
777
|
+
"isSigner": false
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
"name": "orderHistory",
|
|
781
|
+
"isMut": true,
|
|
782
|
+
"isSigner": false
|
|
783
|
+
}
|
|
784
|
+
],
|
|
785
|
+
"args": [
|
|
786
|
+
{
|
|
787
|
+
"name": "bestEffort",
|
|
788
|
+
"type": "bool"
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
"name": "marketIndexOnly",
|
|
792
|
+
"type": "u64"
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
"name": "directionOnly",
|
|
796
|
+
"type": {
|
|
797
|
+
"defined": "PositionDirection"
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
]
|
|
730
801
|
},
|
|
731
802
|
{
|
|
732
803
|
"name": "expireOrders",
|