@drift-labs/sdk 0.2.0-master.2 → 0.2.0-master.3
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 +0 -6
- package/lib/clearingHouse.js +0 -71
- package/lib/idl/clearing_house.json +0 -20
- package/lib/math/orders.js +2 -12
- package/lib/orders.js +1 -9
- package/package.json +1 -1
- package/src/clearingHouse.ts +0 -125
- package/src/idl/clearing_house.json +0 -20
- package/src/math/orders.ts +3 -13
- package/src/orders.ts +1 -8
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -97,18 +97,12 @@ export declare class ClearingHouse {
|
|
|
97
97
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
98
98
|
placeOrder(orderParams: OrderParams): Promise<TransactionSignature>;
|
|
99
99
|
getPlaceOrderIx(orderParams: OrderParams): Promise<TransactionInstruction>;
|
|
100
|
-
expireOrders(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
101
|
-
getExpireOrdersIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
102
100
|
updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
|
|
103
101
|
getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
|
|
104
102
|
cancelOrder(orderId?: BN): Promise<TransactionSignature>;
|
|
105
103
|
getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
|
|
106
104
|
cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
|
|
107
105
|
getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
|
|
108
|
-
cancelAllOrders(bestEffort?: boolean): Promise<TransactionSignature>;
|
|
109
|
-
getCancelAllOrdersIx(bestEffort?: boolean): Promise<TransactionInstruction>;
|
|
110
|
-
cancelOrdersByMarketAndSide(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
|
|
111
|
-
getCancelOrdersByMarketAndSideIx(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
|
|
112
106
|
fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
|
|
113
107
|
getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
|
|
114
108
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
package/lib/clearingHouse.js
CHANGED
|
@@ -491,8 +491,6 @@ class ClearingHouse {
|
|
|
491
491
|
}
|
|
492
492
|
async getPlaceOrderIx(orderParams) {
|
|
493
493
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
494
|
-
const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
|
|
495
|
-
.oracle;
|
|
496
494
|
const remainingAccounts = this.getRemainingAccounts({
|
|
497
495
|
writableMarketIndex: orderParams.marketIndex,
|
|
498
496
|
});
|
|
@@ -501,26 +499,10 @@ class ClearingHouse {
|
|
|
501
499
|
state: await this.getStatePublicKey(),
|
|
502
500
|
user: userAccountPublicKey,
|
|
503
501
|
authority: this.wallet.publicKey,
|
|
504
|
-
oracle: priceOracle,
|
|
505
502
|
},
|
|
506
503
|
remainingAccounts,
|
|
507
504
|
});
|
|
508
505
|
}
|
|
509
|
-
async expireOrders(userAccountPublicKey) {
|
|
510
|
-
const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getExpireOrdersIx(userAccountPublicKey)), [], this.opts);
|
|
511
|
-
return txSig;
|
|
512
|
-
}
|
|
513
|
-
async getExpireOrdersIx(userAccountPublicKey) {
|
|
514
|
-
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
515
|
-
return await this.program.instruction.expireOrders({
|
|
516
|
-
accounts: {
|
|
517
|
-
state: await this.getStatePublicKey(),
|
|
518
|
-
filler: fillerPublicKey,
|
|
519
|
-
user: userAccountPublicKey,
|
|
520
|
-
authority: this.wallet.publicKey,
|
|
521
|
-
},
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
506
|
async updateAMMs(marketIndexes) {
|
|
525
507
|
const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getUpdateAMMsIx(marketIndexes)), [], this.opts);
|
|
526
508
|
return txSig;
|
|
@@ -590,54 +572,6 @@ class ClearingHouse {
|
|
|
590
572
|
remainingAccounts,
|
|
591
573
|
});
|
|
592
574
|
}
|
|
593
|
-
async cancelAllOrders(bestEffort) {
|
|
594
|
-
const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelAllOrdersIx(bestEffort)), [], this.opts);
|
|
595
|
-
return txSig;
|
|
596
|
-
}
|
|
597
|
-
async getCancelAllOrdersIx(bestEffort) {
|
|
598
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
599
|
-
const remainingAccounts = this.getRemainingAccounts({});
|
|
600
|
-
for (const order of this.getUserAccount().orders) {
|
|
601
|
-
const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
|
|
602
|
-
remainingAccounts.push({
|
|
603
|
-
pubkey: oracle,
|
|
604
|
-
isWritable: false,
|
|
605
|
-
isSigner: false,
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
return await this.program.instruction.cancelAllOrders(bestEffort, {
|
|
609
|
-
accounts: {
|
|
610
|
-
state: await this.getStatePublicKey(),
|
|
611
|
-
user: userAccountPublicKey,
|
|
612
|
-
authority: this.wallet.publicKey,
|
|
613
|
-
},
|
|
614
|
-
remainingAccounts,
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
async cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly) {
|
|
618
|
-
const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelOrdersByMarketAndSideIx(bestEffort, marketIndexOnly, directionOnly)), [], this.opts);
|
|
619
|
-
return txSig;
|
|
620
|
-
}
|
|
621
|
-
async getCancelOrdersByMarketAndSideIx(bestEffort, marketIndexOnly, directionOnly) {
|
|
622
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
623
|
-
const remainingAccounts = this.getRemainingAccounts({});
|
|
624
|
-
for (const order of this.getUserAccount().orders) {
|
|
625
|
-
const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
|
|
626
|
-
remainingAccounts.push({
|
|
627
|
-
pubkey: oracle,
|
|
628
|
-
isWritable: false,
|
|
629
|
-
isSigner: false,
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
return await this.program.instruction.cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly, {
|
|
633
|
-
accounts: {
|
|
634
|
-
state: await this.getStatePublicKey(),
|
|
635
|
-
user: userAccountPublicKey,
|
|
636
|
-
authority: this.wallet.publicKey,
|
|
637
|
-
},
|
|
638
|
-
remainingAccounts,
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
575
|
async fillOrder(userAccountPublicKey, user, order, makerInfo) {
|
|
642
576
|
const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getFillOrderIx(userAccountPublicKey, user, order, makerInfo)), [], this.opts);
|
|
643
577
|
return txSig;
|
|
@@ -646,7 +580,6 @@ class ClearingHouse {
|
|
|
646
580
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
647
581
|
const marketIndex = order.marketIndex;
|
|
648
582
|
const marketAccount = this.getMarketAccount(marketIndex);
|
|
649
|
-
const oracle = marketAccount.amm.oracle;
|
|
650
583
|
const bankAccountInfos = [
|
|
651
584
|
{
|
|
652
585
|
pubkey: this.getQuoteAssetBankAccount().pubkey,
|
|
@@ -700,7 +633,6 @@ class ClearingHouse {
|
|
|
700
633
|
filler: fillerPublicKey,
|
|
701
634
|
user: userAccountPublicKey,
|
|
702
635
|
authority: this.wallet.publicKey,
|
|
703
|
-
oracle: oracle,
|
|
704
636
|
},
|
|
705
637
|
remainingAccounts,
|
|
706
638
|
});
|
|
@@ -769,8 +701,6 @@ class ClearingHouse {
|
|
|
769
701
|
}
|
|
770
702
|
async getPlaceAndTakeIx(orderParams, makerInfo) {
|
|
771
703
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
772
|
-
const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
|
|
773
|
-
.oracle;
|
|
774
704
|
const remainingAccounts = this.getRemainingAccounts({
|
|
775
705
|
writableMarketIndex: orderParams.marketIndex,
|
|
776
706
|
writableBankIndex: numericConstants_1.QUOTE_ASSET_BANK_INDEX,
|
|
@@ -789,7 +719,6 @@ class ClearingHouse {
|
|
|
789
719
|
state: await this.getStatePublicKey(),
|
|
790
720
|
user: userAccountPublicKey,
|
|
791
721
|
authority: this.wallet.publicKey,
|
|
792
|
-
oracle: priceOracle,
|
|
793
722
|
},
|
|
794
723
|
remainingAccounts,
|
|
795
724
|
});
|
|
@@ -381,11 +381,6 @@
|
|
|
381
381
|
"name": "authority",
|
|
382
382
|
"isMut": false,
|
|
383
383
|
"isSigner": true
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
"name": "oracle",
|
|
387
|
-
"isMut": false,
|
|
388
|
-
"isSigner": false
|
|
389
384
|
}
|
|
390
385
|
],
|
|
391
386
|
"args": [
|
|
@@ -473,11 +468,6 @@
|
|
|
473
468
|
"name": "user",
|
|
474
469
|
"isMut": true,
|
|
475
470
|
"isSigner": false
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
"name": "oracle",
|
|
479
|
-
"isMut": false,
|
|
480
|
-
"isSigner": false
|
|
481
471
|
}
|
|
482
472
|
],
|
|
483
473
|
"args": [
|
|
@@ -512,11 +502,6 @@
|
|
|
512
502
|
"name": "authority",
|
|
513
503
|
"isMut": false,
|
|
514
504
|
"isSigner": true
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
|
-
"name": "oracle",
|
|
518
|
-
"isMut": false,
|
|
519
|
-
"isSigner": false
|
|
520
505
|
}
|
|
521
506
|
],
|
|
522
507
|
"args": [
|
|
@@ -556,11 +541,6 @@
|
|
|
556
541
|
"name": "authority",
|
|
557
542
|
"isMut": false,
|
|
558
543
|
"isSigner": true
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
"name": "oracle",
|
|
562
|
-
"isMut": false,
|
|
563
|
-
"isSigner": false
|
|
564
544
|
}
|
|
565
545
|
],
|
|
566
546
|
"args": [
|
package/lib/math/orders.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLimitPrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
-
const anchor_1 = require("@project-serum/anchor");
|
|
7
6
|
const auction_1 = require("./auction");
|
|
8
7
|
function isOrderRiskIncreasing(user, order) {
|
|
9
8
|
if ((0, types_1.isVariant)(order.status, 'init')) {
|
|
@@ -81,18 +80,9 @@ exports.standardizeBaseAssetAmount = standardizeBaseAssetAmount;
|
|
|
81
80
|
function getLimitPrice(order, oraclePriceData, slot) {
|
|
82
81
|
let limitPrice;
|
|
83
82
|
if (!order.oraclePriceOffset.eq(numericConstants_1.ZERO)) {
|
|
84
|
-
|
|
85
|
-
if (order.postOnly) {
|
|
86
|
-
limitPrice = (0, types_1.isVariant)(order.direction, 'long')
|
|
87
|
-
? anchor_1.BN.min(order.price, floatingPrice)
|
|
88
|
-
: anchor_1.BN.max(order.price, floatingPrice);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
limitPrice = floatingPrice;
|
|
92
|
-
}
|
|
83
|
+
limitPrice = oraclePriceData.price.add(order.oraclePriceOffset);
|
|
93
84
|
}
|
|
94
|
-
else if ((0, types_1.
|
|
95
|
-
(0, types_1.isVariant)(order.orderType, 'triggerMarket')) {
|
|
85
|
+
else if ((0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket'])) {
|
|
96
86
|
limitPrice = (0, auction_1.getAuctionPrice)(order, slot);
|
|
97
87
|
}
|
|
98
88
|
else {
|
package/lib/orders.js
CHANGED
|
@@ -101,15 +101,7 @@ function calculateAmountToTradeForLimit(market, order, oraclePriceData) {
|
|
|
101
101
|
if (!oraclePriceData) {
|
|
102
102
|
throw Error('Cant calculate limit price for oracle offset oracle without OraclePriceData');
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
if (order.postOnly) {
|
|
106
|
-
limitPrice = (0, types_1.isVariant)(order.direction, 'long')
|
|
107
|
-
? _1.BN.min(order.price, floatingPrice)
|
|
108
|
-
: _1.BN.max(order.price, floatingPrice);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
limitPrice = floatingPrice;
|
|
112
|
-
}
|
|
104
|
+
limitPrice = oraclePriceData.price.add(order.oraclePriceOffset);
|
|
113
105
|
}
|
|
114
106
|
const [maxAmountToTrade, direction] = (0, amm_1.calculateMaxBaseAssetAmountToTrade)(market.amm, limitPrice, order.direction);
|
|
115
107
|
const baseAssetAmount = (0, _1.standardizeBaseAssetAmount)(maxAmountToTrade, market.amm.baseAssetAmountStepSize);
|
package/package.json
CHANGED
package/src/clearingHouse.ts
CHANGED
|
@@ -827,9 +827,6 @@ export class ClearingHouse {
|
|
|
827
827
|
): Promise<TransactionInstruction> {
|
|
828
828
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
829
829
|
|
|
830
|
-
const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
|
|
831
|
-
.oracle;
|
|
832
|
-
|
|
833
830
|
const remainingAccounts = this.getRemainingAccounts({
|
|
834
831
|
writableMarketIndex: orderParams.marketIndex,
|
|
835
832
|
});
|
|
@@ -839,38 +836,11 @@ export class ClearingHouse {
|
|
|
839
836
|
state: await this.getStatePublicKey(),
|
|
840
837
|
user: userAccountPublicKey,
|
|
841
838
|
authority: this.wallet.publicKey,
|
|
842
|
-
oracle: priceOracle,
|
|
843
839
|
},
|
|
844
840
|
remainingAccounts,
|
|
845
841
|
});
|
|
846
842
|
}
|
|
847
843
|
|
|
848
|
-
public async expireOrders(
|
|
849
|
-
userAccountPublicKey: PublicKey
|
|
850
|
-
): Promise<TransactionSignature> {
|
|
851
|
-
const { txSig } = await this.txSender.send(
|
|
852
|
-
wrapInTx(await this.getExpireOrdersIx(userAccountPublicKey)),
|
|
853
|
-
[],
|
|
854
|
-
this.opts
|
|
855
|
-
);
|
|
856
|
-
return txSig;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
public async getExpireOrdersIx(
|
|
860
|
-
userAccountPublicKey: PublicKey
|
|
861
|
-
): Promise<TransactionInstruction> {
|
|
862
|
-
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
863
|
-
|
|
864
|
-
return await this.program.instruction.expireOrders({
|
|
865
|
-
accounts: {
|
|
866
|
-
state: await this.getStatePublicKey(),
|
|
867
|
-
filler: fillerPublicKey,
|
|
868
|
-
user: userAccountPublicKey,
|
|
869
|
-
authority: this.wallet.publicKey,
|
|
870
|
-
},
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
|
|
874
844
|
public async updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature> {
|
|
875
845
|
const { txSig } = await this.txSender.send(
|
|
876
846
|
wrapInTx(await this.getUpdateAMMsIx(marketIndexes)),
|
|
@@ -970,95 +940,6 @@ export class ClearingHouse {
|
|
|
970
940
|
});
|
|
971
941
|
}
|
|
972
942
|
|
|
973
|
-
public async cancelAllOrders(
|
|
974
|
-
bestEffort?: boolean
|
|
975
|
-
): Promise<TransactionSignature> {
|
|
976
|
-
const { txSig } = await this.txSender.send(
|
|
977
|
-
wrapInTx(await this.getCancelAllOrdersIx(bestEffort)),
|
|
978
|
-
[],
|
|
979
|
-
this.opts
|
|
980
|
-
);
|
|
981
|
-
return txSig;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
public async getCancelAllOrdersIx(
|
|
985
|
-
bestEffort?: boolean
|
|
986
|
-
): Promise<TransactionInstruction> {
|
|
987
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
988
|
-
|
|
989
|
-
const remainingAccounts = this.getRemainingAccounts({});
|
|
990
|
-
|
|
991
|
-
for (const order of this.getUserAccount().orders) {
|
|
992
|
-
const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
|
|
993
|
-
remainingAccounts.push({
|
|
994
|
-
pubkey: oracle,
|
|
995
|
-
isWritable: false,
|
|
996
|
-
isSigner: false,
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
return await this.program.instruction.cancelAllOrders(bestEffort, {
|
|
1001
|
-
accounts: {
|
|
1002
|
-
state: await this.getStatePublicKey(),
|
|
1003
|
-
user: userAccountPublicKey,
|
|
1004
|
-
authority: this.wallet.publicKey,
|
|
1005
|
-
},
|
|
1006
|
-
remainingAccounts,
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
public async cancelOrdersByMarketAndSide(
|
|
1011
|
-
bestEffort?: boolean,
|
|
1012
|
-
marketIndexOnly?: BN,
|
|
1013
|
-
directionOnly?: PositionDirection
|
|
1014
|
-
): Promise<TransactionSignature> {
|
|
1015
|
-
const { txSig } = await this.txSender.send(
|
|
1016
|
-
wrapInTx(
|
|
1017
|
-
await this.getCancelOrdersByMarketAndSideIx(
|
|
1018
|
-
bestEffort,
|
|
1019
|
-
marketIndexOnly,
|
|
1020
|
-
directionOnly
|
|
1021
|
-
)
|
|
1022
|
-
),
|
|
1023
|
-
[],
|
|
1024
|
-
this.opts
|
|
1025
|
-
);
|
|
1026
|
-
return txSig;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
public async getCancelOrdersByMarketAndSideIx(
|
|
1030
|
-
bestEffort?: boolean,
|
|
1031
|
-
marketIndexOnly?: BN,
|
|
1032
|
-
directionOnly?: PositionDirection
|
|
1033
|
-
): Promise<TransactionInstruction> {
|
|
1034
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1035
|
-
|
|
1036
|
-
const remainingAccounts = this.getRemainingAccounts({});
|
|
1037
|
-
|
|
1038
|
-
for (const order of this.getUserAccount().orders) {
|
|
1039
|
-
const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
|
|
1040
|
-
remainingAccounts.push({
|
|
1041
|
-
pubkey: oracle,
|
|
1042
|
-
isWritable: false,
|
|
1043
|
-
isSigner: false,
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
return await this.program.instruction.cancelOrdersByMarketAndSide(
|
|
1048
|
-
bestEffort,
|
|
1049
|
-
marketIndexOnly,
|
|
1050
|
-
directionOnly,
|
|
1051
|
-
{
|
|
1052
|
-
accounts: {
|
|
1053
|
-
state: await this.getStatePublicKey(),
|
|
1054
|
-
user: userAccountPublicKey,
|
|
1055
|
-
authority: this.wallet.publicKey,
|
|
1056
|
-
},
|
|
1057
|
-
remainingAccounts,
|
|
1058
|
-
}
|
|
1059
|
-
);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
943
|
public async fillOrder(
|
|
1063
944
|
userAccountPublicKey: PublicKey,
|
|
1064
945
|
user: UserAccount,
|
|
@@ -1085,7 +966,6 @@ export class ClearingHouse {
|
|
|
1085
966
|
|
|
1086
967
|
const marketIndex = order.marketIndex;
|
|
1087
968
|
const marketAccount = this.getMarketAccount(marketIndex);
|
|
1088
|
-
const oracle = marketAccount.amm.oracle;
|
|
1089
969
|
|
|
1090
970
|
const bankAccountInfos = [
|
|
1091
971
|
{
|
|
@@ -1146,7 +1026,6 @@ export class ClearingHouse {
|
|
|
1146
1026
|
filler: fillerPublicKey,
|
|
1147
1027
|
user: userAccountPublicKey,
|
|
1148
1028
|
authority: this.wallet.publicKey,
|
|
1149
|
-
oracle: oracle,
|
|
1150
1029
|
},
|
|
1151
1030
|
remainingAccounts,
|
|
1152
1031
|
});
|
|
@@ -1249,9 +1128,6 @@ export class ClearingHouse {
|
|
|
1249
1128
|
): Promise<TransactionInstruction> {
|
|
1250
1129
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1251
1130
|
|
|
1252
|
-
const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
|
|
1253
|
-
.oracle;
|
|
1254
|
-
|
|
1255
1131
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1256
1132
|
writableMarketIndex: orderParams.marketIndex,
|
|
1257
1133
|
writableBankIndex: QUOTE_ASSET_BANK_INDEX,
|
|
@@ -1275,7 +1151,6 @@ export class ClearingHouse {
|
|
|
1275
1151
|
state: await this.getStatePublicKey(),
|
|
1276
1152
|
user: userAccountPublicKey,
|
|
1277
1153
|
authority: this.wallet.publicKey,
|
|
1278
|
-
oracle: priceOracle,
|
|
1279
1154
|
},
|
|
1280
1155
|
remainingAccounts,
|
|
1281
1156
|
}
|
|
@@ -381,11 +381,6 @@
|
|
|
381
381
|
"name": "authority",
|
|
382
382
|
"isMut": false,
|
|
383
383
|
"isSigner": true
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
"name": "oracle",
|
|
387
|
-
"isMut": false,
|
|
388
|
-
"isSigner": false
|
|
389
384
|
}
|
|
390
385
|
],
|
|
391
386
|
"args": [
|
|
@@ -473,11 +468,6 @@
|
|
|
473
468
|
"name": "user",
|
|
474
469
|
"isMut": true,
|
|
475
470
|
"isSigner": false
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
"name": "oracle",
|
|
479
|
-
"isMut": false,
|
|
480
|
-
"isSigner": false
|
|
481
471
|
}
|
|
482
472
|
],
|
|
483
473
|
"args": [
|
|
@@ -512,11 +502,6 @@
|
|
|
512
502
|
"name": "authority",
|
|
513
503
|
"isMut": false,
|
|
514
504
|
"isSigner": true
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
|
-
"name": "oracle",
|
|
518
|
-
"isMut": false,
|
|
519
|
-
"isSigner": false
|
|
520
505
|
}
|
|
521
506
|
],
|
|
522
507
|
"args": [
|
|
@@ -556,11 +541,6 @@
|
|
|
556
541
|
"name": "authority",
|
|
557
542
|
"isMut": false,
|
|
558
543
|
"isSigner": true
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
"name": "oracle",
|
|
562
|
-
"isMut": false,
|
|
563
|
-
"isSigner": false
|
|
564
544
|
}
|
|
565
545
|
],
|
|
566
546
|
"args": [
|
package/src/math/orders.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClearingHouseUser } from '../clearingHouseUser';
|
|
2
|
-
import { isVariant, Order } from '../types';
|
|
2
|
+
import { isOneOfVariant, isVariant, Order } from '../types';
|
|
3
3
|
import { ZERO, TWO } from '../constants/numericConstants';
|
|
4
4
|
import { BN } from '@project-serum/anchor';
|
|
5
5
|
import { OraclePriceData } from '../oracles/types';
|
|
@@ -125,18 +125,8 @@ export function getLimitPrice(
|
|
|
125
125
|
): BN {
|
|
126
126
|
let limitPrice;
|
|
127
127
|
if (!order.oraclePriceOffset.eq(ZERO)) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
limitPrice = isVariant(order.direction, 'long')
|
|
131
|
-
? BN.min(order.price, floatingPrice)
|
|
132
|
-
: BN.max(order.price, floatingPrice);
|
|
133
|
-
} else {
|
|
134
|
-
limitPrice = floatingPrice;
|
|
135
|
-
}
|
|
136
|
-
} else if (
|
|
137
|
-
isVariant(order.orderType, 'market') ||
|
|
138
|
-
isVariant(order.orderType, 'triggerMarket')
|
|
139
|
-
) {
|
|
128
|
+
limitPrice = oraclePriceData.price.add(order.oraclePriceOffset);
|
|
129
|
+
} else if (isOneOfVariant(order.orderType, ['market', 'triggerMarket'])) {
|
|
140
130
|
limitPrice = getAuctionPrice(order, slot);
|
|
141
131
|
} else {
|
|
142
132
|
limitPrice = order.price;
|
package/src/orders.ts
CHANGED
|
@@ -186,14 +186,7 @@ export function calculateAmountToTradeForLimit(
|
|
|
186
186
|
'Cant calculate limit price for oracle offset oracle without OraclePriceData'
|
|
187
187
|
);
|
|
188
188
|
}
|
|
189
|
-
|
|
190
|
-
if (order.postOnly) {
|
|
191
|
-
limitPrice = isVariant(order.direction, 'long')
|
|
192
|
-
? BN.min(order.price, floatingPrice)
|
|
193
|
-
: BN.max(order.price, floatingPrice);
|
|
194
|
-
} else {
|
|
195
|
-
limitPrice = floatingPrice;
|
|
196
|
-
}
|
|
189
|
+
limitPrice = oraclePriceData.price.add(order.oraclePriceOffset);
|
|
197
190
|
}
|
|
198
191
|
|
|
199
192
|
const [maxAmountToTrade, direction] = calculateMaxBaseAssetAmountToTrade(
|