@kamino-finance/klend-sdk 5.10.34 → 5.10.35-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +28 -20
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +317 -137
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +2 -1
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +1 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +10 -10
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +6 -1
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +269 -156
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +6 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.js +8 -1
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +51 -3
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +89 -5
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -2
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +3 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.js +5 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +9 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +24 -3
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +2 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +12 -4
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +15 -8
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +22 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +5 -3
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -2
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +2 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +19 -13
- package/dist/leverage/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +2 -2
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -9
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +5 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +27 -0
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +58 -0
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +11 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +16 -1
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +8 -10
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +3 -3
- package/src/classes/action.ts +476 -141
- package/src/classes/manager.ts +13 -0
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +2 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +7 -8
- package/src/client_kamino_manager.ts +8 -1
- package/src/idl.json +269 -156
- package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
- package/src/idl_codegen/accounts/Obligation.ts +12 -1
- package/src/idl_codegen/errors/custom.ts +103 -4
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/index.ts +4 -4
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initReserve.ts +6 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/redeemFees.ts +1 -1
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +33 -3
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +2 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +18 -7
- package/src/lending_operations/repay_with_collateral_calcs.ts +14 -5
- package/src/lending_operations/repay_with_collateral_operations.ts +28 -3
- package/src/lending_operations/swap_collateral_operations.ts +6 -5
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +28 -18
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/lookupTable.ts +62 -0
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +18 -0
- package/src/utils/userMetadata.ts +9 -14
- package/dist/classes/lut_utils.d.ts +0 -29
- package/dist/classes/lut_utils.d.ts.map +0 -1
- package/dist/classes/lut_utils.js +0 -62
- package/dist/classes/lut_utils.js.map +0 -1
- package/src/classes/lut_utils.ts +0 -63
|
@@ -37,6 +37,15 @@ export interface RepayAndWithdrawAndRedeemAccounts {
|
|
|
37
37
|
liquidityTokenProgram: PublicKey
|
|
38
38
|
instructionSysvarAccount: PublicKey
|
|
39
39
|
}
|
|
40
|
+
collateralFarmsAccounts: {
|
|
41
|
+
obligationFarmUserState: PublicKey
|
|
42
|
+
reserveFarmState: PublicKey
|
|
43
|
+
}
|
|
44
|
+
debtFarmsAccounts: {
|
|
45
|
+
obligationFarmUserState: PublicKey
|
|
46
|
+
reserveFarmState: PublicKey
|
|
47
|
+
}
|
|
48
|
+
farmsProgram: PublicKey
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
export const layout = borsh.struct([
|
|
@@ -69,7 +78,7 @@ export function repayAndWithdrawAndRedeem(
|
|
|
69
78
|
{
|
|
70
79
|
pubkey: accounts.repayAccounts.reserveLiquidityMint,
|
|
71
80
|
isSigner: false,
|
|
72
|
-
isWritable:
|
|
81
|
+
isWritable: false,
|
|
73
82
|
},
|
|
74
83
|
{
|
|
75
84
|
pubkey: accounts.repayAccounts.reserveDestinationLiquidity,
|
|
@@ -94,7 +103,7 @@ export function repayAndWithdrawAndRedeem(
|
|
|
94
103
|
{
|
|
95
104
|
pubkey: accounts.withdrawAccounts.owner,
|
|
96
105
|
isSigner: true,
|
|
97
|
-
isWritable:
|
|
106
|
+
isWritable: true,
|
|
98
107
|
},
|
|
99
108
|
{
|
|
100
109
|
pubkey: accounts.withdrawAccounts.obligation,
|
|
@@ -119,7 +128,7 @@ export function repayAndWithdrawAndRedeem(
|
|
|
119
128
|
{
|
|
120
129
|
pubkey: accounts.withdrawAccounts.reserveLiquidityMint,
|
|
121
130
|
isSigner: false,
|
|
122
|
-
isWritable:
|
|
131
|
+
isWritable: false,
|
|
123
132
|
},
|
|
124
133
|
{
|
|
125
134
|
pubkey: accounts.withdrawAccounts.reserveSourceCollateral,
|
|
@@ -161,6 +170,27 @@ export function repayAndWithdrawAndRedeem(
|
|
|
161
170
|
isSigner: false,
|
|
162
171
|
isWritable: false,
|
|
163
172
|
},
|
|
173
|
+
{
|
|
174
|
+
pubkey: accounts.collateralFarmsAccounts.obligationFarmUserState,
|
|
175
|
+
isSigner: false,
|
|
176
|
+
isWritable: true,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
pubkey: accounts.collateralFarmsAccounts.reserveFarmState,
|
|
180
|
+
isSigner: false,
|
|
181
|
+
isWritable: true,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
pubkey: accounts.debtFarmsAccounts.obligationFarmUserState,
|
|
185
|
+
isSigner: false,
|
|
186
|
+
isWritable: true,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
pubkey: accounts.debtFarmsAccounts.reserveFarmState,
|
|
190
|
+
isSigner: false,
|
|
191
|
+
isWritable: true,
|
|
192
|
+
},
|
|
193
|
+
{ pubkey: accounts.farmsProgram, isSigner: false, isWritable: false },
|
|
164
194
|
]
|
|
165
195
|
const identifier = Buffer.from([2, 54, 152, 3, 148, 96, 109, 218])
|
|
166
196
|
const buffer = Buffer.alloc(1000)
|
package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
|
33
33
|
programId: PublicKey = PROGRAM_ID
|
|
34
34
|
) {
|
|
35
35
|
const keys: Array<AccountMeta> = [
|
|
36
|
-
{ pubkey: accounts.owner, isSigner: true, isWritable:
|
|
36
|
+
{ pubkey: accounts.owner, isSigner: true, isWritable: true },
|
|
37
37
|
{ pubkey: accounts.obligation, isSigner: false, isWritable: true },
|
|
38
38
|
{ pubkey: accounts.lendingMarket, isSigner: false, isWritable: false },
|
|
39
39
|
{
|
|
@@ -45,7 +45,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
|
45
45
|
{
|
|
46
46
|
pubkey: accounts.reserveLiquidityMint,
|
|
47
47
|
isSigner: false,
|
|
48
|
-
isWritable:
|
|
48
|
+
isWritable: false,
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
pubkey: accounts.reserveSourceCollateral,
|
package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
|
43
43
|
{
|
|
44
44
|
pubkey: accounts.withdrawAccounts.owner,
|
|
45
45
|
isSigner: true,
|
|
46
|
-
isWritable:
|
|
46
|
+
isWritable: true,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
pubkey: accounts.withdrawAccounts.obligation,
|
|
@@ -68,7 +68,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
|
68
68
|
{
|
|
69
69
|
pubkey: accounts.withdrawAccounts.reserveLiquidityMint,
|
|
70
70
|
isSigner: false,
|
|
71
|
-
isWritable:
|
|
71
|
+
isWritable: false,
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
pubkey: accounts.withdrawAccounts.reserveSourceCollateral,
|
|
@@ -486,6 +486,29 @@ export class UpdateIndividualAutodeleverageMarginCallPeriodSecs {
|
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
+
export interface UpdateInitialDepositAmountJSON {
|
|
490
|
+
kind: "UpdateInitialDepositAmount"
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export class UpdateInitialDepositAmount {
|
|
494
|
+
static readonly discriminator = 21
|
|
495
|
+
static readonly kind = "UpdateInitialDepositAmount"
|
|
496
|
+
readonly discriminator = 21
|
|
497
|
+
readonly kind = "UpdateInitialDepositAmount"
|
|
498
|
+
|
|
499
|
+
toJSON(): UpdateInitialDepositAmountJSON {
|
|
500
|
+
return {
|
|
501
|
+
kind: "UpdateInitialDepositAmount",
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
toEncodable() {
|
|
506
|
+
return {
|
|
507
|
+
UpdateInitialDepositAmount: {},
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
489
512
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
490
513
|
export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
|
|
491
514
|
if (typeof obj !== "object") {
|
|
@@ -555,6 +578,9 @@ export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
|
|
|
555
578
|
if ("UpdateIndividualAutodeleverageMarginCallPeriodSecs" in obj) {
|
|
556
579
|
return new UpdateIndividualAutodeleverageMarginCallPeriodSecs()
|
|
557
580
|
}
|
|
581
|
+
if ("UpdateInitialDepositAmount" in obj) {
|
|
582
|
+
return new UpdateInitialDepositAmount()
|
|
583
|
+
}
|
|
558
584
|
|
|
559
585
|
throw new Error("Invalid enum object")
|
|
560
586
|
}
|
|
@@ -626,6 +652,9 @@ export function fromJSON(
|
|
|
626
652
|
case "UpdateIndividualAutodeleverageMarginCallPeriodSecs": {
|
|
627
653
|
return new UpdateIndividualAutodeleverageMarginCallPeriodSecs()
|
|
628
654
|
}
|
|
655
|
+
case "UpdateInitialDepositAmount": {
|
|
656
|
+
return new UpdateInitialDepositAmount()
|
|
657
|
+
}
|
|
629
658
|
}
|
|
630
659
|
}
|
|
631
660
|
|
|
@@ -652,6 +681,7 @@ export function layout(property?: string) {
|
|
|
652
681
|
borsh.struct([], "UpdatePaddingFields"),
|
|
653
682
|
borsh.struct([], "UpdateName"),
|
|
654
683
|
borsh.struct([], "UpdateIndividualAutodeleverageMarginCallPeriodSecs"),
|
|
684
|
+
borsh.struct([], "UpdateInitialDepositAmount"),
|
|
655
685
|
])
|
|
656
686
|
if (property !== undefined) {
|
|
657
687
|
return ret.replicate(property)
|
|
@@ -156,6 +156,7 @@ export type UpdateLendingMarketModeKind =
|
|
|
156
156
|
| UpdateLendingMarketMode.UpdatePaddingFields
|
|
157
157
|
| UpdateLendingMarketMode.UpdateName
|
|
158
158
|
| UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs
|
|
159
|
+
| UpdateLendingMarketMode.UpdateInitialDepositAmount
|
|
159
160
|
export type UpdateLendingMarketModeJSON =
|
|
160
161
|
| UpdateLendingMarketMode.UpdateOwnerJSON
|
|
161
162
|
| UpdateLendingMarketMode.UpdateEmergencyModeJSON
|
|
@@ -178,6 +179,7 @@ export type UpdateLendingMarketModeJSON =
|
|
|
178
179
|
| UpdateLendingMarketMode.UpdatePaddingFieldsJSON
|
|
179
180
|
| UpdateLendingMarketMode.UpdateNameJSON
|
|
180
181
|
| UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecsJSON
|
|
182
|
+
| UpdateLendingMarketMode.UpdateInitialDepositAmountJSON
|
|
181
183
|
|
|
182
184
|
export { LastUpdate } from "./LastUpdate"
|
|
183
185
|
export type { LastUpdateFields, LastUpdateJSON } from "./LastUpdate"
|
|
@@ -48,13 +48,21 @@ export class ObligationZP {
|
|
|
48
48
|
readonly referrer: PublicKey
|
|
49
49
|
/** Marked = 1 if borrowing disabled, 0 = borrowing enabled */
|
|
50
50
|
readonly borrowingDisabled: number
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* A target LTV set by the risk council when marking this obligation for deleveraging.
|
|
53
|
+
* Only effective when `deleveraging_margin_call_started_slot != 0`.
|
|
54
|
+
* */
|
|
52
55
|
readonly autodeleverageTargetLtvPct: number
|
|
53
|
-
|
|
56
|
+
/** The lowest max LTV found amongst the collateral deposits */
|
|
57
|
+
readonly lowestReserveDepositMaxLtvPct: number
|
|
58
|
+
readonly reserved: Array<number>
|
|
54
59
|
readonly highestBorrowFactorPct: BN
|
|
55
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* A timestamp at which the risk council most-recently marked this obligation for deleveraging.
|
|
62
|
+
* Zero if not currently subject to deleveraging.
|
|
63
|
+
* */
|
|
56
64
|
readonly autodeleverageMarginCallStartedTimestamp: BN
|
|
57
|
-
padding3: Array<BN> = new Array(0)
|
|
65
|
+
readonly padding3: Array<BN> = new Array(0)
|
|
58
66
|
|
|
59
67
|
static readonly layout = borsh.struct([
|
|
60
68
|
borsh.u64("tag"),
|
|
@@ -77,7 +85,8 @@ export class ObligationZP {
|
|
|
77
85
|
borsh.publicKey("referrer"),
|
|
78
86
|
borsh.u8("borrowingDisabled"),
|
|
79
87
|
borsh.u8("autodeleverageTargetLtvPct"),
|
|
80
|
-
borsh.
|
|
88
|
+
borsh.u8("lowestReserveDepositMaxLtvPct"),
|
|
89
|
+
borsh.array(borsh.u8(), 5, "reserved"),
|
|
81
90
|
borsh.u64("highestBorrowFactorPct"),
|
|
82
91
|
borsh.u64("autodeleverageMarginCallStartedTimestamp"),
|
|
83
92
|
])
|
|
@@ -109,7 +118,8 @@ export class ObligationZP {
|
|
|
109
118
|
this.referrer = fields.referrer
|
|
110
119
|
this.borrowingDisabled = fields.borrowingDisabled
|
|
111
120
|
this.autodeleverageTargetLtvPct = fields.autodeleverageTargetLtvPct
|
|
112
|
-
this.
|
|
121
|
+
this.lowestReserveDepositMaxLtvPct = fields.lowestReserveDepositMaxLtvPct
|
|
122
|
+
this.reserved = new Array<number>(0)
|
|
113
123
|
this.highestBorrowFactorPct = fields.highestBorrowFactorPct
|
|
114
124
|
this.autodeleverageMarginCallStartedTimestamp = fields.autodeleverageMarginCallStartedTimestamp
|
|
115
125
|
this.padding3 = new Array<BN>(0);
|
|
@@ -187,10 +197,11 @@ export class ObligationZP {
|
|
|
187
197
|
referrer: dec.referrer,
|
|
188
198
|
borrowingDisabled: dec.borrowingDisabled,
|
|
189
199
|
autodeleverageTargetLtvPct: dec.autodeleverageTargetLtvPct,
|
|
200
|
+
lowestReserveDepositMaxLtvPct: dec.lowestReserveDepositMaxLtvPct,
|
|
190
201
|
reserved: dec.reserved,
|
|
191
202
|
highestBorrowFactorPct: dec.highestBorrowFactorPct,
|
|
192
203
|
autodeleverageMarginCallStartedTimestamp: dec.autodeleverageMarginCallStartedTimestamp,
|
|
193
204
|
padding3: [],
|
|
194
205
|
})
|
|
195
206
|
}
|
|
196
|
-
}
|
|
207
|
+
}
|
|
@@ -2,6 +2,7 @@ import Decimal from 'decimal.js';
|
|
|
2
2
|
import { KaminoMarket, KaminoObligation, KaminoReserve, numberToLamportsDecimal } from '../classes';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { lamportsToDecimal } from '../classes/utils';
|
|
5
|
+
import { MaxWithdrawLtvCheck, getMaxWithdrawLtvCheck } from './repay_with_collateral_operations';
|
|
5
6
|
|
|
6
7
|
export function calcRepayAmountWithSlippage(
|
|
7
8
|
kaminoMarket: KaminoMarket,
|
|
@@ -102,6 +103,7 @@ export function calcMaxWithdrawCollateral(
|
|
|
102
103
|
.filter((p) => !p.reserveAddress.equals(borrow.reserveAddress))
|
|
103
104
|
.reduce((acc, b) => acc.add(b.marketValueRefreshed), new Decimal('0'));
|
|
104
105
|
}
|
|
106
|
+
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
105
107
|
|
|
106
108
|
let remainingDepositsValueWithLtv = new Decimal('0');
|
|
107
109
|
if (obligation.getDeposits().length > 1) {
|
|
@@ -109,8 +111,13 @@ export function calcMaxWithdrawCollateral(
|
|
|
109
111
|
.getDeposits()
|
|
110
112
|
.filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
|
|
111
113
|
.reduce((acc, d) => {
|
|
112
|
-
const { maxLtv } = obligation.getLtvForReserve(
|
|
113
|
-
|
|
114
|
+
const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
|
|
115
|
+
market,
|
|
116
|
+
market.getReserveByAddress(d.reserveAddress)!
|
|
117
|
+
);
|
|
118
|
+
const maxWithdrawLtv =
|
|
119
|
+
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
|
|
120
|
+
return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
|
|
114
121
|
}, new Decimal('0'));
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -123,16 +130,18 @@ export function calcMaxWithdrawCollateral(
|
|
|
123
130
|
repayingAllDebt: repayAmountLamports.gte(borrow.amount),
|
|
124
131
|
};
|
|
125
132
|
} else {
|
|
126
|
-
const { maxLtv: collMaxLtv } = obligation.getLtvForReserve(
|
|
133
|
+
const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
|
|
127
134
|
market,
|
|
128
135
|
market.getReserveByAddress(depositReserve.address)!
|
|
129
136
|
);
|
|
137
|
+
const maxWithdrawLtv =
|
|
138
|
+
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
|
|
130
139
|
const numerator = deposit.marketValueRefreshed
|
|
131
|
-
.mul(
|
|
140
|
+
.mul(maxWithdrawLtv)
|
|
132
141
|
.add(remainingDepositsValueWithLtv)
|
|
133
142
|
.sub(remainingBorrowsValue);
|
|
134
143
|
|
|
135
|
-
const denominator = depositReserve.getOracleMarketPrice().mul(
|
|
144
|
+
const denominator = depositReserve.getOracleMarketPrice().mul(maxWithdrawLtv);
|
|
136
145
|
const maxCollWithdrawAmount = numerator.div(denominator);
|
|
137
146
|
const withdrawableCollLamports = maxCollWithdrawAmount.mul(depositReserve.getMintFactor()).floor();
|
|
138
147
|
|
|
@@ -55,6 +55,11 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
|
|
|
55
55
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
export enum MaxWithdrawLtvCheck {
|
|
59
|
+
MAX_LTV,
|
|
60
|
+
LIQUIDATION_THRESHOLD,
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
59
64
|
collTokenMint,
|
|
60
65
|
currentSlot,
|
|
@@ -207,8 +212,17 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
207
212
|
const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
|
|
208
213
|
const { inputAmountLamports: collSwapInLamports } = swapInputs;
|
|
209
214
|
|
|
210
|
-
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)
|
|
211
|
-
|
|
215
|
+
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
216
|
+
|
|
217
|
+
if (!collReserve) {
|
|
218
|
+
throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
222
|
+
|
|
223
|
+
if (!debtReserve) {
|
|
224
|
+
throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
225
|
+
}
|
|
212
226
|
|
|
213
227
|
// the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
|
|
214
228
|
// there is also a chance that the tx will consume debt token from the user's ata which they would not expect
|
|
@@ -296,8 +310,12 @@ async function buildRepayWithCollateralIxs(
|
|
|
296
310
|
|
|
297
311
|
const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
|
|
298
312
|
|
|
313
|
+
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
314
|
+
|
|
299
315
|
// 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
|
|
300
|
-
const repayAndWithdrawAction = await
|
|
316
|
+
const repayAndWithdrawAction = await (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV
|
|
317
|
+
? KaminoAction.buildRepayAndWithdrawTxns
|
|
318
|
+
: KaminoAction.buildRepayAndWithdrawV2Txns)(
|
|
301
319
|
market,
|
|
302
320
|
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
303
321
|
debtReserve.getLiquidityMint(),
|
|
@@ -310,6 +328,7 @@ async function buildRepayWithCollateralIxs(
|
|
|
310
328
|
false,
|
|
311
329
|
requestElevationGroup,
|
|
312
330
|
undefined,
|
|
331
|
+
undefined,
|
|
313
332
|
referrer,
|
|
314
333
|
scopeRefresh
|
|
315
334
|
);
|
|
@@ -328,3 +347,9 @@ async function buildRepayWithCollateralIxs(
|
|
|
328
347
|
flashRepayIxn,
|
|
329
348
|
];
|
|
330
349
|
}
|
|
350
|
+
|
|
351
|
+
export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
|
|
352
|
+
return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
|
|
353
|
+
? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
|
|
354
|
+
: MaxWithdrawLtvCheck.MAX_LTV;
|
|
355
|
+
};
|
|
@@ -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.
|
|
@@ -321,11 +320,11 @@ function getAtaCreationIxns(context: SwapCollContext<any>) {
|
|
|
321
320
|
function getAtaCloseIxns(context: SwapCollContext<any>) {
|
|
322
321
|
const ataCloseIxns: TransactionInstruction[] = [];
|
|
323
322
|
if (
|
|
324
|
-
context.sourceCollReserve.getLiquidityMint().equals(
|
|
325
|
-
context.targetCollReserve.getLiquidityMint().equals(
|
|
323
|
+
context.sourceCollReserve.getLiquidityMint().equals(NATIVE_MINT) ||
|
|
324
|
+
context.targetCollReserve.getLiquidityMint().equals(NATIVE_MINT)
|
|
326
325
|
) {
|
|
327
326
|
const owner = context.obligation.state.owner;
|
|
328
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
327
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
329
328
|
ataCloseIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
330
329
|
}
|
|
331
330
|
return ataCloseIxns;
|
|
@@ -375,6 +374,7 @@ async function getDepositTargetCollIxns(
|
|
|
375
374
|
false, // we do not need ATA ixns here (we construct and close them ourselves)
|
|
376
375
|
removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
|
|
377
376
|
false, // we are dealing with an existing obligation, no need to create user metadata
|
|
377
|
+
false, // we do not need to create a lookup table, dealing with an existing obligation
|
|
378
378
|
context.referrer,
|
|
379
379
|
context.currentSlot,
|
|
380
380
|
context.scopeRefresh,
|
|
@@ -423,6 +423,7 @@ async function getWithdrawSourceCollIxns(
|
|
|
423
423
|
false, // we do not need ATA ixns here (we construct and close them ourselves)
|
|
424
424
|
requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
|
|
425
425
|
false, // we are dealing with an existing obligation, no need to create user metadata
|
|
426
|
+
false, // we do not need to create a lookup table, dealing with an existing obligation
|
|
426
427
|
context.referrer,
|
|
427
428
|
context.currentSlot,
|
|
428
429
|
undefined, // we have refreshed scope already, during depositing
|
|
@@ -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';
|
|
@@ -89,7 +93,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
89
93
|
}> {
|
|
90
94
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
|
|
91
95
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
|
|
92
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
96
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
93
97
|
const flashLoanFee = collReserve.getFlashLoanFee() || new Decimal(0);
|
|
94
98
|
|
|
95
99
|
const selectedTokenIsCollToken = selectedTokenMint.equals(collTokenMint);
|
|
@@ -191,7 +195,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
191
195
|
|
|
192
196
|
if (collIsKtoken) {
|
|
193
197
|
let futureBalanceInAta = new Decimal(0);
|
|
194
|
-
if (debtTokenMint.equals(
|
|
198
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
195
199
|
futureBalanceInAta = futureBalanceInAta.add(
|
|
196
200
|
!collIsKtoken ? quotePriceCalcs.initDepositInSol : quotePriceCalcs.initDepositInSol
|
|
197
201
|
);
|
|
@@ -366,7 +370,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
|
|
|
366
370
|
|
|
367
371
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
368
372
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
369
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
373
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
370
374
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
371
375
|
|
|
372
376
|
const ixs = await buildDepositWithLeverageIxns(
|
|
@@ -485,9 +489,9 @@ async function buildDepositWithLeverageIxns(
|
|
|
485
489
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
486
490
|
if (depositTokenIsSol) {
|
|
487
491
|
fillWsolAtaIxns.push(
|
|
488
|
-
...
|
|
492
|
+
...getTransferWsolIxns(
|
|
489
493
|
owner,
|
|
490
|
-
getAssociatedTokenAddressSync(
|
|
494
|
+
getAssociatedTokenAddressSync(NATIVE_MINT, owner),
|
|
491
495
|
toLamports(calcs.initDepositInSol, SOL_DECIMALS).ceil()
|
|
492
496
|
)
|
|
493
497
|
);
|
|
@@ -530,6 +534,7 @@ async function buildDepositWithLeverageIxns(
|
|
|
530
534
|
false,
|
|
531
535
|
elevationGroupOverride === 0 ? false : true, // emode
|
|
532
536
|
false, // to be checked and created in a setup tx in the UI
|
|
537
|
+
false, // to be checked and created in a setup tx in the UI
|
|
533
538
|
referrer,
|
|
534
539
|
currentSlot,
|
|
535
540
|
scopeRefresh
|
|
@@ -598,7 +603,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
598
603
|
const collIsKtoken = await isKtoken(collTokenMint);
|
|
599
604
|
const strategy = collIsKtoken ? (await kamino!.getStrategyByKTokenMint(collTokenMint))! : undefined;
|
|
600
605
|
|
|
601
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
606
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
602
607
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
603
608
|
|
|
604
609
|
const calcs = withdrawLeverageCalcs(
|
|
@@ -724,7 +729,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
|
|
|
724
729
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
725
730
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
726
731
|
|
|
727
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
732
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
728
733
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
729
734
|
const { swapInputs, initialInputs } = await getWithdrawWithLeverageSwapInputs({
|
|
730
735
|
owner,
|
|
@@ -885,8 +890,8 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
885
890
|
const atasAndCreateIxns = createAtasIdempotent(owner, mintsToCreateAtas);
|
|
886
891
|
|
|
887
892
|
const closeWsolAtaIxns: TransactionInstruction[] = [];
|
|
888
|
-
if (depositTokenIsSol || debtTokenMint.equals(
|
|
889
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
893
|
+
if (depositTokenIsSol || debtTokenMint.equals(NATIVE_MINT)) {
|
|
894
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
890
895
|
closeWsolAtaIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
891
896
|
}
|
|
892
897
|
|
|
@@ -895,13 +900,13 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
895
900
|
// TODO: Might be worth removing as it's only needed for Ktokens
|
|
896
901
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
897
902
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
898
|
-
if (debtTokenMint.equals(
|
|
903
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
899
904
|
const halfSolBalance = (await market.getConnection().getBalance(owner)) / LAMPORTS_PER_SOL / 2;
|
|
900
905
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
901
906
|
fillWsolAtaIxns.push(
|
|
902
|
-
...
|
|
907
|
+
...getTransferWsolIxns(
|
|
903
908
|
owner,
|
|
904
|
-
getAssociatedTokenAddressSync(
|
|
909
|
+
getAssociatedTokenAddressSync(NATIVE_MINT, owner),
|
|
905
910
|
toLamports(balanceToWrap, SOL_DECIMALS).ceil()
|
|
906
911
|
)
|
|
907
912
|
);
|
|
@@ -939,6 +944,7 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
939
944
|
0,
|
|
940
945
|
false,
|
|
941
946
|
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)
|
|
947
|
+
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)
|
|
942
948
|
isClosingPosition,
|
|
943
949
|
referrer,
|
|
944
950
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1473,6 +1479,7 @@ async function buildIncreaseLeverageIxns(
|
|
|
1473
1479
|
false,
|
|
1474
1480
|
false,
|
|
1475
1481
|
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)
|
|
1482
|
+
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)
|
|
1476
1483
|
referrer,
|
|
1477
1484
|
currentSlot,
|
|
1478
1485
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1489,6 +1496,7 @@ async function buildIncreaseLeverageIxns(
|
|
|
1489
1496
|
false,
|
|
1490
1497
|
false,
|
|
1491
1498
|
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
|
+
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)
|
|
1492
1500
|
referrer,
|
|
1493
1501
|
currentSlot,
|
|
1494
1502
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1608,15 +1616,15 @@ async function buildDecreaseLeverageIxns(
|
|
|
1608
1616
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
1609
1617
|
const closeWsolAtaIxns: TransactionInstruction[] = [];
|
|
1610
1618
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
1611
|
-
if (debtTokenMint.equals(
|
|
1612
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
1619
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
1620
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
1613
1621
|
|
|
1614
1622
|
closeWsolAtaIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
1615
1623
|
|
|
1616
1624
|
const halfSolBalance = (await kaminoMarket.getConnection().getBalance(owner)) / LAMPORTS_PER_SOL / 2;
|
|
1617
1625
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
1618
1626
|
fillWsolAtaIxns.push(
|
|
1619
|
-
...
|
|
1627
|
+
...getTransferWsolIxns(owner, wsolAta, toLamports(balanceToWrap, debtReserve!.stats.decimals).ceil())
|
|
1620
1628
|
);
|
|
1621
1629
|
}
|
|
1622
1630
|
|
|
@@ -1649,6 +1657,7 @@ async function buildDecreaseLeverageIxns(
|
|
|
1649
1657
|
false,
|
|
1650
1658
|
false,
|
|
1651
1659
|
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)
|
|
1660
|
+
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)
|
|
1652
1661
|
referrer,
|
|
1653
1662
|
scopeRefresh
|
|
1654
1663
|
);
|
|
@@ -1664,6 +1673,7 @@ async function buildDecreaseLeverageIxns(
|
|
|
1664
1673
|
false,
|
|
1665
1674
|
false,
|
|
1666
1675
|
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)
|
|
1676
|
+
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)
|
|
1667
1677
|
referrer,
|
|
1668
1678
|
currentSlot,
|
|
1669
1679
|
{ 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(
|