@drift-labs/sdk 0.2.0-master.3 → 0.2.0-master.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/lib/admin.d.ts +3 -1
- package/lib/admin.js +20 -2
- package/lib/clearingHouse.d.ts +6 -5
- package/lib/clearingHouse.js +21 -4
- package/lib/idl/clearing_house.json +83 -13
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -1
- package/lib/math/amm.js +7 -35
- package/lib/math/auction.js +4 -1
- package/lib/math/orders.d.ts +2 -2
- package/lib/math/orders.js +19 -2
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +7 -10
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/types.d.ts +57 -1
- package/lib/types.js +36 -1
- package/package.json +3 -3
- package/src/admin.ts +35 -4
- package/src/clearingHouse.ts +28 -26
- package/src/idl/clearing_house.json +83 -13
- package/src/index.ts +2 -1
- package/src/math/amm.ts +19 -49
- package/src/math/auction.ts +5 -1
- package/src/math/orders.ts +17 -3
- package/src/math/trade.ts +23 -25
- package/src/orderParams.ts +20 -141
- package/src/types.ts +54 -2
package/lib/orderParams.js
CHANGED
|
@@ -2,107 +2,19 @@
|
|
|
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
|
-
|
|
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
|
-
};
|
|
5
|
+
function getLimitOrderParams(params) {
|
|
6
|
+
return Object.assign({}, params, { orderType: types_1.OrderType.LIMIT });
|
|
29
7
|
}
|
|
30
8
|
exports.getLimitOrderParams = getLimitOrderParams;
|
|
31
|
-
function getTriggerMarketOrderParams(
|
|
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
|
-
};
|
|
9
|
+
function getTriggerMarketOrderParams(params) {
|
|
10
|
+
return Object.assign({}, params, { orderType: types_1.OrderType.TRIGGER_MARKET });
|
|
54
11
|
}
|
|
55
12
|
exports.getTriggerMarketOrderParams = getTriggerMarketOrderParams;
|
|
56
|
-
function getTriggerLimitOrderParams(
|
|
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
|
-
};
|
|
13
|
+
function getTriggerLimitOrderParams(params) {
|
|
14
|
+
return Object.assign({}, params, { orderType: types_1.OrderType.TRIGGER_LIMIT });
|
|
79
15
|
}
|
|
80
16
|
exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;
|
|
81
|
-
function getMarketOrderParams(
|
|
82
|
-
|
|
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
|
-
};
|
|
17
|
+
function getMarketOrderParams(params) {
|
|
18
|
+
return Object.assign({}, params, { orderType: types_1.OrderType.MARKET });
|
|
107
19
|
}
|
|
108
20
|
exports.getMarketOrderParams = getMarketOrderParams;
|
package/lib/types.d.ts
CHANGED
|
@@ -92,6 +92,20 @@ 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
|
+
}
|
|
95
109
|
export declare class OrderTriggerCondition {
|
|
96
110
|
static readonly ABOVE: {
|
|
97
111
|
above: {};
|
|
@@ -185,7 +199,10 @@ export declare type OrderRecord = {
|
|
|
185
199
|
maker: PublicKey;
|
|
186
200
|
takerOrder: Order;
|
|
187
201
|
makerOrder: Order;
|
|
202
|
+
takerUnsettledPnl: BN;
|
|
203
|
+
makerUnsettledPnl: BN;
|
|
188
204
|
action: OrderAction;
|
|
205
|
+
actionExplanation: OrderActionExplanation;
|
|
189
206
|
filler: PublicKey;
|
|
190
207
|
fillRecordId: BN;
|
|
191
208
|
marketIndex: BN;
|
|
@@ -277,6 +294,8 @@ export declare type AMM = {
|
|
|
277
294
|
lastMarkPriceTwapTs: BN;
|
|
278
295
|
lastOraclePriceTwap: BN;
|
|
279
296
|
lastOraclePriceTwapTs: BN;
|
|
297
|
+
lastOracleMarkSpreadPct: BN;
|
|
298
|
+
lastOracleConfPct: BN;
|
|
280
299
|
oracle: PublicKey;
|
|
281
300
|
oracleSource: OracleSource;
|
|
282
301
|
fundingPeriod: BN;
|
|
@@ -291,6 +310,8 @@ export declare type AMM = {
|
|
|
291
310
|
totalFee: BN;
|
|
292
311
|
minimumQuoteAssetTradeSize: BN;
|
|
293
312
|
baseAssetAmountStepSize: BN;
|
|
313
|
+
maxBaseAssetAmountRatio: number;
|
|
314
|
+
maxSlippageRatio: number;
|
|
294
315
|
lastOraclePrice: BN;
|
|
295
316
|
baseSpread: number;
|
|
296
317
|
curveUpdateIntensity: number;
|
|
@@ -375,7 +396,6 @@ export declare type OrderParams = {
|
|
|
375
396
|
orderType: OrderType;
|
|
376
397
|
userOrderId: number;
|
|
377
398
|
direction: PositionDirection;
|
|
378
|
-
quoteAssetAmount: BN;
|
|
379
399
|
baseAssetAmount: BN;
|
|
380
400
|
price: BN;
|
|
381
401
|
marketIndex: BN;
|
|
@@ -393,6 +413,42 @@ export declare type OrderParams = {
|
|
|
393
413
|
referrer: boolean;
|
|
394
414
|
};
|
|
395
415
|
};
|
|
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
|
+
};
|
|
396
452
|
export declare type MakerInfo = {
|
|
397
453
|
maker: PublicKey;
|
|
398
454
|
order: Order;
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.DefaultOrderParams = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
4
5
|
// # Utility Types / Enums / Constants
|
|
5
6
|
class SwapDirection {
|
|
6
7
|
}
|
|
@@ -51,6 +52,19 @@ OrderAction.CANCEL = { cancel: {} };
|
|
|
51
52
|
OrderAction.EXPIRE = { expire: {} };
|
|
52
53
|
OrderAction.FILL = { fill: {} };
|
|
53
54
|
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
|
+
};
|
|
54
68
|
class OrderTriggerCondition {
|
|
55
69
|
}
|
|
56
70
|
exports.OrderTriggerCondition = OrderTriggerCondition;
|
|
@@ -72,3 +86,24 @@ var TradeSide;
|
|
|
72
86
|
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
73
87
|
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
74
88
|
})(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-master.
|
|
3
|
+
"version": "0.2.0-master.4",
|
|
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.3",
|
|
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",
|
|
42
43
|
"@types/mocha": "^9.1.1",
|
|
43
44
|
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
|
44
45
|
"@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,11 +675,13 @@ export class Admin extends ClearingHouse {
|
|
|
675
675
|
});
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
-
public async
|
|
679
|
-
|
|
678
|
+
public async updateAuctionDuration(
|
|
679
|
+
minDuration: BN | number,
|
|
680
|
+
maxDuration: BN | number
|
|
680
681
|
): Promise<TransactionSignature> {
|
|
681
|
-
return await this.program.rpc.
|
|
682
|
-
typeof
|
|
682
|
+
return await this.program.rpc.updateAuctionDuration(
|
|
683
|
+
typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
|
|
684
|
+
typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
|
|
683
685
|
{
|
|
684
686
|
accounts: {
|
|
685
687
|
admin: this.wallet.publicKey,
|
|
@@ -688,4 +690,33 @@ export class Admin extends ClearingHouse {
|
|
|
688
690
|
}
|
|
689
691
|
);
|
|
690
692
|
}
|
|
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
|
+
}
|
|
691
722
|
}
|
package/src/clearingHouse.ts
CHANGED
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
BankAccount,
|
|
12
12
|
UserBankBalance,
|
|
13
13
|
MakerInfo,
|
|
14
|
+
OptionalOrderParams,
|
|
15
|
+
DefaultOrderParams,
|
|
16
|
+
OrderType,
|
|
14
17
|
} from './types';
|
|
15
18
|
import * as anchor from '@project-serum/anchor';
|
|
16
19
|
import clearingHouseIDL from './idl/clearing_house.json';
|
|
@@ -52,7 +55,6 @@ import { WebSocketClearingHouseAccountSubscriber } from './accounts/webSocketCle
|
|
|
52
55
|
import { RetryTxSender } from './tx/retryTxSender';
|
|
53
56
|
import { ClearingHouseUser } from './clearingHouseUser';
|
|
54
57
|
import { ClearingHouseUserAccountSubscriptionConfig } from './clearingHouseUserConfig';
|
|
55
|
-
import { getMarketOrderParams } from './orderParams';
|
|
56
58
|
import { getMarketsBanksAndOraclesForSubscription } from './config';
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -798,20 +800,17 @@ export class ClearingHouse {
|
|
|
798
800
|
marketIndex: BN,
|
|
799
801
|
limitPrice?: BN
|
|
800
802
|
): Promise<TransactionSignature> {
|
|
801
|
-
return await this.placeAndTake(
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
limitPrice
|
|
809
|
-
)
|
|
810
|
-
);
|
|
803
|
+
return await this.placeAndTake({
|
|
804
|
+
orderType: OrderType.MARKET,
|
|
805
|
+
marketIndex,
|
|
806
|
+
direction,
|
|
807
|
+
baseAssetAmount: amount,
|
|
808
|
+
price: limitPrice,
|
|
809
|
+
});
|
|
811
810
|
}
|
|
812
811
|
|
|
813
812
|
public async placeOrder(
|
|
814
|
-
orderParams:
|
|
813
|
+
orderParams: OptionalOrderParams
|
|
815
814
|
): Promise<TransactionSignature> {
|
|
816
815
|
const { txSig, slot } = await this.txSender.send(
|
|
817
816
|
wrapInTx(await this.getPlaceOrderIx(orderParams)),
|
|
@@ -822,9 +821,14 @@ export class ClearingHouse {
|
|
|
822
821
|
return txSig;
|
|
823
822
|
}
|
|
824
823
|
|
|
824
|
+
getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams {
|
|
825
|
+
return Object.assign({}, DefaultOrderParams, optionalOrderParams);
|
|
826
|
+
}
|
|
827
|
+
|
|
825
828
|
public async getPlaceOrderIx(
|
|
826
|
-
orderParams:
|
|
829
|
+
orderParams: OptionalOrderParams
|
|
827
830
|
): Promise<TransactionInstruction> {
|
|
831
|
+
orderParams = this.getOrderParams(orderParams);
|
|
828
832
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
829
833
|
|
|
830
834
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -996,7 +1000,7 @@ export class ClearingHouse {
|
|
|
996
1000
|
const market = this.getMarketAccount(position.marketIndex);
|
|
997
1001
|
marketAccountInfos.push({
|
|
998
1002
|
pubkey: market.pubkey,
|
|
999
|
-
isWritable:
|
|
1003
|
+
isWritable: true,
|
|
1000
1004
|
isSigner: false,
|
|
1001
1005
|
});
|
|
1002
1006
|
oracleAccountInfos.push({
|
|
@@ -1110,7 +1114,7 @@ export class ClearingHouse {
|
|
|
1110
1114
|
}
|
|
1111
1115
|
|
|
1112
1116
|
public async placeAndTake(
|
|
1113
|
-
orderParams:
|
|
1117
|
+
orderParams: OptionalOrderParams,
|
|
1114
1118
|
makerInfo?: MakerInfo
|
|
1115
1119
|
): Promise<TransactionSignature> {
|
|
1116
1120
|
const { txSig, slot } = await this.txSender.send(
|
|
@@ -1123,9 +1127,10 @@ export class ClearingHouse {
|
|
|
1123
1127
|
}
|
|
1124
1128
|
|
|
1125
1129
|
public async getPlaceAndTakeIx(
|
|
1126
|
-
orderParams:
|
|
1130
|
+
orderParams: OptionalOrderParams,
|
|
1127
1131
|
makerInfo?: MakerInfo
|
|
1128
1132
|
): Promise<TransactionInstruction> {
|
|
1133
|
+
orderParams = this.getOrderParams(orderParams);
|
|
1129
1134
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1130
1135
|
|
|
1131
1136
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1168,16 +1173,13 @@ export class ClearingHouse {
|
|
|
1168
1173
|
throw Error(`No position in market ${marketIndex.toString()}`);
|
|
1169
1174
|
}
|
|
1170
1175
|
|
|
1171
|
-
return await this.placeAndTake(
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
undefined
|
|
1179
|
-
)
|
|
1180
|
-
);
|
|
1176
|
+
return await this.placeAndTake({
|
|
1177
|
+
orderType: OrderType.MARKET,
|
|
1178
|
+
marketIndex,
|
|
1179
|
+
direction: findDirectionToClose(userPosition),
|
|
1180
|
+
baseAssetAmount: userPosition.baseAssetAmount,
|
|
1181
|
+
reduceOnly: true,
|
|
1182
|
+
});
|
|
1181
1183
|
}
|
|
1182
1184
|
|
|
1183
1185
|
public async settlePNLs(
|
|
@@ -1441,6 +1441,58 @@
|
|
|
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
|
+
},
|
|
1444
1496
|
{
|
|
1445
1497
|
"name": "updateAdmin",
|
|
1446
1498
|
"accounts": [
|
|
@@ -1563,7 +1615,7 @@
|
|
|
1563
1615
|
]
|
|
1564
1616
|
},
|
|
1565
1617
|
{
|
|
1566
|
-
"name": "
|
|
1618
|
+
"name": "updateAuctionDuration",
|
|
1567
1619
|
"accounts": [
|
|
1568
1620
|
{
|
|
1569
1621
|
"name": "admin",
|
|
@@ -1578,7 +1630,11 @@
|
|
|
1578
1630
|
],
|
|
1579
1631
|
"args": [
|
|
1580
1632
|
{
|
|
1581
|
-
"name": "
|
|
1633
|
+
"name": "minAuctionDuration",
|
|
1634
|
+
"type": "u8"
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
"name": "maxAuctionDuration",
|
|
1582
1638
|
"type": "u8"
|
|
1583
1639
|
}
|
|
1584
1640
|
]
|
|
@@ -1885,7 +1941,11 @@
|
|
|
1885
1941
|
"type": "u128"
|
|
1886
1942
|
},
|
|
1887
1943
|
{
|
|
1888
|
-
"name": "
|
|
1944
|
+
"name": "minAuctionDuration",
|
|
1945
|
+
"type": "u8"
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
"name": "maxAuctionDuration",
|
|
1889
1949
|
"type": "u8"
|
|
1890
1950
|
},
|
|
1891
1951
|
{
|
|
@@ -1990,10 +2050,6 @@
|
|
|
1990
2050
|
"name": "userOrderId",
|
|
1991
2051
|
"type": "u8"
|
|
1992
2052
|
},
|
|
1993
|
-
{
|
|
1994
|
-
"name": "quoteAssetAmount",
|
|
1995
|
-
"type": "u128"
|
|
1996
|
-
},
|
|
1997
2053
|
{
|
|
1998
2054
|
"name": "baseAssetAmount",
|
|
1999
2055
|
"type": "u128"
|
|
@@ -2042,6 +2098,10 @@
|
|
|
2042
2098
|
"name": "oraclePriceOffset",
|
|
2043
2099
|
"type": "i128"
|
|
2044
2100
|
},
|
|
2101
|
+
{
|
|
2102
|
+
"name": "auctionDuration",
|
|
2103
|
+
"type": "u8"
|
|
2104
|
+
},
|
|
2045
2105
|
{
|
|
2046
2106
|
"name": "padding0",
|
|
2047
2107
|
"type": "bool"
|
|
@@ -2204,6 +2264,14 @@
|
|
|
2204
2264
|
"name": "minimumQuoteAssetTradeSize",
|
|
2205
2265
|
"type": "u128"
|
|
2206
2266
|
},
|
|
2267
|
+
{
|
|
2268
|
+
"name": "maxBaseAssetAmountRatio",
|
|
2269
|
+
"type": "u16"
|
|
2270
|
+
},
|
|
2271
|
+
{
|
|
2272
|
+
"name": "maxSlippageRatio",
|
|
2273
|
+
"type": "u16"
|
|
2274
|
+
},
|
|
2207
2275
|
{
|
|
2208
2276
|
"name": "baseAssetAmountStepSize",
|
|
2209
2277
|
"type": "u128"
|
|
@@ -2688,10 +2756,6 @@
|
|
|
2688
2756
|
"defined": "PositionDirection"
|
|
2689
2757
|
}
|
|
2690
2758
|
},
|
|
2691
|
-
{
|
|
2692
|
-
"name": "quoteAssetAmount",
|
|
2693
|
-
"type": "u128"
|
|
2694
|
-
},
|
|
2695
2759
|
{
|
|
2696
2760
|
"name": "baseAssetAmount",
|
|
2697
2761
|
"type": "u128"
|
|
@@ -2904,6 +2968,12 @@
|
|
|
2904
2968
|
},
|
|
2905
2969
|
{
|
|
2906
2970
|
"name": "OraclePriceBreachedLimitPrice"
|
|
2971
|
+
},
|
|
2972
|
+
{
|
|
2973
|
+
"name": "MarketOrderFilledToLimitPrice"
|
|
2974
|
+
},
|
|
2975
|
+
{
|
|
2976
|
+
"name": "MarketOrderAuctionExpired"
|
|
2907
2977
|
}
|
|
2908
2978
|
]
|
|
2909
2979
|
}
|
|
@@ -3691,8 +3761,8 @@
|
|
|
3691
3761
|
},
|
|
3692
3762
|
{
|
|
3693
3763
|
"code": 6044,
|
|
3694
|
-
"name": "
|
|
3695
|
-
"msg": "
|
|
3764
|
+
"name": "FillOrderDidNotUpdateState",
|
|
3765
|
+
"msg": "FillOrderDidNotUpdateState"
|
|
3696
3766
|
},
|
|
3697
3767
|
{
|
|
3698
3768
|
"code": 6045,
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BN } from '@project-serum/anchor';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import pyth from '@pythnetwork/client';
|
|
3
4
|
|
|
4
5
|
export * from './mockUSDCFaucet';
|
|
5
6
|
export * from './oracles/types';
|
|
@@ -49,4 +50,4 @@ export * from './math/bankBalance';
|
|
|
49
50
|
export * from './constants/banks';
|
|
50
51
|
export * from './clearingHouseConfig';
|
|
51
52
|
|
|
52
|
-
export { BN, PublicKey };
|
|
53
|
+
export { BN, PublicKey, pyth };
|