@kamino-finance/klend-sdk 2.12.1 → 2.12.2-kv-beta
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 +0 -1
- package/dist/classes/action.js +75 -124
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +2 -0
- package/dist/classes/index.js +2 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +158 -0
- package/dist/classes/manager.js +374 -0
- package/dist/classes/manager.js.map +1 -0
- package/dist/classes/obligation.js +0 -21
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +13 -35
- package/dist/classes/reserve.js +747 -73
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +69 -0
- package/dist/classes/vault.js +433 -0
- package/dist/classes/vault.js.map +1 -0
- package/dist/client_kamino_manager.d.ts +11 -0
- package/dist/client_kamino_manager.js +350 -0
- package/dist/client_kamino_manager.js.map +1 -0
- package/dist/idl.json +98 -280
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +3 -3
- package/dist/idl_codegen/accounts/LendingMarket.js +1 -7
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +3 -6
- package/dist/idl_codegen/accounts/Obligation.js +6 -12
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/accounts/Reserve.d.ts +0 -18
- package/dist/idl_codegen/accounts/Reserve.js +2 -14
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +4 -84
- package/dist/idl_codegen/errors/custom.js +8 -139
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +0 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +0 -5
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +1 -3
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -15
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +1 -3
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -15
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +0 -2
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js +0 -5
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +0 -2
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js +0 -5
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +4 -2
- package/dist/idl_codegen/instructions/index.js +5 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligation.js +1 -0
- package/dist/idl_codegen/instructions/initObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -2
- package/dist/idl_codegen/instructions/initReserve.js +1 -10
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +2 -6
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +3 -27
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.d.ts +0 -1
- package/dist/idl_codegen/instructions/redeemFees.js +0 -5
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +1 -3
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -15
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +0 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +0 -5
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +1 -2
- package/dist/idl_codegen/instructions/updateReserveConfig.js +2 -4
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +1 -3
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -15
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +0 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +0 -5
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +0 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +0 -5
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/programId.d.ts +1 -2
- package/dist/idl_codegen/programId.js +1 -5
- package/dist/idl_codegen/programId.js.map +1 -1
- package/dist/idl_codegen/types/ElevationGroup.d.ts +10 -24
- package/dist/idl_codegen/types/ElevationGroup.js +12 -25
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -1
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +0 -23
- package/dist/idl_codegen/types/ObligationCollateral.js +1 -8
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +0 -8
- package/dist/idl_codegen/types/ObligationLiquidity.js +1 -8
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/ReserveConfig.d.ts +9 -55
- package/dist/idl_codegen/types/ReserveConfig.js +6 -20
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts +0 -8
- package/dist/idl_codegen/types/ReserveLiquidity.js +1 -7
- package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +0 -39
- package/dist/idl_codegen/types/UpdateConfigMode.js +1 -79
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +2 -4
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +0 -13
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +1 -27
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +4 -4
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +2 -3
- package/dist/idl_codegen/zero_padding/ObligationZP.js +3 -8
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts +90 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +168 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +69 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +181 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts +4 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js +8 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts +434 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js +713 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +194 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js +322 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts +5 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js +71 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +19 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js +58 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts +10 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js +14 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +13 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +24 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts +18 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js +44 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +19 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +58 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts +27 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js +77 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/programId.d.ts +3 -0
- package/dist/idl_codegen_kamino_vault/programId.js +9 -0
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts +27 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js +73 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts +27 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js +62 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts +26 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js +66 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts +47 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js +86 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts +41 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js +75 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts +25 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js +62 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts +53 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js +93 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +373 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +236 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts +78 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js +86 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts +173 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js +166 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts +41 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js +76 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts +30 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js +67 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts +117 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js +128 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts +56 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js +104 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +38 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +86 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +30 -0
- package/dist/idl_codegen_kamino_vault/types/index.js +34 -0
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -0
- package/dist/leverage/instructions.js +0 -2
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.js +3 -4
- package/dist/leverage/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +5 -5
- package/dist/utils/ata.js +29 -39
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/instruction.d.ts +2 -1
- package/dist/utils/instruction.js +8 -1
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/sendTransactionsUtils.d.ts +40 -0
- package/dist/utils/sendTransactionsUtils.js +154 -0
- package/dist/utils/sendTransactionsUtils.js.map +1 -0
- package/package.json +3 -2
- package/dist/utils/token.d.ts +0 -2
- package/dist/utils/token.js +0 -20
- package/dist/utils/token.js.map +0 -1
package/dist/classes/action.d.ts
CHANGED
package/dist/classes/action.js
CHANGED
|
@@ -24,7 +24,6 @@ const types_1 = require("../idl_codegen/types");
|
|
|
24
24
|
const farms_sdk_1 = require("@hubbleprotocol/farms-sdk");
|
|
25
25
|
const ObligationType_1 = require("../utils/ObligationType");
|
|
26
26
|
const lib_1 = require("../lib");
|
|
27
|
-
const token_1 = require("../utils/token");
|
|
28
27
|
exports.POSITION_LIMIT = 10;
|
|
29
28
|
exports.BORROWS_LIMIT = 5;
|
|
30
29
|
exports.DEPOSITS_LIMIT = 8;
|
|
@@ -83,7 +82,7 @@ class KaminoAction {
|
|
|
83
82
|
if (reserve === undefined) {
|
|
84
83
|
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
85
84
|
}
|
|
86
|
-
const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(payer !== null && payer !== void 0 ? payer : owner, reserve.state);
|
|
85
|
+
const { userTokenAccountAddress, userCollateralAccountAddress } = yield KaminoAction.getUserAccountAddresses(payer !== null && payer !== void 0 ? payer : owner, reserve.state);
|
|
87
86
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = yield KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
|
|
88
87
|
const [_, userMetadata] = yield kaminoMarket.getUserMetadata(owner);
|
|
89
88
|
if (userMetadata) {
|
|
@@ -94,9 +93,11 @@ class KaminoAction {
|
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
95
|
static getUserAccountAddresses(owner, reserve) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const userTokenAccountAddress = yield spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, reserve.liquidity.mintPubkey, owner, true);
|
|
98
|
+
const userCollateralAccountAddress = yield spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, reserve.collateral.mintPubkey, owner, true);
|
|
99
|
+
return { userTokenAccountAddress, userCollateralAccountAddress };
|
|
100
|
+
});
|
|
100
101
|
}
|
|
101
102
|
static loadObligation(action, kaminoMarket, owner, reserve, obligation, outflowReserve) {
|
|
102
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -443,14 +444,12 @@ class KaminoAction {
|
|
|
443
444
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
444
445
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
445
446
|
reserve: this.reserve.address,
|
|
446
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
447
447
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
448
448
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
449
449
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault,
|
|
450
450
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
451
451
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
452
|
-
|
|
453
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
452
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
454
453
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
455
454
|
}, this.kaminoMarket.programId));
|
|
456
455
|
}
|
|
@@ -463,13 +462,11 @@ class KaminoAction {
|
|
|
463
462
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
464
463
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
465
464
|
reserve: this.reserve.address,
|
|
466
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
467
465
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
468
466
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
469
467
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
470
468
|
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
471
|
-
|
|
472
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
469
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
473
470
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
474
471
|
}, this.kaminoMarket.programId));
|
|
475
472
|
}
|
|
@@ -482,13 +479,11 @@ class KaminoAction {
|
|
|
482
479
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
483
480
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
484
481
|
reserve: this.reserve.address,
|
|
485
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
486
482
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
487
483
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
488
484
|
userSourceCollateral: this.userCollateralAccountAddress,
|
|
489
485
|
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
490
|
-
|
|
491
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
486
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
492
487
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
493
488
|
}, this.kaminoMarket.programId));
|
|
494
489
|
}
|
|
@@ -508,13 +503,8 @@ class KaminoAction {
|
|
|
508
503
|
}, this.kaminoMarket.programId));
|
|
509
504
|
}
|
|
510
505
|
addBorrowIx() {
|
|
511
|
-
var _a;
|
|
512
506
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
513
|
-
|
|
514
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
515
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
516
|
-
});
|
|
517
|
-
const borrowIx = (0, instructions_1.borrowObligationLiquidity)({
|
|
507
|
+
this.lendingIxs.push((0, instructions_1.borrowObligationLiquidity)({
|
|
518
508
|
liquidityAmount: this.amount,
|
|
519
509
|
}, {
|
|
520
510
|
owner: this.owner,
|
|
@@ -522,18 +512,13 @@ class KaminoAction {
|
|
|
522
512
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
523
513
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
524
514
|
borrowReserve: this.reserve.address,
|
|
525
|
-
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
526
515
|
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
527
516
|
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
528
517
|
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
529
518
|
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
|
|
530
|
-
tokenProgram:
|
|
519
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
531
520
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
532
|
-
}, this.kaminoMarket.programId);
|
|
533
|
-
borrowIx.keys = ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)
|
|
534
|
-
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
535
|
-
: borrowIx.keys;
|
|
536
|
-
this.lendingIxs.push(borrowIx);
|
|
521
|
+
}, this.kaminoMarket.programId));
|
|
537
522
|
}
|
|
538
523
|
addDepositAndBorrowIx() {
|
|
539
524
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -547,14 +532,12 @@ class KaminoAction {
|
|
|
547
532
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
548
533
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
549
534
|
reserve: this.reserve.address,
|
|
550
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
551
535
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
552
536
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
553
537
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault,
|
|
554
538
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
555
539
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
556
|
-
|
|
557
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
540
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
558
541
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
559
542
|
}, this.kaminoMarket.programId));
|
|
560
543
|
if (!this.outflowReserve) {
|
|
@@ -566,14 +549,7 @@ class KaminoAction {
|
|
|
566
549
|
if (!this.outflowAmount) {
|
|
567
550
|
throw new Error(`outflowAmount not set`);
|
|
568
551
|
}
|
|
569
|
-
|
|
570
|
-
if (depositReservesList.length === 0) {
|
|
571
|
-
depositReservesList.push(this.reserve.address);
|
|
572
|
-
}
|
|
573
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
574
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
575
|
-
});
|
|
576
|
-
const borrowIx = (0, instructions_1.borrowObligationLiquidity)({
|
|
552
|
+
this.lendingIxs.push((0, instructions_1.borrowObligationLiquidity)({
|
|
577
553
|
liquidityAmount: this.outflowAmount,
|
|
578
554
|
}, {
|
|
579
555
|
owner: this.owner,
|
|
@@ -581,41 +557,31 @@ class KaminoAction {
|
|
|
581
557
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
582
558
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
583
559
|
borrowReserve: this.outflowReserve.address,
|
|
584
|
-
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
585
560
|
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
586
561
|
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
587
562
|
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
588
563
|
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
589
|
-
tokenProgram:
|
|
564
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
590
565
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
591
|
-
}, this.kaminoMarket.programId);
|
|
592
|
-
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
593
|
-
this.lendingIxs.push(borrowIx);
|
|
566
|
+
}, this.kaminoMarket.programId));
|
|
594
567
|
});
|
|
595
568
|
}
|
|
596
569
|
addRepayAndWithdrawIxs() {
|
|
597
570
|
return __awaiter(this, void 0, void 0, function* () {
|
|
598
571
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
599
572
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
600
|
-
|
|
601
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
602
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
603
|
-
});
|
|
604
|
-
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
573
|
+
this.lendingIxs.push((0, instructions_1.repayObligationLiquidity)({
|
|
605
574
|
liquidityAmount: this.amount,
|
|
606
575
|
}, {
|
|
607
576
|
owner: this.owner,
|
|
608
577
|
obligation: this.getObligationPda(),
|
|
609
578
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
610
579
|
repayReserve: this.reserve.address,
|
|
611
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
612
580
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
613
581
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
614
|
-
tokenProgram:
|
|
582
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
615
583
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
616
|
-
}, this.kaminoMarket.programId);
|
|
617
|
-
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
618
|
-
this.lendingIxs.push(repayIx);
|
|
584
|
+
}, this.kaminoMarket.programId));
|
|
619
585
|
if (!this.outflowReserve) {
|
|
620
586
|
throw new Error(`outflowReserve not set`);
|
|
621
587
|
}
|
|
@@ -636,14 +602,12 @@ class KaminoAction {
|
|
|
636
602
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
637
603
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
638
604
|
withdrawReserve: this.outflowReserve.address,
|
|
639
|
-
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
640
605
|
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
641
606
|
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
642
607
|
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
643
608
|
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
644
609
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
645
|
-
|
|
646
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
610
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
647
611
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
648
612
|
}, this.kaminoMarket.programId));
|
|
649
613
|
});
|
|
@@ -663,46 +627,34 @@ class KaminoAction {
|
|
|
663
627
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
664
628
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
665
629
|
withdrawReserve: this.reserve.address,
|
|
666
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
667
630
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
668
631
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
669
632
|
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
670
633
|
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
671
634
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
672
|
-
|
|
673
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
635
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
674
636
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
675
637
|
}, this.kaminoMarket.programId));
|
|
676
638
|
});
|
|
677
639
|
}
|
|
678
640
|
addRepayIx() {
|
|
679
|
-
var _a;
|
|
680
641
|
return __awaiter(this, void 0, void 0, function* () {
|
|
681
642
|
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
682
|
-
|
|
683
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
684
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
685
|
-
});
|
|
686
|
-
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
643
|
+
this.lendingIxs.push((0, instructions_1.repayObligationLiquidity)({
|
|
687
644
|
liquidityAmount: this.amount,
|
|
688
645
|
}, {
|
|
689
646
|
owner: this.payer,
|
|
690
647
|
obligation: this.getObligationPda(),
|
|
691
648
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
692
649
|
repayReserve: this.reserve.address,
|
|
693
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
694
650
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
695
651
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
696
|
-
tokenProgram:
|
|
652
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
697
653
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
698
|
-
}, this.kaminoMarket.programId);
|
|
699
|
-
repayIx.keys =
|
|
700
|
-
((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
701
|
-
this.lendingIxs.push(repayIx);
|
|
654
|
+
}, this.kaminoMarket.programId));
|
|
702
655
|
});
|
|
703
656
|
}
|
|
704
657
|
addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
|
|
705
|
-
var _a;
|
|
706
658
|
return __awaiter(this, void 0, void 0, function* () {
|
|
707
659
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
708
660
|
if (!this.outflowReserve) {
|
|
@@ -711,14 +663,11 @@ class KaminoAction {
|
|
|
711
663
|
if (!this.additionalTokenAccountAddress) {
|
|
712
664
|
throw Error(`Liquidating token account address is not defined`);
|
|
713
665
|
}
|
|
714
|
-
|
|
715
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
716
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
717
|
-
});
|
|
718
|
-
const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateral)({
|
|
666
|
+
this.lendingIxs.push((0, instructions_1.liquidateObligationAndRedeemReserveCollateral)({
|
|
719
667
|
liquidityAmount: this.amount,
|
|
720
668
|
// TODO: Configure this when updating liquidator with new interface
|
|
721
|
-
|
|
669
|
+
minAcceptableReceivedCollateralAmount: this.outflowAmount || new bn_js_1.default(0),
|
|
670
|
+
// TODO: remove this before going live
|
|
722
671
|
maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
|
|
723
672
|
}, {
|
|
724
673
|
liquidator: this.owner,
|
|
@@ -726,10 +675,8 @@ class KaminoAction {
|
|
|
726
675
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
727
676
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
728
677
|
repayReserve: this.reserve.address,
|
|
729
|
-
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
730
678
|
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
731
679
|
withdrawReserve: this.outflowReserve.address,
|
|
732
|
-
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
733
680
|
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
734
681
|
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
735
682
|
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
@@ -737,16 +684,9 @@ class KaminoAction {
|
|
|
737
684
|
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
738
685
|
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
739
686
|
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
740
|
-
|
|
741
|
-
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
742
|
-
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
687
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
743
688
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
744
|
-
}, this.kaminoMarket.programId);
|
|
745
|
-
liquidateIx.keys =
|
|
746
|
-
((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0
|
|
747
|
-
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
748
|
-
: liquidateIx.keys;
|
|
749
|
-
this.lendingIxs.push(liquidateIx);
|
|
689
|
+
}, this.kaminoMarket.programId));
|
|
750
690
|
});
|
|
751
691
|
}
|
|
752
692
|
addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
|
|
@@ -923,18 +863,18 @@ class KaminoAction {
|
|
|
923
863
|
const groupsColl = this.reserve.state.config.elevationGroups;
|
|
924
864
|
const groupsDebt = this.outflowReserve.state.config.elevationGroups;
|
|
925
865
|
const groups = this.kaminoMarket.state.elevationGroups;
|
|
926
|
-
const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0
|
|
866
|
+
const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0);
|
|
927
867
|
console.log('Groups of coll reserve', groupsColl, 'Groups of debt reserve', groupsDebt, 'Common groups', commonElevationGroups);
|
|
928
868
|
if (commonElevationGroups.length === 0) {
|
|
929
869
|
console.log('No common elevation groups found, staying with default');
|
|
930
870
|
}
|
|
931
871
|
else {
|
|
932
|
-
const
|
|
872
|
+
const eModeGroupWithMaxLtv = commonElevationGroups.reduce((prev, curr) => {
|
|
933
873
|
const prevGroup = groups.find((group) => group.id === prev);
|
|
934
874
|
const currGroup = groups.find((group) => group.id === curr);
|
|
935
875
|
return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
|
|
936
876
|
});
|
|
937
|
-
const eModeGroup = groups.find((group) => group.id ===
|
|
877
|
+
const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtv).id;
|
|
938
878
|
console.log('Setting eModeGroup to', eModeGroup);
|
|
939
879
|
if (eModeGroup !== 0 && eModeGroup !== ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)) {
|
|
940
880
|
this.addRequestElevationIx(eModeGroup, false);
|
|
@@ -1017,7 +957,20 @@ class KaminoAction {
|
|
|
1017
957
|
lendingMarket: marketAddress,
|
|
1018
958
|
obligation: obligationPda,
|
|
1019
959
|
}, this.kaminoMarket.programId);
|
|
1020
|
-
const depositReservesList = this.
|
|
960
|
+
const depositReservesList = this.depositReserves;
|
|
961
|
+
// check if there's any member in the preloadedDepositReserves that is not in the depositReserves
|
|
962
|
+
// if so, add it to the depositReserves
|
|
963
|
+
for (let i = 0; i < this.preLoadedDepositReservesSameTx.length; i++) {
|
|
964
|
+
const preloadedDepositReserve = this.preLoadedDepositReservesSameTx[i];
|
|
965
|
+
// Check if the depositReserves array contains the current preloadedDepositReserve
|
|
966
|
+
const found = this.depositReserves.some((depositReserve) => {
|
|
967
|
+
return depositReserve.equals(preloadedDepositReserve);
|
|
968
|
+
});
|
|
969
|
+
// If not found, push the current preloadedDepositReserve to the depositReserves array
|
|
970
|
+
if (!found) {
|
|
971
|
+
depositReservesList.push(this.preLoadedDepositReservesSameTx[i]);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
1021
974
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1022
975
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1023
976
|
});
|
|
@@ -1059,7 +1012,20 @@ class KaminoAction {
|
|
|
1059
1012
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1060
1013
|
};
|
|
1061
1014
|
const requestElevationGroupIx = (0, instructions_1.requestElevationGroup)(args, accounts, this.kaminoMarket.programId);
|
|
1062
|
-
const depositReservesList = this.
|
|
1015
|
+
const depositReservesList = this.depositReserves;
|
|
1016
|
+
// check if there's any member in the preloadedDepositReserves that is not in the depositReserves
|
|
1017
|
+
// if so, add it to the depositReserves
|
|
1018
|
+
for (let i = 0; i < this.preLoadedDepositReservesSameTx.length; i++) {
|
|
1019
|
+
const preloadedDepositReserveString = this.preLoadedDepositReservesSameTx[i].toString();
|
|
1020
|
+
// Check if the depositReserves array contains the current preloadedDepositReserve
|
|
1021
|
+
const found = this.depositReserves.some((depositReserve) => {
|
|
1022
|
+
return depositReserve.toString() === preloadedDepositReserveString;
|
|
1023
|
+
});
|
|
1024
|
+
// If not found, push the current preloadedDepositReserve to the depositReserves array
|
|
1025
|
+
if (!found) {
|
|
1026
|
+
depositReservesList.push(this.preLoadedDepositReservesSameTx[i]);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1063
1029
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1064
1030
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1065
1031
|
});
|
|
@@ -1126,6 +1092,7 @@ class KaminoAction {
|
|
|
1126
1092
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1127
1093
|
farmsProgram: farms_sdk_1.farmsId,
|
|
1128
1094
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1095
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1129
1096
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1130
1097
|
};
|
|
1131
1098
|
const refreshFarmForObligationix = (0, instructions_1.refreshObligationFarmsForReserve)(args, accounts, this.kaminoMarket.programId);
|
|
@@ -1186,6 +1153,7 @@ class KaminoAction {
|
|
|
1186
1153
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1187
1154
|
farmsProgram: farms_sdk_1.farmsId,
|
|
1188
1155
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1156
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1189
1157
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1190
1158
|
};
|
|
1191
1159
|
const initObligationForFarm = (0, instructions_1.initObligationFarmsForReserve)(args, accounts, this.kaminoMarket.programId);
|
|
@@ -1219,6 +1187,7 @@ class KaminoAction {
|
|
|
1219
1187
|
seed2Account: this.obligationType.toArgs().seed2,
|
|
1220
1188
|
ownerUserMetadata: userMetadataAddress,
|
|
1221
1189
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1190
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1222
1191
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1223
1192
|
}, this.kaminoMarket.programId);
|
|
1224
1193
|
this.setupIxs.push(initObligationIx);
|
|
@@ -1287,12 +1256,11 @@ class KaminoAction {
|
|
|
1287
1256
|
referrer: this.owner,
|
|
1288
1257
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1289
1258
|
reserve: this.reserve.address,
|
|
1290
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1291
1259
|
referrerTokenState: referrerTokenStateAddress,
|
|
1292
1260
|
reserveSupplyLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1293
1261
|
referrerTokenAccount: this.userTokenAccountAddress,
|
|
1294
1262
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1295
|
-
tokenProgram:
|
|
1263
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1296
1264
|
}, this.kaminoMarket.programId);
|
|
1297
1265
|
this.lendingIxs.push(withdrawReferrerFeesIx);
|
|
1298
1266
|
this.lendingIxsLabels.push(`WithdrawReferrerFeesIx[${this.owner.toString()}]`);
|
|
@@ -1310,7 +1278,7 @@ class KaminoAction {
|
|
|
1310
1278
|
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1311
1279
|
const userTokenAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
|
|
1312
1280
|
if (!userTokenAccountInfo) {
|
|
1313
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.
|
|
1281
|
+
const [, createUserTokenAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.userTokenAccountAddress);
|
|
1314
1282
|
if (this.positions === exports.POSITION_LIMIT && this.hostAta) {
|
|
1315
1283
|
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1316
1284
|
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
@@ -1327,7 +1295,7 @@ class KaminoAction {
|
|
|
1327
1295
|
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1328
1296
|
}
|
|
1329
1297
|
if (!userTokenAccountInfo) {
|
|
1330
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.
|
|
1298
|
+
const [, createUserTokenAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.userTokenAccountAddress);
|
|
1331
1299
|
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1332
1300
|
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1333
1301
|
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
@@ -1341,7 +1309,7 @@ class KaminoAction {
|
|
|
1341
1309
|
.getConnection()
|
|
1342
1310
|
.getAccountInfo(this.userCollateralAccountAddress);
|
|
1343
1311
|
if (!userCollateralAccountInfo) {
|
|
1344
|
-
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner,
|
|
1312
|
+
const [, createUserCollateralAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, this.userCollateralAccountAddress);
|
|
1345
1313
|
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1346
1314
|
this.preTxnIxs.push(createUserCollateralAccountIx);
|
|
1347
1315
|
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
@@ -1367,7 +1335,7 @@ class KaminoAction {
|
|
|
1367
1335
|
.getConnection()
|
|
1368
1336
|
.getAccountInfo(this.additionalTokenAccountAddress);
|
|
1369
1337
|
if (!additionalUserTokenAccountInfo) {
|
|
1370
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.
|
|
1338
|
+
const [, createUserTokenAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.additionalTokenAccountAddress);
|
|
1371
1339
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1372
1340
|
this.setupIxsLabels.unshift(`CreateAdditionalUserTokenAta[${this.owner}]`);
|
|
1373
1341
|
}
|
|
@@ -1376,7 +1344,7 @@ class KaminoAction {
|
|
|
1376
1344
|
const userTokenAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
|
|
1377
1345
|
// TODO: Might need to remove this
|
|
1378
1346
|
if (!userTokenAccountInfo) {
|
|
1379
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.
|
|
1347
|
+
const [, createUserTokenAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.userTokenAccountAddress);
|
|
1380
1348
|
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1381
1349
|
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1382
1350
|
}
|
|
@@ -1387,7 +1355,7 @@ class KaminoAction {
|
|
|
1387
1355
|
.getAccountInfo(this.userCollateralAccountAddress);
|
|
1388
1356
|
if (!userCollateralAccountInfo) {
|
|
1389
1357
|
const collateralMintPubkey = this.reserve.getCTokenMint();
|
|
1390
|
-
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner,
|
|
1358
|
+
const [, createUserCollateralAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, this.userCollateralAccountAddress);
|
|
1391
1359
|
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1392
1360
|
this.preTxnIxs.push(createUserCollateralAccountIx);
|
|
1393
1361
|
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
@@ -1433,7 +1401,7 @@ class KaminoAction {
|
|
|
1433
1401
|
userTokenAccountAddress = this.additionalTokenAccountAddress;
|
|
1434
1402
|
}
|
|
1435
1403
|
const userWSOLAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(userTokenAccountAddress);
|
|
1436
|
-
const rentExempt = yield this.kaminoMarket.getConnection()
|
|
1404
|
+
const rentExempt = yield spl_token_1.Token.getMinBalanceRentForExemptAccount(this.kaminoMarket.getConnection());
|
|
1437
1405
|
// Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
|
|
1438
1406
|
const sendAction = action === 'deposit' ||
|
|
1439
1407
|
action === 'repay' ||
|
|
@@ -1446,7 +1414,7 @@ class KaminoAction {
|
|
|
1446
1414
|
});
|
|
1447
1415
|
preIxs.push(transferLamportsIx);
|
|
1448
1416
|
preIxsLabels.push(`TransferLamportsToUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1449
|
-
const closeWSOLAccountIx = (
|
|
1417
|
+
const closeWSOLAccountIx = spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, userTokenAccountAddress, this.owner, this.owner, []);
|
|
1450
1418
|
const syncIx = (0, utils_1.syncNative)(userTokenAccountAddress);
|
|
1451
1419
|
if (userWSOLAccountInfo) {
|
|
1452
1420
|
if (sendAction) {
|
|
@@ -1459,7 +1427,7 @@ class KaminoAction {
|
|
|
1459
1427
|
}
|
|
1460
1428
|
}
|
|
1461
1429
|
else {
|
|
1462
|
-
const [, createUserWSOLAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, spl_token_1.NATIVE_MINT, this.owner,
|
|
1430
|
+
const [, createUserWSOLAccountIx] = yield (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, spl_token_1.NATIVE_MINT, this.owner, userTokenAccountAddress);
|
|
1463
1431
|
preIxs.push(createUserWSOLAccountIx);
|
|
1464
1432
|
preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1465
1433
|
preIxs.push(syncIx);
|
|
@@ -1488,8 +1456,8 @@ class KaminoAction {
|
|
|
1488
1456
|
if (!outflowReserve || !inflowReserve) {
|
|
1489
1457
|
throw new Error('reserve states are not fetched');
|
|
1490
1458
|
}
|
|
1491
|
-
const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
|
|
1492
|
-
const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
|
|
1459
|
+
const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = yield KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
|
|
1460
|
+
const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = yield KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
|
|
1493
1461
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = yield KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
|
|
1494
1462
|
const [_, userMetadata] = yield kaminoMarket.getUserMetadata(payer);
|
|
1495
1463
|
if (userMetadata) {
|
|
@@ -1549,23 +1517,6 @@ class KaminoAction {
|
|
|
1549
1517
|
? this.obligation.obligationAddress
|
|
1550
1518
|
: this.obligationType.toPda(this.kaminoMarket.getAddress(), this.owner);
|
|
1551
1519
|
}
|
|
1552
|
-
getAdditionalDepositReservesList() {
|
|
1553
|
-
const depositReservesList = this.depositReserves;
|
|
1554
|
-
// check if there's any member in the preloadedDepositReserves that is not in the depositReserves
|
|
1555
|
-
// if so, add it to the depositReserves
|
|
1556
|
-
for (let i = 0; i < this.preLoadedDepositReservesSameTx.length; i++) {
|
|
1557
|
-
const preloadedDepositReserve = this.preLoadedDepositReservesSameTx[i];
|
|
1558
|
-
// Check if the depositReserves array contains the current preloadedDepositReserve
|
|
1559
|
-
const found = this.depositReserves.some((depositReserve) => {
|
|
1560
|
-
return depositReserve.equals(preloadedDepositReserve);
|
|
1561
|
-
});
|
|
1562
|
-
// If not found, push the current preloadedDepositReserve to the depositReserves array
|
|
1563
|
-
if (!found) {
|
|
1564
|
-
depositReservesList.push(this.preLoadedDepositReservesSameTx[i]);
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
return depositReservesList;
|
|
1568
|
-
}
|
|
1569
1520
|
}
|
|
1570
1521
|
exports.KaminoAction = KaminoAction;
|
|
1571
1522
|
//# sourceMappingURL=action.js.map
|