@kamino-finance/klend-sdk 5.11.4 → 5.11.5-beta.0

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.
Files changed (45) hide show
  1. package/dist/classes/action.d.ts +12 -2
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +228 -30
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.d.ts.map +1 -1
  6. package/dist/classes/manager.js +1 -0
  7. package/dist/classes/manager.js.map +1 -1
  8. package/dist/classes/obligation.d.ts +1 -1
  9. package/dist/classes/obligation.d.ts.map +1 -1
  10. package/dist/classes/obligation.js +1 -1
  11. package/dist/classes/obligation.js.map +1 -1
  12. package/dist/classes/vault.js +6 -6
  13. package/dist/classes/vault.js.map +1 -1
  14. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  15. package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
  16. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  17. package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -0
  18. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  19. package/dist/lending_operations/repay_with_collateral_operations.js +26 -1
  20. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  21. package/dist/utils/lookupTable.d.ts +27 -0
  22. package/dist/utils/lookupTable.d.ts.map +1 -1
  23. package/dist/utils/lookupTable.js +58 -0
  24. package/dist/utils/lookupTable.js.map +1 -1
  25. package/dist/utils/seeds.d.ts +11 -1
  26. package/dist/utils/seeds.d.ts.map +1 -1
  27. package/dist/utils/seeds.js +13 -3
  28. package/dist/utils/seeds.js.map +1 -1
  29. package/dist/utils/userMetadata.js +6 -6
  30. package/dist/utils/userMetadata.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/classes/action.ts +361 -50
  33. package/src/classes/manager.ts +4 -6
  34. package/src/classes/obligation.ts +1 -1
  35. package/src/classes/vault.ts +1 -1
  36. package/src/lending_operations/repay_with_collateral_calcs.ts +14 -5
  37. package/src/lending_operations/repay_with_collateral_operations.ts +63 -20
  38. package/src/utils/lookupTable.ts +62 -0
  39. package/src/utils/seeds.ts +14 -4
  40. package/src/utils/userMetadata.ts +14 -14
  41. package/dist/classes/lut_utils.d.ts +0 -29
  42. package/dist/classes/lut_utils.d.ts.map +0 -1
  43. package/dist/classes/lut_utils.js +0 -62
  44. package/dist/classes/lut_utils.js.map +0 -1
  45. package/src/classes/lut_utils.ts +0 -63
@@ -21,6 +21,7 @@ import BN from 'bn.js';
21
21
  import Decimal from 'decimal.js';
