@drift-labs/sdk 2.124.0-beta.12 → 2.124.0-beta.13

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 CHANGED
@@ -1 +1 @@
1
- 2.124.0-beta.12
1
+ 2.124.0-beta.13
@@ -32,3 +32,4 @@ export declare function getPythLazerOraclePublicKey(progarmId: PublicKey, feedId
32
32
  export declare function getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
33
33
  export declare function getHighLeverageModeConfigPublicKey(programId: PublicKey): PublicKey;
34
34
  export declare function getProtectedMakerModeConfigPublicKey(programId: PublicKey): PublicKey;
35
+ export declare function getIfRebalanceConfigPublicKey(programId: PublicKey, inMarketIndex: number, outMarketIndex: number): PublicKey;
@@ -23,9 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSignedMsgWsDelegatesAccountPublicKey = exports.getSignedMsgUserAccountPublicKey = exports.getFuelOverflowAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getIfRebalanceConfigPublicKey = exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSignedMsgWsDelegatesAccountPublicKey = exports.getSignedMsgUserAccountPublicKey = exports.getFuelOverflowAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
+ const anchor_1 = require("@coral-xyz/anchor");
29
30
  const spl_token_1 = require("@solana/spl-token");
30
31
  async function getDriftStateAccountPublicKeyAndNonce(programId) {
31
32
  return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('drift_state'))], programId);
@@ -222,3 +223,11 @@ function getProtectedMakerModeConfigPublicKey(programId) {
222
223
  ], programId)[0];
223
224
  }
224
225
  exports.getProtectedMakerModeConfigPublicKey = getProtectedMakerModeConfigPublicKey;
226
+ function getIfRebalanceConfigPublicKey(programId, inMarketIndex, outMarketIndex) {
227
+ return web3_js_1.PublicKey.findProgramAddressSync([
228
+ Buffer.from(anchor.utils.bytes.utf8.encode('if_rebalance_config')),
229
+ new anchor_1.BN(inMarketIndex).toArrayLike(Buffer, 'le', 2),
230
+ new anchor_1.BN(outMarketIndex).toArrayLike(Buffer, 'le', 2),
231
+ ], programId)[0];
232
+ }
233
+ exports.getIfRebalanceConfigPublicKey = getIfRebalanceConfigPublicKey;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
3
- import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
3
+ import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus, IfRebalanceConfigParams } from './types';
4
4
  import { BN } from '@coral-xyz/anchor';
5
5
  import { DriftClient } from './driftClient';
