@drift-labs/sdk 0.2.0-master.4 → 0.2.0-temp.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/admin.d.ts +1 -3
- package/lib/admin.js +2 -20
- package/lib/clearingHouse.d.ts +5 -6
- package/lib/clearingHouse.js +3 -20
- package/lib/idl/clearing_house.json +13 -83
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -6
- package/lib/math/amm.js +35 -7
- package/lib/math/auction.js +1 -4
- package/lib/math/orders.d.ts +2 -2
- package/lib/math/orders.js +2 -19
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +10 -7
- package/lib/orderParams.d.ts +5 -14
- package/lib/orderParams.js +96 -8
- package/lib/types.d.ts +1 -57
- package/lib/types.js +1 -36
- package/package.json +3 -3
- package/src/admin.ts +4 -35
- package/src/clearingHouse.ts +25 -27
- package/src/idl/clearing_house.json +13 -83
- package/src/index.ts +1 -2
- package/src/math/amm.ts +49 -19
- package/src/math/auction.ts +1 -5
- package/src/math/orders.ts +3 -17
- package/src/math/trade.ts +25 -23
- package/src/orderParams.ts +141 -20
- package/src/types.ts +2 -54
package/lib/orderParams.js
CHANGED
|
@@ -2,19 +2,107 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMarketOrderParams = exports.getTriggerLimitOrderParams = exports.getTriggerMarketOrderParams = exports.getLimitOrderParams = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const numericConstants_1 = require("./constants/numericConstants");
|
|
6
|
+
function getLimitOrderParams(marketIndex, direction, baseAssetAmount, price, reduceOnly, discountToken = false, referrer = false, userOrderId = 0, postOnly = false, oraclePriceOffset = numericConstants_1.ZERO, immediateOrCancel = false) {
|
|
7
|
+
return {
|
|
8
|
+
orderType: types_1.OrderType.LIMIT,
|
|
9
|
+
userOrderId,
|
|
10
|
+
marketIndex,
|
|
11
|
+
direction,
|
|
12
|
+
quoteAssetAmount: numericConstants_1.ZERO,
|
|
13
|
+
baseAssetAmount,
|
|
14
|
+
price,
|
|
15
|
+
reduceOnly,
|
|
16
|
+
postOnly,
|
|
17
|
+
immediateOrCancel,
|
|
18
|
+
positionLimit: numericConstants_1.ZERO,
|
|
19
|
+
padding0: true,
|
|
20
|
+
padding1: numericConstants_1.ZERO,
|
|
21
|
+
optionalAccounts: {
|
|
22
|
+
discountToken,
|
|
23
|
+
referrer,
|
|
24
|
+
},
|
|
25
|
+
triggerCondition: types_1.OrderTriggerCondition.ABOVE,
|
|
26
|
+
triggerPrice: numericConstants_1.ZERO,
|
|
27
|
+
oraclePriceOffset,
|
|
28
|
+
};
|
|
7
29
|
}
|
|
8
30
|
exports.getLimitOrderParams = getLimitOrderParams;
|
|
9
|
-
function getTriggerMarketOrderParams(
|
|
10
|
-
return
|
|
31
|
+
function getTriggerMarketOrderParams(marketIndex, direction, baseAssetAmount, triggerPrice, triggerCondition, reduceOnly, discountToken = false, referrer = false, userOrderId = 0) {
|
|
32
|
+
return {
|
|
33
|
+
orderType: types_1.OrderType.TRIGGER_MARKET,
|
|
34
|
+
userOrderId,
|
|
35
|
+
marketIndex,
|
|
36
|
+
direction,
|
|
37
|
+
quoteAssetAmount: numericConstants_1.ZERO,
|
|
38
|
+
baseAssetAmount,
|
|
39
|
+
price: numericConstants_1.ZERO,
|
|
40
|
+
reduceOnly,
|
|
41
|
+
postOnly: false,
|
|
42
|
+
immediateOrCancel: false,
|
|
43
|
+
positionLimit: numericConstants_1.ZERO,
|
|
44
|
+
padding0: true,
|
|
45
|
+
padding1: numericConstants_1.ZERO,
|
|
46
|
+
optionalAccounts: {
|
|
47
|
+
discountToken,
|
|
48
|
+
referrer,
|
|
49
|
+
},
|
|
50
|
+
triggerCondition,
|
|
51
|
+
triggerPrice,
|
|
52
|
+
oraclePriceOffset: numericConstants_1.ZERO,
|
|
53
|
+
};
|
|
11
54
|
}
|
|
12
55
|
exports.getTriggerMarketOrderParams = getTriggerMarketOrderParams;
|
|
13
|
-
function getTriggerLimitOrderParams(
|
|
14
|
-
return
|
|
56
|
+
function getTriggerLimitOrderParams(marketIndex, direction, baseAssetAmount, price, triggerPrice, triggerCondition, reduceOnly, discountToken = false, referrer = false, userOrderId = 0) {
|
|
57
|
+
return {
|
|
58
|
+
orderType: types_1.OrderType.TRIGGER_LIMIT,
|
|
59
|
+
userOrderId,
|
|
60
|
+
marketIndex,
|
|
61
|
+
direction,
|
|
62
|
+
quoteAssetAmount: numericConstants_1.ZERO,
|
|
63
|
+
baseAssetAmount,
|
|
64
|
+
price,
|
|
65
|
+
reduceOnly,
|
|
66
|
+
postOnly: false,
|
|
67
|
+
immediateOrCancel: false,
|
|
68
|
+
positionLimit: numericConstants_1.ZERO,
|
|
69
|
+
padding0: true,
|
|
70
|
+
padding1: numericConstants_1.ZERO,
|
|
71
|
+
optionalAccounts: {
|
|
72
|
+
discountToken,
|
|
73
|
+
referrer,
|
|
74
|
+
},
|
|
75
|
+
triggerCondition,
|
|
76
|
+
triggerPrice,
|
|
77
|
+
oraclePriceOffset: numericConstants_1.ZERO,
|
|
78
|
+
};
|
|
15
79
|
}
|
|
16
80
|
exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;
|
|
17
|
-
function getMarketOrderParams(
|
|
18
|
-
|
|
81
|
+
function getMarketOrderParams(marketIndex, direction, quoteAssetAmount, baseAssetAmount, reduceOnly, price = numericConstants_1.ZERO, discountToken = false, referrer = false) {
|
|
82
|
+
if (baseAssetAmount.eq(numericConstants_1.ZERO) && quoteAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
83
|
+
throw Error('baseAssetAmount or quoteAssetAmount must be zero');
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
orderType: types_1.OrderType.MARKET,
|
|
87
|
+
userOrderId: 0,
|
|
88
|
+
marketIndex,
|
|
89
|
+
direction,
|
|
90
|
+
quoteAssetAmount,
|
|
91
|
+
baseAssetAmount,
|
|
92
|
+
price,
|
|
93
|
+
reduceOnly,
|
|
94
|
+
postOnly: false,
|
|
95
|
+
immediateOrCancel: false,
|
|
96
|
+
positionLimit: numericConstants_1.ZERO,
|
|
97
|
+
padding0: true,
|
|
98
|
+
padding1: numericConstants_1.ZERO,
|
|
99
|
+
optionalAccounts: {
|
|
100
|
+
discountToken,
|
|
101
|
+
referrer,
|
|
102
|
+
},
|
|
103
|
+
triggerCondition: types_1.OrderTriggerCondition.ABOVE,
|
|
104
|
+
triggerPrice: numericConstants_1.ZERO,
|
|
105
|
+
oraclePriceOffset: numericConstants_1.ZERO,
|
|
106
|
+
};
|
|
19
107
|
}
|
|
20
108
|
exports.getMarketOrderParams = getMarketOrderParams;
|
package/lib/types.d.ts
CHANGED
|
@@ -92,20 +92,6 @@ export declare class OrderAction {
|
|
|
92
92
|
trigger: {};
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
export declare class OrderActionExplanation {
|
|
96
|
-
static readonly NONE: {
|
|
97
|
-
none: {};
|
|
98
|
-
};
|
|
99
|
-
static readonly BREACHED_MARGIN_REQUIREMENT: {
|
|
100
|
-
breachedMarginRequirement: {};
|
|
101
|
-
};
|
|
102
|
-
static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE: {
|
|
103
|
-
oraclePriceBreachedLimitPrice: {};
|
|
104
|
-
};
|
|
105
|
-
static readonly MARKET_ORDER_FILLED_TO_LIMIT_PRICE: {
|
|
106
|
-
marketOrderFilledToLimitPrice: {};
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
95
|
export declare class OrderTriggerCondition {
|
|
110
96
|
static readonly ABOVE: {
|
|
111
97
|
above: {};
|
|
@@ -199,10 +185,7 @@ export declare type OrderRecord = {
|
|
|
199
185
|
maker: PublicKey;
|
|
200
186
|
takerOrder: Order;
|
|
201
187
|
makerOrder: Order;
|
|
202
|
-
takerUnsettledPnl: BN;
|
|
203
|
-
makerUnsettledPnl: BN;
|
|
204
188
|
action: OrderAction;
|
|
205
|
-
actionExplanation: OrderActionExplanation;
|
|
206
189
|
filler: PublicKey;
|
|
207
190
|
fillRecordId: BN;
|
|
208
191
|
marketIndex: BN;
|
|
@@ -294,8 +277,6 @@ export declare type AMM = {
|
|
|
294
277
|
lastMarkPriceTwapTs: BN;
|
|
295
278
|
lastOraclePriceTwap: BN;
|
|
296
279
|
lastOraclePriceTwapTs: BN;
|
|
297
|
-
lastOracleMarkSpreadPct: BN;
|
|
298
|
-
lastOracleConfPct: BN;
|
|
299
280
|
oracle: PublicKey;
|
|
300
281
|
oracleSource: OracleSource;
|
|
301
282
|
fundingPeriod: BN;
|
|
@@ -310,8 +291,6 @@ export declare type AMM = {
|
|
|
310
291
|
totalFee: BN;
|
|
311
292
|
minimumQuoteAssetTradeSize: BN;
|
|
312
293
|
baseAssetAmountStepSize: BN;
|
|
313
|
-
maxBaseAssetAmountRatio: number;
|
|
314
|
-
maxSlippageRatio: number;
|
|
315
294
|
lastOraclePrice: BN;
|
|
316
295
|
baseSpread: number;
|
|
317
296
|
curveUpdateIntensity: number;
|
|
@@ -396,6 +375,7 @@ export declare type OrderParams = {
|
|
|
396
375
|
orderType: OrderType;
|
|
397
376
|
userOrderId: number;
|
|
398
377
|
direction: PositionDirection;
|
|
378
|
+
quoteAssetAmount: BN;
|
|
399
379
|
baseAssetAmount: BN;
|
|
400
380
|
price: BN;
|
|
401
381
|
marketIndex: BN;
|
|
@@ -413,42 +393,6 @@ export declare type OrderParams = {
|
|
|
413
393
|
referrer: boolean;
|
|
414
394
|
};
|
|
415
395
|
};
|
|
416
|
-
export declare type NecessaryOrderParams = {
|
|
417
|
-
orderType: OrderType;
|
|
418
|
-
marketIndex: BN;
|
|
419
|
-
baseAssetAmount: BN;
|
|
420
|
-
direction: PositionDirection;
|
|
421
|
-
};
|
|
422
|
-
export declare type OptionalOrderParams = {
|
|
423
|
-
[Property in keyof OrderParams]?: OrderParams[Property];
|
|
424
|
-
} & NecessaryOrderParams;
|
|
425
|
-
export declare const DefaultOrderParams: {
|
|
426
|
-
orderType: {
|
|
427
|
-
market: {};
|
|
428
|
-
};
|
|
429
|
-
userOrderId: number;
|
|
430
|
-
direction: {
|
|
431
|
-
long: {};
|
|
432
|
-
};
|
|
433
|
-
baseAssetAmount: BN;
|
|
434
|
-
price: BN;
|
|
435
|
-
marketIndex: BN;
|
|
436
|
-
reduceOnly: boolean;
|
|
437
|
-
postOnly: boolean;
|
|
438
|
-
immediateOrCancel: boolean;
|
|
439
|
-
triggerPrice: BN;
|
|
440
|
-
triggerCondition: {
|
|
441
|
-
above: {};
|
|
442
|
-
};
|
|
443
|
-
positionLimit: BN;
|
|
444
|
-
oraclePriceOffset: BN;
|
|
445
|
-
padding0: BN;
|
|
446
|
-
padding1: BN;
|
|
447
|
-
optionalAccounts: {
|
|
448
|
-
discountToken: boolean;
|
|
449
|
-
referrer: boolean;
|
|
450
|
-
};
|
|
451
|
-
};
|
|
452
396
|
export declare type MakerInfo = {
|
|
453
397
|
maker: PublicKey;
|
|
454
398
|
order: Order;
|
package/lib/types.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const _1 = require(".");
|
|
3
|
+
exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
|
|
5
4
|
// # Utility Types / Enums / Constants
|
|
6
5
|
class SwapDirection {
|
|
7
6
|
}
|
|
@@ -52,19 +51,6 @@ OrderAction.CANCEL = { cancel: {} };
|
|
|
52
51
|
OrderAction.EXPIRE = { expire: {} };
|
|
53
52
|
OrderAction.FILL = { fill: {} };
|
|
54
53
|
OrderAction.TRIGGER = { trigger: {} };
|
|
55
|
-
class OrderActionExplanation {
|
|
56
|
-
}
|
|
57
|
-
exports.OrderActionExplanation = OrderActionExplanation;
|
|
58
|
-
OrderActionExplanation.NONE = { none: {} };
|
|
59
|
-
OrderActionExplanation.BREACHED_MARGIN_REQUIREMENT = {
|
|
60
|
-
breachedMarginRequirement: {},
|
|
61
|
-
};
|
|
62
|
-
OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
63
|
-
oraclePriceBreachedLimitPrice: {},
|
|
64
|
-
};
|
|
65
|
-
OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
|
|
66
|
-
marketOrderFilledToLimitPrice: {},
|
|
67
|
-
};
|
|
68
54
|
class OrderTriggerCondition {
|
|
69
55
|
}
|
|
70
56
|
exports.OrderTriggerCondition = OrderTriggerCondition;
|
|
@@ -86,24 +72,3 @@ var TradeSide;
|
|
|
86
72
|
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
87
73
|
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
88
74
|
})(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
|
|
89
|
-
exports.DefaultOrderParams = {
|
|
90
|
-
orderType: OrderType.MARKET,
|
|
91
|
-
userOrderId: 0,
|
|
92
|
-
direction: PositionDirection.LONG,
|
|
93
|
-
baseAssetAmount: _1.ZERO,
|
|
94
|
-
price: _1.ZERO,
|
|
95
|
-
marketIndex: _1.ZERO,
|
|
96
|
-
reduceOnly: false,
|
|
97
|
-
postOnly: false,
|
|
98
|
-
immediateOrCancel: false,
|
|
99
|
-
triggerPrice: _1.ZERO,
|
|
100
|
-
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
101
|
-
positionLimit: _1.ZERO,
|
|
102
|
-
oraclePriceOffset: _1.ZERO,
|
|
103
|
-
padding0: _1.ZERO,
|
|
104
|
-
padding1: _1.ZERO,
|
|
105
|
-
optionalAccounts: {
|
|
106
|
-
discountToken: false,
|
|
107
|
-
referrer: false,
|
|
108
|
-
},
|
|
109
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "0.2.0-
|
|
3
|
+
"version": "0.2.0-temp.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@project-serum/anchor": "0.24.2",
|
|
33
|
-
"@pythnetwork/client": "2.5.
|
|
33
|
+
"@pythnetwork/client": "2.5.1",
|
|
34
34
|
"@solana/spl-token": "^0.1.6",
|
|
35
35
|
"@solana/web3.js": "1.41.0",
|
|
36
36
|
"@switchboard-xyz/switchboard-v2": "^0.0.67",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/chai": "^4.3.1",
|
|
42
|
-
"@types/jest": "^28.1.3",
|
|
43
42
|
"@types/mocha": "^9.1.1",
|
|
44
43
|
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
|
45
44
|
"@typescript-eslint/parser": "^4.28.0",
|
|
45
|
+
"@types/jest": "^28.1.3",
|
|
46
46
|
"chai": "^4.3.6",
|
|
47
47
|
"eslint": "^7.29.0",
|
|
48
48
|
"eslint-config-prettier": "^8.3.0",
|
package/src/admin.ts
CHANGED
|
@@ -675,13 +675,11 @@ export class Admin extends ClearingHouse {
|
|
|
675
675
|
});
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
-
public async
|
|
679
|
-
|
|
680
|
-
maxDuration: BN | number
|
|
678
|
+
public async updateOrderAuctionTime(
|
|
679
|
+
time: BN | number
|
|
681
680
|
): Promise<TransactionSignature> {
|
|
682
|
-
return await this.program.rpc.
|
|
683
|
-
typeof
|
|
684
|
-
typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
|
|
681
|
+
return await this.program.rpc.updateOrderAuctionTime(
|
|
682
|
+
typeof time === 'number' ? time : time.toNumber,
|
|
685
683
|
{
|
|
686
684
|
accounts: {
|
|
687
685
|
admin: this.wallet.publicKey,
|
|
@@ -690,33 +688,4 @@ export class Admin extends ClearingHouse {
|
|
|
690
688
|
}
|
|
691
689
|
);
|
|
692
690
|
}
|
|
693
|
-
|
|
694
|
-
public async updateMaxBaseAssetAmountRatio(
|
|
695
|
-
marketIndex: BN,
|
|
696
|
-
maxBaseAssetAmountRatio: number
|
|
697
|
-
): Promise<TransactionSignature> {
|
|
698
|
-
return await this.program.rpc.updateMaxBaseAssetAmountRatio(
|
|
699
|
-
maxBaseAssetAmountRatio,
|
|
700
|
-
{
|
|
701
|
-
accounts: {
|
|
702
|
-
admin: this.wallet.publicKey,
|
|
703
|
-
state: await this.getStatePublicKey(),
|
|
704
|
-
market: this.getMarketAccount(marketIndex).pubkey,
|
|
705
|
-
},
|
|
706
|
-
}
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
public async updateMaxSlippageRatio(
|
|
711
|
-
marketIndex: BN,
|
|
712
|
-
maxSlippageRatio: number
|
|
713
|
-
): Promise<TransactionSignature> {
|
|
714
|
-
return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
715
|
-
accounts: {
|
|
716
|
-
admin: this.wallet.publicKey,
|
|
717
|
-
state: await this.getStatePublicKey(),
|
|
718
|
-
market: this.getMarketAccount(marketIndex).pubkey,
|
|
719
|
-
},
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
691
|
}
|
package/src/clearingHouse.ts
CHANGED
|
@@ -11,9 +11,6 @@ import {
|
|
|
11
11
|
BankAccount,
|
|
12
12
|
UserBankBalance,
|
|
13
13
|
MakerInfo,
|
|
14
|
-
OptionalOrderParams,
|
|
15
|
-
DefaultOrderParams,
|
|
16
|
-
OrderType,
|
|
17
14
|
} from './types';
|
|
18
15
|
import * as anchor from '@project-serum/anchor';
|
|
19
16
|
import clearingHouseIDL from './idl/clearing_house.json';
|
|
@@ -55,6 +52,7 @@ import { WebSocketClearingHouseAccountSubscriber } from './accounts/webSocketCle
|
|
|
55
52
|
import { RetryTxSender } from './tx/retryTxSender';
|
|
56
53
|
import { ClearingHouseUser } from './clearingHouseUser';
|
|
57
54
|
import { ClearingHouseUserAccountSubscriptionConfig } from './clearingHouseUserConfig';
|
|
55
|
+
import { getMarketOrderParams } from './orderParams';
|
|
58
56
|
import { getMarketsBanksAndOraclesForSubscription } from './config';
|
|
59
57
|
|
|
60
58
|
/**
|
|
@@ -800,17 +798,20 @@ export class ClearingHouse {
|
|
|
800
798
|
marketIndex: BN,
|
|
801
799
|
limitPrice?: BN
|
|
802
800
|
): Promise<TransactionSignature> {
|
|
803
|
-
return await this.placeAndTake(
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
801
|
+
return await this.placeAndTake(
|
|
802
|
+
getMarketOrderParams(
|
|
803
|
+
marketIndex,
|
|
804
|
+
direction,
|
|
805
|
+
ZERO,
|
|
806
|
+
amount,
|
|
807
|
+
false,
|
|
808
|
+
limitPrice
|
|
809
|
+
)
|
|
810
|
+
);
|
|
810
811
|
}
|
|
811
812
|
|
|
812
813
|
public async placeOrder(
|
|
813
|
-
orderParams:
|
|
814
|
+
orderParams: OrderParams
|
|
814
815
|
): Promise<TransactionSignature> {
|
|
815
816
|
const { txSig, slot } = await this.txSender.send(
|
|
816
817
|
wrapInTx(await this.getPlaceOrderIx(orderParams)),
|
|
@@ -821,14 +822,9 @@ export class ClearingHouse {
|
|
|
821
822
|
return txSig;
|
|
822
823
|
}
|
|
823
824
|
|
|
824
|
-
getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams {
|
|
825
|
-
return Object.assign({}, DefaultOrderParams, optionalOrderParams);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
825
|
public async getPlaceOrderIx(
|
|
829
|
-
orderParams:
|
|
826
|
+
orderParams: OrderParams
|
|
830
827
|
): Promise<TransactionInstruction> {
|
|
831
|
-
orderParams = this.getOrderParams(orderParams);
|
|
832
828
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
833
829
|
|
|
834
830
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1114,7 +1110,7 @@ export class ClearingHouse {
|
|
|
1114
1110
|
}
|
|
1115
1111
|
|
|
1116
1112
|
public async placeAndTake(
|
|
1117
|
-
orderParams:
|
|
1113
|
+
orderParams: OrderParams,
|
|
1118
1114
|
makerInfo?: MakerInfo
|
|
1119
1115
|
): Promise<TransactionSignature> {
|
|
1120
1116
|
const { txSig, slot } = await this.txSender.send(
|
|
@@ -1127,10 +1123,9 @@ export class ClearingHouse {
|
|
|
1127
1123
|
}
|
|
1128
1124
|
|
|
1129
1125
|
public async getPlaceAndTakeIx(
|
|
1130
|
-
orderParams:
|
|
1126
|
+
orderParams: OrderParams,
|
|
1131
1127
|
makerInfo?: MakerInfo
|
|
1132
1128
|
): Promise<TransactionInstruction> {
|
|
1133
|
-
orderParams = this.getOrderParams(orderParams);
|
|
1134
1129
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1135
1130
|
|
|
1136
1131
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1173,13 +1168,16 @@ export class ClearingHouse {
|
|
|
1173
1168
|
throw Error(`No position in market ${marketIndex.toString()}`);
|
|
1174
1169
|
}
|
|
1175
1170
|
|
|
1176
|
-
return await this.placeAndTake(
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1171
|
+
return await this.placeAndTake(
|
|
1172
|
+
getMarketOrderParams(
|
|
1173
|
+
marketIndex,
|
|
1174
|
+
findDirectionToClose(userPosition),
|
|
1175
|
+
ZERO,
|
|
1176
|
+
userPosition.baseAssetAmount,
|
|
1177
|
+
true,
|
|
1178
|
+
undefined
|
|
1179
|
+
)
|
|
1180
|
+
);
|
|
1183
1181
|
}
|
|
1184
1182
|
|
|
1185
1183
|
public async settlePNLs(
|
|
@@ -1441,58 +1441,6 @@
|
|
|
1441
1441
|
}
|
|
1442
1442
|
]
|
|
1443
1443
|
},
|
|
1444
|
-
{
|
|
1445
|
-
"name": "updateMarketMaxSlippageRatio",
|
|
1446
|
-
"accounts": [
|
|
1447
|
-
{
|
|
1448
|
-
"name": "admin",
|
|
1449
|
-
"isMut": false,
|
|
1450
|
-
"isSigner": true
|
|
1451
|
-
},
|
|
1452
|
-
{
|
|
1453
|
-
"name": "state",
|
|
1454
|
-
"isMut": false,
|
|
1455
|
-
"isSigner": false
|
|
1456
|
-
},
|
|
1457
|
-
{
|
|
1458
|
-
"name": "market",
|
|
1459
|
-
"isMut": true,
|
|
1460
|
-
"isSigner": false
|
|
1461
|
-
}
|
|
1462
|
-
],
|
|
1463
|
-
"args": [
|
|
1464
|
-
{
|
|
1465
|
-
"name": "maxSlippageRatio",
|
|
1466
|
-
"type": "u16"
|
|
1467
|
-
}
|
|
1468
|
-
]
|
|
1469
|
-
},
|
|
1470
|
-
{
|
|
1471
|
-
"name": "updateMaxBaseAssetAmountRatio",
|
|
1472
|
-
"accounts": [
|
|
1473
|
-
{
|
|
1474
|
-
"name": "admin",
|
|
1475
|
-
"isMut": false,
|
|
1476
|
-
"isSigner": true
|
|
1477
|
-
},
|
|
1478
|
-
{
|
|
1479
|
-
"name": "state",
|
|
1480
|
-
"isMut": false,
|
|
1481
|
-
"isSigner": false
|
|
1482
|
-
},
|
|
1483
|
-
{
|
|
1484
|
-
"name": "market",
|
|
1485
|
-
"isMut": true,
|
|
1486
|
-
"isSigner": false
|
|
1487
|
-
}
|
|
1488
|
-
],
|
|
1489
|
-
"args": [
|
|
1490
|
-
{
|
|
1491
|
-
"name": "maxBaseAssetAmountRatio",
|
|
1492
|
-
"type": "u16"
|
|
1493
|
-
}
|
|
1494
|
-
]
|
|
1495
|
-
},
|
|
1496
1444
|
{
|
|
1497
1445
|
"name": "updateAdmin",
|
|
1498
1446
|
"accounts": [
|
|
@@ -1615,7 +1563,7 @@
|
|
|
1615
1563
|
]
|
|
1616
1564
|
},
|
|
1617
1565
|
{
|
|
1618
|
-
"name": "
|
|
1566
|
+
"name": "updateOrderAuctionTime",
|
|
1619
1567
|
"accounts": [
|
|
1620
1568
|
{
|
|
1621
1569
|
"name": "admin",
|
|
@@ -1630,11 +1578,7 @@
|
|
|
1630
1578
|
],
|
|
1631
1579
|
"args": [
|
|
1632
1580
|
{
|
|
1633
|
-
"name": "
|
|
1634
|
-
"type": "u8"
|
|
1635
|
-
},
|
|
1636
|
-
{
|
|
1637
|
-
"name": "maxAuctionDuration",
|
|
1581
|
+
"name": "orderAuctionTime",
|
|
1638
1582
|
"type": "u8"
|
|
1639
1583
|
}
|
|
1640
1584
|
]
|
|
@@ -1941,11 +1885,7 @@
|
|
|
1941
1885
|
"type": "u128"
|
|
1942
1886
|
},
|
|
1943
1887
|
{
|
|
1944
|
-
"name": "
|
|
1945
|
-
"type": "u8"
|
|
1946
|
-
},
|
|
1947
|
-
{
|
|
1948
|
-
"name": "maxAuctionDuration",
|
|
1888
|
+
"name": "orderAuctionDuration",
|
|
1949
1889
|
"type": "u8"
|
|
1950
1890
|
},
|
|
1951
1891
|
{
|
|
@@ -2050,6 +1990,10 @@
|
|
|
2050
1990
|
"name": "userOrderId",
|
|
2051
1991
|
"type": "u8"
|
|
2052
1992
|
},
|
|
1993
|
+
{
|
|
1994
|
+
"name": "quoteAssetAmount",
|
|
1995
|
+
"type": "u128"
|
|
1996
|
+
},
|
|
2053
1997
|
{
|
|
2054
1998
|
"name": "baseAssetAmount",
|
|
2055
1999
|
"type": "u128"
|
|
@@ -2098,10 +2042,6 @@
|
|
|
2098
2042
|
"name": "oraclePriceOffset",
|
|
2099
2043
|
"type": "i128"
|
|
2100
2044
|
},
|
|
2101
|
-
{
|
|
2102
|
-
"name": "auctionDuration",
|
|
2103
|
-
"type": "u8"
|
|
2104
|
-
},
|
|
2105
2045
|
{
|
|
2106
2046
|
"name": "padding0",
|
|
2107
2047
|
"type": "bool"
|
|
@@ -2264,14 +2204,6 @@
|
|
|
2264
2204
|
"name": "minimumQuoteAssetTradeSize",
|
|
2265
2205
|
"type": "u128"
|
|
2266
2206
|
},
|
|
2267
|
-
{
|
|
2268
|
-
"name": "maxBaseAssetAmountRatio",
|
|
2269
|
-
"type": "u16"
|
|
2270
|
-
},
|
|
2271
|
-
{
|
|
2272
|
-
"name": "maxSlippageRatio",
|
|
2273
|
-
"type": "u16"
|
|
2274
|
-
},
|
|
2275
2207
|
{
|
|
2276
2208
|
"name": "baseAssetAmountStepSize",
|
|
2277
2209
|
"type": "u128"
|
|
@@ -2756,6 +2688,10 @@
|
|
|
2756
2688
|
"defined": "PositionDirection"
|
|
2757
2689
|
}
|
|
2758
2690
|
},
|
|
2691
|
+
{
|
|
2692
|
+
"name": "quoteAssetAmount",
|
|
2693
|
+
"type": "u128"
|
|
2694
|
+
},
|
|
2759
2695
|
{
|
|
2760
2696
|
"name": "baseAssetAmount",
|
|
2761
2697
|
"type": "u128"
|
|
@@ -2968,12 +2904,6 @@
|
|
|
2968
2904
|
},
|
|
2969
2905
|
{
|
|
2970
2906
|
"name": "OraclePriceBreachedLimitPrice"
|
|
2971
|
-
},
|
|
2972
|
-
{
|
|
2973
|
-
"name": "MarketOrderFilledToLimitPrice"
|
|
2974
|
-
},
|
|
2975
|
-
{
|
|
2976
|
-
"name": "MarketOrderAuctionExpired"
|
|
2977
2907
|
}
|
|
2978
2908
|
]
|
|
2979
2909
|
}
|
|
@@ -3761,8 +3691,8 @@
|
|
|
3761
3691
|
},
|
|
3762
3692
|
{
|
|
3763
3693
|
"code": 6044,
|
|
3764
|
-
"name": "
|
|
3765
|
-
"msg": "
|
|
3694
|
+
"name": "CouldNotFillOrder",
|
|
3695
|
+
"msg": "CouldNotFillOrder"
|
|
3766
3696
|
},
|
|
3767
3697
|
{
|
|
3768
3698
|
"code": 6045,
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BN } from '@project-serum/anchor';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
import pyth from '@pythnetwork/client';
|
|
4
3
|
|
|
5
4
|
export * from './mockUSDCFaucet';
|
|
6
5
|
export * from './oracles/types';
|
|
@@ -50,4 +49,4 @@ export * from './math/bankBalance';
|
|
|
50
49
|
export * from './constants/banks';
|
|
51
50
|
export * from './clearingHouseConfig';
|
|
52
51
|
|
|
53
|
-
export { BN, PublicKey
|
|
52
|
+
export { BN, PublicKey };
|