@kamino-finance/klend-sdk 5.11.2-beta.0 → 5.11.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.
Files changed (72) hide show
  1. package/dist/classes/action.d.ts +2 -12
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +29 -245
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/lut_utils.d.ts +29 -0
  6. package/dist/classes/lut_utils.d.ts.map +1 -0
  7. package/dist/classes/lut_utils.js +62 -0
  8. package/dist/classes/lut_utils.js.map +1 -0
  9. package/dist/classes/obligation.d.ts +1 -1
  10. package/dist/classes/obligation.d.ts.map +1 -1
  11. package/dist/classes/obligation.js +1 -1
  12. package/dist/classes/obligation.js.map +1 -1
  13. package/dist/classes/vault.js +18 -18
  14. package/dist/classes/vault.js.map +1 -1
  15. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -3
  16. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  17. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +6 -6
  18. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  19. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
  20. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
  21. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
  22. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
  23. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
  24. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
  25. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
  26. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
  27. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
  28. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
  29. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
  30. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
  31. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
  32. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
  33. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
  34. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
  35. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
  36. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
  37. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
  38. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
  39. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  40. package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
  41. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  42. package/dist/lending_operations/repay_with_collateral_operations.d.ts +0 -5
  43. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  44. package/dist/lending_operations/repay_with_collateral_operations.js +1 -26
  45. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  46. package/dist/utils/lookupTable.d.ts +0 -27
  47. package/dist/utils/lookupTable.d.ts.map +1 -1
  48. package/dist/utils/lookupTable.js +0 -58
  49. package/dist/utils/lookupTable.js.map +1 -1
  50. package/dist/utils/seeds.d.ts +1 -11
  51. package/dist/utils/seeds.d.ts.map +1 -1
  52. package/dist/utils/seeds.js +3 -13
  53. package/dist/utils/seeds.js.map +1 -1
  54. package/dist/utils/userMetadata.js +6 -6
  55. package/dist/utils/userMetadata.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/classes/action.ts +49 -378
  58. package/src/classes/lut_utils.ts +63 -0
  59. package/src/classes/obligation.ts +1 -1
  60. package/src/classes/vault.ts +15 -15
  61. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +8 -8
  62. package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
  63. package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
  64. package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
  65. package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
  66. package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
  67. package/src/idl_kamino_vault.json +7 -7
  68. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
  69. package/src/lending_operations/repay_with_collateral_operations.ts +20 -63
  70. package/src/utils/lookupTable.ts +0 -62
  71. package/src/utils/seeds.ts +4 -14
  72. package/src/utils/userMetadata.ts +14 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamino-finance/klend-sdk",
3
- "version": "5.11.2-beta.0",
3
+ "version": "5.11.2",
4
4
  "description": "Typescript SDK for interacting with the Kamino Lending (klend) protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,6 @@ import BN from 'bn.js';
21
21
  import Decimal from 'decimal.js';
