@lavarage/sdk 7.1.2 → 7.2.1

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,22 +1139,21 @@ 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();
1087
1156
 
1088
-
1089
1157
  const {
1090
1158
  setupInstructions,
1091
1159
  swapInstruction: swapInstructionPayload,
@@ -1121,17 +1189,51 @@ export const closeTradeV1 = async (
1121
1189
  microLamports: computeBudgetMicroLamports ?? 100000,
1122
1190
  });
1123
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
+
1124
1229
  const allInstructions = [
1125
1230
  jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1126
- jupInstruction.instructions?.tokenLedgerInstruction
1127
- ? createAssociatedTokenAccountInstruction
1128
- : null,
1231
+ createAssociatedTokenAccountInstruction,
1129
1232
  jupInstruction.instructions?.tokenLedgerInstruction
1130
1233
  ? deserializeInstruction(
1131
- jupInstruction.instructions.tokenLedgerInstruction
1132
- )
1234
+ jupInstruction.instructions.tokenLedgerInstruction
1235
+ )
1133
1236
  : null,
1134
- toTokenAccount.instruction!,
1135
1237
  closePositionIx,
1136
1238
  ...jupiterIxs,
1137
1239
  repaySolIx,
@@ -1177,6 +1279,7 @@ export const closeTradeV2 = async (
1177
1279
  partnerFeeMarkup?: number,
1178
1280
  computeBudgetMicroLamports?: number,
1179
1281
  platformFeeRecipient?: PublicKey,
1282
+ splitTransactions?: boolean,
1180
1283
  ) => {
1181
1284
  let partnerFeeMarkupAsPkey;
1182
1285
  if (partnerFeeMarkup) {
@@ -1326,22 +1429,22 @@ export const closeTradeV2 = async (
1326
1429
  .remainingAccounts(
1327
1430
  partnerFeeRecipient && partnerFeeMarkupAsPkey
1328
1431
  ? [
1329
- {
1330
- pubkey: getAssociatedTokenAddressSync(
1331
- quoteToken,
1332
- partnerFeeRecipient,
1333
- false,
1334
- quoteTokenProgram
1335
- ),
1336
- isSigner: false,
1337
- isWritable: true,
1338
- },
1339
- {
1340
- pubkey: partnerFeeMarkupAsPkey,
1341
- isSigner: false,
1342
- isWritable: false,
1343
- },
1344
- ]
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
+ ]
1345
1448
  : []
1346
1449
  )
1347
1450
  .instruction();
@@ -1383,17 +1486,17 @@ export const closeTradeV2 = async (
1383
1486
  .remainingAccounts(
1384
1487
  partnerFeeRecipient && partnerFeeMarkupAsPkey
1385
1488
  ? [
1386
- {
1387
- pubkey: partnerFeeRecipient,
1388
- isSigner: false,
1389
- isWritable: true,
1390
- },
1391
- {
1392
- pubkey: partnerFeeMarkupAsPkey,
1393
- isSigner: false,
1394
- isWritable: false,
1395
- },
1396
- ]
1489
+ {
1490
+ pubkey: partnerFeeRecipient,
1491
+ isSigner: false,
1492
+ isWritable: true,
1493
+ },
1494
+ {
1495
+ pubkey: partnerFeeMarkupAsPkey,
1496
+ isSigner: false,
1497
+ isWritable: false,
1498
+ },
1499
+ ]
1397
1500
  : []
1398
1501
  )
1399
1502
  .instruction();
@@ -1435,17 +1538,51 @@ export const closeTradeV2 = async (
1435
1538
  microLamports: computeBudgetMicroLamports ?? 100000,
1436
1539
  });
1437
1540
 
1541
+ if (splitTransactions) {
1542
+ const setUpInstructions = [
1543
+ jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1544
+ createAssociatedTokenAccountInstruction,
1545
+ ].filter((i) => !!i);
1546
+
1547
+ const allInstructions = [
1548
+ jupInstruction.instructions?.tokenLedgerInstruction
1549
+ ? deserializeInstruction(
1550
+ jupInstruction.instructions.tokenLedgerInstruction
1551
+ )
1552
+ : null,
1553
+ closePositionIx,
1554
+ ...jupiterIxs,
1555
+ repaySolIx,
1556
+ computeBudgetMicroLamports ? computeFeeIx : undefined,
1557
+ ].filter((i) => !!i);
1558
+
1559
+ const messageV01 = new TransactionMessage({
1560
+ payerKey: lavarageProgram.provider.publicKey!,
1561
+ recentBlockhash: blockhash,
1562
+ instructions: setUpInstructions,
1563
+ }).compileToV0Message(addressLookupTableAccounts);
1564
+
1565
+ const tx = new VersionedTransaction(messageV01);
1566
+
1567
+ const messageV02 = new TransactionMessage({
1568
+ payerKey: lavarageProgram.provider.publicKey!,
1569
+ recentBlockhash: blockhash,
1570
+ instructions: allInstructions,
1571
+ }).compileToV0Message(addressLookupTableAccounts);
1572
+
1573
+ const tx2 = new VersionedTransaction(messageV02);
1574
+
1575
+ return [tx, tx2];
1576
+ }
1577
+
1438
1578
  const allInstructions = [
1439
1579
  jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
1440
- jupInstruction.instructions?.tokenLedgerInstruction
1441
- ? createAssociatedTokenAccountInstruction
1442
- : null,
1580
+ createAssociatedTokenAccountInstruction,
1443
1581
  jupInstruction.instructions?.tokenLedgerInstruction
1444
1582
  ? deserializeInstruction(
1445
- jupInstruction.instructions.tokenLedgerInstruction
1446
- )
1583
+ jupInstruction.instructions.tokenLedgerInstruction
1584
+ )
1447
1585
  : null,
1448
- toTokenAccount.instruction!,
1449
1586
  closePositionIx,
1450
1587
  ...jupiterIxs,
1451
1588
  repaySolIx,
@@ -1470,13 +1607,13 @@ export const getDelegateAccounts = async (
1470
1607
  const delegateAccounts = await lavarageProgram.account.delegate.all(
1471
1608
  userPubKey
1472
1609
  ? [
1473
- {
1474
- memcmp: {
1475
- offset: 104,
1476
- bytes: userPubKey.toBase58(),
1477
- },
1610
+ {
1611
+ memcmp: {
1612
+ offset: 104,
1613
+ bytes: userPubKey.toBase58(),
1478
1614
  },
1479
- ]
1615
+ },
1616
+ ]
1480
1617
  : undefined
1481
1618
  );
1482
1619
  return delegateAccounts.map((d) => ({
@@ -1615,7 +1752,17 @@ export const splitPositionV2 = async (
1615
1752
 
1616
1753
  const tx = new VersionedTransaction(messageV0);
1617
1754
 
1618
- return tx;
1755
+ return {
1756
+ transaction: tx,
1757
+ newPositionAddresses: [
1758
+ newPosition1AccountPDA.toBase58(),
1759
+ newPosition2AccountPDA.toBase58(),
1760
+ ],
1761
+ newPositionSeeds: [
1762
+ newPosition1Seed.toBase58(),
1763
+ newPosition2Seed.toBase58(),
1764
+ ],
1765
+ };
1619
1766
  };
1620
1767
 
1621
1768
  export const mergePositionV2 = async (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "7.1.2",
3
+ "version": "7.2.1",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",