@drift-labs/sdk 2.98.0-beta.2 → 2.98.0-beta.20
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/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/browser/accounts/types.d.ts +14 -1
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/browser/addresses/pda.d.ts +1 -0
- package/lib/browser/addresses/pda.js +8 -1
- package/lib/browser/constants/perpMarkets.js +11 -0
- package/lib/browser/constants/spotMarkets.js +4 -4
- package/lib/browser/driftClient.d.ts +20 -6
- package/lib/browser/driftClient.js +68 -24
- package/lib/browser/events/types.d.ts +3 -2
- package/lib/browser/events/types.js +1 -0
- package/lib/browser/idl/drift.json +227 -13
- package/lib/browser/index.d.ts +4 -0
- package/lib/browser/index.js +4 -0
- package/lib/browser/jupiter/jupiterClient.d.ts +6 -0
- package/lib/browser/memcmp.d.ts +3 -0
- package/lib/browser/memcmp.js +28 -1
- package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/browser/slot/SlothashSubscriber.js +85 -0
- package/lib/browser/types.d.ts +10 -1
- package/lib/browser/userMap/referrerMap.d.ts +45 -0
- package/lib/browser/userMap/referrerMap.js +180 -0
- package/lib/browser/util/digest.d.ts +4 -0
- package/lib/browser/util/digest.js +14 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/node/accounts/types.d.ts +14 -1
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/node/addresses/pda.d.ts +1 -0
- package/lib/node/addresses/pda.js +8 -1
- package/lib/node/constants/perpMarkets.js +11 -0
- package/lib/node/constants/spotMarkets.js +4 -4
- package/lib/node/driftClient.d.ts +20 -6
- package/lib/node/driftClient.js +68 -24
- package/lib/node/events/types.d.ts +3 -2
- package/lib/node/events/types.js +1 -0
- package/lib/node/idl/drift.json +227 -13
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.js +4 -0
- package/lib/node/jupiter/jupiterClient.d.ts +6 -0
- package/lib/node/memcmp.d.ts +3 -0
- package/lib/node/memcmp.js +28 -1
- package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/node/slot/SlothashSubscriber.js +85 -0
- package/lib/node/types.d.ts +10 -1
- package/lib/node/userMap/referrerMap.d.ts +45 -0
- package/lib/node/userMap/referrerMap.js +180 -0
- package/lib/node/util/digest.d.ts +4 -0
- package/lib/node/util/digest.js +14 -0
- package/package.json +1 -1
- package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +189 -0
- package/src/accounts/types.ts +25 -1
- package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +131 -0
- package/src/addresses/pda.ts +13 -0
- package/src/constants/perpMarkets.ts +12 -0
- package/src/constants/spotMarkets.ts +4 -4
- package/src/driftClient.ts +139 -42
- package/src/events/types.ts +5 -1
- package/src/idl/drift.json +227 -13
- package/src/index.ts +4 -0
- package/src/jupiter/jupiterClient.ts +6 -0
- package/src/memcmp.ts +27 -0
- package/src/slot/SlothashSubscriber.ts +126 -0
- package/src/types.ts +11 -1
- package/src/userMap/referrerMap.ts +283 -0
- package/src/util/digest.ts +11 -0
- package/tests/ci/verifyConstants.ts +16 -2
package/lib/node/driftClient.js
CHANGED
|
@@ -69,6 +69,7 @@ const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_r
|
|
|
69
69
|
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
70
70
|
const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
|
|
71
71
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
72
|
+
const digest_1 = require("./util/digest");
|
|
72
73
|
/**
|
|
73
74
|
* # DriftClient
|
|
74
75
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -185,7 +186,7 @@ class DriftClient {
|
|
|
185
186
|
if (config.env && !this.marketLookupTable) {
|
|
186
187
|
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
|
|
187
188
|
}
|
|
188
|
-
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.
|
|
189
|
+
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
|
|
189
190
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
190
191
|
config.spotMarketIndexes === undefined &&
|
|
191
192
|
config.oracleInfos === undefined;
|
|
@@ -477,8 +478,8 @@ class DriftClient {
|
|
|
477
478
|
this.authority = authority !== null && authority !== void 0 ? authority : this.authority;
|
|
478
479
|
this.userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
|
|
479
480
|
/* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
|
|
480
|
-
if (authorityChanged) {
|
|
481
|
-
if (this.userStats
|
|
481
|
+
if (authorityChanged && this.userStats) {
|
|
482
|
+
if (this.userStats.isSubscribed) {
|
|
482
483
|
await this.userStats.unsubscribe();
|
|
483
484
|
}
|
|
484
485
|
this.userStats = new userStats_1.UserStats({
|
|
@@ -599,6 +600,28 @@ class DriftClient {
|
|
|
599
600
|
});
|
|
600
601
|
return [rfqUserAccountPublicKey, initializeUserAccountIx];
|
|
601
602
|
}
|
|
603
|
+
async initializeSwiftUserOrdersAccount(userAccountPublicKey, txParams) {
|
|
604
|
+
const initializeIxs = [];
|
|
605
|
+
const [swiftUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey);
|
|
606
|
+
initializeIxs.push(initializeUserAccountIx);
|
|
607
|
+
const tx = await this.buildTransaction(initializeIxs, txParams);
|
|
608
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
609
|
+
return [txSig, swiftUserAccountPublicKey];
|
|
610
|
+
}
|
|
611
|
+
async getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey) {
|
|
612
|
+
const swiftUserAccountPublicKey = (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey);
|
|
613
|
+
const initializeUserAccountIx = await this.program.instruction.initializeSwiftUserOrders({
|
|
614
|
+
accounts: {
|
|
615
|
+
swiftUserOrders: swiftUserAccountPublicKey,
|
|
616
|
+
authority: this.wallet.publicKey,
|
|
617
|
+
user: userAccountPublicKey,
|
|
618
|
+
payer: this.wallet.publicKey,
|
|
619
|
+
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
620
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
621
|
+
},
|
|
622
|
+
});
|
|
623
|
+
return [swiftUserAccountPublicKey, initializeUserAccountIx];
|
|
624
|
+
}
|
|
602
625
|
async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
|
|
603
626
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
604
627
|
const remainingAccounts = new Array();
|
|
@@ -2992,25 +3015,22 @@ class DriftClient {
|
|
|
2992
3015
|
});
|
|
2993
3016
|
}
|
|
2994
3017
|
encodeSwiftServerMessage(message) {
|
|
2995
|
-
|
|
2996
|
-
slot: message.slot,
|
|
2997
|
-
swiftOrderSignature: message.swiftOrderSignature,
|
|
2998
|
-
};
|
|
2999
|
-
return this.program.coder.types.encode('SwiftServerMessage', messageWithBuffer);
|
|
3018
|
+
return this.program.coder.types.encode('SwiftServerMessage', message);
|
|
3000
3019
|
}
|
|
3001
3020
|
decodeSwiftServerMessage(encodedMessage) {
|
|
3002
3021
|
const decodedSwiftMessage = this.program.coder.types.decode('SwiftServerMessage', encodedMessage);
|
|
3003
3022
|
return {
|
|
3023
|
+
uuid: decodedSwiftMessage.uuid,
|
|
3004
3024
|
slot: decodedSwiftMessage.slot,
|
|
3005
3025
|
swiftOrderSignature: decodedSwiftMessage.swiftSignature,
|
|
3006
3026
|
};
|
|
3007
3027
|
}
|
|
3008
3028
|
signSwiftServerMessage(message) {
|
|
3009
|
-
const swiftServerMessage = Uint8Array.from(this.encodeSwiftServerMessage(message));
|
|
3029
|
+
const swiftServerMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftServerMessage(message)));
|
|
3010
3030
|
return this.signMessage(swiftServerMessage);
|
|
3011
3031
|
}
|
|
3012
3032
|
signSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3013
|
-
const takerOrderParamsMessage = Uint8Array.from(this.encodeSwiftOrderParamsMessage(orderParamsMessage));
|
|
3033
|
+
const takerOrderParamsMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftOrderParamsMessage(orderParamsMessage)));
|
|
3014
3034
|
return this.signMessage(takerOrderParamsMessage);
|
|
3015
3035
|
}
|
|
3016
3036
|
encodeSwiftOrderParamsMessage(orderParamsMessage) {
|
|
@@ -3036,18 +3056,19 @@ class DriftClient {
|
|
|
3036
3056
|
const swiftServerSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
3037
3057
|
publicKey: new web3_js_1.PublicKey(this.swiftID).toBytes(),
|
|
3038
3058
|
signature: Uint8Array.from(swiftSignature),
|
|
3039
|
-
message: Uint8Array.from(encodedSwiftServerMessage),
|
|
3059
|
+
message: Uint8Array.from((0, digest_1.digest)(encodedSwiftServerMessage)),
|
|
3040
3060
|
});
|
|
3041
3061
|
const swiftOrderParamsSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
3042
3062
|
publicKey: takerInfo.takerUserAccount.authority.toBytes(),
|
|
3043
3063
|
signature: Uint8Array.from(swiftOrderParamsSignature),
|
|
3044
|
-
message: Uint8Array.from(encodedSwiftOrderParamsMessage),
|
|
3064
|
+
message: Uint8Array.from((0, digest_1.digest)(encodedSwiftOrderParamsMessage)),
|
|
3045
3065
|
});
|
|
3046
|
-
const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage,
|
|
3066
|
+
const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, {
|
|
3047
3067
|
accounts: {
|
|
3048
3068
|
state: await this.getStatePublicKey(),
|
|
3049
3069
|
user: takerInfo.taker,
|
|
3050
3070
|
userStats: takerInfo.takerStats,
|
|
3071
|
+
swiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
|
|
3051
3072
|
authority: this.wallet.publicKey,
|
|
3052
3073
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3053
3074
|
},
|
|
@@ -3059,13 +3080,13 @@ class DriftClient {
|
|
|
3059
3080
|
placeTakerSwiftPerpOrderIx,
|
|
3060
3081
|
];
|
|
3061
3082
|
}
|
|
3062
|
-
async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature,
|
|
3063
|
-
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature,
|
|
3083
|
+
async placeAndMakeSwiftPerpOrder(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId) {
|
|
3084
|
+
const ixs = await this.getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId);
|
|
3064
3085
|
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
|
|
3065
3086
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
3066
3087
|
return txSig;
|
|
3067
3088
|
}
|
|
3068
|
-
async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature,
|
|
3089
|
+
async getPlaceAndMakeSwiftPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, swiftOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId) {
|
|
3069
3090
|
const [swiftServerSignatureIx, swiftOrderSignatureIx, placeTakerSwiftPerpOrderIx,] = await this.getPlaceSwiftTakerPerpOrderIxs(encodedSwiftMessage, swiftSignature, encodedSwiftOrderParamsMessage, swiftOrderParamsSignature, orderParams.marketIndex, takerInfo);
|
|
3070
3091
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
3071
3092
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
@@ -3090,7 +3111,7 @@ class DriftClient {
|
|
|
3090
3111
|
isSigner: false,
|
|
3091
3112
|
});
|
|
3092
3113
|
}
|
|
3093
|
-
const placeAndMakeIx = await this.program.instruction.
|
|
3114
|
+
const placeAndMakeIx = await this.program.instruction.placeAndMakeSwiftPerpOrder(orderParams, swiftOrderUuid, {
|
|
3094
3115
|
accounts: {
|
|
3095
3116
|
state: await this.getStatePublicKey(),
|
|
3096
3117
|
user,
|
|
@@ -3098,6 +3119,7 @@ class DriftClient {
|
|
|
3098
3119
|
taker: takerInfo.taker,
|
|
3099
3120
|
takerStats: takerInfo.takerStats,
|
|
3100
3121
|
authority: this.wallet.publicKey,
|
|
3122
|
+
takerSwiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, takerInfo.taker),
|
|
3101
3123
|
},
|
|
3102
3124
|
remainingAccounts,
|
|
3103
3125
|
});
|
|
@@ -3879,6 +3901,10 @@ class DriftClient {
|
|
|
3879
3901
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
3880
3902
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
3881
3903
|
const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
3904
|
+
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
3905
|
+
// create associated token account because it may not exist
|
|
3906
|
+
const associatedTokenAccountPublicKey = (0, spl_token_1.getAssociatedTokenAddressSync)(spotMarketAccount.mint, this.wallet.publicKey, true, tokenProgramId);
|
|
3907
|
+
addIfStakeIxs.push(await (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.wallet.publicKey, associatedTokenAccountPublicKey, this.wallet.publicKey, spotMarketAccount.mint, tokenProgramId));
|
|
3882
3908
|
let tokenAccount;
|
|
3883
3909
|
if (!(await this.checkIfAccountExists(this.getUserStatsAccountPublicKey()))) {
|
|
3884
3910
|
addIfStakeIxs.push(await this.getInitializeUserStatsIx());
|
|
@@ -3951,6 +3977,7 @@ class DriftClient {
|
|
|
3951
3977
|
const additionalSigners = [];
|
|
3952
3978
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
3953
3979
|
const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
3980
|
+
const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
|
|
3954
3981
|
let tokenAccount;
|
|
3955
3982
|
if (createWSOLTokenAccount) {
|
|
3956
3983
|
const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(numericConstants_1.ZERO, true);
|
|
@@ -3963,7 +3990,7 @@ class DriftClient {
|
|
|
3963
3990
|
tokenAccount = collateralAccountPublicKey;
|
|
3964
3991
|
const tokenAccountExists = await this.checkIfAccountExists(tokenAccount);
|
|
3965
3992
|
if (!tokenAccountExists) {
|
|
3966
|
-
const createTokenAccountIx = await this.createAssociatedTokenAccountIdempotentInstruction(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, spotMarketAccount.mint);
|
|
3993
|
+
const createTokenAccountIx = await this.createAssociatedTokenAccountIdempotentInstruction(tokenAccount, this.wallet.publicKey, this.wallet.publicKey, spotMarketAccount.mint, tokenProgramId);
|
|
3967
3994
|
removeIfStakeIxs.push(createTokenAccountIx);
|
|
3968
3995
|
}
|
|
3969
3996
|
}
|
|
@@ -4100,6 +4127,13 @@ class DriftClient {
|
|
|
4100
4127
|
});
|
|
4101
4128
|
return ix;
|
|
4102
4129
|
}
|
|
4130
|
+
/**
|
|
4131
|
+
* This ix will donate your funds to drift revenue pool. It does not deposit into your user account
|
|
4132
|
+
* @param marketIndex
|
|
4133
|
+
* @param amount
|
|
4134
|
+
* @param userTokenAccountPublicKey
|
|
4135
|
+
* @returns
|
|
4136
|
+
*/
|
|
4103
4137
|
async depositIntoSpotMarketRevenuePool(marketIndex, amount, userTokenAccountPublicKey) {
|
|
4104
4138
|
const ix = await this.getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey);
|
|
4105
4139
|
const tx = await this.buildTransaction([ix]);
|
|
@@ -4288,7 +4322,7 @@ class DriftClient {
|
|
|
4288
4322
|
},
|
|
4289
4323
|
});
|
|
4290
4324
|
}
|
|
4291
|
-
async getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures = 3) {
|
|
4325
|
+
async getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures = 3) {
|
|
4292
4326
|
const program = await this.getSwitchboardOnDemandProgram();
|
|
4293
4327
|
const feedAccount = new on_demand_1.PullFeed(program, feed);
|
|
4294
4328
|
if (!this.sbProgramFeedConfigs) {
|
|
@@ -4300,14 +4334,16 @@ class DriftClient {
|
|
|
4300
4334
|
}
|
|
4301
4335
|
const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
|
|
4302
4336
|
numSignatures,
|
|
4303
|
-
}
|
|
4337
|
+
}, recentSlothash
|
|
4338
|
+
? [[new anchor_1.BN(recentSlothash.slot), recentSlothash.hash]]
|
|
4339
|
+
: undefined);
|
|
4304
4340
|
if (!success) {
|
|
4305
4341
|
return undefined;
|
|
4306
4342
|
}
|
|
4307
4343
|
return pullIx;
|
|
4308
4344
|
}
|
|
4309
|
-
async postSwitchboardOnDemandUpdate(feed, numSignatures = 3) {
|
|
4310
|
-
const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures);
|
|
4345
|
+
async postSwitchboardOnDemandUpdate(feed, recentSlothash, numSignatures = 3) {
|
|
4346
|
+
const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures);
|
|
4311
4347
|
if (!pullIx) {
|
|
4312
4348
|
return undefined;
|
|
4313
4349
|
}
|
|
@@ -4372,9 +4408,17 @@ class DriftClient {
|
|
|
4372
4408
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getEnableHighLeverageModeIx(subAccountId), txParams), [], this.opts);
|
|
4373
4409
|
return txSig;
|
|
4374
4410
|
}
|
|
4375
|
-
async getEnableHighLeverageModeIx(subAccountId) {
|
|
4411
|
+
async getEnableHighLeverageModeIx(subAccountId, depositToTradeArgs) {
|
|
4412
|
+
const isDepositToTradeTx = depositToTradeArgs !== undefined;
|
|
4376
4413
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4377
|
-
userAccounts:
|
|
4414
|
+
userAccounts: (depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.isMakingNewAccount)
|
|
4415
|
+
? []
|
|
4416
|
+
: [this.getUserAccount(subAccountId)],
|
|
4417
|
+
useMarketLastSlotCache: false,
|
|
4418
|
+
readablePerpMarketIndex: depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.orderMarketIndex,
|
|
4419
|
+
readableSpotMarketIndexes: isDepositToTradeTx
|
|
4420
|
+
? [depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.depositMarketIndex]
|
|
4421
|
+
: undefined,
|
|
4378
4422
|
});
|
|
4379
4423
|
const ix = await this.program.instruction.enableUserHighLeverageMode(subAccountId, {
|
|
4380
4424
|
accounts: {
|
|
@@ -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 } from '../index';
|
|
3
|
+
import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord } from '../index';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
export type EventSubscriptionOptions = {
|
|
6
6
|
address?: PublicKey;
|
|
@@ -41,9 +41,10 @@ export type EventMap = {
|
|
|
41
41
|
CurveRecord: Event<CurveRecord>;
|
|
42
42
|
SwapRecord: Event<SwapRecord>;
|
|
43
43
|
SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
|
|
44
|
+
SwiftOrderRecord: Event<SwiftOrderRecord>;
|
|
44
45
|
};
|
|
45
46
|
export type EventType = keyof EventMap;
|
|
46
|
-
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>;
|
|
47
|
+
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<SwiftOrderRecord>;
|
|
47
48
|
export interface EventSubscriberEvents {
|
|
48
49
|
newEvent: (event: WrappedEvent<EventType>) => void;
|
|
49
50
|
}
|
package/lib/node/events/types.js
CHANGED
package/lib/node/idl/drift.json
CHANGED
|
@@ -129,6 +129,42 @@
|
|
|
129
129
|
],
|
|
130
130
|
"args": []
|
|
131
131
|
},
|
|
132
|
+
{
|
|
133
|
+
"name": "initializeSwiftUserOrders",
|
|
134
|
+
"accounts": [
|
|
135
|
+
{
|
|
136
|
+
"name": "swiftUserOrders",
|
|
137
|
+
"isMut": true,
|
|
138
|
+
"isSigner": false
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"name": "authority",
|
|
142
|
+
"isMut": false,
|
|
143
|
+
"isSigner": true
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"name": "user",
|
|
147
|
+
"isMut": true,
|
|
148
|
+
"isSigner": false
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "payer",
|
|
152
|
+
"isMut": true,
|
|
153
|
+
"isSigner": true
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"name": "rent",
|
|
157
|
+
"isMut": false,
|
|
158
|
+
"isSigner": false
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "systemProgram",
|
|
162
|
+
"isMut": false,
|
|
163
|
+
"isSigner": false
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"args": []
|
|
167
|
+
},
|
|
132
168
|
{
|
|
133
169
|
"name": "initializeReferrerName",
|
|
134
170
|
"accounts": [
|
|
@@ -644,6 +680,63 @@
|
|
|
644
680
|
}
|
|
645
681
|
]
|
|
646
682
|
},
|
|
683
|
+
{
|
|
684
|
+
"name": "placeAndMakeSwiftPerpOrder",
|
|
685
|
+
"accounts": [
|
|
686
|
+
{
|
|
687
|
+
"name": "state",
|
|
688
|
+
"isMut": false,
|
|
689
|
+
"isSigner": false
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
"name": "user",
|
|
693
|
+
"isMut": true,
|
|
694
|
+
"isSigner": false
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
"name": "userStats",
|
|
698
|
+
"isMut": true,
|
|
699
|
+
"isSigner": false
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
"name": "taker",
|
|
703
|
+
"isMut": true,
|
|
704
|
+
"isSigner": false
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
"name": "takerStats",
|
|
708
|
+
"isMut": true,
|
|
709
|
+
"isSigner": false
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
"name": "takerSwiftUserOrders",
|
|
713
|
+
"isMut": false,
|
|
714
|
+
"isSigner": false
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
"name": "authority",
|
|
718
|
+
"isMut": false,
|
|
719
|
+
"isSigner": true
|
|
720
|
+
}
|
|
721
|
+
],
|
|
722
|
+
"args": [
|
|
723
|
+
{
|
|
724
|
+
"name": "params",
|
|
725
|
+
"type": {
|
|
726
|
+
"defined": "OrderParams"
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
"name": "swiftOrderUuid",
|
|
731
|
+
"type": {
|
|
732
|
+
"array": [
|
|
733
|
+
"u8",
|
|
734
|
+
8
|
|
735
|
+
]
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
]
|
|
739
|
+
},
|
|
647
740
|
{
|
|
648
741
|
"name": "placeSwiftTakerOrder",
|
|
649
742
|
"accounts": [
|
|
@@ -662,6 +755,11 @@
|
|
|
662
755
|
"isMut": true,
|
|
663
756
|
"isSigner": false
|
|
664
757
|
},
|
|
758
|
+
{
|
|
759
|
+
"name": "swiftUserOrders",
|
|
760
|
+
"isMut": true,
|
|
761
|
+
"isSigner": false
|
|
762
|
+
},
|
|
665
763
|
{
|
|
666
764
|
"name": "authority",
|
|
667
765
|
"isMut": false,
|
|
@@ -686,15 +784,6 @@
|
|
|
686
784
|
{
|
|
687
785
|
"name": "swiftOrderParamsMessageBytes",
|
|
688
786
|
"type": "bytes"
|
|
689
|
-
},
|
|
690
|
-
{
|
|
691
|
-
"name": "swiftMessageSignature",
|
|
692
|
-
"type": {
|
|
693
|
-
"array": [
|
|
694
|
-
"u8",
|
|
695
|
-
64
|
|
696
|
-
]
|
|
697
|
-
}
|
|
698
787
|
}
|
|
699
788
|
]
|
|
700
789
|
},
|
|
@@ -7477,6 +7566,29 @@
|
|
|
7477
7566
|
]
|
|
7478
7567
|
}
|
|
7479
7568
|
},
|
|
7569
|
+
{
|
|
7570
|
+
"name": "SwiftUserOrders",
|
|
7571
|
+
"type": {
|
|
7572
|
+
"kind": "struct",
|
|
7573
|
+
"fields": [
|
|
7574
|
+
{
|
|
7575
|
+
"name": "userPubkey",
|
|
7576
|
+
"type": "publicKey"
|
|
7577
|
+
},
|
|
7578
|
+
{
|
|
7579
|
+
"name": "swiftOrderData",
|
|
7580
|
+
"type": {
|
|
7581
|
+
"array": [
|
|
7582
|
+
{
|
|
7583
|
+
"defined": "SwiftOrderId"
|
|
7584
|
+
},
|
|
7585
|
+
32
|
|
7586
|
+
]
|
|
7587
|
+
}
|
|
7588
|
+
}
|
|
7589
|
+
]
|
|
7590
|
+
}
|
|
7591
|
+
},
|
|
7480
7592
|
{
|
|
7481
7593
|
"name": "User",
|
|
7482
7594
|
"type": {
|
|
@@ -8441,6 +8553,15 @@
|
|
|
8441
8553
|
"type": {
|
|
8442
8554
|
"kind": "struct",
|
|
8443
8555
|
"fields": [
|
|
8556
|
+
{
|
|
8557
|
+
"name": "uuid",
|
|
8558
|
+
"type": {
|
|
8559
|
+
"array": [
|
|
8560
|
+
"u8",
|
|
8561
|
+
8
|
|
8562
|
+
]
|
|
8563
|
+
}
|
|
8564
|
+
},
|
|
8444
8565
|
{
|
|
8445
8566
|
"name": "swiftOrderSignature",
|
|
8446
8567
|
"type": {
|
|
@@ -8468,10 +8589,6 @@
|
|
|
8468
8589
|
"defined": "OrderParams"
|
|
8469
8590
|
}
|
|
8470
8591
|
},
|
|
8471
|
-
{
|
|
8472
|
-
"name": "expectedOrderId",
|
|
8473
|
-
"type": "i32"
|
|
8474
|
-
},
|
|
8475
8592
|
{
|
|
8476
8593
|
"name": "subAccountId",
|
|
8477
8594
|
"type": "u16"
|
|
@@ -9651,6 +9768,31 @@
|
|
|
9651
9768
|
]
|
|
9652
9769
|
}
|
|
9653
9770
|
},
|
|
9771
|
+
{
|
|
9772
|
+
"name": "SwiftOrderId",
|
|
9773
|
+
"type": {
|
|
9774
|
+
"kind": "struct",
|
|
9775
|
+
"fields": [
|
|
9776
|
+
{
|
|
9777
|
+
"name": "uuid",
|
|
9778
|
+
"type": {
|
|
9779
|
+
"array": [
|
|
9780
|
+
"u8",
|
|
9781
|
+
8
|
|
9782
|
+
]
|
|
9783
|
+
}
|
|
9784
|
+
},
|
|
9785
|
+
{
|
|
9786
|
+
"name": "maxSlot",
|
|
9787
|
+
"type": "u64"
|
|
9788
|
+
},
|
|
9789
|
+
{
|
|
9790
|
+
"name": "orderId",
|
|
9791
|
+
"type": "u32"
|
|
9792
|
+
}
|
|
9793
|
+
]
|
|
9794
|
+
}
|
|
9795
|
+
},
|
|
9654
9796
|
{
|
|
9655
9797
|
"name": "UserFees",
|
|
9656
9798
|
"type": {
|
|
@@ -11529,6 +11671,53 @@
|
|
|
11529
11671
|
}
|
|
11530
11672
|
]
|
|
11531
11673
|
},
|
|
11674
|
+
{
|
|
11675
|
+
"name": "SwiftOrderRecord",
|
|
11676
|
+
"fields": [
|
|
11677
|
+
{
|
|
11678
|
+
"name": "user",
|
|
11679
|
+
"type": "publicKey",
|
|
11680
|
+
"index": false
|
|
11681
|
+
},
|
|
11682
|
+
{
|
|
11683
|
+
"name": "hash",
|
|
11684
|
+
"type": "string",
|
|
11685
|
+
"index": false
|
|
11686
|
+
},
|
|
11687
|
+
{
|
|
11688
|
+
"name": "matchingOrderParams",
|
|
11689
|
+
"type": {
|
|
11690
|
+
"defined": "OrderParams"
|
|
11691
|
+
},
|
|
11692
|
+
"index": false
|
|
11693
|
+
},
|
|
11694
|
+
{
|
|
11695
|
+
"name": "userOrderId",
|
|
11696
|
+
"type": "u32",
|
|
11697
|
+
"index": false
|
|
11698
|
+
},
|
|
11699
|
+
{
|
|
11700
|
+
"name": "swiftOrderMaxSlot",
|
|
11701
|
+
"type": "u64",
|
|
11702
|
+
"index": false
|
|
11703
|
+
},
|
|
11704
|
+
{
|
|
11705
|
+
"name": "swiftOrderUuid",
|
|
11706
|
+
"type": {
|
|
11707
|
+
"array": [
|
|
11708
|
+
"u8",
|
|
11709
|
+
8
|
|
11710
|
+
]
|
|
11711
|
+
},
|
|
11712
|
+
"index": false
|
|
11713
|
+
},
|
|
11714
|
+
{
|
|
11715
|
+
"name": "ts",
|
|
11716
|
+
"type": "i64",
|
|
11717
|
+
"index": false
|
|
11718
|
+
}
|
|
11719
|
+
]
|
|
11720
|
+
},
|
|
11532
11721
|
{
|
|
11533
11722
|
"name": "OrderRecord",
|
|
11534
11723
|
"fields": [
|
|
@@ -13648,6 +13837,31 @@
|
|
|
13648
13837
|
"code": 6296,
|
|
13649
13838
|
"name": "InvalidRFQMatch",
|
|
13650
13839
|
"msg": "RFQ matches must be valid"
|
|
13840
|
+
},
|
|
13841
|
+
{
|
|
13842
|
+
"code": 6297,
|
|
13843
|
+
"name": "InvalidSwiftUserAccount",
|
|
13844
|
+
"msg": "Invalid swift user account"
|
|
13845
|
+
},
|
|
13846
|
+
{
|
|
13847
|
+
"code": 6298,
|
|
13848
|
+
"name": "SwiftUserAccountWrongMutability",
|
|
13849
|
+
"msg": "Swift account wrong mutability"
|
|
13850
|
+
},
|
|
13851
|
+
{
|
|
13852
|
+
"code": 6299,
|
|
13853
|
+
"name": "SwiftUserOrdersAccountFull",
|
|
13854
|
+
"msg": "SwiftUserAccount has too many active orders"
|
|
13855
|
+
},
|
|
13856
|
+
{
|
|
13857
|
+
"code": 6300,
|
|
13858
|
+
"name": "SwiftOrderDoesNotExist",
|
|
13859
|
+
"msg": "Order with swift uuid does not exist"
|
|
13860
|
+
},
|
|
13861
|
+
{
|
|
13862
|
+
"code": 6301,
|
|
13863
|
+
"name": "InvalidSwiftOrderId",
|
|
13864
|
+
"msg": "Swift order id cannot be 0s"
|
|
13651
13865
|
}
|
|
13652
13866
|
],
|
|
13653
13867
|
"metadata": {
|
package/lib/node/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './constants/perpMarkets';
|
|
|
10
10
|
export * from './accounts/fetch';
|
|
11
11
|
export * from './accounts/webSocketDriftClientAccountSubscriber';
|
|
12
12
|
export * from './accounts/webSocketInsuranceFundStakeAccountSubscriber';
|
|
13
|
+
export * from './accounts/webSocketHighLeverageModeConfigAccountSubscriber';
|
|
13
14
|
export * from './accounts/bulkAccountLoader';
|
|
14
15
|
export * from './accounts/bulkUserSubscription';
|
|
15
16
|
export * from './accounts/bulkUserStatsSubscription';
|
|
@@ -19,6 +20,7 @@ export * from './accounts/pollingTokenAccountSubscriber';
|
|
|
19
20
|
export * from './accounts/pollingUserAccountSubscriber';
|
|
20
21
|
export * from './accounts/pollingUserStatsAccountSubscriber';
|
|
21
22
|
export * from './accounts/pollingInsuranceFundStakeAccountSubscriber';
|
|
23
|
+
export * from './accounts/pollingHighLeverageModeConfigAccountSubscriber';
|
|
22
24
|
export * from './accounts/basicUserAccountSubscriber';
|
|
23
25
|
export * from './accounts/oneShotUserAccountSubscriber';
|
|
24
26
|
export * from './accounts/types';
|
|
@@ -64,6 +66,7 @@ export * from './math/tiers';
|
|
|
64
66
|
export * from './marinade';
|
|
65
67
|
export * from './orderParams';
|
|
66
68
|
export * from './slot/SlotSubscriber';
|
|
69
|
+
export * from './slot/SlothashSubscriber';
|
|
67
70
|
export * from './wallet';
|
|
68
71
|
export * from './keypair';
|
|
69
72
|
export * from './types';
|
|
@@ -104,6 +107,7 @@ export * from './dlob/DLOBApiClient';
|
|
|
104
107
|
export * from './dlob/types';
|
|
105
108
|
export * from './dlob/orderBookLevels';
|
|
106
109
|
export * from './userMap/userMap';
|
|
110
|
+
export * from './userMap/referrerMap';
|
|
107
111
|
export * from './userMap/userStatsMap';
|
|
108
112
|
export * from './userMap/userMapConfig';
|
|
109
113
|
export * from './math/bankruptcy';
|
package/lib/node/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __exportStar(require("./constants/perpMarkets"), exports);
|
|
|
33
33
|
__exportStar(require("./accounts/fetch"), exports);
|
|
34
34
|
__exportStar(require("./accounts/webSocketDriftClientAccountSubscriber"), exports);
|
|
35
35
|
__exportStar(require("./accounts/webSocketInsuranceFundStakeAccountSubscriber"), exports);
|
|
36
|
+
__exportStar(require("./accounts/webSocketHighLeverageModeConfigAccountSubscriber"), exports);
|
|
36
37
|
__exportStar(require("./accounts/bulkAccountLoader"), exports);
|
|
37
38
|
__exportStar(require("./accounts/bulkUserSubscription"), exports);
|
|
38
39
|
__exportStar(require("./accounts/bulkUserStatsSubscription"), exports);
|
|
@@ -42,6 +43,7 @@ __exportStar(require("./accounts/pollingTokenAccountSubscriber"), exports);
|
|
|
42
43
|
__exportStar(require("./accounts/pollingUserAccountSubscriber"), exports);
|
|
43
44
|
__exportStar(require("./accounts/pollingUserStatsAccountSubscriber"), exports);
|
|
44
45
|
__exportStar(require("./accounts/pollingInsuranceFundStakeAccountSubscriber"), exports);
|
|
46
|
+
__exportStar(require("./accounts/pollingHighLeverageModeConfigAccountSubscriber"), exports);
|
|
45
47
|
__exportStar(require("./accounts/basicUserAccountSubscriber"), exports);
|
|
46
48
|
__exportStar(require("./accounts/oneShotUserAccountSubscriber"), exports);
|
|
47
49
|
__exportStar(require("./accounts/types"), exports);
|
|
@@ -87,6 +89,7 @@ __exportStar(require("./math/tiers"), exports);
|
|
|
87
89
|
__exportStar(require("./marinade"), exports);
|
|
88
90
|
__exportStar(require("./orderParams"), exports);
|
|
89
91
|
__exportStar(require("./slot/SlotSubscriber"), exports);
|
|
92
|
+
__exportStar(require("./slot/SlothashSubscriber"), exports);
|
|
90
93
|
__exportStar(require("./wallet"), exports);
|
|
91
94
|
__exportStar(require("./keypair"), exports);
|
|
92
95
|
__exportStar(require("./types"), exports);
|
|
@@ -127,6 +130,7 @@ __exportStar(require("./dlob/DLOBApiClient"), exports);
|
|
|
127
130
|
__exportStar(require("./dlob/types"), exports);
|
|
128
131
|
__exportStar(require("./dlob/orderBookLevels"), exports);
|
|
129
132
|
__exportStar(require("./userMap/userMap"), exports);
|
|
133
|
+
__exportStar(require("./userMap/referrerMap"), exports);
|
|
130
134
|
__exportStar(require("./userMap/userStatsMap"), exports);
|
|
131
135
|
__exportStar(require("./userMap/userMapConfig"), exports);
|
|
132
136
|
__exportStar(require("./math/bankruptcy"), exports);
|
|
@@ -201,6 +201,12 @@ export interface QuoteResponse {
|
|
|
201
201
|
* @memberof QuoteResponse
|
|
202
202
|
*/
|
|
203
203
|
error?: string;
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @type {string}
|
|
207
|
+
* @memberof QuoteResponse
|
|
208
|
+
*/
|
|
209
|
+
errorCode?: string;
|
|
204
210
|
}
|
|
205
211
|
export declare class JupiterClient {
|
|
206
212
|
url: string;
|
package/lib/node/memcmp.d.ts
CHANGED
|
@@ -5,3 +5,6 @@ export declare function getUserWithOrderFilter(): MemcmpFilter;
|
|
|
5
5
|
export declare function getUserWithAuctionFilter(): MemcmpFilter;
|
|
6
6
|
export declare function getUserThatHasBeenLP(): MemcmpFilter;
|
|
7
7
|
export declare function getUserWithName(name: string): MemcmpFilter;
|
|
8
|
+
export declare function getUserStatsFilter(): MemcmpFilter;
|
|
9
|
+
export declare function getUserStatsIsReferredFilter(): MemcmpFilter;
|
|
10
|
+
export declare function getUserStatsIsReferredOrReferrerFilter(): MemcmpFilter;
|