22
22
  import {
23
23
  borrowObligationLiquidity,
24
- depositAndWithdraw,
25
24
  borrowObligationLiquidityV2,
26
25
  depositObligationCollateral,
27
26
  depositObligationCollateralV2,
@@ -42,7 +41,6 @@ import {
42
41
  RefreshObligationFarmsForReserveAccounts,
43
42
  RefreshObligationFarmsForReserveArgs,
44
43
  refreshReserve,
45
- repayAndWithdrawAndRedeem,
46
44
  repayObligationLiquidity,
47
45
  repayObligationLiquidityV2,
48
46
  requestElevationGroup,
@@ -92,9 +90,7 @@ export type ActionType =
92
90
  | 'repayAndWithdraw'
93
91
  | 'refreshObligation'
94
92
  | 'requestElevationGroup'
95
- | 'withdrawReferrerFees'
96
- | 'repayAndWithdrawV2'
97
- | 'depositAndWithdraw';
93
+ | 'withdrawReferrerFees';
98
94
 
99
95
  export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
100
96
 
@@ -821,132 +817,6 @@ export class KaminoAction {
821
817
  return axn;
822
818
  }
823
819
 
824
- static async buildDepositAndWithdrawV2Txns(
825
- kaminoMarket: KaminoMarket,
826
- depositAmount: string | BN,
827
- depositMint: PublicKey,
828
- withdrawAmount: string | BN,
829
- withdrawMint: PublicKey,
830
- payer: PublicKey,
831
- currentSlot: number,
832
- obligation: KaminoObligation | ObligationType,
833
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
834
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
835
- requestElevationGroup: boolean = false,
836
- includeUserMetadata: boolean = true, // if true it includes user metadata,
837
- referrer: PublicKey = PublicKey.default,
838
- scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
839
- ) {
840
- const axn = await KaminoAction.initializeMultiTokenAction(
841
- kaminoMarket,
842
- 'depositAndWithdraw',
843
- depositAmount,
844
- depositMint,
845
- withdrawMint,
846
- payer,
847
- payer,
848
- obligation,
849
- withdrawAmount,
850
- referrer,
851
- currentSlot
852
- );
853
- const addInitObligationForFarm = true;
854
- const twoTokenAction = true;
855
- if (extraComputeBudget > 0) {
856
- axn.addComputeBudgetIxn(extraComputeBudget);
857
- }
858
-
859
- const allReserves = new PublicKeySet<PublicKey>([
860
- ...axn.depositReserves,
861
- ...axn.borrowReserves,
862
- axn.reserve.address,
863
- axn.outflowReserve!.address,
864
- ]).toArray();
865
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
866
-
867
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
868
- await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
869
- }
870
-
871
- await axn.addSupportIxs(
872
- 'depositAndWithdraw',
873
- includeAtaIxns,
874
- requestElevationGroup,
875
- includeUserMetadata,
876
- addInitObligationForFarm,
877
- true,
878
- twoTokenAction
879
- );
880
- const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
881
- axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
882
-
883
- return axn;
884
- }
885
-
886
- static async buildRepayAndWithdrawV2Txns(
887
- kaminoMarket: KaminoMarket,
888
- repayAmount: string | BN,
889
- repayMint: PublicKey,
890
- withdrawAmount: string | BN,
891
- withdrawMint: PublicKey,
892
- payer: PublicKey,
893
- currentSlot: number,
894
- obligation: KaminoObligation | ObligationType,
895
- extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
896
- includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
897
- requestElevationGroup: boolean = false,
898
- includeUserMetadata: boolean = true, // if true it includes user metadata,
899
- createLookupTable: boolean = true,
900
- referrer: PublicKey = PublicKey.default,
901
- scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
902
- ) {
903
- const axn = await KaminoAction.initializeMultiTokenAction(
904
- kaminoMarket,
905
- 'repayAndWithdrawV2',
906
- repayAmount,
907
- repayMint,
908
- withdrawMint,
909
- payer,
910
- payer,
911
- obligation,
912
- withdrawAmount,
913
- referrer,
914
- currentSlot
915
- );
916
- const addInitObligationForFarm = true;
917
- const twoTokenAction = true;
918
- if (extraComputeBudget > 0) {
919
- axn.addComputeBudgetIxn(extraComputeBudget);
920
- }
921
-
922
- const allReserves = new PublicKeySet<PublicKey>([
923
- ...axn.depositReserves,
924
- ...axn.borrowReserves,
925
- axn.reserve.address,
926
- axn.outflowReserve!.address,
927
- ]).toArray();
928
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
929
-
930
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
931
- await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
932
- }
933
-
934
- await axn.addSupportIxs(
935
- 'repayAndWithdrawV2',
936
- includeAtaIxns,
937
- requestElevationGroup,
938
- includeUserMetadata,
939
- addInitObligationForFarm,
940
- true,
941
- createLookupTable,
942
- twoTokenAction
943
- );
944
- const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
945
- axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
946
-
947
- return axn;
948
- }
949
-
950
820
  static async buildRepayAndWithdrawTxns(
951
821
  kaminoMarket: KaminoMarket,
952
822
  repayAmount: string | BN,
@@ -1458,7 +1328,10 @@ export class KaminoAction {
1458
1328
  reserveFarmState: PROGRAM_ID,
1459
1329
  }
1460
1330
  : {
1461
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1331
+ obligationFarmUserState: obligationFarmStatePda(
1332
+ this.getObligationPda(),
1333
+ this.reserve.state.farmCollateral
1334
+ )[0],
1462
1335
  reserveFarmState: this.reserve.state.farmCollateral,
1463
1336
  };
1464
1337
 
@@ -1523,7 +1396,10 @@ export class KaminoAction {
1523
1396
  reserveFarmState: PROGRAM_ID,
1524
1397
  }
1525
1398
  : {
1526
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1399
+ obligationFarmUserState: obligationFarmStatePda(
1400
+ this.getObligationPda(),
1401
+ this.reserve.state.farmCollateral
1402
+ )[0],
1527
1403
  reserveFarmState: this.reserve.state.farmCollateral,
1528
1404
  };
1529
1405
 
@@ -1605,7 +1481,7 @@ export class KaminoAction {
1605
1481
  reserveFarmState: PROGRAM_ID,
1606
1482
  }
1607
1483
  : {
1608
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1484
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1609
1485
  reserveFarmState: this.reserve.state.farmDebt,
1610
1486
  };
1611
1487
 
@@ -1680,7 +1556,10 @@ export class KaminoAction {
1680
1556
  reserveFarmState: PROGRAM_ID,
1681
1557
  }
1682
1558
  : {
1683
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1559
+ obligationFarmUserState: obligationFarmStatePda(
1560
+ this.getObligationPda(),
1561
+ this.reserve.state.farmCollateral
1562
+ )[0],
1684
1563
  reserveFarmState: this.reserve.state.farmCollateral,
1685
1564
  };
1686
1565
 
@@ -1764,7 +1643,7 @@ export class KaminoAction {
1764
1643
  reserveFarmState: PROGRAM_ID,
1765
1644
  }
1766
1645
  : {
1767
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1646
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
1768
1647
  reserveFarmState: this.reserve.state.farmDebt,
1769
1648
  };
1770
1649
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -1800,208 +1679,6 @@ export class KaminoAction {
1800
1679
  this.lendingIxs.push(repayIx);
1801
1680
  }
1802
1681
 
1803
- addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1804
- this.lendingIxsLabels.push(
1805
- `repayAndWithdrawAndRedeem(repayReserve=${this.reserve!.address})(withdrawReserve=${
1806
- this.outflowReserve!.address
1807
- })(obligation=${this.getObligationPda()})`
1808
- );
1809
-
1810
- const depositReservesList = this.getAdditionalDepositReservesList();
1811
-
1812
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1813
- return { pubkey: reserve, isSigner: false, isWritable: true };
1814
- });
1815
- const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
1816
- return { pubkey: reserve, isSigner: false, isWritable: true };
1817
- });
1818
-
1819
- if (!this.outflowAmount) {
1820
- throw new Error(`outflowAmount not set`);
1821
- }
1822
-
1823
- if (!this.outflowReserve) {
1824
- throw new Error(`outflowReserve not set`);
1825
- }
1826
-
1827
- if (!this.additionalTokenAccountAddress) {
1828
- throw new Error(`additionalTokenAccountAddress not set`);
1829
- }
1830
-
1831
- const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1832
- ? {
1833
- obligationFarmUserState: this.kaminoMarket.programId,
1834
- reserveFarmState: this.kaminoMarket.programId,
1835
- }
1836
- : {
1837
- obligationFarmUserState: obligationFarmStatePda(
1838
- this.outflowReserve.state.farmCollateral,
1839
- this.getObligationPda()
1840
- ),
1841
- reserveFarmState: this.outflowReserve.state.farmCollateral,
1842
- };
1843
-
1844
- const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
1845
- ? {
1846
- obligationFarmUserState: this.kaminoMarket.programId,
1847
- reserveFarmState: this.kaminoMarket.programId,
1848
- }
1849
- : {
1850
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1851
- reserveFarmState: this.reserve.state.farmDebt,
1852
- };
1853
-
1854
- const repayAndWithdrawIx = repayAndWithdrawAndRedeem(
1855
- {
1856
- repayAmount: this.amount,
1857
- withdrawCollateralAmount,
1858
- },
1859
- {
1860
- repayAccounts: {
1861
- owner: this.owner,
1862
- obligation: this.getObligationPda(),
1863
- lendingMarket: this.kaminoMarket.getAddress(),
1864
- repayReserve: this.reserve!.address,
1865
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1866
- userSourceLiquidity: this.userTokenAccountAddress,
1867
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
1868
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
1869
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1870
- },
1871
- withdrawAccounts: {
1872
- owner: this.owner,
1873
- obligation: this.getObligationPda(),
1874
- lendingMarket: this.kaminoMarket.getAddress(),
1875
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1876
- withdrawReserve: this.outflowReserve.address,
1877
- reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1878
- reserveCollateralMint: this.outflowReserve.getCTokenMint(),
1879
- reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1880
- reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
1881
- userDestinationLiquidity: this.additionalTokenAccountAddress,
1882
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1883
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1884
- liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1885
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1886
- },
1887
- collateralFarmsAccounts,
1888
- debtFarmsAccounts,
1889
- farmsProgram: farmsId,
1890
- },
1891
- this.kaminoMarket.programId
1892
- );
1893
-
1894
- repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
1895
- ...depositReserveAccountMetas,
1896
- ...borrowReserveAccountMetas,
1897
- ]);
1898
-
1899
- this.lendingIxs.push(repayAndWithdrawIx);
1900
- }
1901
-
1902
- addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
1903
- this.lendingIxsLabels.push(
1904
- `depositAndWithdrawV2(depositReserve=${this.reserve!.address})(withdrawReserve=${
1905
- this.outflowReserve!.address
1906
- })(obligation=${this.getObligationPda()})`
1907
- );
1908
-
1909
- const depositReservesList = this.getAdditionalDepositReservesList();
1910
-
1911
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
1912
- return { pubkey: reserve, isSigner: false, isWritable: true };
1913
- });
1914
- const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
1915
- return { pubkey: reserve, isSigner: false, isWritable: true };
1916
- });
1917
-
1918
- if (!this.outflowAmount) {
1919
- throw new Error(`outflowAmount not set`);
1920
- }
1921
-
1922
- if (!this.outflowReserve) {
1923
- throw new Error(`outflowReserve not set`);
1924
- }
1925
-
1926
- if (!this.additionalTokenAccountAddress) {
1927
- throw new Error(`additionalTokenAccountAddress not set`);
1928
- }
1929
-
1930
- const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
1931
- ? {
1932
- obligationFarmUserState: this.kaminoMarket.programId,
1933
- reserveFarmState: this.kaminoMarket.programId,
1934
- }
1935
- : {
1936
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1937
- reserveFarmState: this.reserve.state.farmCollateral,
1938
- };
1939
- const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
1940
- ? {
1941
- obligationFarmUserState: this.kaminoMarket.programId,
1942
- reserveFarmState: this.kaminoMarket.programId,
1943
- }
1944
- : {
1945
- obligationFarmUserState: obligationFarmStatePda(
1946
- this.outflowReserve.state.farmCollateral,
1947
- this.getObligationPda()
1948
- ),
1949
- reserveFarmState: this.outflowReserve.state.farmCollateral,
1950
- };
1951
-
1952
- const depositAndWithdrawIx = depositAndWithdraw(
1953
- {
1954
- liquidityAmount: this.amount,
1955
- withdrawCollateralAmount,
1956
- },
1957
- {
1958
- depositAccounts: {
1959
- owner: this.owner,
1960
- obligation: this.getObligationPda(),
1961
- lendingMarket: this.kaminoMarket.getAddress(),
1962
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1963
- reserve: this.reserve.address,
1964
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
1965
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
1966
- reserveCollateralMint: this.reserve.getCTokenMint(),
1967
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
1968
- userSourceLiquidity: this.userTokenAccountAddress,
1969
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1970
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1971
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
1972
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1973
- },
1974
- withdrawAccounts: {
1975
- owner: this.owner,
1976
- obligation: this.getObligationPda(),
1977
- lendingMarket: this.kaminoMarket.getAddress(),
1978
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1979
- withdrawReserve: this.outflowReserve.address,
1980
- reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
1981
- reserveCollateralMint: this.outflowReserve.getCTokenMint(),
1982
- reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
1983
- reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
1984
- userDestinationLiquidity: this.additionalTokenAccountAddress,
1985
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
1986
- collateralTokenProgram: TOKEN_PROGRAM_ID,
1987
- liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
1988
- instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
1989
- },
1990
- depositFarmsAccounts,
1991
- withdrawFarmsAccounts,
1992
- farmsProgram: farmsId,
1993
- },
1994
- this.kaminoMarket.programId
1995
- );
1996
-
1997
- depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
1998
- ...depositReserveAccountMetas,
1999
- ...borrowReserveAccountMetas,
2000
- ]);
2001
-
2002
- this.lendingIxs.push(depositAndWithdrawIx);
2003
- }
2004
-
2005
1682
  async addDepositAndBorrowIx() {
2006
1683
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
2007
1684
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
@@ -2087,7 +1764,10 @@ export class KaminoAction {
2087
1764
  reserveFarmState: PROGRAM_ID,
2088
1765
  }
2089
1766
  : {
2090
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
1767
+ obligationFarmUserState: obligationFarmStatePda(
1768
+ this.getObligationPda(),
1769
+ this.reserve.state.farmCollateral
1770
+ )[0],
2091
1771
  reserveFarmState: this.reserve.state.farmCollateral,
2092
1772
  };
2093
1773
 
@@ -2148,7 +1828,10 @@ export class KaminoAction {
2148
1828
  reserveFarmState: PROGRAM_ID,
2149
1829
  }
2150
1830
  : {
2151
- obligationFarmUserState: obligationFarmStatePda(this.outflowReserve.state.farmDebt, this.getObligationPda()),
1831
+ obligationFarmUserState: obligationFarmStatePda(
1832
+ this.getObligationPda(),
1833
+ this.outflowReserve.state.farmDebt!
1834
+ )[0],
2152
1835
  reserveFarmState: this.outflowReserve.state.farmDebt,
2153
1836
  };
2154
1837
 
@@ -2274,7 +1957,7 @@ export class KaminoAction {
2274
1957
  reserveFarmState: PROGRAM_ID,
2275
1958
  }
2276
1959
  : {
2277
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
1960
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
2278
1961
  reserveFarmState: this.reserve.state.farmDebt,
2279
1962
  };
2280
1963
 
@@ -2323,9 +2006,9 @@ export class KaminoAction {
2323
2006
  }
2324
2007
  : {
2325
2008
  obligationFarmUserState: obligationFarmStatePda(
2326
- this.outflowReserve.state.farmCollateral,
2327
- this.getObligationPda()
2328
- ),
2009
+ this.getObligationPda(),
2010
+ this.outflowReserve.state.farmCollateral
2011
+ )[0],
2329
2012
  reserveFarmState: this.outflowReserve.state.farmCollateral,
2330
2013
  };
