@drift-labs/sdk 2.145.0-beta.2 → 2.145.0-beta.3
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/types.d.ts +13 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +53 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +453 -0
- package/lib/browser/addresses/pda.d.ts +9 -0
- package/lib/browser/addresses/pda.js +60 -1
- package/lib/browser/adminClient.d.ts +160 -8
- package/lib/browser/adminClient.js +754 -18
- package/lib/browser/constituentMap/constituentMap.d.ts +64 -0
- package/lib/browser/constituentMap/constituentMap.js +170 -0
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.d.ts +24 -0
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +60 -0
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +24 -0
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +58 -0
- package/lib/browser/driftClient.d.ts +89 -2
- package/lib/browser/driftClient.js +486 -27
- package/lib/browser/driftClientConfig.d.ts +2 -7
- package/lib/browser/idl/drift.json +4303 -1379
- package/lib/browser/index.d.ts +1 -4
- package/lib/browser/index.js +2 -9
- package/lib/browser/memcmp.d.ts +3 -1
- package/lib/browser/memcmp.js +19 -1
- package/lib/browser/types.d.ts +147 -0
- package/lib/browser/types.js +13 -1
- package/lib/node/accounts/types.d.ts +13 -1
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +54 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +453 -0
- package/lib/node/addresses/pda.d.ts +9 -0
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +60 -1
- package/lib/node/adminClient.d.ts +160 -8
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +754 -18
- package/lib/node/constituentMap/constituentMap.d.ts +65 -0
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -0
- package/lib/node/constituentMap/constituentMap.js +170 -0
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts +25 -0
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -0
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +60 -0
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +25 -0
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -0
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +58 -0
- package/lib/node/driftClient.d.ts +89 -2
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +486 -27
- package/lib/node/driftClientConfig.d.ts +2 -7
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/idl/drift.json +4303 -1379
- package/lib/node/index.d.ts +1 -4
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -9
- package/lib/node/memcmp.d.ts +3 -1
- package/lib/node/memcmp.d.ts.map +1 -1
- package/lib/node/memcmp.js +19 -1
- package/lib/node/types.d.ts +147 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +13 -1
- package/package.json +1 -1
- package/src/accounts/types.ts +20 -0
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +596 -0
- package/src/addresses/pda.ts +115 -1
- package/src/adminClient.ts +1612 -41
- package/src/constituentMap/constituentMap.ts +285 -0
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +97 -0
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +112 -0
- package/src/driftClient.ts +1097 -17
- package/src/driftClientConfig.ts +8 -15
- package/src/idl/drift.json +4303 -1379
- package/src/index.ts +1 -4
- package/src/memcmp.ts +23 -1
- package/src/types.ts +160 -0
package/lib/node/driftClient.js
CHANGED
|
@@ -42,6 +42,7 @@ const position_1 = require("./math/position");
|
|
|
42
42
|
const spotBalance_1 = require("./math/spotBalance");
|
|
43
43
|
const userName_1 = require("./userName");
|
|
44
44
|
const pollingDriftClientAccountSubscriber_1 = require("./accounts/pollingDriftClientAccountSubscriber");
|
|
45
|
+
const webSocketDriftClientAccountSubscriber_1 = require("./accounts/webSocketDriftClientAccountSubscriber");
|
|
45
46
|
const retryTxSender_1 = require("./tx/retryTxSender");
|
|
46
47
|
const user_1 = require("./user");
|
|
47
48
|
const config_1 = require("./config");
|
|
@@ -72,7 +73,6 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
|
72
73
|
const oracleId_1 = require("./oracles/oracleId");
|
|
73
74
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
74
75
|
const utils_3 = require("./oracles/utils");
|
|
75
|
-
const webSocketDriftClientAccountSubscriber_1 = require("./accounts/webSocketDriftClientAccountSubscriber");
|
|
76
76
|
const orders_1 = require("./math/orders");
|
|
77
77
|
const builder_1 = require("./math/builder");
|
|
78
78
|
const titanClient_1 = require("./titan/titanClient");
|
|
@@ -89,7 +89,7 @@ class DriftClient {
|
|
|
89
89
|
this._isSubscribed = val;
|
|
90
90
|
}
|
|
91
91
|
constructor(config) {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25
|
|
92
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
|
|
93
93
|
this.users = new Map();
|
|
94
94
|
this._isSubscribed = false;
|
|
95
95
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -180,13 +180,12 @@ class DriftClient {
|
|
|
180
180
|
resubTimeoutMs: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.resubTimeoutMs,
|
|
181
181
|
logResubMessages: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.logResubMessages,
|
|
182
182
|
commitment: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.commitment,
|
|
183
|
-
programUserAccountSubscriber: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.programUserAccountSubscriber,
|
|
184
183
|
};
|
|
185
184
|
this.userStatsAccountSubscriptionConfig = {
|
|
186
185
|
type: 'websocket',
|
|
187
|
-
resubTimeoutMs: (
|
|
188
|
-
logResubMessages: (
|
|
189
|
-
commitment: (
|
|
186
|
+
resubTimeoutMs: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.resubTimeoutMs,
|
|
187
|
+
logResubMessages: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.logResubMessages,
|
|
188
|
+
commitment: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.commitment,
|
|
190
189
|
};
|
|
191
190
|
}
|
|
192
191
|
if (config.userStats) {
|
|
@@ -208,22 +207,21 @@ class DriftClient {
|
|
|
208
207
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
209
208
|
config.spotMarketIndexes === undefined &&
|
|
210
209
|
config.oracleInfos === undefined;
|
|
211
|
-
if (((
|
|
212
|
-
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (
|
|
213
|
-
}
|
|
214
|
-
else if (((
|
|
215
|
-
const accountSubscriberClass = (
|
|
216
|
-
this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (
|
|
217
|
-
resubTimeoutMs: (
|
|
218
|
-
logResubMessages: (
|
|
210
|
+
if (((_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.type) === 'polling') {
|
|
211
|
+
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_6 = config.perpMarketIndexes) !== null && _6 !== void 0 ? _6 : [], (_7 = config.spotMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.oracleInfos) !== null && _8 !== void 0 ? _8 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
|
|
212
|
+
}
|
|
213
|
+
else if (((_9 = config.accountSubscription) === null || _9 === void 0 ? void 0 : _9.type) === 'grpc') {
|
|
214
|
+
const accountSubscriberClass = (_11 = (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.driftClientAccountSubscriber) !== null && _11 !== void 0 ? _11 : grpcDriftClientAccountSubscriber_1.grpcDriftClientAccountSubscriber;
|
|
215
|
+
this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
216
|
+
resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
|
|
217
|
+
logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
|
|
219
218
|
});
|
|
220
219
|
}
|
|
221
220
|
else {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}, (_25 = config.accountSubscription) === null || _25 === void 0 ? void 0 : _25.commitment);
|
|
221
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_17 = config.perpMarketIndexes) !== null && _17 !== void 0 ? _17 : [], (_18 = config.spotMarketIndexes) !== null && _18 !== void 0 ? _18 : [], (_19 = config.oracleInfos) !== null && _19 !== void 0 ? _19 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
222
|
+
resubTimeoutMs: (_20 = config.accountSubscription) === null || _20 === void 0 ? void 0 : _20.resubTimeoutMs,
|
|
223
|
+
logResubMessages: (_21 = config.accountSubscription) === null || _21 === void 0 ? void 0 : _21.logResubMessages,
|
|
224
|
+
}, (_22 = config.accountSubscription) === null || _22 === void 0 ? void 0 : _22.commitment, (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.perpMarketAccountSubscriber, (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.oracleAccountSubscriber);
|
|
227
225
|
}
|
|
228
226
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
229
227
|
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
@@ -231,7 +229,7 @@ class DriftClient {
|
|
|
231
229
|
this.enableMetricsEvents = true;
|
|
232
230
|
}
|
|
233
231
|
this.txSender =
|
|
234
|
-
(
|
|
232
|
+
(_25 = config.txSender) !== null && _25 !== void 0 ? _25 : new retryTxSender_1.RetryTxSender({
|
|
235
233
|
connection: this.connection,
|
|
236
234
|
wallet: this.wallet,
|
|
237
235
|
opts: this.opts,
|
|
@@ -335,17 +333,15 @@ class DriftClient {
|
|
|
335
333
|
.map((value) => value.data);
|
|
336
334
|
}
|
|
337
335
|
getSpotMarketAccount(marketIndex) {
|
|
338
|
-
|
|
339
|
-
return (_a = this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
|
|
336
|
+
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data;
|
|
340
337
|
}
|
|
341
338
|
/**
|
|
342
339
|
* Forces a fetch to rpc before returning accounts. Useful for anchor tests.
|
|
343
340
|
* @param marketIndex
|
|
344
341
|
*/
|
|
345
342
|
async forceGetSpotMarketAccount(marketIndex) {
|
|
346
|
-
var _a;
|
|
347
343
|
await this.accountSubscriber.fetch();
|
|
348
|
-
return
|
|
344
|
+
return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data;
|
|
349
345
|
}
|
|
350
346
|
getSpotMarketAccounts() {
|
|
351
347
|
return this.accountSubscriber
|
|
@@ -1594,13 +1590,13 @@ class DriftClient {
|
|
|
1594
1590
|
* @param useNative
|
|
1595
1591
|
* @param tokenProgram
|
|
1596
1592
|
*/
|
|
1597
|
-
async getAssociatedTokenAccount(marketIndex, useNative = true, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
|
|
1593
|
+
async getAssociatedTokenAccount(marketIndex, useNative = true, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID, authority = this.wallet.publicKey, allowOwnerOffCurve = false) {
|
|
1598
1594
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
1599
1595
|
if (useNative && spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
|
|
1600
|
-
return
|
|
1596
|
+
return authority;
|
|
1601
1597
|
}
|
|
1602
1598
|
const mint = spotMarket.mint;
|
|
1603
|
-
return await (0, spl_token_1.getAssociatedTokenAddress)(mint,
|
|
1599
|
+
return await (0, spl_token_1.getAssociatedTokenAddress)(mint, authority, allowOwnerOffCurve, tokenProgram);
|
|
1604
1600
|
}
|
|
1605
1601
|
createAssociatedTokenAccountIdempotentInstruction(account, payer, owner, mint, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
|
|
1606
1602
|
return new web3_js_1.TransactionInstruction({
|
|
@@ -5913,6 +5909,469 @@ class DriftClient {
|
|
|
5913
5909
|
data,
|
|
5914
5910
|
});
|
|
5915
5911
|
}
|
|
5912
|
+
async getLpPoolAccount(lpPoolId) {
|
|
5913
|
+
return (await this.program.account.lpPool.fetch((0, pda_1.getLpPoolPublicKey)(this.program.programId, lpPoolId)));
|
|
5914
|
+
}
|
|
5915
|
+
async getConstituentTargetBaseAccount(lpPoolId) {
|
|
5916
|
+
return (await this.program.account.constituentTargetBase.fetch((0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, (0, pda_1.getLpPoolPublicKey)(this.program.programId, lpPoolId))));
|
|
5917
|
+
}
|
|
5918
|
+
async getAmmCache() {
|
|
5919
|
+
return (await this.program.account.ammCache.fetch((0, pda_1.getAmmCachePublicKey)(this.program.programId)));
|
|
5920
|
+
}
|
|
5921
|
+
async updateLpConstituentTargetBase(lpPoolId, constituents, txParams) {
|
|
5922
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateLpConstituentTargetBaseIx(lpPoolId, constituents), txParams), [], this.opts);
|
|
5923
|
+
return txSig;
|
|
5924
|
+
}
|
|
5925
|
+
async getUpdateLpConstituentTargetBaseIx(lpPoolId, constituents) {
|
|
5926
|
+
const lpPool = (0, pda_1.getLpPoolPublicKey)(this.program.programId, lpPoolId);
|
|
5927
|
+
const ammConstituentMappingPublicKey = (0, pda_1.getAmmConstituentMappingPublicKey)(this.program.programId, lpPool);
|
|
5928
|
+
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool);
|
|
5929
|
+
const ammCache = (0, pda_1.getAmmCachePublicKey)(this.program.programId);
|
|
5930
|
+
const remainingAccounts = constituents.map((constituent) => {
|
|
5931
|
+
return {
|
|
5932
|
+
isWritable: false,
|
|
5933
|
+
isSigner: false,
|
|
5934
|
+
pubkey: constituent,
|
|
5935
|
+
};
|
|
5936
|
+
});
|
|
5937
|
+
return this.program.instruction.updateLpConstituentTargetBase({
|
|
5938
|
+
accounts: {
|
|
5939
|
+
keeper: this.wallet.publicKey,
|
|
5940
|
+
lpPool,
|
|
5941
|
+
ammConstituentMapping: ammConstituentMappingPublicKey,
|
|
5942
|
+
constituentTargetBase,
|
|
5943
|
+
state: await this.getStatePublicKey(),
|
|
5944
|
+
ammCache,
|
|
5945
|
+
},
|
|
5946
|
+
remainingAccounts,
|
|
5947
|
+
});
|
|
5948
|
+
}
|
|
5949
|
+
async updateLpPoolAum(lpPool, spotMarketIndexOfConstituents, txParams) {
|
|
5950
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateLpPoolAumIxs(lpPool, spotMarketIndexOfConstituents), txParams), [], this.opts);
|
|
5951
|
+
return txSig;
|
|
5952
|
+
}
|
|
5953
|
+
async getUpdateLpPoolAumIxs(lpPool, spotMarketIndexOfConstituents) {
|
|
5954
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
5955
|
+
userAccounts: [],
|
|
5956
|
+
readableSpotMarketIndexes: spotMarketIndexOfConstituents,
|
|
5957
|
+
});
|
|
5958
|
+
remainingAccounts.push(...spotMarketIndexOfConstituents.map((index) => {
|
|
5959
|
+
return {
|
|
5960
|
+
pubkey: (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, index),
|
|
5961
|
+
isSigner: false,
|
|
5962
|
+
isWritable: true,
|
|
5963
|
+
};
|
|
5964
|
+
}));
|
|
5965
|
+
return this.program.instruction.updateLpPoolAum({
|
|
5966
|
+
accounts: {
|
|
5967
|
+
keeper: this.wallet.publicKey,
|
|
5968
|
+
lpPool: lpPool.pubkey,
|
|
5969
|
+
state: await this.getStatePublicKey(),
|
|
5970
|
+
constituentTargetBase: (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool.pubkey),
|
|
5971
|
+
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
5972
|
+
},
|
|
5973
|
+
remainingAccounts,
|
|
5974
|
+
});
|
|
5975
|
+
}
|
|
5976
|
+
async updateAmmCache(perpMarketIndexes, txParams) {
|
|
5977
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateAmmCacheIx(perpMarketIndexes), txParams), [], this.opts);
|
|
5978
|
+
return txSig;
|
|
5979
|
+
}
|
|
5980
|
+
async getUpdateAmmCacheIx(perpMarketIndexes) {
|
|
5981
|
+
if (perpMarketIndexes.length > 50) {
|
|
5982
|
+
throw new Error('Cant update more than 50 markets at once');
|
|
5983
|
+
}
|
|
5984
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
5985
|
+
userAccounts: [],
|
|
5986
|
+
readablePerpMarketIndex: perpMarketIndexes,
|
|
5987
|
+
});
|
|
5988
|
+
return this.program.instruction.updateAmmCache({
|
|
5989
|
+
accounts: {
|
|
5990
|
+
state: await this.getStatePublicKey(),
|
|
5991
|
+
keeper: this.wallet.publicKey,
|
|
5992
|
+
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
5993
|
+
quoteMarket: this.getSpotMarketAccount(0).pubkey,
|
|
5994
|
+
},
|
|
5995
|
+
remainingAccounts,
|
|
5996
|
+
});
|
|
5997
|
+
}
|
|
5998
|
+
async updateConstituentOracleInfo(constituent) {
|
|
5999
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateConstituentOracleInfoIx(constituent), undefined), [], this.opts);
|
|
6000
|
+
return txSig;
|
|
6001
|
+
}
|
|
6002
|
+
async getUpdateConstituentOracleInfoIx(constituent) {
|
|
6003
|
+
const spotMarket = this.getSpotMarketAccount(constituent.spotMarketIndex);
|
|
6004
|
+
return this.program.instruction.updateConstituentOracleInfo({
|
|
6005
|
+
accounts: {
|
|
6006
|
+
keeper: this.wallet.publicKey,
|
|
6007
|
+
constituent: constituent.pubkey,
|
|
6008
|
+
state: await this.getStatePublicKey(),
|
|
6009
|
+
oracle: spotMarket.oracle,
|
|
6010
|
+
spotMarket: spotMarket.pubkey,
|
|
6011
|
+
},
|
|
6012
|
+
});
|
|
6013
|
+
}
|
|
6014
|
+
async lpPoolSwap(inMarketIndex, outMarketIndex, inAmount, minOutAmount, lpPool, userAuthority, txParams) {
|
|
6015
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getLpPoolSwapIx(inMarketIndex, outMarketIndex, inAmount, minOutAmount, lpPool, userAuthority), txParams), [], this.opts);
|
|
6016
|
+
return txSig;
|
|
6017
|
+
}
|
|
6018
|
+
async getLpPoolSwapIx(inMarketIndex, outMarketIndex, inAmount, minOutAmount, lpPool, userAuthority) {
|
|
6019
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
6020
|
+
userAccounts: [],
|
|
6021
|
+
readableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
|
|
6022
|
+
});
|
|
6023
|
+
const constituentInTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, inMarketIndex);
|
|
6024
|
+
const constituentOutTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, outMarketIndex);
|
|
6025
|
+
const userInTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccount(inMarketIndex).mint, userAuthority);
|
|
6026
|
+
const userOutTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccount(outMarketIndex).mint, userAuthority);
|
|
6027
|
+
const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, inMarketIndex);
|
|
6028
|
+
const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, outMarketIndex);
|
|
6029
|
+
const inMarketMint = this.getSpotMarketAccount(inMarketIndex).mint;
|
|
6030
|
+
const outMarketMint = this.getSpotMarketAccount(outMarketIndex).mint;
|
|
6031
|
+
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool);
|
|
6032
|
+
return this.program.instruction.lpPoolSwap(inMarketIndex, outMarketIndex, inAmount, minOutAmount, {
|
|
6033
|
+
remainingAccounts,
|
|
6034
|
+
accounts: {
|
|
6035
|
+
state: await this.getStatePublicKey(),
|
|
6036
|
+
lpPool,
|
|
6037
|
+
constituentTargetBase,
|
|
6038
|
+
constituentInTokenAccount,
|
|
6039
|
+
constituentOutTokenAccount,
|
|
6040
|
+
constituentCorrelations: (0, pda_1.getConstituentCorrelationsPublicKey)(this.program.programId, lpPool),
|
|
6041
|
+
userInTokenAccount,
|
|
6042
|
+
userOutTokenAccount,
|
|
6043
|
+
inConstituent,
|
|
6044
|
+
outConstituent,
|
|
6045
|
+
inMarketMint,
|
|
6046
|
+
outMarketMint,
|
|
6047
|
+
authority: this.wallet.publicKey,
|
|
6048
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
6049
|
+
},
|
|
6050
|
+
});
|
|
6051
|
+
}
|
|
6052
|
+
async viewLpPoolSwapFees(inMarketIndex, outMarketIndex, inAmount, inTargetWeight, outTargetWeight, lpPool, constituentTargetBase, constituentInTokenAccount, constituentOutTokenAccount, inConstituent, outConstituent, txParams) {
|
|
6053
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getViewLpPoolSwapFeesIx(inMarketIndex, outMarketIndex, inAmount, inTargetWeight, outTargetWeight, lpPool, constituentTargetBase, constituentInTokenAccount, constituentOutTokenAccount, inConstituent, outConstituent), txParams), [], this.opts);
|
|
6054
|
+
return txSig;
|
|
6055
|
+
}
|
|
6056
|
+
async getViewLpPoolSwapFeesIx(inMarketIndex, outMarketIndex, inAmount, inTargetWeight, outTargetWeight, lpPool, constituentTargetBase, constituentInTokenAccount, constituentOutTokenAccount, inConstituent, outConstituent) {
|
|
6057
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
6058
|
+
userAccounts: [],
|
|
6059
|
+
readableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
|
|
6060
|
+
});
|
|
6061
|
+
return this.program.instruction.viewLpPoolSwapFees(inMarketIndex, outMarketIndex, inAmount, inTargetWeight, outTargetWeight, {
|
|
6062
|
+
remainingAccounts,
|
|
6063
|
+
accounts: {
|
|
6064
|
+
driftSigner: this.getSignerPublicKey(),
|
|
6065
|
+
state: await this.getStatePublicKey(),
|
|
6066
|
+
lpPool,
|
|
6067
|
+
constituentTargetBase,
|
|
6068
|
+
constituentInTokenAccount,
|
|
6069
|
+
constituentOutTokenAccount,
|
|
6070
|
+
constituentCorrelations: (0, pda_1.getConstituentCorrelationsPublicKey)(this.program.programId, lpPool),
|
|
6071
|
+
inConstituent,
|
|
6072
|
+
outConstituent,
|
|
6073
|
+
authority: this.wallet.publicKey,
|
|
6074
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
6075
|
+
},
|
|
6076
|
+
});
|
|
6077
|
+
}
|
|
6078
|
+
async getCreateLpPoolTokenAccountIx(lpPool) {
|
|
6079
|
+
const lpMint = lpPool.mint;
|
|
6080
|
+
const userLpTokenAccount = await (0, pda_1.getLpPoolTokenTokenAccountPublicKey)(lpMint, this.wallet.publicKey);
|
|
6081
|
+
return this.createAssociatedTokenAccountIdempotentInstruction(userLpTokenAccount, this.wallet.publicKey, this.wallet.publicKey, lpMint);
|
|
6082
|
+
}
|
|
6083
|
+
async createLpPoolTokenAccount(lpPool, txParams) {
|
|
6084
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCreateLpPoolTokenAccountIx(lpPool), txParams), [], this.opts);
|
|
6085
|
+
return txSig;
|
|
6086
|
+
}
|
|
6087
|
+
async lpPoolAddLiquidity({ inMarketIndex, inAmount, minMintAmount, lpPool, txParams, }) {
|
|
6088
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getLpPoolAddLiquidityIx({
|
|
6089
|
+
inMarketIndex,
|
|
6090
|
+
inAmount,
|
|
6091
|
+
minMintAmount,
|
|
6092
|
+
lpPool,
|
|
6093
|
+
}), txParams), [], this.opts);
|
|
6094
|
+
return txSig;
|
|
6095
|
+
}
|
|
6096
|
+
async getLpPoolAddLiquidityIx({ inMarketIndex, inAmount, minMintAmount, lpPool, }) {
|
|
6097
|
+
const ixs = [];
|
|
6098
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
6099
|
+
userAccounts: [],
|
|
6100
|
+
writableSpotMarketIndexes: [inMarketIndex],
|
|
6101
|
+
});
|
|
6102
|
+
const spotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
6103
|
+
const inMarketMint = spotMarket.mint;
|
|
6104
|
+
const isSolMarket = inMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
6105
|
+
let wSolTokenAccount;
|
|
6106
|
+
if (isSolMarket) {
|
|
6107
|
+
const { ixs: wSolIxs, pubkey } = await this.getWrappedSolAccountCreationIxs(inAmount, true);
|
|
6108
|
+
wSolTokenAccount = pubkey;
|
|
6109
|
+
ixs.push(...wSolIxs);
|
|
6110
|
+
}
|
|
6111
|
+
const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, inMarketIndex);
|
|
6112
|
+
const userInTokenAccount = wSolTokenAccount !== null && wSolTokenAccount !== void 0 ? wSolTokenAccount : (await this.getAssociatedTokenAccount(inMarketIndex, false));
|
|
6113
|
+
const constituentInTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool.pubkey, inMarketIndex);
|
|
6114
|
+
const lpMint = lpPool.mint;
|
|
6115
|
+
const userLpTokenAccount = await (0, pda_1.getLpPoolTokenTokenAccountPublicKey)(lpMint, this.wallet.publicKey);
|
|
6116
|
+
if (!(await this.checkIfAccountExists(userLpTokenAccount))) {
|
|
6117
|
+
ixs.push(this.createAssociatedTokenAccountIdempotentInstruction(userLpTokenAccount, this.wallet.publicKey, this.wallet.publicKey, lpMint));
|
|
6118
|
+
}
|
|
6119
|
+
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool.pubkey);
|
|
6120
|
+
if (!lpPool.whitelistMint.equals(web3_js_1.PublicKey.default)) {
|
|
6121
|
+
const associatedTokenPublicKey = await (0, spl_token_1.getAssociatedTokenAddress)(lpPool.whitelistMint, this.wallet.publicKey);
|
|
6122
|
+
remainingAccounts.push({
|
|
6123
|
+
pubkey: associatedTokenPublicKey,
|
|
6124
|
+
isWritable: false,
|
|
6125
|
+
isSigner: false,
|
|
6126
|
+
});
|
|
6127
|
+
}
|
|
6128
|
+
const lpPoolAddLiquidityIx = this.program.instruction.lpPoolAddLiquidity(inMarketIndex, inAmount, minMintAmount, {
|
|
6129
|
+
remainingAccounts,
|
|
6130
|
+
accounts: {
|
|
6131
|
+
state: await this.getStatePublicKey(),
|
|
6132
|
+
lpPool: lpPool.pubkey,
|
|
6133
|
+
authority: this.wallet.publicKey,
|
|
6134
|
+
inMarketMint,
|
|
6135
|
+
inConstituent,
|
|
6136
|
+
userInTokenAccount,
|
|
6137
|
+
constituentInTokenAccount,
|
|
6138
|
+
userLpTokenAccount,
|
|
6139
|
+
lpMint,
|
|
6140
|
+
lpPoolTokenVault: (0, pda_1.getLpPoolTokenVaultPublicKey)(this.program.programId, lpPool.pubkey),
|
|
6141
|
+
constituentTargetBase,
|
|
6142
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
6143
|
+
},
|
|
6144
|
+
});
|
|
6145
|
+
ixs.push(lpPoolAddLiquidityIx);
|
|
6146
|
+
if (isSolMarket && wSolTokenAccount) {
|
|
6147
|
+
ixs.push((0, spl_token_1.createCloseAccountInstruction)(wSolTokenAccount, this.wallet.publicKey, this.wallet.publicKey));
|
|
6148
|
+
}
|
|
6149
|
+
return [...ixs];
|
|
6150
|
+
}
|
|
6151
|
+
async viewLpPoolAddLiquidityFees({ inMarketIndex, inAmount, lpPool, txParams, }) {
|
|
6152
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getViewLpPoolAddLiquidityFeesIx({
|
|
6153
|
+
inMarketIndex,
|
|
6154
|
+
inAmount,
|
|
6155
|
+
lpPool,
|
|
6156
|
+
}), txParams), [], this.opts);
|
|
6157
|
+
return txSig;
|
|
6158
|
+
}
|
|
6159
|
+
async getViewLpPoolAddLiquidityFeesIx({ inMarketIndex, inAmount, lpPool, }) {
|
|
6160
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
6161
|
+
userAccounts: [],
|
|
6162
|
+
readableSpotMarketIndexes: [inMarketIndex],
|
|
6163
|
+
});
|
|
6164
|
+
const spotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
6165
|
+
const inMarketMint = spotMarket.mint;
|
|
6166
|
+
const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, inMarketIndex);
|
|
6167
|
+
const lpMint = lpPool.mint;
|
|
6168
|
+
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool.pubkey);
|
|
6169
|
+
return this.program.instruction.viewLpPoolAddLiquidityFees(inMarketIndex, inAmount, {
|
|
6170
|
+
accounts: {
|
|
6171
|
+
state: await this.getStatePublicKey(),
|
|
6172
|
+
lpPool: lpPool.pubkey,
|
|
6173
|
+
authority: this.wallet.publicKey,
|
|
6174
|
+
inMarketMint,
|
|
6175
|
+
inConstituent,
|
|
6176
|
+
lpMint,
|
|
6177
|
+
constituentTargetBase,
|
|
6178
|
+
},
|
|
6179
|
+
remainingAccounts,
|
|
6180
|
+
});
|
|
6181
|
+
}
|
|
6182
|
+
async lpPoolRemoveLiquidity({ outMarketIndex, lpToBurn, minAmountOut, lpPool, txParams, }) {
|
|
6183
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getLpPoolRemoveLiquidityIx({
|
|
6184
|
+
outMarketIndex,
|
|
6185
|
+
lpToBurn,
|
|
6186
|
+
minAmountOut,
|
|
6187
|
+
lpPool,
|
|
6188
|
+
}), txParams), [], this.opts);
|
|
6189
|
+
return txSig;
|
|
6190
|
+
}
|
|
6191
|
+
async getLpPoolRemoveLiquidityIx({ outMarketIndex, lpToBurn, minAmountOut, lpPool, }) {
|
|
6192
|
+
const ixs = [];
|
|
6193
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
6194
|
+
userAccounts: [],
|
|
6195
|
+
writableSpotMarketIndexes: [outMarketIndex],
|
|
6196
|
+
});
|
|
6197
|
+
const spotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
6198
|
+
const outMarketMint = spotMarket.mint;
|
|
6199
|
+
const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
|
|
6200
|
+
if (outMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
|
|
6201
|
+
ixs.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.wallet.publicKey, await this.getAssociatedTokenAccount(outMarketIndex, false), this.wallet.publicKey, spotMarkets_1.WRAPPED_SOL_MINT));
|
|
6202
|
+
}
|
|
6203
|
+
const userOutTokenAccount = await this.getAssociatedTokenAccount(outMarketIndex, false);
|
|
6204
|
+
const constituentOutTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
|
|
6205
|
+
const lpMint = lpPool.mint;
|
|
6206
|
+
const userLpTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(lpMint, this.wallet.publicKey, true);
|
|
6207
|
+
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool.pubkey);
|
|
6208
|
+
ixs.push(this.program.instruction.lpPoolRemoveLiquidity(outMarketIndex, lpToBurn, minAmountOut, {
|
|
6209
|
+
remainingAccounts,
|
|
6210
|
+
accounts: {
|
|
6211
|
+
driftSigner: this.getSignerPublicKey(),
|
|
6212
|
+
state: await this.getStatePublicKey(),
|
|
6213
|
+
lpPool: lpPool.pubkey,
|
|
6214
|
+
authority: this.wallet.publicKey,
|
|
6215
|
+
outMarketMint,
|
|
6216
|
+
outConstituent,
|
|
6217
|
+
userOutTokenAccount,
|
|
6218
|
+
constituentOutTokenAccount,
|
|
6219
|
+
userLpTokenAccount,
|
|
6220
|
+
spotMarketTokenAccount: spotMarket.vault,
|
|
6221
|
+
lpMint,
|
|
6222
|
+
lpPoolTokenVault: (0, pda_1.getLpPoolTokenVaultPublicKey)(this.program.programId, lpPool.pubkey),
|
|
6223
|
+
constituentTargetBase,
|
|
6224
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
6225
|
+
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
6226
|
+
},
|
|
6227
|
+
}));
|
|
6228
|
+
return ixs;
|
|
6229
|
+
}
|
|
6230
|
+
async viewLpPoolRemoveLiquidityFees({ outMarketIndex, lpToBurn, lpPool, txParams, }) {
|
|
6231
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getViewLpPoolRemoveLiquidityFeesIx({
|
|
6232
|
+
outMarketIndex,
|
|
6233
|
+
lpToBurn,
|
|
6234
|
+
lpPool,
|
|
6235
|
+
}), txParams), [], this.opts);
|
|
6236
|
+
return txSig;
|
|
6237
|
+
}
|
|
6238
|
+
async getViewLpPoolRemoveLiquidityFeesIx({ outMarketIndex, lpToBurn, lpPool, }) {
|
|
6239
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
6240
|
+
userAccounts: [],
|
|
6241
|
+
writableSpotMarketIndexes: [outMarketIndex],
|
|
6242
|
+
});
|
|
6243
|
+
const spotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
6244
|
+
const outMarketMint = spotMarket.mint;
|
|
6245
|
+
const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
|
|
6246
|
+
const lpMint = lpPool.mint;
|
|
6247
|
+
const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool.pubkey);
|
|
6248
|
+
return this.program.instruction.viewLpPoolRemoveLiquidityFees(outMarketIndex, lpToBurn, {
|
|
6249
|
+
remainingAccounts,
|
|
6250
|
+
accounts: {
|
|
6251
|
+
state: await this.getStatePublicKey(),
|
|
6252
|
+
lpPool: lpPool.pubkey,
|
|
6253
|
+
authority: this.wallet.publicKey,
|
|
6254
|
+
outMarketMint,
|
|
6255
|
+
outConstituent,
|
|
6256
|
+
lpMint,
|
|
6257
|
+
constituentTargetBase,
|
|
6258
|
+
},
|
|
6259
|
+
});
|
|
6260
|
+
}
|
|
6261
|
+
async getAllLpPoolAddLiquidityIxs({ inMarketIndex, inAmount, minMintAmount, lpPool, }, constituentMap, includeUpdateConstituentOracleInfo = true, view = false) {
|
|
6262
|
+
const ixs = [];
|
|
6263
|
+
ixs.push(...(await this.getAllUpdateLpPoolAumIxs(lpPool, constituentMap, includeUpdateConstituentOracleInfo)));
|
|
6264
|
+
if (view) {
|
|
6265
|
+
ixs.push(await this.getViewLpPoolAddLiquidityFeesIx({
|
|
6266
|
+
inMarketIndex,
|
|
6267
|
+
inAmount,
|
|
6268
|
+
lpPool,
|
|
6269
|
+
}));
|
|
6270
|
+
}
|
|
6271
|
+
else {
|
|
6272
|
+
ixs.push(...(await this.getLpPoolAddLiquidityIx({
|
|
6273
|
+
inMarketIndex,
|
|
6274
|
+
inAmount,
|
|
6275
|
+
minMintAmount,
|
|
6276
|
+
lpPool,
|
|
6277
|
+
})));
|
|
6278
|
+
}
|
|
6279
|
+
return ixs;
|
|
6280
|
+
}
|
|
6281
|
+
async getAllLpPoolRemoveLiquidityIxs({ outMarketIndex, lpToBurn, minAmountOut, lpPool, }, constituentMap, includeUpdateConstituentOracleInfo = true, view = false) {
|
|
6282
|
+
const ixs = [];
|
|
6283
|
+
ixs.push(...(await this.getAllSettlePerpToLpPoolIxs(lpPool.lpPoolId, this.getPerpMarketAccounts()
|
|
6284
|
+
.filter((marketAccount) => marketAccount.lpStatus > 0)
|
|
6285
|
+
.map((marketAccount) => marketAccount.marketIndex))));
|
|
6286
|
+
ixs.push(...(await this.getAllUpdateLpPoolAumIxs(lpPool, constituentMap, includeUpdateConstituentOracleInfo)));
|
|
6287
|
+
if (view) {
|
|
6288
|
+
ixs.push(await this.getViewLpPoolRemoveLiquidityFeesIx({
|
|
6289
|
+
outMarketIndex,
|
|
6290
|
+
lpToBurn,
|
|
6291
|
+
lpPool,
|
|
6292
|
+
}));
|
|
6293
|
+
}
|
|
6294
|
+
else {
|
|
6295
|
+
ixs.push(...(await this.getLpPoolRemoveLiquidityIx({
|
|
6296
|
+
outMarketIndex,
|
|
6297
|
+
lpToBurn,
|
|
6298
|
+
minAmountOut,
|
|
6299
|
+
lpPool,
|
|
6300
|
+
})));
|
|
6301
|
+
}
|
|
6302
|
+
return ixs;
|
|
6303
|
+
}
|
|
6304
|
+
async getAllUpdateLpPoolAumIxs(lpPool, constituentMap, includeUpdateConstituentOracleInfo = true) {
|
|
6305
|
+
const ixs = [];
|
|
6306
|
+
const constituents = Array.from(constituentMap.values());
|
|
6307
|
+
if (includeUpdateConstituentOracleInfo) {
|
|
6308
|
+
for (const constituent of constituents) {
|
|
6309
|
+
ixs.push(await this.getUpdateConstituentOracleInfoIx(constituent));
|
|
6310
|
+
}
|
|
6311
|
+
}
|
|
6312
|
+
const spotMarketIndexes = constituents.map((constituent) => constituent.spotMarketIndex);
|
|
6313
|
+
ixs.push(await this.getUpdateLpPoolAumIxs(lpPool, spotMarketIndexes));
|
|
6314
|
+
return ixs;
|
|
6315
|
+
}
|
|
6316
|
+
async getAllUpdateConstituentTargetBaseIxs(perpMarketIndexes, lpPool, constituentMap, includeUpdateConstituentOracleInfo = true) {
|
|
6317
|
+
const ixs = [];
|
|
6318
|
+
ixs.push(await this.getUpdateAmmCacheIx(perpMarketIndexes));
|
|
6319
|
+
const constituents = Array.from(constituentMap.values());
|
|
6320
|
+
if (includeUpdateConstituentOracleInfo) {
|
|
6321
|
+
for (const constituent of constituents) {
|
|
6322
|
+
ixs.push(await this.getUpdateConstituentOracleInfoIx(constituent));
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6325
|
+
ixs.push(await this.getUpdateLpConstituentTargetBaseIx(lpPool.lpPoolId, Array.from(constituentMap.values()).map((constituent) => constituent.pubkey)));
|
|
6326
|
+
ixs.push(...(await this.getAllUpdateLpPoolAumIxs(lpPool, constituentMap, false)));
|
|
6327
|
+
return ixs;
|
|
6328
|
+
}
|
|
6329
|
+
async getAllLpPoolSwapIxs(lpPool, constituentMap, inMarketIndex, outMarketIndex, inAmount, minOutAmount, userAuthority) {
|
|
6330
|
+
const ixs = [];
|
|
6331
|
+
ixs.push(...(await this.getAllUpdateLpPoolAumIxs(lpPool, constituentMap)));
|
|
6332
|
+
ixs.push(await this.getLpPoolSwapIx(inMarketIndex, outMarketIndex, inAmount, minOutAmount, lpPool.pubkey, userAuthority));
|
|
6333
|
+
return ixs;
|
|
6334
|
+
}
|
|
6335
|
+
async settlePerpToLpPool(lpPoolId, perpMarketIndexes) {
|
|
6336
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getSettlePerpToLpPoolIx(lpPoolId, perpMarketIndexes), undefined), [], this.opts);
|
|
6337
|
+
return txSig;
|
|
6338
|
+
}
|
|
6339
|
+
async getSettlePerpToLpPoolIx(lpPoolId, perpMarketIndexes) {
|
|
6340
|
+
const remainingAccounts = [];
|
|
6341
|
+
remainingAccounts.push(...perpMarketIndexes.map((index) => {
|
|
6342
|
+
return {
|
|
6343
|
+
pubkey: this.getPerpMarketAccount(index).pubkey,
|
|
6344
|
+
isSigner: false,
|
|
6345
|
+
isWritable: true,
|
|
6346
|
+
};
|
|
6347
|
+
}));
|
|
6348
|
+
const quoteSpotMarketAccount = this.getQuoteSpotMarketAccount();
|
|
6349
|
+
const lpPool = (0, pda_1.getLpPoolPublicKey)(this.program.programId, lpPoolId);
|
|
6350
|
+
return this.program.instruction.settlePerpToLpPool({
|
|
6351
|
+
accounts: {
|
|
6352
|
+
driftSigner: this.getSignerPublicKey(),
|
|
6353
|
+
state: await this.getStatePublicKey(),
|
|
6354
|
+
keeper: this.wallet.publicKey,
|
|
6355
|
+
ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
|
|
6356
|
+
quoteMarket: quoteSpotMarketAccount.pubkey,
|
|
6357
|
+
constituent: (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, 0),
|
|
6358
|
+
constituentQuoteTokenAccount: (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, 0),
|
|
6359
|
+
lpPool,
|
|
6360
|
+
quoteTokenVault: quoteSpotMarketAccount.vault,
|
|
6361
|
+
tokenProgram: this.getTokenProgramForSpotMarket(quoteSpotMarketAccount),
|
|
6362
|
+
},
|
|
6363
|
+
remainingAccounts,
|
|
6364
|
+
});
|
|
6365
|
+
}
|
|
6366
|
+
async getAllSettlePerpToLpPoolIxs(lpPoolId, marketIndexes) {
|
|
6367
|
+
const ixs = [];
|
|
6368
|
+
ixs.push(await this.getUpdateAmmCacheIx(marketIndexes));
|
|
6369
|
+
ixs.push(await this.getSettlePerpToLpPoolIx(lpPoolId, marketIndexes));
|
|
6370
|
+
return ixs;
|
|
6371
|
+
}
|
|
6372
|
+
/**
|
|
6373
|
+
* Below here are the transaction sending functions
|
|
6374
|
+
*/
|
|
5916
6375
|
handleSignedTransaction(signedTxs) {
|
|
5917
6376
|
if (this.enableMetricsEvents && this.metricsEventEmitter) {
|
|
5918
6377
|
this.metricsEventEmitter.emit('txSigned', signedTxs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { Commitment, ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
|
|
4
|
-
import { IWallet, TxParams
|
|
4
|
+
import { IWallet, TxParams } from './types';
|
|
5
5
|
import { OracleInfo } from './oracles/types';
|
|
6
6
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
7
7
|
import { DriftEnv } from './config';
|
|
@@ -11,9 +11,6 @@ import { GrpcConfigs, ResubOpts, DelistedMarketSetting } from './accounts/types'
|
|
|
11
11
|
import { Coder, Program } from '@coral-xyz/anchor';
|
|
12
12
|
import { WebSocketAccountSubscriber } from './accounts/webSocketAccountSubscriber';
|
|
13
13
|
import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscriberV2';
|
|
14
|
-
import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
15
|
-
import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
|
|
16
|
-
import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber';
|
|
17
14
|
import { grpcDriftClientAccountSubscriberV2 } from './accounts/grpcDriftClientAccountSubscriberV2';
|
|
18
15
|
import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
19
16
|
import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
|
|
@@ -59,10 +56,8 @@ export type DriftClientSubscriptionConfig = {
|
|
|
59
56
|
resubTimeoutMs?: number;
|
|
60
57
|
logResubMessages?: boolean;
|
|
61
58
|
commitment?: Commitment;
|
|
62
|
-
programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
63
59
|
perpMarketAccountSubscriber?: new (accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, commitment?: Commitment) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
|
|
64
|
-
|
|
65
|
-
driftClientAccountSubscriber?: new (program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting) => WebSocketDriftClientAccountSubscriber | WebSocketDriftClientAccountSubscriberV2;
|
|
60
|
+
oracleAccountSubscriber?: new (accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, commitment?: Commitment) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
|
|
66
61
|
} | {
|
|
67
62
|
type: 'polling';
|
|
68
63
|
accountLoader: BulkAccountLoader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driftClientConfig.d.ts","sourceRoot":"","sources":["../../src/driftClientConfig.ts"],"names":[],"mappings":";;AAAA,OAAO,EACN,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"driftClientConfig.d.ts","sourceRoot":"","s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