@kamino-finance/klend-sdk 5.11.5-beta.0 → 5.11.5
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/dist/classes/action.d.ts +2 -12
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +30 -228
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/lut_utils.d.ts +29 -0
- package/dist/classes/lut_utils.d.ts.map +1 -0
- package/dist/classes/lut_utils.js +62 -0
- package/dist/classes/lut_utils.js.map +1 -0
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +0 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/vault.js +6 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +0 -5
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +1 -26
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +0 -27
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +0 -58
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/seeds.d.ts +1 -11
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +3 -13
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +7 -8
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +50 -361
- package/src/classes/lut_utils.ts +63 -0
- package/src/classes/manager.ts +0 -3
- package/src/classes/obligation.ts +1 -1
- package/src/classes/types.ts +1 -1
- package/src/classes/vault.ts +1 -1
- package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
- package/src/lending_operations/repay_with_collateral_operations.ts +20 -63
- package/src/utils/lookupTable.ts +0 -62
- package/src/utils/seeds.ts +4 -14
- package/src/utils/userMetadata.ts +15 -16
package/src/classes/action.ts
CHANGED
|
@@ -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
|
|
|
@@ -772,112 +768,6 @@ export class KaminoAction {
|
|
|
772
768
|
return axn;
|
|
773
769
|
}
|
|
774
770
|
|
|
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
|
-
|
|
881
771
|
static async buildRepayAndWithdrawTxns(
|
|
882
772
|
kaminoMarket: KaminoMarket,
|
|
883
773
|
repayAmount: string | BN,
|
|
@@ -1371,7 +1261,10 @@ export class KaminoAction {
|
|
|
1371
1261
|
reserveFarmState: this.kaminoMarket.programId,
|
|
1372
1262
|
}
|
|
1373
1263
|
: {
|
|
1374
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1264
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1265
|
+
this.getObligationPda(),
|
|
1266
|
+
this.reserve.state.farmCollateral
|
|
1267
|
+
)[0],
|
|
1375
1268
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1376
1269
|
};
|
|
1377
1270
|
|
|
@@ -1436,7 +1329,10 @@ export class KaminoAction {
|
|
|
1436
1329
|
reserveFarmState: this.kaminoMarket.programId,
|
|
1437
1330
|
}
|
|
1438
1331
|
: {
|
|
1439
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1332
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1333
|
+
this.getObligationPda(),
|
|
1334
|
+
this.reserve.state.farmCollateral
|
|
1335
|
+
)[0],
|
|
1440
1336
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1441
1337
|
};
|
|
1442
1338
|
|
|
@@ -1518,7 +1414,7 @@ export class KaminoAction {
|
|
|
1518
1414
|
reserveFarmState: this.kaminoMarket.programId,
|
|
1519
1415
|
}
|
|
1520
1416
|
: {
|
|
1521
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
1417
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1522
1418
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
1523
1419
|
};
|
|
1524
1420
|
|
|
@@ -1593,7 +1489,10 @@ export class KaminoAction {
|
|
|
1593
1489
|
reserveFarmState: this.kaminoMarket.programId,
|
|
1594
1490
|
}
|
|
1595
1491
|
: {
|
|
1596
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1492
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1493
|
+
this.getObligationPda(),
|
|
1494
|
+
this.reserve.state.farmCollateral
|
|
1495
|
+
)[0],
|
|
1597
1496
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1598
1497
|
};
|
|
1599
1498
|
|
|
@@ -1677,7 +1576,7 @@ export class KaminoAction {
|
|
|
1677
1576
|
reserveFarmState: this.kaminoMarket.programId,
|
|
1678
1577
|
}
|
|
1679
1578
|
: {
|
|
1680
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
1579
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1681
1580
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
1682
1581
|
};
|
|
1683
1582
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
@@ -1713,208 +1612,6 @@ export class KaminoAction {
|
|
|
1713
1612
|
this.lendingIxs.push(repayIx);
|
|
1714
1613
|
}
|
|
1715
1614
|
|
|
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
|
-
|
|
1918
1615
|
async addDepositAndBorrowIx() {
|
|
1919
1616
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1920
1617
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -2000,7 +1697,10 @@ export class KaminoAction {
|
|
|
2000
1697
|
reserveFarmState: this.kaminoMarket.programId,
|
|
2001
1698
|
}
|
|
2002
1699
|
: {
|
|
2003
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1700
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1701
|
+
this.getObligationPda(),
|
|
1702
|
+
this.reserve.state.farmCollateral
|
|
1703
|
+
)[0],
|
|
2004
1704
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
2005
1705
|
};
|
|
2006
1706
|
|
|
@@ -2061,7 +1761,10 @@ export class KaminoAction {
|
|
|
2061
1761
|
reserveFarmState: this.kaminoMarket.programId,
|
|
2062
1762
|
}
|
|
2063
1763
|
: {
|
|
2064
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1764
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1765
|
+
this.getObligationPda(),
|
|
1766
|
+
this.outflowReserve.state.farmDebt!
|
|
1767
|
+
)[0],
|
|
2065
1768
|
reserveFarmState: this.outflowReserve.state.farmDebt,
|
|
2066
1769
|
};
|
|
2067
1770
|
|
|
@@ -2187,7 +1890,7 @@ export class KaminoAction {
|
|
|
2187
1890
|
reserveFarmState: this.kaminoMarket.programId,
|
|
2188
1891
|
}
|
|
2189
1892
|
: {
|
|
2190
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
1893
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
2191
1894
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
2192
1895
|
};
|
|
2193
1896
|
|
|
@@ -2236,9 +1939,9 @@ export class KaminoAction {
|
|
|
2236
1939
|
}
|
|
2237
1940
|
: {
|
|
2238
1941
|
obligationFarmUserState: obligationFarmStatePda(
|
|
2239
|
-
this.
|
|
2240
|
-
this.
|
|
2241
|
-
),
|
|
1942
|
+
this.getObligationPda(),
|
|
1943
|
+
this.outflowReserve.state.farmCollateral
|
|
1944
|
+
)[0],
|
|
2242
1945
|
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2243
1946
|
};
|
|
2244
1947
|
|
|
@@ -2272,7 +1975,7 @@ export class KaminoAction {
|
|
|
2272
1975
|
);
|
|
2273
1976
|
}
|
|
2274
1977
|
|
|
2275
|
-
addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
1978
|
+
async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
2276
1979
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
2277
1980
|
if (!this.outflowReserve) {
|
|
2278
1981
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
@@ -2345,9 +2048,9 @@ export class KaminoAction {
|
|
|
2345
2048
|
}
|
|
2346
2049
|
: {
|
|
2347
2050
|
obligationFarmUserState: obligationFarmStatePda(
|
|
2348
|
-
this.
|
|
2349
|
-
this.
|
|
2350
|
-
),
|
|
2051
|
+
this.getObligationPda(),
|
|
2052
|
+
this.outflowReserve.state.farmCollateral
|
|
2053
|
+
)[0],
|
|
2351
2054
|
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2352
2055
|
};
|
|
2353
2056
|
|
|
@@ -2357,7 +2060,7 @@ export class KaminoAction {
|
|
|
2357
2060
|
reserveFarmState: this.kaminoMarket.programId,
|
|
2358
2061
|
}
|
|
2359
2062
|
: {
|
|
2360
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
2063
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
2361
2064
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
2362
2065
|
};
|
|
2363
2066
|
|
|
@@ -2469,9 +2172,7 @@ export class KaminoAction {
|
|
|
2469
2172
|
'repay',
|
|
2470
2173
|
'depositAndBorrow',
|
|
2471
2174
|
'repayAndWithdraw',
|
|
2472
|
-
'repayAndWithdrawV2',
|
|
2473
2175
|
'refreshObligation',
|
|
2474
|
-
'depositAndWithdraw',
|
|
2475
2176
|
].includes(action)
|
|
2476
2177
|
) {
|
|
2477
2178
|
// The support ixns in order are:
|
|
@@ -2489,17 +2190,12 @@ export class KaminoAction {
|
|
|
2489
2190
|
|
|
2490
2191
|
let currentReserves: KaminoReserve[] = [];
|
|
2491
2192
|
|
|
2492
|
-
if (
|
|
2493
|
-
action === 'liquidate' ||
|
|
2494
|
-
action === 'depositAndBorrow' ||
|
|
2495
|
-
action === 'repayAndWithdraw' ||
|
|
2496
|
-
action === 'repayAndWithdrawV2'
|
|
2497
|
-
) {
|
|
2193
|
+
if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
2498
2194
|
if (!this.outflowReserve) {
|
|
2499
2195
|
throw new Error('outflowReserve is undefined');
|
|
2500
2196
|
}
|
|
2501
2197
|
|
|
2502
|
-
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw'
|
|
2198
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
2503
2199
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
2504
2200
|
if (action === 'depositAndBorrow') {
|
|
2505
2201
|
if (this.obligation) {
|
|
@@ -2538,19 +2234,13 @@ export class KaminoAction {
|
|
|
2538
2234
|
action === 'depositAndBorrow' ||
|
|
2539
2235
|
action === 'depositCollateral' ||
|
|
2540
2236
|
action === 'withdraw' ||
|
|
2541
|
-
action === 'deposit'
|
|
2542
|
-
action === 'depositAndWithdraw'
|
|
2237
|
+
action === 'deposit'
|
|
2543
2238
|
) {
|
|
2544
2239
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Collateral, addAsSupportIx);
|
|
2545
|
-
if (this.outflowReserve
|
|
2240
|
+
if (this.outflowReserve) {
|
|
2546
2241
|
await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
2547
2242
|
}
|
|
2548
|
-
} else if (
|
|
2549
|
-
action === 'repayAndWithdraw' ||
|
|
2550
|
-
action === 'borrow' ||
|
|
2551
|
-
action === 'repay' ||
|
|
2552
|
-
action === 'repayAndWithdrawV2'
|
|
2553
|
-
) {
|
|
2243
|
+
} else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
2554
2244
|
// todo - probably don't need to add both debt and collateral for everything here
|
|
2555
2245
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
2556
2246
|
if (this.outflowReserve) {
|
|
@@ -2581,7 +2271,7 @@ export class KaminoAction {
|
|
|
2581
2271
|
}
|
|
2582
2272
|
|
|
2583
2273
|
if (requestElevationGroup) {
|
|
2584
|
-
if (action === 'repay'
|
|
2274
|
+
if (action === 'repay') {
|
|
2585
2275
|
const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
|
|
2586
2276
|
|
|
2587
2277
|
if (!repayObligationLiquidity) {
|
|
@@ -3009,7 +2699,7 @@ export class KaminoAction {
|
|
|
3009
2699
|
farms.push([
|
|
3010
2700
|
ReserveFarmKind.Collateral,
|
|
3011
2701
|
kaminoReserve.state.farmCollateral,
|
|
3012
|
-
obligationFarmStatePda(kaminoReserve.state.farmCollateral
|
|
2702
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
3013
2703
|
kaminoReserve,
|
|
3014
2704
|
]);
|
|
3015
2705
|
}
|
|
@@ -3017,7 +2707,7 @@ export class KaminoAction {
|
|
|
3017
2707
|
farms.push([
|
|
3018
2708
|
ReserveFarmKind.Debt,
|
|
3019
2709
|
kaminoReserve.state.farmDebt,
|
|
3020
|
-
obligationFarmStatePda(kaminoReserve.state.farmDebt
|
|
2710
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
3021
2711
|
kaminoReserve,
|
|
3022
2712
|
]);
|
|
3023
2713
|
}
|
|
@@ -3101,18 +2791,18 @@ export class KaminoAction {
|
|
|
3101
2791
|
const farms: [number, PublicKey, PublicKey][] = [];
|
|
3102
2792
|
|
|
3103
2793
|
if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
|
|
3104
|
-
const
|
|
3105
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
2794
|
+
const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
|
|
2795
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
3106
2796
|
if (!account) {
|
|
3107
|
-
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
2797
|
+
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
3108
2798
|
}
|
|
3109
2799
|
}
|
|
3110
2800
|
|
|
3111
2801
|
if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
|
|
3112
|
-
const
|
|
3113
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
2802
|
+
const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
|
|
2803
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
3114
2804
|
if (!account) {
|
|
3115
|
-
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
2805
|
+
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
3116
2806
|
}
|
|
3117
2807
|
}
|
|
3118
2808
|
|
|
@@ -3146,7 +2836,7 @@ export class KaminoAction {
|
|
|
3146
2836
|
});
|
|
3147
2837
|
}
|
|
3148
2838
|
|
|
3149
|
-
private addInitObligationIxs() {
|
|
2839
|
+
private async addInitObligationIxs() {
|
|
3150
2840
|
if (!this.obligation) {
|
|
3151
2841
|
const obligationPda = this.getObligationPda();
|
|
3152
2842
|
const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
|
|
@@ -3361,7 +3051,7 @@ export class KaminoAction {
|
|
|
3361
3051
|
|
|
3362
3052
|
let safeRepay = new BN(this.amount);
|
|
3363
3053
|
|
|
3364
|
-
if (this.obligation &&
|
|
3054
|
+
if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
|
|
3365
3055
|
const borrow = this.obligation.state.borrows.find(
|
|
3366
3056
|
(borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
|
|
3367
3057
|
);
|
|
@@ -3375,7 +3065,7 @@ export class KaminoAction {
|
|
|
3375
3065
|
this.currentSlot,
|
|
3376
3066
|
this.kaminoMarket.state.referralFeeBps
|
|
3377
3067
|
);
|
|
3378
|
-
|
|
3068
|
+
// TODO: shouldn't this calc be added to all other stuff as well?
|
|
3379
3069
|
safeRepay = new BN(
|
|
3380
3070
|
Math.floor(
|
|
3381
3071
|
KaminoObligation.getBorrowAmount(borrow)
|
|
@@ -3403,7 +3093,6 @@ export class KaminoAction {
|
|
|
3403
3093
|
const sendAction =
|
|
3404
3094
|
action === 'deposit' ||
|
|
3405
3095
|
action === 'repay' ||
|
|
3406
|
-
action === 'repayAndWithdrawV2' ||
|
|
3407
3096
|
action === 'mint' ||
|
|
3408
3097
|
(action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
3409
3098
|
|
|
@@ -3513,7 +3202,7 @@ export class KaminoAction {
|
|
|
3513
3202
|
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
3514
3203
|
primaryMint = inflowTokenMint;
|
|
3515
3204
|
secondaryMint = outflowTokenMint;
|
|
3516
|
-
} else if (action === 'repayAndWithdraw'
|
|
3205
|
+
} else if (action === 'repayAndWithdraw') {
|
|
3517
3206
|
primaryMint = inflowTokenMint;
|
|
3518
3207
|
secondaryMint = outflowTokenMint;
|
|
3519
3208
|
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
|
|
5
|
+
* @param payer - the owner of the lookup table
|
|
6
|
+
* @param slot - the current slot
|
|
7
|
+
* @returns - the instruction to create the lookup table and its address
|
|
8
|
+
*/
|
|
9
|
+
export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
|
|
10
|
+
const [ixn, address] = AddressLookupTableProgram.createLookupTable({
|
|
11
|
+
authority: payer,
|
|
12
|
+
payer,
|
|
13
|
+
recentSlot: slot,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return [ixn, address];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This method retuns an instruction that deactivates a lookup table, which is needed to close it
|
|
21
|
+
* @param payer - the owner of the lookup table
|
|
22
|
+
* @param lookupTable - the lookup table to deactivate
|
|
23
|
+
* @returns - the instruction to deactivate the lookup table
|
|
24
|
+
*/
|
|
25
|
+
export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
26
|
+
const ixn = AddressLookupTableProgram.deactivateLookupTable({
|
|
27
|
+
authority: payer,
|
|
28
|
+
lookupTable: lookupTable,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return ixn;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
|
|
36
|
+
* @param payer - the owner of the lookup table
|
|
37
|
+
* @param lookupTable - the lookup table to close
|
|
38
|
+
* @returns - the instruction to close the lookup table
|
|
39
|
+
*/
|
|
40
|
+
/// this require the LUT to be deactivated at least 500 blocks before
|
|
41
|
+
export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
42
|
+
const ixn = AddressLookupTableProgram.closeLookupTable({
|
|
43
|
+
authority: payer,
|
|
44
|
+
recipient: payer,
|
|
45
|
+
lookupTable: lookupTable,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return ixn;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns the accounts in a lookup table
|
|
53
|
+
* @param lookupTable - lookup table to get the accounts from
|
|
54
|
+
* @returns - an array of accounts in the lookup table
|
|
55
|
+
*/
|
|
56
|
+
export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
|
|
57
|
+
const lutState = await connection.getAddressLookupTable(lookupTable);
|
|
58
|
+
if (!lutState || !lutState.value) {
|
|
59
|
+
throw new Error(`Lookup table ${lookupTable} not found`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return lutState.value.state.addresses;
|
|
63
|
+
}
|