@drift-labs/sdk 2.31.1-beta.10 → 2.31.1-beta.12
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/driftClient.d.ts +24 -1
- package/lib/driftClient.js +134 -173
- package/lib/idl/drift.json +31 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/marinade/index.d.ts +11 -0
- package/lib/marinade/index.js +36 -0
- package/lib/marinade/types.d.ts +1963 -0
- package/lib/marinade/types.js +1965 -0
- package/package.json +1 -1
- package/src/driftClient.ts +255 -190
- package/src/idl/drift.json +31 -1
- package/src/index.ts +1 -0
- package/src/marinade/idl/idl.json +1962 -0
- package/src/marinade/index.ts +64 -0
- package/src/marinade/types.ts +3925 -0
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -117,12 +117,13 @@ import { castNumberToSpotPrecision } from './math/spotMarket';
|
|
|
117
117
|
import { JupiterClient, Route, SwapMode } from './jupiter/jupiterClient';
|
|
118
118
|
import { getNonIdleUserFilter } from './memcmp';
|
|
119
119
|
import { UserStatsSubscriptionConfig } from './userStatsConfig';
|
|
120
|
+
import { getMarinadeDepositIx, getMarinadeFinanceProgram } from './marinade';
|
|
120
121
|
|
|
121
122
|
type RemainingAccountParams = {
|
|
122
123
|
userAccounts: UserAccount[];
|
|
123
124
|
writablePerpMarketIndexes?: number[];
|
|
124
125
|
writableSpotMarketIndexes?: number[];
|
|
125
|
-
readablePerpMarketIndex?: number;
|
|
126
|
+
readablePerpMarketIndex?: number | number[];
|
|
126
127
|
readableSpotMarketIndexes?: number[];
|
|
127
128
|
useMarketLastSlotCache?: boolean;
|
|
128
129
|
};
|
|
@@ -148,6 +149,8 @@ export class DriftClient {
|
|
|
148
149
|
txSender: TxSender;
|
|
149
150
|
perpMarketLastSlotCache = new Map<number, number>();
|
|
150
151
|
spotMarketLastSlotCache = new Map<number, number>();
|
|
152
|
+
mustIncludePerpMarketIndexes = new Set<number>();
|
|
153
|
+
mustIncludeSpotMarketIndexes = new Set<number>();
|
|
151
154
|
authority: PublicKey;
|
|
152
155
|
marketLookupTable: PublicKey;
|
|
153
156
|
lookupTableAccount: AddressLookupTableAccount;
|
|
@@ -1197,6 +1200,29 @@ export class DriftClient {
|
|
|
1197
1200
|
return amount.mul(PRICE_PRECISION);
|
|
1198
1201
|
}
|
|
1199
1202
|
|
|
1203
|
+
/**
|
|
1204
|
+
* Each drift instruction must include perp and sport market accounts in the ix remaining accounts.
|
|
1205
|
+
* Use this function to force a subset of markets to be included in the remaining accounts for every ix
|
|
1206
|
+
*
|
|
1207
|
+
* @param perpMarketIndexes
|
|
1208
|
+
* @param spotMarketIndexes
|
|
1209
|
+
*/
|
|
1210
|
+
public mustIncludeMarketsInIx({
|
|
1211
|
+
perpMarketIndexes,
|
|
1212
|
+
spotMarketIndexes,
|
|
1213
|
+
}: {
|
|
1214
|
+
perpMarketIndexes: number[];
|
|
1215
|
+
spotMarketIndexes: number[];
|
|
1216
|
+
}): void {
|
|
1217
|
+
perpMarketIndexes.forEach((perpMarketIndex) => {
|
|
1218
|
+
this.mustIncludePerpMarketIndexes.add(perpMarketIndex);
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
spotMarketIndexes.forEach((spotMarketIndex) => {
|
|
1222
|
+
this.mustIncludeSpotMarketIndexes.add(spotMarketIndex);
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1200
1226
|
getRemainingAccounts(params: RemainingAccountParams): AccountMeta[] {
|
|
1201
1227
|
const { oracleAccountMap, spotMarketAccountMap, perpMarketAccountMap } =
|
|
1202
1228
|
this.getRemainingAccountMapsForUsers(params.userAccounts);
|
|
@@ -1210,32 +1236,13 @@ export class DriftClient {
|
|
|
1210
1236
|
// if cache has more recent slot than user positions account slot, add market to remaining accounts
|
|
1211
1237
|
// otherwise remove from slot
|
|
1212
1238
|
if (slot > lastUserSlot) {
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
|
|
1220
|
-
pubkey: perpMarketAccount.amm.oracle,
|
|
1221
|
-
isSigner: false,
|
|
1222
|
-
isWritable: false,
|
|
1223
|
-
});
|
|
1224
|
-
const spotMarketAccount = this.getSpotMarketAccount(
|
|
1225
|
-
perpMarketAccount.quoteSpotMarketIndex
|
|
1239
|
+
this.addPerpMarketToRemainingAccountMaps(
|
|
1240
|
+
marketIndex,
|
|
1241
|
+
false,
|
|
1242
|
+
oracleAccountMap,
|
|
1243
|
+
spotMarketAccountMap,
|
|
1244
|
+
perpMarketAccountMap
|
|
1226
1245
|
);
|
|
1227
|
-
spotMarketAccountMap.set(perpMarketAccount.quoteSpotMarketIndex, {
|
|
1228
|
-
pubkey: spotMarketAccount.pubkey,
|
|
1229
|
-
isSigner: false,
|
|
1230
|
-
isWritable: false,
|
|
1231
|
-
});
|
|
1232
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1233
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1234
|
-
pubkey: spotMarketAccount.oracle,
|
|
1235
|
-
isSigner: false,
|
|
1236
|
-
isWritable: false,
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
1246
|
} else {
|
|
1240
1247
|
this.perpMarketLastSlotCache.delete(marketIndex);
|
|
1241
1248
|
}
|
|
@@ -1248,19 +1255,12 @@ export class DriftClient {
|
|
|
1248
1255
|
// if cache has more recent slot than user positions account slot, add market to remaining accounts
|
|
1249
1256
|
// otherwise remove from slot
|
|
1250
1257
|
if (slot > lastUserSlot) {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1258
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1259
|
-
pubkey: spotMarketAccount.oracle,
|
|
1260
|
-
isSigner: false,
|
|
1261
|
-
isWritable: false,
|
|
1262
|
-
});
|
|
1263
|
-
}
|
|
1258
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1259
|
+
marketIndex,
|
|
1260
|
+
false,
|
|
1261
|
+
oracleAccountMap,
|
|
1262
|
+
spotMarketAccountMap
|
|
1263
|
+
);
|
|
1264
1264
|
} else {
|
|
1265
1265
|
this.spotMarketLastSlotCache.delete(marketIndex);
|
|
1266
1266
|
}
|
|
@@ -1268,106 +1268,72 @@ export class DriftClient {
|
|
|
1268
1268
|
}
|
|
1269
1269
|
|
|
1270
1270
|
if (params.readablePerpMarketIndex !== undefined) {
|
|
1271
|
-
const
|
|
1271
|
+
const readablePerpMarketIndexes = Array.isArray(
|
|
1272
1272
|
params.readablePerpMarketIndex
|
|
1273
|
-
)
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
const spotMarketAccount = this.getSpotMarketAccount(
|
|
1285
|
-
perpMarketAccount.quoteSpotMarketIndex
|
|
1286
|
-
);
|
|
1287
|
-
spotMarketAccountMap.set(perpMarketAccount.quoteSpotMarketIndex, {
|
|
1288
|
-
pubkey: spotMarketAccount.pubkey,
|
|
1289
|
-
isSigner: false,
|
|
1290
|
-
isWritable: false,
|
|
1291
|
-
});
|
|
1292
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1293
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1294
|
-
pubkey: spotMarketAccount.oracle,
|
|
1295
|
-
isSigner: false,
|
|
1296
|
-
isWritable: false,
|
|
1297
|
-
});
|
|
1273
|
+
)
|
|
1274
|
+
? params.readablePerpMarketIndex
|
|
1275
|
+
: [params.readablePerpMarketIndex];
|
|
1276
|
+
for (const marketIndex of readablePerpMarketIndexes) {
|
|
1277
|
+
this.addPerpMarketToRemainingAccountMaps(
|
|
1278
|
+
marketIndex,
|
|
1279
|
+
false,
|
|
1280
|
+
oracleAccountMap,
|
|
1281
|
+
spotMarketAccountMap,
|
|
1282
|
+
perpMarketAccountMap
|
|
1283
|
+
);
|
|
1298
1284
|
}
|
|
1299
1285
|
}
|
|
1300
1286
|
|
|
1287
|
+
for (const perpMarketIndex of this.mustIncludePerpMarketIndexes.values()) {
|
|
1288
|
+
this.addPerpMarketToRemainingAccountMaps(
|
|
1289
|
+
perpMarketIndex,
|
|
1290
|
+
false,
|
|
1291
|
+
oracleAccountMap,
|
|
1292
|
+
spotMarketAccountMap,
|
|
1293
|
+
perpMarketAccountMap
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1301
1297
|
if (params.readableSpotMarketIndexes !== undefined) {
|
|
1302
1298
|
for (const readableSpotMarketIndex of params.readableSpotMarketIndexes) {
|
|
1303
|
-
|
|
1304
|
-
readableSpotMarketIndex
|
|
1299
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1300
|
+
readableSpotMarketIndex,
|
|
1301
|
+
false,
|
|
1302
|
+
oracleAccountMap,
|
|
1303
|
+
spotMarketAccountMap
|
|
1305
1304
|
);
|
|
1306
|
-
spotMarketAccountMap.set(readableSpotMarketIndex, {
|
|
1307
|
-
pubkey: spotMarketAccount.pubkey,
|
|
1308
|
-
isSigner: false,
|
|
1309
|
-
isWritable: false,
|
|
1310
|
-
});
|
|
1311
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1312
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1313
|
-
pubkey: spotMarketAccount.oracle,
|
|
1314
|
-
isSigner: false,
|
|
1315
|
-
isWritable: false,
|
|
1316
|
-
});
|
|
1317
|
-
}
|
|
1318
1305
|
}
|
|
1319
1306
|
}
|
|
1320
1307
|
|
|
1308
|
+
for (const spotMarketIndex of this.mustIncludeSpotMarketIndexes.values()) {
|
|
1309
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1310
|
+
spotMarketIndex,
|
|
1311
|
+
false,
|
|
1312
|
+
oracleAccountMap,
|
|
1313
|
+
spotMarketAccountMap
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1321
1317
|
if (params.writablePerpMarketIndexes !== undefined) {
|
|
1322
1318
|
for (const writablePerpMarketIndex of params.writablePerpMarketIndexes) {
|
|
1323
|
-
|
|
1324
|
-
writablePerpMarketIndex
|
|
1319
|
+
this.addPerpMarketToRemainingAccountMaps(
|
|
1320
|
+
writablePerpMarketIndex,
|
|
1321
|
+
true,
|
|
1322
|
+
oracleAccountMap,
|
|
1323
|
+
spotMarketAccountMap,
|
|
1324
|
+
perpMarketAccountMap
|
|
1325
1325
|
);
|
|
1326
|
-
perpMarketAccountMap.set(writablePerpMarketIndex, {
|
|
1327
|
-
pubkey: perpMarketAccount.pubkey,
|
|
1328
|
-
isSigner: false,
|
|
1329
|
-
isWritable: true,
|
|
1330
|
-
});
|
|
1331
|
-
oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
|
|
1332
|
-
pubkey: perpMarketAccount.amm.oracle,
|
|
1333
|
-
isSigner: false,
|
|
1334
|
-
isWritable: false,
|
|
1335
|
-
});
|
|
1336
|
-
const spotMarketAccount = this.getSpotMarketAccount(
|
|
1337
|
-
perpMarketAccount.quoteSpotMarketIndex
|
|
1338
|
-
);
|
|
1339
|
-
spotMarketAccountMap.set(perpMarketAccount.quoteSpotMarketIndex, {
|
|
1340
|
-
pubkey: spotMarketAccount.pubkey,
|
|
1341
|
-
isSigner: false,
|
|
1342
|
-
isWritable: false,
|
|
1343
|
-
});
|
|
1344
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1345
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1346
|
-
pubkey: spotMarketAccount.oracle,
|
|
1347
|
-
isSigner: false,
|
|
1348
|
-
isWritable: false,
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
1326
|
}
|
|
1352
1327
|
}
|
|
1353
1328
|
|
|
1354
1329
|
if (params.writableSpotMarketIndexes !== undefined) {
|
|
1355
1330
|
for (const writableSpotMarketIndex of params.writableSpotMarketIndexes) {
|
|
1356
|
-
|
|
1357
|
-
writableSpotMarketIndex
|
|
1331
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1332
|
+
writableSpotMarketIndex,
|
|
1333
|
+
true,
|
|
1334
|
+
oracleAccountMap,
|
|
1335
|
+
spotMarketAccountMap
|
|
1358
1336
|
);
|
|
1359
|
-
spotMarketAccountMap.set(spotMarketAccount.marketIndex, {
|
|
1360
|
-
pubkey: spotMarketAccount.pubkey,
|
|
1361
|
-
isSigner: false,
|
|
1362
|
-
isWritable: true,
|
|
1363
|
-
});
|
|
1364
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1365
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1366
|
-
pubkey: spotMarketAccount.oracle,
|
|
1367
|
-
isSigner: false,
|
|
1368
|
-
isWritable: false,
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
1337
|
}
|
|
1372
1338
|
}
|
|
1373
1339
|
|
|
@@ -1378,6 +1344,53 @@ export class DriftClient {
|
|
|
1378
1344
|
];
|
|
1379
1345
|
}
|
|
1380
1346
|
|
|
1347
|
+
addPerpMarketToRemainingAccountMaps(
|
|
1348
|
+
marketIndex: number,
|
|
1349
|
+
writable: boolean,
|
|
1350
|
+
oracleAccountMap: Map<string, AccountMeta>,
|
|
1351
|
+
spotMarketAccountMap: Map<number, AccountMeta>,
|
|
1352
|
+
perpMarketAccountMap: Map<number, AccountMeta>
|
|
1353
|
+
): void {
|
|
1354
|
+
const perpMarketAccount = this.getPerpMarketAccount(marketIndex);
|
|
1355
|
+
perpMarketAccountMap.set(marketIndex, {
|
|
1356
|
+
pubkey: perpMarketAccount.pubkey,
|
|
1357
|
+
isSigner: false,
|
|
1358
|
+
isWritable: writable,
|
|
1359
|
+
});
|
|
1360
|
+
oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
|
|
1361
|
+
pubkey: perpMarketAccount.amm.oracle,
|
|
1362
|
+
isSigner: false,
|
|
1363
|
+
isWritable: false,
|
|
1364
|
+
});
|
|
1365
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1366
|
+
perpMarketAccount.quoteSpotMarketIndex,
|
|
1367
|
+
false,
|
|
1368
|
+
oracleAccountMap,
|
|
1369
|
+
spotMarketAccountMap
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
addSpotMarketToRemainingAccountMaps(
|
|
1374
|
+
marketIndex: number,
|
|
1375
|
+
writable: boolean,
|
|
1376
|
+
oracleAccountMap: Map<string, AccountMeta>,
|
|
1377
|
+
spotMarketAccountMap: Map<number, AccountMeta>
|
|
1378
|
+
): void {
|
|
1379
|
+
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
1380
|
+
spotMarketAccountMap.set(spotMarketAccount.marketIndex, {
|
|
1381
|
+
pubkey: spotMarketAccount.pubkey,
|
|
1382
|
+
isSigner: false,
|
|
1383
|
+
isWritable: writable,
|
|
1384
|
+
});
|
|
1385
|
+
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1386
|
+
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1387
|
+
pubkey: spotMarketAccount.oracle,
|
|
1388
|
+
isSigner: false,
|
|
1389
|
+
isWritable: false,
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1381
1394
|
getRemainingAccountMapsForUsers(userAccounts: UserAccount[]): {
|
|
1382
1395
|
oracleAccountMap: Map<string, AccountMeta>;
|
|
1383
1396
|
spotMarketAccountMap: Map<number, AccountMeta>;
|
|
@@ -1390,73 +1403,35 @@ export class DriftClient {
|
|
|
1390
1403
|
for (const userAccount of userAccounts) {
|
|
1391
1404
|
for (const spotPosition of userAccount.spotPositions) {
|
|
1392
1405
|
if (!isSpotPositionAvailable(spotPosition)) {
|
|
1393
|
-
|
|
1394
|
-
spotPosition.marketIndex
|
|
1406
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1407
|
+
spotPosition.marketIndex,
|
|
1408
|
+
false,
|
|
1409
|
+
oracleAccountMap,
|
|
1410
|
+
spotMarketAccountMap
|
|
1395
1411
|
);
|
|
1396
|
-
spotMarketAccountMap.set(spotPosition.marketIndex, {
|
|
1397
|
-
pubkey: spotMarket.pubkey,
|
|
1398
|
-
isSigner: false,
|
|
1399
|
-
isWritable: false,
|
|
1400
|
-
});
|
|
1401
|
-
|
|
1402
|
-
if (!spotMarket.oracle.equals(PublicKey.default)) {
|
|
1403
|
-
oracleAccountMap.set(spotMarket.oracle.toString(), {
|
|
1404
|
-
pubkey: spotMarket.oracle,
|
|
1405
|
-
isSigner: false,
|
|
1406
|
-
isWritable: false,
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
1412
|
|
|
1410
1413
|
if (
|
|
1411
1414
|
!spotPosition.openAsks.eq(ZERO) ||
|
|
1412
1415
|
!spotPosition.openBids.eq(ZERO)
|
|
1413
1416
|
) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (!quoteSpotMarket.oracle.equals(PublicKey.default)) {
|
|
1421
|
-
oracleAccountMap.set(quoteSpotMarket.oracle.toString(), {
|
|
1422
|
-
pubkey: quoteSpotMarket.oracle,
|
|
1423
|
-
isSigner: false,
|
|
1424
|
-
isWritable: false,
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1417
|
+
this.addSpotMarketToRemainingAccountMaps(
|
|
1418
|
+
QUOTE_SPOT_MARKET_INDEX,
|
|
1419
|
+
false,
|
|
1420
|
+
oracleAccountMap,
|
|
1421
|
+
spotMarketAccountMap
|
|
1422
|
+
);
|
|
1427
1423
|
}
|
|
1428
1424
|
}
|
|
1429
1425
|
}
|
|
1430
1426
|
for (const position of userAccount.perpPositions) {
|
|
1431
1427
|
if (!positionIsAvailable(position)) {
|
|
1432
|
-
|
|
1433
|
-
position.marketIndex
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
isSigner: false,
|
|
1439
|
-
});
|
|
1440
|
-
oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
|
|
1441
|
-
pubkey: perpMarketAccount.amm.oracle,
|
|
1442
|
-
isWritable: false,
|
|
1443
|
-
isSigner: false,
|
|
1444
|
-
});
|
|
1445
|
-
const spotMarketAccount = this.getSpotMarketAccount(
|
|
1446
|
-
perpMarketAccount.quoteSpotMarketIndex
|
|
1428
|
+
this.addPerpMarketToRemainingAccountMaps(
|
|
1429
|
+
position.marketIndex,
|
|
1430
|
+
false,
|
|
1431
|
+
oracleAccountMap,
|
|
1432
|
+
spotMarketAccountMap,
|
|
1433
|
+
perpMarketAccountMap
|
|
1447
1434
|
);
|
|
1448
|
-
spotMarketAccountMap.set(perpMarketAccount.quoteSpotMarketIndex, {
|
|
1449
|
-
pubkey: spotMarketAccount.pubkey,
|
|
1450
|
-
isSigner: false,
|
|
1451
|
-
isWritable: false,
|
|
1452
|
-
});
|
|
1453
|
-
if (!spotMarketAccount.oracle.equals(PublicKey.default)) {
|
|
1454
|
-
oracleAccountMap.set(spotMarketAccount.oracle.toString(), {
|
|
1455
|
-
pubkey: spotMarketAccount.oracle,
|
|
1456
|
-
isSigner: false,
|
|
1457
|
-
isWritable: false,
|
|
1458
|
-
});
|
|
1459
|
-
}
|
|
1460
1435
|
}
|
|
1461
1436
|
}
|
|
1462
1437
|
}
|
|
@@ -2815,32 +2790,65 @@ export class DriftClient {
|
|
|
2815
2790
|
placeOrderParams: OrderParams[],
|
|
2816
2791
|
txParams?: TxParams
|
|
2817
2792
|
): Promise<TransactionSignature> {
|
|
2818
|
-
const
|
|
2793
|
+
const ixs = [
|
|
2819
2794
|
await this.getCancelOrdersIx(
|
|
2820
2795
|
cancelOrderParams.marketType,
|
|
2821
2796
|
cancelOrderParams.marketIndex,
|
|
2822
2797
|
cancelOrderParams.direction
|
|
2823
2798
|
),
|
|
2824
|
-
|
|
2825
|
-
|
|
2799
|
+
await this.getPlaceOrdersIx(placeOrderParams),
|
|
2800
|
+
];
|
|
2801
|
+
const tx = await this.buildTransaction(ixs, txParams);
|
|
2802
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2803
|
+
return txSig;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
public async placeOrders(
|
|
2807
|
+
params: OrderParams[],
|
|
2808
|
+
txParams?: TxParams
|
|
2809
|
+
): Promise<TransactionSignature> {
|
|
2810
|
+
const { txSig } = await this.sendTransaction(
|
|
2811
|
+
await this.buildTransaction(
|
|
2812
|
+
await this.getPlaceOrdersIx(params),
|
|
2813
|
+
txParams
|
|
2814
|
+
),
|
|
2815
|
+
[],
|
|
2816
|
+
this.opts
|
|
2826
2817
|
);
|
|
2818
|
+
return txSig;
|
|
2819
|
+
}
|
|
2827
2820
|
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2821
|
+
public async getPlaceOrdersIx(
|
|
2822
|
+
params: OrderParams[]
|
|
2823
|
+
): Promise<TransactionInstruction> {
|
|
2824
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2825
|
+
|
|
2826
|
+
const readablePerpMarketIndex: number[] = [];
|
|
2827
|
+
const readableSpotMarketIndexes: number[] = [];
|
|
2828
|
+
for (const param of params) {
|
|
2829
|
+
if (isVariant(param.marketType, 'perp')) {
|
|
2830
|
+
readablePerpMarketIndex.push(param.marketIndex);
|
|
2836
2831
|
} else {
|
|
2837
|
-
|
|
2832
|
+
readableSpotMarketIndexes.push(param.marketIndex);
|
|
2838
2833
|
}
|
|
2839
|
-
tx.add(ix);
|
|
2840
2834
|
}
|
|
2841
2835
|
|
|
2842
|
-
const
|
|
2843
|
-
|
|
2836
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
2837
|
+
userAccounts: [this.getUserAccount()],
|
|
2838
|
+
readablePerpMarketIndex,
|
|
2839
|
+
readableSpotMarketIndexes,
|
|
2840
|
+
useMarketLastSlotCache: true,
|
|
2841
|
+
});
|
|
2842
|
+
|
|
2843
|
+
return await this.program.instruction.placeOrders(params, {
|
|
2844
|
+
accounts: {
|
|
2845
|
+
state: await this.getStatePublicKey(),
|
|
2846
|
+
user: userAccountPublicKey,
|
|
2847
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
2848
|
+
authority: this.wallet.publicKey,
|
|
2849
|
+
},
|
|
2850
|
+
remainingAccounts,
|
|
2851
|
+
});
|
|
2844
2852
|
}
|
|
2845
2853
|
|
|
2846
2854
|
public async fillPerpOrder(
|
|
@@ -3540,6 +3548,63 @@ export class DriftClient {
|
|
|
3540
3548
|
return { beginSwapIx, endSwapIx };
|
|
3541
3549
|
}
|
|
3542
3550
|
|
|
3551
|
+
public async stakeForMSOL({ amount }: { amount: BN }): Promise<TxSigAndSlot> {
|
|
3552
|
+
const ixs = await this.getStakeForMSOLIx({ amount });
|
|
3553
|
+
const tx = await this.buildTransaction(ixs);
|
|
3554
|
+
return this.sendTransaction(tx);
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
public async getStakeForMSOLIx({
|
|
3558
|
+
amount,
|
|
3559
|
+
}: {
|
|
3560
|
+
amount: BN;
|
|
3561
|
+
}): Promise<TransactionInstruction[]> {
|
|
3562
|
+
const wSOLMint = this.getSpotMarketAccount(1).mint;
|
|
3563
|
+
const mSOLAccount = await this.getAssociatedTokenAccount(2);
|
|
3564
|
+
const wSOLAccount = await this.getAssociatedTokenAccount(1, false);
|
|
3565
|
+
|
|
3566
|
+
const wSOLAccountExists = await this.checkIfAccountExists(wSOLAccount);
|
|
3567
|
+
|
|
3568
|
+
const closeWSOLIx = createCloseAccountInstruction(
|
|
3569
|
+
wSOLAccount,
|
|
3570
|
+
this.wallet.publicKey,
|
|
3571
|
+
this.wallet.publicKey
|
|
3572
|
+
);
|
|
3573
|
+
|
|
3574
|
+
const createWSOLIx =
|
|
3575
|
+
await this.createAssociatedTokenAccountIdempotentInstruction(
|
|
3576
|
+
wSOLAccount,
|
|
3577
|
+
this.wallet.publicKey,
|
|
3578
|
+
this.wallet.publicKey,
|
|
3579
|
+
wSOLMint
|
|
3580
|
+
);
|
|
3581
|
+
|
|
3582
|
+
const { beginSwapIx, endSwapIx } = await this.getSwapIx({
|
|
3583
|
+
inMarketIndex: 1,
|
|
3584
|
+
outMarketIndex: 2,
|
|
3585
|
+
amountIn: amount,
|
|
3586
|
+
inTokenAccount: wSOLAccount,
|
|
3587
|
+
outTokenAccount: mSOLAccount,
|
|
3588
|
+
});
|
|
3589
|
+
|
|
3590
|
+
const program = getMarinadeFinanceProgram(this.provider);
|
|
3591
|
+
const depositIx = await getMarinadeDepositIx({
|
|
3592
|
+
program,
|
|
3593
|
+
mSOLAccount: mSOLAccount,
|
|
3594
|
+
transferFrom: this.wallet.publicKey,
|
|
3595
|
+
amount,
|
|
3596
|
+
});
|
|
3597
|
+
|
|
3598
|
+
const ixs = [];
|
|
3599
|
+
|
|
3600
|
+
if (!wSOLAccountExists) {
|
|
3601
|
+
ixs.push(createWSOLIx);
|
|
3602
|
+
}
|
|
3603
|
+
ixs.push(beginSwapIx, closeWSOLIx, depositIx, createWSOLIx, endSwapIx);
|
|
3604
|
+
|
|
3605
|
+
return ixs;
|
|
3606
|
+
}
|
|
3607
|
+
|
|
3543
3608
|
public async triggerOrder(
|
|
3544
3609
|
userAccountPublicKey: PublicKey,
|
|
3545
3610
|
user: UserAccount,
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.31.1-beta.
|
|
2
|
+
"version": "2.31.1-beta.12",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -710,6 +710,36 @@
|
|
|
710
710
|
}
|
|
711
711
|
]
|
|
712
712
|
},
|
|
713
|
+
{
|
|
714
|
+
"name": "placeOrders",
|
|
715
|
+
"accounts": [
|
|
716
|
+
{
|
|
717
|
+
"name": "state",
|
|
718
|
+
"isMut": false,
|
|
719
|
+
"isSigner": false
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
"name": "user",
|
|
723
|
+
"isMut": true,
|
|
724
|
+
"isSigner": false
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
"name": "authority",
|
|
728
|
+
"isMut": false,
|
|
729
|
+
"isSigner": true
|
|
730
|
+
}
|
|
731
|
+
],
|
|
732
|
+
"args": [
|
|
733
|
+
{
|
|
734
|
+
"name": "params",
|
|
735
|
+
"type": {
|
|
736
|
+
"vec": {
|
|
737
|
+
"defined": "OrderParams"
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
]
|
|
742
|
+
},
|
|
713
743
|
{
|
|
714
744
|
"name": "beginSwap",
|
|
715
745
|
"accounts": [
|
package/src/index.ts
CHANGED
|
@@ -46,6 +46,7 @@ export * from './math/orders';
|
|
|
46
46
|
export * from './math/repeg';
|
|
47
47
|
export * from './math/margin';
|
|
48
48
|
export * from './math/insurance';
|
|
49
|
+
export * from './marinade';
|
|
49
50
|
export * from './orderParams';
|
|
50
51
|
export * from './slot/SlotSubscriber';
|
|
51
52
|
export * from './wallet';
|