@drift-labs/sdk 0.2.0-master.20 → 0.2.0-master.23
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/addresses/pda.d.ts +3 -0
- package/lib/addresses/pda.js +23 -1
- package/lib/admin.d.ts +3 -0
- package/lib/admin.js +31 -0
- package/lib/clearingHouse.d.ts +11 -4
- package/lib/clearingHouse.js +157 -23
- package/lib/clearingHouseUser.d.ts +9 -1
- package/lib/clearingHouseUser.js +62 -25
- package/lib/config.js +1 -1
- package/lib/constants/banks.d.ts +2 -0
- package/lib/constants/banks.js +9 -0
- package/lib/constants/numericConstants.d.ts +2 -0
- package/lib/constants/numericConstants.js +4 -1
- package/lib/events/sort.js +7 -10
- package/lib/events/types.d.ts +2 -1
- package/lib/events/types.js +1 -0
- package/lib/idl/clearing_house.json +1008 -147
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/amm.js +2 -2
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +1 -1
- package/lib/math/margin.js +5 -7
- package/lib/math/orders.d.ts +2 -1
- package/lib/math/orders.js +14 -5
- package/lib/math/position.js +1 -1
- package/lib/types.d.ts +59 -20
- package/lib/types.js +0 -3
- package/package.json +1 -1
- package/src/addresses/pda.ts +47 -0
- package/src/admin.ts +65 -0
- package/src/clearingHouse.ts +244 -32
- package/src/clearingHouseUser.ts +77 -48
- package/src/config.ts +1 -1
- package/src/constants/banks.ts +16 -0
- package/src/constants/numericConstants.ts +4 -0
- package/src/events/sort.ts +10 -14
- package/src/events/types.ts +3 -0
- package/src/idl/clearing_house.json +1008 -147
- package/src/index.ts +1 -0
- package/src/math/amm.ts +2 -2
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +3 -10
- package/src/math/orders.ts +26 -9
- package/src/math/position.ts +2 -2
- package/src/types.ts +67 -20
- package/src/events/eventSubscriber.js +0 -139
- package/src/events/fetchLogs.js +0 -50
- package/src/events/pollingLogProvider.js +0 -64
- package/src/events/sort.js +0 -44
- package/src/events/webSocketLogProvider.js +0 -41
package/lib/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export * from './math/trade';
|
|
|
40
40
|
export * from './math/orders';
|
|
41
41
|
export * from './math/repeg';
|
|
42
42
|
export * from './math/margin';
|
|
43
|
+
export * from './math/insurance';
|
|
43
44
|
export * from './orderParams';
|
|
44
45
|
export * from './slot/SlotSubscriber';
|
|
45
46
|
export * from './wallet';
|
package/lib/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __exportStar(require("./math/trade"), exports);
|
|
|
63
63
|
__exportStar(require("./math/orders"), exports);
|
|
64
64
|
__exportStar(require("./math/repeg"), exports);
|
|
65
65
|
__exportStar(require("./math/margin"), exports);
|
|
66
|
+
__exportStar(require("./math/insurance"), exports);
|
|
66
67
|
__exportStar(require("./orderParams"), exports);
|
|
67
68
|
__exportStar(require("./slot/SlotSubscriber"), exports);
|
|
68
69
|
__exportStar(require("./wallet"), exports);
|
package/lib/math/amm.js
CHANGED
|
@@ -371,10 +371,10 @@ function calculateMaxBaseAssetAmountFillable(amm, orderDirection) {
|
|
|
371
371
|
const maxFillSize = amm.baseAssetReserve.div(new anchor_1.BN(amm.maxBaseAssetAmountRatio));
|
|
372
372
|
let maxBaseAssetAmountOnSide;
|
|
373
373
|
if ((0, types_1.isVariant)(orderDirection, 'long')) {
|
|
374
|
-
maxBaseAssetAmountOnSide = anchor_1.BN.max(numericConstants_1.ZERO, amm.
|
|
374
|
+
maxBaseAssetAmountOnSide = anchor_1.BN.max(numericConstants_1.ZERO, amm.baseAssetReserve.sub(amm.minBaseAssetReserve));
|
|
375
375
|
}
|
|
376
376
|
else {
|
|
377
|
-
maxBaseAssetAmountOnSide = anchor_1.BN.max(numericConstants_1.ZERO, amm.
|
|
377
|
+
maxBaseAssetAmountOnSide = anchor_1.BN.max(numericConstants_1.ZERO, amm.maxBaseAssetReserve.sub(amm.baseAssetReserve));
|
|
378
378
|
}
|
|
379
379
|
return (0, __1.standardizeBaseAssetAmount)(anchor_1.BN.min(maxFillSize, maxBaseAssetAmountOnSide), amm.baseAssetAmountStepSize);
|
|
380
380
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN } from '../index';
|
|
3
|
+
export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
4
|
+
export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
|
|
4
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
function stakeAmountToShares(amount, totalIfShares, insuranceFundVaultBalance) {
|
|
7
|
+
let nShares;
|
|
8
|
+
if (insuranceFundVaultBalance.gt(numericConstants_1.ZERO)) {
|
|
9
|
+
nShares = amount.mul(totalIfShares).div(insuranceFundVaultBalance);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
nShares = amount;
|
|
13
|
+
}
|
|
14
|
+
return nShares;
|
|
15
|
+
}
|
|
16
|
+
exports.stakeAmountToShares = stakeAmountToShares;
|
|
17
|
+
function unstakeSharesToAmount(nShares, totalIfShares, insuranceFundVaultBalance) {
|
|
18
|
+
let amount;
|
|
19
|
+
if (totalIfShares.gt(numericConstants_1.ZERO)) {
|
|
20
|
+
amount = index_1.BN.max(numericConstants_1.ZERO, nShares.mul(insuranceFundVaultBalance).div(totalIfShares).sub(numericConstants_1.ONE));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
amount = numericConstants_1.ZERO;
|
|
24
|
+
}
|
|
25
|
+
return amount;
|
|
26
|
+
}
|
|
27
|
+
exports.unstakeSharesToAmount = unstakeSharesToAmount;
|
package/lib/math/margin.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ imfFactor: BN, liabilityWeight: BN, precision: BN): BN;
|
|
|
7
7
|
export declare function calculateSizeDiscountAssetWeight(size: BN, // AMM_RESERVE_PRECISION
|
|
8
8
|
imfFactor: BN, assetWeight: BN): BN;
|
|
9
9
|
export declare function calculateOraclePriceForPerpMargin(marketPosition: UserPosition, market: MarketAccount, oraclePriceData: OraclePriceData): BN;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function calculateBaseAssetValueWithOracle(market: MarketAccount, marketPosition: UserPosition, oraclePriceData: OraclePriceData): BN;
|
|
11
11
|
export declare function calculateWorstCaseBaseAssetAmount(marketPosition: UserPosition): BN;
|
package/lib/math/margin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateWorstCaseBaseAssetAmount = exports.
|
|
3
|
+
exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateOraclePriceForPerpMargin = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
6
|
const anchor_1 = require("@project-serum/anchor");
|
|
@@ -50,15 +50,13 @@ function calculateOraclePriceForPerpMargin(marketPosition, market, oraclePriceDa
|
|
|
50
50
|
return marginPrice;
|
|
51
51
|
}
|
|
52
52
|
exports.calculateOraclePriceForPerpMargin = calculateOraclePriceForPerpMargin;
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
const baseAssetValue = marketPosition.baseAssetAmount
|
|
53
|
+
function calculateBaseAssetValueWithOracle(market, marketPosition, oraclePriceData) {
|
|
54
|
+
return marketPosition.baseAssetAmount
|
|
56
55
|
.abs()
|
|
57
|
-
.mul(
|
|
56
|
+
.mul(oraclePriceData.price)
|
|
58
57
|
.div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO.mul(numericConstants_1.MARK_PRICE_PRECISION));
|
|
59
|
-
return baseAssetValue;
|
|
60
58
|
}
|
|
61
|
-
exports.
|
|
59
|
+
exports.calculateBaseAssetValueWithOracle = calculateBaseAssetValueWithOracle;
|
|
62
60
|
function calculateWorstCaseBaseAssetAmount(marketPosition) {
|
|
63
61
|
const allBids = marketPosition.baseAssetAmount.add(marketPosition.openBids);
|
|
64
62
|
const allAsks = marketPosition.baseAssetAmount.add(marketPosition.openAsks);
|
package/lib/math/orders.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare function isOrderRiskIncreasingInSameDirection(user: ClearingHouse
|
|
|
8
8
|
export declare function isOrderReduceOnly(user: ClearingHouseUser, order: Order): boolean;
|
|
9
9
|
export declare function standardizeBaseAssetAmount(baseAssetAmount: BN, stepSize: BN): BN;
|
|
10
10
|
export declare function getLimitPrice(order: Order, market: MarketAccount, oraclePriceData: OraclePriceData, slot: number): BN;
|
|
11
|
-
export declare function isFillableByVAMM(order: Order, market: MarketAccount, oraclePriceData: OraclePriceData, slot: number): boolean;
|
|
11
|
+
export declare function isFillableByVAMM(order: Order, market: MarketAccount, oraclePriceData: OraclePriceData, slot: number, maxAuctionDuration: number): boolean;
|
|
12
12
|
export declare function calculateBaseAssetAmountForAmmToFulfill(order: Order, market: MarketAccount, oraclePriceData: OraclePriceData, slot: number): BN;
|
|
13
13
|
export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, market: MarketAccount, limitPrice: BN, oraclePriceData: OraclePriceData): BN;
|
|
14
|
+
export declare function isOrderExpired(order: Order, slot: number, maxAuctionDuration: number): boolean;
|
package/lib/math/orders.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.getLimitPrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
|
|
3
|
+
exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = 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
6
|
const anchor_1 = require("@project-serum/anchor");
|
|
@@ -86,7 +86,7 @@ function getLimitPrice(order, market, oraclePriceData, slot) {
|
|
|
86
86
|
limitPrice = oraclePriceData.price.add(order.oraclePriceOffset);
|
|
87
87
|
}
|
|
88
88
|
else if ((0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket'])) {
|
|
89
|
-
if ((0, auction_1.isAuctionComplete)(order, slot)) {
|
|
89
|
+
if (!(0, auction_1.isAuctionComplete)(order, slot)) {
|
|
90
90
|
limitPrice = (0, auction_1.getAuctionPrice)(order, slot);
|
|
91
91
|
}
|
|
92
92
|
else if (!order.price.eq(numericConstants_1.ZERO)) {
|
|
@@ -109,9 +109,10 @@ function getLimitPrice(order, market, oraclePriceData, slot) {
|
|
|
109
109
|
return limitPrice;
|
|
110
110
|
}
|
|
111
111
|
exports.getLimitPrice = getLimitPrice;
|
|
112
|
-
function isFillableByVAMM(order, market, oraclePriceData, slot) {
|
|
113
|
-
return ((0, auction_1.isAuctionComplete)(order, slot) &&
|
|
114
|
-
!calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData, slot).eq(numericConstants_1.ZERO))
|
|
112
|
+
function isFillableByVAMM(order, market, oraclePriceData, slot, maxAuctionDuration) {
|
|
113
|
+
return (((0, auction_1.isAuctionComplete)(order, slot) &&
|
|
114
|
+
!calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData, slot).eq(numericConstants_1.ZERO)) ||
|
|
115
|
+
isOrderExpired(order, slot, maxAuctionDuration));
|
|
115
116
|
}
|
|
116
117
|
exports.isFillableByVAMM = isFillableByVAMM;
|
|
117
118
|
function calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData, slot) {
|
|
@@ -142,3 +143,11 @@ function isSameDirection(firstDirection, secondDirection) {
|
|
|
142
143
|
return (((0, types_1.isVariant)(firstDirection, 'long') && (0, types_1.isVariant)(secondDirection, 'long')) ||
|
|
143
144
|
((0, types_1.isVariant)(firstDirection, 'short') && (0, types_1.isVariant)(secondDirection, 'short')));
|
|
144
145
|
}
|
|
146
|
+
function isOrderExpired(order, slot, maxAuctionDuration) {
|
|
147
|
+
if (!(0, types_1.isVariant)(order.orderType, 'market') ||
|
|
148
|
+
!(0, types_1.isVariant)(order.status, 'open')) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return new anchor_1.BN(slot).sub(order.slot).gt(new anchor_1.BN(maxAuctionDuration));
|
|
152
|
+
}
|
|
153
|
+
exports.isOrderExpired = isOrderExpired;
|
package/lib/math/position.js
CHANGED
|
@@ -61,7 +61,7 @@ function calculatePositionPNL(market, marketPosition, withFunding = false, oracl
|
|
|
61
61
|
if (marketPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
62
62
|
return marketPosition.quoteAssetAmount;
|
|
63
63
|
}
|
|
64
|
-
const baseAssetValue = (0, margin_1.
|
|
64
|
+
const baseAssetValue = (0, margin_1.calculateBaseAssetValueWithOracle)(market, marketPosition, oraclePriceData);
|
|
65
65
|
const baseAssetValueSign = marketPosition.baseAssetAmount.isNeg()
|
|
66
66
|
? new __1.BN(-1)
|
|
67
67
|
: new __1.BN(1);
|
package/lib/types.d.ts
CHANGED
|
@@ -104,9 +104,6 @@ export declare class OrderActionExplanation {
|
|
|
104
104
|
static readonly NONE: {
|
|
105
105
|
none: {};
|
|
106
106
|
};
|
|
107
|
-
static readonly BREACHED_MARGIN_REQUIREMENT: {
|
|
108
|
-
breachedMarginRequirement: {};
|
|
109
|
-
};
|
|
110
107
|
static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE: {
|
|
111
108
|
oraclePriceBreachedLimitPrice: {};
|
|
112
109
|
};
|
|
@@ -183,10 +180,15 @@ export declare type FundingRateRecord = {
|
|
|
183
180
|
recordId: BN;
|
|
184
181
|
marketIndex: BN;
|
|
185
182
|
fundingRate: BN;
|
|
183
|
+
fundingRateLong: BN;
|
|
184
|
+
fundingRateShort: BN;
|
|
186
185
|
cumulativeFundingRateLong: BN;
|
|
187
186
|
cumulativeFundingRateShort: BN;
|
|
188
187
|
oraclePriceTwap: BN;
|
|
189
188
|
markPriceTwap: BN;
|
|
189
|
+
periodRevenue: BN;
|
|
190
|
+
netBaseAssetAmount: BN;
|
|
191
|
+
netUnsettledLpBaseAssetAmount: BN;
|
|
190
192
|
};
|
|
191
193
|
export declare type FundingPaymentRecord = {
|
|
192
194
|
ts: BN;
|
|
@@ -294,27 +296,40 @@ export declare type SettlePnlRecord = {
|
|
|
294
296
|
};
|
|
295
297
|
export declare type OrderRecord = {
|
|
296
298
|
ts: BN;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
makerPnl: BN;
|
|
299
|
+
user: PublicKey;
|
|
300
|
+
order: Order;
|
|
301
|
+
};
|
|
302
|
+
export declare type OrderActionRecord = {
|
|
303
|
+
ts: BN;
|
|
303
304
|
action: OrderAction;
|
|
304
305
|
actionExplanation: OrderActionExplanation;
|
|
305
|
-
filler: PublicKey;
|
|
306
|
-
fillRecordId: BN;
|
|
307
306
|
marketIndex: BN;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
307
|
+
filler: PublicKey | null;
|
|
308
|
+
fillerReward: BN | null;
|
|
309
|
+
fillRecordId: BN | null;
|
|
310
|
+
referrer: PublicKey | null;
|
|
311
|
+
baseAssetAmountFilled: BN | null;
|
|
312
|
+
quoteAssetAmountFilled: BN | null;
|
|
313
|
+
takerPnl: BN | null;
|
|
314
|
+
makerPnl: BN | null;
|
|
315
|
+
takerFee: BN | null;
|
|
316
|
+
makerRebate: BN | null;
|
|
317
|
+
referrerReward: BN | null;
|
|
318
|
+
refereeDiscount: BN | null;
|
|
319
|
+
quoteAssetAmountSurplus: BN | null;
|
|
320
|
+
taker: PublicKey | null;
|
|
321
|
+
takerOrderId: BN | null;
|
|
322
|
+
takerOrderBaseAssetAmount: BN | null;
|
|
323
|
+
takerOrderBaseAssetAmountFilled: BN | null;
|
|
324
|
+
takerOrderQuoteAssetAmountFilled: BN | null;
|
|
325
|
+
takerOrderFee: BN | null;
|
|
326
|
+
maker: PublicKey | null;
|
|
327
|
+
makerOrderId: BN | null;
|
|
328
|
+
makerOrderBaseAssetAmount: BN | null;
|
|
329
|
+
makerOrderBaseAssetAmountFilled: BN | null;
|
|
330
|
+
makerOrderQuoteAssetAmountFilled: BN | null;
|
|
331
|
+
makerOrderFee: BN | null;
|
|
314
332
|
oraclePrice: BN;
|
|
315
|
-
referrer: PublicKey;
|
|
316
|
-
referrerReward: BN;
|
|
317
|
-
refereeDiscount: BN;
|
|
318
333
|
};
|
|
319
334
|
export declare type StateAccount = {
|
|
320
335
|
admin: PublicKey;
|
|
@@ -345,6 +360,8 @@ export declare type StateAccount = {
|
|
|
345
360
|
numberOfMarkets: BN;
|
|
346
361
|
numberOfBanks: BN;
|
|
347
362
|
minOrderQuoteAssetAmount: BN;
|
|
363
|
+
maxAuctionDuration: number;
|
|
364
|
+
minAuctionDuration: number;
|
|
348
365
|
};
|
|
349
366
|
export declare type MarketAccount = {
|
|
350
367
|
initialized: boolean;
|
|
@@ -372,6 +389,16 @@ export declare type BankAccount = {
|
|
|
372
389
|
vault: PublicKey;
|
|
373
390
|
vaultAuthority: PublicKey;
|
|
374
391
|
vaultAuthorityNonce: number;
|
|
392
|
+
insuranceFundVault: PublicKey;
|
|
393
|
+
insuranceFundVaultAuthority: PublicKey;
|
|
394
|
+
insuranceFundVaultAuthorityNonce: number;
|
|
395
|
+
insuranceWithdrawEscrowPeriod: BN;
|
|
396
|
+
revenuePool: PoolBalance;
|
|
397
|
+
totalIfShares: BN;
|
|
398
|
+
userIfShares: BN;
|
|
399
|
+
userIfFactor: BN;
|
|
400
|
+
totalIfFactor: BN;
|
|
401
|
+
liquidationIfFactor: BN;
|
|
375
402
|
decimals: number;
|
|
376
403
|
optimalUtilization: BN;
|
|
377
404
|
optimalBorrowRate: BN;
|
|
@@ -451,6 +478,7 @@ export declare type AMM = {
|
|
|
451
478
|
maxSpread: number;
|
|
452
479
|
marketPosition: UserPosition;
|
|
453
480
|
marketPositionPerLp: UserPosition;
|
|
481
|
+
ammJitIntensity: number;
|
|
454
482
|
maxBaseAssetReserve: BN;
|
|
455
483
|
minBaseAssetReserve: BN;
|
|
456
484
|
};
|
|
@@ -487,6 +515,7 @@ export declare type UserStatsAccount = {
|
|
|
487
515
|
isReferrer: boolean;
|
|
488
516
|
totalReferrerReward: BN;
|
|
489
517
|
authority: PublicKey;
|
|
518
|
+
quoteAssetInsuranceFundStake: BN;
|
|
490
519
|
};
|
|
491
520
|
export declare type UserAccount = {
|
|
492
521
|
authority: PublicKey;
|
|
@@ -597,6 +626,7 @@ export declare type MakerInfo = {
|
|
|
597
626
|
export declare type TakerInfo = {
|
|
598
627
|
taker: PublicKey;
|
|
599
628
|
takerStats: PublicKey;
|
|
629
|
+
takerUserAccount: UserAccount;
|
|
600
630
|
order: Order;
|
|
601
631
|
};
|
|
602
632
|
export declare type ReferrerInfo = {
|
|
@@ -662,3 +692,12 @@ export declare type OrderFillerRewardStructure = {
|
|
|
662
692
|
timeBasedRewardLowerBound: BN;
|
|
663
693
|
};
|
|
664
694
|
export declare type MarginCategory = 'Initial' | 'Maintenance';
|
|
695
|
+
export declare type InsuranceFundStake = {
|
|
696
|
+
bankIndex: BN;
|
|
697
|
+
authority: PublicKey;
|
|
698
|
+
ifShares: BN;
|
|
699
|
+
ifBase: BN;
|
|
700
|
+
lastWithdrawRequestShares: BN;
|
|
701
|
+
lastWithdrawRequestValue: BN;
|
|
702
|
+
lastWithdrawRequestTs: BN;
|
|
703
|
+
};
|
package/lib/types.js
CHANGED
|
@@ -61,9 +61,6 @@ class OrderActionExplanation {
|
|
|
61
61
|
}
|
|
62
62
|
exports.OrderActionExplanation = OrderActionExplanation;
|
|
63
63
|
OrderActionExplanation.NONE = { none: {} };
|
|
64
|
-
OrderActionExplanation.BREACHED_MARGIN_REQUIREMENT = {
|
|
65
|
-
breachedMarginRequirement: {},
|
|
66
|
-
};
|
|
67
64
|
OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
68
65
|
oraclePriceBreachedLimitPrice: {},
|
|
69
66
|
};
|
package/package.json
CHANGED
package/src/addresses/pda.ts
CHANGED
|
@@ -129,3 +129,50 @@ export async function getBankVaultAuthorityPublicKey(
|
|
|
129
129
|
)
|
|
130
130
|
)[0];
|
|
131
131
|
}
|
|
132
|
+
|
|
133
|
+
export async function getInsuranceFundVaultPublicKey(
|
|
134
|
+
programId: PublicKey,
|
|
135
|
+
bankIndex: BN
|
|
136
|
+
): Promise<PublicKey> {
|
|
137
|
+
return (
|
|
138
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
139
|
+
[
|
|
140
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
141
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
142
|
+
],
|
|
143
|
+
programId
|
|
144
|
+
)
|
|
145
|
+
)[0];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export async function getInsuranceFundVaultAuthorityPublicKey(
|
|
149
|
+
programId: PublicKey,
|
|
150
|
+
bankIndex: BN
|
|
151
|
+
): Promise<PublicKey> {
|
|
152
|
+
return (
|
|
153
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
154
|
+
[
|
|
155
|
+
Buffer.from(
|
|
156
|
+
anchor.utils.bytes.utf8.encode('insurance_fund_vault_authority')
|
|
157
|
+
),
|
|
158
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
159
|
+
],
|
|
160
|
+
programId
|
|
161
|
+
)
|
|
162
|
+
)[0];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function getInsuranceFundStakeAccountPublicKey(
|
|
166
|
+
programId: PublicKey,
|
|
167
|
+
authority: PublicKey,
|
|
168
|
+
bankIndex: BN
|
|
169
|
+
): PublicKey {
|
|
170
|
+
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
171
|
+
[
|
|
172
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
173
|
+
authority.toBuffer(),
|
|
174
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
175
|
+
],
|
|
176
|
+
programId
|
|
177
|
+
)[0];
|
|
178
|
+
}
|
package/src/admin.ts
CHANGED
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
getBankPublicKey,
|
|
18
18
|
getBankVaultPublicKey,
|
|
19
19
|
getMarketPublicKey,
|
|
20
|
+
getInsuranceFundVaultPublicKey,
|
|
21
|
+
getInsuranceFundVaultAuthorityPublicKey,
|
|
20
22
|
} from './addresses/pda';
|
|
21
23
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
24
|
import { ClearingHouse } from './clearingHouse';
|
|
@@ -102,6 +104,17 @@ export class Admin extends ClearingHouse {
|
|
|
102
104
|
bankIndex
|
|
103
105
|
);
|
|
104
106
|
|
|
107
|
+
const insuranceFundVault = await getInsuranceFundVaultPublicKey(
|
|
108
|
+
this.program.programId,
|
|
109
|
+
bankIndex
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const insuranceFundVaultAuthority =
|
|
113
|
+
await getInsuranceFundVaultAuthorityPublicKey(
|
|
114
|
+
this.program.programId,
|
|
115
|
+
bankIndex
|
|
116
|
+
);
|
|
117
|
+
|
|
105
118
|
const initializeTx = await this.program.transaction.initializeBank(
|
|
106
119
|
optimalUtilization,
|
|
107
120
|
optimalRate,
|
|
@@ -120,6 +133,8 @@ export class Admin extends ClearingHouse {
|
|
|
120
133
|
bank,
|
|
121
134
|
bankVault,
|
|
122
135
|
bankVaultAuthority,
|
|
136
|
+
insuranceFundVault,
|
|
137
|
+
insuranceFundVaultAuthority,
|
|
123
138
|
bankMint: mint,
|
|
124
139
|
oracle,
|
|
125
140
|
rent: SYSVAR_RENT_PUBKEY,
|
|
@@ -452,6 +467,19 @@ export class Admin extends ClearingHouse {
|
|
|
452
467
|
});
|
|
453
468
|
}
|
|
454
469
|
|
|
470
|
+
public async updateAmmJitIntensity(
|
|
471
|
+
marketIndex: BN,
|
|
472
|
+
ammJitIntensity: number
|
|
473
|
+
): Promise<TransactionSignature> {
|
|
474
|
+
return await this.program.rpc.updateAmmJitIntensity(ammJitIntensity, {
|
|
475
|
+
accounts: {
|
|
476
|
+
admin: this.wallet.publicKey,
|
|
477
|
+
state: await this.getStatePublicKey(),
|
|
478
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
455
483
|
public async updateMarketMaxSpread(
|
|
456
484
|
marketIndex: BN,
|
|
457
485
|
maxSpread: number
|
|
@@ -591,6 +619,43 @@ export class Admin extends ClearingHouse {
|
|
|
591
619
|
);
|
|
592
620
|
}
|
|
593
621
|
|
|
622
|
+
public async updateBankIfFactor(
|
|
623
|
+
bankIndex: BN,
|
|
624
|
+
userIfFactor: BN,
|
|
625
|
+
totalIfFactor: BN,
|
|
626
|
+
liquidationIfFactor: BN
|
|
627
|
+
): Promise<TransactionSignature> {
|
|
628
|
+
return await this.program.rpc.updateBankIfFactor(
|
|
629
|
+
bankIndex,
|
|
630
|
+
userIfFactor,
|
|
631
|
+
totalIfFactor,
|
|
632
|
+
liquidationIfFactor,
|
|
633
|
+
{
|
|
634
|
+
accounts: {
|
|
635
|
+
admin: this.wallet.publicKey,
|
|
636
|
+
state: await this.getStatePublicKey(),
|
|
637
|
+
bank: await getBankPublicKey(this.program.programId, bankIndex),
|
|
638
|
+
},
|
|
639
|
+
}
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
public async updateBankInsuranceWithdrawEscrowPeriod(
|
|
644
|
+
bankIndex: BN,
|
|
645
|
+
insuranceWithdrawEscrowPeriod: BN
|
|
646
|
+
): Promise<TransactionSignature> {
|
|
647
|
+
return await this.program.rpc.updateBankInsuranceWithdrawEscrowPeriod(
|
|
648
|
+
insuranceWithdrawEscrowPeriod,
|
|
649
|
+
{
|
|
650
|
+
accounts: {
|
|
651
|
+
admin: this.wallet.publicKey,
|
|
652
|
+
state: await this.getStatePublicKey(),
|
|
653
|
+
bank: await getBankPublicKey(this.program.programId, bankIndex),
|
|
654
|
+
},
|
|
655
|
+
}
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
|
|
594
659
|
public async updateLpCooldownTime(
|
|
595
660
|
marketIndex: BN,
|
|
596
661
|
cooldownTime: BN
|