@drift-labs/sdk-browser 2.110.0-beta.13 → 2.110.0-beta.15
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/browser/addresses/pda.d.ts +1 -1
- package/lib/browser/addresses/pda.js +4 -4
- package/lib/browser/constants/perpMarkets.js +10 -0
- package/lib/browser/driftClient.d.ts +18 -18
- package/lib/browser/driftClient.js +56 -52
- package/lib/browser/events/types.d.ts +3 -3
- package/lib/browser/events/types.js +1 -1
- package/lib/browser/idl/drift.json +82 -313
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -7
- package/lib/browser/swift/swiftOrderSubscriber.js +13 -13
- package/lib/browser/types.d.ts +17 -5
- package/lib/node/addresses/pda.d.ts +1 -1
- package/lib/node/addresses/pda.js +4 -4
- package/lib/node/constants/perpMarkets.js +10 -0
- package/lib/node/driftClient.d.ts +18 -18
- package/lib/node/driftClient.js +56 -52
- package/lib/node/events/types.d.ts +3 -3
- package/lib/node/events/types.js +1 -1
- package/lib/node/idl/drift.json +82 -313
- package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -7
- package/lib/node/swift/swiftOrderSubscriber.js +13 -13
- package/lib/node/types.d.ts +17 -5
- package/package.json +1 -1
- package/src/addresses/pda.ts +2 -2
- package/src/constants/perpMarkets.ts +10 -0
- package/src/driftClient.ts +86 -81
- package/src/events/types.ts +4 -4
- package/src/idl/drift.json +82 -313
- package/src/swift/swiftOrderSubscriber.ts +20 -18
- package/src/types.ts +19 -5
- package/lib/browser/swift/types.d.ts +0 -17
- package/lib/browser/swift/types.js +0 -2
- package/lib/node/swift/types.d.ts +0 -17
- package/lib/node/swift/types.js +0 -2
- package/src/swift/types.ts +0 -16
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.110.0-beta.
|
|
1
|
+
2.110.0-beta.15
|
|
@@ -9,7 +9,7 @@ export declare function getUserAccountPublicKey(programId: PublicKey, authority:
|
|
|
9
9
|
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
|
|
10
10
|
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
11
11
|
export declare function getFuelOverflowAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function getSignedMsgUserAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
13
13
|
export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
14
|
export declare function getPerpMarketPublicKeySync(programId: PublicKey, marketIndex: number): PublicKey;
|
|
15
15
|
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
@@ -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.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.
|
|
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.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
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -69,13 +69,13 @@ function getFuelOverflowAccountPublicKey(programId, authority) {
|
|
|
69
69
|
], programId)[0];
|
|
70
70
|
}
|
|
71
71
|
exports.getFuelOverflowAccountPublicKey = getFuelOverflowAccountPublicKey;
|
|
72
|
-
function
|
|
72
|
+
function getSignedMsgUserAccountPublicKey(programId, authority) {
|
|
73
73
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
74
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
74
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('SIGNED_MSG')),
|
|
75
75
|
authority.toBuffer(),
|
|
76
76
|
], programId)[0];
|
|
77
77
|
}
|
|
78
|
-
exports.
|
|
78
|
+
exports.getSignedMsgUserAccountPublicKey = getSignedMsgUserAccountPublicKey;
|
|
79
79
|
async function getPerpMarketPublicKey(programId, marketIndex) {
|
|
80
80
|
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
81
81
|
Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
|
|
@@ -1120,6 +1120,16 @@ exports.MainnetPerpMarkets = [
|
|
|
1120
1120
|
launchTs: 1739463226000,
|
|
1121
1121
|
oracleSource: __1.OracleSource.Prelaunch,
|
|
1122
1122
|
},
|
|
1123
|
+
{
|
|
1124
|
+
fullName: 'KAITO',
|
|
1125
|
+
category: ['AI'],
|
|
1126
|
+
symbol: 'KAITO-PERP',
|
|
1127
|
+
baseAssetSymbol: 'KAITO',
|
|
1128
|
+
marketIndex: 69,
|
|
1129
|
+
oracle: new web3_js_1.PublicKey('92178mkEc5EFbHPaRNrsv9KPBpgbbDQCPzbSpxmDVy6a'),
|
|
1130
|
+
launchTs: 1739545901000,
|
|
1131
|
+
oracleSource: __1.OracleSource.Prelaunch,
|
|
1132
|
+
},
|
|
1123
1133
|
];
|
|
1124
1134
|
exports.PerpMarkets = {
|
|
1125
1135
|
devnet: exports.DevnetPerpMarkets,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as anchor from '@coral-xyz/anchor';
|
|
6
6
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
7
7
|
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
8
|
-
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly,
|
|
8
|
+
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, OracleSource, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SignedMsgOrderParamsMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
|
|
9
9
|
import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, Keypair, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
10
10
|
import { TokenFaucet } from './tokenFaucet';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
@@ -24,7 +24,7 @@ import { TxHandler } from './tx/txHandler';
|
|
|
24
24
|
import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/idl/wormhole_core_bridge_solana';
|
|
25
25
|
import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
|
|
26
26
|
import { Slothash } from './slot/SlothashSubscriber';
|
|
27
|
-
import {
|
|
27
|
+
import { SignedMsgOrderParams } from './types';
|
|
28
28
|
type RemainingAccountParams = {
|
|
29
29
|
userAccounts: UserAccount[];
|
|
30
30
|
writablePerpMarketIndexes?: number[];
|
|
@@ -148,10 +148,10 @@ export declare class DriftClient {
|
|
|
148
148
|
addAndSubscribeToUsers(authority?: PublicKey): Promise<boolean>;
|
|
149
149
|
initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
|
|
150
150
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
initializeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
|
|
152
|
+
getInitializeSignedMsgUserOrdersAccountIx(authority: PublicKey, numOrders: number): Promise<[PublicKey, TransactionInstruction]>;
|
|
153
|
+
resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
154
|
+
getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
|
|
155
155
|
initializeFuelOverflow(authority?: PublicKey): Promise<TransactionSignature>;
|
|
156
156
|
getInitializeFuelOverflowIx(authority?: PublicKey): Promise<TransactionInstruction>;
|
|
157
157
|
sweepFuel(authority?: PublicKey): Promise<TransactionSignature>;
|
|
@@ -196,17 +196,17 @@ export declare class DriftClient {
|
|
|
196
196
|
getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
|
|
197
197
|
forceDeleteUser(userAccountPublicKey: PublicKey, userAccount: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
|
|
198
198
|
getForceDeleteUserIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<anchor.web3.TransactionInstruction>;
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
deleteSignedMsgUserOrders(txParams?: TxParams): Promise<TransactionSignature>;
|
|
200
|
+
getSignedMsgUserOrdersDeletionIx(authority: PublicKey): Promise<anchor.web3.TransactionInstruction>;
|
|
201
201
|
/**
|
|
202
|
-
* Checks if a
|
|
202
|
+
* Checks if a SignedMsg User Orders account exists for the given authority.
|
|
203
203
|
* The account pubkey is derived using the program ID and authority as seeds.
|
|
204
204
|
* Makes an RPC call to check if the account exists on-chain.
|
|
205
205
|
*
|
|
206
206
|
* @param authority The authority public key to check for
|
|
207
207
|
* @returns Promise that resolves to true if the account exists, false otherwise
|
|
208
208
|
*/
|
|
209
|
-
|
|
209
|
+
isSignedMsgUserOrdersAccountInitialized(authority: PublicKey): Promise<boolean>;
|
|
210
210
|
reclaimRent(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
211
211
|
getReclaimRentIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
|
|
212
212
|
getUser(subAccountId?: number, authority?: PublicKey): User;
|
|
@@ -412,7 +412,7 @@ export declare class DriftClient {
|
|
|
412
412
|
}>;
|
|
413
413
|
getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number): Promise<TransactionInstruction>;
|
|
414
414
|
fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerSubAccountId?: number, fillerAuthority?: PublicKey): Promise<TransactionSignature>;
|
|
415
|
-
getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number,
|
|
415
|
+
getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number, isSignedMsg?: boolean, fillerAuthority?: PublicKey): Promise<TransactionInstruction>;
|
|
416
416
|
getRevertFillIx(fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
417
417
|
placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
418
418
|
preparePlaceSpotOrderTx(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<{
|
|
@@ -550,29 +550,29 @@ export declare class DriftClient {
|
|
|
550
550
|
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
551
551
|
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
552
552
|
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
signSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage): SignedMsgOrderParams;
|
|
554
|
+
encodeSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage): Buffer;
|
|
555
|
+
decodeSignedMsgOrderParamsMessage(encodedMessage: Buffer): SignedMsgOrderParamsMessage;
|
|
556
556
|
signMessage(message: Uint8Array, keypair?: Keypair): Buffer;
|
|
557
|
-
|
|
557
|
+
placeSignedMsgTakerOrder(signedSignedMsgOrderParams: SignedMsgOrderParams, marketIndex: number, takerInfo: {
|
|
558
558
|
taker: PublicKey;
|
|
559
559
|
takerStats: PublicKey;
|
|
560
560
|
takerUserAccount: UserAccount;
|
|
561
561
|
signingAuthority: PublicKey;
|
|
562
562
|
}, precedingIxs?: TransactionInstruction[], overrideIxCount?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
563
|
-
|
|
563
|
+
getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams: SignedMsgOrderParams, marketIndex: number, takerInfo: {
|
|
564
564
|
taker: PublicKey;
|
|
565
565
|
takerStats: PublicKey;
|
|
566
566
|
takerUserAccount: UserAccount;
|
|
567
567
|
signingAuthority: PublicKey;
|
|
568
568
|
}, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionInstruction[]>;
|
|
569
|
-
|
|
569
|
+
placeAndMakeSignedMsgPerpOrder(signedSignedMsgOrderParams: SignedMsgOrderParams, signedMsgOrderUuid: Uint8Array, takerInfo: {
|
|
570
570
|
taker: PublicKey;
|
|
571
571
|
takerStats: PublicKey;
|
|
572
572
|
takerUserAccount: UserAccount;
|
|
573
573
|
signingAuthority: PublicKey;
|
|
574
574
|
}, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number, precedingIxs?: TransactionInstruction[], overrideIxCount?: number): Promise<TransactionSignature>;
|
|
575
|
-
|
|
575
|
+
getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams: SignedMsgOrderParams, signedMsgOrderUuid: Uint8Array, takerInfo: {
|
|
576
576
|
taker: PublicKey;
|
|
577
577
|
takerStats: PublicKey;
|
|
578
578
|
takerUserAccount: UserAccount;
|
|
@@ -603,38 +603,38 @@ class DriftClient {
|
|
|
603
603
|
},
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
|
-
async
|
|
606
|
+
async initializeSignedMsgUserOrders(authority, numOrders, txParams) {
|
|
607
607
|
const initializeIxs = [];
|
|
608
|
-
const [
|
|
608
|
+
const [signedMsgUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSignedMsgUserOrdersAccountIx(authority, numOrders);
|
|
609
609
|
initializeIxs.push(initializeUserAccountIx);
|
|
610
610
|
const tx = await this.buildTransaction(initializeIxs, txParams);
|
|
611
611
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
612
|
-
return [txSig,
|
|
612
|
+
return [txSig, signedMsgUserAccountPublicKey];
|
|
613
613
|
}
|
|
614
|
-
async
|
|
615
|
-
const
|
|
616
|
-
const initializeUserAccountIx = await this.program.instruction.
|
|
614
|
+
async getInitializeSignedMsgUserOrdersAccountIx(authority, numOrders) {
|
|
615
|
+
const signedMsgUserAccountPublicKey = (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, authority);
|
|
616
|
+
const initializeUserAccountIx = await this.program.instruction.initializeSignedMsgUserOrders(numOrders, {
|
|
617
617
|
accounts: {
|
|
618
|
-
|
|
618
|
+
signedMsgUserOrders: signedMsgUserAccountPublicKey,
|
|
619
619
|
authority: this.wallet.publicKey,
|
|
620
620
|
payer: this.wallet.publicKey,
|
|
621
621
|
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
622
622
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
623
623
|
},
|
|
624
624
|
});
|
|
625
|
-
return [
|
|
625
|
+
return [signedMsgUserAccountPublicKey, initializeUserAccountIx];
|
|
626
626
|
}
|
|
627
|
-
async
|
|
628
|
-
const resizeUserAccountIx = await this.
|
|
627
|
+
async resizeSignedMsgUserOrders(authority, numOrders, txParams) {
|
|
628
|
+
const resizeUserAccountIx = await this.getResizeSignedMsgUserOrdersInstruction(authority, numOrders);
|
|
629
629
|
const tx = await this.buildTransaction([resizeUserAccountIx], txParams);
|
|
630
630
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
631
631
|
return txSig;
|
|
632
632
|
}
|
|
633
|
-
async
|
|
634
|
-
const
|
|
635
|
-
const resizeUserAccountIx = await this.program.instruction.
|
|
633
|
+
async getResizeSignedMsgUserOrdersInstruction(authority, numOrders) {
|
|
634
|
+
const signedMsgUserAccountPublicKey = (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, authority);
|
|
635
|
+
const resizeUserAccountIx = await this.program.instruction.resizeSignedMsgUserOrders(numOrders, {
|
|
636
636
|
accounts: {
|
|
637
|
-
|
|
637
|
+
signedMsgUserOrders: signedMsgUserAccountPublicKey,
|
|
638
638
|
authority: this.wallet.publicKey,
|
|
639
639
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
640
640
|
},
|
|
@@ -1024,16 +1024,16 @@ class DriftClient {
|
|
|
1024
1024
|
});
|
|
1025
1025
|
return ix;
|
|
1026
1026
|
}
|
|
1027
|
-
async
|
|
1028
|
-
const ix = await this.
|
|
1027
|
+
async deleteSignedMsgUserOrders(txParams) {
|
|
1028
|
+
const ix = await this.getSignedMsgUserOrdersDeletionIx(this.wallet.publicKey);
|
|
1029
1029
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
|
|
1030
1030
|
return txSig;
|
|
1031
1031
|
}
|
|
1032
|
-
async
|
|
1033
|
-
const ix = await this.program.instruction.
|
|
1032
|
+
async getSignedMsgUserOrdersDeletionIx(authority) {
|
|
1033
|
+
const ix = await this.program.instruction.deleteSignedMsgUserOrders({
|
|
1034
1034
|
accounts: {
|
|
1035
1035
|
user: authority,
|
|
1036
|
-
|
|
1036
|
+
signedMsgUserOrders: (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, authority),
|
|
1037
1037
|
authority: this.wallet.publicKey,
|
|
1038
1038
|
state: await this.getStatePublicKey(),
|
|
1039
1039
|
},
|
|
@@ -1041,16 +1041,16 @@ class DriftClient {
|
|
|
1041
1041
|
return ix;
|
|
1042
1042
|
}
|
|
1043
1043
|
/**
|
|
1044
|
-
* Checks if a
|
|
1044
|
+
* Checks if a SignedMsg User Orders account exists for the given authority.
|
|
1045
1045
|
* The account pubkey is derived using the program ID and authority as seeds.
|
|
1046
1046
|
* Makes an RPC call to check if the account exists on-chain.
|
|
1047
1047
|
*
|
|
1048
1048
|
* @param authority The authority public key to check for
|
|
1049
1049
|
* @returns Promise that resolves to true if the account exists, false otherwise
|
|
1050
1050
|
*/
|
|
1051
|
-
async
|
|
1052
|
-
const
|
|
1053
|
-
return this.checkIfAccountExists(
|
|
1051
|
+
async isSignedMsgUserOrdersAccountInitialized(authority) {
|
|
1052
|
+
const signedMsgUserOrdersAccountPublicKey = (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, authority);
|
|
1053
|
+
return this.checkIfAccountExists(signedMsgUserOrdersAccountPublicKey);
|
|
1054
1054
|
}
|
|
1055
1055
|
async reclaimRent(subAccountId = 0, txParams) {
|
|
1056
1056
|
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
@@ -2157,7 +2157,7 @@ class DriftClient {
|
|
|
2157
2157
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerSubAccountId, undefined, fillerAuthority), txParams), [], this.opts);
|
|
2158
2158
|
return txSig;
|
|
2159
2159
|
}
|
|
2160
|
-
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId,
|
|
2160
|
+
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId, isSignedMsg, fillerAuthority) {
|
|
2161
2161
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2162
2162
|
let filler;
|
|
2163
2163
|
if (fillerAuthority) {
|
|
@@ -2217,7 +2217,7 @@ class DriftClient {
|
|
|
2217
2217
|
});
|
|
2218
2218
|
}
|
|
2219
2219
|
}
|
|
2220
|
-
const orderId =
|
|
2220
|
+
const orderId = isSignedMsg ? null : order.orderId;
|
|
2221
2221
|
return await this.program.instruction.fillPerpOrder(orderId, null, {
|
|
2222
2222
|
accounts: {
|
|
2223
2223
|
state: await this.getStatePublicKey(),
|
|
@@ -3216,8 +3216,8 @@ class DriftClient {
|
|
|
3216
3216
|
remainingAccounts,
|
|
3217
3217
|
});
|
|
3218
3218
|
}
|
|
3219
|
-
|
|
3220
|
-
const borshBuf = this.
|
|
3219
|
+
signSignedMsgOrderParamsMessage(orderParamsMessage) {
|
|
3220
|
+
const borshBuf = this.encodeSignedMsgOrderParamsMessage(orderParamsMessage);
|
|
3221
3221
|
const orderParams = Buffer.from(borshBuf.toString('hex'));
|
|
3222
3222
|
return {
|
|
3223
3223
|
orderParams,
|
|
@@ -3225,69 +3225,69 @@ class DriftClient {
|
|
|
3225
3225
|
};
|
|
3226
3226
|
}
|
|
3227
3227
|
/*
|
|
3228
|
-
* Borsh encode
|
|
3228
|
+
* Borsh encode signedMsg taker order params
|
|
3229
3229
|
*/
|
|
3230
|
-
|
|
3231
|
-
const anchorIxName = 'global' + ':' + '
|
|
3230
|
+
encodeSignedMsgOrderParamsMessage(orderParamsMessage) {
|
|
3231
|
+
const anchorIxName = 'global' + ':' + 'SignedMsgOrderParamsMessage';
|
|
3232
3232
|
const prefix = Buffer.from((0, sha256_1.sha256)(anchorIxName).slice(0, 8));
|
|
3233
3233
|
const buf = Buffer.concat([
|
|
3234
3234
|
prefix,
|
|
3235
|
-
this.program.coder.types.encode('
|
|
3235
|
+
this.program.coder.types.encode('SignedMsgOrderParamsMessage', orderParamsMessage),
|
|
3236
3236
|
]);
|
|
3237
3237
|
return buf;
|
|
3238
3238
|
}
|
|
3239
3239
|
/*
|
|
3240
|
-
* Decode
|
|
3240
|
+
* Decode signedMsg taker order params from borsh buffer
|
|
3241
3241
|
*/
|
|
3242
|
-
|
|
3243
|
-
return this.program.coder.types.decode('
|
|
3242
|
+
decodeSignedMsgOrderParamsMessage(encodedMessage) {
|
|
3243
|
+
return this.program.coder.types.decode('SignedMsgOrderParamsMessage', encodedMessage.slice(8) // assumes discriminator
|
|
3244
3244
|
);
|
|
3245
3245
|
}
|
|
3246
3246
|
signMessage(message, keypair = this.wallet.payer) {
|
|
3247
3247
|
return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
|
|
3248
3248
|
}
|
|
3249
|
-
async
|
|
3250
|
-
const ixs = await this.
|
|
3249
|
+
async placeSignedMsgTakerOrder(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideIxCount, txParams) {
|
|
3250
|
+
const ixs = await this.getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs, overrideIxCount);
|
|
3251
3251
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3252
3252
|
return txSig;
|
|
3253
3253
|
}
|
|
3254
|
-
async
|
|
3254
|
+
async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideIxCount) {
|
|
3255
3255
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3256
3256
|
userAccounts: [takerInfo.takerUserAccount],
|
|
3257
3257
|
useMarketLastSlotCache: true,
|
|
3258
3258
|
readablePerpMarketIndex: marketIndex,
|
|
3259
3259
|
});
|
|
3260
3260
|
const messageLengthBuffer = Buffer.alloc(2);
|
|
3261
|
-
messageLengthBuffer.writeUInt16LE(
|
|
3262
|
-
const
|
|
3263
|
-
|
|
3261
|
+
messageLengthBuffer.writeUInt16LE(signedSignedMsgOrderParams.orderParams.length);
|
|
3262
|
+
const signedMsgIxData = Buffer.concat([
|
|
3263
|
+
signedSignedMsgOrderParams.signature,
|
|
3264
3264
|
takerInfo.signingAuthority.toBytes(),
|
|
3265
3265
|
messageLengthBuffer,
|
|
3266
|
-
|
|
3266
|
+
signedSignedMsgOrderParams.orderParams,
|
|
3267
3267
|
]);
|
|
3268
|
-
const
|
|
3268
|
+
const signedMsgOrderParamsSignatureIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, signedMsgIxData, 0);
|
|
3269
3269
|
const isDelegateSigner = takerInfo.signingAuthority.equals(takerInfo.takerUserAccount.delegate);
|
|
3270
|
-
const
|
|
3270
|
+
const placeTakerSignedMsgPerpOrderIx = this.program.instruction.placeSignedMsgTakerOrder(signedMsgIxData, isDelegateSigner, {
|
|
3271
3271
|
accounts: {
|
|
3272
3272
|
state: await this.getStatePublicKey(),
|
|
3273
3273
|
user: takerInfo.taker,
|
|
3274
3274
|
userStats: takerInfo.takerStats,
|
|
3275
|
-
|
|
3275
|
+
signedMsgUserOrders: (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, takerInfo.takerUserAccount.authority),
|
|
3276
3276
|
authority: this.wallet.publicKey,
|
|
3277
3277
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3278
3278
|
},
|
|
3279
3279
|
remainingAccounts,
|
|
3280
3280
|
});
|
|
3281
|
-
return [
|
|
3281
|
+
return [signedMsgOrderParamsSignatureIx, placeTakerSignedMsgPerpOrderIx];
|
|
3282
3282
|
}
|
|
3283
|
-
async
|
|
3284
|
-
const ixs = await this.
|
|
3283
|
+
async placeAndMakeSignedMsgPerpOrder(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId, precedingIxs = [], overrideIxCount) {
|
|
3284
|
+
const ixs = await this.getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs, overrideIxCount);
|
|
3285
3285
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3286
3286
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
3287
3287
|
return txSig;
|
|
3288
3288
|
}
|
|
3289
|
-
async
|
|
3290
|
-
const [
|
|
3289
|
+
async getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs = [], overrideIxCount) {
|
|
3290
|
+
const [signedMsgOrderSignatureIx, placeTakerSignedMsgPerpOrderIx] = await this.getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, orderParams.marketIndex, takerInfo, precedingIxs, overrideIxCount);
|
|
3291
3291
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
3292
3292
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3293
3293
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
@@ -3311,7 +3311,7 @@ class DriftClient {
|
|
|
3311
3311
|
isSigner: false,
|
|
3312
3312
|
});
|
|
3313
3313
|
}
|
|
3314
|
-
const placeAndMakeIx = await this.program.instruction.
|
|
3314
|
+
const placeAndMakeIx = await this.program.instruction.placeAndMakeSignedMsgPerpOrder(orderParams, signedMsgOrderUuid, {
|
|
3315
3315
|
accounts: {
|
|
3316
3316
|
state: await this.getStatePublicKey(),
|
|
3317
3317
|
user,
|
|
@@ -3319,11 +3319,15 @@ class DriftClient {
|
|
|
3319
3319
|
taker: takerInfo.taker,
|
|
3320
3320
|
takerStats: takerInfo.takerStats,
|
|
3321
3321
|
authority: this.wallet.publicKey,
|
|
3322
|
-
|
|
3322
|
+
takerSignedMsgUserOrders: (0, pda_1.getSignedMsgUserAccountPublicKey)(this.program.programId, takerInfo.takerUserAccount.authority),
|
|
3323
3323
|
},
|
|
3324
3324
|
remainingAccounts,
|
|
3325
3325
|
});
|
|
3326
|
-
return [
|
|
3326
|
+
return [
|
|
3327
|
+
signedMsgOrderSignatureIx,
|
|
3328
|
+
placeTakerSignedMsgPerpOrderIx,
|
|
3329
|
+
placeAndMakeIx,
|
|
3330
|
+
];
|
|
3327
3331
|
}
|
|
3328
3332
|
async preparePlaceAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams, subAccountId) {
|
|
3329
3333
|
const tx = await this.buildTransaction(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo, subAccountId), txParams);
|
|
@@ -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,
|
|
3
|
+
import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SignedMsgOrderRecord, DeleteUserRecord } from '../index';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
export type EventSubscriptionOptions = {
|
|
6
6
|
address?: PublicKey;
|
|
@@ -41,11 +41,11 @@ export type EventMap = {
|
|
|
41
41
|
CurveRecord: Event<CurveRecord>;
|
|
42
42
|
SwapRecord: Event<SwapRecord>;
|
|
43
43
|
SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
|
|
44
|
-
|
|
44
|
+
SignedMsgOrderRecord: Event<SignedMsgOrderRecord>;
|
|
45
45
|
DeleteUserRecord: Event<DeleteUserRecord>;
|
|
46
46
|
};
|
|
47
47
|
export type EventType = keyof EventMap;
|
|
48
|
-
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<
|
|
48
|
+
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>;
|
|
49
49
|
export interface EventSubscriberEvents {
|
|
50
50
|
newEvent: (event: WrappedEvent<EventType>) => void;
|
|
51
51
|
}
|