@drift-labs/sdk 2.87.0-beta.0 → 2.87.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/VERSION +1 -1
- package/lib/addresses/pda.d.ts +2 -0
- package/lib/addresses/pda.js +9 -1
- package/lib/adminClient.d.ts +2 -0
- package/lib/adminClient.js +27 -4
- package/lib/bankrun/bankrunConnection.js +1 -1
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -0
- package/lib/constants/perpMarkets.js +12 -12
- package/lib/constants/spotMarkets.d.ts +1 -0
- package/lib/constants/spotMarkets.js +13 -3
- package/lib/dlob/orderBookLevels.d.ts +1 -1
- package/lib/driftClient.d.ts +15 -5
- package/lib/driftClient.js +155 -41
- package/lib/events/types.d.ts +3 -2
- package/lib/events/types.js +1 -0
- package/lib/factory/oracleClient.js +4 -0
- package/lib/idl/drift.json +147 -5
- package/lib/idl/openbook.json +3854 -0
- package/lib/idl/switchboard_on_demand_30.json +4383 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/math/spotMarket.d.ts +6 -0
- package/lib/math/spotMarket.js +16 -1
- package/lib/math/superStake.d.ts +3 -2
- package/lib/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
- package/lib/openbook/openbookV2FulfillmentConfigMap.js +17 -0
- package/lib/openbook/openbookV2Subscriber.d.ts +36 -0
- package/lib/openbook/openbookV2Subscriber.js +102 -0
- package/lib/oracles/switchboardOnDemandClient.d.ts +11 -0
- package/lib/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/types.d.ts +13 -0
- package/lib/types.js +1 -0
- package/package.json +6 -2
- package/src/addresses/pda.ts +10 -0
- package/src/adminClient.ts +47 -4
- package/src/bankrun/bankrunConnection.ts +2 -2
- package/src/config.ts +3 -0
- package/src/constants/perpMarkets.ts +12 -12
- package/src/constants/spotMarkets.ts +15 -3
- package/src/dlob/orderBookLevels.ts +1 -1
- package/src/driftClient.ts +229 -52
- package/src/events/types.ts +5 -1
- package/src/factory/oracleClient.ts +5 -0
- package/src/idl/drift.json +147 -5
- package/src/idl/switchboard_on_demand_30.json +4383 -0
- package/src/index.ts +2 -0
- package/src/math/spotMarket.ts +28 -2
- package/src/openbook/openbookV2FulfillmentConfigMap.ts +29 -0
- package/src/openbook/openbookV2Subscriber.ts +165 -0
- package/src/oracles/switchboardOnDemandClient.ts +56 -0
- package/src/types.ts +13 -0
- package/tests/ci/verifyConstants.ts +3 -6
- package/tests/subscriber/openbook.ts +58 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.87.0-beta.
|
|
1
|
+
2.87.0-beta.10
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BN } from '@coral-xyz/anchor';
|
|
4
|
+
import { SpotMarketAccount } from '..';
|
|
4
5
|
export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
6
|
export declare function getDriftStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
7
|
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<[PublicKey, number]>;
|
|
@@ -22,3 +23,4 @@ export declare function getReferrerNamePublicKeySync(programId: PublicKey, nameB
|
|
|
22
23
|
export declare function getProtocolIfSharesTransferConfigPublicKey(programId: PublicKey): PublicKey;
|
|
23
24
|
export declare function getPrelaunchOraclePublicKey(programId: PublicKey, marketIndex: number): PublicKey;
|
|
24
25
|
export declare function getPythPullOraclePublicKey(progarmId: PublicKey, feedId: Uint8Array): PublicKey;
|
|
26
|
+
export declare function getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -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.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.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
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.getSpotMarketPublicKey = 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
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
29
30
|
async function getDriftStateAccountPublicKeyAndNonce(programId) {
|
|
30
31
|
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('drift_state'))], programId);
|
|
31
32
|
}
|
|
@@ -158,3 +159,10 @@ function getPythPullOraclePublicKey(progarmId, feedId) {
|
|
|
158
159
|
], progarmId)[0];
|
|
159
160
|
}
|
|
160
161
|
exports.getPythPullOraclePublicKey = getPythPullOraclePublicKey;
|
|
162
|
+
function getTokenProgramForSpotMarket(spotMarketAccount) {
|
|
163
|
+
if (spotMarketAccount.tokenProgram === 1) {
|
|
164
|
+
return spl_token_1.TOKEN_2022_PROGRAM_ID;
|
|
165
|
+
}
|
|
166
|
+
return spl_token_1.TOKEN_PROGRAM_ID;
|
|
167
|
+
}
|
|
168
|
+
exports.getTokenProgramForSpotMarket = getTokenProgramForSpotMarket;
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
41
41
|
getResetPerpMarketAmmOracleTwapIx(perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
42
42
|
depositIntoPerpMarketFeePool(perpMarketIndex: number, amount: BN, sourceVault: PublicKey): Promise<TransactionSignature>;
|
|
43
43
|
getDepositIntoPerpMarketFeePoolIx(perpMarketIndex: number, amount: BN, sourceVault: PublicKey): Promise<TransactionInstruction>;
|
|
44
|
+
depositIntoSpotMarketVault(spotMarketIndex: number, amount: BN, sourceVault: PublicKey): Promise<TransactionSignature>;
|
|
45
|
+
getDepositIntoSpotMarketVaultIx(spotMarketIndex: number, amount: BN, sourceVault: PublicKey): Promise<TransactionInstruction>;
|
|
44
46
|
updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
|
|
45
47
|
getUpdateAdminIx(admin: PublicKey): Promise<TransactionInstruction>;
|
|
46
48
|
updatePerpMarketCurveUpdateIntensity(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
package/lib/adminClient.js
CHANGED
|
@@ -82,6 +82,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
82
82
|
const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
83
83
|
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
84
84
|
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
85
|
+
const tokenProgram = (await this.connection.getAccountInfo(mint)).owner;
|
|
85
86
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
86
87
|
const initializeIx = await this.program.instruction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, ifLiquidationFee, activeStatus, assetTier, scaleInitialAssetWeightStart, withdrawGuardThreshold, orderTickSize, orderStepSize, ifTotalFactor, nameBuffer, {
|
|
87
88
|
accounts: {
|
|
@@ -97,7 +98,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
97
98
|
oracle,
|
|
98
99
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
99
100
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
100
|
-
tokenProgram
|
|
101
|
+
tokenProgram,
|
|
101
102
|
},
|
|
102
103
|
});
|
|
103
104
|
return initializeIx;
|
|
@@ -432,6 +433,30 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
432
433
|
},
|
|
433
434
|
});
|
|
434
435
|
}
|
|
436
|
+
async depositIntoSpotMarketVault(spotMarketIndex, amount, sourceVault) {
|
|
437
|
+
const depositIntoPerpMarketFeePoolIx = await this.getDepositIntoSpotMarketVaultIx(spotMarketIndex, amount, sourceVault);
|
|
438
|
+
const tx = await this.buildTransaction(depositIntoPerpMarketFeePoolIx);
|
|
439
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
440
|
+
return txSig;
|
|
441
|
+
}
|
|
442
|
+
async getDepositIntoSpotMarketVaultIx(spotMarketIndex, amount, sourceVault) {
|
|
443
|
+
const spotMarket = this.getSpotMarketAccount(spotMarketIndex);
|
|
444
|
+
const remainingAccounts = [];
|
|
445
|
+
this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
|
|
446
|
+
const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
|
|
447
|
+
return await this.program.instruction.depositIntoSpotMarketVault(amount, {
|
|
448
|
+
accounts: {
|
|
449
|
+
admin: this.isSubscribed
|
|
450
|
+
? this.getStateAccount().admin
|
|
451
|
+
: this.wallet.publicKey,
|
|
452
|
+
state: await this.getStatePublicKey(),
|
|
453
|
+
sourceVault,
|
|
454
|
+
spotMarket: spotMarket.pubkey,
|
|
455
|
+
spotMarketVault: spotMarket.vault,
|
|
456
|
+
tokenProgram,
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
}
|
|
435
460
|
async updateAdmin(admin) {
|
|
436
461
|
const updateAdminIx = await this.getUpdateAdminIx(admin);
|
|
437
462
|
const tx = await this.buildTransaction(updateAdminIx);
|
|
@@ -484,9 +509,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
484
509
|
netUnsettledFundingPnl: netUnsettledFundingPnl !== null && netUnsettledFundingPnl !== void 0 ? netUnsettledFundingPnl : null,
|
|
485
510
|
}, {
|
|
486
511
|
accounts: {
|
|
487
|
-
admin: this.
|
|
488
|
-
? this.getStateAccount().admin
|
|
489
|
-
: this.wallet.publicKey,
|
|
512
|
+
admin: this.wallet.publicKey,
|
|
490
513
|
state: await this.getStatePublicKey(),
|
|
491
514
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
492
515
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX),
|
|
@@ -78,7 +78,7 @@ class BankrunConnection {
|
|
|
78
78
|
}
|
|
79
79
|
async getTokenAccount(publicKey) {
|
|
80
80
|
const info = await this.getAccountInfo(publicKey);
|
|
81
|
-
return (0, spl_token_1.unpackAccount)(publicKey, info,
|
|
81
|
+
return (0, spl_token_1.unpackAccount)(publicKey, info, info.owner);
|
|
82
82
|
}
|
|
83
83
|
async getMultipleAccountsInfo(publicKeys, _commitmentOrConfig) {
|
|
84
84
|
const accountInfos = [];
|
package/lib/config.d.ts
CHANGED
package/lib/config.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.configs = {
|
|
|
14
14
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
15
15
|
SERUM_V3: 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
|
|
16
16
|
PHOENIX: 'PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY',
|
|
17
|
+
OPENBOOK: 'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb',
|
|
17
18
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'DeEiGWfCMP9psnLGkxGrBBMEAW5Jv8bBGMN8DCtFRCyB',
|
|
18
19
|
PERP_MARKETS: perpMarkets_1.DevnetPerpMarkets,
|
|
19
20
|
SPOT_MARKETS: spotMarkets_1.DevnetSpotMarkets,
|
|
@@ -28,6 +29,7 @@ exports.configs = {
|
|
|
28
29
|
USDC_MINT_ADDRESS: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
29
30
|
SERUM_V3: 'srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX',
|
|
30
31
|
PHOENIX: 'PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY',
|
|
32
|
+
OPENBOOK: 'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb',
|
|
31
33
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'Cmvhycb6LQvvzaShGw4iDHRLzeSSryioAsU98DSSkMNa',
|
|
32
34
|
PERP_MARKETS: perpMarkets_1.MainnetPerpMarkets,
|
|
33
35
|
SPOT_MARKETS: spotMarkets_1.MainnetSpotMarkets,
|
|
@@ -137,15 +137,15 @@ exports.DevnetPerpMarkets = [
|
|
|
137
137
|
pythFeedId: '0x385f64d993f7b77d8182ed5003d97c60aa3361f3cecfe711544d2d59165e9bdf',
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
|
-
fullName: '
|
|
140
|
+
fullName: 'RENDER',
|
|
141
141
|
category: ['Infra'],
|
|
142
|
-
symbol: '
|
|
143
|
-
baseAssetSymbol: '
|
|
142
|
+
symbol: 'RENDER-PERP',
|
|
143
|
+
baseAssetSymbol: 'RENDER',
|
|
144
144
|
marketIndex: 12,
|
|
145
|
-
oracle: new web3_js_1.PublicKey('
|
|
145
|
+
oracle: new web3_js_1.PublicKey('8TQztfGcNjHGRusX4ejQQtPZs3Ypczt9jWF6pkgQMqUX'),
|
|
146
146
|
launchTs: 1687201081000,
|
|
147
147
|
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
148
|
-
pythFeedId: '
|
|
148
|
+
pythFeedId: '0x3d4a2bd9535be6ce8059d75eadeba507b043257321aa544717c56fa19b49e35d',
|
|
149
149
|
},
|
|
150
150
|
{
|
|
151
151
|
fullName: 'XRP',
|
|
@@ -263,9 +263,9 @@ exports.DevnetPerpMarkets = [
|
|
|
263
263
|
symbol: 'W-PERP',
|
|
264
264
|
baseAssetSymbol: 'W',
|
|
265
265
|
marketIndex: 23,
|
|
266
|
-
oracle: new web3_js_1.PublicKey('
|
|
266
|
+
oracle: new web3_js_1.PublicKey('4iCi4DvXrubHQne8jzbMaWL3pd7v1Fip8iTe4H9vHNXB'),
|
|
267
267
|
launchTs: 1709852537000,
|
|
268
|
-
oracleSource: __1.OracleSource.
|
|
268
|
+
oracleSource: __1.OracleSource.SWITCHBOARD_ON_DEMAND,
|
|
269
269
|
pythFeedId: '0xeff7446475e218517566ea99e72a4abec2e1bd8498b43b7d8331e29dcb059389',
|
|
270
270
|
},
|
|
271
271
|
{
|
|
@@ -425,15 +425,15 @@ exports.MainnetPerpMarkets = [
|
|
|
425
425
|
pythFeedId: '0x385f64d993f7b77d8182ed5003d97c60aa3361f3cecfe711544d2d59165e9bdf',
|
|
426
426
|
},
|
|
427
427
|
{
|
|
428
|
-
fullName: '
|
|
428
|
+
fullName: 'RENDER',
|
|
429
429
|
category: ['Infra', 'Solana'],
|
|
430
|
-
symbol: '
|
|
431
|
-
baseAssetSymbol: '
|
|
430
|
+
symbol: 'RENDER-PERP',
|
|
431
|
+
baseAssetSymbol: 'RENDER',
|
|
432
432
|
marketIndex: 12,
|
|
433
|
-
oracle: new web3_js_1.PublicKey('
|
|
433
|
+
oracle: new web3_js_1.PublicKey('8TQztfGcNjHGRusX4ejQQtPZs3Ypczt9jWF6pkgQMqUX'),
|
|
434
434
|
launchTs: 1687201081000,
|
|
435
435
|
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
436
|
-
pythFeedId: '
|
|
436
|
+
pythFeedId: '0x3d4a2bd9535be6ce8059d75eadeba507b043257321aa544717c56fa19b49e35d',
|
|
437
437
|
},
|
|
438
438
|
{
|
|
439
439
|
fullName: 'XRP',
|
|
@@ -39,6 +39,16 @@ exports.DevnetSpotMarkets = [
|
|
|
39
39
|
serumMarket: new web3_js_1.PublicKey('AGsmbVu3MS9u68GEYABWosQQCZwmLcBHu4pWEuBYH7Za'),
|
|
40
40
|
pythFeedId: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
symbol: 'PYUSD',
|
|
44
|
+
marketIndex: 3,
|
|
45
|
+
oracle: new web3_js_1.PublicKey('HpMoKp3TCd3QT4MWYUKk2zCBwmhr5Df45fB6wdxYqEeh'),
|
|
46
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
47
|
+
mint: new web3_js_1.PublicKey('GLfF72ZCUnS6N9iDJw8kedHzd6WFVf3VbpwdKKy76FRk'),
|
|
48
|
+
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
49
|
+
precisionExp: numericConstants_1.SIX,
|
|
50
|
+
pythFeedId: '0xc1da1b73d7f01e7ddd54b3766cf7fcd644395ad14f70aa706ec5384c59e76692',
|
|
51
|
+
},
|
|
42
52
|
];
|
|
43
53
|
exports.MainnetSpotMarkets = [
|
|
44
54
|
{
|
|
@@ -180,16 +190,16 @@ exports.MainnetSpotMarkets = [
|
|
|
180
190
|
pythFeedId: '0x0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996',
|
|
181
191
|
},
|
|
182
192
|
{
|
|
183
|
-
symbol: '
|
|
193
|
+
symbol: 'RENDER',
|
|
184
194
|
marketIndex: 12,
|
|
185
|
-
oracle: new web3_js_1.PublicKey('
|
|
195
|
+
oracle: new web3_js_1.PublicKey('8TQztfGcNjHGRusX4ejQQtPZs3Ypczt9jWF6pkgQMqUX'),
|
|
186
196
|
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
187
197
|
mint: new web3_js_1.PublicKey('rndrizKT3MK1iimdxRdWabcF7Zg7AR5T4nud4EkHBof'),
|
|
188
198
|
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
189
199
|
precisionExp: numericConstants_1.EIGHT,
|
|
190
200
|
serumMarket: new web3_js_1.PublicKey('2m7ZLEKtxWF29727DSb5D91erpXPUY1bqhRWRC3wQX7u'),
|
|
191
201
|
launchTs: 1708964021000,
|
|
192
|
-
pythFeedId: '
|
|
202
|
+
pythFeedId: '0x3d4a2bd9535be6ce8059d75eadeba507b043257321aa544717c56fa19b49e35d',
|
|
193
203
|
},
|
|
194
204
|
{
|
|
195
205
|
symbol: 'W',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { BN, DLOBNode, OraclePriceData, PerpMarketAccount } from '..';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
type liquiditySource = 'serum' | 'vamm' | 'dlob' | 'phoenix';
|
|
4
|
+
type liquiditySource = 'serum' | 'vamm' | 'dlob' | 'phoenix' | 'openbook';
|
|
5
5
|
export type L2Level = {
|
|
6
6
|
price: BN;
|
|
7
7
|
size: BN;
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
5
|
+
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
5
6
|
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord, OpenbookV2FulfillmentConfigAccount } from './types';
|
|
6
7
|
import * as anchor from '@coral-xyz/anchor';
|
|
7
8
|
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
@@ -65,6 +66,8 @@ export declare class DriftClient {
|
|
|
65
66
|
txHandler: TxHandler;
|
|
66
67
|
receiverProgram?: Program<PythSolanaReceiver>;
|
|
67
68
|
wormholeProgram?: Program<WormholeCoreBridgeSolana>;
|
|
69
|
+
sbOnDemandProgram?: Program30<Idl30>;
|
|
70
|
+
sbProgramFeedConfigs?: Map<string, any>;
|
|
68
71
|
get isSubscribed(): boolean;
|
|
69
72
|
set isSubscribed(val: boolean);
|
|
70
73
|
constructor(config: DriftClientConfig);
|
|
@@ -227,8 +230,8 @@ export declare class DriftClient {
|
|
|
227
230
|
* @param useNative
|
|
228
231
|
*/
|
|
229
232
|
getAssociatedTokenAccount(marketIndex: number, useNative?: boolean): Promise<PublicKey>;
|
|
230
|
-
createAssociatedTokenAccountIdempotentInstruction(account: PublicKey, payer: PublicKey, owner: PublicKey, mint: PublicKey): TransactionInstruction;
|
|
231
|
-
createDepositTxn(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, txParams?: TxParams): Promise<
|
|
233
|
+
createAssociatedTokenAccountIdempotentInstruction(account: PublicKey, payer: PublicKey, owner: PublicKey, mint: PublicKey, tokenProgram?: anchor.web3.PublicKey): TransactionInstruction;
|
|
234
|
+
createDepositTxn(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, txParams?: TxParams): Promise<VersionedTransaction | Transaction>;
|
|
232
235
|
/**
|
|
233
236
|
* Deposit funds into the given spot market
|
|
234
237
|
*
|
|
@@ -247,6 +250,8 @@ export declare class DriftClient {
|
|
|
247
250
|
signers: Signer[];
|
|
248
251
|
pubkey: PublicKey;
|
|
249
252
|
}>;
|
|
253
|
+
getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
|
|
254
|
+
addTokenMintToRemainingAccounts(spotMarketAccount: SpotMarketAccount, remainingAccounts: AccountMeta[]): void;
|
|
250
255
|
getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
|
|
251
256
|
createInitializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number): Promise<[Transaction | VersionedTransaction, PublicKey]>;
|
|
252
257
|
/**
|
|
@@ -636,6 +641,8 @@ export declare class DriftClient {
|
|
|
636
641
|
settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
|
|
637
642
|
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
|
|
638
643
|
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
|
|
644
|
+
liquidatePerpWithFill(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
|
|
645
|
+
getLiquidatePerpWithFillIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
|
|
639
646
|
liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
|
|
640
647
|
getLiquidateSpotIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
|
|
641
648
|
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN, txParams?: TxParams, liquidatorSubAccountId?: number): Promise<TransactionSignature>;
|
|
@@ -659,7 +666,7 @@ export declare class DriftClient {
|
|
|
659
666
|
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
660
667
|
initializeInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
661
668
|
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
662
|
-
getAddInsuranceFundStakeIx(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey
|
|
669
|
+
getAddInsuranceFundStakeIx(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
663
670
|
/**
|
|
664
671
|
* Add to an insurance fund stake and optionally initialize the account
|
|
665
672
|
*/
|
|
@@ -686,8 +693,8 @@ export declare class DriftClient {
|
|
|
686
693
|
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
687
694
|
cancelRequestRemoveInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
688
695
|
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
689
|
-
settleRevenueToInsuranceFund(spotMarketIndex: number,
|
|
690
|
-
getSettleRevenueToInsuranceFundIx(spotMarketIndex: number
|
|
696
|
+
settleRevenueToInsuranceFund(spotMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
697
|
+
getSettleRevenueToInsuranceFundIx(spotMarketIndex: number): Promise<TransactionInstruction>;
|
|
691
698
|
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
692
699
|
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
693
700
|
getDepositIntoSpotMarketRevenuePoolIx(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
@@ -714,6 +721,7 @@ export declare class DriftClient {
|
|
|
714
721
|
marketType: MarketType;
|
|
715
722
|
} | undefined;
|
|
716
723
|
getReceiverProgram(): Program<PythSolanaReceiver>;
|
|
724
|
+
getSwitchboardOnDemandProgram(): Program30<Idl30>;
|
|
717
725
|
postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
718
726
|
postMultiPythPullOracleUpdatesAtomic(vaaString: string, feedIds: string[]): Promise<TransactionSignature>;
|
|
719
727
|
getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedIds: string | string[], numSignatures?: number): Promise<TransactionInstruction[]>;
|
|
@@ -725,6 +733,8 @@ export declare class DriftClient {
|
|
|
725
733
|
proof: number[][];
|
|
726
734
|
};
|
|
727
735
|
}, feedId: string, encodedVaaAddress: PublicKey): Promise<TransactionInstruction>;
|
|
736
|
+
getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, numSignatures?: number): Promise<TransactionInstruction | undefined>;
|
|
737
|
+
postSwitchboardOnDemandUpdate(feed: PublicKey, numSignatures?: number): Promise<TransactionSignature>;
|
|
728
738
|
private getBuildEncodedVaaIxs;
|
|
729
739
|
private handleSignedTransaction;
|
|
730
740
|
private handlePreSignedTransaction;
|