2331
2014
 
@@ -2359,7 +2042,7 @@ export class KaminoAction {
2359
2042
  );
2360
2043
  }
2361
2044
 
2362
- addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
2045
+ async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
2363
2046
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
2364
2047
  if (!this.outflowReserve) {
2365
2048
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -2432,9 +2115,9 @@ export class KaminoAction {
2432
2115
  }
2433
2116
  : {
2434
2117
  obligationFarmUserState: obligationFarmStatePda(
2435
- this.outflowReserve.state.farmCollateral,
2436
- this.getObligationPda()
2437
- ),
2118
+ this.getObligationPda(),
2119
+ this.outflowReserve.state.farmCollateral
2120
+ )[0],
2438
2121
  reserveFarmState: this.outflowReserve.state.farmCollateral,
2439
2122
  };
2440
2123
 
@@ -2444,7 +2127,7 @@ export class KaminoAction {
2444
2127
  reserveFarmState: PROGRAM_ID,
2445
2128
  }
2446
2129
  : {
2447
- obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
2130
+ obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
2448
2131
  reserveFarmState: this.reserve.state.farmDebt,
2449
2132
  };
2450
2133
 
@@ -2556,7 +2239,6 @@ export class KaminoAction {
2556
2239
  'repay',
2557
2240
  'depositAndBorrow',
2558
2241
  'repayAndWithdraw',
2559
- 'repayAndWithdrawV2',
2560
2242
  'refreshObligation',
2561
2243
  ].includes(action)
