@drift-labs/sdk 2.97.0-beta.0 → 2.97.0-beta.10
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/README.md +11 -4
- package/VERSION +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +5 -1
- package/lib/adminClient.d.ts +6 -0
- package/lib/adminClient.js +53 -0
- package/lib/config.d.ts +1 -1
- package/lib/config.js +5 -3
- package/lib/constants/perpMarkets.js +20 -0
- package/lib/driftClient.d.ts +8 -1
- package/lib/driftClient.js +55 -4
- package/lib/idl/drift.json +247 -2
- package/lib/math/margin.d.ts +2 -2
- package/lib/math/margin.js +4 -4
- package/lib/math/market.d.ts +1 -1
- package/lib/math/market.js +15 -3
- package/lib/types.d.ts +11 -0
- package/lib/types.js +6 -1
- package/lib/user.d.ts +1 -0
- package/lib/user.js +12 -8
- package/package.json +1 -1
- package/src/addresses/pda.ts +9 -0
- package/src/adminClient.ts +114 -0
- package/src/config.ts +12 -3
- package/src/constants/perpMarkets.ts +20 -0
- package/src/driftClient.ts +132 -11
- package/src/idl/drift.json +247 -2
- package/src/math/margin.ts +8 -4
- package/src/math/market.ts +19 -3
- package/src/types.ts +9 -0
- package/src/user.ts +21 -8
package/README.md
CHANGED
|
@@ -19,13 +19,20 @@ npm i @drift-labs/sdk
|
|
|
19
19
|
|
|
20
20
|
## Getting Started
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
*Start here if you're integrating with Drift!*
|
|
23
23
|
|
|
24
|
-
- [API
|
|
24
|
+
- [Drift v2-teacher + API Docs](https://drift-labs.github.io/v2-teacher/)
|
|
25
|
+
- Docs and examples for using the SDK in Typescript and Python
|
|
26
|
+
- Useful concepts and examples when integrating Drift
|
|
27
|
+
- Docs for Drift's "Data API"
|
|
25
28
|
- [Typescript API docs](https://drift-labs.github.io/protocol-v2/sdk/)
|
|
26
|
-
-
|
|
29
|
+
- JSDoc automated documentation for the Drift v2 Typescript SDK
|
|
30
|
+
- [Drift docs](https://docs.drift.trade/)
|
|
31
|
+
- Comprehensive universal docs for Drift
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
The below is a light overview of using Solana and Drift's typescript sdk. If you want comprehensive docs with examples of how to integrate with Drift you should use the [v2-teacher docs](https://drift-labs.github.io/v2-teacher/).
|
|
29
36
|
|
|
30
37
|
### Setting up a wallet for your program
|
|
31
38
|
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.97.0-beta.
|
|
1
|
+
2.97.0-beta.10
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -26,3 +26,4 @@ export declare function getProtocolIfSharesTransferConfigPublicKey(programId: Pu
|
|
|
26
26
|
export declare function getPrelaunchOraclePublicKey(programId: PublicKey, marketIndex: number): PublicKey;
|
|
27
27
|
export declare function getPythPullOraclePublicKey(progarmId: PublicKey, feedId: Uint8Array): PublicKey;
|
|
28
28
|
export declare function getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
|
|
29
|
+
export declare function getHighLeverageModeConfigPublicKey(programId: PublicKey): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getTokenProgramForSpotMarket = 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.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
26
|
+
exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = 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.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
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -180,3 +180,7 @@ function getTokenProgramForSpotMarket(spotMarketAccount) {
|
|
|
180
180
|
return spl_token_1.TOKEN_PROGRAM_ID;
|
|
181
181
|
}
|
|
182
182
|
exports.getTokenProgramForSpotMarket = getTokenProgramForSpotMarket;
|
|
183
|
+
function getHighLeverageModeConfigPublicKey(programId) {
|
|
184
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('high_leverage_mode_config'))], programId)[0];
|
|
185
|
+
}
|
|
186
|
+
exports.getHighLeverageModeConfigPublicKey = getHighLeverageModeConfigPublicKey;
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
55
55
|
getUpdatePerpMarketTargetBaseAssetAmountPerLpIx(perpMarketIndex: number, targetBaseAssetAmountPerLP: number): Promise<TransactionInstruction>;
|
|
56
56
|
updatePerpMarketMarginRatio(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
57
57
|
getUpdatePerpMarketMarginRatioIx(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionInstruction>;
|
|
58
|
+
updatePerpMarketHighLeverageMarginRatio(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
59
|
+
getUpdatePerpMarketHighLeverageMarginRatioIx(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionInstruction>;
|
|
58
60
|
updatePerpMarketImfFactor(perpMarketIndex: number, imfFactor: number, unrealizedPnlImfFactor: number): Promise<TransactionSignature>;
|
|
59
61
|
getUpdatePerpMarketImfFactorIx(perpMarketIndex: number, imfFactor: number, unrealizedPnlImfFactor: number): Promise<TransactionInstruction>;
|
|
60
62
|
updatePerpMarketBaseSpread(perpMarketIndex: number, baseSpread: number): Promise<TransactionSignature>;
|
|
@@ -193,4 +195,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
193
195
|
getInitUserFuelIx(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionInstruction>;
|
|
194
196
|
initializePythPullOracle(feedId: string): Promise<TransactionSignature>;
|
|
195
197
|
getInitializePythPullOracleIx(feedId: string): Promise<TransactionInstruction>;
|
|
198
|
+
initializeHighLeverageModeConfig(maxUsers: number): Promise<TransactionSignature>;
|
|
199
|
+
getInitializeHighLeverageModeConfigIx(maxUsers: number): Promise<TransactionInstruction>;
|
|
200
|
+
updateUpdateHighLeverageModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
|
|
201
|
+
getUpdateHighLeverageModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
|
|
196
202
|
}
|
package/lib/adminClient.js
CHANGED
|
@@ -561,6 +561,23 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
561
561
|
},
|
|
562
562
|
});
|
|
563
563
|
}
|
|
564
|
+
async updatePerpMarketHighLeverageMarginRatio(perpMarketIndex, marginRatioInitial, marginRatioMaintenance) {
|
|
565
|
+
const updatePerpMarketHighLeverageMarginRatioIx = await this.getUpdatePerpMarketHighLeverageMarginRatioIx(perpMarketIndex, marginRatioInitial, marginRatioMaintenance);
|
|
566
|
+
const tx = await this.buildTransaction(updatePerpMarketHighLeverageMarginRatioIx);
|
|
567
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
568
|
+
return txSig;
|
|
569
|
+
}
|
|
570
|
+
async getUpdatePerpMarketHighLeverageMarginRatioIx(perpMarketIndex, marginRatioInitial, marginRatioMaintenance) {
|
|
571
|
+
return await this.program.instruction.updatePerpMarketHighLeverageMarginRatio(marginRatioInitial, marginRatioMaintenance, {
|
|
572
|
+
accounts: {
|
|
573
|
+
admin: this.isSubscribed
|
|
574
|
+
? this.getStateAccount().admin
|
|
575
|
+
: this.wallet.publicKey,
|
|
576
|
+
state: await this.getStatePublicKey(),
|
|
577
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
}
|
|
564
581
|
async updatePerpMarketImfFactor(perpMarketIndex, imfFactor, unrealizedPnlImfFactor) {
|
|
565
582
|
const updatePerpMarketImfFactorIx = await this.getUpdatePerpMarketImfFactorIx(perpMarketIndex, imfFactor, unrealizedPnlImfFactor);
|
|
566
583
|
const tx = await this.buildTransaction(updatePerpMarketImfFactorIx);
|
|
@@ -1769,5 +1786,41 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1769
1786
|
},
|
|
1770
1787
|
});
|
|
1771
1788
|
}
|
|
1789
|
+
async initializeHighLeverageModeConfig(maxUsers) {
|
|
1790
|
+
const initializeHighLeverageModeConfigIx = await this.getInitializeHighLeverageModeConfigIx(maxUsers);
|
|
1791
|
+
const tx = await this.buildTransaction(initializeHighLeverageModeConfigIx);
|
|
1792
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1793
|
+
return txSig;
|
|
1794
|
+
}
|
|
1795
|
+
async getInitializeHighLeverageModeConfigIx(maxUsers) {
|
|
1796
|
+
return await this.program.instruction.initializeHighLeverageModeConfig(maxUsers, {
|
|
1797
|
+
accounts: {
|
|
1798
|
+
admin: this.isSubscribed
|
|
1799
|
+
? this.getStateAccount().admin
|
|
1800
|
+
: this.wallet.publicKey,
|
|
1801
|
+
state: await this.getStatePublicKey(),
|
|
1802
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1803
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
1804
|
+
highLeverageModeConfig: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
|
|
1805
|
+
},
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
async updateUpdateHighLeverageModeConfig(maxUsers, reduceOnly) {
|
|
1809
|
+
const updateHighLeverageModeConfigIx = await this.getUpdateHighLeverageModeConfigIx(maxUsers, reduceOnly);
|
|
1810
|
+
const tx = await this.buildTransaction(updateHighLeverageModeConfigIx);
|
|
1811
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1812
|
+
return txSig;
|
|
1813
|
+
}
|
|
1814
|
+
async getUpdateHighLeverageModeConfigIx(maxUsers, reduceOnly) {
|
|
1815
|
+
return await this.program.instruction.updateHighLeverageModeConfig(maxUsers, reduceOnly, {
|
|
1816
|
+
accounts: {
|
|
1817
|
+
admin: this.isSubscribed
|
|
1818
|
+
? this.getStateAccount().admin
|
|
1819
|
+
: this.wallet.publicKey,
|
|
1820
|
+
state: await this.getStatePublicKey(),
|
|
1821
|
+
highLeverageModeConfig: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
|
|
1822
|
+
},
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1772
1825
|
}
|
|
1773
1826
|
exports.AdminClient = AdminClient;
|
package/lib/config.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const initialize: (props: {
|
|
|
43
43
|
env: DriftEnv;
|
|
44
44
|
overrideEnv?: Partial<DriftConfig>;
|
|
45
45
|
}) => DriftConfig;
|
|
46
|
-
export declare function getMarketsAndOraclesForSubscription(env: DriftEnv): {
|
|
46
|
+
export declare function getMarketsAndOraclesForSubscription(env: DriftEnv, perpMarkets?: PerpMarketConfig[], spotMarkets?: SpotMarketConfig[]): {
|
|
47
47
|
perpMarketIndexes: number[];
|
|
48
48
|
spotMarketIndexes: number[];
|
|
49
49
|
oracleInfos: OracleInfo[];
|
package/lib/config.js
CHANGED
|
@@ -66,18 +66,20 @@ const initialize = (props) => {
|
|
|
66
66
|
return currentConfig;
|
|
67
67
|
};
|
|
68
68
|
exports.initialize = initialize;
|
|
69
|
-
function getMarketsAndOraclesForSubscription(env) {
|
|
69
|
+
function getMarketsAndOraclesForSubscription(env, perpMarkets, spotMarkets) {
|
|
70
|
+
const perpMarketsToUse = (perpMarkets === null || perpMarkets === void 0 ? void 0 : perpMarkets.length) > 0 ? perpMarkets : perpMarkets_1.PerpMarkets[env];
|
|
71
|
+
const spotMarketsToUse = (spotMarkets === null || spotMarkets === void 0 ? void 0 : spotMarkets.length) > 0 ? spotMarkets : spotMarkets_1.SpotMarkets[env];
|
|
70
72
|
const perpMarketIndexes = [];
|
|
71
73
|
const spotMarketIndexes = [];
|
|
72
74
|
const oracleInfos = new Map();
|
|
73
|
-
for (const market of
|
|
75
|
+
for (const market of perpMarketsToUse) {
|
|
74
76
|
perpMarketIndexes.push(market.marketIndex);
|
|
75
77
|
oracleInfos.set(market.oracle.toString(), {
|
|
76
78
|
publicKey: market.oracle,
|
|
77
79
|
source: market.oracleSource,
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
|
-
for (const spotMarket of
|
|
82
|
+
for (const spotMarket of spotMarketsToUse) {
|
|
81
83
|
spotMarketIndexes.push(spotMarket.marketIndex);
|
|
82
84
|
oracleInfos.set(spotMarket.oracle.toString(), {
|
|
83
85
|
publicKey: spotMarket.oracle,
|
|
@@ -820,6 +820,26 @@ exports.MainnetPerpMarkets = [
|
|
|
820
820
|
launchTs: 1727965864000,
|
|
821
821
|
oracleSource: __1.OracleSource.Prelaunch,
|
|
822
822
|
},
|
|
823
|
+
{
|
|
824
|
+
fullName: 'DeBridge',
|
|
825
|
+
category: ['Bridge'],
|
|
826
|
+
symbol: 'DBR-PERP',
|
|
827
|
+
baseAssetSymbol: 'DBR',
|
|
828
|
+
marketIndex: 47,
|
|
829
|
+
oracle: new web3_js_1.PublicKey('AQzxePg2vY52Cw4di1j5xF7BqetNPxogqYPgDBL7HXWn'),
|
|
830
|
+
launchTs: 1728574493000,
|
|
831
|
+
oracleSource: __1.OracleSource.Prelaunch,
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
fullName: 'WLF-5B-1W',
|
|
835
|
+
category: ['Prediction'],
|
|
836
|
+
symbol: 'WLF-5B-1W-BET',
|
|
837
|
+
baseAssetSymbol: 'WLF-5B-1W',
|
|
838
|
+
marketIndex: 48,
|
|
839
|
+
oracle: new web3_js_1.PublicKey('7LpRfPaWR7cQqN7CMkCmZjEQpWyqso5LGuKCvDXH5ZAr'),
|
|
840
|
+
launchTs: 1728574493000,
|
|
841
|
+
oracleSource: __1.OracleSource.Prelaunch,
|
|
842
|
+
},
|
|
823
843
|
];
|
|
824
844
|
exports.PerpMarkets = {
|
|
825
845
|
devnet: exports.DevnetPerpMarkets,
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -354,7 +354,8 @@ export declare class DriftClient {
|
|
|
354
354
|
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
|
355
355
|
settleExpiredMarket(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
356
356
|
getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
357
|
-
settleExpiredMarketPoolsToRevenuePool(
|
|
357
|
+
settleExpiredMarketPoolsToRevenuePool(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
358
|
+
getSettleExpiredMarketPoolsToRevenuePoolIx(perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
358
359
|
cancelOrder(orderId?: number, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
359
360
|
getCancelOrderIx(orderId?: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
360
361
|
cancelOrderByUserId(userOrderId: number, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
@@ -490,6 +491,8 @@ export declare class DriftClient {
|
|
|
490
491
|
getForceCancelOrdersIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
491
492
|
updateUserIdle(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
492
493
|
getUpdateUserIdleIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
494
|
+
updateUserFuelBonus(userAccountPublicKey: PublicKey, user: UserAccount, userAuthority: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
495
|
+
getUpdateUserFuelBonusIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, userAuthority: PublicKey): Promise<TransactionInstruction>;
|
|
493
496
|
updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
494
497
|
getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
495
498
|
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
@@ -786,6 +789,10 @@ export declare class DriftClient {
|
|
|
786
789
|
getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, numSignatures?: number): Promise<TransactionInstruction | undefined>;
|
|
787
790
|
postSwitchboardOnDemandUpdate(feed: PublicKey, numSignatures?: number): Promise<TransactionSignature>;
|
|
788
791
|
private getBuildEncodedVaaIxs;
|
|
792
|
+
enableUserHighLeverageMode(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
793
|
+
getEnableHighLeverageModeIx(subAccountId: number): Promise<anchor.web3.TransactionInstruction>;
|
|
794
|
+
disableUserHighLeverageMode(user: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
795
|
+
getDisableHighLeverageModeIx(user: PublicKey): Promise<anchor.web3.TransactionInstruction>;
|
|
789
796
|
private handleSignedTransaction;
|
|
790
797
|
private handlePreSignedTransaction;
|
|
791
798
|
private isVersionedTransaction;
|
package/lib/driftClient.js
CHANGED
|
@@ -1761,10 +1761,14 @@ class DriftClient {
|
|
|
1761
1761
|
remainingAccounts,
|
|
1762
1762
|
});
|
|
1763
1763
|
}
|
|
1764
|
-
async settleExpiredMarketPoolsToRevenuePool(
|
|
1764
|
+
async settleExpiredMarketPoolsToRevenuePool(marketIndex, txParams) {
|
|
1765
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getSettleExpiredMarketPoolsToRevenuePoolIx(marketIndex), txParams), [], this.opts);
|
|
1766
|
+
return txSig;
|
|
1767
|
+
}
|
|
1768
|
+
async getSettleExpiredMarketPoolsToRevenuePoolIx(perpMarketIndex) {
|
|
1765
1769
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
1766
1770
|
const spotMarketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
1767
|
-
|
|
1771
|
+
return await this.program.instruction.settleExpiredMarketPoolsToRevenuePool({
|
|
1768
1772
|
accounts: {
|
|
1769
1773
|
state: await this.getStatePublicKey(),
|
|
1770
1774
|
admin: this.isSubscribed
|
|
@@ -1774,8 +1778,6 @@ class DriftClient {
|
|
|
1774
1778
|
perpMarket: perpMarketPublicKey,
|
|
1775
1779
|
},
|
|
1776
1780
|
});
|
|
1777
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
|
|
1778
|
-
return txSig;
|
|
1779
1781
|
}
|
|
1780
1782
|
async cancelOrder(orderId, txParams, subAccountId) {
|
|
1781
1783
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderIx(orderId, subAccountId), txParams), [], this.opts);
|
|
@@ -2710,6 +2712,25 @@ class DriftClient {
|
|
|
2710
2712
|
remainingAccounts,
|
|
2711
2713
|
});
|
|
2712
2714
|
}
|
|
2715
|
+
async updateUserFuelBonus(userAccountPublicKey, user, userAuthority, txParams) {
|
|
2716
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserFuelBonusIx(userAccountPublicKey, user, userAuthority), txParams), [], this.opts);
|
|
2717
|
+
return txSig;
|
|
2718
|
+
}
|
|
2719
|
+
async getUpdateUserFuelBonusIx(userAccountPublicKey, userAccount, userAuthority) {
|
|
2720
|
+
const userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAuthority);
|
|
2721
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
2722
|
+
userAccounts: [userAccount],
|
|
2723
|
+
});
|
|
2724
|
+
return await this.program.instruction.updateUserFuelBonus({
|
|
2725
|
+
accounts: {
|
|
2726
|
+
state: await this.getStatePublicKey(),
|
|
2727
|
+
user: userAccountPublicKey,
|
|
2728
|
+
userStats: userStatsAccountPublicKey,
|
|
2729
|
+
authority: this.wallet.publicKey,
|
|
2730
|
+
},
|
|
2731
|
+
remainingAccounts,
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2713
2734
|
async updateUserOpenOrdersCount(userAccountPublicKey, user, txParams, fillerPublicKey) {
|
|
2714
2735
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserOpenOrdersCountIx(userAccountPublicKey, user, fillerPublicKey), txParams), [], this.opts);
|
|
2715
2736
|
return txSig;
|
|
@@ -4233,6 +4254,36 @@ class DriftClient {
|
|
|
4233
4254
|
.instruction());
|
|
4234
4255
|
return [postIxs, encodedVaaKeypair];
|
|
4235
4256
|
}
|
|
4257
|
+
async enableUserHighLeverageMode(subAccountId, txParams) {
|
|
4258
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getEnableHighLeverageModeIx(subAccountId), txParams), [], this.opts);
|
|
4259
|
+
return txSig;
|
|
4260
|
+
}
|
|
4261
|
+
async getEnableHighLeverageModeIx(subAccountId) {
|
|
4262
|
+
const ix = await this.program.instruction.enableUserHighLeverageMode(subAccountId, {
|
|
4263
|
+
accounts: {
|
|
4264
|
+
state: await this.getStatePublicKey(),
|
|
4265
|
+
user: (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId),
|
|
4266
|
+
authority: this.wallet.publicKey,
|
|
4267
|
+
highLeverageModeConfig: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
|
|
4268
|
+
},
|
|
4269
|
+
});
|
|
4270
|
+
return ix;
|
|
4271
|
+
}
|
|
4272
|
+
async disableUserHighLeverageMode(user, txParams) {
|
|
4273
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getDisableHighLeverageModeIx(user), txParams), [], this.opts);
|
|
4274
|
+
return txSig;
|
|
4275
|
+
}
|
|
4276
|
+
async getDisableHighLeverageModeIx(user) {
|
|
4277
|
+
const ix = await this.program.instruction.disableUserHighLeverageMode({
|
|
4278
|
+
accounts: {
|
|
4279
|
+
state: await this.getStatePublicKey(),
|
|
4280
|
+
user,
|
|
4281
|
+
authority: this.wallet.publicKey,
|
|
4282
|
+
highLeverageModeConfig: (0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId),
|
|
4283
|
+
},
|
|
4284
|
+
});
|
|
4285
|
+
return ix;
|
|
4286
|
+
}
|
|
4236
4287
|
handleSignedTransaction(signedTxs) {
|
|
4237
4288
|
if (this.enableMetricsEvents && this.metricsEventEmitter) {
|
|
4238
4289
|
this.metricsEventEmitter.emit('txSigned', signedTxs);
|
package/lib/idl/drift.json
CHANGED
|
@@ -1283,6 +1283,37 @@
|
|
|
1283
1283
|
],
|
|
1284
1284
|
"args": []
|
|
1285
1285
|
},
|
|
1286
|
+
{
|
|
1287
|
+
"name": "enableUserHighLeverageMode",
|
|
1288
|
+
"accounts": [
|
|
1289
|
+
{
|
|
1290
|
+
"name": "state",
|
|
1291
|
+
"isMut": false,
|
|
1292
|
+
"isSigner": false
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
"name": "user",
|
|
1296
|
+
"isMut": true,
|
|
1297
|
+
"isSigner": false
|
|
1298
|
+
},
|
|
1299
|
+
{
|
|
1300
|
+
"name": "authority",
|
|
1301
|
+
"isMut": false,
|
|
1302
|
+
"isSigner": true
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
"name": "highLeverageModeConfig",
|
|
1306
|
+
"isMut": true,
|
|
1307
|
+
"isSigner": false
|
|
1308
|
+
}
|
|
1309
|
+
],
|
|
1310
|
+
"args": [
|
|
1311
|
+
{
|
|
1312
|
+
"name": "subAccountId",
|
|
1313
|
+
"type": "u16"
|
|
1314
|
+
}
|
|
1315
|
+
]
|
|
1316
|
+
},
|
|
1286
1317
|
{
|
|
1287
1318
|
"name": "fillPerpOrder",
|
|
1288
1319
|
"accounts": [
|
|
@@ -1498,6 +1529,58 @@
|
|
|
1498
1529
|
],
|
|
1499
1530
|
"args": []
|
|
1500
1531
|
},
|
|
1532
|
+
{
|
|
1533
|
+
"name": "disableUserHighLeverageMode",
|
|
1534
|
+
"accounts": [
|
|
1535
|
+
{
|
|
1536
|
+
"name": "state",
|
|
1537
|
+
"isMut": false,
|
|
1538
|
+
"isSigner": false
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
"name": "authority",
|
|
1542
|
+
"isMut": false,
|
|
1543
|
+
"isSigner": true
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
"name": "user",
|
|
1547
|
+
"isMut": true,
|
|
1548
|
+
"isSigner": false
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
"name": "highLeverageModeConfig",
|
|
1552
|
+
"isMut": true,
|
|
1553
|
+
"isSigner": false
|
|
1554
|
+
}
|
|
1555
|
+
],
|
|
1556
|
+
"args": []
|
|
1557
|
+
},
|
|
1558
|
+
{
|
|
1559
|
+
"name": "updateUserFuelBonus",
|
|
1560
|
+
"accounts": [
|
|
1561
|
+
{
|
|
1562
|
+
"name": "state",
|
|
1563
|
+
"isMut": false,
|
|
1564
|
+
"isSigner": false
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
"name": "authority",
|
|
1568
|
+
"isMut": false,
|
|
1569
|
+
"isSigner": true
|
|
1570
|
+
},
|
|
1571
|
+
{
|
|
1572
|
+
"name": "user",
|
|
1573
|
+
"isMut": true,
|
|
1574
|
+
"isSigner": false
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
"name": "userStats",
|
|
1578
|
+
"isMut": true,
|
|
1579
|
+
"isSigner": false
|
|
1580
|
+
}
|
|
1581
|
+
],
|
|
1582
|
+
"args": []
|
|
1583
|
+
},
|
|
1501
1584
|
{
|
|
1502
1585
|
"name": "updateUserOpenOrdersCount",
|
|
1503
1586
|
"accounts": [
|
|
@@ -3961,6 +4044,36 @@
|
|
|
3961
4044
|
}
|
|
3962
4045
|
]
|
|
3963
4046
|
},
|
|
4047
|
+
{
|
|
4048
|
+
"name": "updatePerpMarketHighLeverageMarginRatio",
|
|
4049
|
+
"accounts": [
|
|
4050
|
+
{
|
|
4051
|
+
"name": "admin",
|
|
4052
|
+
"isMut": false,
|
|
4053
|
+
"isSigner": true
|
|
4054
|
+
},
|
|
4055
|
+
{
|
|
4056
|
+
"name": "state",
|
|
4057
|
+
"isMut": false,
|
|
4058
|
+
"isSigner": false
|
|
4059
|
+
},
|
|
4060
|
+
{
|
|
4061
|
+
"name": "perpMarket",
|
|
4062
|
+
"isMut": true,
|
|
4063
|
+
"isSigner": false
|
|
4064
|
+
}
|
|
4065
|
+
],
|
|
4066
|
+
"args": [
|
|
4067
|
+
{
|
|
4068
|
+
"name": "marginRatioInitial",
|
|
4069
|
+
"type": "u16"
|
|
4070
|
+
},
|
|
4071
|
+
{
|
|
4072
|
+
"name": "marginRatioMaintenance",
|
|
4073
|
+
"type": "u16"
|
|
4074
|
+
}
|
|
4075
|
+
]
|
|
4076
|
+
},
|
|
3964
4077
|
{
|
|
3965
4078
|
"name": "updatePerpMarketFundingPeriod",
|
|
3966
4079
|
"accounts": [
|
|
@@ -5926,6 +6039,72 @@
|
|
|
5926
6039
|
}
|
|
5927
6040
|
}
|
|
5928
6041
|
]
|
|
6042
|
+
},
|
|
6043
|
+
{
|
|
6044
|
+
"name": "initializeHighLeverageModeConfig",
|
|
6045
|
+
"accounts": [
|
|
6046
|
+
{
|
|
6047
|
+
"name": "admin",
|
|
6048
|
+
"isMut": true,
|
|
6049
|
+
"isSigner": true
|
|
6050
|
+
},
|
|
6051
|
+
{
|
|
6052
|
+
"name": "highLeverageModeConfig",
|
|
6053
|
+
"isMut": true,
|
|
6054
|
+
"isSigner": false
|
|
6055
|
+
},
|
|
6056
|
+
{
|
|
6057
|
+
"name": "state",
|
|
6058
|
+
"isMut": false,
|
|
6059
|
+
"isSigner": false
|
|
6060
|
+
},
|
|
6061
|
+
{
|
|
6062
|
+
"name": "rent",
|
|
6063
|
+
"isMut": false,
|
|
6064
|
+
"isSigner": false
|
|
6065
|
+
},
|
|
6066
|
+
{
|
|
6067
|
+
"name": "systemProgram",
|
|
6068
|
+
"isMut": false,
|
|
6069
|
+
"isSigner": false
|
|
6070
|
+
}
|
|
6071
|
+
],
|
|
6072
|
+
"args": [
|
|
6073
|
+
{
|
|
6074
|
+
"name": "maxUsers",
|
|
6075
|
+
"type": "u32"
|
|
6076
|
+
}
|
|
6077
|
+
]
|
|
6078
|
+
},
|
|
6079
|
+
{
|
|
6080
|
+
"name": "updateHighLeverageModeConfig",
|
|
6081
|
+
"accounts": [
|
|
6082
|
+
{
|
|
6083
|
+
"name": "admin",
|
|
6084
|
+
"isMut": true,
|
|
6085
|
+
"isSigner": true
|
|
6086
|
+
},
|
|
6087
|
+
{
|
|
6088
|
+
"name": "highLeverageModeConfig",
|
|
6089
|
+
"isMut": true,
|
|
6090
|
+
"isSigner": false
|
|
6091
|
+
},
|
|
6092
|
+
{
|
|
6093
|
+
"name": "state",
|
|
6094
|
+
"isMut": false,
|
|
6095
|
+
"isSigner": false
|
|
6096
|
+
}
|
|
6097
|
+
],
|
|
6098
|
+
"args": [
|
|
6099
|
+
{
|
|
6100
|
+
"name": "maxUsers",
|
|
6101
|
+
"type": "u32"
|
|
6102
|
+
},
|
|
6103
|
+
{
|
|
6104
|
+
"name": "reduceOnly",
|
|
6105
|
+
"type": "bool"
|
|
6106
|
+
}
|
|
6107
|
+
]
|
|
5929
6108
|
}
|
|
5930
6109
|
],
|
|
5931
6110
|
"accounts": [
|
|
@@ -6132,6 +6311,35 @@
|
|
|
6132
6311
|
]
|
|
6133
6312
|
}
|
|
6134
6313
|
},
|
|
6314
|
+
{
|
|
6315
|
+
"name": "HighLeverageModeConfig",
|
|
6316
|
+
"type": {
|
|
6317
|
+
"kind": "struct",
|
|
6318
|
+
"fields": [
|
|
6319
|
+
{
|
|
6320
|
+
"name": "maxUsers",
|
|
6321
|
+
"type": "u32"
|
|
6322
|
+
},
|
|
6323
|
+
{
|
|
6324
|
+
"name": "currentUsers",
|
|
6325
|
+
"type": "u32"
|
|
6326
|
+
},
|
|
6327
|
+
{
|
|
6328
|
+
"name": "reduceOnly",
|
|
6329
|
+
"type": "u8"
|
|
6330
|
+
},
|
|
6331
|
+
{
|
|
6332
|
+
"name": "padding",
|
|
6333
|
+
"type": {
|
|
6334
|
+
"array": [
|
|
6335
|
+
"u8",
|
|
6336
|
+
31
|
|
6337
|
+
]
|
|
6338
|
+
}
|
|
6339
|
+
}
|
|
6340
|
+
]
|
|
6341
|
+
}
|
|
6342
|
+
},
|
|
6135
6343
|
{
|
|
6136
6344
|
"name": "InsuranceFundStake",
|
|
6137
6345
|
"type": {
|
|
@@ -6520,12 +6728,24 @@
|
|
|
6520
6728
|
],
|
|
6521
6729
|
"type": "u8"
|
|
6522
6730
|
},
|
|
6731
|
+
{
|
|
6732
|
+
"name": "padding1",
|
|
6733
|
+
"type": "u8"
|
|
6734
|
+
},
|
|
6735
|
+
{
|
|
6736
|
+
"name": "highLeverageMarginRatioInitial",
|
|
6737
|
+
"type": "u16"
|
|
6738
|
+
},
|
|
6739
|
+
{
|
|
6740
|
+
"name": "highLeverageMarginRatioMaintenance",
|
|
6741
|
+
"type": "u16"
|
|
6742
|
+
},
|
|
6523
6743
|
{
|
|
6524
6744
|
"name": "padding",
|
|
6525
6745
|
"type": {
|
|
6526
6746
|
"array": [
|
|
6527
6747
|
"u8",
|
|
6528
|
-
|
|
6748
|
+
38
|
|
6529
6749
|
]
|
|
6530
6750
|
}
|
|
6531
6751
|
}
|
|
@@ -7375,12 +7595,18 @@
|
|
|
7375
7595
|
],
|
|
7376
7596
|
"type": "bool"
|
|
7377
7597
|
},
|
|
7598
|
+
{
|
|
7599
|
+
"name": "marginMode",
|
|
7600
|
+
"type": {
|
|
7601
|
+
"defined": "MarginMode"
|
|
7602
|
+
}
|
|
7603
|
+
},
|
|
7378
7604
|
{
|
|
7379
7605
|
"name": "padding1",
|
|
7380
7606
|
"type": {
|
|
7381
7607
|
"array": [
|
|
7382
7608
|
"u8",
|
|
7383
|
-
|
|
7609
|
+
4
|
|
7384
7610
|
]
|
|
7385
7611
|
}
|
|
7386
7612
|
},
|
|
@@ -10633,6 +10859,20 @@
|
|
|
10633
10859
|
}
|
|
10634
10860
|
]
|
|
10635
10861
|
}
|
|
10862
|
+
},
|
|
10863
|
+
{
|
|
10864
|
+
"name": "MarginMode",
|
|
10865
|
+
"type": {
|
|
10866
|
+
"kind": "enum",
|
|
10867
|
+
"variants": [
|
|
10868
|
+
{
|
|
10869
|
+
"name": "Default"
|
|
10870
|
+
},
|
|
10871
|
+
{
|
|
10872
|
+
"name": "HighLeverage"
|
|
10873
|
+
}
|
|
10874
|
+
]
|
|
10875
|
+
}
|
|
10636
10876
|
}
|
|
10637
10877
|
],
|
|
10638
10878
|
"events": [
|
|
@@ -13126,6 +13366,11 @@
|
|
|
13126
13366
|
"code": 6289,
|
|
13127
13367
|
"name": "PlaceAndTakeOrderSuccessConditionFailed",
|
|
13128
13368
|
"msg": "Place and take order success condition failed"
|
|
13369
|
+
},
|
|
13370
|
+
{
|
|
13371
|
+
"code": 6290,
|
|
13372
|
+
"name": "InvalidHighLeverageModeConfig",
|
|
13373
|
+
"msg": "Invalid High Leverage Mode Config"
|
|
13129
13374
|
}
|
|
13130
13375
|
],
|
|
13131
13376
|
"metadata": {
|
package/lib/math/margin.d.ts
CHANGED
|
@@ -28,12 +28,12 @@ export declare function calculatePerpLiabilityValue(baseAssetAmount: BN, oracleP
|
|
|
28
28
|
* @param baseSize
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
export declare function calculateMarginUSDCRequiredForTrade(driftClient: DriftClient, targetMarketIndex: number, baseSize: BN, userMaxMarginRatio?: number): BN;
|
|
31
|
+
export declare function calculateMarginUSDCRequiredForTrade(driftClient: DriftClient, targetMarketIndex: number, baseSize: BN, userMaxMarginRatio?: number, userHighLeverageMode?: boolean): BN;
|
|
32
32
|
/**
|
|
33
33
|
* Similar to calculatetMarginUSDCRequiredForTrade, but calculates how much of a given collateral is required to cover the margin requirements for a given trade. Basically does the same thing as getMarginUSDCRequiredForTrade but also accounts for asset weight of the selected collateral.
|
|
34
34
|
*
|
|
35
35
|
* Returns collateral required in the precision of the target collateral market.
|
|
36
36
|
*/
|
|
37
|
-
export declare function calculateCollateralDepositRequiredForTrade(driftClient: DriftClient, targetMarketIndex: number, baseSize: BN, collateralIndex: number, userMaxMarginRatio?: number): BN;
|
|
37
|
+
export declare function calculateCollateralDepositRequiredForTrade(driftClient: DriftClient, targetMarketIndex: number, baseSize: BN, collateralIndex: number, userMaxMarginRatio?: number, userHighLeverageMode?: boolean): BN;
|
|
38
38
|
export declare function calculateCollateralValueOfDeposit(driftClient: DriftClient, collateralIndex: number, baseSize: BN): BN;
|
|
39
39
|
export declare function calculateLiquidationPrice(freeCollateral: BN, freeCollateralDelta: BN, oraclePrice: BN): BN;
|