6
6
  export declare class AdminClient extends DriftClient {
@@ -183,6 +183,8 @@ export declare class AdminClient extends DriftClient {
183
183
  getInitializeProtocolIfSharesTransferConfigIx(): Promise<TransactionInstruction>;
184
184
  updateProtocolIfSharesTransferConfig(whitelistedSigners?: PublicKey[], maxTransferPerEpoch?: BN): Promise<TransactionSignature>;
185
185
  getUpdateProtocolIfSharesTransferConfigIx(whitelistedSigners?: PublicKey[], maxTransferPerEpoch?: BN): Promise<TransactionInstruction>;
186
+ transferProtocolIfSharesToRevenuePool(outMarketIndex: number, inMarketIndex: number, amount: BN): Promise<TransactionSignature>;
187
+ getTransferProtocolIfSharesToRevenuePoolIx(outMarketIndex: number, inMarketIndex: number, amount: BN): Promise<TransactionInstruction>;
186
188
  initializePrelaunchOracle(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionSignature>;
187
189
  getInitializePrelaunchOracleIx(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionInstruction>;
188
190
  updatePrelaunchOracleParams(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionSignature>;
@@ -199,6 +201,8 @@ export declare class AdminClient extends DriftClient {
199
201
  getUpdatePerpMarketAmmSpreadAdjustmentIx(perpMarketIndex: number, ammSpreadAdjustment: number): Promise<TransactionInstruction>;
200
202
  updatePerpMarketProtectedMakerParams(perpMarketIndex: number, protectedMakerLimitPriceDivisor?: number, protectedMakerDynamicDivisor?: number): Promise<TransactionSignature>;
201
203
  getUpdatePerpMarketProtectedMakerParamsIx(perpMarketIndex: number, protectedMakerLimitPriceDivisor?: number, protectedMakerDynamicDivisor?: number): Promise<TransactionInstruction>;
204
+ initializeIfRebalanceConfig(params: IfRebalanceConfigParams): Promise<TransactionSignature>;
205
+ getInitializeIfRebalanceConfigIx(params: IfRebalanceConfigParams): Promise<TransactionInstruction>;
202
206
  initUserFuel(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionSignature>;
203
207
  getInitUserFuelIx(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionInstruction>;
204
208
  /**
@@ -1666,6 +1666,30 @@ class AdminClient extends driftClient_1.DriftClient {
1666
1666
  },
1667
1667
  });
1668
1668
  }
1669
+ async transferProtocolIfSharesToRevenuePool(outMarketIndex, inMarketIndex, amount) {
1670
+ const transferProtocolIfSharesToRevenuePoolIx = await this.getTransferProtocolIfSharesToRevenuePoolIx(outMarketIndex, inMarketIndex, amount);
1671
+ const tx = await this.buildTransaction(transferProtocolIfSharesToRevenuePoolIx);
1672
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1673
+ return txSig;
1674
+ }
1675
+ async getTransferProtocolIfSharesToRevenuePoolIx(outMarketIndex, inMarketIndex, amount) {
1676
+ const remainingAccounts = await this.getRemainingAccounts({
1677
+ userAccounts: [],
1678
+ writableSpotMarketIndexes: [outMarketIndex],
1679
+ });
1680
+ return await this.program.instruction.transferProtocolIfSharesToRevenuePool(outMarketIndex, amount, {
1681
+ accounts: {
1682
+ authority: this.wallet.publicKey,
1683
+ state: await this.getStatePublicKey(),
1684
+ insuranceFundVault: await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, outMarketIndex),
1685
+ spotMarketVault: await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, outMarketIndex),
1686
+ ifRebalanceConfig: await (0, pda_1.getIfRebalanceConfigPublicKey)(this.program.programId, inMarketIndex, outMarketIndex),
1687
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1688
+ driftSigner: this.getStateAccount().signer,
1689
+ },
1690
+ remainingAccounts,
1691
+ });
1692
+ }
1669
1693
  async initializePrelaunchOracle(perpMarketIndex, price, maxPrice) {
1670
1694
  const initializePrelaunchOracleIx = await this.getInitializePrelaunchOracleIx(perpMarketIndex, price, maxPrice);
1671
1695
  const tx = await this.buildTransaction(initializePrelaunchOracleIx);
@@ -1828,6 +1852,25 @@ class AdminClient extends driftClient_1.DriftClient {
1828
1852
  },
1829
1853
  });
1830
1854
  }
1855
+ async initializeIfRebalanceConfig(params) {
1856
+ const initializeIfRebalanceConfigIx = await this.getInitializeIfRebalanceConfigIx(params);
1857
+ const tx = await this.buildTransaction(initializeIfRebalanceConfigIx);
1858
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1859
+ return txSig;
1860
+ }
1861
+ async getInitializeIfRebalanceConfigIx(params) {
1862
+ return await this.program.instruction.initializeIfRebalanceConfig(params, {
1863
+ accounts: {
1864
+ admin: this.isSubscribed
1865
+ ? this.getStateAccount().admin
1866
+ : this.wallet.publicKey,
1867
+ state: await this.getStatePublicKey(),
1868
+ ifRebalanceConfig: await (0, pda_1.getIfRebalanceConfigPublicKey)(this.program.programId, params.inMarketIndex, params.outMarketIndex),
1869
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1870
+ systemProgram: anchor.web3.SystemProgram.programId,
1871
+ },
1872
+ });
1873
+ }
1831
1874
  async initUserFuel(user, authority, fuelBonusDeposits, fuelBonusBorrows, fuelBonusTaker, fuelBonusMaker, fuelBonusInsurance) {
1832
1875
  const updatePerpMarketFuelIx = await this.getInitUserFuelIx(user, authority, fuelBonusDeposits, fuelBonusBorrows, fuelBonusTaker, fuelBonusMaker, fuelBonusInsurance);
1833
1876
  const tx = await this.buildTransaction(updatePerpMarketFuelIx);
@@ -795,6 +795,16 @@ export declare class DriftClient {
795
795
  beginSwapIx: TransactionInstruction;
796
796
  endSwapIx: TransactionInstruction;
797
797
  }>;
798
+ getInsuranceFundSwapIx({ inMarketIndex, outMarketIndex, amountIn, inTokenAccount, outTokenAccount, }: {
799
+ inMarketIndex: number;
800
+ outMarketIndex: number;
801
+ amountIn: BN;
802
+ inTokenAccount: PublicKey;
803
+ outTokenAccount: PublicKey;
804
+ }): Promise<{
805
+ beginSwapIx: TransactionInstruction;
806
+ endSwapIx: TransactionInstruction;
807
+ }>;
798
808
  liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
799
809
  getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
800
810
  liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
@@ -4101,6 +4101,46 @@ class DriftClient {
4101
4101
  });
4102
4102
  return { beginSwapIx, endSwapIx };
4103
4103
  }
4104
+ async getInsuranceFundSwapIx({ inMarketIndex, outMarketIndex, amountIn, inTokenAccount, outTokenAccount, }) {
4105
+ const remainingAccounts = await this.getRemainingAccounts({
4106
+ userAccounts: [],
4107
+ writableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
4108
+ });
4109
+ const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
4110
+ const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
4111
+ const ifRebalanceConfig = (0, pda_1.getIfRebalanceConfigPublicKey)(this.program.programId, inMarketIndex, outMarketIndex);
4112
+ const beginSwapIx = await this.program.instruction.beginInsuranceFundSwap(inMarketIndex, outMarketIndex, amountIn, {
4113
+ accounts: {
4114
+ state: await this.getStatePublicKey(),
4115
+ authority: this.wallet.publicKey,
4116
+ outInsuranceFundVault: outSpotMarket.insuranceFund.vault,
4117
+ inInsuranceFundVault: inSpotMarket.insuranceFund.vault,
4118
+ outTokenAccount,
4119
+ inTokenAccount,
4120
+ ifRebalanceConfig: ifRebalanceConfig,
4121
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4122
+ driftSigner: this.getStateAccount().signer,
4123
+ instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
4124
+ },
4125
+ remainingAccounts,
4126
+ });
4127
+ const endSwapIx = await this.program.instruction.endInsuranceFundSwap(inMarketIndex, outMarketIndex, {
4128
+ accounts: {
4129
+ state: await this.getStatePublicKey(),
4130
+ authority: this.wallet.publicKey,
4131
+ outInsuranceFundVault: outSpotMarket.insuranceFund.vault,
4132
+ inInsuranceFundVault: inSpotMarket.insuranceFund.vault,
4133
+ outTokenAccount,
4134
+ inTokenAccount,
4135
+ ifRebalanceConfig: ifRebalanceConfig,
4136
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4137
+ driftSigner: this.getStateAccount().signer,
4138
+ instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
4139
+ },
4140
+ remainingAccounts,
4141
+ });
4142
+ return { beginSwapIx, endSwapIx };
4143
+ }
4104
4144
  async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
4105
4145
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
4106
4146
  this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SignedMsgOrderRecord, DeleteUserRecord, FuelSweepRecord, FuelSeasonRecord } from '../index';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SignedMsgOrderRecord, DeleteUserRecord, FuelSweepRecord, FuelSeasonRecord, InsuranceFundSwapRecord, TransferProtocolIfSharesToRevenuePoolRecord } from '../index';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -45,9 +45,11 @@ export type EventMap = {
45
45
  DeleteUserRecord: Event<DeleteUserRecord>;
46
46
  FuelSweepRecord: Event<FuelSweepRecord>;
47
47
  FuelSeasonRecord: Event<FuelSeasonRecord>;
48
+ InsuranceFundSwapRecord: Event<InsuranceFundSwapRecord>;
49
+ TransferProtocolIfSharesToRevenuePoolRecord: Event<TransferProtocolIfSharesToRevenuePoolRecord>;
48
50
  };
49
51
  export type EventType = keyof EventMap;
50
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SignedMsgOrderRecord> | Event<DeleteUserRecord> | Event<FuelSweepRecord> | Event<FuelSeasonRecord>;
52
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SignedMsgOrderRecord> | Event<DeleteUserRecord> | Event<FuelSweepRecord> | Event<FuelSeasonRecord> | Event<InsuranceFundSwapRecord> | Event<TransferProtocolIfSharesToRevenuePoolRecord>;
51
53
  export interface EventSubscriberEvents {
52
54
  newEvent: (event: WrappedEvent<EventType>) => void;
53
55
  }
@@ -22,6 +22,8 @@ exports.DefaultEventSubscriptionOptions = {
22
22
  'DeleteUserRecord',
23
23
  'FuelSweepRecord',
24
24
  'FuelSeasonRecord',
25
+ 'InsuranceFundSwapRecord',
26
+ 'TransferProtocolIfSharesToRevenuePoolRecord',
25
27
  ],
26
28
  maxEventsPerType: 4096,
27
29
  orderBy: 'blockchain',