@lavarage/sdk 7.2.0 → 7.2.2

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/index.ts CHANGED
@@ -198,6 +198,7 @@ export const openTradeV1 = async (
198
198
  partnerFeeMarkup?: number,
199
199
  computeBudgetMicroLamports?: number,
200
200
  platformFeeRecipient?: PublicKey,
201
+ splitTransactions?: boolean,
201
202
  ) => {
202
203
  let partnerFeeMarkupAsPkey;
203
204
  if (partnerFeeMarkup) {
@@ -325,17 +326,17 @@ export const openTradeV1 = async (
325
326
  .remainingAccounts(
326
327
  partnerFeeRecipient && partnerFeeMarkupAsPkey
327
328
  ? [
328
- {
329
- pubkey: partnerFeeRecipient,
330
- isSigner: false,
331
- isWritable: true,
332
- },
333
- {
334
- pubkey: partnerFeeMarkupAsPkey,
335
- isSigner: false,
336
- isWritable: false,
337
- },
338
- ]
329
+ {
330
+ pubkey: partnerFeeRecipient,
331
+ isSigner: false,
332
+ isWritable: true,
333
+ },
334
+ {
335
+ pubkey: partnerFeeMarkupAsPkey,
336
+ isSigner: false,
337
+ isWritable: false,
338
+ },
339
+ ]
339
340
  : []
340
341
  )
341
342
  .instruction();
@@ -362,6 +363,39 @@ export const openTradeV1 = async (
362
363
  microLamports: computeBudgetMicroLamports ?? 100000,
363
364
  });
364
365
 
366
+ if (splitTransactions) {
367
+ const setUpInstructions = [
368
+ fromTokenAccount.instruction!,
369
+ toTokenAccount.instruction!,
370
+ ...setupInstructions.map(deserializeInstruction),
371
+ ]
372
+
373
+ const allInstructions = [
374
+ tradingOpenBorrowInstruction!,
375
+ deserializeInstruction(swapInstructionPayload), ,
376
+ openAddCollateralInstruction!,
377
+ computeBudgetMicroLamports ? computeFeeIx : undefined,
378
+ ].filter(Boolean) as TransactionInstruction[];
379
+
380
+ const messageV01 = new TransactionMessage({
381
+ payerKey: lavarageProgram.provider.publicKey!,
382
+ recentBlockhash: blockhash,
383
+ instructions: setUpInstructions,
384
+ }).compileToV0Message(addressLookupTableAccounts);
385
+
386
+ const tx2 = new VersionedTransaction(messageV01);
387
+
388
+ const messageV0 = new TransactionMessage({
389
+ payerKey: lavarageProgram.provider.publicKey!,
390
+ recentBlockhash: blockhash,
391
+ instructions: allInstructions,
392
+ }).compileToV0Message(addressLookupTableAccounts);
393
+
394
+ const tx = new VersionedTransaction(messageV0);
395
+
396
+ return [tx2, tx];
397
+ }
398
+
365
399
  const allInstructions = [
366
400
  fromTokenAccount.instruction!,
367
401
  toTokenAccount.instruction!,
@@ -405,6 +439,7 @@ export const openTradeV2 = async (
405
439
  partnerFeeMarkup?: number,
406
440
  computeBudgetMicroLamports?: number,
407
441
  platformFeeRecipient?: PublicKey,
442
+ splitTransactions?: boolean,
408
443
  ) => {
409
444
  let partnerFeeMarkupAsPkey;
410
445
  if (partnerFeeMarkup) {
@@ -555,22 +590,22 @@ export const openTradeV2 = async (
555
590
  .remainingAccounts(
556
591
  partnerFeeRecipient && partnerFeeMarkupAsPkey
557
592
  ? [
558
- {
559
- pubkey: getAssociatedTokenAddressSync(
560
- quoteToken,
561
- partnerFeeRecipient,
562
- false,
563
- quoteTokenProgram
564
- ),
565
- isSigner: false,
566
- isWritable: true,
567
- },
568
- {
569
- pubkey: partnerFeeMarkupAsPkey,
570
- isSigner: false,
571
- isWritable: false,
572
- },
573
- ]
593
+ {
594
+ pubkey: getAssociatedTokenAddressSync(
595
+ quoteToken,
596
+ partnerFeeRecipient,
597
+ false,
598
+ quoteTokenProgram
599
+ ),
600
+ isSigner: false,
601
+ isWritable: true,
602
+ },
603
+ {
604
+ pubkey: partnerFeeMarkupAsPkey,
605
+ isSigner: false,
606
+ isWritable: false,
607
+ },
608
+ ]
574
609
  : []
575
610
  )
576
611
  .instruction();
@@ -597,6 +632,39 @@ export const openTradeV2 = async (
597
632
  microLamports: computeBudgetMicroLamports ?? 100000,
598
633
  });
599
634
 
635
+ if (splitTransactions) {
636
+ const setUpInstructions = [
637
+ fromTokenAccount.instruction!,
638
+ toTokenAccount.instruction!,
639
+ ...setupInstructions.map(deserializeInstruction),
640
+ ]
641
+
642
+ const allInstructions = [
643
+ tradingOpenBorrowInstruction!,
644
+ deserializeInstruction(swapInstructionPayload), ,
645
+ openAddCollateralInstruction!,
646
+ computeBudgetMicroLamports ? computeFeeIx : undefined,
647
+ ].filter(Boolean) as TransactionInstruction[];
648
+
649
+ const messageV01 = new TransactionMessage({
650
+ payerKey: lavarageProgram.provider.publicKey!,
651
+ recentBlockhash: blockhash,
652
+ instructions: setUpInstructions,
653
+ }).compileToV0Message(addressLookupTableAccounts);
654
+
655
+ const tx2 = new VersionedTransaction(messageV01);
656
+
657
+ const messageV0 = new TransactionMessage({
658
+ payerKey: lavarageProgram.provider.publicKey!,
659
+ recentBlockhash: blockhash,
660
+ instructions: allInstructions,
661
+ }).compileToV0Message(addressLookupTableAccounts);
662
+
663
+ const tx = new VersionedTransaction(messageV0);
664
+
665
+ return [tx2, tx];
666
+ }
667
+
600
668
  const allInstructions = [
601
669
  fromTokenAccount.instruction!,
602
670
  toTokenAccount.instruction!,
@@ -652,20 +720,20 @@ export const createTpDelegate = async (
652
720
  .remainingAccounts(
653
721
  partnerFeeRecipient
654
722
  ? [
655
- {
656
- pubkey:
657
- quoteToken.toBase58() ==
723
+ {
724
+ pubkey:
725
+ quoteToken.toBase58() ==
658
726
  "So11111111111111111111111111111111111111112"
659
- ? partnerFeeRecipient
660
- : getAssociatedTokenAddressSync(
661
- quoteToken,
662
- partnerFeeRecipient,
663
- false
664
- ),
665
- isSigner: false,
666
- isWritable: true,
667
- },
668
- ]
727
+ ? partnerFeeRecipient
728
+ : getAssociatedTokenAddressSync(
729
+ quoteToken,
730
+ partnerFeeRecipient,
731
+ false
732
+ ),
733
+ isSigner: false,
734
+ isWritable: true,
735
+ },
736
+ ]
669
737
  : []
670
738
  )
671
739
  .instruction();
@@ -728,20 +796,20 @@ export const modifyTpDelegate = async (
728
796
  .remainingAccounts(
729
797
  partnerFeeRecipient
730
798
  ? [
731
- {
732
- pubkey:
733
- quoteToken.toBase58() ==
799
+ {
800
+ pubkey:
801
+ quoteToken.toBase58() ==
734
802
  "So11111111111111111111111111111111111111112"
735
- ? partnerFeeRecipient
736
- : getAssociatedTokenAddressSync(
737
- quoteToken,
738
- partnerFeeRecipient,
739
- false
740
- ),
741
- isSigner: false,
742
- isWritable: true,
743
- },
744
- ]
803
+ ? partnerFeeRecipient
804
+ : getAssociatedTokenAddressSync(
805
+ quoteToken,
806
+ partnerFeeRecipient,
807
+ false
808
+ ),
809
+ isSigner: false,
810
+ isWritable: true,
811
+ },
812
+ ]
745
813
  : []
746
814
  )
747
815
  .instruction();
@@ -911,6 +979,7 @@ export const closeTradeV1 = async (
911
979
  partnerFeeMarkup?: number,
912
980
  computeBudgetMicroLamports?: number,
913
981
  platformFeeRecipient?: PublicKey,
982
+ splitTransactions?: boolean,
914
983
  ) => {
915
984
  let partnerFeeMarkupAsPkey;
916
985
  if (partnerFeeMarkup) {
@@ -1037,17 +1106,17 @@ export const closeTradeV1 = async (
1037
1106
  .remainingAccounts(
1038
1107
  partnerFeeRecipient && partnerFeeMarkupAsPkey
1039
1108
  ? [
1040
- {
1041
- pubkey: partnerFeeRecipient,
1042
- isSigner: false,
1043
- isWritable: true,
1044
- },
1045
- {
1046
- pubkey: partnerFeeMarkupAsPkey,
1047
- isSigner: false,
1048
- isWritable: false,
1049
- },
1050
- ]
1109
+ {
1110
+ pubkey: partnerFeeRecipient,
1111
+ isSigner: false,
1112
+ isWritable: true,
1113
+ },
1114
+ {
1115
+ pubkey: partnerFeeMarkupAsPkey,
1116
+ isSigner: false,
1117
+ isWritable: false,
1118
+ },
1119
+ ]
1051
1120
  : []
1052
1121
  )
1053
1122
  .instruction();
@@ -1070,17 +1139,17 @@ export const closeTradeV1 = async (
1070
1139
  .remainingAccounts(
1071
1140
  partnerFeeRecipient && partnerFeeMarkupAsPkey
1072
1141
  ? [
1073
- {
1074
- pubkey: partnerFeeRecipient,
1075
- isSigner: false,
1076
- isWritable: true,
1077
- },
1078
- {
1079
- pubkey: partnerFeeMarkupAsPkey,
1080
- isSigner: false,
1081
- isWritable: false,
1082
- },
1083
- ]
1142
+ {
1143
+ pubkey: partnerFeeRecipient,
1144
+ isSigner: false,
1145
+ isWritable: true,
1146
+ },
1147
+ {
1148
+ pubkey: partnerFeeMarkupAsPkey,
1149
+ isSigner: false,
1150
+ isWritable: false,
1151
+ },
1152
+ ]
1084
1153
  : []
1085
1154
  )
1086
1155
  .instruction();
@@ -1120,17 +1189,51 @@ export const closeTradeV1 = async (
1120
1189
  microLamports: computeBudgetMicroLamports ?? 100000,
1121
1190
  });
1122
1191
 
1192
+ if (splitTransactions) {
1193
+ const setUpInstructions = [
1194
+ jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1195
+ createAssociatedTokenAccountInstruction
1196
+ ].filter((i) => !!i);
1197
+
1198
+ const allInstructions = [
1199
+ jupInstruction.instructions?.tokenLedgerInstruction
1200
+ ? deserializeInstruction(
1201
+ jupInstruction.instructions.tokenLedgerInstruction
1202
+ )
1203
+ : null,
1204
+ closePositionIx,
1205
+ ...jupiterIxs,
1206
+ repaySolIx,
1207
+ computeBudgetMicroLamports ? computeFeeIx : undefined,
1208
+ ].filter((i) => !!i);
1209
+
1210
+ const messageV01 = new TransactionMessage({
1211
+ payerKey: lavarageProgram.provider.publicKey!,
1212
+ recentBlockhash: blockhash,
1213
+ instructions: setUpInstructions,
1214
+ }).compileToV0Message(addressLookupTableAccounts);
1215
+
1216
+ const tx = new VersionedTransaction(messageV01);
1217
+
1218
+ const messageV02 = new TransactionMessage({
1219
+ payerKey: lavarageProgram.provider.publicKey!,
1220
+ recentBlockhash: blockhash,
1221
+ instructions: allInstructions,
1222
+ }).compileToV0Message(addressLookupTableAccounts);
1223
+
1224
+ const tx2 = new VersionedTransaction(messageV02);
1225
+
1226
+ return [tx, tx2];
1227
+ }
1228
+
1123
1229
  const allInstructions = [
1124
1230
  jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1125
- jupInstruction.instructions?.tokenLedgerInstruction
1126
- ? createAssociatedTokenAccountInstruction
1127
- : null,
1231
+ createAssociatedTokenAccountInstruction,
1128
1232
  jupInstruction.instructions?.tokenLedgerInstruction
1129
1233
  ? deserializeInstruction(
1130
- jupInstruction.instructions.tokenLedgerInstruction
1131
- )
1234
+ jupInstruction.instructions.tokenLedgerInstruction
1235
+ )
1132
1236
  : null,
1133
- toTokenAccount.instruction!,
1134
1237
  closePositionIx,
1135
1238
  ...jupiterIxs,
1136
1239
  repaySolIx,
@@ -1176,6 +1279,7 @@ export const closeTradeV2 = async (
1176
1279
  partnerFeeMarkup?: number,
1177
1280
  computeBudgetMicroLamports?: number,
1178
1281
  platformFeeRecipient?: PublicKey,
1282
+ splitTransactions?: boolean,
1179
1283
  ) => {
1180
1284
  let partnerFeeMarkupAsPkey;
1181
1285
  if (partnerFeeMarkup) {
@@ -1325,22 +1429,22 @@ export const closeTradeV2 = async (
1325
1429
  .remainingAccounts(
1326
1430
  partnerFeeRecipient && partnerFeeMarkupAsPkey
1327
1431
  ? [
1328
- {
1329
- pubkey: getAssociatedTokenAddressSync(
1330
- quoteToken,
1331
- partnerFeeRecipient,
1332
- false,
1333
- quoteTokenProgram
1334
- ),
1335
- isSigner: false,
1336
- isWritable: true,
1337
- },
1338
- {
1339
- pubkey: partnerFeeMarkupAsPkey,
1340
- isSigner: false,
1341
- isWritable: false,
1342
- },
1343
- ]
1432
+ {
1433
+ pubkey: getAssociatedTokenAddressSync(
1434
+ quoteToken,
1435
+ partnerFeeRecipient,
1436
+ false,
1437
+ quoteTokenProgram
1438
+ ),
1439
+ isSigner: false,
1440
+ isWritable: true,
1441
+ },
1442
+ {
1443
+ pubkey: partnerFeeMarkupAsPkey,
1444
+ isSigner: false,
1445
+ isWritable: false,
1446
+ },
1447
+ ]
1344
1448
  : []
1345
1449
  )
1346
1450
  .instruction();
@@ -1382,17 +1486,22 @@ export const closeTradeV2 = async (
1382
1486
  .remainingAccounts(
1383
1487
  partnerFeeRecipient && partnerFeeMarkupAsPkey
1384
1488
  ? [
1385
- {
1386
- pubkey: partnerFeeRecipient,
1387
- isSigner: false,
1388
- isWritable: true,
1389
- },
1390
- {
1391
- pubkey: partnerFeeMarkupAsPkey,
1392
- isSigner: false,
1393
- isWritable: false,
1394
- },
1395
- ]
1489
+ {
1490
+ pubkey: getAssociatedTokenAddressSync(
1491
+ quoteToken,
1492
+ partnerFeeRecipient,
1493
+ false,
1494
+ quoteTokenProgram
1495
+ ),
1496
+ isSigner: false,
1497
+ isWritable: true,
1498
+ },
1499
+ {
1500
+ pubkey: partnerFeeMarkupAsPkey,
1501
+ isSigner: false,
1502
+ isWritable: false,
1503
+ },
1504
+ ]
1396
1505
  : []
1397
1506
  )
1398
1507
  .instruction();
@@ -1434,17 +1543,51 @@ export const closeTradeV2 = async (
1434
1543
  microLamports: computeBudgetMicroLamports ?? 100000,
1435
1544
  });
1436
1545
 
1546
+ if (splitTransactions) {
1547
+ const setUpInstructions = [
1548
+ jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1549
+ createAssociatedTokenAccountInstruction,
1550
+ ].filter((i) => !!i);
1551
+
1552
+ const allInstructions = [
1553
+ jupInstruction.instructions?.tokenLedgerInstruction
1554
+ ? deserializeInstruction(
1555
+ jupInstruction.instructions.tokenLedgerInstruction
1556
+ )
1557
+ : null,
1558
+ closePositionIx,
1559
+ ...jupiterIxs,
1560
+ repaySolIx,
1561
+ computeBudgetMicroLamports ? computeFeeIx : undefined,
1562
+ ].filter((i) => !!i);
1563
+
1564
+ const messageV01 = new TransactionMessage({
1565
+ payerKey: lavarageProgram.provider.publicKey!,
1566
+ recentBlockhash: blockhash,
1567
+ instructions: setUpInstructions,
1568
+ }).compileToV0Message(addressLookupTableAccounts);
1569
+
1570
+ const tx = new VersionedTransaction(messageV01);
1571
+
1572
+ const messageV02 = new TransactionMessage({
1573
+ payerKey: lavarageProgram.provider.publicKey!,
1574
+ recentBlockhash: blockhash,
1575
+ instructions: allInstructions,
1576
+ }).compileToV0Message(addressLookupTableAccounts);
1577
+
1578
+ const tx2 = new VersionedTransaction(messageV02);
1579
+
1580
+ return [tx, tx2];
1581
+ }
1582
+
1437
1583
  const allInstructions = [
1438
1584
  jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1439
- jupInstruction.instructions?.tokenLedgerInstruction
1440
- ? createAssociatedTokenAccountInstruction
1441
- : null,
1585
+ createAssociatedTokenAccountInstruction,
1442
1586
  jupInstruction.instructions?.tokenLedgerInstruction
1443
1587
  ? deserializeInstruction(
1444
- jupInstruction.instructions.tokenLedgerInstruction
1445
- )
1588
+ jupInstruction.instructions.tokenLedgerInstruction
1589
+ )
1446
1590
  : null,
1447
- toTokenAccount.instruction!,
1448
1591
  closePositionIx,
1449
1592
  ...jupiterIxs,
1450
1593
  repaySolIx,
@@ -1469,13 +1612,13 @@ export const getDelegateAccounts = async (
1469
1612
  const delegateAccounts = await lavarageProgram.account.delegate.all(
1470
1613
  userPubKey
1471
1614
  ? [
1472
- {
1473
- memcmp: {
1474
- offset: 104,
1475
- bytes: userPubKey.toBase58(),
1476
- },
1615
+ {
1616
+ memcmp: {
1617
+ offset: 104,
1618
+ bytes: userPubKey.toBase58(),
1477
1619
  },
1478
- ]
1620
+ },
1621
+ ]
1479
1622
  : undefined
1480
1623
  );
1481
1624
  return delegateAccounts.map((d) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",