@drift-labs/sdk 2.86.0-beta.9 → 2.87.0-beta.1
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/VERSION +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/adminClient.d.ts +8 -4
- package/lib/adminClient.js +51 -8
- package/lib/bankrun/bankrunConnection.d.ts +1 -0
- package/lib/bankrun/bankrunConnection.js +6 -0
- package/lib/constants/numericConstants.d.ts +2 -0
- package/lib/constants/numericConstants.js +3 -1
- package/lib/constants/perpMarkets.js +139 -126
- package/lib/constants/spotMarkets.js +52 -40
- package/lib/driftClient.d.ts +12 -14
- package/lib/driftClient.js +147 -9
- package/lib/idl/drift.json +344 -10
- package/lib/idl/pyth_solana_receiver.json +628 -0
- package/lib/math/fuel.d.ts +1 -0
- package/lib/math/fuel.js +12 -2
- package/lib/types.d.ts +25 -6
- package/lib/types.js +3 -2
- package/lib/user.d.ts +6 -5
- package/lib/user.js +36 -18
- package/package.json +1 -1
- package/src/addresses/pda.ts +15 -0
- package/src/adminClient.ts +119 -7
- package/src/bankrun/bankrunConnection.ts +13 -0
- package/src/constants/numericConstants.ts +2 -0
- package/src/constants/perpMarkets.ts +142 -126
- package/src/constants/spotMarkets.ts +54 -40
- package/src/driftClient.ts +203 -16
- package/src/idl/drift.json +344 -10
- package/src/idl/openbook.json +3854 -0
- package/src/idl/pyth_solana_receiver.json +628 -0
- package/src/math/fuel.ts +15 -1
- package/src/types.ts +28 -7
- package/src/user.ts +119 -55
- package/tests/ci/verifyConstants.ts +214 -0
- package/tests/dlob/helpers.ts +30 -0
- package/tests/user/helpers.ts +1 -0
- package/tests/user/test.ts +2 -0
package/lib/types.d.ts
CHANGED
|
@@ -55,8 +55,9 @@ export declare enum PerpOperation {
|
|
|
55
55
|
export declare enum SpotOperation {
|
|
56
56
|
UPDATE_CUMULATIVE_INTEREST = 1,
|
|
57
57
|
FILL = 2,
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
DEPOSIT = 4,
|
|
59
|
+
WITHDRAW = 8,
|
|
60
|
+
LIQUIDATION = 16
|
|
60
61
|
}
|
|
61
62
|
export declare enum InsuranceFundOperation {
|
|
62
63
|
INIT = 1,
|
|
@@ -731,9 +732,9 @@ export type PerpMarketAccount = {
|
|
|
731
732
|
quoteSpotMarketIndex: number;
|
|
732
733
|
feeAdjustment: number;
|
|
733
734
|
pausedOperations: number;
|
|
734
|
-
fuelBoostPosition: number;
|
|
735
|
-
fuelBoostMaker: number;
|
|
736
735
|
fuelBoostTaker: number;
|
|
736
|
+
fuelBoostMaker: number;
|
|
737
|
+
fuelBoostPosition: number;
|
|
737
738
|
};
|
|
738
739
|
export type HistoricalOracleData = {
|
|
739
740
|
lastOraclePrice: BN;
|
|
@@ -817,8 +818,9 @@ export type SpotMarketAccount = {
|
|
|
817
818
|
minBorrowRate: number;
|
|
818
819
|
fuelBoostDeposits: number;
|
|
819
820
|
fuelBoostBorrows: number;
|
|
820
|
-
fuelBoostMaker: number;
|
|
821
821
|
fuelBoostTaker: number;
|
|
822
|
+
fuelBoostMaker: number;
|
|
823
|
+
fuelBoostInsurance: number;
|
|
822
824
|
};
|
|
823
825
|
export type PoolBalance = {
|
|
824
826
|
scaledBalance: BN;
|
|
@@ -946,6 +948,8 @@ export type UserStatsAccount = {
|
|
|
946
948
|
isReferrer: boolean;
|
|
947
949
|
authority: PublicKey;
|
|
948
950
|
ifStakedQuoteAssetAmount: BN;
|
|
951
|
+
lastFuelIfBonusUpdateTs: number;
|
|
952
|
+
fuelInsurance: number;
|
|
949
953
|
fuelDeposits: number;
|
|
950
954
|
fuelBorrows: number;
|
|
951
955
|
fuelPositions: number;
|
|
@@ -980,7 +984,7 @@ export type UserAccount = {
|
|
|
980
984
|
hasOpenOrder: boolean;
|
|
981
985
|
openAuctions: number;
|
|
982
986
|
hasOpenAuction: boolean;
|
|
983
|
-
lastFuelBonusUpdateTs:
|
|
987
|
+
lastFuelBonusUpdateTs: number;
|
|
984
988
|
};
|
|
985
989
|
export type SpotPosition = {
|
|
986
990
|
marketIndex: number;
|
|
@@ -1199,6 +1203,21 @@ export type PhoenixV1FulfillmentConfigAccount = {
|
|
|
1199
1203
|
fulfillmentType: SpotFulfillmentType;
|
|
1200
1204
|
status: SpotFulfillmentStatus;
|
|
1201
1205
|
};
|
|
1206
|
+
export type OpenbookV2FulfillmentConfigAccount = {
|
|
1207
|
+
pubkey: PublicKey;
|
|
1208
|
+
openbookV2ProgramId: PublicKey;
|
|
1209
|
+
openbookV2Market: PublicKey;
|
|
1210
|
+
openbookV2MarketAuthority: PublicKey;
|
|
1211
|
+
openbookV2EventHeap: PublicKey;
|
|
1212
|
+
openbookV2Bids: PublicKey;
|
|
1213
|
+
openbookV2Asks: PublicKey;
|
|
1214
|
+
openbookV2BaseVault: PublicKey;
|
|
1215
|
+
openbookV2QuoteVault: PublicKey;
|
|
1216
|
+
marketIndex: number;
|
|
1217
|
+
fulfillmentType: SpotFulfillmentType;
|
|
1218
|
+
status: SpotFulfillmentStatus;
|
|
1219
|
+
remainingAccounts?: PublicKey[];
|
|
1220
|
+
};
|
|
1202
1221
|
export type ReferrerNameAccount = {
|
|
1203
1222
|
name: number[];
|
|
1204
1223
|
user: PublicKey;
|
package/lib/types.js
CHANGED
|
@@ -40,8 +40,9 @@ var SpotOperation;
|
|
|
40
40
|
(function (SpotOperation) {
|
|
41
41
|
SpotOperation[SpotOperation["UPDATE_CUMULATIVE_INTEREST"] = 1] = "UPDATE_CUMULATIVE_INTEREST";
|
|
42
42
|
SpotOperation[SpotOperation["FILL"] = 2] = "FILL";
|
|
43
|
-
SpotOperation[SpotOperation["
|
|
44
|
-
SpotOperation[SpotOperation["
|
|
43
|
+
SpotOperation[SpotOperation["DEPOSIT"] = 4] = "DEPOSIT";
|
|
44
|
+
SpotOperation[SpotOperation["WITHDRAW"] = 8] = "WITHDRAW";
|
|
45
|
+
SpotOperation[SpotOperation["LIQUIDATION"] = 16] = "LIQUIDATION";
|
|
45
46
|
})(SpotOperation = exports.SpotOperation || (exports.SpotOperation = {}));
|
|
46
47
|
var InsuranceFundOperation;
|
|
47
48
|
(function (InsuranceFundOperation) {
|
package/lib/user.d.ts
CHANGED
|
@@ -137,11 +137,12 @@ export declare class User {
|
|
|
137
137
|
*/
|
|
138
138
|
getUnrealizedFundingPNL(marketIndex?: number): BN;
|
|
139
139
|
getFuelBonus(now: BN, includeSettled?: boolean, includeUnsettled?: boolean): {
|
|
140
|
-
depositFuel:
|
|
141
|
-
borrowFuel:
|
|
142
|
-
positionFuel:
|
|
143
|
-
takerFuel:
|
|
144
|
-
makerFuel:
|
|
140
|
+
depositFuel: BN;
|
|
141
|
+
borrowFuel: BN;
|
|
142
|
+
positionFuel: BN;
|
|
143
|
+
takerFuel: BN;
|
|
144
|
+
makerFuel: BN;
|
|
145
|
+
insuranceFuel: BN;
|
|
145
146
|
};
|
|
146
147
|
getSpotMarketAssetAndLiabilityValue(marketIndex?: number, marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean, strict?: boolean, now?: BN): {
|
|
147
148
|
totalAssetValue: BN;
|
package/lib/user.js
CHANGED
|
@@ -543,6 +543,7 @@ class User {
|
|
|
543
543
|
getFuelBonus(now, includeSettled = true, includeUnsettled = true) {
|
|
544
544
|
const userAccount = this.getUserAccount();
|
|
545
545
|
const result = {
|
|
546
|
+
insuranceFuel: numericConstants_1.ZERO,
|
|
546
547
|
takerFuel: numericConstants_1.ZERO,
|
|
547
548
|
makerFuel: numericConstants_1.ZERO,
|
|
548
549
|
depositFuel: numericConstants_1.ZERO,
|
|
@@ -553,6 +554,7 @@ class User {
|
|
|
553
554
|
const userStats = this.driftClient
|
|
554
555
|
.getUserStats()
|
|
555
556
|
.getAccount();
|
|
557
|
+
result.insuranceFuel = result.insuranceFuel.add(new _1.BN(userStats.fuelInsurance));
|
|
556
558
|
result.takerFuel = result.takerFuel.add(new _1.BN(userStats.fuelTaker));
|
|
557
559
|
result.makerFuel = result.makerFuel.add(new _1.BN(userStats.fuelMaker));
|
|
558
560
|
result.depositFuel = result.depositFuel.add(new _1.BN(userStats.fuelDeposits));
|
|
@@ -560,27 +562,43 @@ class User {
|
|
|
560
562
|
result.positionFuel = result.positionFuel.add(new _1.BN(userStats.fuelPositions));
|
|
561
563
|
}
|
|
562
564
|
if (includeUnsettled) {
|
|
563
|
-
const fuelBonusNumerator = now.sub(userAccount.lastFuelBonusUpdateTs);
|
|
564
|
-
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
565
|
+
const fuelBonusNumerator = _1.BN.max(now.sub(_1.BN.max(new _1.BN(userAccount.lastFuelBonusUpdateTs), numericConstants_1.FUEL_START_TS)), numericConstants_1.ZERO);
|
|
566
|
+
if (fuelBonusNumerator.gt(numericConstants_1.ZERO)) {
|
|
567
|
+
for (const spotPosition of this.getActiveSpotPositions()) {
|
|
568
|
+
const spotMarketAccount = this.driftClient.getSpotMarketAccount(spotPosition.marketIndex);
|
|
569
|
+
const tokenAmount = this.getTokenAmount(spotPosition.marketIndex);
|
|
570
|
+
const oraclePriceData = this.getOracleDataForSpotMarket(spotPosition.marketIndex);
|
|
571
|
+
const twap5min = (0, oracles_1.calculateLiveOracleTwap)(spotMarketAccount.historicalOracleData, oraclePriceData, now, numericConstants_1.FIVE_MINUTE // 5MIN
|
|
572
|
+
);
|
|
573
|
+
const strictOraclePrice = new strictOraclePrice_1.StrictOraclePrice(oraclePriceData.price, twap5min);
|
|
574
|
+
const signedTokenValue = (0, _1.getStrictTokenValue)(tokenAmount, spotMarketAccount.decimals, strictOraclePrice);
|
|
575
|
+
if (signedTokenValue.gt(numericConstants_1.ZERO)) {
|
|
576
|
+
result.depositFuel = result.depositFuel.add((0, fuel_1.calculateSpotFuelBonus)(spotMarketAccount, signedTokenValue, fuelBonusNumerator));
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
result.borrowFuel = result.borrowFuel.add((0, fuel_1.calculateSpotFuelBonus)(spotMarketAccount, signedTokenValue, fuelBonusNumerator));
|
|
580
|
+
}
|
|
574
581
|
}
|
|
575
|
-
|
|
576
|
-
|
|
582
|
+
for (const perpPosition of this.getActivePerpPositions()) {
|
|
583
|
+
const oraclePriceData = this.getOracleDataForPerpMarket(perpPosition.marketIndex);
|
|
584
|
+
const perpMarketAccount = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
|
|
585
|
+
const baseAssetValue = this.getPerpPositionValue(perpPosition.marketIndex, oraclePriceData, false);
|
|
586
|
+
result.positionFuel = result.positionFuel.add((0, fuel_1.calculatePerpFuelBonus)(perpMarketAccount, baseAssetValue, fuelBonusNumerator));
|
|
577
587
|
}
|
|
578
588
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
589
|
+
const userStats = this.driftClient
|
|
590
|
+
.getUserStats()
|
|
591
|
+
.getAccount();
|
|
592
|
+
// todo: get real time ifStakedGovTokenAmount using ifStakeAccount
|
|
593
|
+
if (userStats.ifStakedGovTokenAmount.gt(numericConstants_1.ZERO)) {
|
|
594
|
+
const spotMarketAccount = this.driftClient.getSpotMarketAccount(numericConstants_1.GOV_SPOT_MARKET_INDEX);
|
|
595
|
+
const fuelBonusNumeratorUserStats = _1.BN.max(now.sub(_1.BN.max(new _1.BN(userStats.lastFuelIfBonusUpdateTs), numericConstants_1.FUEL_START_TS)), numericConstants_1.ZERO);
|
|
596
|
+
result.insuranceFuel = result.insuranceFuel.add((0, fuel_1.calculateInsuranceFuelBonus)(spotMarketAccount, userStats.ifStakedGovTokenAmount, fuelBonusNumeratorUserStats));
|
|
597
|
+
}
|
|
598
|
+
if (userStats.ifStakedQuoteAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
599
|
+
const spotMarketAccount = this.driftClient.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
600
|
+
const fuelBonusNumeratorUserStats = _1.BN.max(now.sub(_1.BN.max(new _1.BN(userStats.lastFuelIfBonusUpdateTs), numericConstants_1.FUEL_START_TS)), numericConstants_1.ZERO);
|
|
601
|
+
result.insuranceFuel = result.insuranceFuel.add((0, fuel_1.calculateInsuranceFuelBonus)(spotMarketAccount, userStats.ifStakedQuoteAssetAmount, fuelBonusNumeratorUserStats));
|
|
584
602
|
}
|
|
585
603
|
}
|
|
586
604
|
return result;
|
package/package.json
CHANGED
package/src/addresses/pda.ts
CHANGED
|
@@ -202,6 +202,21 @@ export function getPhoenixFulfillmentConfigPublicKey(
|
|
|
202
202
|
)[0];
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
export function getOpenbookV2FulfillmentConfigPublicKey(
|
|
206
|
+
programId: PublicKey,
|
|
207
|
+
market: PublicKey
|
|
208
|
+
): PublicKey {
|
|
209
|
+
return PublicKey.findProgramAddressSync(
|
|
210
|
+
[
|
|
211
|
+
Buffer.from(
|
|
212
|
+
anchor.utils.bytes.utf8.encode('openbook_v2_fulfillment_config')
|
|
213
|
+
),
|
|
214
|
+
market.toBuffer(),
|
|
215
|
+
],
|
|
216
|
+
programId
|
|
217
|
+
)[0];
|
|
218
|
+
}
|
|
219
|
+
|
|
205
220
|
export function getReferrerNamePublicKeySync(
|
|
206
221
|
programId: PublicKey,
|
|
207
222
|
nameBuffer: number[]
|
package/src/adminClient.ts
CHANGED
|
@@ -29,7 +29,9 @@ import {
|
|
|
29
29
|
getPhoenixFulfillmentConfigPublicKey,
|
|
30
30
|
getProtocolIfSharesTransferConfigPublicKey,
|
|
31
31
|
getPrelaunchOraclePublicKey,
|
|
32
|
+
getOpenbookV2FulfillmentConfigPublicKey,
|
|
32
33
|
getPythPullOraclePublicKey,
|
|
34
|
+
getUserStatsAccountPublicKey,
|
|
33
35
|
} from './addresses/pda';
|
|
34
36
|
import { squareRootBN } from './math/utils';
|
|
35
37
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
@@ -48,6 +50,10 @@ import { PROGRAM_ID as PHOENIX_PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
|
|
|
48
50
|
import { DRIFT_ORACLE_RECEIVER_ID } from './config';
|
|
49
51
|
import { getFeedIdUint8Array } from './util/pythPullOracleUtils';
|
|
50
52
|
|
|
53
|
+
const OPENBOOK_PROGRAM_ID = new PublicKey(
|
|
54
|
+
'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb'
|
|
55
|
+
);
|
|
56
|
+
|
|
51
57
|
export class AdminClient extends DriftClient {
|
|
52
58
|
public async initialize(
|
|
53
59
|
usdcMint: PublicKey,
|
|
@@ -385,6 +391,52 @@ export class AdminClient extends DriftClient {
|
|
|
385
391
|
);
|
|
386
392
|
}
|
|
387
393
|
|
|
394
|
+
public async initializeOpenbookV2FulfillmentConfig(
|
|
395
|
+
marketIndex: number,
|
|
396
|
+
openbookMarket: PublicKey
|
|
397
|
+
): Promise<TransactionSignature> {
|
|
398
|
+
const initializeIx = await this.getInitializeOpenbookV2FulfillmentConfigIx(
|
|
399
|
+
marketIndex,
|
|
400
|
+
openbookMarket
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
const tx = await this.buildTransaction(initializeIx);
|
|
404
|
+
|
|
405
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
406
|
+
|
|
407
|
+
return txSig;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
public async getInitializeOpenbookV2FulfillmentConfigIx(
|
|
411
|
+
marketIndex: number,
|
|
412
|
+
openbookMarket: PublicKey
|
|
413
|
+
): Promise<TransactionInstruction> {
|
|
414
|
+
const openbookFulfillmentConfig = getOpenbookV2FulfillmentConfigPublicKey(
|
|
415
|
+
this.program.programId,
|
|
416
|
+
openbookMarket
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
return this.program.instruction.initializeOpenbookV2FulfillmentConfig(
|
|
420
|
+
marketIndex,
|
|
421
|
+
{
|
|
422
|
+
accounts: {
|
|
423
|
+
baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
424
|
+
quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
|
|
425
|
+
state: await this.getStatePublicKey(),
|
|
426
|
+
openbookV2Program: OPENBOOK_PROGRAM_ID,
|
|
427
|
+
openbookV2Market: openbookMarket,
|
|
428
|
+
driftSigner: this.getSignerPublicKey(),
|
|
429
|
+
openbookV2FulfillmentConfig: openbookFulfillmentConfig,
|
|
430
|
+
admin: this.isSubscribed
|
|
431
|
+
? this.getStateAccount().admin
|
|
432
|
+
: this.wallet.publicKey,
|
|
433
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
434
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
435
|
+
},
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
388
440
|
public async initializePerpMarket(
|
|
389
441
|
marketIndex: number,
|
|
390
442
|
priceOracle: PublicKey,
|
|
@@ -1818,12 +1870,12 @@ export class AdminClient extends DriftClient {
|
|
|
1818
1870
|
|
|
1819
1871
|
public async updateSpotMarketMaxTokenBorrows(
|
|
1820
1872
|
spotMarketIndex: number,
|
|
1821
|
-
|
|
1873
|
+
maxTokenBorrowsFraction: number
|
|
1822
1874
|
): Promise<TransactionSignature> {
|
|
1823
1875
|
const updateSpotMarketMaxTokenBorrowsIx =
|
|
1824
1876
|
await this.getUpdateSpotMarketMaxTokenBorrowsIx(
|
|
1825
1877
|
spotMarketIndex,
|
|
1826
|
-
|
|
1878
|
+
maxTokenBorrowsFraction
|
|
1827
1879
|
);
|
|
1828
1880
|
|
|
1829
1881
|
const tx = await this.buildTransaction(updateSpotMarketMaxTokenBorrowsIx);
|
|
@@ -1835,10 +1887,10 @@ export class AdminClient extends DriftClient {
|
|
|
1835
1887
|
|
|
1836
1888
|
public async getUpdateSpotMarketMaxTokenBorrowsIx(
|
|
1837
1889
|
spotMarketIndex: number,
|
|
1838
|
-
|
|
1890
|
+
maxTokenBorrowsFraction: number
|
|
1839
1891
|
): Promise<TransactionInstruction> {
|
|
1840
1892
|
return this.program.instruction.updateSpotMarketMaxTokenBorrows(
|
|
1841
|
-
|
|
1893
|
+
maxTokenBorrowsFraction,
|
|
1842
1894
|
{
|
|
1843
1895
|
accounts: {
|
|
1844
1896
|
admin: this.isSubscribed
|
|
@@ -3538,14 +3590,16 @@ export class AdminClient extends DriftClient {
|
|
|
3538
3590
|
fuelBoostDeposits?: number,
|
|
3539
3591
|
fuelBoostBorrows?: number,
|
|
3540
3592
|
fuelBoostTaker?: number,
|
|
3541
|
-
fuelBoostMaker?: number
|
|
3593
|
+
fuelBoostMaker?: number,
|
|
3594
|
+
fuelBoostInsurance?: number
|
|
3542
3595
|
): Promise<TransactionSignature> {
|
|
3543
3596
|
const updateSpotMarketFuelIx = await this.getUpdateSpotMarketFuelIx(
|
|
3544
3597
|
spotMarketIndex,
|
|
3545
3598
|
fuelBoostDeposits || null,
|
|
3546
3599
|
fuelBoostBorrows || null,
|
|
3547
3600
|
fuelBoostTaker || null,
|
|
3548
|
-
fuelBoostMaker || null
|
|
3601
|
+
fuelBoostMaker || null,
|
|
3602
|
+
fuelBoostInsurance || null
|
|
3549
3603
|
);
|
|
3550
3604
|
|
|
3551
3605
|
const tx = await this.buildTransaction(updateSpotMarketFuelIx);
|
|
@@ -3559,7 +3613,8 @@ export class AdminClient extends DriftClient {
|
|
|
3559
3613
|
fuelBoostDeposits?: number,
|
|
3560
3614
|
fuelBoostBorrows?: number,
|
|
3561
3615
|
fuelBoostTaker?: number,
|
|
3562
|
-
fuelBoostMaker?: number
|
|
3616
|
+
fuelBoostMaker?: number,
|
|
3617
|
+
fuelBoostInsurance?: number
|
|
3563
3618
|
): Promise<TransactionInstruction> {
|
|
3564
3619
|
const spotMarketPublicKey = await getSpotMarketPublicKey(
|
|
3565
3620
|
this.program.programId,
|
|
@@ -3571,6 +3626,7 @@ export class AdminClient extends DriftClient {
|
|
|
3571
3626
|
fuelBoostBorrows || null,
|
|
3572
3627
|
fuelBoostTaker || null,
|
|
3573
3628
|
fuelBoostMaker || null,
|
|
3629
|
+
fuelBoostInsurance || null,
|
|
3574
3630
|
{
|
|
3575
3631
|
accounts: {
|
|
3576
3632
|
admin: this.isSubscribed
|
|
@@ -3629,6 +3685,62 @@ export class AdminClient extends DriftClient {
|
|
|
3629
3685
|
);
|
|
3630
3686
|
}
|
|
3631
3687
|
|
|
3688
|
+
public async initUserFuel(
|
|
3689
|
+
user: PublicKey,
|
|
3690
|
+
authority: PublicKey,
|
|
3691
|
+
fuelBonusDeposits?: number,
|
|
3692
|
+
fuelBonusBorrows?: number,
|
|
3693
|
+
fuelBonusTaker?: number,
|
|
3694
|
+
fuelBonusMaker?: number,
|
|
3695
|
+
fuelBonusInsurance?: number
|
|
3696
|
+
): Promise<TransactionSignature> {
|
|
3697
|
+
const updatePerpMarketFuelIx = await this.getInitUserFuelIx(
|
|
3698
|
+
user,
|
|
3699
|
+
authority,
|
|
3700
|
+
fuelBonusDeposits,
|
|
3701
|
+
fuelBonusBorrows,
|
|
3702
|
+
fuelBonusTaker,
|
|
3703
|
+
fuelBonusMaker,
|
|
3704
|
+
fuelBonusInsurance
|
|
3705
|
+
);
|
|
3706
|
+
|
|
3707
|
+
const tx = await this.buildTransaction(updatePerpMarketFuelIx);
|
|
3708
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3709
|
+
|
|
3710
|
+
return txSig;
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3713
|
+
public async getInitUserFuelIx(
|
|
3714
|
+
user: PublicKey,
|
|
3715
|
+
authority: PublicKey,
|
|
3716
|
+
fuelBonusDeposits?: number,
|
|
3717
|
+
fuelBonusBorrows?: number,
|
|
3718
|
+
fuelBonusTaker?: number,
|
|
3719
|
+
fuelBonusMaker?: number,
|
|
3720
|
+
fuelBonusInsurance?: number
|
|
3721
|
+
): Promise<TransactionInstruction> {
|
|
3722
|
+
const userStats = await getUserStatsAccountPublicKey(
|
|
3723
|
+
this.program.programId,
|
|
3724
|
+
authority
|
|
3725
|
+
);
|
|
3726
|
+
|
|
3727
|
+
return await this.program.instruction.initUserFuel(
|
|
3728
|
+
fuelBonusDeposits || null,
|
|
3729
|
+
fuelBonusBorrows || null,
|
|
3730
|
+
fuelBonusTaker || null,
|
|
3731
|
+
fuelBonusMaker || null,
|
|
3732
|
+
fuelBonusInsurance || null,
|
|
3733
|
+
{
|
|
3734
|
+
accounts: {
|
|
3735
|
+
admin: this.wallet.publicKey,
|
|
3736
|
+
state: await this.getStatePublicKey(),
|
|
3737
|
+
user,
|
|
3738
|
+
userStats,
|
|
3739
|
+
},
|
|
3740
|
+
}
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3632
3744
|
public async initializePythPullOracle(
|
|
3633
3745
|
feedId: string
|
|
3634
3746
|
): Promise<TransactionSignature> {
|
|
@@ -118,6 +118,19 @@ export class BankrunContextWrapper {
|
|
|
118
118
|
);
|
|
119
119
|
await this.context.setClock(newClock);
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
async setTimestamp(unix_timestamp: number): Promise<void> {
|
|
123
|
+
const currentClock = await this.context.banksClient.getClock();
|
|
124
|
+
const newUnixTimestamp = BigInt(unix_timestamp);
|
|
125
|
+
const newClock = new Clock(
|
|
126
|
+
currentClock.slot,
|
|
127
|
+
currentClock.epochStartTimestamp,
|
|
128
|
+
currentClock.epoch,
|
|
129
|
+
currentClock.leaderScheduleEpoch,
|
|
130
|
+
newUnixTimestamp
|
|
131
|
+
);
|
|
132
|
+
await this.context.setClock(newClock);
|
|
133
|
+
}
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
export class BankrunConnection {
|
|
@@ -90,6 +90,7 @@ export const ONE_HOUR = new BN(60 * 60);
|
|
|
90
90
|
export const ONE_YEAR = new BN(31536000);
|
|
91
91
|
|
|
92
92
|
export const QUOTE_SPOT_MARKET_INDEX = 0;
|
|
93
|
+
export const GOV_SPOT_MARKET_INDEX = 15;
|
|
93
94
|
|
|
94
95
|
export const LAMPORTS_PRECISION = new BN(LAMPORTS_PER_SOL);
|
|
95
96
|
export const LAMPORTS_EXP = new BN(Math.log10(LAMPORTS_PER_SOL));
|
|
@@ -107,3 +108,4 @@ export const SLOT_TIME_ESTIMATE_MS = 400;
|
|
|
107
108
|
export const DUST_POSITION_SIZE = QUOTE_PRECISION.divn(100); // Dust position is any position smaller than 1c
|
|
108
109
|
|
|
109
110
|
export const FUEL_WINDOW = new BN(60 * 60 * 24 * 28); // 28 days
|
|
111
|
+
export const FUEL_START_TS = new BN(1722384000); // unix timestamp
|