@kamino-finance/klend-sdk 5.11.0-beta.0 → 5.11.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 +16 -17
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +61 -102
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +16 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +28 -3
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +6 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +4 -2
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +2 -2
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +15 -11
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/types.d.ts +4 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +1 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +17 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +80 -26
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +8 -3
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +199 -152
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +18 -2
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +31 -3
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -2
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +3 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.js +5 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +2 -2
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +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/instructions/withdrawProtocolFee.js +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +2 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +10 -4
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +9 -7
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +5 -3
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +12 -10
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -2
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +2 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +19 -13
- package/dist/leverage/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +2 -2
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -9
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +5 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +1 -3
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +2 -1
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +7 -7
- package/src/classes/action.ts +77 -105
- package/src/classes/manager.ts +35 -3
- package/src/classes/obligation.ts +8 -4
- package/src/classes/reserve.ts +16 -13
- package/src/classes/types.ts +5 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +95 -38
- package/src/client_kamino_manager.ts +10 -3
- package/src/idl.json +199 -152
- package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
- package/src/idl_codegen/errors/custom.ts +39 -2
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/index.ts +4 -4
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initReserve.ts +6 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/redeemFees.ts +1 -1
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +2 -2
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +2 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +12 -6
- package/src/lending_operations/repay_with_collateral_operations.ts +1 -0
- package/src/lending_operations/swap_collateral_operations.ts +6 -5
- package/src/leverage/calcs.ts +16 -13
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +28 -18
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/instruction.ts +1 -3
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/userMetadata.ts +2 -2
|
@@ -16,11 +16,10 @@ import {
|
|
|
16
16
|
ScopeRefresh,
|
|
17
17
|
U64_MAX,
|
|
18
18
|
uniqueAccounts,
|
|
19
|
-
WRAPPED_SOL_MINT,
|
|
20
19
|
} from '../utils';
|
|
21
20
|
import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
22
21
|
import Decimal from 'decimal.js';
|
|
23
|
-
import { createCloseAccountInstruction, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
|
+
import { createCloseAccountInstruction, NATIVE_MINT, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Inputs to the `getSwapCollIxns()` operation.
|
|
@@ -330,11 +329,11 @@ function getAtaCreationIxns(context: SwapCollContext<any>) {
|
|
|
330
329
|
function getAtaCloseIxns(context: SwapCollContext<any>) {
|
|
331
330
|
const ataCloseIxns: TransactionInstruction[] = [];
|
|
332
331
|
if (
|
|
333
|
-
context.sourceCollReserve.getLiquidityMint().equals(
|
|
334
|
-
context.targetCollReserve.getLiquidityMint().equals(
|
|
332
|
+
context.sourceCollReserve.getLiquidityMint().equals(NATIVE_MINT) ||
|
|
333
|
+
context.targetCollReserve.getLiquidityMint().equals(NATIVE_MINT)
|
|
335
334
|
) {
|
|
336
335
|
const owner = context.obligation.state.owner;
|
|
337
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
336
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
338
337
|
ataCloseIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
339
338
|
}
|
|
340
339
|
return ataCloseIxns;
|
|
@@ -385,6 +384,7 @@ async function getDepositTargetCollIxns(
|
|
|
385
384
|
false, // we do not need ATA ixns here (we construct and close them ourselves)
|
|
386
385
|
removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
|
|
387
386
|
false, // we are dealing with an existing obligation, no need to create user metadata
|
|
387
|
+
false, // we do not need to create a lookup table, dealing with an existing obligation
|
|
388
388
|
context.referrer,
|
|
389
389
|
context.currentSlot,
|
|
390
390
|
context.scopeRefresh,
|
|
@@ -434,6 +434,7 @@ async function getWithdrawSourceCollIxns(
|
|
|
434
434
|
false, // we do not need ATA ixns here (we construct and close them ourselves)
|
|
435
435
|
requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
|
|
436
436
|
false, // we are dealing with an existing obligation, no need to create user metadata
|
|
437
|
+
false, // we do not need to create a lookup table, dealing with an existing obligation
|
|
437
438
|
context.referrer,
|
|
438
439
|
context.currentSlot,
|
|
439
440
|
undefined, // we have refreshed scope already, during depositing
|
package/src/leverage/calcs.ts
CHANGED
|
@@ -65,7 +65,8 @@ export async function calculateMultiplyEffects(
|
|
|
65
65
|
debtBorrowFactorPct,
|
|
66
66
|
priceCollToDebt,
|
|
67
67
|
priceDebtToColl,
|
|
68
|
-
}: LeverageFormsCalcsArgs
|
|
68
|
+
}: LeverageFormsCalcsArgs,
|
|
69
|
+
logEstimations = false
|
|
69
70
|
): Promise<FormsCalcsResult> {
|
|
70
71
|
// calculate estimations for deposit operation
|
|
71
72
|
const {
|
|
@@ -107,18 +108,20 @@ export async function calculateMultiplyEffects(
|
|
|
107
108
|
flashLoanFee: flashBorrowReserveFlashLoanFeePercentage, // TODO: is this the right flash borrow?
|
|
108
109
|
});
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
if (logEstimations) {
|
|
112
|
+
console.log(
|
|
113
|
+
'Estimations',
|
|
114
|
+
toJson({
|
|
115
|
+
activeTab,
|
|
116
|
+
depositModeEstimatedDepositAmount,
|
|
117
|
+
depositModeEstimatedBorrowAmount,
|
|
118
|
+
withdrawModeEstimatedDepositTokenWithdrawn,
|
|
119
|
+
withdrawModeEstimatedBorrowTokenWithdrawn,
|
|
120
|
+
adjustModeEstimatedDepositAmount,
|
|
121
|
+
adjustModeEstimateBorrowAmount,
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
}
|
|
122
125
|
|
|
123
126
|
let [isClosingPosition, totalDeposited, totalBorrowed] = [false, new Decimal(0), new Decimal(0)];
|
|
124
127
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from '@solana/web3.js';
|
|
2
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
2
3
|
import { KaminoReserve } from '../classes';
|
|
3
4
|
import {
|
|
4
5
|
FlashBorrowReserveLiquidityArgs,
|
|
@@ -9,12 +10,6 @@ import {
|
|
|
9
10
|
flashRepayReserveLiquidity,
|
|
10
11
|
} from '../lib';
|
|
11
12
|
import Decimal from 'decimal.js';
|
|
12
|
-
import * as anchor from '@coral-xyz/anchor';
|
|
13
|
-
|
|
14
|
-
export const SOL_MINTS: Array<PublicKey> = [
|
|
15
|
-
new PublicKey('So11111111111111111111111111111111111111111'),
|
|
16
|
-
new PublicKey('So11111111111111111111111111111111111111112'),
|
|
17
|
-
];
|
|
18
13
|
|
|
19
14
|
export const getFlashLoanInstructions = (args: {
|
|
20
15
|
borrowIxnIndex: number;
|
|
@@ -17,11 +17,10 @@ import {
|
|
|
17
17
|
ObligationTypeTag,
|
|
18
18
|
SOL_DECIMALS,
|
|
19
19
|
U64_MAX,
|
|
20
|
-
WRAPPED_SOL_MINT,
|
|
21
20
|
createAtasIdempotent,
|
|
22
21
|
getAssociatedTokenAddress,
|
|
23
22
|
getComputeBudgetAndPriorityFeeIxns,
|
|
24
|
-
|
|
23
|
+
getTransferWsolIxns,
|
|
25
24
|
getLookupTableAccount,
|
|
26
25
|
removeBudgetAndAtaIxns,
|
|
27
26
|
uniqueAccounts,
|
|
@@ -35,7 +34,12 @@ import {
|
|
|
35
34
|
toJson,
|
|
36
35
|
withdrawLeverageCalcs,
|
|
37
36
|
} from './calcs';
|
|
38
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
NATIVE_MINT,
|
|
39
|
+
TOKEN_PROGRAM_ID,
|
|
40
|
+
createCloseAccountInstruction,
|
|
41
|
+
getAssociatedTokenAddressSync,
|
|
42
|
+
} from '@solana/spl-token';
|
|
39
43
|
import { Kamino, StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
|
|
40
44
|
import { getExpectedTokenBalanceAfterBorrow, getKtokenToTokenSwapper, getTokenToKtokenSwapper } from './utils';
|
|
41
45
|
import { FullBPS } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
@@ -90,7 +94,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
90
94
|
}> {
|
|
91
95
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
|
|
92
96
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
|
|
93
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
97
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
94
98
|
const flashLoanFee = collReserve.getFlashLoanFee() || new Decimal(0);
|
|
95
99
|
|
|
96
100
|
const selectedTokenIsCollToken = selectedTokenMint.equals(collTokenMint);
|
|
@@ -193,7 +197,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
193
197
|
|
|
194
198
|
if (collIsKtoken) {
|
|
195
199
|
let futureBalanceInAta = new Decimal(0);
|
|
196
|
-
if (debtTokenMint.equals(
|
|
200
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
197
201
|
futureBalanceInAta = futureBalanceInAta.add(
|
|
198
202
|
!collIsKtoken ? quotePriceCalcs.initDepositInSol : quotePriceCalcs.initDepositInSol
|
|
199
203
|
);
|
|
@@ -370,7 +374,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
|
|
|
370
374
|
|
|
371
375
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
372
376
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
373
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
377
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
374
378
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
375
379
|
|
|
376
380
|
const ixs = await buildDepositWithLeverageIxns(
|
|
@@ -491,9 +495,9 @@ async function buildDepositWithLeverageIxns(
|
|
|
491
495
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
492
496
|
if (depositTokenIsSol) {
|
|
493
497
|
fillWsolAtaIxns.push(
|
|
494
|
-
...
|
|
498
|
+
...getTransferWsolIxns(
|
|
495
499
|
owner,
|
|
496
|
-
getAssociatedTokenAddressSync(
|
|
500
|
+
getAssociatedTokenAddressSync(NATIVE_MINT, owner),
|
|
497
501
|
toLamports(calcs.initDepositInSol, SOL_DECIMALS).ceil()
|
|
498
502
|
)
|
|
499
503
|
);
|
|
@@ -537,6 +541,7 @@ async function buildDepositWithLeverageIxns(
|
|
|
537
541
|
false,
|
|
538
542
|
elevationGroupOverride === 0 ? false : true, // emode
|
|
539
543
|
false, // to be checked and created in a setup tx in the UI
|
|
544
|
+
false, // to be checked and created in a setup tx in the UI
|
|
540
545
|
referrer,
|
|
541
546
|
currentSlot,
|
|
542
547
|
scopeRefresh
|
|
@@ -606,7 +611,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
606
611
|
const collIsKtoken = await isKtoken(collTokenMint);
|
|
607
612
|
const strategy = collIsKtoken ? (await kamino!.getStrategyByKTokenMint(collTokenMint))! : undefined;
|
|
608
613
|
|
|
609
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
614
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
610
615
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
611
616
|
|
|
612
617
|
const calcs = withdrawLeverageCalcs(
|
|
@@ -734,7 +739,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
|
|
|
734
739
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
735
740
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
736
741
|
|
|
737
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
742
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
738
743
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
739
744
|
const { swapInputs, initialInputs } = await getWithdrawWithLeverageSwapInputs({
|
|
740
745
|
owner,
|
|
@@ -898,8 +903,8 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
898
903
|
const atasAndCreateIxns = createAtasIdempotent(owner, mintsToCreateAtas);
|
|
899
904
|
|
|
900
905
|
const closeWsolAtaIxns: TransactionInstruction[] = [];
|
|
901
|
-
if (depositTokenIsSol || debtTokenMint.equals(
|
|
902
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
906
|
+
if (depositTokenIsSol || debtTokenMint.equals(NATIVE_MINT)) {
|
|
907
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
903
908
|
closeWsolAtaIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
904
909
|
}
|
|
905
910
|
|
|
@@ -908,13 +913,13 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
908
913
|
// TODO: Might be worth removing as it's only needed for Ktokens
|
|
909
914
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
910
915
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
911
|
-
if (debtTokenMint.equals(
|
|
916
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
912
917
|
const halfSolBalance = (await market.getConnection().getBalance(owner)) / LAMPORTS_PER_SOL / 2;
|
|
913
918
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
914
919
|
fillWsolAtaIxns.push(
|
|
915
|
-
...
|
|
920
|
+
...getTransferWsolIxns(
|
|
916
921
|
owner,
|
|
917
|
-
getAssociatedTokenAddressSync(
|
|
922
|
+
getAssociatedTokenAddressSync(NATIVE_MINT, owner),
|
|
918
923
|
toLamports(balanceToWrap, SOL_DECIMALS).ceil()
|
|
919
924
|
)
|
|
920
925
|
);
|
|
@@ -953,6 +958,7 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
953
958
|
0,
|
|
954
959
|
false,
|
|
955
960
|
false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
961
|
+
false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
956
962
|
isClosingPosition,
|
|
957
963
|
referrer,
|
|
958
964
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1496,6 +1502,7 @@ async function buildIncreaseLeverageIxns(
|
|
|
1496
1502
|
false,
|
|
1497
1503
|
false,
|
|
1498
1504
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1505
|
+
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1499
1506
|
referrer,
|
|
1500
1507
|
currentSlot,
|
|
1501
1508
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1513,6 +1520,7 @@ async function buildIncreaseLeverageIxns(
|
|
|
1513
1520
|
false,
|
|
1514
1521
|
false,
|
|
1515
1522
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1523
|
+
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1516
1524
|
referrer,
|
|
1517
1525
|
currentSlot,
|
|
1518
1526
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1633,15 +1641,15 @@ async function buildDecreaseLeverageIxns(
|
|
|
1633
1641
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
1634
1642
|
const closeWsolAtaIxns: TransactionInstruction[] = [];
|
|
1635
1643
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
1636
|
-
if (debtTokenMint.equals(
|
|
1637
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
1644
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
1645
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
1638
1646
|
|
|
1639
1647
|
closeWsolAtaIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
1640
1648
|
|
|
1641
1649
|
const halfSolBalance = (await kaminoMarket.getConnection().getBalance(owner)) / LAMPORTS_PER_SOL / 2;
|
|
1642
1650
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
1643
1651
|
fillWsolAtaIxns.push(
|
|
1644
|
-
...
|
|
1652
|
+
...getTransferWsolIxns(owner, wsolAta, toLamports(balanceToWrap, debtReserve!.stats.decimals).ceil())
|
|
1645
1653
|
);
|
|
1646
1654
|
}
|
|
1647
1655
|
|
|
@@ -1675,6 +1683,7 @@ async function buildDecreaseLeverageIxns(
|
|
|
1675
1683
|
false,
|
|
1676
1684
|
false,
|
|
1677
1685
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1686
|
+
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1678
1687
|
referrer,
|
|
1679
1688
|
scopeRefresh
|
|
1680
1689
|
);
|
|
@@ -1691,6 +1700,7 @@ async function buildDecreaseLeverageIxns(
|
|
|
1691
1700
|
false,
|
|
1692
1701
|
false,
|
|
1693
1702
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1703
|
+
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1694
1704
|
referrer,
|
|
1695
1705
|
currentSlot,
|
|
1696
1706
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
package/src/utils/ata.ts
CHANGED
|
@@ -98,7 +98,7 @@ export function createAtasIdempotent(
|
|
|
98
98
|
return res;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export function
|
|
101
|
+
export function getTransferWsolIxns(owner: PublicKey, ata: PublicKey, amountLamports: Decimal) {
|
|
102
102
|
const ixns: TransactionInstruction[] = [];
|
|
103
103
|
|
|
104
104
|
ixns.push(
|
package/src/utils/constants.ts
CHANGED
|
@@ -72,22 +72,16 @@ export const SLOTS_PER_YEAR = SLOTS_PER_DAY * 365;
|
|
|
72
72
|
*/
|
|
73
73
|
export const MIN_AUTODELEVERAGE_BONUS_BPS = 50;
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* WSOL Mint
|
|
77
|
-
*/
|
|
78
|
-
export const WRAPPED_SOL_MINT = new PublicKey('So11111111111111111111111111111111111111112');
|
|
79
|
-
|
|
80
75
|
export const SOL_DECIMALS = 9;
|
|
81
76
|
|
|
82
|
-
/**
|
|
83
|
-
* USDC Mint
|
|
84
|
-
*/
|
|
85
|
-
export const USDC_MAINNET_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
86
|
-
|
|
87
77
|
export const MAINNET_BETA_CHAIN_ID = 101;
|
|
88
78
|
|
|
89
|
-
export const POSITION_LIMIT = 10;
|
|
90
79
|
export const BORROWS_LIMIT = 5;
|
|
91
80
|
export const DEPOSITS_LIMIT = 8;
|
|
92
81
|
|
|
93
82
|
export const DEFAULT_MAX_COMPUTE_UNITS = 1_400_000;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Minimum initial deposit required for the initialization of a reserve
|
|
86
|
+
*/
|
|
87
|
+
export const MIN_INITIAL_DEPOSIT = 100_000;
|
package/src/utils/instruction.ts
CHANGED
|
@@ -38,7 +38,7 @@ export async function buildAndSendTxnWithLogs(
|
|
|
38
38
|
});
|
|
39
39
|
console.log('Transaction Hash:', withDescription, sig);
|
|
40
40
|
if (withLogsIfSuccess) {
|
|
41
|
-
await sleep(
|
|
41
|
+
await sleep(1000);
|
|
42
42
|
const res = await c.getTransaction(sig, {
|
|
43
43
|
commitment: 'confirmed',
|
|
44
44
|
maxSupportedTransactionVersion: 6,
|
|
@@ -49,7 +49,6 @@ export async function buildAndSendTxnWithLogs(
|
|
|
49
49
|
} catch (e: any) {
|
|
50
50
|
console.log(e);
|
|
51
51
|
process.stdout.write(e.logs.toString());
|
|
52
|
-
await sleep(5000);
|
|
53
52
|
const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];
|
|
54
53
|
const res: VersionedTransactionResponse | null = await c.getTransaction(sig, {
|
|
55
54
|
commitment: 'confirmed',
|
|
@@ -115,7 +114,6 @@ export async function simulateTxn(c: Connection, tx: Transaction, owner: Keypair
|
|
|
115
114
|
} catch (e: any) {
|
|
116
115
|
console.log(e);
|
|
117
116
|
process.stdout.write(e.logs.toString());
|
|
118
|
-
await sleep(5000);
|
|
119
117
|
const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];
|
|
120
118
|
const res: TransactionResponse | null = await c.getTransaction(sig, {
|
|
121
119
|
commitment: 'confirmed',
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
Connection,
|
|
7
7
|
GetProgramAccountsFilter,
|
|
8
8
|
} from '@solana/web3.js';
|
|
9
|
+
import { NATIVE_MINT } from '@solana/spl-token';
|
|
9
10
|
import { KaminoMarket, KaminoObligation } from '../classes';
|
|
10
11
|
import {
|
|
11
12
|
LeverageObligation,
|
|
12
13
|
MultiplyObligation,
|
|
13
|
-
WRAPPED_SOL_MINT,
|
|
14
14
|
createLookupTableIx,
|
|
15
15
|
extendLookupTableIxs,
|
|
16
16
|
getAssociatedTokenAddress,
|
|
@@ -259,7 +259,7 @@ function getMultiplyObligationAndObligationFarmStateAddresses(
|
|
|
259
259
|
const collMintString = collMint.toString();
|
|
260
260
|
const debtMintString = debtMint.toString();
|
|
261
261
|
if (collReserve && debtReserve) {
|
|
262
|
-
const multiplyObligation = new MultiplyObligation(collMint,
|
|
262
|
+
const multiplyObligation = new MultiplyObligation(collMint, NATIVE_MINT, kaminoMarket.programId);
|
|
263
263
|
obligationPdas.push({
|
|
264
264
|
address: multiplyObligation.toPda(kaminoMarket.getAddress(), user),
|
|
265
265
|
log: 'multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|