22
22
  import {
23
23
  borrowObligationLiquidity,
24
+ depositAndWithdraw,
24
25
  borrowObligationLiquidityV2,
25
26
  depositObligationCollateral,
26
27
  depositObligationCollateralV2,
@@ -41,6 +42,7 @@ import {
41
42
  RefreshObligationFarmsForReserveAccounts,
42
43
  RefreshObligationFarmsForReserveArgs,
43
44
  refreshReserve,
45
+ repayAndWithdrawAndRedeem,
44
46
  repayObligationLiquidity,
45
47
  repayObligationLiquidityV2,
46
48
  requestElevationGroup,
@@ -90,7 +92,9 @@ export type ActionType =
90
92
  | 'repayAndWithdraw'
91
93
  | 'refreshObligation'
92
94
  | 'requestElevationGroup'
93
- | 'withdrawReferrerFees';
95
+ | 'withdrawReferrerFees'
96
+ | 'repayAndWithdrawV2'
97
+ | 'depositAndWithdraw';
94
98
 
95
99
  export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
96
100
 
@@ -768,6 +772,112 @@ export class KaminoAction {
768
772
  return axn;
769
773
  }
770
774
 
775
+ static async buildDepositAndWithdrawV2Txns(
776
+ kaminoMarket: KaminoMarket,
777
+ depositAmount: string | BN,
778
+ depositMint: PublicKey,
779
+ withdrawAmount: string | BN,
780
+ withdrawMint: PublicKey,
781
+ payer: PublicKey,
782
+ currentSlot: number,
783
+ obligation: KaminoObligation | ObligationType,
784
+ scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
785
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
786
+ includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
787
+ requestElevationGroup: boolean = false,
788
+ includeUserMetadata: boolean = true, // if true it includes user metadata,
789
+ createLookupTable: boolean = true,
790
+ referrer: PublicKey = PublicKey.default
791
+ ) {
792
+ const axn = await KaminoAction.initializeMultiTokenAction(
793
+ kaminoMarket,
794
+ 'depositAndWithdraw',
795
+ depositAmount,
796
+ depositMint,
797
+ withdrawMint,
798
+ payer,
799
+ payer,
800
+ obligation,
801
+ withdrawAmount,
802
+ referrer,
803
+ currentSlot
804
+ );
805
+ const addInitObligationForFarm = true;
806
+ const twoTokenAction = true;
807
+ if (extraComputeBudget > 0) {
808
+ axn.addComputeBudgetIxn(extraComputeBudget);
809
+ }
810
+
811
+ await axn.addSupportIxs(
812
+ 'depositAndWithdraw',
813
+ includeAtaIxns,
814
+ requestElevationGroup,
815
+ includeUserMetadata,
816
+ addInitObligationForFarm,
817
+ true,
818
+ scopeRefreshConfig,
819
+ createLookupTable,
820
+ twoTokenAction
821
+ );
822
+ const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
823
+ axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
824
+
825
+ return axn;
826
+ }
827
+
828
+ static async buildRepayAndWithdrawV2Txns(
829
+ kaminoMarket: KaminoMarket,
830
+ repayAmount: string | BN,
831
+ repayMint: PublicKey,
832
+ withdrawAmount: string | BN,
833
+ withdrawMint: PublicKey,
834
+ payer: PublicKey,
835
+ currentSlot: number,
836
+ obligation: KaminoObligation | ObligationType,
837
+ scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
838
+ extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
839
+ includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
840
+ requestElevationGroup: boolean = false,
841
+ includeUserMetadata: boolean = true, // if true it includes user metadata,
842
+ createLookupTable: boolean = true,
843
+ referrer: PublicKey = PublicKey.default
844
+ ) {
845
+ const axn = await KaminoAction.initializeMultiTokenAction(
846
+ kaminoMarket,
847
+ 'repayAndWithdrawV2',
848
+ repayAmount,
849
+ repayMint,
850
+ withdrawMint,
851
+ payer,
852
+ payer,
853
+ obligation,
854
+ withdrawAmount,
855
+ referrer,
856
+ currentSlot
857
+ );
858
+ const addInitObligationForFarm = true;
859
+ const twoTokenAction = true;
860
+ if (extraComputeBudget > 0) {
861
+ axn.addComputeBudgetIxn(extraComputeBudget);
862
+ }
863
+
864
+ await axn.addSupportIxs(
865
+ 'repayAndWithdrawV2',
866
+ includeAtaIxns,
867
+ requestElevationGroup,
868
+ includeUserMetadata,
869
+ addInitObligationForFarm,
870
+ true,
871
+ scopeRefreshConfig,
872
+ createLookupTable,
873
+ twoTokenAction
874
+ );
875
+ const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
876
+ axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
877
+
878
+ return axn;
879
+ }
880
+
771
881
  static async buildRepayAndWithdrawTxns(
772
882
  kaminoMarket: KaminoMarket,
773
883
  repayAmount: string | BN,
@@ -1261,10 +1371,7 @@ export class KaminoAction {
1261
1371
  reserveFarmState: this.kaminoMarket.programId,
1262
1372
  }
1263
1373
  : {
1264
- obligationFarmUserState: obligationFarmStatePda(
1265
- this.getObligationPda(),
1266
- this.reserve.state.farmCollateral
1267
- )[0],
1374
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1268
1375
  reserveFarmState: this.reserve.state.farmCollateral,
1269
1376
  };
1270
1377
 
@@ -1329,10 +1436,7 @@ export class KaminoAction {
1329
1436
  reserveFarmState: this.kaminoMarket.programId,
1330
1437
  }
1331
1438
  : {
1332
- obligationFarmUserState: obligationFarmStatePda(
1333
- this.getObligationPda(),
1334
- this.reserve.state.farmCollateral
1335
- )[0],
1439
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1336
1440
  reserveFarmState: this.reserve.state.farmCollateral,
1337
1441
  };
1338
1442
 
@@ -1414,7 +1518,7 @@ export class KaminoAction {
1414
1518
  reserveFarmState: this.kaminoMarket.programId,
1415
1519
  }
1416
1520
  : {
1417
- obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1521
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1418
1522
  reserveFarmState: this.reserve.state.farmDebt,
1419
1523
  };
1420
1524
 
@@ -1489,10 +1593,7 @@ export class KaminoAction {
1489
1593
  reserveFarmState: this.kaminoMarket.programId,
1490
1594
  }
1491
1595
  : {
1492
- obligationFarmUserState: obligationFarmStatePda(
1493
- this.getObligationPda(),
1494
- this.reserve.state.farmCollateral
1495
- )[0],
1596
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1496
1597
  reserveFarmState: this.reserve.state.farmCollateral,
1497
1598
  };
1498
1599
 
@@ -1576,7 +1677,7 @@ export class KaminoAction {
1576
1677
  reserveFarmState: this.kaminoMarket.programId,
1577
1678
  }
1578
1679
  : {
1579
- obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1680
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1580
1681
  reserveFarmState: this.reserve.state.farmDebt,
1581
1682
  };
1582
1683
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -1612,6 +1713,208 @@ export class KaminoAction {
1612
1713
  this.lendingIxs.push(repayIx);
1613
1714
  }
1614
1715
 
1716
+ addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1717
+ this.lendingIxsLabels.push(
1718
+ `repayAndWithdrawAndRedeem(repayReserve=${this.reserve!.address})(withdrawReserve=${
1719
+ this.outflowReserve!.address
1720
+ })(obligation=${this.getObligationPda()})`
1721
+ );
1722
+
1723
+ const depositReservesList = this.getAdditionalDepositReservesList();
1724
+
1725
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1726
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1727
+ });
1728
+ const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
1729
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1730
+ });
1731
+
1732
+ if (!this.outflowAmount) {
1733
+ throw new Error(`outflowAmount not set`);
1734
+ }
1735
+
1736
+ if (!this.outflowReserve) {
1737
+ throw new Error(`outflowReserve not set`);
1738
+ }
1739
+
1740
+ if (!this.additionalTokenAccountAddress) {
1741
+ throw new Error(`additionalTokenAccountAddress not set`);
1742
+ }
1743
+
1744
+ const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1745
+ ? {
1746
+ obligationFarmUserState: this.kaminoMarket.programId,
1747
+ reserveFarmState: this.kaminoMarket.programId,
1748
+ }
1749
+ : {
1750
+ obligationFarmUserState: obligationFarmStatePda(
1751
+ this.outflowReserve.state.farmCollateral,
1752
+ this.getObligationPda()
1753
+ ),
1754
+ reserveFarmState: this.outflowReserve.state.farmCollateral,
1755
+ };
1756
+
1757
+ const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1758
+ ? {
1759
+ obligationFarmUserState: this.kaminoMarket.programId,
1760
+ reserveFarmState: this.kaminoMarket.programId,
1761
+ }
1762
+ : {
1763
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1764
+ reserveFarmState: this.reserve.state.farmDebt,
1765
+ };
1766
+
1767
+ const repayAndWithdrawIx = repayAndWithdrawAndRedeem(
1768
+ {
1769
+ repayAmount: this.amount,
1770
+ withdrawCollateralAmount,
1771
+ },
1772
+ {
1773
+ repayAccounts: {
1774
+ owner: this.owner,
1775
+ obligation: this.getObligationPda(),
1776
+ lendingMarket: this.kaminoMarket.getAddress(),
1777
+ repayReserve: this.reserve!.address,
1778
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1779
+ userSourceLiquidity: this.userTokenAccountAddress,
1780
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1781
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
1782
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1783
+ },
1784
+ withdrawAccounts: {
1785
+ owner: this.owner,
1786
+ obligation: this.getObligationPda(),
1787
+ lendingMarket: this.kaminoMarket.getAddress(),
1788
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1789
+ withdrawReserve: this.outflowReserve.address,
1790
+ reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1791
+ reserveCollateralMint: this.outflowReserve.getCTokenMint(),
1792
+ reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1793
+ reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
1794
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
1795
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1796
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1797
+ liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1798
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1799
+ },
1800
+ collateralFarmsAccounts,
1801
+ debtFarmsAccounts,
1802
+ farmsProgram: farmsId,
1803
+ },
1804
+ this.kaminoMarket.programId
1805
+ );
1806
+
1807
+ repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
1808
+ ...depositReserveAccountMetas,
1809
+ ...borrowReserveAccountMetas,
1810
+ ]);
1811
+
1812
+ this.lendingIxs.push(repayAndWithdrawIx);
1813
+ }
1814
+
1815
+ addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1816
+ this.lendingIxsLabels.push(
1817
+ `depositAndWithdrawV2(depositReserve=${this.reserve!.address})(withdrawReserve=${
1818
+ this.outflowReserve!.address
1819
+ })(obligation=${this.getObligationPda()})`
1820
+ );
1821
+
1822
+ const depositReservesList = this.getAdditionalDepositReservesList();
1823
+
1824
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1825
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1826
+ });
1827
+ const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
1828
+ return { pubkey: reserve, isSigner: false, isWritable: true };
1829
+ });
1830
+
1831
+ if (!this.outflowAmount) {
1832
+ throw new Error(`outflowAmount not set`);
1833
+ }
1834
+
1835
+ if (!this.outflowReserve) {
1836
+ throw new Error(`outflowReserve not set`);
1837
+ }
1838
+
1839
+ if (!this.additionalTokenAccountAddress) {
1840
+ throw new Error(`additionalTokenAccountAddress not set`);
1841
+ }
1842
+
1843
+ const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1844
+ ? {
1845
+ obligationFarmUserState: this.kaminoMarket.programId,
1846
+ reserveFarmState: this.kaminoMarket.programId,
1847
+ }
1848
+ : {
1849
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1850
+ reserveFarmState: this.reserve.state.farmCollateral,
1851
+ };
1852
+ const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1853
+ ? {
1854
+ obligationFarmUserState: this.kaminoMarket.programId,
1855
+ reserveFarmState: this.kaminoMarket.programId,
1856
+ }
1857
+ : {
1858
+ obligationFarmUserState: obligationFarmStatePda(
1859
+ this.outflowReserve.state.farmCollateral,
1860
+ this.getObligationPda()
1861
+ ),
1862
+ reserveFarmState: this.outflowReserve.state.farmCollateral,
1863
+ };
1864
+
1865
+ const depositAndWithdrawIx = depositAndWithdraw(
1866
+ {
1867
+ liquidityAmount: this.amount,
1868
+ withdrawCollateralAmount,
1869
+ },
1870
+ {
1871
+ depositAccounts: {
1872
+ owner: this.owner,
1873
+ obligation: this.getObligationPda(),
1874
+ lendingMarket: this.kaminoMarket.getAddress(),
1875
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1876
+ reserve: this.reserve.address,
1877
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
1878
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1879
+ reserveCollateralMint: this.reserve.getCTokenMint(),
1880
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1881
+ userSourceLiquidity: this.userTokenAccountAddress,
1882
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1883
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1884
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1885
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1886
+ },
1887
+ withdrawAccounts: {
1888
+ owner: this.owner,
1889
+ obligation: this.getObligationPda(),
1890
+ lendingMarket: this.kaminoMarket.getAddress(),
1891
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1892
+ withdrawReserve: this.outflowReserve.address,
1893
+ reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1894
+ reserveCollateralMint: this.outflowReserve.getCTokenMint(),
1895
+ reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1896
+ reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
1897
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
1898
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1899
+ collateralTokenProgram: TOKEN_PROGRAM_ID,
1900
+ liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1901
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1902
+ },
1903
+ depositFarmsAccounts,
1904
+ withdrawFarmsAccounts,
1905
+ farmsProgram: farmsId,
1906
+ },
1907
+ this.kaminoMarket.programId
1908
+ );
1909
+
1910
+ depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
1911
+ ...depositReserveAccountMetas,
1912
+ ...borrowReserveAccountMetas,
1913
+ ]);
1914
+
1915
+ this.lendingIxs.push(depositAndWithdrawIx);
1916
+ }
1917
+
1615
1918
  async addDepositAndBorrowIx() {
1616
1919
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
1617
1920
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
@@ -1697,10 +2000,7 @@ export class KaminoAction {
1697
2000
  reserveFarmState: this.kaminoMarket.programId,
1698
2001
  }
1699
2002
  : {
1700
- obligationFarmUserState: obligationFarmStatePda(
1701
- this.getObligationPda(),
1702
- this.reserve.state.farmCollateral
1703
- )[0],
2003
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1704
2004
  reserveFarmState: this.reserve.state.farmCollateral,
1705
2005
  };
1706
2006
 
@@ -1761,10 +2061,7 @@ export class KaminoAction {
1761
2061
  reserveFarmState: this.kaminoMarket.programId,
1762
2062
  }
1763
2063
  : {
1764
- obligationFarmUserState: obligationFarmStatePda(
1765
- this.getObligationPda(),
1766
- this.outflowReserve.state.farmDebt!
1767
- )[0],
2064
+ obligationFarmUserState: obligationFarmStatePda(this.outflowReserve.state.farmDebt, this.getObligationPda()),
1768
2065
  reserveFarmState: this.outflowReserve.state.farmDebt,
1769
2066
  };
1770
2067
 
@@ -1890,7 +2187,7 @@ export class KaminoAction {
1890
2187
  reserveFarmState: this.kaminoMarket.programId,
1891
2188
  }
1892
2189
  : {
1893
- obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
2190
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1894
2191
  reserveFarmState: this.reserve.state.farmDebt,
1895
2192
  };
1896
2193
 
@@ -1939,9 +2236,9 @@ export class KaminoAction {
1939
2236
  }
1940
2237
  : {
1941
2238
  obligationFarmUserState: obligationFarmStatePda(
1942
- this.getObligationPda(),
1943
- this.outflowReserve.state.farmCollateral
1944
- )[0],
2239
+ this.outflowReserve.state.farmCollateral,
2240
+ this.getObligationPda()
2241
+ ),
1945
2242
  reserveFarmState: this.outflowReserve.state.farmCollateral,
1946
2243
  };
