@kamino-finance/klend-sdk 5.10.28-beta.0 → 5.11.0-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 +22 -14
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +585 -132
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +0 -3
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +0 -3
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.js +1 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -6
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +2 -4
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/types.d.ts +1 -13
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/idl.json +71 -5
- 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 +35 -3
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +61 -5
- package/dist/idl_codegen/errors/custom.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 +22 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +2 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +6 -1
- 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 +4 -2
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +10 -12
- package/dist/leverage/calcs.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 +27 -24
- 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/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 +6 -9
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +4 -4
- package/src/classes/action.ts +749 -146
- package/src/classes/index.ts +0 -3
- package/src/classes/manager.ts +1 -1
- package/src/classes/obligation.ts +4 -8
- package/src/classes/types.ts +1 -17
- package/src/client.ts +7 -3
- package/src/idl.json +71 -5
- package/src/idl_codegen/accounts/Obligation.ts +12 -1
- package/src/idl_codegen/errors/custom.ts +66 -4
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +31 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +1 -1
- package/src/idl_codegen/zero_padding/ObligationZP.ts +6 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +11 -3
- package/src/lending_operations/swap_collateral_operations.ts +11 -0
- package/src/leverage/calcs.ts +13 -16
- package/src/leverage/operations.ts +38 -11
- package/src/leverage/types.ts +4 -1
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +19 -24
- package/dist/classes/stakePool.d.ts +0 -8
- package/dist/classes/stakePool.d.ts.map +0 -1
- package/dist/classes/stakePool.js +0 -18
- package/dist/classes/stakePool.js.map +0 -1
- package/dist/classes/standardStakePool.d.ts +0 -255
- package/dist/classes/standardStakePool.d.ts.map +0 -1
- package/dist/classes/standardStakePool.js +0 -275
- package/dist/classes/standardStakePool.js.map +0 -1
- package/dist/classes/unstakingPool.d.ts +0 -111
- package/dist/classes/unstakingPool.d.ts.map +0 -1
- package/dist/classes/unstakingPool.js +0 -437
- package/dist/classes/unstakingPool.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.d.ts +0 -50
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.js +0 -156
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/index.d.ts +0 -3
- package/dist/idl_codegen_unstaking_pool/accounts/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/index.js +0 -6
- package/dist/idl_codegen_unstaking_pool/accounts/index.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/anchor.d.ts +0 -435
- package/dist/idl_codegen_unstaking_pool/errors/anchor.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/anchor.js +0 -767
- package/dist/idl_codegen_unstaking_pool/errors/anchor.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/custom.d.ts +0 -163
- package/dist/idl_codegen_unstaking_pool/errors/custom.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/custom.js +0 -290
- package/dist/idl_codegen_unstaking_pool/errors/custom.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/index.d.ts +0 -6
- package/dist/idl_codegen_unstaking_pool/errors/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/index.js +0 -75
- package/dist/idl_codegen_unstaking_pool/errors/index.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/burn.d.ts +0 -21
- package/dist/idl_codegen_unstaking_pool/instructions/burn.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/burn.js +0 -73
- package/dist/idl_codegen_unstaking_pool/instructions/burn.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/collect.d.ts +0 -16
- package/dist/idl_codegen_unstaking_pool/instructions/collect.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/collect.js +0 -29
- package/dist/idl_codegen_unstaking_pool/instructions/collect.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/index.d.ts +0 -11
- package/dist/idl_codegen_unstaking_pool/instructions/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/index.js +0 -14
- package/dist/idl_codegen_unstaking_pool/instructions/index.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.d.ts +0 -15
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.js +0 -28
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/mint.d.ts +0 -21
- package/dist/idl_codegen_unstaking_pool/instructions/mint.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/mint.js +0 -77
- package/dist/idl_codegen_unstaking_pool/instructions/mint.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.d.ts +0 -13
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.js +0 -58
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/programId.d.ts +0 -4
- package/dist/idl_codegen_unstaking_pool/programId.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/programId.js +0 -9
- package/dist/idl_codegen_unstaking_pool/programId.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.d.ts +0 -32
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.js +0 -105
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/index.d.ts +0 -5
- package/dist/idl_codegen_unstaking_pool/types/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/index.js +0 -39
- package/dist/idl_codegen_unstaking_pool/types/index.js.map +0 -1
- package/src/classes/stakePool.ts +0 -21
- package/src/classes/standardStakePool.ts +0 -361
- package/src/classes/unstakingPool.ts +0 -565
- package/src/idl_codegen_unstaking_pool/accounts/PoolState.ts +0 -163
- package/src/idl_codegen_unstaking_pool/accounts/index.ts +0 -2
- package/src/idl_codegen_unstaking_pool/errors/anchor.ts +0 -764
- package/src/idl_codegen_unstaking_pool/errors/custom.ts +0 -288
- package/src/idl_codegen_unstaking_pool/errors/index.ts +0 -49
- package/src/idl_codegen_unstaking_pool/instructions/burn.ts +0 -60
- package/src/idl_codegen_unstaking_pool/instructions/collect.ts +0 -43
- package/src/idl_codegen_unstaking_pool/instructions/index.ts +0 -10
- package/src/idl_codegen_unstaking_pool/instructions/initializePool.ts +0 -41
- package/src/idl_codegen_unstaking_pool/instructions/mint.ts +0 -64
- package/src/idl_codegen_unstaking_pool/instructions/updatePoolConfig.ts +0 -40
- package/src/idl_codegen_unstaking_pool/programId.ts +0 -7
- package/src/idl_codegen_unstaking_pool/types/PoolConfigField.ts +0 -85
- package/src/idl_codegen_unstaking_pool/types/index.ts +0 -6
- package/src/idl_unstaking_pool.json +0 -456
package/dist/classes/action.js
CHANGED
|
@@ -183,7 +183,7 @@ class KaminoAction {
|
|
|
183
183
|
axn.addRequestElevationIx(elevationGroup, 'setup');
|
|
184
184
|
return axn;
|
|
185
185
|
}
|
|
186
|
-
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
186
|
+
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
187
187
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
188
188
|
requestElevationGroup = false, // to be requested *before* the deposit
|
|
189
189
|
includeUserMetadata = true, // if true it includes user metadata
|
|
@@ -203,8 +203,13 @@ class KaminoAction {
|
|
|
203
203
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
204
204
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
205
205
|
}
|
|
206
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
207
|
-
|
|
206
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, undefined, overrideElevationGroupRequest);
|
|
207
|
+
if (useV2Ixs) {
|
|
208
|
+
axn.addDepositIxV2();
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
axn.addDepositIx();
|
|
212
|
+
}
|
|
208
213
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
209
214
|
return axn;
|
|
210
215
|
}
|
|
@@ -236,7 +241,7 @@ class KaminoAction {
|
|
|
236
241
|
feed: feed,
|
|
237
242
|
}, tokens));
|
|
238
243
|
}
|
|
239
|
-
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
244
|
+
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
240
245
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
241
246
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
242
247
|
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
|
|
@@ -255,8 +260,13 @@ class KaminoAction {
|
|
|
255
260
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
256
261
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
257
262
|
}
|
|
258
|
-
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
259
|
-
|
|
263
|
+
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, undefined, overrideElevationGroupRequest);
|
|
264
|
+
if (useV2Ixs) {
|
|
265
|
+
axn.addBorrowIxV2();
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
axn.addBorrowIx();
|
|
269
|
+
}
|
|
260
270
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
261
271
|
return axn;
|
|
262
272
|
}
|
|
@@ -278,7 +288,7 @@ class KaminoAction {
|
|
|
278
288
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
279
289
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
280
290
|
}
|
|
281
|
-
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
291
|
+
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false);
|
|
282
292
|
axn.addDepositReserveLiquidityIx();
|
|
283
293
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
284
294
|
return axn;
|
|
@@ -301,12 +311,12 @@ class KaminoAction {
|
|
|
301
311
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
302
312
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
303
313
|
}
|
|
304
|
-
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
314
|
+
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false);
|
|
305
315
|
axn.addRedeemReserveCollateralIx();
|
|
306
316
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
307
317
|
return axn;
|
|
308
318
|
}
|
|
309
|
-
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
319
|
+
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
310
320
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
311
321
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
312
322
|
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
@@ -324,12 +334,17 @@ class KaminoAction {
|
|
|
324
334
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
325
335
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
326
336
|
}
|
|
327
|
-
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
328
|
-
|
|
337
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs);
|
|
338
|
+
if (useV2Ixs) {
|
|
339
|
+
axn.addDepositObligationCollateralIxV2();
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
axn.addDepositObligationCollateralIx();
|
|
343
|
+
}
|
|
329
344
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
330
345
|
return axn;
|
|
331
346
|
}
|
|
332
|
-
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
347
|
+
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
333
348
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
334
349
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
335
350
|
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
@@ -350,13 +365,18 @@ class KaminoAction {
|
|
|
350
365
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
351
366
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
352
367
|
}
|
|
353
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, twoTokenAction);
|
|
354
|
-
|
|
355
|
-
|
|
368
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, twoTokenAction);
|
|
369
|
+
if (useV2Ixs) {
|
|
370
|
+
await axn.addDepositAndBorrowIxV2();
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
await axn.addDepositAndBorrowIx();
|
|
374
|
+
}
|
|
375
|
+
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
|
|
356
376
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
357
377
|
return axn;
|
|
358
378
|
}
|
|
359
|
-
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
379
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
360
380
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
361
381
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
362
382
|
referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
@@ -377,13 +397,18 @@ class KaminoAction {
|
|
|
377
397
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
378
398
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
379
399
|
}
|
|
380
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, twoTokenAction);
|
|
381
|
-
|
|
382
|
-
|
|
400
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, twoTokenAction);
|
|
401
|
+
if (useV2Ixs) {
|
|
402
|
+
await axn.addRepayAndWithdrawIxsV2();
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
await axn.addRepayAndWithdrawIxs();
|
|
406
|
+
}
|
|
407
|
+
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
|
|
383
408
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
384
409
|
return axn;
|
|
385
410
|
}
|
|
386
|
-
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
411
|
+
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
387
412
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
388
413
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
389
414
|
includeUserMetadata = true, // if true it includes user metadata
|
|
@@ -405,8 +430,13 @@ class KaminoAction {
|
|
|
405
430
|
if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
|
|
406
431
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
407
432
|
}
|
|
408
|
-
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, false, overrideElevationGroupRequest);
|
|
409
|
-
|
|
433
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, false, overrideElevationGroupRequest);
|
|
434
|
+
if (useV2Ixs) {
|
|
435
|
+
await axn.addWithdrawIxV2();
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
await axn.addWithdrawIx();
|
|
439
|
+
}
|
|
410
440
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
411
441
|
return axn;
|
|
412
442
|
}
|
|
@@ -425,7 +455,7 @@ class KaminoAction {
|
|
|
425
455
|
* @param includeUserMetadata - if true it includes user metadata
|
|
426
456
|
* @param referrer
|
|
427
457
|
*/
|
|
428
|
-
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
458
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
429
459
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
430
460
|
const addInitObligationForFarm = true;
|
|
431
461
|
if (extraComputeBudget > 0) {
|
|
@@ -440,12 +470,17 @@ class KaminoAction {
|
|
|
440
470
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
441
471
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
442
472
|
}
|
|
443
|
-
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
444
|
-
|
|
473
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs);
|
|
474
|
+
if (useV2Ixs) {
|
|
475
|
+
await axn.addRepayIxV2();
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
await axn.addRepayIx();
|
|
479
|
+
}
|
|
445
480
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
446
481
|
return axn;
|
|
447
482
|
}
|
|
448
|
-
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
483
|
+
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
449
484
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
450
485
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
451
486
|
referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
@@ -464,8 +499,13 @@ class KaminoAction {
|
|
|
464
499
|
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
465
500
|
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
466
501
|
}
|
|
467
|
-
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
468
|
-
|
|
502
|
+
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs);
|
|
503
|
+
if (useV2Ixs) {
|
|
504
|
+
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
508
|
+
}
|
|
469
509
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
470
510
|
return axn;
|
|
471
511
|
}
|
|
@@ -535,31 +575,29 @@ class KaminoAction {
|
|
|
535
575
|
return '';
|
|
536
576
|
return await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
537
577
|
}
|
|
538
|
-
|
|
539
|
-
this.lendingIxsLabels.push(`
|
|
540
|
-
this.lendingIxs.push((0, instructions_1.
|
|
578
|
+
addDepositReserveLiquidityIx() {
|
|
579
|
+
this.lendingIxsLabels.push(`depositReserveLiquidity`);
|
|
580
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidity)({
|
|
541
581
|
liquidityAmount: this.amount,
|
|
542
582
|
}, {
|
|
543
583
|
owner: this.owner,
|
|
544
|
-
obligation: this.getObligationPda(),
|
|
545
584
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
546
585
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
547
586
|
reserve: this.reserve.address,
|
|
548
587
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
549
588
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
550
589
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
551
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
552
590
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
553
|
-
|
|
591
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
554
592
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
555
593
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
556
594
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
557
595
|
}, this.kaminoMarket.programId));
|
|
558
596
|
}
|
|
559
|
-
|
|
560
|
-
this.lendingIxsLabels.push(`
|
|
561
|
-
this.lendingIxs.push((0, instructions_1.
|
|
562
|
-
|
|
597
|
+
addRedeemReserveCollateralIx() {
|
|
598
|
+
this.lendingIxsLabels.push(`redeemReserveCollateral`);
|
|
599
|
+
this.lendingIxs.push((0, instructions_1.redeemReserveCollateral)({
|
|
600
|
+
collateralAmount: this.amount,
|
|
563
601
|
}, {
|
|
564
602
|
owner: this.owner,
|
|
565
603
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
@@ -568,32 +606,70 @@ class KaminoAction {
|
|
|
568
606
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
569
607
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
570
608
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
571
|
-
|
|
572
|
-
|
|
609
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
610
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
573
611
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
574
612
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
575
613
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
576
614
|
}, this.kaminoMarket.programId));
|
|
577
615
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
this.
|
|
581
|
-
|
|
616
|
+
// @deprecated -- use addDepositIxV2 instead
|
|
617
|
+
addDepositIx() {
|
|
618
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
619
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
|
|
620
|
+
liquidityAmount: this.amount,
|
|
582
621
|
}, {
|
|
583
622
|
owner: this.owner,
|
|
623
|
+
obligation: this.getObligationPda(),
|
|
584
624
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
585
625
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
586
626
|
reserve: this.reserve.address,
|
|
587
627
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
588
628
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
589
629
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
590
|
-
|
|
591
|
-
|
|
630
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
631
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
632
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
592
633
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
593
634
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
594
635
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
595
636
|
}, this.kaminoMarket.programId));
|
|
596
637
|
}
|
|
638
|
+
addDepositIxV2() {
|
|
639
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
640
|
+
? {
|
|
641
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
642
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
643
|
+
}
|
|
644
|
+
: {
|
|
645
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
646
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
647
|
+
};
|
|
648
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
649
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({
|
|
650
|
+
liquidityAmount: this.amount,
|
|
651
|
+
}, {
|
|
652
|
+
depositAccounts: {
|
|
653
|
+
owner: this.owner,
|
|
654
|
+
obligation: this.getObligationPda(),
|
|
655
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
656
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
657
|
+
reserve: this.reserve.address,
|
|
658
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
659
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
660
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
661
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
662
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
663
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
664
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
665
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
666
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
667
|
+
},
|
|
668
|
+
farmsAccounts,
|
|
669
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
670
|
+
}, this.kaminoMarket.programId));
|
|
671
|
+
}
|
|
672
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
597
673
|
addDepositObligationCollateralIx() {
|
|
598
674
|
this.lendingIxsLabels.push(`depositObligationCollateral`);
|
|
599
675
|
this.lendingIxs.push((0, instructions_1.depositObligationCollateral)({
|
|
@@ -609,6 +685,36 @@ class KaminoAction {
|
|
|
609
685
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
610
686
|
}, this.kaminoMarket.programId));
|
|
611
687
|
}
|
|
688
|
+
addDepositObligationCollateralIxV2() {
|
|
689
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
690
|
+
? {
|
|
691
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
692
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
693
|
+
}
|
|
694
|
+
: {
|
|
695
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
696
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
697
|
+
};
|
|
698
|
+
this.lendingIxsLabels.push(`depositObligationCollateralV2`);
|
|
699
|
+
this.lendingIxs.push((0, instructions_1.depositObligationCollateralV2)({
|
|
700
|
+
collateralAmount: this.amount,
|
|
701
|
+
}, {
|
|
702
|
+
depositAccounts: {
|
|
703
|
+
owner: this.owner,
|
|
704
|
+
obligation: this.getObligationPda(),
|
|
705
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
706
|
+
depositReserve: this.reserve.address,
|
|
707
|
+
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
708
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
709
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
710
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
711
|
+
},
|
|
712
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
713
|
+
farmsAccounts,
|
|
714
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
715
|
+
}, this.kaminoMarket.programId));
|
|
716
|
+
}
|
|
717
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
612
718
|
addBorrowIx() {
|
|
613
719
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
614
720
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
@@ -637,6 +743,173 @@ class KaminoAction {
|
|
|
637
743
|
: borrowIx.keys;
|
|
638
744
|
this.lendingIxs.push(borrowIx);
|
|
639
745
|
}
|
|
746
|
+
addBorrowIxV2() {
|
|
747
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
748
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
749
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
750
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
751
|
+
});
|
|
752
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
753
|
+
? {
|
|
754
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
755
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
756
|
+
}
|
|
757
|
+
: {
|
|
758
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
759
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
760
|
+
};
|
|
761
|
+
const borrowIx = (0, instructions_1.borrowObligationLiquidityV2)({
|
|
762
|
+
liquidityAmount: this.amount,
|
|
763
|
+
}, {
|
|
764
|
+
borrowAccounts: {
|
|
765
|
+
owner: this.owner,
|
|
766
|
+
obligation: this.getObligationPda(),
|
|
767
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
768
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
769
|
+
borrowReserve: this.reserve.address,
|
|
770
|
+
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
771
|
+
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
772
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
773
|
+
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
774
|
+
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
|
|
775
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
776
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
777
|
+
},
|
|
778
|
+
farmsAccounts,
|
|
779
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
780
|
+
}, this.kaminoMarket.programId);
|
|
781
|
+
borrowIx.keys =
|
|
782
|
+
this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0
|
|
783
|
+
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
784
|
+
: borrowIx.keys;
|
|
785
|
+
this.lendingIxs.push(borrowIx);
|
|
786
|
+
}
|
|
787
|
+
/// @deprecated -- use addWithdrawIxV2 instead
|
|
788
|
+
async addWithdrawIx() {
|
|
789
|
+
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
790
|
+
const collateralAmount = this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
791
|
+
? this.amount
|
|
792
|
+
: new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
793
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
794
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
795
|
+
collateralAmount,
|
|
796
|
+
}, {
|
|
797
|
+
owner: this.owner,
|
|
798
|
+
obligation: this.getObligationPda(),
|
|
799
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
800
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
801
|
+
withdrawReserve: this.reserve.address,
|
|
802
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
803
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
804
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
805
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
806
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
807
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
808
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
809
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
810
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
811
|
+
}, this.kaminoMarket.programId));
|
|
812
|
+
}
|
|
813
|
+
async addWithdrawIxV2() {
|
|
814
|
+
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
815
|
+
// TODO: Move this side effect from here...
|
|
816
|
+
const collateralAmount = this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
817
|
+
? this.amount
|
|
818
|
+
: new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
819
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
820
|
+
? {
|
|
821
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
822
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
823
|
+
}
|
|
824
|
+
: {
|
|
825
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
826
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
827
|
+
};
|
|
828
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
829
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
|
|
830
|
+
collateralAmount,
|
|
831
|
+
}, {
|
|
832
|
+
withdrawAccounts: {
|
|
833
|
+
owner: this.owner,
|
|
834
|
+
obligation: this.getObligationPda(),
|
|
835
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
836
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
837
|
+
withdrawReserve: this.reserve.address,
|
|
838
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
839
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
840
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
841
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
842
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
843
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
844
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
845
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
846
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
847
|
+
},
|
|
848
|
+
farmsAccounts: farmsAccounts,
|
|
849
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
850
|
+
}, this.kaminoMarket.programId));
|
|
851
|
+
}
|
|
852
|
+
/// @deprecated -- use addRepayIxV2 instead
|
|
853
|
+
async addRepayIx() {
|
|
854
|
+
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
855
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
856
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
857
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
858
|
+
});
|
|
859
|
+
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
860
|
+
liquidityAmount: this.amount,
|
|
861
|
+
}, {
|
|
862
|
+
owner: this.payer,
|
|
863
|
+
obligation: this.getObligationPda(),
|
|
864
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
865
|
+
repayReserve: this.reserve.address,
|
|
866
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
867
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
868
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
869
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
870
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
871
|
+
}, this.kaminoMarket.programId);
|
|
872
|
+
repayIx.keys =
|
|
873
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
874
|
+
this.lendingIxs.push(repayIx);
|
|
875
|
+
}
|
|
876
|
+
async addRepayIxV2() {
|
|
877
|
+
this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
878
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
879
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
880
|
+
? {
|
|
881
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
882
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
883
|
+
}
|
|
884
|
+
: {
|
|
885
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
886
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
887
|
+
};
|
|
888
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
889
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
890
|
+
});
|
|
891
|
+
const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
|
|
892
|
+
liquidityAmount: this.amount,
|
|
893
|
+
}, {
|
|
894
|
+
repayAccounts: {
|
|
895
|
+
owner: this.payer,
|
|
896
|
+
obligation: this.getObligationPda(),
|
|
897
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
898
|
+
repayReserve: this.reserve.address,
|
|
899
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
900
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
901
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
902
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
903
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
904
|
+
},
|
|
905
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
906
|
+
farmsAccounts,
|
|
907
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
908
|
+
}, this.kaminoMarket.programId);
|
|
909
|
+
repayIx.keys =
|
|
910
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
911
|
+
this.lendingIxs.push(repayIx);
|
|
912
|
+
}
|
|
640
913
|
async addDepositAndBorrowIx() {
|
|
641
914
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
642
915
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -693,6 +966,88 @@ class KaminoAction {
|
|
|
693
966
|
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
694
967
|
this.lendingIxs.push(borrowIx);
|
|
695
968
|
}
|
|
969
|
+
async addDepositAndBorrowIxV2() {
|
|
970
|
+
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
971
|
+
? {
|
|
972
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
973
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
974
|
+
}
|
|
975
|
+
: {
|
|
976
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
977
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
978
|
+
};
|
|
979
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
980
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
981
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({
|
|
982
|
+
liquidityAmount: this.amount,
|
|
983
|
+
}, {
|
|
984
|
+
depositAccounts: {
|
|
985
|
+
owner: this.owner,
|
|
986
|
+
obligation: this.getObligationPda(),
|
|
987
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
988
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
989
|
+
reserve: this.reserve.address,
|
|
990
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
991
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
992
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
993
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
994
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
995
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
996
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
997
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
998
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
999
|
+
},
|
|
1000
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
1001
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1002
|
+
}, this.kaminoMarket.programId));
|
|
1003
|
+
if (!this.outflowReserve) {
|
|
1004
|
+
throw new Error(`outflowReserve not set`);
|
|
1005
|
+
}
|
|
1006
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1007
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1008
|
+
}
|
|
1009
|
+
if (!this.outflowAmount) {
|
|
1010
|
+
throw new Error(`outflowAmount not set`);
|
|
1011
|
+
}
|
|
1012
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1013
|
+
if (depositReservesList.length === 0) {
|
|
1014
|
+
depositReservesList.push(this.reserve.address);
|
|
1015
|
+
}
|
|
1016
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1017
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1018
|
+
});
|
|
1019
|
+
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1020
|
+
? {
|
|
1021
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1022
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1023
|
+
}
|
|
1024
|
+
: {
|
|
1025
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmDebt)[0],
|
|
1026
|
+
reserveFarmState: this.outflowReserve.state.farmDebt,
|
|
1027
|
+
};
|
|
1028
|
+
const borrowIx = (0, instructions_1.borrowObligationLiquidityV2)({
|
|
1029
|
+
liquidityAmount: this.outflowAmount,
|
|
1030
|
+
}, {
|
|
1031
|
+
borrowAccounts: {
|
|
1032
|
+
owner: this.owner,
|
|
1033
|
+
obligation: this.getObligationPda(),
|
|
1034
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1035
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1036
|
+
borrowReserve: this.outflowReserve.address,
|
|
1037
|
+
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1038
|
+
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1039
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1040
|
+
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1041
|
+
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
1042
|
+
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1043
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1044
|
+
},
|
|
1045
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1046
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1047
|
+
}, this.kaminoMarket.programId);
|
|
1048
|
+
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
1049
|
+
this.lendingIxs.push(borrowIx);
|
|
1050
|
+
}
|
|
696
1051
|
async addRepayAndWithdrawIxs() {
|
|
697
1052
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
698
1053
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
@@ -746,53 +1101,85 @@ class KaminoAction {
|
|
|
746
1101
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
747
1102
|
}, this.kaminoMarket.programId));
|
|
748
1103
|
}
|
|
749
|
-
async
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
? this.amount
|
|
753
|
-
: new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
754
|
-
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
755
|
-
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
756
|
-
collateralAmount,
|
|
757
|
-
}, {
|
|
758
|
-
owner: this.owner,
|
|
759
|
-
obligation: this.getObligationPda(),
|
|
760
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
761
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
762
|
-
withdrawReserve: this.reserve.address,
|
|
763
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
764
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
765
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
766
|
-
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
767
|
-
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
768
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
769
|
-
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
770
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
771
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
772
|
-
}, this.kaminoMarket.programId));
|
|
773
|
-
}
|
|
774
|
-
async addRepayIx() {
|
|
775
|
-
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
1104
|
+
async addRepayAndWithdrawIxsV2() {
|
|
1105
|
+
this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
1106
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
776
1107
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
777
1108
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
778
1109
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
779
1110
|
});
|
|
780
|
-
const
|
|
1111
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1112
|
+
? {
|
|
1113
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1114
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1115
|
+
}
|
|
1116
|
+
: {
|
|
1117
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1118
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1119
|
+
};
|
|
1120
|
+
const repayIx = (0, instructions_1.repayObligationLiquidityV2)({
|
|
781
1121
|
liquidityAmount: this.amount,
|
|
782
1122
|
}, {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
1123
|
+
repayAccounts: {
|
|
1124
|
+
owner: this.owner,
|
|
1125
|
+
obligation: this.getObligationPda(),
|
|
1126
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1127
|
+
repayReserve: this.reserve.address,
|
|
1128
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1129
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1130
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1131
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1132
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1133
|
+
},
|
|
1134
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1135
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1136
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
792
1137
|
}, this.kaminoMarket.programId);
|
|
793
|
-
repayIx.keys =
|
|
794
|
-
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1138
|
+
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
795
1139
|
this.lendingIxs.push(repayIx);
|
|
1140
|
+
if (!this.outflowReserve) {
|
|
1141
|
+
throw new Error(`outflowReserve not set`);
|
|
1142
|
+
}
|
|
1143
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1144
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1145
|
+
}
|
|
1146
|
+
if (!this.outflowAmount) {
|
|
1147
|
+
throw new Error(`outflowAmount not set`);
|
|
1148
|
+
}
|
|
1149
|
+
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
1150
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1151
|
+
? {
|
|
1152
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1153
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1154
|
+
}
|
|
1155
|
+
: {
|
|
1156
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
1157
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1158
|
+
};
|
|
1159
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({
|
|
1160
|
+
collateralAmount: this.outflowAmount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
1161
|
+
? this.outflowAmount
|
|
1162
|
+
: new bn_js_1.default(new decimal_js_1.default(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
1163
|
+
}, {
|
|
1164
|
+
withdrawAccounts: {
|
|
1165
|
+
owner: this.owner,
|
|
1166
|
+
obligation: this.getObligationPda(),
|
|
1167
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1168
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1169
|
+
withdrawReserve: this.outflowReserve.address,
|
|
1170
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1171
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1172
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1173
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1174
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1175
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1176
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1177
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1178
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1179
|
+
},
|
|
1180
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
1181
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1182
|
+
}, this.kaminoMarket.programId));
|
|
796
1183
|
}
|
|
797
1184
|
async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
|
|
798
1185
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
@@ -839,8 +1226,76 @@ class KaminoAction {
|
|
|
839
1226
|
: liquidateIx.keys;
|
|
840
1227
|
this.lendingIxs.push(liquidateIx);
|
|
841
1228
|
}
|
|
842
|
-
async
|
|
843
|
-
|
|
1229
|
+
async addLiquidateIxV2(maxAllowedLtvOverridePercent = 0) {
|
|
1230
|
+
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
|
|
1231
|
+
if (!this.outflowReserve) {
|
|
1232
|
+
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1233
|
+
}
|
|
1234
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1235
|
+
throw Error(`Liquidating token account address is not defined`);
|
|
1236
|
+
}
|
|
1237
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1238
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1239
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1240
|
+
});
|
|
1241
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1242
|
+
? {
|
|
1243
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1244
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1245
|
+
}
|
|
1246
|
+
: {
|
|
1247
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
1248
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1249
|
+
};
|
|
1250
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1251
|
+
? {
|
|
1252
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1253
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1254
|
+
}
|
|
1255
|
+
: {
|
|
1256
|
+
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1257
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1258
|
+
};
|
|
1259
|
+
const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateralV2)({
|
|
1260
|
+
liquidityAmount: this.amount,
|
|
1261
|
+
// TODO: Configure this when updating liquidator with new interface
|
|
1262
|
+
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
|
|
1263
|
+
maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
|
|
1264
|
+
}, {
|
|
1265
|
+
liquidationAccounts: {
|
|
1266
|
+
liquidator: this.owner,
|
|
1267
|
+
obligation: this.getObligationPda(),
|
|
1268
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1269
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1270
|
+
repayReserve: this.reserve.address,
|
|
1271
|
+
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1272
|
+
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1273
|
+
withdrawReserve: this.outflowReserve.address,
|
|
1274
|
+
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1275
|
+
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1276
|
+
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
1277
|
+
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1278
|
+
userSourceLiquidity: this.additionalTokenAccountAddress,
|
|
1279
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
1280
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1281
|
+
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1282
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1283
|
+
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1284
|
+
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1285
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1286
|
+
},
|
|
1287
|
+
debtFarmsAccounts,
|
|
1288
|
+
collateralFarmsAccounts,
|
|
1289
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1290
|
+
}, this.kaminoMarket.programId);
|
|
1291
|
+
liquidateIx.keys =
|
|
1292
|
+
this.obligation.state.elevationGroup > 0
|
|
1293
|
+
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
1294
|
+
: liquidateIx.keys;
|
|
1295
|
+
this.lendingIxs.push(liquidateIx);
|
|
1296
|
+
}
|
|
1297
|
+
async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, useV2Ixs) {
|
|
1298
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'inBetween', requestElevationGroup, addInitObligationForFarm);
|
|
844
1299
|
}
|
|
845
1300
|
addRefreshObligation(crank) {
|
|
846
1301
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
@@ -852,7 +1307,7 @@ class KaminoAction {
|
|
|
852
1307
|
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
|
|
853
1308
|
this.addRefreshObligationIx(addAllToSetupIxns);
|
|
854
1309
|
}
|
|
855
|
-
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1310
|
+
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
856
1311
|
// TODO: why are we not doing this first?
|
|
857
1312
|
if (includeAtaIxns) {
|
|
858
1313
|
await this.addAtaIxs(action);
|
|
@@ -1046,43 +1501,45 @@ class KaminoAction {
|
|
|
1046
1501
|
this.addRequestElevationIx(overrideElevationGroupRequest, 'cleanup', skipReserveIfClosing);
|
|
1047
1502
|
}
|
|
1048
1503
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
action === '
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
else {
|
|
1070
|
-
// If this is an inbetween, it means it's part of a two-token-action
|
|
1071
|
-
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1072
|
-
// add added to 'setup' ixns
|
|
1073
|
-
if (action === 'depositAndBorrow') {
|
|
1074
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1075
|
-
}
|
|
1076
|
-
else if (action === 'repayAndWithdraw') {
|
|
1077
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1504
|
+
if (!useV2Ixs) {
|
|
1505
|
+
if (addAsSupportIx === 'setup') {
|
|
1506
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
1507
|
+
// or the first of a two-token-action
|
|
1508
|
+
if (action === 'liquidate') {
|
|
1509
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1510
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1511
|
+
}
|
|
1512
|
+
else if (action === 'depositAndBorrow' ||
|
|
1513
|
+
action === 'depositCollateral' ||
|
|
1514
|
+
action === 'withdraw' ||
|
|
1515
|
+
action === 'deposit') {
|
|
1516
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Collateral, undefined, twoTokenAction);
|
|
1517
|
+
}
|
|
1518
|
+
else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
1519
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Debt, undefined, twoTokenAction);
|
|
1520
|
+
}
|
|
1521
|
+
else {
|
|
1522
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1523
|
+
}
|
|
1078
1524
|
}
|
|
1079
1525
|
else {
|
|
1080
|
-
|
|
1526
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
1527
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1528
|
+
// add added to 'setup' ixns
|
|
1529
|
+
if (action === 'depositAndBorrow') {
|
|
1530
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1531
|
+
}
|
|
1532
|
+
else if (action === 'repayAndWithdraw') {
|
|
1533
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1534
|
+
}
|
|
1535
|
+
else {
|
|
1536
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1537
|
+
}
|
|
1081
1538
|
}
|
|
1082
1539
|
}
|
|
1083
1540
|
}
|
|
1084
1541
|
}
|
|
1085
|
-
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1542
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1086
1543
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1087
1544
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1088
1545
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
@@ -1097,7 +1554,7 @@ class KaminoAction {
|
|
|
1097
1554
|
}
|
|
1098
1555
|
await this.addInitObligationIxs();
|
|
1099
1556
|
}
|
|
1100
|
-
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1557
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1101
1558
|
}
|
|
1102
1559
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1103
1560
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1245,15 +1702,13 @@ class KaminoAction {
|
|
|
1245
1702
|
}
|
|
1246
1703
|
}
|
|
1247
1704
|
addRefreshFarmsForReserve(reserves, addAsSupportIx = 'setup', mode, crank = this.payer, twoTokenAction = false) {
|
|
1248
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1249
|
-
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1250
1705
|
const farms = [];
|
|
1251
1706
|
for (const kaminoReserve of reserves) {
|
|
1252
1707
|
if (mode === types_1.ReserveFarmKind.Collateral && !kaminoReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)) {
|
|
1253
1708
|
farms.push([
|
|
1254
1709
|
types_1.ReserveFarmKind.Collateral,
|
|
1255
1710
|
kaminoReserve.state.farmCollateral,
|
|
1256
|
-
|
|
1711
|
+
(0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
1257
1712
|
kaminoReserve,
|
|
1258
1713
|
]);
|
|
1259
1714
|
}
|
|
@@ -1261,7 +1716,7 @@ class KaminoAction {
|
|
|
1261
1716
|
farms.push([
|
|
1262
1717
|
types_1.ReserveFarmKind.Debt,
|
|
1263
1718
|
kaminoReserve.state.farmDebt,
|
|
1264
|
-
|
|
1719
|
+
(0, utils_1.obligationFarmStatePda)(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
1265
1720
|
kaminoReserve,
|
|
1266
1721
|
]);
|
|
1267
1722
|
}
|
|
@@ -1309,21 +1764,19 @@ class KaminoAction {
|
|
|
1309
1764
|
this.cleanupIxsLabels.splice(0, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
|
|
1310
1765
|
}
|
|
1311
1766
|
async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
|
|
1312
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1313
|
-
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1314
1767
|
const farms = [];
|
|
1315
1768
|
if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
|
|
1316
|
-
const
|
|
1317
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
1769
|
+
const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmCollateral)[0];
|
|
1770
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
1318
1771
|
if (!account) {
|
|
1319
|
-
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
1772
|
+
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
1320
1773
|
}
|
|
1321
1774
|
}
|
|
1322
1775
|
if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
|
|
1323
|
-
const
|
|
1324
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
1776
|
+
const userPda = (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), reserve.state.farmDebt)[0];
|
|
1777
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
1325
1778
|
if (!account) {
|
|
1326
|
-
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
1779
|
+
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
1327
1780
|
}
|
|
1328
1781
|
}
|
|
1329
1782
|
farms.forEach((arg) => {
|