@drift-labs/sdk 2.110.0-beta.4 → 2.110.0-beta.5
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/config.d.ts +2 -0
- package/lib/browser/config.js +7 -0
- package/lib/browser/driftClient.d.ts +6 -0
- package/lib/browser/driftClient.js +32 -15
- package/lib/browser/driftClientConfig.d.ts +2 -0
- package/lib/browser/tx/txHandler.d.ts +1 -1
- package/lib/browser/tx/txHandler.js +4 -4
- package/lib/node/config.d.ts +2 -0
- package/lib/node/config.js +7 -0
- package/lib/node/driftClient.d.ts +6 -0
- package/lib/node/driftClient.js +32 -15
- package/lib/node/driftClientConfig.d.ts +2 -0
- package/lib/node/tx/txHandler.d.ts +1 -1
- package/lib/node/tx/txHandler.js +4 -4
- package/package.json +1 -1
- package/src/config.ts +9 -0
- package/src/driftClient.ts +58 -19
- package/src/driftClientConfig.ts +2 -0
- package/src/tx/txHandler.ts +5 -5
- package/tests/ci/verifyConstants.ts +3 -3
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.110.0-beta.
|
|
1
|
+
2.110.0-beta.5
|
package/lib/browser/config.d.ts
CHANGED
|
@@ -17,7 +17,9 @@ type DriftConfig = {
|
|
|
17
17
|
V2_ALPHA_TICKET_MINT_ADDRESS: string;
|
|
18
18
|
PERP_MARKETS: PerpMarketConfig[];
|
|
19
19
|
SPOT_MARKETS: SpotMarketConfig[];
|
|
20
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
20
21
|
MARKET_LOOKUP_TABLE: string;
|
|
22
|
+
MARKET_LOOKUP_TABLES: string[];
|
|
21
23
|
SERUM_LOOKUP_TABLE?: string;
|
|
22
24
|
PYTH_PULL_ORACLE_LOOKUP_TABLE?: string;
|
|
23
25
|
SB_ON_DEMAND_PID: PublicKey;
|
package/lib/browser/config.js
CHANGED
|
@@ -27,7 +27,9 @@ exports.configs = {
|
|
|
27
27
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'DeEiGWfCMP9psnLGkxGrBBMEAW5Jv8bBGMN8DCtFRCyB',
|
|
28
28
|
PERP_MARKETS: perpMarkets_1.DevnetPerpMarkets,
|
|
29
29
|
SPOT_MARKETS: spotMarkets_1.DevnetSpotMarkets,
|
|
30
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
30
31
|
MARKET_LOOKUP_TABLE: 'FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb',
|
|
32
|
+
MARKET_LOOKUP_TABLES: ['FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb'],
|
|
31
33
|
DRIFT_ORACLE_RECEIVER_ID: exports.DRIFT_ORACLE_RECEIVER_ID,
|
|
32
34
|
SB_ON_DEMAND_PID: on_demand_1.ON_DEMAND_DEVNET_PID,
|
|
33
35
|
},
|
|
@@ -43,7 +45,12 @@ exports.configs = {
|
|
|
43
45
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'Cmvhycb6LQvvzaShGw4iDHRLzeSSryioAsU98DSSkMNa',
|
|
44
46
|
PERP_MARKETS: perpMarkets_1.MainnetPerpMarkets,
|
|
45
47
|
SPOT_MARKETS: spotMarkets_1.MainnetSpotMarkets,
|
|
48
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
46
49
|
MARKET_LOOKUP_TABLE: 'Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL',
|
|
50
|
+
MARKET_LOOKUP_TABLES: [
|
|
51
|
+
'Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL',
|
|
52
|
+
'EiWSskK5HXnBTptiS5DH6gpAJRVNQ3cAhTKBGaiaysAb',
|
|
53
|
+
],
|
|
47
54
|
SERUM_LOOKUP_TABLE: 'GPZkp76cJtNL2mphCvT6FXkJCVPpouidnacckR6rzKDN',
|
|
48
55
|
DRIFT_ORACLE_RECEIVER_ID: exports.DRIFT_ORACLE_RECEIVER_ID,
|
|
49
56
|
SB_ON_DEMAND_PID: on_demand_1.ON_DEMAND_MAINNET_PID,
|
|
@@ -60,8 +60,12 @@ export declare class DriftClient {
|
|
|
60
60
|
mustIncludePerpMarketIndexes: Set<number>;
|
|
61
61
|
mustIncludeSpotMarketIndexes: Set<number>;
|
|
62
62
|
authority: PublicKey;
|
|
63
|
+
/** @deprecated use marketLookupTables */
|
|
63
64
|
marketLookupTable: PublicKey;
|
|
65
|
+
/** @deprecated use lookupTableAccounts */
|
|
64
66
|
lookupTableAccount: AddressLookupTableAccount;
|
|
67
|
+
marketLookupTables: PublicKey[];
|
|
68
|
+
lookupTableAccounts: AddressLookupTableAccount[];
|
|
65
69
|
includeDelegates?: boolean;
|
|
66
70
|
authoritySubAccountMap?: Map<string, number[]>;
|
|
67
71
|
skipLoadUsers?: boolean;
|
|
@@ -118,7 +122,9 @@ export declare class DriftClient {
|
|
|
118
122
|
getPhoenixV1FulfillmentConfigs(): Promise<PhoenixV1FulfillmentConfigAccount[]>;
|
|
119
123
|
getOpenbookV2FulfillmentConfig(openbookMarket: PublicKey): Promise<OpenbookV2FulfillmentConfigAccount>;
|
|
120
124
|
getOpenbookV2FulfillmentConfigs(): Promise<OpenbookV2FulfillmentConfigAccount[]>;
|
|
125
|
+
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
121
126
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
127
|
+
fetchAllLookupTableAccounts(): Promise<AddressLookupTableAccount[]>;
|
|
122
128
|
/**
|
|
123
129
|
* Update the wallet to use for drift transactions and linked user account
|
|
124
130
|
* @param newWallet
|
|
@@ -191,6 +191,10 @@ class DriftClient {
|
|
|
191
191
|
if (!this.marketLookupTable) {
|
|
192
192
|
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE);
|
|
193
193
|
}
|
|
194
|
+
this.marketLookupTables = config.marketLookupTables;
|
|
195
|
+
if (!this.marketLookupTables) {
|
|
196
|
+
this.marketLookupTables = config_1.configs[this.env].MARKET_LOOKUP_TABLES.map((tableAddr) => new web3_js_1.PublicKey(tableAddr));
|
|
197
|
+
}
|
|
194
198
|
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
|
|
195
199
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
196
200
|
config.spotMarketIndexes === undefined &&
|
|
@@ -366,6 +370,7 @@ class DriftClient {
|
|
|
366
370
|
const accounts = await this.program.account.openbookV2FulfillmentConfig.all();
|
|
367
371
|
return accounts.map((account) => account.account);
|
|
368
372
|
}
|
|
373
|
+
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
369
374
|
async fetchMarketLookupTableAccount() {
|
|
370
375
|
if (this.lookupTableAccount)
|
|
371
376
|
return this.lookupTableAccount;
|
|
@@ -377,6 +382,18 @@ class DriftClient {
|
|
|
377
382
|
this.lookupTableAccount = lookupTableAccount;
|
|
378
383
|
return lookupTableAccount;
|
|
379
384
|
}
|
|
385
|
+
async fetchAllLookupTableAccounts() {
|
|
386
|
+
if (this.lookupTableAccounts)
|
|
387
|
+
return this.lookupTableAccounts;
|
|
388
|
+
if (!this.marketLookupTables) {
|
|
389
|
+
console.log('Market lookup table address not set');
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const lookupTableAccountResults = await Promise.all(this.marketLookupTables.map((lookupTable) => this.connection.getAddressLookupTable(lookupTable)));
|
|
393
|
+
const lookupTableAccounts = lookupTableAccountResults.map((result) => result.value);
|
|
394
|
+
this.lookupTableAccounts = lookupTableAccounts;
|
|
395
|
+
return lookupTableAccounts;
|
|
396
|
+
}
|
|
380
397
|
/**
|
|
381
398
|
* Update the wallet to use for drift transactions and linked user account
|
|
382
399
|
* @param newWallet
|
|
@@ -2120,8 +2137,8 @@ class DriftClient {
|
|
|
2120
2137
|
return txSig;
|
|
2121
2138
|
}
|
|
2122
2139
|
async preparePlaceOrdersTx(params, txParams, subAccountId, optionalIxs) {
|
|
2123
|
-
const
|
|
2124
|
-
const tx = await this.buildTransaction(await this.getPlaceOrdersIx(params, subAccountId), txParams, undefined,
|
|
2140
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
2141
|
+
const tx = await this.buildTransaction(await this.getPlaceOrdersIx(params, subAccountId), txParams, undefined, lookupTableAccounts, undefined, undefined, optionalIxs);
|
|
2125
2142
|
return {
|
|
2126
2143
|
placeOrdersTx: tx,
|
|
2127
2144
|
};
|
|
@@ -3044,7 +3061,7 @@ class DriftClient {
|
|
|
3044
3061
|
};
|
|
3045
3062
|
// Get recent block hash so that we can re-use it for all transactions. Makes this logic run faster with fewer RPC requests
|
|
3046
3063
|
const recentBlockHash = await this.txHandler.getLatestBlockhashForTransaction();
|
|
3047
|
-
const
|
|
3064
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
3048
3065
|
let earlyExitFailedPlaceAndTakeSim = false;
|
|
3049
3066
|
const prepPlaceAndTakeTx = async () => {
|
|
3050
3067
|
var _a;
|
|
@@ -3061,7 +3078,7 @@ class DriftClient {
|
|
|
3061
3078
|
useSimulatedComputeUnits: false,
|
|
3062
3079
|
};
|
|
3063
3080
|
if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
|
|
3064
|
-
const placeAndTakeTxToSim = (await this.buildTransaction(placeAndTakeIxs, txParams, undefined,
|
|
3081
|
+
const placeAndTakeTxToSim = (await this.buildTransaction(placeAndTakeIxs, txParams, undefined, lookupTableAccounts, true, recentBlockHash, optionalIxs));
|
|
3065
3082
|
const simulationResult = await txParamProcessor_1.TransactionParamProcessor.getTxSimComputeUnits(placeAndTakeTxToSim, this.connection, (_a = txParams.computeUnitsBufferMultiplier) !== null && _a !== void 0 ? _a : 1.2, txParams.lowerBoundCu);
|
|
3066
3083
|
if (shouldExitIfSimulationFails && !simulationResult.success) {
|
|
3067
3084
|
earlyExitFailedPlaceAndTakeSim = true;
|
|
@@ -3070,17 +3087,17 @@ class DriftClient {
|
|
|
3070
3087
|
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, {
|
|
3071
3088
|
...txParamsWithoutImplicitSimulation,
|
|
3072
3089
|
computeUnits: simulationResult.computeUnits,
|
|
3073
|
-
}, undefined,
|
|
3090
|
+
}, undefined, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3074
3091
|
}
|
|
3075
3092
|
else {
|
|
3076
|
-
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, txParams, undefined,
|
|
3093
|
+
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, txParams, undefined, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3077
3094
|
}
|
|
3078
3095
|
return;
|
|
3079
3096
|
};
|
|
3080
3097
|
const prepCancelOrderTx = async () => {
|
|
3081
3098
|
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
3082
3099
|
const cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, subAccountId);
|
|
3083
|
-
txsToSign.cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion,
|
|
3100
|
+
txsToSign.cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3084
3101
|
}
|
|
3085
3102
|
return;
|
|
3086
3103
|
};
|
|
@@ -3088,7 +3105,7 @@ class DriftClient {
|
|
|
3088
3105
|
if (settlePnl && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
3089
3106
|
const userAccountPublicKey = await this.getUserAccountPublicKey(subAccountId);
|
|
3090
3107
|
const settlePnlIx = await this.settlePNLIx(userAccountPublicKey, this.getUserAccount(subAccountId), orderParams.marketIndex);
|
|
3091
|
-
txsToSign.settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion,
|
|
3108
|
+
txsToSign.settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3092
3109
|
}
|
|
3093
3110
|
return;
|
|
3094
3111
|
};
|
|
@@ -3695,8 +3712,8 @@ class DriftClient {
|
|
|
3695
3712
|
return ixs;
|
|
3696
3713
|
}
|
|
3697
3714
|
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams, optionalIxs) {
|
|
3698
|
-
const
|
|
3699
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams, undefined,
|
|
3715
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
3716
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams, undefined, lookupTableAccounts, undefined, undefined, optionalIxs), [], this.opts);
|
|
3700
3717
|
return txSig;
|
|
3701
3718
|
}
|
|
3702
3719
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -4777,7 +4794,7 @@ class DriftClient {
|
|
|
4777
4794
|
ixs: [pullIx],
|
|
4778
4795
|
payer: this.wallet.publicKey,
|
|
4779
4796
|
computeUnitLimitMultiple: 1.3,
|
|
4780
|
-
lookupTables:
|
|
4797
|
+
lookupTables: await this.fetchAllLookupTableAccounts(),
|
|
4781
4798
|
});
|
|
4782
4799
|
const { txSig } = await this.sendTransaction(tx, [], {
|
|
4783
4800
|
commitment: 'processed',
|
|
@@ -4949,7 +4966,7 @@ class DriftClient {
|
|
|
4949
4966
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4950
4967
|
connection: this.connection,
|
|
4951
4968
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4952
|
-
|
|
4969
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4953
4970
|
lookupTables,
|
|
4954
4971
|
forceVersionedTransaction,
|
|
4955
4972
|
recentBlockhash,
|
|
@@ -4963,7 +4980,7 @@ class DriftClient {
|
|
|
4963
4980
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4964
4981
|
connection: this.connection,
|
|
4965
4982
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4966
|
-
|
|
4983
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4967
4984
|
lookupTables,
|
|
4968
4985
|
forceVersionedTransaction,
|
|
4969
4986
|
});
|
|
@@ -4975,7 +4992,7 @@ class DriftClient {
|
|
|
4975
4992
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4976
4993
|
connection: this.connection,
|
|
4977
4994
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4978
|
-
|
|
4995
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4979
4996
|
lookupTables,
|
|
4980
4997
|
forceVersionedTransaction,
|
|
4981
4998
|
});
|
|
@@ -4987,7 +5004,7 @@ class DriftClient {
|
|
|
4987
5004
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4988
5005
|
connection: this.connection,
|
|
4989
5006
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4990
|
-
|
|
5007
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4991
5008
|
lookupTables,
|
|
4992
5009
|
forceVersionedTransaction,
|
|
4993
5010
|
});
|
|
@@ -19,7 +19,9 @@ export type DriftClientConfig = {
|
|
|
19
19
|
activeSubAccountId?: number;
|
|
20
20
|
perpMarketIndexes?: number[];
|
|
21
21
|
spotMarketIndexes?: number[];
|
|
22
|
+
/** @deprecated use marketLookupTables */
|
|
22
23
|
marketLookupTable?: PublicKey;
|
|
24
|
+
marketLookupTables?: PublicKey[];
|
|
23
25
|
oracleInfos?: OracleInfo[];
|
|
24
26
|
userStats?: boolean;
|
|
25
27
|
authority?: PublicKey;
|
|
@@ -6,7 +6,7 @@ export type TxBuildingProps = {
|
|
|
6
6
|
txVersion: TransactionVersion;
|
|
7
7
|
connection: Connection;
|
|
8
8
|
preFlightCommitment: Commitment;
|
|
9
|
-
|
|
9
|
+
fetchAllMarketLookupTableAccounts: () => Promise<AddressLookupTableAccount[]>;
|
|
10
10
|
lookupTables?: AddressLookupTableAccount[];
|
|
11
11
|
forceVersionedTransaction?: boolean;
|
|
12
12
|
txParams?: TxParams;
|
|
@@ -277,7 +277,7 @@ class TxHandler {
|
|
|
277
277
|
*/
|
|
278
278
|
async buildTransaction(props) {
|
|
279
279
|
var _a;
|
|
280
|
-
const { txVersion, txParams, connection: _connection, preFlightCommitment: _preFlightCommitment,
|
|
280
|
+
const { txVersion, txParams, connection: _connection, preFlightCommitment: _preFlightCommitment, fetchAllMarketLookupTableAccounts, forceVersionedTransaction, instructions, } = props;
|
|
281
281
|
let { lookupTables } = props;
|
|
282
282
|
// # Collect and process Tx Params
|
|
283
283
|
let baseTxParams = {
|
|
@@ -337,10 +337,10 @@ class TxHandler {
|
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
else {
|
|
340
|
-
const
|
|
340
|
+
const marketLookupTables = await fetchAllMarketLookupTableAccounts();
|
|
341
341
|
lookupTables = lookupTables
|
|
342
|
-
? [...lookupTables,
|
|
343
|
-
:
|
|
342
|
+
? [...lookupTables, ...marketLookupTables]
|
|
343
|
+
: marketLookupTables;
|
|
344
344
|
return this.generateVersionedTransaction(recentBlockhash, allIx, lookupTables);
|
|
345
345
|
}
|
|
346
346
|
}
|
package/lib/node/config.d.ts
CHANGED
|
@@ -17,7 +17,9 @@ type DriftConfig = {
|
|
|
17
17
|
V2_ALPHA_TICKET_MINT_ADDRESS: string;
|
|
18
18
|
PERP_MARKETS: PerpMarketConfig[];
|
|
19
19
|
SPOT_MARKETS: SpotMarketConfig[];
|
|
20
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
20
21
|
MARKET_LOOKUP_TABLE: string;
|
|
22
|
+
MARKET_LOOKUP_TABLES: string[];
|
|
21
23
|
SERUM_LOOKUP_TABLE?: string;
|
|
22
24
|
PYTH_PULL_ORACLE_LOOKUP_TABLE?: string;
|
|
23
25
|
SB_ON_DEMAND_PID: PublicKey;
|
package/lib/node/config.js
CHANGED
|
@@ -27,7 +27,9 @@ exports.configs = {
|
|
|
27
27
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'DeEiGWfCMP9psnLGkxGrBBMEAW5Jv8bBGMN8DCtFRCyB',
|
|
28
28
|
PERP_MARKETS: perpMarkets_1.DevnetPerpMarkets,
|
|
29
29
|
SPOT_MARKETS: spotMarkets_1.DevnetSpotMarkets,
|
|
30
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
30
31
|
MARKET_LOOKUP_TABLE: 'FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb',
|
|
32
|
+
MARKET_LOOKUP_TABLES: ['FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb'],
|
|
31
33
|
DRIFT_ORACLE_RECEIVER_ID: exports.DRIFT_ORACLE_RECEIVER_ID,
|
|
32
34
|
SB_ON_DEMAND_PID: on_demand_1.ON_DEMAND_DEVNET_PID,
|
|
33
35
|
},
|
|
@@ -43,7 +45,12 @@ exports.configs = {
|
|
|
43
45
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'Cmvhycb6LQvvzaShGw4iDHRLzeSSryioAsU98DSSkMNa',
|
|
44
46
|
PERP_MARKETS: perpMarkets_1.MainnetPerpMarkets,
|
|
45
47
|
SPOT_MARKETS: spotMarkets_1.MainnetSpotMarkets,
|
|
48
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
46
49
|
MARKET_LOOKUP_TABLE: 'Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL',
|
|
50
|
+
MARKET_LOOKUP_TABLES: [
|
|
51
|
+
'Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL',
|
|
52
|
+
'EiWSskK5HXnBTptiS5DH6gpAJRVNQ3cAhTKBGaiaysAb',
|
|
53
|
+
],
|
|
47
54
|
SERUM_LOOKUP_TABLE: 'GPZkp76cJtNL2mphCvT6FXkJCVPpouidnacckR6rzKDN',
|
|
48
55
|
DRIFT_ORACLE_RECEIVER_ID: exports.DRIFT_ORACLE_RECEIVER_ID,
|
|
49
56
|
SB_ON_DEMAND_PID: on_demand_1.ON_DEMAND_MAINNET_PID,
|
|
@@ -60,8 +60,12 @@ export declare class DriftClient {
|
|
|
60
60
|
mustIncludePerpMarketIndexes: Set<number>;
|
|
61
61
|
mustIncludeSpotMarketIndexes: Set<number>;
|
|
62
62
|
authority: PublicKey;
|
|
63
|
+
/** @deprecated use marketLookupTables */
|
|
63
64
|
marketLookupTable: PublicKey;
|
|
65
|
+
/** @deprecated use lookupTableAccounts */
|
|
64
66
|
lookupTableAccount: AddressLookupTableAccount;
|
|
67
|
+
marketLookupTables: PublicKey[];
|
|
68
|
+
lookupTableAccounts: AddressLookupTableAccount[];
|
|
65
69
|
includeDelegates?: boolean;
|
|
66
70
|
authoritySubAccountMap?: Map<string, number[]>;
|
|
67
71
|
skipLoadUsers?: boolean;
|
|
@@ -118,7 +122,9 @@ export declare class DriftClient {
|
|
|
118
122
|
getPhoenixV1FulfillmentConfigs(): Promise<PhoenixV1FulfillmentConfigAccount[]>;
|
|
119
123
|
getOpenbookV2FulfillmentConfig(openbookMarket: PublicKey): Promise<OpenbookV2FulfillmentConfigAccount>;
|
|
120
124
|
getOpenbookV2FulfillmentConfigs(): Promise<OpenbookV2FulfillmentConfigAccount[]>;
|
|
125
|
+
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
121
126
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
127
|
+
fetchAllLookupTableAccounts(): Promise<AddressLookupTableAccount[]>;
|
|
122
128
|
/**
|
|
123
129
|
* Update the wallet to use for drift transactions and linked user account
|
|
124
130
|
* @param newWallet
|
package/lib/node/driftClient.js
CHANGED
|
@@ -191,6 +191,10 @@ class DriftClient {
|
|
|
191
191
|
if (!this.marketLookupTable) {
|
|
192
192
|
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE);
|
|
193
193
|
}
|
|
194
|
+
this.marketLookupTables = config.marketLookupTables;
|
|
195
|
+
if (!this.marketLookupTables) {
|
|
196
|
+
this.marketLookupTables = config_1.configs[this.env].MARKET_LOOKUP_TABLES.map((tableAddr) => new web3_js_1.PublicKey(tableAddr));
|
|
197
|
+
}
|
|
194
198
|
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
|
|
195
199
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
196
200
|
config.spotMarketIndexes === undefined &&
|
|
@@ -366,6 +370,7 @@ class DriftClient {
|
|
|
366
370
|
const accounts = await this.program.account.openbookV2FulfillmentConfig.all();
|
|
367
371
|
return accounts.map((account) => account.account);
|
|
368
372
|
}
|
|
373
|
+
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
369
374
|
async fetchMarketLookupTableAccount() {
|
|
370
375
|
if (this.lookupTableAccount)
|
|
371
376
|
return this.lookupTableAccount;
|
|
@@ -377,6 +382,18 @@ class DriftClient {
|
|
|
377
382
|
this.lookupTableAccount = lookupTableAccount;
|
|
378
383
|
return lookupTableAccount;
|
|
379
384
|
}
|
|
385
|
+
async fetchAllLookupTableAccounts() {
|
|
386
|
+
if (this.lookupTableAccounts)
|
|
387
|
+
return this.lookupTableAccounts;
|
|
388
|
+
if (!this.marketLookupTables) {
|
|
389
|
+
console.log('Market lookup table address not set');
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const lookupTableAccountResults = await Promise.all(this.marketLookupTables.map((lookupTable) => this.connection.getAddressLookupTable(lookupTable)));
|
|
393
|
+
const lookupTableAccounts = lookupTableAccountResults.map((result) => result.value);
|
|
394
|
+
this.lookupTableAccounts = lookupTableAccounts;
|
|
395
|
+
return lookupTableAccounts;
|
|
396
|
+
}
|
|
380
397
|
/**
|
|
381
398
|
* Update the wallet to use for drift transactions and linked user account
|
|
382
399
|
* @param newWallet
|
|
@@ -2120,8 +2137,8 @@ class DriftClient {
|
|
|
2120
2137
|
return txSig;
|
|
2121
2138
|
}
|
|
2122
2139
|
async preparePlaceOrdersTx(params, txParams, subAccountId, optionalIxs) {
|
|
2123
|
-
const
|
|
2124
|
-
const tx = await this.buildTransaction(await this.getPlaceOrdersIx(params, subAccountId), txParams, undefined,
|
|
2140
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
2141
|
+
const tx = await this.buildTransaction(await this.getPlaceOrdersIx(params, subAccountId), txParams, undefined, lookupTableAccounts, undefined, undefined, optionalIxs);
|
|
2125
2142
|
return {
|
|
2126
2143
|
placeOrdersTx: tx,
|
|
2127
2144
|
};
|
|
@@ -3044,7 +3061,7 @@ class DriftClient {
|
|
|
3044
3061
|
};
|
|
3045
3062
|
// Get recent block hash so that we can re-use it for all transactions. Makes this logic run faster with fewer RPC requests
|
|
3046
3063
|
const recentBlockHash = await this.txHandler.getLatestBlockhashForTransaction();
|
|
3047
|
-
const
|
|
3064
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
3048
3065
|
let earlyExitFailedPlaceAndTakeSim = false;
|
|
3049
3066
|
const prepPlaceAndTakeTx = async () => {
|
|
3050
3067
|
var _a;
|
|
@@ -3061,7 +3078,7 @@ class DriftClient {
|
|
|
3061
3078
|
useSimulatedComputeUnits: false,
|
|
3062
3079
|
};
|
|
3063
3080
|
if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
|
|
3064
|
-
const placeAndTakeTxToSim = (await this.buildTransaction(placeAndTakeIxs, txParams, undefined,
|
|
3081
|
+
const placeAndTakeTxToSim = (await this.buildTransaction(placeAndTakeIxs, txParams, undefined, lookupTableAccounts, true, recentBlockHash, optionalIxs));
|
|
3065
3082
|
const simulationResult = await txParamProcessor_1.TransactionParamProcessor.getTxSimComputeUnits(placeAndTakeTxToSim, this.connection, (_a = txParams.computeUnitsBufferMultiplier) !== null && _a !== void 0 ? _a : 1.2, txParams.lowerBoundCu);
|
|
3066
3083
|
if (shouldExitIfSimulationFails && !simulationResult.success) {
|
|
3067
3084
|
earlyExitFailedPlaceAndTakeSim = true;
|
|
@@ -3070,17 +3087,17 @@ class DriftClient {
|
|
|
3070
3087
|
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, {
|
|
3071
3088
|
...txParamsWithoutImplicitSimulation,
|
|
3072
3089
|
computeUnits: simulationResult.computeUnits,
|
|
3073
|
-
}, undefined,
|
|
3090
|
+
}, undefined, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3074
3091
|
}
|
|
3075
3092
|
else {
|
|
3076
|
-
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, txParams, undefined,
|
|
3093
|
+
txsToSign.placeAndTakeTx = await this.buildTransaction(placeAndTakeIxs, txParams, undefined, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3077
3094
|
}
|
|
3078
3095
|
return;
|
|
3079
3096
|
};
|
|
3080
3097
|
const prepCancelOrderTx = async () => {
|
|
3081
3098
|
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
3082
3099
|
const cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, subAccountId);
|
|
3083
|
-
txsToSign.cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion,
|
|
3100
|
+
txsToSign.cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3084
3101
|
}
|
|
3085
3102
|
return;
|
|
3086
3103
|
};
|
|
@@ -3088,7 +3105,7 @@ class DriftClient {
|
|
|
3088
3105
|
if (settlePnl && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
3089
3106
|
const userAccountPublicKey = await this.getUserAccountPublicKey(subAccountId);
|
|
3090
3107
|
const settlePnlIx = await this.settlePNLIx(userAccountPublicKey, this.getUserAccount(subAccountId), orderParams.marketIndex);
|
|
3091
|
-
txsToSign.settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion,
|
|
3108
|
+
txsToSign.settlePnlTx = await this.buildTransaction([settlePnlIx], txParams, this.txVersion, lookupTableAccounts, undefined, recentBlockHash, optionalIxs);
|
|
3092
3109
|
}
|
|
3093
3110
|
return;
|
|
3094
3111
|
};
|
|
@@ -3695,8 +3712,8 @@ class DriftClient {
|
|
|
3695
3712
|
return ixs;
|
|
3696
3713
|
}
|
|
3697
3714
|
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams, optionalIxs) {
|
|
3698
|
-
const
|
|
3699
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams, undefined,
|
|
3715
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
3716
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams, undefined, lookupTableAccounts, undefined, undefined, optionalIxs), [], this.opts);
|
|
3700
3717
|
return txSig;
|
|
3701
3718
|
}
|
|
3702
3719
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -4777,7 +4794,7 @@ class DriftClient {
|
|
|
4777
4794
|
ixs: [pullIx],
|
|
4778
4795
|
payer: this.wallet.publicKey,
|
|
4779
4796
|
computeUnitLimitMultiple: 1.3,
|
|
4780
|
-
lookupTables:
|
|
4797
|
+
lookupTables: await this.fetchAllLookupTableAccounts(),
|
|
4781
4798
|
});
|
|
4782
4799
|
const { txSig } = await this.sendTransaction(tx, [], {
|
|
4783
4800
|
commitment: 'processed',
|
|
@@ -4949,7 +4966,7 @@ class DriftClient {
|
|
|
4949
4966
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4950
4967
|
connection: this.connection,
|
|
4951
4968
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4952
|
-
|
|
4969
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4953
4970
|
lookupTables,
|
|
4954
4971
|
forceVersionedTransaction,
|
|
4955
4972
|
recentBlockhash,
|
|
@@ -4963,7 +4980,7 @@ class DriftClient {
|
|
|
4963
4980
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4964
4981
|
connection: this.connection,
|
|
4965
4982
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4966
|
-
|
|
4983
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4967
4984
|
lookupTables,
|
|
4968
4985
|
forceVersionedTransaction,
|
|
4969
4986
|
});
|
|
@@ -4975,7 +4992,7 @@ class DriftClient {
|
|
|
4975
4992
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4976
4993
|
connection: this.connection,
|
|
4977
4994
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4978
|
-
|
|
4995
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4979
4996
|
lookupTables,
|
|
4980
4997
|
forceVersionedTransaction,
|
|
4981
4998
|
});
|
|
@@ -4987,7 +5004,7 @@ class DriftClient {
|
|
|
4987
5004
|
txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
|
|
4988
5005
|
connection: this.connection,
|
|
4989
5006
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
4990
|
-
|
|
5007
|
+
fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
|
|
4991
5008
|
lookupTables,
|
|
4992
5009
|
forceVersionedTransaction,
|
|
4993
5010
|
});
|
|
@@ -19,7 +19,9 @@ export type DriftClientConfig = {
|
|
|
19
19
|
activeSubAccountId?: number;
|
|
20
20
|
perpMarketIndexes?: number[];
|
|
21
21
|
spotMarketIndexes?: number[];
|
|
22
|
+
/** @deprecated use marketLookupTables */
|
|
22
23
|
marketLookupTable?: PublicKey;
|
|
24
|
+
marketLookupTables?: PublicKey[];
|
|
23
25
|
oracleInfos?: OracleInfo[];
|
|
24
26
|
userStats?: boolean;
|
|
25
27
|
authority?: PublicKey;
|
|
@@ -6,7 +6,7 @@ export type TxBuildingProps = {
|
|
|
6
6
|
txVersion: TransactionVersion;
|
|
7
7
|
connection: Connection;
|
|
8
8
|
preFlightCommitment: Commitment;
|
|
9
|
-
|
|
9
|
+
fetchAllMarketLookupTableAccounts: () => Promise<AddressLookupTableAccount[]>;
|
|
10
10
|
lookupTables?: AddressLookupTableAccount[];
|
|
11
11
|
forceVersionedTransaction?: boolean;
|
|
12
12
|
txParams?: TxParams;
|
package/lib/node/tx/txHandler.js
CHANGED
|
@@ -277,7 +277,7 @@ class TxHandler {
|
|
|
277
277
|
*/
|
|
278
278
|
async buildTransaction(props) {
|
|
279
279
|
var _a;
|
|
280
|
-
const { txVersion, txParams, connection: _connection, preFlightCommitment: _preFlightCommitment,
|
|
280
|
+
const { txVersion, txParams, connection: _connection, preFlightCommitment: _preFlightCommitment, fetchAllMarketLookupTableAccounts, forceVersionedTransaction, instructions, } = props;
|
|
281
281
|
let { lookupTables } = props;
|
|
282
282
|
// # Collect and process Tx Params
|
|
283
283
|
let baseTxParams = {
|
|
@@ -337,10 +337,10 @@ class TxHandler {
|
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
else {
|
|
340
|
-
const
|
|
340
|
+
const marketLookupTables = await fetchAllMarketLookupTableAccounts();
|
|
341
341
|
lookupTables = lookupTables
|
|
342
|
-
? [...lookupTables,
|
|
343
|
-
:
|
|
342
|
+
? [...lookupTables, ...marketLookupTables]
|
|
343
|
+
: marketLookupTables;
|
|
344
344
|
return this.generateVersionedTransaction(recentBlockhash, allIx, lookupTables);
|
|
345
345
|
}
|
|
346
346
|
}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -33,7 +33,9 @@ type DriftConfig = {
|
|
|
33
33
|
V2_ALPHA_TICKET_MINT_ADDRESS: string;
|
|
34
34
|
PERP_MARKETS: PerpMarketConfig[];
|
|
35
35
|
SPOT_MARKETS: SpotMarketConfig[];
|
|
36
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
36
37
|
MARKET_LOOKUP_TABLE: string;
|
|
38
|
+
MARKET_LOOKUP_TABLES: string[];
|
|
37
39
|
SERUM_LOOKUP_TABLE?: string;
|
|
38
40
|
PYTH_PULL_ORACLE_LOOKUP_TABLE?: string;
|
|
39
41
|
SB_ON_DEMAND_PID: PublicKey;
|
|
@@ -69,7 +71,9 @@ export const configs: { [key in DriftEnv]: DriftConfig } = {
|
|
|
69
71
|
'DeEiGWfCMP9psnLGkxGrBBMEAW5Jv8bBGMN8DCtFRCyB',
|
|
70
72
|
PERP_MARKETS: DevnetPerpMarkets,
|
|
71
73
|
SPOT_MARKETS: DevnetSpotMarkets,
|
|
74
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
72
75
|
MARKET_LOOKUP_TABLE: 'FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb',
|
|
76
|
+
MARKET_LOOKUP_TABLES: ['FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb'],
|
|
73
77
|
DRIFT_ORACLE_RECEIVER_ID,
|
|
74
78
|
SB_ON_DEMAND_PID: ON_DEMAND_DEVNET_PID,
|
|
75
79
|
},
|
|
@@ -86,7 +90,12 @@ export const configs: { [key in DriftEnv]: DriftConfig } = {
|
|
|
86
90
|
'Cmvhycb6LQvvzaShGw4iDHRLzeSSryioAsU98DSSkMNa',
|
|
87
91
|
PERP_MARKETS: MainnetPerpMarkets,
|
|
88
92
|
SPOT_MARKETS: MainnetSpotMarkets,
|
|
93
|
+
/** @deprecated use MARKET_LOOKUP_TABLES */
|
|
89
94
|
MARKET_LOOKUP_TABLE: 'Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL',
|
|
95
|
+
MARKET_LOOKUP_TABLES: [
|
|
96
|
+
'Fpys8GRa5RBWfyeN7AaDUwFGD1zkDCA4z3t4CJLV8dfL',
|
|
97
|
+
'EiWSskK5HXnBTptiS5DH6gpAJRVNQ3cAhTKBGaiaysAb',
|
|
98
|
+
],
|
|
90
99
|
SERUM_LOOKUP_TABLE: 'GPZkp76cJtNL2mphCvT6FXkJCVPpouidnacckR6rzKDN',
|
|
91
100
|
DRIFT_ORACLE_RECEIVER_ID,
|
|
92
101
|
SB_ON_DEMAND_PID: ON_DEMAND_MAINNET_PID,
|
package/src/driftClient.ts
CHANGED
|
@@ -224,8 +224,15 @@ export class DriftClient {
|
|
|
224
224
|
mustIncludePerpMarketIndexes = new Set<number>();
|
|
225
225
|
mustIncludeSpotMarketIndexes = new Set<number>();
|
|
226
226
|
authority: PublicKey;
|
|
227
|
+
|
|
228
|
+
/** @deprecated use marketLookupTables */
|
|
227
229
|
marketLookupTable: PublicKey;
|
|
230
|
+
/** @deprecated use lookupTableAccounts */
|
|
228
231
|
lookupTableAccount: AddressLookupTableAccount;
|
|
232
|
+
|
|
233
|
+
marketLookupTables: PublicKey[];
|
|
234
|
+
lookupTableAccounts: AddressLookupTableAccount[];
|
|
235
|
+
|
|
229
236
|
includeDelegates?: boolean;
|
|
230
237
|
authoritySubAccountMap?: Map<string, number[]>;
|
|
231
238
|
skipLoadUsers?: boolean;
|
|
@@ -379,6 +386,13 @@ export class DriftClient {
|
|
|
379
386
|
);
|
|
380
387
|
}
|
|
381
388
|
|
|
389
|
+
this.marketLookupTables = config.marketLookupTables;
|
|
390
|
+
if (!this.marketLookupTables) {
|
|
391
|
+
this.marketLookupTables = configs[this.env].MARKET_LOOKUP_TABLES.map(
|
|
392
|
+
(tableAddr) => new PublicKey(tableAddr)
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
382
396
|
const delistedMarketSetting =
|
|
383
397
|
config.delistedMarketSetting || DelistedMarketSetting.Unsubscribe;
|
|
384
398
|
const noMarketsAndOraclesSpecified =
|
|
@@ -683,6 +697,7 @@ export class DriftClient {
|
|
|
683
697
|
) as OpenbookV2FulfillmentConfigAccount[];
|
|
684
698
|
}
|
|
685
699
|
|
|
700
|
+
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
686
701
|
public async fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount> {
|
|
687
702
|
if (this.lookupTableAccount) return this.lookupTableAccount;
|
|
688
703
|
|
|
@@ -699,6 +714,30 @@ export class DriftClient {
|
|
|
699
714
|
return lookupTableAccount;
|
|
700
715
|
}
|
|
701
716
|
|
|
717
|
+
public async fetchAllLookupTableAccounts(): Promise<
|
|
718
|
+
AddressLookupTableAccount[]
|
|
719
|
+
> {
|
|
720
|
+
if (this.lookupTableAccounts) return this.lookupTableAccounts;
|
|
721
|
+
|
|
722
|
+
if (!this.marketLookupTables) {
|
|
723
|
+
console.log('Market lookup table address not set');
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
const lookupTableAccountResults = await Promise.all(
|
|
728
|
+
this.marketLookupTables.map((lookupTable) =>
|
|
729
|
+
this.connection.getAddressLookupTable(lookupTable)
|
|
730
|
+
)
|
|
731
|
+
);
|
|
732
|
+
|
|
733
|
+
const lookupTableAccounts = lookupTableAccountResults.map(
|
|
734
|
+
(result) => result.value
|
|
735
|
+
);
|
|
736
|
+
this.lookupTableAccounts = lookupTableAccounts;
|
|
737
|
+
|
|
738
|
+
return lookupTableAccounts;
|
|
739
|
+
}
|
|
740
|
+
|
|
702
741
|
/**
|
|
703
742
|
* Update the wallet to use for drift transactions and linked user account
|
|
704
743
|
* @param newWallet
|
|
@@ -4019,13 +4058,13 @@ export class DriftClient {
|
|
|
4019
4058
|
subAccountId?: number,
|
|
4020
4059
|
optionalIxs?: TransactionInstruction[]
|
|
4021
4060
|
) {
|
|
4022
|
-
const
|
|
4061
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
4023
4062
|
|
|
4024
4063
|
const tx = await this.buildTransaction(
|
|
4025
4064
|
await this.getPlaceOrdersIx(params, subAccountId),
|
|
4026
4065
|
txParams,
|
|
4027
4066
|
undefined,
|
|
4028
|
-
|
|
4067
|
+
lookupTableAccounts,
|
|
4029
4068
|
undefined,
|
|
4030
4069
|
undefined,
|
|
4031
4070
|
optionalIxs
|
|
@@ -5605,7 +5644,7 @@ export class DriftClient {
|
|
|
5605
5644
|
const recentBlockHash =
|
|
5606
5645
|
await this.txHandler.getLatestBlockhashForTransaction();
|
|
5607
5646
|
|
|
5608
|
-
const
|
|
5647
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
5609
5648
|
|
|
5610
5649
|
let earlyExitFailedPlaceAndTakeSim = false;
|
|
5611
5650
|
|
|
@@ -5643,7 +5682,7 @@ export class DriftClient {
|
|
|
5643
5682
|
placeAndTakeIxs,
|
|
5644
5683
|
txParams,
|
|
5645
5684
|
undefined,
|
|
5646
|
-
|
|
5685
|
+
lookupTableAccounts,
|
|
5647
5686
|
true,
|
|
5648
5687
|
recentBlockHash,
|
|
5649
5688
|
optionalIxs
|
|
@@ -5669,7 +5708,7 @@ export class DriftClient {
|
|
|
5669
5708
|
computeUnits: simulationResult.computeUnits,
|
|
5670
5709
|
},
|
|
5671
5710
|
undefined,
|
|
5672
|
-
|
|
5711
|
+
lookupTableAccounts,
|
|
5673
5712
|
undefined,
|
|
5674
5713
|
recentBlockHash,
|
|
5675
5714
|
optionalIxs
|
|
@@ -5679,7 +5718,7 @@ export class DriftClient {
|
|
|
5679
5718
|
placeAndTakeIxs,
|
|
5680
5719
|
txParams,
|
|
5681
5720
|
undefined,
|
|
5682
|
-
|
|
5721
|
+
lookupTableAccounts,
|
|
5683
5722
|
undefined,
|
|
5684
5723
|
recentBlockHash,
|
|
5685
5724
|
optionalIxs
|
|
@@ -5702,7 +5741,7 @@ export class DriftClient {
|
|
|
5702
5741
|
[cancelOrdersIx],
|
|
5703
5742
|
txParams,
|
|
5704
5743
|
this.txVersion,
|
|
5705
|
-
|
|
5744
|
+
lookupTableAccounts,
|
|
5706
5745
|
undefined,
|
|
5707
5746
|
recentBlockHash,
|
|
5708
5747
|
optionalIxs
|
|
@@ -5728,7 +5767,7 @@ export class DriftClient {
|
|
|
5728
5767
|
[settlePnlIx],
|
|
5729
5768
|
txParams,
|
|
5730
5769
|
this.txVersion,
|
|
5731
|
-
|
|
5770
|
+
lookupTableAccounts,
|
|
5732
5771
|
undefined,
|
|
5733
5772
|
recentBlockHash,
|
|
5734
5773
|
optionalIxs
|
|
@@ -6919,7 +6958,7 @@ export class DriftClient {
|
|
|
6919
6958
|
txParams?: TxParams,
|
|
6920
6959
|
optionalIxs?: TransactionInstruction[]
|
|
6921
6960
|
): Promise<TransactionSignature> {
|
|
6922
|
-
const
|
|
6961
|
+
const lookupTableAccounts = await this.fetchAllLookupTableAccounts();
|
|
6923
6962
|
|
|
6924
6963
|
const { txSig } = await this.sendTransaction(
|
|
6925
6964
|
await this.buildTransaction(
|
|
@@ -6930,7 +6969,7 @@ export class DriftClient {
|
|
|
6930
6969
|
),
|
|
6931
6970
|
txParams,
|
|
6932
6971
|
undefined,
|
|
6933
|
-
|
|
6972
|
+
lookupTableAccounts,
|
|
6934
6973
|
undefined,
|
|
6935
6974
|
undefined,
|
|
6936
6975
|
optionalIxs
|
|
@@ -9076,7 +9115,7 @@ export class DriftClient {
|
|
|
9076
9115
|
ixs: [pullIx],
|
|
9077
9116
|
payer: this.wallet.publicKey,
|
|
9078
9117
|
computeUnitLimitMultiple: 1.3,
|
|
9079
|
-
lookupTables:
|
|
9118
|
+
lookupTables: await this.fetchAllLookupTableAccounts(),
|
|
9080
9119
|
});
|
|
9081
9120
|
const { txSig } = await this.sendTransaction(tx, [], {
|
|
9082
9121
|
commitment: 'processed',
|
|
@@ -9406,8 +9445,8 @@ export class DriftClient {
|
|
|
9406
9445
|
txParams: txParams ?? this.txParams,
|
|
9407
9446
|
connection: this.connection,
|
|
9408
9447
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
9409
|
-
|
|
9410
|
-
this.
|
|
9448
|
+
fetchAllMarketLookupTableAccounts:
|
|
9449
|
+
this.fetchAllLookupTableAccounts.bind(this),
|
|
9411
9450
|
lookupTables,
|
|
9412
9451
|
forceVersionedTransaction,
|
|
9413
9452
|
recentBlockhash,
|
|
@@ -9428,8 +9467,8 @@ export class DriftClient {
|
|
|
9428
9467
|
txParams: txParams ?? this.txParams,
|
|
9429
9468
|
connection: this.connection,
|
|
9430
9469
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
9431
|
-
|
|
9432
|
-
this.
|
|
9470
|
+
fetchAllMarketLookupTableAccounts:
|
|
9471
|
+
this.fetchAllLookupTableAccounts.bind(this),
|
|
9433
9472
|
lookupTables,
|
|
9434
9473
|
forceVersionedTransaction,
|
|
9435
9474
|
});
|
|
@@ -9451,8 +9490,8 @@ export class DriftClient {
|
|
|
9451
9490
|
txParams: txParams ?? this.txParams,
|
|
9452
9491
|
connection: this.connection,
|
|
9453
9492
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
9454
|
-
|
|
9455
|
-
this.
|
|
9493
|
+
fetchAllMarketLookupTableAccounts:
|
|
9494
|
+
this.fetchAllLookupTableAccounts.bind(this),
|
|
9456
9495
|
lookupTables,
|
|
9457
9496
|
forceVersionedTransaction,
|
|
9458
9497
|
});
|
|
@@ -9474,8 +9513,8 @@ export class DriftClient {
|
|
|
9474
9513
|
txParams: txParams ?? this.txParams,
|
|
9475
9514
|
connection: this.connection,
|
|
9476
9515
|
preFlightCommitment: this.opts.preflightCommitment,
|
|
9477
|
-
|
|
9478
|
-
this.
|
|
9516
|
+
fetchAllMarketLookupTableAccounts:
|
|
9517
|
+
this.fetchAllLookupTableAccounts.bind(this),
|
|
9479
9518
|
lookupTables,
|
|
9480
9519
|
forceVersionedTransaction,
|
|
9481
9520
|
});
|
package/src/driftClientConfig.ts
CHANGED
|
@@ -26,7 +26,9 @@ export type DriftClientConfig = {
|
|
|
26
26
|
activeSubAccountId?: number;
|
|
27
27
|
perpMarketIndexes?: number[];
|
|
28
28
|
spotMarketIndexes?: number[];
|
|
29
|
+
/** @deprecated use marketLookupTables */
|
|
29
30
|
marketLookupTable?: PublicKey;
|
|
31
|
+
marketLookupTables?: PublicKey[];
|
|
30
32
|
oracleInfos?: OracleInfo[];
|
|
31
33
|
userStats?: boolean;
|
|
32
34
|
authority?: PublicKey; // explicitly pass an authority if signer is delegate
|
package/src/tx/txHandler.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type TxBuildingProps = {
|
|
|
51
51
|
txVersion: TransactionVersion;
|
|
52
52
|
connection: Connection;
|
|
53
53
|
preFlightCommitment: Commitment;
|
|
54
|
-
|
|
54
|
+
fetchAllMarketLookupTableAccounts: () => Promise<AddressLookupTableAccount[]>;
|
|
55
55
|
lookupTables?: AddressLookupTableAccount[];
|
|
56
56
|
forceVersionedTransaction?: boolean;
|
|
57
57
|
txParams?: TxParams;
|
|
@@ -475,7 +475,7 @@ export class TxHandler {
|
|
|
475
475
|
txParams,
|
|
476
476
|
connection: _connection,
|
|
477
477
|
preFlightCommitment: _preFlightCommitment,
|
|
478
|
-
|
|
478
|
+
fetchAllMarketLookupTableAccounts,
|
|
479
479
|
forceVersionedTransaction,
|
|
480
480
|
instructions,
|
|
481
481
|
} = props;
|
|
@@ -561,10 +561,10 @@ export class TxHandler {
|
|
|
561
561
|
return this.generateLegacyTransaction(allIx, recentBlockhash);
|
|
562
562
|
}
|
|
563
563
|
} else {
|
|
564
|
-
const
|
|
564
|
+
const marketLookupTables = await fetchAllMarketLookupTableAccounts();
|
|
565
565
|
lookupTables = lookupTables
|
|
566
|
-
? [...lookupTables,
|
|
567
|
-
:
|
|
566
|
+
? [...lookupTables, ...marketLookupTables]
|
|
567
|
+
: marketLookupTables;
|
|
568
568
|
|
|
569
569
|
return this.generateVersionedTransaction(
|
|
570
570
|
recentBlockhash,
|
|
@@ -68,9 +68,9 @@ describe('Verify Constants', function () {
|
|
|
68
68
|
await devnetDriftClient.subscribe();
|
|
69
69
|
await mainnetDriftClient.subscribe();
|
|
70
70
|
|
|
71
|
-
const
|
|
72
|
-
await mainnetDriftClient.
|
|
73
|
-
lutAccounts =
|
|
71
|
+
const lookupTables =
|
|
72
|
+
await mainnetDriftClient.fetchAllLookupTableAccounts();
|
|
73
|
+
lutAccounts = lookupTables.map((lut) => lut.state.addresses.map((x) => x.toBase58())).flat();
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
after(async () => {
|