1947
2244
 
@@ -1975,7 +2272,7 @@ export class KaminoAction {
1975
2272
  );
1976
2273
  }
1977
2274
 
1978
- async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
2275
+ addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
1979
2276
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
1980
2277
  if (!this.outflowReserve) {
1981
2278
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -2048,9 +2345,9 @@ export class KaminoAction {
2048
2345
  }
2049
2346
  : {
2050
2347
  obligationFarmUserState: obligationFarmStatePda(
2051
- this.getObligationPda(),
2052
- this.outflowReserve.state.farmCollateral
2053
- )[0],
2348
+ this.outflowReserve.state.farmCollateral,
2349
+ this.getObligationPda()
2350
+ ),
2054
2351
  reserveFarmState: this.outflowReserve.state.farmCollateral,
2055
2352
  };
2056
2353
 
@@ -2060,7 +2357,7 @@ export class KaminoAction {
2060
2357
  reserveFarmState: this.kaminoMarket.programId,
2061
2358
  }
2062
2359
  : {
2063
- obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
2360
+ obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
2064
2361
  reserveFarmState: this.reserve.state.farmDebt,
2065
2362
  };
2066
2363
 
@@ -2172,7 +2469,9 @@ export class KaminoAction {
2172
2469
  'repay',
2173
2470
  'depositAndBorrow',
2174
2471
  'repayAndWithdraw',
2472
+ 'repayAndWithdrawV2',
2175
2473
  'refreshObligation',
2474
+ 'depositAndWithdraw',
2176
2475
  ].includes(action)
