@drift-labs/sdk 0.2.0-master.21 → 0.2.0-master.24
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 +1 -0
- 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 +9 -2
- package/lib/clearingHouse.js +132 -4
- package/lib/clearingHouseUser.js +5 -5
- 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/position.js +1 -1
- package/lib/types.d.ts +56 -20
- package/lib/types.js +0 -3
- package/package.json +1 -1
- package/src/addresses/marketAddresses.js +26 -0
- package/src/addresses/pda.ts +47 -0
- package/src/admin.ts +65 -0
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +217 -9
- package/src/clearingHouseUser.ts +10 -6
- package/src/config.ts +1 -1
- package/src/constants/banks.js +42 -0
- package/src/constants/banks.ts +16 -0
- package/src/constants/markets.js +42 -0
- package/src/constants/numericConstants.js +41 -0
- package/src/constants/numericConstants.ts +4 -0
- package/src/events/eventList.js +77 -0
- package/src/events/sort.ts +10 -14
- package/src/events/txEventCache.js +71 -0
- package/src/events/types.ts +3 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/factory/bigNum.js +390 -0
- package/src/factory/oracleClient.js +20 -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/auction.js +42 -0
- package/src/math/conversion.js +11 -0
- package/src/math/funding.js +248 -0
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +3 -10
- package/src/math/oracles.js +26 -0
- package/src/math/position.ts +2 -2
- package/src/math/repeg.js +128 -0
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/utils.js +26 -0
- package/src/math/utils.js.map +1 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/types.js +2 -0
- package/src/orderParams.js +20 -0
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/token/index.js +38 -0
- package/src/tokenFaucet.js +189 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/types.ts +64 -20
- package/src/userName.js +20 -0
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/my-script/.env +0 -7
- package/my-script/getUserStats.ts +0 -124
- package/my-script/multiConnections.ts +0 -137
- package/my-script/test-regex.ts +0 -11
- package/my-script/utils.ts +0 -52
- package/my-script/ww18NdhuLSQPCrHSx7V68eZJpe2y311heWeXJfSmP3Q.json +0 -1
- package/my-script/ww2z7N9TG1PLLUQGQF2VKzCFaPtQ5FBhRfeEAuy6c5C.json +0 -1
- package/my-script/ww3StJtTubhwssqAhvSSAc5ifCgKjzmF8hz7Gt2DmSa.json +0 -1
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/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;
|
|
@@ -374,6 +389,16 @@ export declare type BankAccount = {
|
|
|
374
389
|
vault: PublicKey;
|
|
375
390
|
vaultAuthority: PublicKey;
|
|
376
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;
|
|
377
402
|
decimals: number;
|
|
378
403
|
optimalUtilization: BN;
|
|
379
404
|
optimalBorrowRate: BN;
|
|
@@ -453,6 +478,7 @@ export declare type AMM = {
|
|
|
453
478
|
maxSpread: number;
|
|
454
479
|
marketPosition: UserPosition;
|
|
455
480
|
marketPositionPerLp: UserPosition;
|
|
481
|
+
ammJitIntensity: number;
|
|
456
482
|
maxBaseAssetReserve: BN;
|
|
457
483
|
minBaseAssetReserve: BN;
|
|
458
484
|
};
|
|
@@ -489,6 +515,7 @@ export declare type UserStatsAccount = {
|
|
|
489
515
|
isReferrer: boolean;
|
|
490
516
|
totalReferrerReward: BN;
|
|
491
517
|
authority: PublicKey;
|
|
518
|
+
quoteAssetInsuranceFundStake: BN;
|
|
492
519
|
};
|
|
493
520
|
export declare type UserAccount = {
|
|
494
521
|
authority: PublicKey;
|
|
@@ -665,3 +692,12 @@ export declare type OrderFillerRewardStructure = {
|
|
|
665
692
|
timeBasedRewardLowerBound: BN;
|
|
666
693
|
};
|
|
667
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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getMarketAddress = void 0;
|
|
13
|
+
const pda_1 = require("./pda");
|
|
14
|
+
const CACHE = new Map();
|
|
15
|
+
function getMarketAddress(programId, marketIndex) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const cacheKey = `${programId.toString()}-${marketIndex.toString()}`;
|
|
18
|
+
if (CACHE.has(cacheKey)) {
|
|
19
|
+
return CACHE.get(cacheKey);
|
|
20
|
+
}
|
|
21
|
+
const publicKey = yield pda_1.getMarketPublicKey(programId, marketIndex);
|
|
22
|
+
CACHE.set(cacheKey, publicKey);
|
|
23
|
+
return publicKey;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.getMarketAddress = getMarketAddress;
|
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
|