@kamino-finance/klend-sdk 5.10.34 → 5.10.35-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +28 -20
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +317 -137
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -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/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/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.map +1 -1
- package/dist/classes/vault.js +10 -10
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +6 -1
- 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_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +22 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +5 -3
- 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.map +1 -1
- package/dist/leverage/operations.js +19 -13
- package/dist/leverage/operations.js.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/lookupTable.d.ts +27 -0
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +58 -0
- package/dist/utils/lookupTable.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 +11 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +16 -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 +3 -3
- package/src/classes/action.ts +476 -141
- package/src/classes/manager.ts +13 -0
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +2 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +7 -8
- package/src/client_kamino_manager.ts +8 -1
- 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_calcs.ts +14 -5
- package/src/lending_operations/repay_with_collateral_operations.ts +28 -3
- package/src/lending_operations/swap_collateral_operations.ts +6 -5
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +28 -18
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/lookupTable.ts +62 -0
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +18 -0
- package/src/utils/userMetadata.ts +9 -14
- package/dist/classes/lut_utils.d.ts +0 -29
- package/dist/classes/lut_utils.d.ts.map +0 -1
- package/dist/classes/lut_utils.js +0 -62
- package/dist/classes/lut_utils.js.map +0 -1
- package/src/classes/lut_utils.ts +0 -63
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,
|
|
@@ -187,7 +184,7 @@ class KaminoAction {
|
|
|
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,7 +200,7 @@ 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);
|
|
203
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
207
204
|
axn.addDepositIx();
|
|
208
205
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
209
206
|
return axn;
|
|
@@ -239,7 +236,7 @@ class KaminoAction {
|
|
|
239
236
|
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
240
237
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
241
238
|
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
|
|
239
|
+
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
240
|
) {
|
|
244
241
|
const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
245
242
|
const addInitObligationForFarm = true;
|
|
@@ -255,15 +252,14 @@ class KaminoAction {
|
|
|
255
252
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
256
253
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
257
254
|
}
|
|
258
|
-
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
255
|
+
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
259
256
|
axn.addBorrowIx();
|
|
260
257
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
261
258
|
return axn;
|
|
262
259
|
}
|
|
263
260
|
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
264
261
|
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' }) {
|
|
262
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
267
263
|
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
268
264
|
const addInitObligationForFarm = true;
|
|
269
265
|
if (extraComputeBudget > 0) {
|
|
@@ -278,15 +274,14 @@ class KaminoAction {
|
|
|
278
274
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
279
275
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
280
276
|
}
|
|
281
|
-
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup,
|
|
277
|
+
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, false);
|
|
282
278
|
axn.addDepositReserveLiquidityIx();
|
|
283
279
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
284
280
|
return axn;
|
|
285
281
|
}
|
|
286
282
|
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
287
283
|
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' }) {
|
|
284
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
290
285
|
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
291
286
|
const addInitObligationForFarm = true;
|
|
292
287
|
if (extraComputeBudget > 0) {
|
|
@@ -301,7 +296,7 @@ class KaminoAction {
|
|
|
301
296
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
302
297
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
303
298
|
}
|
|
304
|
-
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup,
|
|
299
|
+
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, false);
|
|
305
300
|
axn.addRedeemReserveCollateralIx();
|
|
306
301
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
307
302
|
return axn;
|
|
@@ -309,7 +304,7 @@ class KaminoAction {
|
|
|
309
304
|
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
310
305
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
311
306
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
312
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
307
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
313
308
|
const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
314
309
|
const addInitObligationForFarm = true;
|
|
315
310
|
if (extraComputeBudget > 0) {
|
|
@@ -324,7 +319,7 @@ class KaminoAction {
|
|
|
324
319
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
325
320
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
326
321
|
}
|
|
327
|
-
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
322
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
|
|
328
323
|
axn.addDepositObligationCollateralIx();
|
|
329
324
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
330
325
|
return axn;
|
|
@@ -332,7 +327,7 @@ class KaminoAction {
|
|
|
332
327
|
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
333
328
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
334
329
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
335
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
330
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
336
331
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
|
|
337
332
|
const addInitObligationForFarmForDeposit = true;
|
|
338
333
|
const addInitObligationForFarmForBorrow = false;
|
|
@@ -350,16 +345,66 @@ class KaminoAction {
|
|
|
350
345
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
351
346
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
352
347
|
}
|
|
353
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, twoTokenAction);
|
|
354
|
-
|
|
348
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, false, createLookupTable, twoTokenAction);
|
|
349
|
+
axn.addDepositAndBorrowIx();
|
|
355
350
|
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow);
|
|
356
351
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
357
352
|
return axn;
|
|
358
353
|
}
|
|
359
|
-
static async
|
|
354
|
+
static async buildDepositAndWithdrawV2Txns(kaminoMarket, depositAmount, depositMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
360
355
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
361
356
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
362
357
|
referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
358
|
+
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndWithdraw', depositAmount, depositMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
359
|
+
const addInitObligationForFarm = true;
|
|
360
|
+
const twoTokenAction = true;
|
|
361
|
+
if (extraComputeBudget > 0) {
|
|
362
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
363
|
+
}
|
|
364
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
365
|
+
...axn.depositReserves,
|
|
366
|
+
...axn.borrowReserves,
|
|
367
|
+
axn.reserve.address,
|
|
368
|
+
axn.outflowReserve.address,
|
|
369
|
+
]).toArray();
|
|
370
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
371
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
372
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
373
|
+
}
|
|
374
|
+
await axn.addSupportIxs('depositAndWithdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, true, twoTokenAction);
|
|
375
|
+
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
376
|
+
axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
377
|
+
return axn;
|
|
378
|
+
}
|
|
379
|
+
static async buildRepayAndWithdrawV2Txns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
380
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
381
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
382
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
383
|
+
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdrawV2', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
384
|
+
const addInitObligationForFarm = true;
|
|
385
|
+
const twoTokenAction = true;
|
|
386
|
+
if (extraComputeBudget > 0) {
|
|
387
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
388
|
+
}
|
|
389
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
390
|
+
...axn.depositReserves,
|
|
391
|
+
...axn.borrowReserves,
|
|
392
|
+
axn.reserve.address,
|
|
393
|
+
axn.outflowReserve.address,
|
|
394
|
+
]).toArray();
|
|
395
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
396
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
397
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
398
|
+
}
|
|
399
|
+
await axn.addSupportIxs('repayAndWithdrawV2', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, true, createLookupTable, twoTokenAction);
|
|
400
|
+
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
401
|
+
axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
402
|
+
return axn;
|
|
403
|
+
}
|
|
404
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
405
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
406
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
407
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
363
408
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
364
409
|
const addInitObligationForFarmForRepay = true;
|
|
365
410
|
const addInitObligationForFarmForWithdraw = false;
|
|
@@ -377,7 +422,7 @@ class KaminoAction {
|
|
|
377
422
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
378
423
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
379
424
|
}
|
|
380
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, twoTokenAction);
|
|
425
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, false, createLookupTable, twoTokenAction);
|
|
381
426
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
382
427
|
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
383
428
|
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw);
|
|
@@ -388,7 +433,7 @@ class KaminoAction {
|
|
|
388
433
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
389
434
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
390
435
|
includeUserMetadata = true, // if true it includes user metadata
|
|
391
|
-
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = undefined, overrideElevationGroupRequest,
|
|
436
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = undefined, overrideElevationGroupRequest,
|
|
392
437
|
// Optional customizations which may be needed if the obligation was mutated by some previous ixn.
|
|
393
438
|
obligationCustomizations) {
|
|
394
439
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
@@ -406,9 +451,9 @@ class KaminoAction {
|
|
|
406
451
|
if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
|
|
407
452
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
408
453
|
}
|
|
409
|
-
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, overrideElevationGroupRequest);
|
|
454
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable, false, overrideElevationGroupRequest);
|
|
410
455
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
411
|
-
|
|
456
|
+
axn.addWithdrawIx(collateralAmount);
|
|
412
457
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
413
458
|
return axn;
|
|
414
459
|
}
|
|
@@ -427,7 +472,7 @@ class KaminoAction {
|
|
|
427
472
|
* @param includeUserMetadata - if true it includes user metadata
|
|
428
473
|
* @param referrer
|
|
429
474
|
*/
|
|
430
|
-
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' }) {
|
|
475
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, 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' }) {
|
|
431
476
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
432
477
|
const addInitObligationForFarm = true;
|
|
433
478
|
if (extraComputeBudget > 0) {
|
|
@@ -442,15 +487,15 @@ class KaminoAction {
|
|
|
442
487
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
443
488
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
444
489
|
}
|
|
445
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
446
|
-
|
|
490
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
|
|
491
|
+
axn.addRepayIx();
|
|
447
492
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
448
493
|
return axn;
|
|
449
494
|
}
|
|
450
495
|
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
451
496
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
452
497
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
453
|
-
referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
498
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
454
499
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
455
500
|
const addInitObligationForFarm = true;
|
|
456
501
|
if (extraComputeBudget > 0) {
|
|
@@ -466,8 +511,8 @@ class KaminoAction {
|
|
|
466
511
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
467
512
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
468
513
|
}
|
|
469
|
-
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
470
|
-
|
|
514
|
+
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, createLookupTable);
|
|
515
|
+
axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
471
516
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
472
517
|
return axn;
|
|
473
518
|
}
|
|
@@ -639,7 +684,7 @@ class KaminoAction {
|
|
|
639
684
|
: borrowIx.keys;
|
|
640
685
|
this.lendingIxs.push(borrowIx);
|
|
641
686
|
}
|
|
642
|
-
|
|
687
|
+
addDepositAndBorrowIx() {
|
|
643
688
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
644
689
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
645
690
|
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
|
|
@@ -695,7 +740,7 @@ class KaminoAction {
|
|
|
695
740
|
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
696
741
|
this.lendingIxs.push(borrowIx);
|
|
697
742
|
}
|
|
698
|
-
|
|
743
|
+
addRepayAndWithdrawIxs(withdrawCollateralAmount) {
|
|
699
744
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
700
745
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
701
746
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
@@ -745,7 +790,166 @@ class KaminoAction {
|
|
|
745
790
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
746
791
|
}, this.kaminoMarket.programId));
|
|
747
792
|
}
|
|
748
|
-
|
|
793
|
+
addRepayAndWithdrawV2Ixs(withdrawCollateralAmount) {
|
|
794
|
+
this.lendingIxsLabels.push(`repayAndWithdrawAndRedeem(repayReserve=${this.reserve.address})(withdrawReserve=${this.outflowReserve.address})(obligation=${this.getObligationPda()})`);
|
|
795
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
796
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
797
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
798
|
+
});
|
|
799
|
+
const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
|
|
800
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
801
|
+
});
|
|
802
|
+
if (!this.outflowAmount) {
|
|
803
|
+
throw new Error(`outflowAmount not set`);
|
|
804
|
+
}
|
|
805
|
+
if (!this.outflowReserve) {
|
|
806
|
+
throw new Error(`outflowReserve not set`);
|
|
807
|
+
}
|
|
808
|
+
if (!this.additionalTokenAccountAddress) {
|
|
809
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
810
|
+
}
|
|
811
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
812
|
+
? {
|
|
813
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
814
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
815
|
+
}
|
|
816
|
+
: {
|
|
817
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.outflowReserve.state.farmCollateral, this.getObligationPda()),
|
|
818
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
819
|
+
};
|
|
820
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
821
|
+
? {
|
|
822
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
823
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
824
|
+
}
|
|
825
|
+
: {
|
|
826
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.reserve.state.farmDebt, this.getObligationPda()),
|
|
827
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
828
|
+
};
|
|
829
|
+
const repayAndWithdrawIx = (0, instructions_1.repayAndWithdrawAndRedeem)({
|
|
830
|
+
repayAmount: this.amount,
|
|
831
|
+
withdrawCollateralAmount,
|
|
832
|
+
}, {
|
|
833
|
+
repayAccounts: {
|
|
834
|
+
owner: this.owner,
|
|
835
|
+
obligation: this.getObligationPda(),
|
|
836
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
837
|
+
repayReserve: this.reserve.address,
|
|
838
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
839
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
840
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
841
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
842
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
843
|
+
},
|
|
844
|
+
withdrawAccounts: {
|
|
845
|
+
owner: this.owner,
|
|
846
|
+
obligation: this.getObligationPda(),
|
|
847
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
848
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
849
|
+
withdrawReserve: this.outflowReserve.address,
|
|
850
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
851
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
852
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
853
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
854
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
855
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
856
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
857
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
858
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
859
|
+
},
|
|
860
|
+
collateralFarmsAccounts,
|
|
861
|
+
debtFarmsAccounts,
|
|
862
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
863
|
+
}, this.kaminoMarket.programId);
|
|
864
|
+
repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
|
|
865
|
+
...depositReserveAccountMetas,
|
|
866
|
+
...borrowReserveAccountMetas,
|
|
867
|
+
]);
|
|
868
|
+
this.lendingIxs.push(repayAndWithdrawIx);
|
|
869
|
+
}
|
|
870
|
+
addDepositAndWithdrawV2Ixs(withdrawCollateralAmount) {
|
|
871
|
+
this.lendingIxsLabels.push(`depositAndWithdrawV2(depositReserve=${this.reserve.address})(withdrawReserve=${this.outflowReserve.address})(obligation=${this.getObligationPda()})`);
|
|
872
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
873
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
874
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
875
|
+
});
|
|
876
|
+
const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
|
|
877
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
878
|
+
});
|
|
879
|
+
if (!this.outflowAmount) {
|
|
880
|
+
throw new Error(`outflowAmount not set`);
|
|
881
|
+
}
|
|
882
|
+
if (!this.outflowReserve) {
|
|
883
|
+
throw new Error(`outflowReserve not set`);
|
|
884
|
+
}
|
|
885
|
+
if (!this.additionalTokenAccountAddress) {
|
|
886
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
887
|
+
}
|
|
888
|
+
const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
889
|
+
? {
|
|
890
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
891
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
892
|
+
}
|
|
893
|
+
: {
|
|
894
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.reserve.state.farmDebt, this.getObligationPda()),
|
|
895
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
896
|
+
};
|
|
897
|
+
const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
898
|
+
? {
|
|
899
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
900
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
901
|
+
}
|
|
902
|
+
: {
|
|
903
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.outflowReserve.state.farmCollateral, this.getObligationPda()),
|
|
904
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
905
|
+
};
|
|
906
|
+
const depositAndWithdrawIx = (0, instructions_1.depositAndWithdraw)({
|
|
907
|
+
liquidityAmount: this.amount,
|
|
908
|
+
withdrawCollateralAmount,
|
|
909
|
+
}, {
|
|
910
|
+
depositAccounts: {
|
|
911
|
+
owner: this.owner,
|
|
912
|
+
obligation: this.getObligationPda(),
|
|
913
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
914
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
915
|
+
reserve: this.reserve.address,
|
|
916
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
917
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
918
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
919
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
920
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
921
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
922
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
923
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
924
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
925
|
+
},
|
|
926
|
+
withdrawAccounts: {
|
|
927
|
+
owner: this.owner,
|
|
928
|
+
obligation: this.getObligationPda(),
|
|
929
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
930
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
931
|
+
withdrawReserve: this.outflowReserve.address,
|
|
932
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
933
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
934
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
935
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
936
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
937
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
938
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
939
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
940
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
941
|
+
},
|
|
942
|
+
depositFarmsAccounts,
|
|
943
|
+
withdrawFarmsAccounts,
|
|
944
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
945
|
+
}, this.kaminoMarket.programId);
|
|
946
|
+
depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
|
|
947
|
+
...depositReserveAccountMetas,
|
|
948
|
+
...borrowReserveAccountMetas,
|
|
949
|
+
]);
|
|
950
|
+
this.lendingIxs.push(depositAndWithdrawIx);
|
|
951
|
+
}
|
|
952
|
+
addWithdrawIx(withdrawCollateralAmount) {
|
|
749
953
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
750
954
|
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
751
955
|
collateralAmount: withdrawCollateralAmount,
|
|
@@ -766,7 +970,7 @@ class KaminoAction {
|
|
|
766
970
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
767
971
|
}, this.kaminoMarket.programId));
|
|
768
972
|
}
|
|
769
|
-
|
|
973
|
+
addRepayIx() {
|
|
770
974
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
771
975
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
772
976
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
@@ -789,7 +993,7 @@ class KaminoAction {
|
|
|
789
993
|
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
790
994
|
this.lendingIxs.push(repayIx);
|
|
791
995
|
}
|
|
792
|
-
|
|
996
|
+
addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
|
|
793
997
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
794
998
|
if (!this.outflowReserve) {
|
|
795
999
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
@@ -835,7 +1039,7 @@ class KaminoAction {
|
|
|
835
1039
|
this.lendingIxs.push(liquidateIx);
|
|
836
1040
|
}
|
|
837
1041
|
async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm) {
|
|
838
|
-
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'inBetween', requestElevationGroup, addInitObligationForFarm);
|
|
1042
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, false, 'inBetween', requestElevationGroup, addInitObligationForFarm);
|
|
839
1043
|
}
|
|
840
1044
|
addRefreshObligation(crank) {
|
|
841
1045
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
@@ -847,7 +1051,7 @@ class KaminoAction {
|
|
|
847
1051
|
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
|
|
848
1052
|
this.addRefreshObligationIx(addAllToSetupIxns);
|
|
849
1053
|
}
|
|
850
|
-
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1054
|
+
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
851
1055
|
// TODO: why are we not doing this first?
|
|
852
1056
|
if (includeAtaIxns) {
|
|
853
1057
|
await this.addAtaIxs(action);
|
|
@@ -861,6 +1065,7 @@ class KaminoAction {
|
|
|
861
1065
|
'repay',
|
|
862
1066
|
'depositAndBorrow',
|
|
863
1067
|
'repayAndWithdraw',
|
|
1068
|
+
'repayAndWithdrawV2',
|
|
864
1069
|
'refreshObligation',
|
|
865
1070
|
].includes(action)) {
|
|
866
1071
|
// The support ixns in order are:
|
|
@@ -876,11 +1081,14 @@ class KaminoAction {
|
|
|
876
1081
|
// 7. Ixn to refresh the `debt` farm of the obligation
|
|
877
1082
|
// 8. Ixn to refresh the `collateral` farm of the obligation
|
|
878
1083
|
let currentReserves = [];
|
|
879
|
-
if (action === 'liquidate' ||
|
|
1084
|
+
if (action === 'liquidate' ||
|
|
1085
|
+
action === 'depositAndBorrow' ||
|
|
1086
|
+
action === 'repayAndWithdraw' ||
|
|
1087
|
+
action === 'repayAndWithdrawV2') {
|
|
880
1088
|
if (!this.outflowReserve) {
|
|
881
1089
|
throw new Error('outflowReserve is undefined');
|
|
882
1090
|
}
|
|
883
|
-
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
1091
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
884
1092
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
885
1093
|
if (action === 'depositAndBorrow') {
|
|
886
1094
|
if (this.obligation) {
|
|
@@ -924,7 +1132,10 @@ class KaminoAction {
|
|
|
924
1132
|
await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
925
1133
|
}
|
|
926
1134
|
}
|
|
927
|
-
else if (action === 'repayAndWithdraw' ||
|
|
1135
|
+
else if (action === 'repayAndWithdraw' ||
|
|
1136
|
+
action === 'borrow' ||
|
|
1137
|
+
action === 'repay' ||
|
|
1138
|
+
action === 'repayAndWithdrawV2') {
|
|
928
1139
|
// todo - probably don't need to add both debt and collateral for everything here
|
|
929
1140
|
await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
930
1141
|
if (this.outflowReserve) {
|
|
@@ -955,7 +1166,7 @@ class KaminoAction {
|
|
|
955
1166
|
this.addRefreshObligationIx(addAsSupportIx);
|
|
956
1167
|
}
|
|
957
1168
|
if (requestElevationGroup) {
|
|
958
|
-
if (action === 'repay') {
|
|
1169
|
+
if (action === 'repay' || action === 'repayAndWithdrawV2') {
|
|
959
1170
|
const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
|
|
960
1171
|
if (!repayObligationLiquidity) {
|
|
961
1172
|
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
@@ -1041,47 +1252,56 @@ class KaminoAction {
|
|
|
1041
1252
|
this.addRequestElevationIx(overrideElevationGroupRequest, 'cleanup', skipReserveIfClosing);
|
|
1042
1253
|
}
|
|
1043
1254
|
}
|
|
1044
|
-
if (
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
action === '
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
else {
|
|
1065
|
-
// If this is an inbetween, it means it's part of a two-token-action
|
|
1066
|
-
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1067
|
-
// add added to 'setup' ixns
|
|
1068
|
-
if (action === 'depositAndBorrow') {
|
|
1069
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1070
|
-
}
|
|
1071
|
-
else if (action === 'repayAndWithdraw') {
|
|
1072
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1255
|
+
if (!useV2Ixs) {
|
|
1256
|
+
if (addAsSupportIx === 'setup') {
|
|
1257
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
1258
|
+
// or the first of a two-token-action
|
|
1259
|
+
if (action === 'liquidate') {
|
|
1260
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1261
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1262
|
+
}
|
|
1263
|
+
else if (action === 'depositAndBorrow' ||
|
|
1264
|
+
action === 'depositCollateral' ||
|
|
1265
|
+
action === 'withdraw' ||
|
|
1266
|
+
action === 'deposit') {
|
|
1267
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Collateral, undefined, twoTokenAction);
|
|
1268
|
+
}
|
|
1269
|
+
else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
1270
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Debt, undefined, twoTokenAction);
|
|
1271
|
+
}
|
|
1272
|
+
else {
|
|
1273
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1274
|
+
}
|
|
1073
1275
|
}
|
|
1074
1276
|
else {
|
|
1075
|
-
|
|
1277
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
1278
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1279
|
+
// add added to 'setup' ixns
|
|
1280
|
+
if (action === 'depositAndBorrow') {
|
|
1281
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1282
|
+
}
|
|
1283
|
+
else if (action === 'repayAndWithdraw') {
|
|
1284
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1285
|
+
}
|
|
1286
|
+
else {
|
|
1287
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1288
|
+
}
|
|
1076
1289
|
}
|
|
1077
1290
|
}
|
|
1078
1291
|
}
|
|
1079
1292
|
}
|
|
1080
|
-
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1293
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1081
1294
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1082
1295
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1083
1296
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
1084
|
-
|
|
1297
|
+
let lookupTable = web3_js_1.PublicKey.default;
|
|
1298
|
+
if (createLookupTable) {
|
|
1299
|
+
const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
|
|
1300
|
+
lookupTable = lookupTableAddress;
|
|
1301
|
+
this.setupIxs.push(createLutIx);
|
|
1302
|
+
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
1303
|
+
}
|
|
1304
|
+
this.addInitUserMetadataIxs(lookupTable);
|
|
1085
1305
|
}
|
|
1086
1306
|
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
1087
1307
|
await this.addInitReferrerTokenStateIx(this.reserve);
|
|
@@ -1090,9 +1310,9 @@ class KaminoAction {
|
|
|
1090
1310
|
if (action === 'deposit' && this.outflowReserve) {
|
|
1091
1311
|
await this.addInitReferrerTokenStateIx(this.outflowReserve);
|
|
1092
1312
|
}
|
|
1093
|
-
|
|
1313
|
+
this.addInitObligationIxs();
|
|
1094
1314
|
}
|
|
1095
|
-
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1315
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1096
1316
|
}
|
|
1097
1317
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1098
1318
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1240,15 +1460,13 @@ class KaminoAction {
|
|
|
1240
1460
|
}
|
|
1241
1461
|
}
|
|
1242
1462
|
addRefreshFarmsForReserve(reserves, addAsSupportIx = 'setup', mode, crank = this.payer, twoTokenAction = false) {
|
|
1243
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1244
|
-
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1245
1463
|
const farms = [];
|
|
1246
1464
|
for (const kaminoReserve of reserves) {
|
|
1247
1465
|
if (mode === types_1.ReserveFarmKind.Collateral && !kaminoReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)) {
|
|
1248
1466
|
farms.push([
|
|
1249
1467
|
types_1.ReserveFarmKind.Collateral,
|
|
1250
1468
|
kaminoReserve.state.farmCollateral,
|
|
1251
|
-
|
|
1469
|
+
(0, utils_1.obligationFarmStatePda)(kaminoReserve.state.farmCollateral, this.getObligationPda()),
|
|
1252
1470
|
kaminoReserve,
|
|
1253
1471
|
]);
|
|
1254
1472
|
}
|
|
@@ -1256,7 +1474,7 @@ class KaminoAction {
|
|
|
1256
1474
|
farms.push([
|
|
1257
1475
|
types_1.ReserveFarmKind.Debt,
|
|
1258
1476
|
kaminoReserve.state.farmDebt,
|
|
1259
|
-
|
|
1477
|
+
(0, utils_1.obligationFarmStatePda)(kaminoReserve.state.farmDebt, this.getObligationPda()),
|
|
1260
1478
|
kaminoReserve,
|
|
1261
1479
|
]);
|
|
1262
1480
|
}
|
|
@@ -1304,21 +1522,19 @@ class KaminoAction {
|
|
|
1304
1522
|
this.cleanupIxsLabels.splice(0, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
|
|
1305
1523
|
}
|
|
1306
1524
|
async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
|
|
1307
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1308
|
-
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1309
1525
|
const farms = [];
|
|
1310
1526
|
if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
|
|
1311
|
-
const pda =
|
|
1527
|
+
const pda = (0, utils_1.obligationFarmStatePda)(reserve.state.farmCollateral, this.getObligationPda());
|
|
1312
1528
|
const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
|
|
1313
1529
|
if (!account) {
|
|
1314
1530
|
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
|
|
1315
1531
|
}
|
|
1316
1532
|
}
|
|
1317
1533
|
if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
|
|
1318
|
-
const pda =
|
|
1534
|
+
const pda = (0, utils_1.obligationFarmStatePda)(reserve.state.farmDebt, this.getObligationPda());
|
|
1319
1535
|
const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
|
|
1320
1536
|
if (!account) {
|
|
1321
|
-
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
1537
|
+
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
|
|
1322
1538
|
}
|
|
1323
1539
|
}
|
|
1324
1540
|
farms.forEach((arg) => {
|
|
@@ -1347,7 +1563,7 @@ class KaminoAction {
|
|
|
1347
1563
|
}
|
|
1348
1564
|
});
|
|
1349
1565
|
}
|
|
1350
|
-
|
|
1566
|
+
addInitObligationIxs() {
|
|
1351
1567
|
if (!this.obligation) {
|
|
1352
1568
|
const obligationPda = this.getObligationPda();
|
|
1353
1569
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
@@ -1371,10 +1587,7 @@ class KaminoAction {
|
|
|
1371
1587
|
this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
|
|
1372
1588
|
}
|
|
1373
1589
|
}
|
|
1374
|
-
|
|
1375
|
-
const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
|
|
1376
|
-
this.setupIxs.push(createLutIx);
|
|
1377
|
-
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
1590
|
+
addInitUserMetadataIxs(lookupTableAddress) {
|
|
1378
1591
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1379
1592
|
const referrerUserMetadataAddress = this.referrer.equals(web3_js_1.PublicKey.default)
|
|
1380
1593
|
? this.kaminoMarket.programId
|
|
@@ -1433,48 +1646,29 @@ class KaminoAction {
|
|
|
1433
1646
|
this.computeBudgetIxsLabels.push(`AddComputeBudget[${units}]`);
|
|
1434
1647
|
}
|
|
1435
1648
|
async addAtaIxs(action) {
|
|
1436
|
-
if (this.mint.equals(
|
|
1649
|
+
if (this.mint.equals(spl_token_1.NATIVE_MINT) || this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1437
1650
|
await this.updateWSOLAccount(action);
|
|
1438
1651
|
}
|
|
1439
|
-
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(
|
|
1652
|
+
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(spl_token_1.NATIVE_MINT)) {
|
|
1440
1653
|
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1444
|
-
}
|
|
1445
|
-
else {
|
|
1446
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1447
|
-
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1448
|
-
}
|
|
1654
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1655
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1449
1656
|
}
|
|
1450
1657
|
if (action === 'liquidate') {
|
|
1451
1658
|
if (!this.outflowReserve) {
|
|
1452
1659
|
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1453
1660
|
}
|
|
1454
1661
|
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1458
|
-
}
|
|
1459
|
-
else {
|
|
1460
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1461
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1462
|
-
}
|
|
1662
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1663
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1463
1664
|
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1467
|
-
}
|
|
1468
|
-
else {
|
|
1469
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1470
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1471
|
-
}
|
|
1665
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1666
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1472
1667
|
if (!this.additionalTokenAccountAddress) {
|
|
1473
1668
|
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
1474
1669
|
}
|
|
1475
1670
|
}
|
|
1476
|
-
if (action === 'depositAndBorrow' ||
|
|
1477
|
-
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT))) {
|
|
1671
|
+
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(spl_token_1.NATIVE_MINT))) {
|
|
1478
1672
|
if (!this.additionalTokenAccountAddress) {
|
|
1479
1673
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1480
1674
|
}
|
|
@@ -1498,14 +1692,8 @@ class KaminoAction {
|
|
|
1498
1692
|
if (action === 'mint') {
|
|
1499
1693
|
const collateralMintPubkey = this.reserve.getCTokenMint();
|
|
1500
1694
|
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1504
|
-
}
|
|
1505
|
-
else {
|
|
1506
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1507
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1508
|
-
}
|
|
1695
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1696
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1509
1697
|
}
|
|
1510
1698
|
}
|
|
1511
1699
|
async updateWSOLAccount(action) {
|
|
@@ -1517,14 +1705,13 @@ class KaminoAction {
|
|
|
1517
1705
|
return;
|
|
1518
1706
|
}
|
|
1519
1707
|
let safeRepay = new bn_js_1.default(this.amount);
|
|
1520
|
-
if (this.obligation && action === 'repay' && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
|
|
1708
|
+
if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
|
|
1521
1709
|
const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
|
|
1522
1710
|
if (!borrow) {
|
|
1523
1711
|
throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
|
|
1524
1712
|
}
|
|
1525
1713
|
const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
|
|
1526
1714
|
const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
1527
|
-
// TODO: shouldn't this calc be added to all other stuff as well?
|
|
1528
1715
|
safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
|
|
1529
1716
|
.mul(cumulativeBorrowRateReserve)
|
|
1530
1717
|
.div(cumulativeBorrowRateObligation)
|
|
@@ -1532,7 +1719,7 @@ class KaminoAction {
|
|
|
1532
1719
|
.toNumber()).toString());
|
|
1533
1720
|
}
|
|
1534
1721
|
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
1535
|
-
if (this.secondaryMint?.equals(
|
|
1722
|
+
if (this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1536
1723
|
if (!this.additionalTokenAccountAddress) {
|
|
1537
1724
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1538
1725
|
}
|
|
@@ -1543,8 +1730,9 @@ class KaminoAction {
|
|
|
1543
1730
|
// Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
|
|
1544
1731
|
const sendAction = action === 'deposit' ||
|
|
1545
1732
|
action === 'repay' ||
|
|
1733
|
+
action === 'repayAndWithdrawV2' ||
|
|
1546
1734
|
action === 'mint' ||
|
|
1547
|
-
(action === 'liquidate' && this.secondaryMint?.equals(
|
|
1735
|
+
(action === 'liquidate' && this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
1548
1736
|
const transferLamportsIx = web3_js_1.SystemProgram.transfer({
|
|
1549
1737
|
fromPubkey: this.owner,
|
|
1550
1738
|
toPubkey: userTokenAccountAddress,
|
|
@@ -1573,14 +1761,6 @@ class KaminoAction {
|
|
|
1573
1761
|
postIxs.push(closeWSOLAccountIx);
|
|
1574
1762
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1575
1763
|
}
|
|
1576
|
-
// TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
|
|
1577
|
-
// if (this.positions && this.positions >= POSITION_LIMIT) {
|
|
1578
|
-
// this.preTxnIxs.push(...preIxs);
|
|
1579
|
-
// this.preTxnIxsLabels.push(...preIxsLabels);
|
|
1580
|
-
// this.postTxnIxs.push(...postIxs);
|
|
1581
|
-
// this.postTxnIxsLabels.push(...postIxsLabels);
|
|
1582
|
-
// } else {
|
|
1583
|
-
// }
|
|
1584
1764
|
this.setupIxs.unshift(...preIxs);
|
|
1585
1765
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
1586
1766
|
this.cleanupIxs.push(...postIxs);
|
|
@@ -1615,7 +1795,7 @@ class KaminoAction {
|
|
|
1615
1795
|
primaryMint = inflowTokenMint;
|
|
1616
1796
|
secondaryMint = outflowTokenMint;
|
|
1617
1797
|
}
|
|
1618
|
-
else if (action === 'repayAndWithdraw') {
|
|
1798
|
+
else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
1619
1799
|
primaryMint = inflowTokenMint;
|
|
1620
1800
|
secondaryMint = outflowTokenMint;
|
|
1621
1801
|
userTokenAccountAddress = userInflowTokenAccountAddress;
|