@drift-labs/sdk 2.25.4 → 2.26.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/examples/phoenix.ts +40 -0
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +5 -4
- package/lib/accounts/pollingUserAccountSubscriber.js +35 -48
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -4
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +30 -47
- package/lib/accounts/types.d.ts +2 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketAccountSubscriber.js +4 -3
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/adminClient.d.ts +1 -0
- package/lib/adminClient.js +20 -0
- package/lib/dlob/DLOBApiClient.d.ts +14 -0
- package/lib/dlob/DLOBApiClient.js +34 -0
- package/lib/dlob/DLOBSubscriber.d.ts +19 -0
- package/lib/dlob/DLOBSubscriber.js +42 -0
- package/lib/dlob/types.d.ts +16 -0
- package/lib/dlob/types.js +2 -0
- package/lib/driftClient.d.ts +13 -10
- package/lib/driftClient.js +124 -28
- package/lib/examples/loadDlob.js +2 -4
- package/lib/idl/drift.json +264 -82
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/phoenix/phoenixSubscriber.d.ts +34 -0
- package/lib/phoenix/phoenixSubscriber.js +79 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/tx/retryTxSender.d.ts +2 -1
- package/lib/tx/retryTxSender.js +5 -1
- package/lib/tx/types.d.ts +4 -1
- package/lib/types.d.ts +11 -0
- package/lib/userMap/userMap.d.ts +17 -6
- package/lib/userMap/userMap.js +74 -46
- package/lib/userMap/userStatsMap.d.ts +6 -3
- package/lib/userMap/userStatsMap.js +30 -30
- package/package.json +2 -1
- package/src/accounts/pollingUserAccountSubscriber.ts +51 -63
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +46 -62
- package/src/accounts/types.ts +2 -1
- package/src/accounts/webSocketAccountSubscriber.ts +4 -3
- package/src/accounts/webSocketUserAccountSubscriber.ts +10 -0
- package/src/addresses/pda.ts +13 -0
- package/src/adminClient.ts +34 -0
- package/src/dlob/DLOBApiClient.ts +37 -0
- package/src/dlob/DLOBSubscriber.ts +57 -0
- package/src/dlob/types.ts +20 -0
- package/src/driftClient.ts +216 -59
- package/src/examples/loadDlob.ts +2 -4
- package/src/idl/drift.json +264 -82
- package/src/index.ts +4 -0
- package/src/phoenix/phoenixFulfillmentConfigMap.ts +26 -0
- package/src/phoenix/phoenixSubscriber.ts +156 -0
- package/src/slot/SlotSubscriber.ts +4 -0
- package/src/tx/retryTxSender.ts +19 -2
- package/src/tx/types.ts +13 -0
- package/src/types.ts +12 -0
- package/src/userMap/userMap.ts +111 -60
- package/src/userMap/userStatsMap.ts +43 -44
- package/tests/dlob/helpers.ts +3 -1
- package/src/assert/assert.js +0 -9
- package/src/token/index.js +0 -38
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
3
|
-
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams } from './types';
|
|
3
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams, PhoenixV1FulfillmentConfigAccount } from './types';
|
|
4
4
|
import * as anchor from '@coral-xyz/anchor';
|
|
5
5
|
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount } from '@solana/web3.js';
|
|
6
6
|
import { TokenFaucet } from './tokenFaucet';
|
|
@@ -43,6 +43,7 @@ export declare class DriftClient {
|
|
|
43
43
|
spotMarketLastSlotCache: Map<number, number>;
|
|
44
44
|
authority: PublicKey;
|
|
45
45
|
marketLookupTable: PublicKey;
|
|
46
|
+
lookupTableAccount: AddressLookupTableAccount;
|
|
46
47
|
get isSubscribed(): boolean;
|
|
47
48
|
set isSubscribed(val: boolean);
|
|
48
49
|
constructor(config: DriftClientConfig);
|
|
@@ -82,6 +83,7 @@ export declare class DriftClient {
|
|
|
82
83
|
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
83
84
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
84
85
|
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
86
|
+
getPhoenixV1FulfillmentConfig(phoenixMarket: PublicKey): Promise<PhoenixV1FulfillmentConfigAccount>;
|
|
85
87
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
86
88
|
/**
|
|
87
89
|
* Update the wallet to use for drift transactions and linked user account
|
|
@@ -199,10 +201,11 @@ export declare class DriftClient {
|
|
|
199
201
|
getRevertFillIx(): Promise<TransactionInstruction>;
|
|
200
202
|
placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams): Promise<TransactionSignature>;
|
|
201
203
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
202
|
-
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
203
|
-
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
204
|
-
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount): void;
|
|
204
|
+
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
205
|
+
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
206
|
+
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount): void;
|
|
205
207
|
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
208
|
+
addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
|
|
206
209
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams): Promise<TransactionSignature>;
|
|
207
210
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
208
211
|
forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
|
|
@@ -344,7 +347,7 @@ export declare class DriftClient {
|
|
|
344
347
|
/**
|
|
345
348
|
* Add to an insurance fund stake and optionally initialize the account
|
|
346
349
|
*/
|
|
347
|
-
addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, }: {
|
|
350
|
+
addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }: {
|
|
348
351
|
/**
|
|
349
352
|
* Spot market index
|
|
350
353
|
*/
|
|
@@ -358,14 +361,14 @@ export declare class DriftClient {
|
|
|
358
361
|
* Add instructions to initialize the staking account -- required if its the first time the currrent authority has staked in this market
|
|
359
362
|
*/
|
|
360
363
|
initializeStakeAccount?: boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Optional -- withdraw from current subaccount to fund stake amount, instead of wallet balance
|
|
366
|
+
*/
|
|
367
|
+
fromSubaccount?: boolean;
|
|
361
368
|
}): Promise<TransactionSignature>;
|
|
362
369
|
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
363
370
|
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
364
|
-
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey
|
|
365
|
-
/**
|
|
366
|
-
* If unstaking SOL, it's required to pass in the amount
|
|
367
|
-
*/
|
|
368
|
-
amount?: BN): Promise<TransactionSignature>;
|
|
371
|
+
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
369
372
|
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
370
373
|
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
371
374
|
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -242,12 +242,20 @@ class DriftClient {
|
|
|
242
242
|
const address = await (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
243
243
|
return (await this.program.account.serumV3FulfillmentConfig.fetch(address));
|
|
244
244
|
}
|
|
245
|
+
async getPhoenixV1FulfillmentConfig(phoenixMarket) {
|
|
246
|
+
const address = await (0, pda_1.getPhoenixFulfillmentConfigPublicKey)(this.program.programId, phoenixMarket);
|
|
247
|
+
return (await this.program.account.phoenixV1FulfillmentConfig.fetch(address));
|
|
248
|
+
}
|
|
245
249
|
async fetchMarketLookupTableAccount() {
|
|
250
|
+
if (this.lookupTableAccount)
|
|
251
|
+
return this.lookupTableAccount;
|
|
246
252
|
if (!this.marketLookupTable) {
|
|
247
|
-
|
|
253
|
+
console.log('Market lookup table address not set');
|
|
254
|
+
return;
|
|
248
255
|
}
|
|
249
|
-
|
|
250
|
-
|
|
256
|
+
const lookupTableAccount = (await this.connection.getAddressLookupTable(this.marketLookupTable)).value;
|
|
257
|
+
this.lookupTableAccount = lookupTableAccount;
|
|
258
|
+
return lookupTableAccount;
|
|
251
259
|
}
|
|
252
260
|
/**
|
|
253
261
|
* Update the wallet to use for drift transactions and linked user account
|
|
@@ -887,7 +895,7 @@ class DriftClient {
|
|
|
887
895
|
return false;
|
|
888
896
|
}
|
|
889
897
|
}
|
|
890
|
-
async getWrappedSolAccountCreationIxs(amount,
|
|
898
|
+
async getWrappedSolAccountCreationIxs(amount, includeRent) {
|
|
891
899
|
const wrappedSolAccount = new web3_js_1.Keypair();
|
|
892
900
|
const result = {
|
|
893
901
|
ixs: [],
|
|
@@ -895,7 +903,7 @@ class DriftClient {
|
|
|
895
903
|
pubkey: wrappedSolAccount.publicKey,
|
|
896
904
|
};
|
|
897
905
|
const rentSpaceLamports = new anchor_1.BN(web3_js_1.LAMPORTS_PER_SOL / 100);
|
|
898
|
-
const lamports =
|
|
906
|
+
const lamports = includeRent
|
|
899
907
|
? amount.add(rentSpaceLamports)
|
|
900
908
|
: rentSpaceLamports;
|
|
901
909
|
const authority = this.wallet.publicKey;
|
|
@@ -1206,26 +1214,54 @@ class DriftClient {
|
|
|
1206
1214
|
* @returns
|
|
1207
1215
|
*/
|
|
1208
1216
|
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo) {
|
|
1217
|
+
var _a, _b;
|
|
1209
1218
|
const marketIndex = orderParams.marketIndex;
|
|
1210
1219
|
const orderId = userAccount.nextOrderId;
|
|
1211
|
-
const
|
|
1220
|
+
const bracketOrderIxs = [];
|
|
1221
|
+
const placePerpOrderIx = await this.getPlacePerpOrderIx(orderParams);
|
|
1212
1222
|
for (const bracketOrderParams of bracketOrdersParams) {
|
|
1213
|
-
|
|
1223
|
+
const placeBracketOrderIx = await this.getPlacePerpOrderIx(bracketOrderParams);
|
|
1224
|
+
bracketOrderIxs.push(placeBracketOrderIx);
|
|
1214
1225
|
}
|
|
1215
|
-
const
|
|
1226
|
+
const fillPerpOrderIx = await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1216
1227
|
orderId,
|
|
1217
1228
|
marketIndex,
|
|
1218
|
-
}, makerInfo, referrerInfo)
|
|
1219
|
-
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
+
}, makerInfo, referrerInfo);
|
|
1230
|
+
const lookupTableAccount = await this.fetchMarketLookupTableAccount();
|
|
1231
|
+
const walletSupportsVersionedTxns =
|
|
1232
|
+
//@ts-ignore
|
|
1233
|
+
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
1234
|
+
// use versioned transactions if there is a lookup table account and wallet is compatible
|
|
1235
|
+
if (walletSupportsVersionedTxns && lookupTableAccount) {
|
|
1236
|
+
const versionedMarketOrderTx = await this.txSender.getVersionedTransaction([placePerpOrderIx].concat(bracketOrderIxs), [lookupTableAccount], [], this.opts);
|
|
1237
|
+
const versionedFillTx = await this.txSender.getVersionedTransaction([fillPerpOrderIx], [lookupTableAccount], [], this.opts);
|
|
1238
|
+
const [signedVersionedMarketOrderTx, signedVersionedFillTx] = await this.provider.wallet.signAllTransactions([
|
|
1239
|
+
//@ts-ignore
|
|
1240
|
+
versionedMarketOrderTx,
|
|
1241
|
+
//@ts-ignore
|
|
1242
|
+
versionedFillTx,
|
|
1243
|
+
]);
|
|
1244
|
+
const { txSig, slot } = await this.txSender.sendRawTransaction(signedVersionedMarketOrderTx.serialize(), this.opts);
|
|
1245
|
+
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1246
|
+
return { txSig, signedFillTx: signedVersionedFillTx };
|
|
1247
|
+
}
|
|
1248
|
+
else {
|
|
1249
|
+
const marketOrderTx = (0, utils_1.wrapInTx)(placePerpOrderIx, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
1250
|
+
if (bracketOrderIxs.length > 0) {
|
|
1251
|
+
marketOrderTx.add(...bracketOrderIxs);
|
|
1252
|
+
}
|
|
1253
|
+
const fillTx = (0, utils_1.wrapInTx)(fillPerpOrderIx, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
1254
|
+
// Apply the latest blockhash to the txs so that we can sign before sending them
|
|
1255
|
+
const currentBlockHash = (await this.connection.getLatestBlockhash('finalized')).blockhash;
|
|
1256
|
+
marketOrderTx.recentBlockhash = currentBlockHash;
|
|
1257
|
+
fillTx.recentBlockhash = currentBlockHash;
|
|
1258
|
+
marketOrderTx.feePayer = userAccount.authority;
|
|
1259
|
+
fillTx.feePayer = userAccount.authority;
|
|
1260
|
+
const [signedMarketOrderTx, signedFillTx] = await this.provider.wallet.signAllTransactions([marketOrderTx, fillTx]);
|
|
1261
|
+
const { txSig, slot } = await this.sendTransaction(signedMarketOrderTx, [], this.opts, true);
|
|
1262
|
+
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1263
|
+
return { txSig, signedFillTx };
|
|
1264
|
+
}
|
|
1229
1265
|
}
|
|
1230
1266
|
async placePerpOrder(orderParams, txParams) {
|
|
1231
1267
|
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlacePerpOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
@@ -1574,7 +1610,15 @@ class DriftClient {
|
|
|
1574
1610
|
}
|
|
1575
1611
|
addSpotFulfillmentAccounts(marketIndex, remainingAccounts, fulfillmentConfig) {
|
|
1576
1612
|
if (fulfillmentConfig) {
|
|
1577
|
-
|
|
1613
|
+
if ('serumProgramId' in fulfillmentConfig) {
|
|
1614
|
+
this.addSerumRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
|
|
1615
|
+
}
|
|
1616
|
+
else if ('phoenixProgramId' in fulfillmentConfig) {
|
|
1617
|
+
this.addPhoenixRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
|
|
1618
|
+
}
|
|
1619
|
+
else {
|
|
1620
|
+
throw Error('Invalid fulfillment config type');
|
|
1621
|
+
}
|
|
1578
1622
|
}
|
|
1579
1623
|
else {
|
|
1580
1624
|
remainingAccounts.push({
|
|
@@ -1671,6 +1715,58 @@ class DriftClient {
|
|
|
1671
1715
|
isSigner: false,
|
|
1672
1716
|
});
|
|
1673
1717
|
}
|
|
1718
|
+
addPhoenixRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig) {
|
|
1719
|
+
remainingAccounts.push({
|
|
1720
|
+
pubkey: fulfillmentConfig.pubkey,
|
|
1721
|
+
isWritable: false,
|
|
1722
|
+
isSigner: false,
|
|
1723
|
+
});
|
|
1724
|
+
remainingAccounts.push({
|
|
1725
|
+
pubkey: fulfillmentConfig.phoenixProgramId,
|
|
1726
|
+
isWritable: false,
|
|
1727
|
+
isSigner: false,
|
|
1728
|
+
});
|
|
1729
|
+
remainingAccounts.push({
|
|
1730
|
+
pubkey: fulfillmentConfig.phoenixLogAuthority,
|
|
1731
|
+
isWritable: false,
|
|
1732
|
+
isSigner: false,
|
|
1733
|
+
});
|
|
1734
|
+
remainingAccounts.push({
|
|
1735
|
+
pubkey: fulfillmentConfig.phoenixMarket,
|
|
1736
|
+
isWritable: true,
|
|
1737
|
+
isSigner: false,
|
|
1738
|
+
});
|
|
1739
|
+
remainingAccounts.push({
|
|
1740
|
+
pubkey: this.getSignerPublicKey(),
|
|
1741
|
+
isWritable: false,
|
|
1742
|
+
isSigner: false,
|
|
1743
|
+
});
|
|
1744
|
+
remainingAccounts.push({
|
|
1745
|
+
pubkey: fulfillmentConfig.phoenixBaseVault,
|
|
1746
|
+
isWritable: true,
|
|
1747
|
+
isSigner: false,
|
|
1748
|
+
});
|
|
1749
|
+
remainingAccounts.push({
|
|
1750
|
+
pubkey: fulfillmentConfig.phoenixQuoteVault,
|
|
1751
|
+
isWritable: true,
|
|
1752
|
+
isSigner: false,
|
|
1753
|
+
});
|
|
1754
|
+
remainingAccounts.push({
|
|
1755
|
+
pubkey: this.getSpotMarketAccount(marketIndex).vault,
|
|
1756
|
+
isWritable: true,
|
|
1757
|
+
isSigner: false,
|
|
1758
|
+
});
|
|
1759
|
+
remainingAccounts.push({
|
|
1760
|
+
pubkey: this.getQuoteSpotMarketAccount().vault,
|
|
1761
|
+
isWritable: true,
|
|
1762
|
+
isSigner: false,
|
|
1763
|
+
});
|
|
1764
|
+
remainingAccounts.push({
|
|
1765
|
+
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1766
|
+
isWritable: false,
|
|
1767
|
+
isSigner: false,
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1674
1770
|
async triggerOrder(userAccountPublicKey, user, order, txParams) {
|
|
1675
1771
|
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1676
1772
|
return txSig;
|
|
@@ -2400,7 +2496,7 @@ class DriftClient {
|
|
|
2400
2496
|
/**
|
|
2401
2497
|
* Add to an insurance fund stake and optionally initialize the account
|
|
2402
2498
|
*/
|
|
2403
|
-
async addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, }) {
|
|
2499
|
+
async addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }) {
|
|
2404
2500
|
const tx = new web3_js_1.Transaction();
|
|
2405
2501
|
const additionalSigners = [];
|
|
2406
2502
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -2418,6 +2514,10 @@ class DriftClient {
|
|
|
2418
2514
|
else {
|
|
2419
2515
|
tokenAccount = collateralAccountPublicKey;
|
|
2420
2516
|
}
|
|
2517
|
+
if (fromSubaccount) {
|
|
2518
|
+
const withdrawIx = await this.getWithdrawIx(amount, marketIndex, tokenAccount);
|
|
2519
|
+
tx.add(withdrawIx);
|
|
2520
|
+
}
|
|
2421
2521
|
if (initializeStakeAccount) {
|
|
2422
2522
|
const initializeIx = await this.getInitializeInsuranceFundStakeIx(marketIndex);
|
|
2423
2523
|
tx.add(initializeIx);
|
|
@@ -2474,11 +2574,7 @@ class DriftClient {
|
|
|
2474
2574
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2475
2575
|
return txSig;
|
|
2476
2576
|
}
|
|
2477
|
-
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey
|
|
2478
|
-
/**
|
|
2479
|
-
* If unstaking SOL, it's required to pass in the amount
|
|
2480
|
-
*/
|
|
2481
|
-
amount) {
|
|
2577
|
+
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
|
|
2482
2578
|
const tx = new web3_js_1.Transaction();
|
|
2483
2579
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2484
2580
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
@@ -2487,7 +2583,7 @@ class DriftClient {
|
|
|
2487
2583
|
const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
2488
2584
|
let tokenAccount;
|
|
2489
2585
|
if (createWSOLTokenAccount) {
|
|
2490
|
-
const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(
|
|
2586
|
+
const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
|
|
2491
2587
|
tokenAccount = pubkey;
|
|
2492
2588
|
ixs.forEach((ix) => {
|
|
2493
2589
|
tx.add(ix);
|
|
@@ -2521,7 +2617,7 @@ class DriftClient {
|
|
|
2521
2617
|
if (createWSOLTokenAccount) {
|
|
2522
2618
|
tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
|
|
2523
2619
|
}
|
|
2524
|
-
const { txSig } = await this.sendTransaction(tx,
|
|
2620
|
+
const { txSig } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
2525
2621
|
return txSig;
|
|
2526
2622
|
}
|
|
2527
2623
|
async settleRevenueToInsuranceFund(marketIndex) {
|
package/lib/examples/loadDlob.js
CHANGED
|
@@ -38,16 +38,14 @@ const main = async () => {
|
|
|
38
38
|
accountLoader: bulkAccountLoader,
|
|
39
39
|
});
|
|
40
40
|
// fetches all users and subscribes for updates
|
|
41
|
-
await userMap.
|
|
41
|
+
await userMap.subscribe();
|
|
42
42
|
console.log('Loading dlob from user map...');
|
|
43
43
|
const dlob = new __1.DLOB();
|
|
44
44
|
await dlob.initFromUserMap(userMap, bulkAccountLoader.mostRecentSlot);
|
|
45
45
|
console.log('number of orders', dlob.getDLOBOrders().length);
|
|
46
46
|
dlob.clear();
|
|
47
47
|
console.log('Unsubscribing users...');
|
|
48
|
-
|
|
49
|
-
await user.unsubscribe();
|
|
50
|
-
}
|
|
48
|
+
await userMap.unsubscribe();
|
|
51
49
|
console.log('Unsubscribing drift client...');
|
|
52
50
|
await driftClient.unsubscribe();
|
|
53
51
|
};
|