@drift-labs/sdk 0.2.0-master.2 → 0.2.0-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/accounts/types.d.ts +0 -1
- package/lib/admin.d.ts +5 -3
- package/lib/admin.js +30 -7
- package/lib/clearingHouse.d.ts +8 -11
- package/lib/clearingHouse.js +49 -75
- package/lib/config.js +1 -1
- package/lib/idl/clearing_house.json +171 -36
- 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 +18 -11
- package/lib/math/position.js +3 -1
- 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/orders.js +1 -9
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +70 -1
- package/lib/types.js +41 -1
- package/package.json +3 -3
- package/src/admin.ts +47 -8
- package/src/clearingHouse.ts +79 -151
- package/src/config.ts +1 -1
- package/src/idl/clearing_house.json +171 -36
- 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 -13
- package/src/math/position.ts +5 -1
- package/src/math/trade.ts +23 -25
- package/src/orderParams.ts +20 -141
- package/src/orders.ts +1 -8
- package/src/tx/utils.ts +1 -1
- package/src/types.ts +65 -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/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/lib/tx/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.wrapInTx = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const COMPUTE_UNITS_DEFAULT = 200000;
|
|
6
|
-
function wrapInTx(instruction, computeUnits =
|
|
6
|
+
function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
|
|
7
7
|
) {
|
|
8
8
|
const tx = new web3_js_1.Transaction();
|
|
9
9
|
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
package/lib/types.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export declare class PositionDirection {
|
|
|
25
25
|
short: {};
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
export declare class DepositDirection {
|
|
29
|
+
static readonly DEPOSIT: {
|
|
30
|
+
deposit: {};
|
|
31
|
+
};
|
|
32
|
+
static readonly WITHDRAW: {
|
|
33
|
+
withdraw: {};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
28
36
|
export declare class OracleSource {
|
|
29
37
|
static readonly PYTH: {
|
|
30
38
|
pyth: {};
|
|
@@ -92,6 +100,20 @@ export declare class OrderAction {
|
|
|
92
100
|
trigger: {};
|
|
93
101
|
};
|
|
94
102
|
}
|
|
103
|
+
export declare class OrderActionExplanation {
|
|
104
|
+
static readonly NONE: {
|
|
105
|
+
none: {};
|
|
106
|
+
};
|
|
107
|
+
static readonly BREACHED_MARGIN_REQUIREMENT: {
|
|
108
|
+
breachedMarginRequirement: {};
|
|
109
|
+
};
|
|
110
|
+
static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE: {
|
|
111
|
+
oraclePriceBreachedLimitPrice: {};
|
|
112
|
+
};
|
|
113
|
+
static readonly MARKET_ORDER_FILLED_TO_LIMIT_PRICE: {
|
|
114
|
+
marketOrderFilledToLimitPrice: {};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
95
117
|
export declare class OrderTriggerCondition {
|
|
96
118
|
static readonly ABOVE: {
|
|
97
119
|
above: {};
|
|
@@ -118,6 +140,7 @@ export declare type DepositRecord = {
|
|
|
118
140
|
};
|
|
119
141
|
bankIndex: BN;
|
|
120
142
|
amount: BN;
|
|
143
|
+
oraclePrice: BN;
|
|
121
144
|
from?: PublicKey;
|
|
122
145
|
to?: PublicKey;
|
|
123
146
|
};
|
|
@@ -185,7 +208,10 @@ export declare type OrderRecord = {
|
|
|
185
208
|
maker: PublicKey;
|
|
186
209
|
takerOrder: Order;
|
|
187
210
|
makerOrder: Order;
|
|
211
|
+
takerUnsettledPnl: BN;
|
|
212
|
+
makerUnsettledPnl: BN;
|
|
188
213
|
action: OrderAction;
|
|
214
|
+
actionExplanation: OrderActionExplanation;
|
|
189
215
|
filler: PublicKey;
|
|
190
216
|
fillRecordId: BN;
|
|
191
217
|
marketIndex: BN;
|
|
@@ -277,6 +303,8 @@ export declare type AMM = {
|
|
|
277
303
|
lastMarkPriceTwapTs: BN;
|
|
278
304
|
lastOraclePriceTwap: BN;
|
|
279
305
|
lastOraclePriceTwapTs: BN;
|
|
306
|
+
lastOracleMarkSpreadPct: BN;
|
|
307
|
+
lastOracleConfPct: BN;
|
|
280
308
|
oracle: PublicKey;
|
|
281
309
|
oracleSource: OracleSource;
|
|
282
310
|
fundingPeriod: BN;
|
|
@@ -291,6 +319,8 @@ export declare type AMM = {
|
|
|
291
319
|
totalFee: BN;
|
|
292
320
|
minimumQuoteAssetTradeSize: BN;
|
|
293
321
|
baseAssetAmountStepSize: BN;
|
|
322
|
+
maxBaseAssetAmountRatio: number;
|
|
323
|
+
maxSlippageRatio: number;
|
|
294
324
|
lastOraclePrice: BN;
|
|
295
325
|
baseSpread: number;
|
|
296
326
|
curveUpdateIntensity: number;
|
|
@@ -375,7 +405,6 @@ export declare type OrderParams = {
|
|
|
375
405
|
orderType: OrderType;
|
|
376
406
|
userOrderId: number;
|
|
377
407
|
direction: PositionDirection;
|
|
378
|
-
quoteAssetAmount: BN;
|
|
379
408
|
baseAssetAmount: BN;
|
|
380
409
|
price: BN;
|
|
381
410
|
marketIndex: BN;
|
|
@@ -393,10 +422,50 @@ export declare type OrderParams = {
|
|
|
393
422
|
referrer: boolean;
|
|
394
423
|
};
|
|
395
424
|
};
|
|
425
|
+
export declare type NecessaryOrderParams = {
|
|
426
|
+
orderType: OrderType;
|
|
427
|
+
marketIndex: BN;
|
|
428
|
+
baseAssetAmount: BN;
|
|
429
|
+
direction: PositionDirection;
|
|
430
|
+
};
|
|
431
|
+
export declare type OptionalOrderParams = {
|
|
432
|
+
[Property in keyof OrderParams]?: OrderParams[Property];
|
|
433
|
+
} & NecessaryOrderParams;
|
|
434
|
+
export declare const DefaultOrderParams: {
|
|
435
|
+
orderType: {
|
|
436
|
+
market: {};
|
|
437
|
+
};
|
|
438
|
+
userOrderId: number;
|
|
439
|
+
direction: {
|
|
440
|
+
long: {};
|
|
441
|
+
};
|
|
442
|
+
baseAssetAmount: BN;
|
|
443
|
+
price: BN;
|
|
444
|
+
marketIndex: BN;
|
|
445
|
+
reduceOnly: boolean;
|
|
446
|
+
postOnly: boolean;
|
|
447
|
+
immediateOrCancel: boolean;
|
|
448
|
+
triggerPrice: BN;
|
|
449
|
+
triggerCondition: {
|
|
450
|
+
above: {};
|
|
451
|
+
};
|
|
452
|
+
positionLimit: BN;
|
|
453
|
+
oraclePriceOffset: BN;
|
|
454
|
+
padding0: BN;
|
|
455
|
+
padding1: BN;
|
|
456
|
+
optionalAccounts: {
|
|
457
|
+
discountToken: boolean;
|
|
458
|
+
referrer: boolean;
|
|
459
|
+
};
|
|
460
|
+
};
|
|
396
461
|
export declare type MakerInfo = {
|
|
397
462
|
maker: PublicKey;
|
|
398
463
|
order: Order;
|
|
399
464
|
};
|
|
465
|
+
export declare type TakerInfo = {
|
|
466
|
+
taker: PublicKey;
|
|
467
|
+
order: Order;
|
|
468
|
+
};
|
|
400
469
|
export interface IWallet {
|
|
401
470
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
402
471
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
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.DepositDirection = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
4
5
|
// # Utility Types / Enums / Constants
|
|
5
6
|
class SwapDirection {
|
|
6
7
|
}
|
|
@@ -17,6 +18,11 @@ class PositionDirection {
|
|
|
17
18
|
exports.PositionDirection = PositionDirection;
|
|
18
19
|
PositionDirection.LONG = { long: {} };
|
|
19
20
|
PositionDirection.SHORT = { short: {} };
|
|
21
|
+
class DepositDirection {
|
|
22
|
+
}
|
|
23
|
+
exports.DepositDirection = DepositDirection;
|
|
24
|
+
DepositDirection.DEPOSIT = { deposit: {} };
|
|
25
|
+
DepositDirection.WITHDRAW = { withdraw: {} };
|
|
20
26
|
class OracleSource {
|
|
21
27
|
}
|
|
22
28
|
exports.OracleSource = OracleSource;
|
|
@@ -51,6 +57,19 @@ OrderAction.CANCEL = { cancel: {} };
|
|
|
51
57
|
OrderAction.EXPIRE = { expire: {} };
|
|
52
58
|
OrderAction.FILL = { fill: {} };
|
|
53
59
|
OrderAction.TRIGGER = { trigger: {} };
|
|
60
|
+
class OrderActionExplanation {
|
|
61
|
+
}
|
|
62
|
+
exports.OrderActionExplanation = OrderActionExplanation;
|
|
63
|
+
OrderActionExplanation.NONE = { none: {} };
|
|
64
|
+
OrderActionExplanation.BREACHED_MARGIN_REQUIREMENT = {
|
|
65
|
+
breachedMarginRequirement: {},
|
|
66
|
+
};
|
|
67
|
+
OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
68
|
+
oraclePriceBreachedLimitPrice: {},
|
|
69
|
+
};
|
|
70
|
+
OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
|
|
71
|
+
marketOrderFilledToLimitPrice: {},
|
|
72
|
+
};
|
|
54
73
|
class OrderTriggerCondition {
|
|
55
74
|
}
|
|
56
75
|
exports.OrderTriggerCondition = OrderTriggerCondition;
|
|
@@ -72,3 +91,24 @@ var TradeSide;
|
|
|
72
91
|
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
73
92
|
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
74
93
|
})(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
|
|
94
|
+
exports.DefaultOrderParams = {
|
|
95
|
+
orderType: OrderType.MARKET,
|
|
96
|
+
userOrderId: 0,
|
|
97
|
+
direction: PositionDirection.LONG,
|
|
98
|
+
baseAssetAmount: _1.ZERO,
|
|
99
|
+
price: _1.ZERO,
|
|
100
|
+
marketIndex: _1.ZERO,
|
|
101
|
+
reduceOnly: false,
|
|
102
|
+
postOnly: false,
|
|
103
|
+
immediateOrCancel: false,
|
|
104
|
+
triggerPrice: _1.ZERO,
|
|
105
|
+
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
106
|
+
positionLimit: _1.ZERO,
|
|
107
|
+
oraclePriceOffset: _1.ZERO,
|
|
108
|
+
padding0: _1.ZERO,
|
|
109
|
+
padding1: _1.ZERO,
|
|
110
|
+
optionalAccounts: {
|
|
111
|
+
discountToken: false,
|
|
112
|
+
referrer: false,
|
|
113
|
+
},
|
|
114
|
+
};
|
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.5",
|
|
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
|
@@ -85,7 +85,8 @@ export class Admin extends ClearingHouse {
|
|
|
85
85
|
initialAssetWeight: BN,
|
|
86
86
|
maintenanceAssetWeight: BN,
|
|
87
87
|
initialLiabilityWeight: BN,
|
|
88
|
-
maintenanceLiabilityWeight: BN
|
|
88
|
+
maintenanceLiabilityWeight: BN,
|
|
89
|
+
imfFactor = new BN(0)
|
|
89
90
|
): Promise<TransactionSignature> {
|
|
90
91
|
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
91
92
|
const bank = await getBankPublicKey(this.program.programId, bankIndex);
|
|
@@ -109,6 +110,7 @@ export class Admin extends ClearingHouse {
|
|
|
109
110
|
maintenanceAssetWeight,
|
|
110
111
|
initialLiabilityWeight,
|
|
111
112
|
maintenanceLiabilityWeight,
|
|
113
|
+
imfFactor,
|
|
112
114
|
{
|
|
113
115
|
accounts: {
|
|
114
116
|
admin: this.wallet.publicKey,
|
|
@@ -329,10 +331,12 @@ export class Admin extends ClearingHouse {
|
|
|
329
331
|
recipient: PublicKey
|
|
330
332
|
): Promise<TransactionSignature> {
|
|
331
333
|
const state = await this.getStateAccount();
|
|
334
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
332
335
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
333
336
|
accounts: {
|
|
334
337
|
admin: this.wallet.publicKey,
|
|
335
338
|
state: await this.getStatePublicKey(),
|
|
339
|
+
bank: bank.pubkey,
|
|
336
340
|
insuranceVault: state.insuranceVault,
|
|
337
341
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
338
342
|
recipient: recipient,
|
|
@@ -341,7 +345,7 @@ export class Admin extends ClearingHouse {
|
|
|
341
345
|
});
|
|
342
346
|
}
|
|
343
347
|
|
|
344
|
-
public async
|
|
348
|
+
public async withdrawFromMarketToInsuranceVault(
|
|
345
349
|
marketIndex: BN,
|
|
346
350
|
amount: BN,
|
|
347
351
|
recipient: PublicKey
|
|
@@ -351,7 +355,7 @@ export class Admin extends ClearingHouse {
|
|
|
351
355
|
marketIndex
|
|
352
356
|
);
|
|
353
357
|
const bank = this.getQuoteAssetBankAccount();
|
|
354
|
-
return await this.program.rpc.
|
|
358
|
+
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
355
359
|
accounts: {
|
|
356
360
|
admin: this.wallet.publicKey,
|
|
357
361
|
state: await this.getStatePublicKey(),
|
|
@@ -370,6 +374,8 @@ export class Admin extends ClearingHouse {
|
|
|
370
374
|
amount: BN
|
|
371
375
|
): Promise<TransactionSignature> {
|
|
372
376
|
const state = await this.getStateAccount();
|
|
377
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
378
|
+
|
|
373
379
|
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
374
380
|
accounts: {
|
|
375
381
|
admin: this.wallet.publicKey,
|
|
@@ -377,7 +383,9 @@ export class Admin extends ClearingHouse {
|
|
|
377
383
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
378
384
|
insuranceVault: state.insuranceVault,
|
|
379
385
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
380
|
-
|
|
386
|
+
bank: bank.pubkey,
|
|
387
|
+
bankVault: bank.vault,
|
|
388
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
381
389
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
382
390
|
},
|
|
383
391
|
});
|
|
@@ -675,11 +683,13 @@ export class Admin extends ClearingHouse {
|
|
|
675
683
|
});
|
|
676
684
|
}
|
|
677
685
|
|
|
678
|
-
public async
|
|
679
|
-
|
|
686
|
+
public async updateAuctionDuration(
|
|
687
|
+
minDuration: BN | number,
|
|
688
|
+
maxDuration: BN | number
|
|
680
689
|
): Promise<TransactionSignature> {
|
|
681
|
-
return await this.program.rpc.
|
|
682
|
-
typeof
|
|
690
|
+
return await this.program.rpc.updateAuctionDuration(
|
|
691
|
+
typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
|
|
692
|
+
typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
|
|
683
693
|
{
|
|
684
694
|
accounts: {
|
|
685
695
|
admin: this.wallet.publicKey,
|
|
@@ -688,4 +698,33 @@ export class Admin extends ClearingHouse {
|
|
|
688
698
|
}
|
|
689
699
|
);
|
|
690
700
|
}
|
|
701
|
+
|
|
702
|
+
public async updateMaxBaseAssetAmountRatio(
|
|
703
|
+
marketIndex: BN,
|
|
704
|
+
maxBaseAssetAmountRatio: number
|
|
705
|
+
): Promise<TransactionSignature> {
|
|
706
|
+
return await this.program.rpc.updateMaxBaseAssetAmountRatio(
|
|
707
|
+
maxBaseAssetAmountRatio,
|
|
708
|
+
{
|
|
709
|
+
accounts: {
|
|
710
|
+
admin: this.wallet.publicKey,
|
|
711
|
+
state: await this.getStatePublicKey(),
|
|
712
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
713
|
+
},
|
|
714
|
+
}
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
public async updateMaxSlippageRatio(
|
|
719
|
+
marketIndex: BN,
|
|
720
|
+
maxSlippageRatio: number
|
|
721
|
+
): Promise<TransactionSignature> {
|
|
722
|
+
return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
723
|
+
accounts: {
|
|
724
|
+
admin: this.wallet.publicKey,
|
|
725
|
+
state: await this.getStatePublicKey(),
|
|
726
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
}
|
|
691
730
|
}
|