@kamino-finance/klend-sdk 5.10.33 → 5.10.35-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.
- package/dist/classes/action.d.ts +33 -26
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +614 -202
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +4 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +13 -4
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +2 -1
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/types.d.ts +4 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +1 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +4 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +39 -26
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +8 -3
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +269 -156
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +6 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.js +8 -1
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +51 -3
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +89 -5
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -2
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +3 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.js +5 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +9 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +24 -3
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +2 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +12 -4
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +15 -8
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -2
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +7 -6
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +9 -5
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -2
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +2 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -8
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +46 -37
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -1
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ata.d.ts +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +2 -2
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -9
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +5 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +1 -3
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +5 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +10 -1
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +8 -10
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +6 -3
- package/src/classes/action.ts +789 -214
- package/src/classes/manager.ts +18 -4
- package/src/classes/reserve.ts +2 -0
- package/src/classes/types.ts +5 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +49 -37
- package/src/client.ts +7 -3
- package/src/client_kamino_manager.ts +10 -3
- package/src/idl.json +269 -156
- package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
- package/src/idl_codegen/accounts/Obligation.ts +12 -1
- package/src/idl_codegen/errors/custom.ts +103 -4
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/index.ts +4 -4
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initReserve.ts +6 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/redeemFees.ts +1 -1
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +33 -3
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +2 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +18 -7
- package/src/lending_operations/repay_with_collateral_operations.ts +12 -3
- package/src/lending_operations/swap_collateral_operations.ts +17 -5
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +66 -29
- package/src/leverage/types.ts +4 -1
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/instruction.ts +1 -3
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +21 -26
package/dist/classes/action.js
CHANGED
|
@@ -143,9 +143,6 @@ class KaminoAction {
|
|
|
143
143
|
...(action === 'deposit' ? [reserve] : []),
|
|
144
144
|
...(action === 'depositAndBorrow' ? [outflowReserve] : []),
|
|
145
145
|
]).toArray().length;
|
|
146
|
-
if (distinctReserveCount > utils_1.POSITION_LIMIT) {
|
|
147
|
-
throw Error(`Obligation already has max number of positions: ${utils_1.POSITION_LIMIT}`);
|
|
148
|
-
}
|
|
149
146
|
return {
|
|
150
147
|
kaminoObligation,
|
|
151
148
|
depositReserves,
|
|
@@ -183,11 +180,11 @@ class KaminoAction {
|
|
|
183
180
|
axn.addRequestElevationIx(elevationGroup, 'setup');
|
|
184
181
|
return axn;
|
|
185
182
|
}
|
|
186
|
-
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
183
|
+
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
187
184
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
188
185
|
requestElevationGroup = false, // to be requested *before* the deposit
|
|
189
186
|
includeUserMetadata = true, // if true it includes user metadata
|
|
190
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
187
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
191
188
|
) {
|
|
192
189
|
const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
193
190
|
const addInitObligationForFarm = true;
|
|
@@ -203,8 +200,13 @@ class KaminoAction {
|
|
|
203
200
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
204
201
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
205
202
|
}
|
|
206
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
207
|
-
|
|
203
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
204
|
+
if (useV2Ixs) {
|
|
205
|
+
axn.addDepositIxV2();
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
axn.addDepositIx();
|
|
209
|
+
}
|
|
208
210
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
209
211
|
return axn;
|
|
210
212
|
}
|
|
@@ -236,10 +238,10 @@ class KaminoAction {
|
|
|
236
238
|
feed: feed,
|
|
237
239
|
}, tokens));
|
|
238
240
|
}
|
|
239
|
-
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
241
|
+
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
240
242
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
241
243
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
242
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
244
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
243
245
|
) {
|
|
244
246
|
const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
245
247
|
const addInitObligationForFarm = true;
|
|
@@ -255,15 +257,19 @@ class KaminoAction {
|
|
|
255
257
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
256
258
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
257
259
|
}
|
|
258
|
-
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
259
|
-
|
|
260
|
+
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
261
|
+
if (useV2Ixs) {
|
|
262
|
+
axn.addBorrowIxV2();
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
axn.addBorrowIx();
|
|
266
|
+
}
|
|
260
267
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
261
268
|
return axn;
|
|
262
269
|
}
|
|
263
270
|
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
264
271
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
265
|
-
requestElevationGroup = false,
|
|
266
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
272
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
267
273
|
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
268
274
|
const addInitObligationForFarm = true;
|
|
269
275
|
if (extraComputeBudget > 0) {
|
|
@@ -278,15 +284,14 @@ class KaminoAction {
|
|
|
278
284
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
279
285
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
280
286
|
}
|
|
281
|
-
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup,
|
|
287
|
+
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, false);
|
|
282
288
|
axn.addDepositReserveLiquidityIx();
|
|
283
289
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
284
290
|
return axn;
|
|
285
291
|
}
|
|
286
292
|
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
287
293
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
288
|
-
requestElevationGroup = false,
|
|
289
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
294
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
290
295
|
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
291
296
|
const addInitObligationForFarm = true;
|
|
292
297
|
if (extraComputeBudget > 0) {
|
|
@@ -301,15 +306,15 @@ class KaminoAction {
|
|
|
301
306
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
302
307
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
303
308
|
}
|
|
304
|
-
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup,
|
|
309
|
+
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, false);
|
|
305
310
|
axn.addRedeemReserveCollateralIx();
|
|
306
311
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
307
312
|
return axn;
|
|
308
313
|
}
|
|
309
|
-
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
314
|
+
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
310
315
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
311
316
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
312
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
317
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
313
318
|
const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
314
319
|
const addInitObligationForFarm = true;
|
|
315
320
|
if (extraComputeBudget > 0) {
|
|
@@ -324,15 +329,20 @@ class KaminoAction {
|
|
|
324
329
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
325
330
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
326
331
|
}
|
|
327
|
-
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
328
|
-
|
|
332
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
|
|
333
|
+
if (useV2Ixs) {
|
|
334
|
+
axn.addDepositObligationCollateralIxV2();
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
axn.addDepositObligationCollateralIx();
|
|
338
|
+
}
|
|
329
339
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
330
340
|
return axn;
|
|
331
341
|
}
|
|
332
|
-
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
342
|
+
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
333
343
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
334
344
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
335
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
345
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
336
346
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
|
|
337
347
|
const addInitObligationForFarmForDeposit = true;
|
|
338
348
|
const addInitObligationForFarmForBorrow = false;
|
|
@@ -350,16 +360,21 @@ class KaminoAction {
|
|
|
350
360
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
351
361
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
352
362
|
}
|
|
353
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, twoTokenAction);
|
|
354
|
-
|
|
355
|
-
|
|
363
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, createLookupTable, twoTokenAction);
|
|
364
|
+
if (useV2Ixs) {
|
|
365
|
+
await axn.addDepositAndBorrowIxV2();
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
await axn.addDepositAndBorrowIx();
|
|
369
|
+
}
|
|
370
|
+
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
|
|
356
371
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
357
372
|
return axn;
|
|
358
373
|
}
|
|
359
|
-
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
374
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
360
375
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
361
376
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
362
|
-
referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
377
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
363
378
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
364
379
|
const addInitObligationForFarmForRepay = true;
|
|
365
380
|
const addInitObligationForFarmForWithdraw = false;
|
|
@@ -377,17 +392,23 @@ class KaminoAction {
|
|
|
377
392
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
378
393
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
379
394
|
}
|
|
380
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, twoTokenAction);
|
|
381
|
-
|
|
382
|
-
|
|
395
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, createLookupTable, twoTokenAction);
|
|
396
|
+
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
397
|
+
if (useV2Ixs) {
|
|
398
|
+
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
402
|
+
}
|
|
403
|
+
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
|
|
383
404
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
384
405
|
return axn;
|
|
385
406
|
}
|
|
386
|
-
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
407
|
+
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
387
408
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
388
409
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
389
410
|
includeUserMetadata = true, // if true it includes user metadata
|
|
390
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = undefined, overrideElevationGroupRequest,
|
|
411
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = undefined, overrideElevationGroupRequest,
|
|
391
412
|
// Optional customizations which may be needed if the obligation was mutated by some previous ixn.
|
|
392
413
|
obligationCustomizations) {
|
|
393
414
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
@@ -405,8 +426,14 @@ class KaminoAction {
|
|
|
405
426
|
if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
|
|
406
427
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
407
428
|
}
|
|
408
|
-
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, overrideElevationGroupRequest);
|
|
409
|
-
|
|
429
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, false, overrideElevationGroupRequest);
|
|
430
|
+
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
431
|
+
if (useV2Ixs) {
|
|
432
|
+
await axn.addWithdrawIxV2(collateralAmount);
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
await axn.addWithdrawIx(collateralAmount);
|
|
436
|
+
}
|
|
410
437
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
411
438
|
return axn;
|
|
412
439
|
}
|
|
@@ -425,7 +452,7 @@ class KaminoAction {
|
|
|
425
452
|
* @param includeUserMetadata - if true it includes user metadata
|
|
426
453
|
* @param referrer
|
|
427
454
|
*/
|
|
428
|
-
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
455
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
429
456
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
430
457
|
const addInitObligationForFarm = true;
|
|
431
458
|
if (extraComputeBudget > 0) {
|
|
@@ -440,15 +467,20 @@ class KaminoAction {
|
|
|
440
467
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
441
468
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
442
469
|
}
|
|
443
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
444
|
-
|
|
470
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
|
|
471
|
+
if (useV2Ixs) {
|
|
472
|
+
await axn.addRepayIxV2();
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
await axn.addRepayIx();
|
|
476
|
+
}
|
|
445
477
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
446
478
|
return axn;
|
|
447
479
|
}
|
|
448
|
-
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
480
|
+
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
449
481
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
450
482
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
451
|
-
referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
483
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
452
484
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
453
485
|
const addInitObligationForFarm = true;
|
|
454
486
|
if (extraComputeBudget > 0) {
|
|
@@ -464,8 +496,13 @@ class KaminoAction {
|
|
|
464
496
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
465
497
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
466
498
|
}
|
|
467
|
-
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
468
|
-
|
|
499
|
+
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
|
|
500
|
+
if (useV2Ixs) {
|
|
501
|
+
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
505
|
+
}
|
|
469
506
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
470
507
|
return axn;
|
|
471
508
|
}
|
|
@@ -535,31 +572,29 @@ class KaminoAction {
|
|
|
535
572
|
return '';
|
|
536
573
|
return await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
537
574
|
}
|
|
538
|
-
|
|
539
|
-
this.lendingIxsLabels.push(`
|
|
540
|
-
this.lendingIxs.push((0, instructions_1.
|
|
575
|
+
addDepositReserveLiquidityIx() {
|
|
576
|
+
this.lendingIxsLabels.push(`depositReserveLiquidity`);
|
|
577
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
|
|
541
578
|
liquidityAmount: this.amount,
|
|
542
579
|
}, {
|
|
543
580
|
owner: this.owner,
|
|
544
|
-
obligation: this.getObligationPda(),
|
|
545
581
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
546
582
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
547
583
|
reserve: this.reserve.address,
|
|
548
584
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
549
585
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
550
586
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
551
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
552
587
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
553
|
-
|
|
588
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
554
589
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
555
590
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
556
591
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
557
592
|
}, this.kaminoMarket.programId));
|
|
558
593
|
}
|
|
559
|
-
|
|
560
|
-
this.lendingIxsLabels.push(`
|
|
561
|
-
this.lendingIxs.push((0, instructions_1.
|
|
562
|
-
|
|
594
|
+
addRedeemReserveCollateralIx() {
|
|
595
|
+
this.lendingIxsLabels.push(`redeemReserveCollateral`);
|
|
596
|
+
this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
|
|
597
|
+
collateralAmount: this.amount,
|
|
563
598
|
}, {
|
|
564
599
|
owner: this.owner,
|
|
565
600
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
@@ -568,32 +603,70 @@ class KaminoAction {
|
|
|
568
603
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
569
604
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
570
605
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
571
|
-
|
|
572
|
-
|
|
606
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
607
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
573
608
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
574
609
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
575
610
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
576
611
|
}, this.kaminoMarket.programId));
|
|
577
612
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
this.
|
|
581
|
-
|
|
613
|
+
// @deprecated -- use addDepositIxV2 instead
|
|
614
|
+
addDepositIx() {
|
|
615
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
616
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
|
|
617
|
+
liquidityAmount: this.amount,
|
|
582
618
|
}, {
|
|
583
619
|
owner: this.owner,
|
|
620
|
+
obligation: this.getObligationPda(),
|
|
584
621
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
585
622
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
586
623
|
reserve: this.reserve.address,
|
|
587
624
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
588
625
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
589
626
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
590
|
-
|
|
591
|
-
|
|
627
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
628
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
629
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
592
630
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
593
631
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
594
632
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
595
633
|
}, this.kaminoMarket.programId));
|
|
596
634
|
}
|
|
635
|
+
addDepositIxV2() {
|
|
636
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
637
|
+
? {
|
|
638
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
639
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
640
|
+
}
|
|
641
|
+
: {
|
|
642
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
643
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
644
|
+
};
|
|
645
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
646
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({
|
|
647
|
+
liquidityAmount: this.amount,
|
|
648
|
+
}, {
|
|
649
|
+
depositAccounts: {
|
|
650
|
+
owner: this.owner,
|
|
651
|
+
obligation: this.getObligationPda(),
|
|
652
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
653
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
654
|
+
reserve: this.reserve.address,
|
|
655
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
656
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
657
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
658
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
659
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
660
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
661
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
662
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
663
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
664
|
+
},
|
|
665
|
+
farmsAccounts,
|
|
666
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
667
|
+
}, this.kaminoMarket.programId));
|
|
668
|
+
}
|
|
669
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
597
670
|
addDepositObligationCollateralIx() {
|
|
598
671
|
this.lendingIxsLabels.push(`depositObligationCollateral`);
|
|
599
672
|
this.lendingIxs.push((0, instructions_1.depositObligationCollateral)({
|
|
@@ -609,6 +682,36 @@ class KaminoAction {
|
|
|
609
682
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
610
683
|
}, this.kaminoMarket.programId));
|
|
611
684
|
}
|
|
685
|
+
addDepositObligationCollateralIxV2() {
|
|
686
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
687
|
+
? {
|
|
688
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
689
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
690
|
+
}
|
|
691
|
+
: {
|
|
692
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
693
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
694
|
+
};
|
|
695
|
+
this.lendingIxsLabels.push(`depositObligationCollateralV2`);
|
|
696
|
+
this.lendingIxs.push((0, instructions_1.depositObligationCollateralV2)({
|
|
697
|
+
collateralAmount: this.amount,
|
|
698
|
+
}, {
|
|
699
|
+
depositAccounts: {
|
|
700
|
+
owner: this.owner,
|
|
701
|
+
obligation: this.getObligationPda(),
|
|
702
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
703
|
+
depositReserve: this.reserve.address,
|
|
704
|
+
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
705
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
706
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
707
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
708
|
+
},
|
|
709
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
710
|
+
farmsAccounts,
|
|
711
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
712
|
+
}, this.kaminoMarket.programId));
|
|
713
|
+
}
|
|
714
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
612
715
|
addBorrowIx() {
|
|
613
716
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
614
717
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
@@ -637,6 +740,164 @@ class KaminoAction {
|
|
|
637
740
|
: borrowIx.keys;
|
|
638
741
|
this.lendingIxs.push(borrowIx);
|
|
639
742
|
}
|
|
743
|
+
addBorrowIxV2() {
|
|
744
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
745
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
746
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
747
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
748
|
+
});
|
|
749
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
750
|
+
? {
|
|
751
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
752
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
753
|
+
}
|
|
754
|
+
: {
|
|
755
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
756
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
757
|
+
};
|
|
758
|
+
const borrowIx = (0, instructions_1.borrowObligationLiquidityV2)({
|
|
759
|
+
liquidityAmount: this.amount,
|
|
760
|
+
}, {
|
|
761
|
+
borrowAccounts: {
|
|
762
|
+
owner: this.owner,
|
|
763
|
+
obligation: this.getObligationPda(),
|
|
764
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
765
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
766
|
+
borrowReserve: this.reserve.address,
|
|
767
|
+
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
768
|
+
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
769
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
770
|
+
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
771
|
+
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
|
|
772
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
773
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
774
|
+
},
|
|
775
|
+
farmsAccounts,
|
|
776
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
777
|
+
}, this.kaminoMarket.programId);
|
|
778
|
+
borrowIx.keys =
|
|
779
|
+
this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0
|
|
780
|
+
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
781
|
+
: borrowIx.keys;
|
|
782
|
+
this.lendingIxs.push(borrowIx);
|
|
783
|
+
}
|
|
784
|
+
/// @deprecated -- use addWithdrawIxV2 instead
|
|
785
|
+
async addWithdrawIx(collateralAmount) {
|
|
786
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
787
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
788
|
+
collateralAmount,
|
|
789
|
+
}, {
|
|
790
|
+
owner: this.owner,
|
|
791
|
+
obligation: this.getObligationPda(),
|
|
792
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
793
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
794
|
+
withdrawReserve: this.reserve.address,
|
|
795
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
796
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
797
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
798
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
799
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
800
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
801
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
802
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
803
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
804
|
+
}, this.kaminoMarket.programId));
|
|
805
|
+
}
|
|
806
|
+
async addWithdrawIxV2(collateralAmount) {
|
|
807
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
808
|
+
? {
|
|
809
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
810
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
811
|
+
}
|
|
812
|
+
: {
|
|
813
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
814
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
815
|
+
};
|
|
816
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
817
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
|
|
818
|
+
collateralAmount,
|
|
819
|
+
}, {
|
|
820
|
+
withdrawAccounts: {
|
|
821
|
+
owner: this.owner,
|
|
822
|
+
obligation: this.getObligationPda(),
|
|
823
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
824
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
825
|
+
withdrawReserve: this.reserve.address,
|
|
826
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
827
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
828
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
829
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
830
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
831
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
832
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
833
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
834
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
835
|
+
},
|
|
836
|
+
farmsAccounts: farmsAccounts,
|
|
837
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
838
|
+
}, this.kaminoMarket.programId));
|
|
839
|
+
}
|
|
840
|
+
/// @deprecated -- use addRepayIxV2 instead
|
|
841
|
+
async addRepayIx() {
|
|
842
|
+
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
843
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
844
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
845
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
846
|
+
});
|
|
847
|
+
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
848
|
+
liquidityAmount: this.amount,
|
|
849
|
+
}, {
|
|
850
|
+
owner: this.payer,
|
|
851
|
+
obligation: this.getObligationPda(),
|
|
852
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
853
|
+
repayReserve: this.reserve.address,
|
|
854
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
855
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
856
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
857
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
858
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
859
|
+
}, this.kaminoMarket.programId);
|
|
860
|
+
repayIx.keys =
|
|
861
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
862
|
+
this.lendingIxs.push(repayIx);
|
|
863
|
+
}
|
|
864
|
+
async addRepayIxV2() {
|
|
865
|
+
this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
866
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
867
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
868
|
+
? {
|
|
869
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
870
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
871
|
+
}
|
|
872
|
+
: {
|
|
873
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
874
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
875
|
+
};
|
|
876
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
877
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
878
|
+
});
|
|
879
|
+
const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
|
|
880
|
+
liquidityAmount: this.amount,
|
|
881
|
+
}, {
|
|
882
|
+
repayAccounts: {
|
|
883
|
+
owner: this.payer,
|
|
884
|
+
obligation: this.getObligationPda(),
|
|
885
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
886
|
+
repayReserve: this.reserve.address,
|
|
887
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
888
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
889
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
890
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
891
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
892
|
+
},
|
|
893
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
894
|
+
farmsAccounts,
|
|
895
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
896
|
+
}, this.kaminoMarket.programId);
|
|
897
|
+
repayIx.keys =
|
|
898
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
899
|
+
this.lendingIxs.push(repayIx);
|
|
900
|
+
}
|
|
640
901
|
async addDepositAndBorrowIx() {
|
|
641
902
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
642
903
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -693,7 +954,89 @@ class KaminoAction {
|
|
|
693
954
|
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
694
955
|
this.lendingIxs.push(borrowIx);
|
|
695
956
|
}
|
|
696
|
-
async
|
|
957
|
+
async addDepositAndBorrowIxV2() {
|
|
958
|
+
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
959
|
+
? {
|
|
960
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
961
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
962
|
+
}
|
|
963
|
+
: {
|
|
964
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
965
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
966
|
+
};
|
|
967
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
968
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
969
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({
|
|
970
|
+
liquidityAmount: this.amount,
|
|
971
|
+
}, {
|
|
972
|
+
depositAccounts: {
|
|
973
|
+
owner: this.owner,
|
|
974
|
+
obligation: this.getObligationPda(),
|
|
975
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
976
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
977
|
+
reserve: this.reserve.address,
|
|
978
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
979
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
980
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
981
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
982
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
983
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
984
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
985
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
986
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
987
|
+
},
|
|
988
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
989
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
990
|
+
}, this.kaminoMarket.programId));
|
|
991
|
+
if (!this.outflowReserve) {
|
|
992
|
+
throw new Error(`outflowReserve not set`);
|
|
993
|
+
}
|
|
994
|
+
if (!this.additionalTokenAccountAddress) {
|
|
995
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
996
|
+
}
|
|
997
|
+
if (!this.outflowAmount) {
|
|
998
|
+
throw new Error(`outflowAmount not set`);
|
|
999
|
+
}
|
|
1000
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1001
|
+
if (depositReservesList.length === 0) {
|
|
1002
|
+
depositReservesList.push(this.reserve.address);
|
|
1003
|
+
}
|
|
1004
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1005
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1006
|
+
});
|
|
1007
|
+
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1008
|
+
? {
|
|
1009
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1010
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1011
|
+
}
|
|
1012
|
+
: {
|
|
1013
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmDebt)[0],
|
|
1014
|
+
reserveFarmState: this.outflowReserve.state.farmDebt,
|
|
1015
|
+
};
|
|
1016
|
+
const borrowIx = (0, instructions_1.borrowObligationLiquidityV2)({
|
|
1017
|
+
liquidityAmount: this.outflowAmount,
|
|
1018
|
+
}, {
|
|
1019
|
+
borrowAccounts: {
|
|
1020
|
+
owner: this.owner,
|
|
1021
|
+
obligation: this.getObligationPda(),
|
|
1022
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1023
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1024
|
+
borrowReserve: this.outflowReserve.address,
|
|
1025
|
+
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1026
|
+
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1027
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1028
|
+
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1029
|
+
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
1030
|
+
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1031
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1032
|
+
},
|
|
1033
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1034
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1035
|
+
}, this.kaminoMarket.programId);
|
|
1036
|
+
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
1037
|
+
this.lendingIxs.push(borrowIx);
|
|
1038
|
+
}
|
|
1039
|
+
async addRepayAndWithdrawIxs(withdrawCollateralAmount) {
|
|
697
1040
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
698
1041
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
699
1042
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
@@ -724,11 +1067,8 @@ class KaminoAction {
|
|
|
724
1067
|
if (!this.outflowAmount) {
|
|
725
1068
|
throw new Error(`outflowAmount not set`);
|
|
726
1069
|
}
|
|
727
|
-
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
728
1070
|
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
729
|
-
collateralAmount:
|
|
730
|
-
? this.outflowAmount
|
|
731
|
-
: new bn_js_1.default(new decimal_js_1.default(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
1071
|
+
collateralAmount: withdrawCollateralAmount,
|
|
732
1072
|
}, {
|
|
733
1073
|
owner: this.owner,
|
|
734
1074
|
obligation: this.getObligationPda(),
|
|
@@ -746,53 +1086,82 @@ class KaminoAction {
|
|
|
746
1086
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
747
1087
|
}, this.kaminoMarket.programId));
|
|
748
1088
|
}
|
|
749
|
-
async
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
? this.amount
|
|
753
|
-
: new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
754
|
-
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
755
|
-
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
756
|
-
collateralAmount,
|
|
757
|
-
}, {
|
|
758
|
-
owner: this.owner,
|
|
759
|
-
obligation: this.getObligationPda(),
|
|
760
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
761
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
762
|
-
withdrawReserve: this.reserve.address,
|
|
763
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
764
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
765
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
766
|
-
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
767
|
-
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
768
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
769
|
-
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
770
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
771
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
772
|
-
}, this.kaminoMarket.programId));
|
|
773
|
-
}
|
|
774
|
-
async addRepayIx() {
|
|
775
|
-
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
1089
|
+
async addRepayAndWithdrawIxsV2(withdrawCollateralAmount) {
|
|
1090
|
+
this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
1091
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
776
1092
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
777
1093
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
778
1094
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
779
1095
|
});
|
|
780
|
-
const
|
|
1096
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1097
|
+
? {
|
|
1098
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1099
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1100
|
+
}
|
|
1101
|
+
: {
|
|
1102
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1103
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1104
|
+
};
|
|
1105
|
+
const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
|
|
781
1106
|
liquidityAmount: this.amount,
|
|
782
1107
|
}, {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
1108
|
+
repayAccounts: {
|
|
1109
|
+
owner: this.owner,
|
|
1110
|
+
obligation: this.getObligationPda(),
|
|
1111
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1112
|
+
repayReserve: this.reserve.address,
|
|
1113
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1114
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1115
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1116
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1117
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1118
|
+
},
|
|
1119
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1120
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1121
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
792
1122
|
}, this.kaminoMarket.programId);
|
|
793
|
-
repayIx.keys =
|
|
794
|
-
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1123
|
+
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
795
1124
|
this.lendingIxs.push(repayIx);
|
|
1125
|
+
if (!this.outflowReserve) {
|
|
1126
|
+
throw new Error(`outflowReserve not set`);
|
|
1127
|
+
}
|
|
1128
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1129
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1130
|
+
}
|
|
1131
|
+
if (!this.outflowAmount) {
|
|
1132
|
+
throw new Error(`outflowAmount not set`);
|
|
1133
|
+
}
|
|
1134
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1135
|
+
? {
|
|
1136
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1137
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1138
|
+
}
|
|
1139
|
+
: {
|
|
1140
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
1141
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1142
|
+
};
|
|
1143
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
|
|
1144
|
+
collateralAmount: withdrawCollateralAmount,
|
|
1145
|
+
}, {
|
|
1146
|
+
withdrawAccounts: {
|
|
1147
|
+
owner: this.owner,
|
|
1148
|
+
obligation: this.getObligationPda(),
|
|
1149
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1150
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1151
|
+
withdrawReserve: this.outflowReserve.address,
|
|
1152
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1153
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1154
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1155
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1156
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1157
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1158
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1159
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1160
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1161
|
+
},
|
|
1162
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
1163
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1164
|
+
}, this.kaminoMarket.programId));
|
|
796
1165
|
}
|
|
797
1166
|
async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
|
|
798
1167
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
@@ -839,8 +1208,76 @@ class KaminoAction {
|
|
|
839
1208
|
: liquidateIx.keys;
|
|
840
1209
|
this.lendingIxs.push(liquidateIx);
|
|
841
1210
|
}
|
|
842
|
-
async
|
|
843
|
-
|
|
1211
|
+
async addLiquidateIxV2(maxAllowedLtvOverridePercent = 0) {
|
|
1212
|
+
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
|
|
1213
|
+
if (!this.outflowReserve) {
|
|
1214
|
+
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1215
|
+
}
|
|
1216
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1217
|
+
throw Error(`Liquidating token account address is not defined`);
|
|
1218
|
+
}
|
|
1219
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1220
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1221
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1222
|
+
});
|
|
1223
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1224
|
+
? {
|
|
1225
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1226
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1227
|
+
}
|
|
1228
|
+
: {
|
|
1229
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
1230
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1231
|
+
};
|
|
1232
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1233
|
+
? {
|
|
1234
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1235
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1236
|
+
}
|
|
1237
|
+
: {
|
|
1238
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1239
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1240
|
+
};
|
|
1241
|
+
const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateralV2)({
|
|
1242
|
+
liquidityAmount: this.amount,
|
|
1243
|
+
// TODO: Configure this when updating liquidator with new interface
|
|
1244
|
+
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
|
|
1245
|
+
maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
|
|
1246
|
+
}, {
|
|
1247
|
+
liquidationAccounts: {
|
|
1248
|
+
liquidator: this.owner,
|
|
1249
|
+
obligation: this.getObligationPda(),
|
|
1250
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1251
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1252
|
+
repayReserve: this.reserve.address,
|
|
1253
|
+
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1254
|
+
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1255
|
+
withdrawReserve: this.outflowReserve.address,
|
|
1256
|
+
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1257
|
+
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1258
|
+
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
1259
|
+
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1260
|
+
userSourceLiquidity: this.additionalTokenAccountAddress,
|
|
1261
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
1262
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1263
|
+
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1264
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1265
|
+
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1266
|
+
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1267
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1268
|
+
},
|
|
1269
|
+
debtFarmsAccounts,
|
|
1270
|
+
collateralFarmsAccounts,
|
|
1271
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1272
|
+
}, this.kaminoMarket.programId);
|
|
1273
|
+
liquidateIx.keys =
|
|
1274
|
+
this.obligation.state.elevationGroup > 0
|
|
1275
|
+
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
1276
|
+
: liquidateIx.keys;
|
|
1277
|
+
this.lendingIxs.push(liquidateIx);
|
|
1278
|
+
}
|
|
1279
|
+
async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, useV2Ixs) {
|
|
1280
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'inBetween', requestElevationGroup, addInitObligationForFarm);
|
|
844
1281
|
}
|
|
845
1282
|
addRefreshObligation(crank) {
|
|
846
1283
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
@@ -852,7 +1289,7 @@ class KaminoAction {
|
|
|
852
1289
|
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
|
|
853
1290
|
this.addRefreshObligationIx(addAllToSetupIxns);
|
|
854
1291
|
}
|
|
855
|
-
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1292
|
+
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
856
1293
|
// TODO: why are we not doing this first?
|
|
857
1294
|
if (includeAtaIxns) {
|
|
858
1295
|
await this.addAtaIxs(action);
|
|
@@ -1046,47 +1483,56 @@ class KaminoAction {
|
|
|
1046
1483
|
this.addRequestElevationIx(overrideElevationGroupRequest, 'cleanup', skipReserveIfClosing);
|
|
1047
1484
|
}
|
|
1048
1485
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
action === '
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
else {
|
|
1070
|
-
// If this is an inbetween, it means it's part of a two-token-action
|
|
1071
|
-
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1072
|
-
// add added to 'setup' ixns
|
|
1073
|
-
if (action === 'depositAndBorrow') {
|
|
1074
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1075
|
-
}
|
|
1076
|
-
else if (action === 'repayAndWithdraw') {
|
|
1077
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1486
|
+
if (!useV2Ixs) {
|
|
1487
|
+
if (addAsSupportIx === 'setup') {
|
|
1488
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
1489
|
+
// or the first of a two-token-action
|
|
1490
|
+
if (action === 'liquidate') {
|
|
1491
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1492
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1493
|
+
}
|
|
1494
|
+
else if (action === 'depositAndBorrow' ||
|
|
1495
|
+
action === 'depositCollateral' ||
|
|
1496
|
+
action === 'withdraw' ||
|
|
1497
|
+
action === 'deposit') {
|
|
1498
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Collateral, undefined, twoTokenAction);
|
|
1499
|
+
}
|
|
1500
|
+
else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
1501
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Debt, undefined, twoTokenAction);
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1505
|
+
}
|
|
1078
1506
|
}
|
|
1079
1507
|
else {
|
|
1080
|
-
|
|
1508
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
1509
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1510
|
+
// add added to 'setup' ixns
|
|
1511
|
+
if (action === 'depositAndBorrow') {
|
|
1512
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1513
|
+
}
|
|
1514
|
+
else if (action === 'repayAndWithdraw') {
|
|
1515
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1516
|
+
}
|
|
1517
|
+
else {
|
|
1518
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1519
|
+
}
|
|
1081
1520
|
}
|
|
1082
1521
|
}
|
|
1083
1522
|
}
|
|
1084
1523
|
}
|
|
1085
|
-
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1524
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1086
1525
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1087
1526
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1088
1527
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
1089
|
-
|
|
1528
|
+
let lookupTable = web3_js_1.PublicKey.default;
|
|
1529
|
+
if (createLookupTable) {
|
|
1530
|
+
const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
|
|
1531
|
+
lookupTable = lookupTableAddress;
|
|
1532
|
+
this.setupIxs.push(createLutIx);
|
|
1533
|
+
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
1534
|
+
}
|
|
1535
|
+
this.addInitUserMetadataIxs(lookupTable);
|
|
1090
1536
|
}
|
|
1091
1537
|
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
1092
1538
|
await this.addInitReferrerTokenStateIx(this.reserve);
|
|
@@ -1097,7 +1543,7 @@ class KaminoAction {
|
|
|
1097
1543
|
}
|
|
1098
1544
|
await this.addInitObligationIxs();
|
|
1099
1545
|
}
|
|
1100
|
-
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1546
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1101
1547
|
}
|
|
1102
1548
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1103
1549
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1245,15 +1691,13 @@ class KaminoAction {
|
|
|
1245
1691
|
}
|
|
1246
1692
|
}
|
|
1247
1693
|
addRefreshFarmsForReserve(reserves, addAsSupportIx = 'setup', mode, crank = this.payer, twoTokenAction = false) {
|
|
1248
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1249
|
-
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1250
1694
|
const farms = [];
|
|
1251
1695
|
for (const kaminoReserve of reserves) {
|
|
1252
1696
|
if (mode === types_1.ReserveFarmKind.Collateral && !kaminoReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)) {
|
|
1253
1697
|
farms.push([
|
|
1254
1698
|
types_1.ReserveFarmKind.Collateral,
|
|
1255
1699
|
kaminoReserve.state.farmCollateral,
|
|
1256
|
-
|
|
1700
|
+
(0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
1257
1701
|
kaminoReserve,
|
|
1258
1702
|
]);
|
|
1259
1703
|
}
|
|
@@ -1261,7 +1705,7 @@ class KaminoAction {
|
|
|
1261
1705
|
farms.push([
|
|
1262
1706
|
types_1.ReserveFarmKind.Debt,
|
|
1263
1707
|
kaminoReserve.state.farmDebt,
|
|
1264
|
-
|
|
1708
|
+
(0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
1265
1709
|
kaminoReserve,
|
|
1266
1710
|
]);
|
|
1267
1711
|
}
|
|
@@ -1309,21 +1753,19 @@ class KaminoAction {
|
|
|
1309
1753
|
this.cleanupIxsLabels.splice(0, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
|
|
1310
1754
|
}
|
|
1311
1755
|
async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
|
|
1312
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1313
|
-
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1314
1756
|
const farms = [];
|
|
1315
1757
|
if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
|
|
1316
|
-
const
|
|
1317
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
1758
|
+
const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmCollateral)[0];
|
|
1759
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
1318
1760
|
if (!account) {
|
|
1319
|
-
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
1761
|
+
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
1320
1762
|
}
|
|
1321
1763
|
}
|
|
1322
1764
|
if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
|
|
1323
|
-
const
|
|
1324
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
1765
|
+
const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmDebt)[0];
|
|
1766
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
1325
1767
|
if (!account) {
|
|
1326
|
-
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
1768
|
+
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
1327
1769
|
}
|
|
1328
1770
|
}
|
|
1329
1771
|
farms.forEach((arg) => {
|
|
@@ -1376,10 +1818,7 @@ class KaminoAction {
|
|
|
1376
1818
|
this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
|
|
1377
1819
|
}
|
|
1378
1820
|
}
|
|
1379
|
-
|
|
1380
|
-
const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
|
|
1381
|
-
this.setupIxs.push(createLutIx);
|
|
1382
|
-
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
1821
|
+
addInitUserMetadataIxs(lookupTableAddress) {
|
|
1383
1822
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1384
1823
|
const referrerUserMetadataAddress = this.referrer.equals(web3_js_1.PublicKey.default)
|
|
1385
1824
|
? this.kaminoMarket.programId
|
|
@@ -1438,48 +1877,29 @@ class KaminoAction {
|
|
|
1438
1877
|
this.computeBudgetIxsLabels.push(`AddComputeBudget[${units}]`);
|
|
1439
1878
|
}
|
|
1440
1879
|
async addAtaIxs(action) {
|
|
1441
|
-
if (this.mint.equals(
|
|
1880
|
+
if (this.mint.equals(spl_token_1.NATIVE_MINT) || this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1442
1881
|
await this.updateWSOLAccount(action);
|
|
1443
1882
|
}
|
|
1444
|
-
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(
|
|
1883
|
+
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(spl_token_1.NATIVE_MINT)) {
|
|
1445
1884
|
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1449
|
-
}
|
|
1450
|
-
else {
|
|
1451
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1452
|
-
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1453
|
-
}
|
|
1885
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1886
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1454
1887
|
}
|
|
1455
1888
|
if (action === 'liquidate') {
|
|
1456
1889
|
if (!this.outflowReserve) {
|
|
1457
1890
|
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1458
1891
|
}
|
|
1459
1892
|
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1463
|
-
}
|
|
1464
|
-
else {
|
|
1465
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1466
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1467
|
-
}
|
|
1893
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1894
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1468
1895
|
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1472
|
-
}
|
|
1473
|
-
else {
|
|
1474
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1475
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1476
|
-
}
|
|
1896
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1897
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1477
1898
|
if (!this.additionalTokenAccountAddress) {
|
|
1478
1899
|
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
1479
1900
|
}
|
|
1480
1901
|
}
|
|
1481
|
-
if (action === 'depositAndBorrow' ||
|
|
1482
|
-
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT))) {
|
|
1902
|
+
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(spl_token_1.NATIVE_MINT))) {
|
|
1483
1903
|
if (!this.additionalTokenAccountAddress) {
|
|
1484
1904
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1485
1905
|
}
|
|
@@ -1503,14 +1923,8 @@ class KaminoAction {
|
|
|
1503
1923
|
if (action === 'mint') {
|
|
1504
1924
|
const collateralMintPubkey = this.reserve.getCTokenMint();
|
|
1505
1925
|
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1509
|
-
}
|
|
1510
|
-
else {
|
|
1511
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1512
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1513
|
-
}
|
|
1926
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1927
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1514
1928
|
}
|
|
1515
1929
|
}
|
|
1516
1930
|
async updateWSOLAccount(action) {
|
|
@@ -1537,7 +1951,7 @@ class KaminoAction {
|
|
|
1537
1951
|
.toNumber()).toString());
|
|
1538
1952
|
}
|
|
1539
1953
|
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
1540
|
-
if (this.secondaryMint?.equals(
|
|
1954
|
+
if (this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1541
1955
|
if (!this.additionalTokenAccountAddress) {
|
|
1542
1956
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1543
1957
|
}
|
|
@@ -1549,7 +1963,7 @@ class KaminoAction {
|
|
|
1549
1963
|
const sendAction = action === 'deposit' ||
|
|
1550
1964
|
action === 'repay' ||
|
|
1551
1965
|
action === 'mint' ||
|
|
1552
|
-
(action === 'liquidate' && this.secondaryMint?.equals(
|
|
1966
|
+
(action === 'liquidate' && this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
1553
1967
|
const transferLamportsIx = web3_js_1.SystemProgram.transfer({
|
|
1554
1968
|
fromPubkey: this.owner,
|
|
1555
1969
|
toPubkey: userTokenAccountAddress,
|
|
@@ -1578,14 +1992,6 @@ class KaminoAction {
|
|
|
1578
1992
|
postIxs.push(closeWSOLAccountIx);
|
|
1579
1993
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1580
1994
|
}
|
|
1581
|
-
// TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
|
|
1582
|
-
// if (this.positions && this.positions >= POSITION_LIMIT) {
|
|
1583
|
-
// this.preTxnIxs.push(...preIxs);
|
|
1584
|
-
// this.preTxnIxsLabels.push(...preIxsLabels);
|
|
1585
|
-
// this.postTxnIxs.push(...postIxs);
|
|
1586
|
-
// this.postTxnIxsLabels.push(...postIxsLabels);
|
|
1587
|
-
// } else {
|
|
1588
|
-
// }
|
|
1589
1995
|
this.setupIxs.unshift(...preIxs);
|
|
1590
1996
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
1591
1997
|
this.cleanupIxs.push(...postIxs);
|
|
@@ -1649,6 +2055,12 @@ class KaminoAction {
|
|
|
1649
2055
|
createAtaIxs: [createAtaIx],
|
|
1650
2056
|
};
|
|
1651
2057
|
}
|
|
2058
|
+
getWithdrawCollateralAmount(reserve, amount) {
|
|
2059
|
+
const collateralExchangeRate = reserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
2060
|
+
return amount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
2061
|
+
? amount
|
|
2062
|
+
: new bn_js_1.default(new decimal_js_1.default(amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
2063
|
+
}
|
|
1652
2064
|
getObligationPda() {
|
|
1653
2065
|
return this.obligation
|
|
1654
2066
|
? this.obligation.obligationAddress
|