2177
2476
  ) {
2178
2477
  // The support ixns in order are:
@@ -2190,12 +2489,17 @@ export class KaminoAction {
2190
2489
 
2191
2490
  let currentReserves: KaminoReserve[] = [];
2192
2491
 
2193
- if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2492
+ if (
2493
+ action === 'liquidate' ||
2494
+ action === 'depositAndBorrow' ||
2495
+ action === 'repayAndWithdraw' ||
2496
+ action === 'repayAndWithdrawV2'
2497
+ ) {
2194
2498
  if (!this.outflowReserve) {
2195
2499
  throw new Error('outflowReserve is undefined');
2196
2500
  }
2197
2501
 
2198
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2502
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2199
2503
  currentReserves = [this.reserve, this.outflowReserve];
2200
2504
  if (action === 'depositAndBorrow') {
2201
2505
  if (this.obligation) {
@@ -2234,13 +2538,19 @@ export class KaminoAction {
2234
2538
  action === 'depositAndBorrow' ||
2235
2539
  action === 'depositCollateral' ||
2236
2540
  action === 'withdraw' ||
2237
- action === 'deposit'
2541
+ action === 'deposit' ||
2542
+ action === 'depositAndWithdraw'
2238
2543
  ) {
2239
2544
  await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Collateral, addAsSupportIx);
2240
- if (this.outflowReserve) {
2545
+ if (this.outflowReserve && action !== 'depositAndWithdraw') {
2241
2546
  await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
2242
2547
  }
2243
- } else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
2548
+ } else if (
2549
+ action === 'repayAndWithdraw' ||
2550
+ action === 'borrow' ||
2551
+ action === 'repay' ||
2552
+ action === 'repayAndWithdrawV2'
2553
+ ) {
2244
2554
  // todo - probably don't need to add both debt and collateral for everything here
2245
2555
  await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
2246
2556
  if (this.outflowReserve) {
@@ -2271,7 +2581,7 @@ export class KaminoAction {
2271
2581
  }
2272
2582
 
2273
2583
  if (requestElevationGroup) {
2274
- if (action === 'repay') {
2584
+ if (action === 'repay' || action === 'repayAndWithdrawV2') {
2275
2585
  const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
2276
2586
 
2277
2587
  if (!repayObligationLiquidity) {
@@ -2699,7 +3009,7 @@ export class KaminoAction {
2699
3009
  farms.push([
2700
3010
  ReserveFarmKind.Collateral,
2701
3011
  kaminoReserve.state.farmCollateral,
2702
- obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
3012
+ obligationFarmStatePda(kaminoReserve.state.farmCollateral, this.getObligationPda()),
2703
3013
  kaminoReserve,
2704
3014
  ]);
2705
3015
  }
@@ -2707,7 +3017,7 @@ export class KaminoAction {
2707
3017
  farms.push([
2708
3018
  ReserveFarmKind.Debt,
2709
3019
  kaminoReserve.state.farmDebt,
2710
- obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
3020
+ obligationFarmStatePda(kaminoReserve.state.farmDebt, this.getObligationPda()),
2711
3021
  kaminoReserve,
2712
3022
  ]);
2713
3023
  }
@@ -2791,18 +3101,18 @@ export class KaminoAction {
2791
3101
  const farms: [number, PublicKey, PublicKey][] = [];
2792
3102
 
2793
3103
  if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
2794
- const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
2795
- const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
3104
+ const pda = obligationFarmStatePda(reserve.state.farmCollateral, this.getObligationPda());
3105
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2796
3106
  if (!account) {
2797
- farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
3107
+ farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
2798
3108
  }
2799
3109
  }
2800
3110
 
2801
3111
  if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
2802
- const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
2803
- const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
3112
+ const pda = obligationFarmStatePda(reserve.state.farmDebt, this.getObligationPda());
3113
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2804
3114
  if (!account) {
2805
- farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
3115
+ farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
2806
3116
  }
2807
3117
  }
2808
3118
 
@@ -2836,7 +3146,7 @@ export class KaminoAction {
2836
3146
  });
2837
3147
  }
2838
3148
 
2839
- private async addInitObligationIxs() {
3149
+ private addInitObligationIxs() {
2840
3150
  if (!this.obligation) {
2841
3151
  const obligationPda = this.getObligationPda();
2842
3152
  const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
@@ -3051,7 +3361,7 @@ export class KaminoAction {
3051
3361
 
3052
3362
  let safeRepay = new BN(this.amount);
3053
3363
 
3054
- if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
3364
+ if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new BN(U64_MAX))) {
3055
3365
  const borrow = this.obligation.state.borrows.find(
3056
3366
  (borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
3057
3367
  );
@@ -3065,7 +3375,7 @@ export class KaminoAction {
3065
3375
  this.currentSlot,
3066
3376
  this.kaminoMarket.state.referralFeeBps
3067
3377
  );
3068
- // TODO: shouldn't this calc be added to all other stuff as well?
3378
+
3069
3379
  safeRepay = new BN(
3070
3380
  Math.floor(
3071
3381
  KaminoObligation.getBorrowAmount(borrow)
@@ -3093,6 +3403,7 @@ export class KaminoAction {
3093
3403
  const sendAction =
3094
3404
  action === 'deposit' ||
3095
3405
  action === 'repay' ||
3406
+ action === 'repayAndWithdrawV2' ||
3096
3407
  action === 'mint' ||
3097
3408
  (action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
3098
3409
 
@@ -3202,7 +3513,7 @@ export class KaminoAction {
3202
3513
  additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
3203
3514
  primaryMint = inflowTokenMint;
3204
3515
  secondaryMint = outflowTokenMint;
3205
- } else if (action === 'repayAndWithdraw') {
3516
+ } else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2' || action === 'depositAndWithdraw') {
3206
3517
  primaryMint = inflowTokenMint;
3207
3518
  secondaryMint = outflowTokenMint;
3208
3519
  userTokenAccountAddress = userInflowTokenAccountAddress;
@@ -50,6 +50,7 @@ import {
50
50
  ReserveWithAddress,
51
51
  sameLengthArrayEquals,
52
52
  ScopeOracleConfig,
53
+ sleep,
53
54
  updateEntireReserveConfigIx,
54
55
  updateLendingMarket,
55
56
  UpdateLendingMarketAccounts,
@@ -593,14 +594,11 @@ export class KaminoManager {
593
594
  }
594
595
  );
595
596
 
597
+ await sleep(500);
598
+
596
599
  const markets = await Promise.all(
597
600
  lendingMarketsAccounts.map((account) =>
598
- KaminoMarket.load(
599
- this._connection,
600
- account.pubkey,
601
- this.recentSlotDurationMs,
602
- this._kaminoLendProgramId
603
- )
601
+ KaminoMarket.load(this._connection, account.pubkey, this.recentSlotDurationMs, this._kaminoLendProgramId)
604
602
  )
605
603
  );
606
604
  return markets.filter((market): market is KaminoMarket => market !== null);
@@ -267,7 +267,7 @@ export class KaminoObligation {
267
267
  /**
268
268
  * @returns total borrow power of the obligation, relative to max LTV of each asset's reserve
269
269
  */
270
- getAllowedBorrowValue(): Decimal {
270
+ getMaxAllowedBorrowValue(): Decimal {
271
271
  return new Fraction(this.state.allowedBorrowValueSf).toDecimal();
272
272
  }
273
273
 
@@ -82,7 +82,7 @@ import {
82
82
  import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
83
83
  import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
84
84
  import { FarmState } from '@kamino-finance/farms-sdk/dist';
85
- import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
85
+ import { getAccountsInLUT, initLookupTableIx } from '../utils/lookupTable';
86
86
  import {
87
87
  getFarmStakeIxs,
88
88
  getFarmUnstakeAndWithdrawIxs,