2562
2244
  ) {
@@ -2575,17 +2257,12 @@ export class KaminoAction {
2575
2257
 
2576
2258
  let currentReserves: KaminoReserve[] = [];
2577
2259
 
2578
- if (
2579
- action === 'liquidate' ||
2580
- action === 'depositAndBorrow' ||
2581
- action === 'repayAndWithdraw' ||
2582
- action === 'repayAndWithdrawV2'
2583
- ) {
2260
+ if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2584
2261
  if (!this.outflowReserve) {
2585
2262
  throw new Error('outflowReserve is undefined');
2586
2263
  }
2587
2264
 
2588
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
2265
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
2589
2266
  currentReserves = [this.reserve, this.outflowReserve];
2590
2267
  if (action === 'depositAndBorrow') {
2591
2268
  if (this.obligation) {
@@ -2630,12 +2307,7 @@ export class KaminoAction {
2630
2307
  if (this.outflowReserve) {
2631
2308
  await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
2632
2309
  }
2633
- } else if (
2634
- action === 'repayAndWithdraw' ||
2635
- action === 'borrow' ||
2636
- action === 'repay' ||
2637
- action === 'repayAndWithdrawV2'
2638
- ) {
2310
+ } else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
2639
2311
  // todo - probably don't need to add both debt and collateral for everything here
2640
2312
  await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
2641
2313
  if (this.outflowReserve) {
@@ -2666,7 +2338,7 @@ export class KaminoAction {
2666
2338
  }
2667
2339
 
2668
2340
  if (requestElevationGroup) {
2669
- if (action === 'repay' || action === 'repayAndWithdrawV2') {
2341
+ if (action === 'repay') {
2670
2342
  const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
2671
2343
 
2672
2344
  if (!repayObligationLiquidity) {
@@ -2855,7 +2527,7 @@ export class KaminoAction {
2855
2527
  if (action === 'deposit' && this.outflowReserve) {
2856
2528
  await this.addInitReferrerTokenStateIx(this.outflowReserve);
2857
2529
  }
2858
- this.addInitObligationIxs();
2530
+ await this.addInitObligationIxs();
2859
2531
  }
2860
2532
 
2861
2533
  await this.addSupportIxsWithoutInitObligation(
@@ -3087,7 +2759,7 @@ export class KaminoAction {
3087
2759
  farms.push([
3088
2760
  ReserveFarmKind.Collateral,
3089
2761
  kaminoReserve.state.farmCollateral,
3090
- obligationFarmStatePda(kaminoReserve.state.farmCollateral, this.getObligationPda()),
2762
+ obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
3091
2763
  kaminoReserve,
3092
2764
  ]);
3093
2765
  }
@@ -3095,7 +2767,7 @@ export class KaminoAction {
3095
2767
  farms.push([
3096
2768
  ReserveFarmKind.Debt,
3097
2769
  kaminoReserve.state.farmDebt,
3098
- obligationFarmStatePda(kaminoReserve.state.farmDebt, this.getObligationPda()),
2770
+ obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
3099
2771
  kaminoReserve,
3100
2772
  ]);
3101
2773
  }
@@ -3179,18 +2851,18 @@ export class KaminoAction {
3179
2851
  const farms: [number, PublicKey, PublicKey][] = [];
3180
2852
 
3181
2853
  if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
3182
- const pda = obligationFarmStatePda(reserve.state.farmCollateral, this.getObligationPda());
3183
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2854
+ const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
2855
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
3184
2856
  if (!account) {
3185
- farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
2857
+ farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
3186
2858
  }
3187
2859
  }
3188
2860
 
3189
2861
  if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
3190
- const pda = obligationFarmStatePda(reserve.state.farmDebt, this.getObligationPda());
3191
- const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
2862
+ const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
2863
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
3192
2864
  if (!account) {
3193
- farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
2865
+ farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
3194
2866
  }
3195
2867
  }
3196
2868
 
@@ -3224,7 +2896,7 @@ export class KaminoAction {
3224
2896
  });
3225
2897
  }
3226
2898
 
3227
- private addInitObligationIxs() {
2899
+ private async addInitObligationIxs() {
3228
2900
  if (!this.obligation) {
3229
2901
  const obligationPda = this.getObligationPda();
3230
2902
  const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
@@ -3447,7 +3119,7 @@ export class KaminoAction {
3447
3119
 
3448
3120
  let safeRepay = new BN(this.amount);
3449
3121
 
3450
- if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new BN(U64_MAX))) {
3122
+ if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
3451
3123
  const borrow = this.obligation.state.borrows.find(
3452
3124
  (borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
3453
3125
  );
@@ -3461,7 +3133,7 @@ export class KaminoAction {
3461
3133
  this.currentSlot,
3462
3134
  this.kaminoMarket.state.referralFeeBps
3463
3135
  );
3464
-
3136
+ // TODO: shouldn't this calc be added to all other stuff as well?
3465
3137
  safeRepay = new BN(
3466
3138
  Math.floor(
3467
3139
  KaminoObligation.getBorrowAmount(borrow)
@@ -3489,7 +3161,6 @@ export class KaminoAction {
3489
3161
  const sendAction =
3490
3162
  action === 'deposit' ||
3491
3163
  action === 'repay' ||
3492
- action === 'repayAndWithdrawV2' ||
3493
3164
  action === 'mint' ||
3494
3165
  (action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
3495
3166
 
@@ -3599,7 +3270,7 @@ export class KaminoAction {
3599
3270
  additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
3600
3271
  primaryMint = inflowTokenMint;
3601
3272
  secondaryMint = outflowTokenMint;
3602
- } else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
3273
+ } else if (action === 'repayAndWithdraw') {
3603
3274
  primaryMint = inflowTokenMint;
3604
3275
  secondaryMint = outflowTokenMint;
3605
3276
  userTokenAccountAddress = userInflowTokenAccountAddress;