@kamino-finance/klend-sdk 5.10.34 → 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 +31 -25
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +604 -193
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +11 -2
- 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/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 +4 -4
- 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_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/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 +770 -196
- package/src/classes/manager.ts +14 -1
- package/src/classes/reserve.ts +2 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +6 -7
- package/src/client.ts +7 -3
- 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_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/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,18 +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);
|
|
395
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, createLookupTable, twoTokenAction);
|
|
381
396
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
382
|
-
|
|
383
|
-
|
|
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);
|
|
384
404
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
385
405
|
return axn;
|
|
386
406
|
}
|
|
387
|
-
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
|
|
388
408
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
389
409
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
390
410
|
includeUserMetadata = true, // if true it includes user metadata
|
|
391
|
-
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,
|
|
392
412
|
// Optional customizations which may be needed if the obligation was mutated by some previous ixn.
|
|
393
413
|
obligationCustomizations) {
|
|
394
414
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
@@ -406,9 +426,14 @@ class KaminoAction {
|
|
|
406
426
|
if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
|
|
407
427
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
408
428
|
}
|
|
409
|
-
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, overrideElevationGroupRequest);
|
|
429
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, false, overrideElevationGroupRequest);
|
|
410
430
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
411
|
-
|
|
431
|
+
if (useV2Ixs) {
|
|
432
|
+
await axn.addWithdrawIxV2(collateralAmount);
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
await axn.addWithdrawIx(collateralAmount);
|
|
436
|
+
}
|
|
412
437
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
413
438
|
return axn;
|
|
414
439
|
}
|
|
@@ -427,7 +452,7 @@ class KaminoAction {
|
|
|
427
452
|
* @param includeUserMetadata - if true it includes user metadata
|
|
428
453
|
* @param referrer
|
|
429
454
|
*/
|
|
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' }) {
|
|
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' }) {
|
|
431
456
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
432
457
|
const addInitObligationForFarm = true;
|
|
433
458
|
if (extraComputeBudget > 0) {
|
|
@@ -442,15 +467,20 @@ class KaminoAction {
|
|
|
442
467
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
443
468
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
444
469
|
}
|
|
445
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
446
|
-
|
|
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
|
+
}
|
|
447
477
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
448
478
|
return axn;
|
|
449
479
|
}
|
|
450
|
-
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
|
|
451
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
|
|
452
482
|
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' }) {
|
|
483
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
454
484
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
455
485
|
const addInitObligationForFarm = true;
|
|
456
486
|
if (extraComputeBudget > 0) {
|
|
@@ -466,8 +496,13 @@ class KaminoAction {
|
|
|
466
496
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
467
497
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
468
498
|
}
|
|
469
|
-
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
470
|
-
|
|
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
|
+
}
|
|
471
506
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
472
507
|
return axn;
|
|
473
508
|
}
|
|
@@ -537,31 +572,29 @@ class KaminoAction {
|
|
|
537
572
|
return '';
|
|
538
573
|
return await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
539
574
|
}
|
|
540
|
-
|
|
541
|
-
this.lendingIxsLabels.push(`
|
|
542
|
-
this.lendingIxs.push((0, instructions_1.
|
|
575
|
+
addDepositReserveLiquidityIx() {
|
|
576
|
+
this.lendingIxsLabels.push(`depositReserveLiquidity`);
|
|
577
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
|
|
543
578
|
liquidityAmount: this.amount,
|
|
544
579
|
}, {
|
|
545
580
|
owner: this.owner,
|
|
546
|
-
obligation: this.getObligationPda(),
|
|
547
581
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
548
582
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
549
583
|
reserve: this.reserve.address,
|
|
550
584
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
551
585
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
552
586
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
553
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
554
587
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
555
|
-
|
|
588
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
556
589
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
557
590
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
558
591
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
559
592
|
}, this.kaminoMarket.programId));
|
|
560
593
|
}
|
|
561
|
-
|
|
562
|
-
this.lendingIxsLabels.push(`
|
|
563
|
-
this.lendingIxs.push((0, instructions_1.
|
|
564
|
-
|
|
594
|
+
addRedeemReserveCollateralIx() {
|
|
595
|
+
this.lendingIxsLabels.push(`redeemReserveCollateral`);
|
|
596
|
+
this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
|
|
597
|
+
collateralAmount: this.amount,
|
|
565
598
|
}, {
|
|
566
599
|
owner: this.owner,
|
|
567
600
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
@@ -570,32 +603,70 @@ class KaminoAction {
|
|
|
570
603
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
571
604
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
572
605
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
573
|
-
|
|
574
|
-
|
|
606
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
607
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
575
608
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
576
609
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
577
610
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
578
611
|
}, this.kaminoMarket.programId));
|
|
579
612
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
this.
|
|
583
|
-
|
|
613
|
+
// @deprecated -- use addDepositIxV2 instead
|
|
614
|
+
addDepositIx() {
|
|
615
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
616
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
|
|
617
|
+
liquidityAmount: this.amount,
|
|
584
618
|
}, {
|
|
585
619
|
owner: this.owner,
|
|
620
|
+
obligation: this.getObligationPda(),
|
|
586
621
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
587
622
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
588
623
|
reserve: this.reserve.address,
|
|
589
624
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
590
625
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
591
626
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
592
|
-
|
|
593
|
-
|
|
627
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
628
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
629
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
594
630
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
595
631
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
596
632
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
597
633
|
}, this.kaminoMarket.programId));
|
|
598
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
|
|
599
670
|
addDepositObligationCollateralIx() {
|
|
600
671
|
this.lendingIxsLabels.push(`depositObligationCollateral`);
|
|
601
672
|
this.lendingIxs.push((0, instructions_1.depositObligationCollateral)({
|
|
@@ -611,6 +682,36 @@ class KaminoAction {
|
|
|
611
682
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
612
683
|
}, this.kaminoMarket.programId));
|
|
613
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
|
|
614
715
|
addBorrowIx() {
|
|
615
716
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
616
717
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
@@ -639,6 +740,164 @@ class KaminoAction {
|
|
|
639
740
|
: borrowIx.keys;
|
|
640
741
|
this.lendingIxs.push(borrowIx);
|
|
641
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
|
+
}
|
|
642
901
|
async addDepositAndBorrowIx() {
|
|
643
902
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
644
903
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -695,6 +954,88 @@ class KaminoAction {
|
|
|
695
954
|
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
696
955
|
this.lendingIxs.push(borrowIx);
|
|
697
956
|
}
|
|
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
|
+
}
|
|
698
1039
|
async addRepayAndWithdrawIxs(withdrawCollateralAmount) {
|
|
699
1040
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
700
1041
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
@@ -745,49 +1086,82 @@ class KaminoAction {
|
|
|
745
1086
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
746
1087
|
}, this.kaminoMarket.programId));
|
|
747
1088
|
}
|
|
748
|
-
async
|
|
749
|
-
this.lendingIxsLabels.push(`
|
|
750
|
-
this.
|
|
751
|
-
collateralAmount: withdrawCollateralAmount,
|
|
752
|
-
}, {
|
|
753
|
-
owner: this.owner,
|
|
754
|
-
obligation: this.getObligationPda(),
|
|
755
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
756
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
757
|
-
withdrawReserve: this.reserve.address,
|
|
758
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
759
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
760
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
761
|
-
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
762
|
-
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
763
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
764
|
-
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
765
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
766
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
767
|
-
}, this.kaminoMarket.programId));
|
|
768
|
-
}
|
|
769
|
-
async addRepayIx() {
|
|
770
|
-
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`);
|
|
771
1092
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
772
1093
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
773
1094
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
774
1095
|
});
|
|
775
|
-
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)({
|
|
776
1106
|
liquidityAmount: this.amount,
|
|
777
1107
|
}, {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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,
|
|
787
1122
|
}, this.kaminoMarket.programId);
|
|
788
|
-
repayIx.keys =
|
|
789
|
-
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1123
|
+
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
790
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));
|
|
791
1165
|
}
|
|
792
1166
|
async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
|
|
793
1167
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
@@ -834,8 +1208,76 @@ class KaminoAction {
|
|
|
834
1208
|
: liquidateIx.keys;
|
|
835
1209
|
this.lendingIxs.push(liquidateIx);
|
|
836
1210
|
}
|
|
837
|
-
async
|
|
838
|
-
|
|
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);
|
|
839
1281
|
}
|
|
840
1282
|
addRefreshObligation(crank) {
|
|
841
1283
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
@@ -847,7 +1289,7 @@ class KaminoAction {
|
|
|
847
1289
|
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
|
|
848
1290
|
this.addRefreshObligationIx(addAllToSetupIxns);
|
|
849
1291
|
}
|
|
850
|
-
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) {
|
|
851
1293
|
// TODO: why are we not doing this first?
|
|
852
1294
|
if (includeAtaIxns) {
|
|
853
1295
|
await this.addAtaIxs(action);
|
|
@@ -1041,47 +1483,56 @@ class KaminoAction {
|
|
|
1041
1483
|
this.addRequestElevationIx(overrideElevationGroupRequest, 'cleanup', skipReserveIfClosing);
|
|
1042
1484
|
}
|
|
1043
1485
|
}
|
|
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);
|
|
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
|
+
}
|
|
1073
1506
|
}
|
|
1074
1507
|
else {
|
|
1075
|
-
|
|
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
|
+
}
|
|
1076
1520
|
}
|
|
1077
1521
|
}
|
|
1078
1522
|
}
|
|
1079
1523
|
}
|
|
1080
|
-
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1524
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1081
1525
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1082
1526
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1083
1527
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
1084
|
-
|
|
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);
|
|
1085
1536
|
}
|
|
1086
1537
|
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
1087
1538
|
await this.addInitReferrerTokenStateIx(this.reserve);
|
|
@@ -1092,7 +1543,7 @@ class KaminoAction {
|
|
|
1092
1543
|
}
|
|
1093
1544
|
await this.addInitObligationIxs();
|
|
1094
1545
|
}
|
|
1095
|
-
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1546
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1096
1547
|
}
|
|
1097
1548
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1098
1549
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1240,15 +1691,13 @@ class KaminoAction {
|
|
|
1240
1691
|
}
|
|
1241
1692
|
}
|
|
1242
1693
|
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
1694
|
const farms = [];
|
|
1246
1695
|
for (const kaminoReserve of reserves) {
|
|
1247
1696
|
if (mode === types_1.ReserveFarmKind.Collateral && !kaminoReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)) {
|
|
1248
1697
|
farms.push([
|
|
1249
1698
|
types_1.ReserveFarmKind.Collateral,
|
|
1250
1699
|
kaminoReserve.state.farmCollateral,
|
|
1251
|
-
|
|
1700
|
+
(0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
1252
1701
|
kaminoReserve,
|
|
1253
1702
|
]);
|
|
1254
1703
|
}
|
|
@@ -1256,7 +1705,7 @@ class KaminoAction {
|
|
|
1256
1705
|
farms.push([
|
|
1257
1706
|
types_1.ReserveFarmKind.Debt,
|
|
1258
1707
|
kaminoReserve.state.farmDebt,
|
|
1259
|
-
|
|
1708
|
+
(0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
1260
1709
|
kaminoReserve,
|
|
1261
1710
|
]);
|
|
1262
1711
|
}
|
|
@@ -1304,21 +1753,19 @@ class KaminoAction {
|
|
|
1304
1753
|
this.cleanupIxsLabels.splice(0, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
|
|
1305
1754
|
}
|
|
1306
1755
|
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
1756
|
const farms = [];
|
|
1310
1757
|
if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
|
|
1311
|
-
const
|
|
1312
|
-
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);
|
|
1313
1760
|
if (!account) {
|
|
1314
|
-
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
1761
|
+
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
1315
1762
|
}
|
|
1316
1763
|
}
|
|
1317
1764
|
if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
|
|
1318
|
-
const
|
|
1319
|
-
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);
|
|
1320
1767
|
if (!account) {
|
|
1321
|
-
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
1768
|
+
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
1322
1769
|
}
|
|
1323
1770
|
}
|
|
1324
1771
|
farms.forEach((arg) => {
|
|
@@ -1371,10 +1818,7 @@ class KaminoAction {
|
|
|
1371
1818
|
this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
|
|
1372
1819
|
}
|
|
1373
1820
|
}
|
|
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()}]`);
|
|
1821
|
+
addInitUserMetadataIxs(lookupTableAddress) {
|
|
1378
1822
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1379
1823
|
const referrerUserMetadataAddress = this.referrer.equals(web3_js_1.PublicKey.default)
|
|
1380
1824
|
? this.kaminoMarket.programId
|
|
@@ -1433,48 +1877,29 @@ class KaminoAction {
|
|
|
1433
1877
|
this.computeBudgetIxsLabels.push(`AddComputeBudget[${units}]`);
|
|
1434
1878
|
}
|
|
1435
1879
|
async addAtaIxs(action) {
|
|
1436
|
-
if (this.mint.equals(
|
|
1880
|
+
if (this.mint.equals(spl_token_1.NATIVE_MINT) || this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1437
1881
|
await this.updateWSOLAccount(action);
|
|
1438
1882
|
}
|
|
1439
|
-
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)) {
|
|
1440
1884
|
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
|
-
}
|
|
1885
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1886
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1449
1887
|
}
|
|
1450
1888
|
if (action === 'liquidate') {
|
|
1451
1889
|
if (!this.outflowReserve) {
|
|
1452
1890
|
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1453
1891
|
}
|
|
1454
1892
|
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
|
-
}
|
|
1893
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1894
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1463
1895
|
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
|
-
}
|
|
1896
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1897
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1472
1898
|
if (!this.additionalTokenAccountAddress) {
|
|
1473
1899
|
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
1474
1900
|
}
|
|
1475
1901
|
}
|
|
1476
|
-
if (action === 'depositAndBorrow' ||
|
|
1477
|
-
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT))) {
|
|
1902
|
+
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(spl_token_1.NATIVE_MINT))) {
|
|
1478
1903
|
if (!this.additionalTokenAccountAddress) {
|
|
1479
1904
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1480
1905
|
}
|
|
@@ -1498,14 +1923,8 @@ class KaminoAction {
|
|
|
1498
1923
|
if (action === 'mint') {
|
|
1499
1924
|
const collateralMintPubkey = this.reserve.getCTokenMint();
|
|
1500
1925
|
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
|
-
}
|
|
1926
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1927
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1509
1928
|
}
|
|
1510
1929
|
}
|
|
1511
1930
|
async updateWSOLAccount(action) {
|
|
@@ -1532,7 +1951,7 @@ class KaminoAction {
|
|
|
1532
1951
|
.toNumber()).toString());
|
|
1533
1952
|
}
|
|
1534
1953
|
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
1535
|
-
if (this.secondaryMint?.equals(
|
|
1954
|
+
if (this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1536
1955
|
if (!this.additionalTokenAccountAddress) {
|
|
1537
1956
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1538
1957
|
}
|
|
@@ -1544,7 +1963,7 @@ class KaminoAction {
|
|
|
1544
1963
|
const sendAction = action === 'deposit' ||
|
|
1545
1964
|
action === 'repay' ||
|
|
1546
1965
|
action === 'mint' ||
|
|
1547
|
-
(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
|
|
1548
1967
|
const transferLamportsIx = web3_js_1.SystemProgram.transfer({
|
|
1549
1968
|
fromPubkey: this.owner,
|
|
1550
1969
|
toPubkey: userTokenAccountAddress,
|
|
@@ -1573,14 +1992,6 @@ class KaminoAction {
|
|
|
1573
1992
|
postIxs.push(closeWSOLAccountIx);
|
|
1574
1993
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1575
1994
|
}
|
|
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
1995
|
this.setupIxs.unshift(...preIxs);
|
|
1585
1996
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
1586
1997
|
this.cleanupIxs.push(...postIxs);
|