@kamino-finance/klend-sdk 5.13.9 → 5.13.11
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.map +1 -1
- package/dist/classes/action.js +0 -1
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +7 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +12 -3
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +4 -0
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +8 -2
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +8 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +31 -2
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +10 -0
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +5 -5
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +9 -9
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +8 -8
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +25 -25
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/instructions.d.ts +5 -5
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +6 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +5 -0
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +131 -304
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +35 -57
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +1 -1
- package/dist/leverage/utils.js +5 -5
- package/dist/leverage/utils.js.map +1 -1
- package/dist/utils/ata.d.ts +0 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +0 -14
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +10 -0
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/vault.d.ts +3 -0
- package/dist/utils/vault.d.ts.map +1 -0
- package/dist/utils/vault.js +50 -0
- package/dist/utils/vault.js.map +1 -0
- package/package.json +1 -1
- package/src/classes/action.ts +0 -1
- package/src/classes/manager.ts +13 -3
- package/src/classes/reserve.ts +9 -2
- package/src/classes/vault.ts +34 -2
- package/src/client_kamino_manager.ts +12 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +1 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +6 -6
- package/src/lending_operations/swap_collateral_operations.ts +22 -24
- package/src/leverage/calcs.ts +26 -26
- package/src/leverage/instructions.ts +8 -8
- package/src/leverage/operations.ts +232 -325
- package/src/leverage/types.ts +38 -67
- package/src/leverage/utils.ts +5 -5
- package/src/utils/ata.ts +1 -26
- package/src/utils/instruction.ts +12 -0
- package/src/utils/vault.ts +51 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;AAwBA,0DAuCC;AAED,0CAWC;AAED,gFA6BC;AAED,kCAkBC;AAED,oDAEC;AAUD,8CAsBC;AAED,sDAqBC;AA6BD,wDAmBC;AAkBD,4BAQC;AAED,oEAoBC;
|
|
1
|
+
{"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;AAwBA,0DAuCC;AAED,0CAWC;AAED,gFA6BC;AAED,kCAkBC;AAED,oDAEC;AAUD,8CAsBC;AAED,sDAq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CAAC;QACjC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACtB,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC,OAAO,EAAE,CAAC;AAClC,CAAC;AAED,SAAgB,eAAe,CAAC,GAA6B;IAC3D,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QACvB,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;QAEzB,IAAI,SAAS,CAAC,MAAM,CAAC,8BAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../src/utils/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC;AAG7E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CA+CzD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeVaultState = decodeVaultState;
|
|
4
|
+
const VaultState_1 = require("../idl_codegen_kamino_vault/accounts/VaultState");
|
|
5
|
+
const VaultAllocation_1 = require("../idl_codegen_kamino_vault/types/VaultAllocation");
|
|
6
|
+
function decodeVaultState(data) {
|
|
7
|
+
if (!VaultState_1.VaultState.discriminator.equals(data.slice(0, 8))) {
|
|
8
|
+
throw new Error('invalid account discriminator');
|
|
9
|
+
}
|
|
10
|
+
const dec = VaultState_1.VaultState.layout.decode(data.slice(8));
|
|
11
|
+
return new VaultState_1.VaultState({
|
|
12
|
+
vaultAdminAuthority: dec.vaultAdminAuthority,
|
|
13
|
+
baseVaultAuthority: dec.baseVaultAuthority,
|
|
14
|
+
baseVaultAuthorityBump: dec.baseVaultAuthorityBump,
|
|
15
|
+
tokenMint: dec.tokenMint,
|
|
16
|
+
tokenMintDecimals: dec.tokenMintDecimals,
|
|
17
|
+
tokenVault: dec.tokenVault,
|
|
18
|
+
tokenProgram: dec.tokenProgram,
|
|
19
|
+
sharesMint: dec.sharesMint,
|
|
20
|
+
sharesMintDecimals: dec.sharesMintDecimals,
|
|
21
|
+
tokenAvailable: dec.tokenAvailable,
|
|
22
|
+
sharesIssued: dec.sharesIssued,
|
|
23
|
+
availableCrankFunds: dec.availableCrankFunds,
|
|
24
|
+
padding0: dec.padding0,
|
|
25
|
+
performanceFeeBps: dec.performanceFeeBps,
|
|
26
|
+
managementFeeBps: dec.managementFeeBps,
|
|
27
|
+
lastFeeChargeTimestamp: dec.lastFeeChargeTimestamp,
|
|
28
|
+
prevAumSf: dec.prevAumSf,
|
|
29
|
+
pendingFeesSf: dec.pendingFeesSf,
|
|
30
|
+
vaultAllocationStrategy: dec.vaultAllocationStrategy.map((item /* eslint-disable-line @typescript-eslint/no-explicit-any */) => VaultAllocation_1.VaultAllocation.fromDecoded(item)),
|
|
31
|
+
padding1: dec.padding1,
|
|
32
|
+
minDepositAmount: dec.minDepositAmount,
|
|
33
|
+
minWithdrawAmount: dec.minWithdrawAmount,
|
|
34
|
+
minInvestAmount: dec.minInvestAmount,
|
|
35
|
+
minInvestDelaySlots: dec.minInvestDelaySlots,
|
|
36
|
+
crankFundFeePerReserve: dec.crankFundFeePerReserve,
|
|
37
|
+
pendingAdmin: dec.pendingAdmin,
|
|
38
|
+
cumulativeEarnedInterestSf: dec.cumulativeEarnedInterestSf,
|
|
39
|
+
cumulativeMgmtFeesSf: dec.cumulativeMgmtFeesSf,
|
|
40
|
+
cumulativePerfFeesSf: dec.cumulativePerfFeesSf,
|
|
41
|
+
name: dec.name,
|
|
42
|
+
vaultLookupTable: dec.vaultLookupTable,
|
|
43
|
+
vaultFarm: dec.vaultFarm,
|
|
44
|
+
creationTimestamp: dec.creationTimestamp,
|
|
45
|
+
padding2: dec.padding2,
|
|
46
|
+
allocationAdmin: dec.allocationAdmin,
|
|
47
|
+
padding3: dec.padding3,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=vault.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../../src/utils/vault.ts"],"names":[],"mappings":";;AAGA,4CA+CC;AAlDD,gFAA6E;AAC7E,uFAAoF;AAEpF,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC,uBAAU,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,GAAG,GAAG,uBAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,OAAO,IAAI,uBAAU,CAAC;QACpB,mBAAmB,EAAE,GAAG,CAAC,mBAAmB;QAC5C,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,sBAAsB,EAAE,GAAG,CAAC,sBAAsB;QAClD,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,cAAc,EAAE,GAAG,CAAC,cAAc;QAClC,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,mBAAmB,EAAE,GAAG,CAAC,mBAAmB;QAC5C,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;QACtC,sBAAsB,EAAE,GAAG,CAAC,sBAAsB;QAClD,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,uBAAuB,EAAE,GAAG,CAAC,uBAAuB,CAAC,GAAG,CACtD,CAAC,IAAS,CAAC,4DAA4D,EAAE,EAAE,CAAC,iCAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAC9G;QACD,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;QACtC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,mBAAmB,EAAE,GAAG,CAAC,mBAAmB;QAC5C,sBAAsB,EAAE,GAAG,CAAC,sBAAsB;QAClD,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,0BAA0B,EAAE,GAAG,CAAC,0BAA0B;QAC1D,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;QAC9C,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;QAC9C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;QACtC,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACvB,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/classes/action.ts
CHANGED
package/src/classes/manager.ts
CHANGED
|
@@ -95,6 +95,7 @@ import {
|
|
|
95
95
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
96
96
|
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
97
97
|
import { getSquadsMultisigAdminsAndThreshold, walletIsSquadsMultisig, WalletType } from '../utils/multisig';
|
|
98
|
+
import { decodeVaultState } from '../utils/vault';
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
|
|
@@ -279,12 +280,12 @@ export class KaminoManager {
|
|
|
279
280
|
* @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
|
|
280
281
|
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
|
|
281
282
|
*/
|
|
282
|
-
async
|
|
283
|
+
async withdrawEverythingAndBlockInvestReserve(
|
|
283
284
|
vault: KaminoVault,
|
|
284
285
|
reserve: PublicKey,
|
|
285
286
|
payer?: PublicKey
|
|
286
287
|
): Promise<WithdrawAndBlockReserveIxs> {
|
|
287
|
-
return this._vaultClient.
|
|
288
|
+
return this._vaultClient.withdrawEverythingAndBlockInvestReserve(vault, reserve, payer);
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
/**
|
|
@@ -761,7 +762,7 @@ export class KaminoManager {
|
|
|
761
762
|
throw new Error(`kaminoVault with pubkey ${kaminoVault.pubkey.toString()} does not exist`);
|
|
762
763
|
}
|
|
763
764
|
|
|
764
|
-
const kaminoVaultAccount =
|
|
765
|
+
const kaminoVaultAccount = decodeVaultState(kaminoVault.account.data);
|
|
765
766
|
if (!kaminoVaultAccount) {
|
|
766
767
|
throw Error(`kaminoVault with pubkey ${kaminoVault.pubkey.toString()} could not be decoded`);
|
|
767
768
|
}
|
|
@@ -826,6 +827,15 @@ export class KaminoManager {
|
|
|
826
827
|
return result;
|
|
827
828
|
};
|
|
828
829
|
|
|
830
|
+
/**
|
|
831
|
+
* Get all vaults for a given token
|
|
832
|
+
* @param token - the token to get all vaults for
|
|
833
|
+
* @returns an array of all vaults for the given token
|
|
834
|
+
*/
|
|
835
|
+
async getAllVaultsForToken(token: PublicKey): Promise<Array<KaminoVault>> {
|
|
836
|
+
return this._vaultClient.getAllVaultsForToken(token);
|
|
837
|
+
}
|
|
838
|
+
|
|
829
839
|
/**
|
|
830
840
|
* This will return an VaultHoldings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
|
|
831
841
|
* @param vault - the kamino vault to get available liquidity to withdraw for
|
package/src/classes/reserve.ts
CHANGED
|
@@ -276,7 +276,14 @@ export class KaminoReserve {
|
|
|
276
276
|
* @returns 10^mint_decimals
|
|
277
277
|
*/
|
|
278
278
|
getMintFactor(): Decimal {
|
|
279
|
-
return new Decimal(10).pow(this.
|
|
279
|
+
return new Decimal(10).pow(this.getMintDecimals());
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @returns mint_decimals of the liquidity token
|
|
284
|
+
*/
|
|
285
|
+
getMintDecimals(): number {
|
|
286
|
+
return this.state.liquidity.mintDecimals.toNumber();
|
|
280
287
|
}
|
|
281
288
|
|
|
282
289
|
/**
|
|
@@ -875,7 +882,7 @@ export class KaminoReserve {
|
|
|
875
882
|
|
|
876
883
|
// Reserve info
|
|
877
884
|
symbol: parseTokenSymbol(parsedData.config.tokenInfo.name),
|
|
878
|
-
decimals: this.
|
|
885
|
+
decimals: this.getMintDecimals(),
|
|
879
886
|
accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),
|
|
880
887
|
mintTotalSupply,
|
|
881
888
|
depositLimitCrossedTimestamp: parsedData.liquidity.depositLimitCrossedTimestamp.toNumber(),
|
package/src/classes/vault.ts
CHANGED
|
@@ -104,6 +104,7 @@ import {
|
|
|
104
104
|
getUserSharesInFarm,
|
|
105
105
|
} from './farm_utils';
|
|
106
106
|
import { getInitializeKVaultSharesMetadataIx, getUpdateSharesMetadataIx, resolveMetadata } from '../utils/metadata';
|
|
107
|
+
import { decodeVaultState } from '../utils/vault';
|
|
107
108
|
|
|
108
109
|
export const kaminoVaultId = new PublicKey('KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd');
|
|
109
110
|
export const kaminoVaultStagingId = new PublicKey('stKvQfwRsQiKnLtMNVLHKS3exFJmZFsgfzBPWHECUYK');
|
|
@@ -451,7 +452,7 @@ export class KaminoVaultClient {
|
|
|
451
452
|
* @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
|
|
452
453
|
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
|
|
453
454
|
*/
|
|
454
|
-
async
|
|
455
|
+
async withdrawEverythingAndBlockInvestReserve(
|
|
455
456
|
vault: KaminoVault,
|
|
456
457
|
reserve: PublicKey,
|
|
457
458
|
payer?: PublicKey
|
|
@@ -1997,6 +1998,37 @@ export class KaminoVaultClient {
|
|
|
1997
1998
|
},
|
|
1998
1999
|
];
|
|
1999
2000
|
|
|
2001
|
+
return await this.getAllVaultsWithFilter(filters);
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* Get all vaults for a given token
|
|
2006
|
+
* @param token - the token to get all vaults for
|
|
2007
|
+
* @returns an array of all vaults for the given token
|
|
2008
|
+
*/
|
|
2009
|
+
async getAllVaultsForToken(token: PublicKey): Promise<Array<KaminoVault>> {
|
|
2010
|
+
const filters = [
|
|
2011
|
+
{
|
|
2012
|
+
dataSize: VaultState.layout.span + 8,
|
|
2013
|
+
},
|
|
2014
|
+
{
|
|
2015
|
+
memcmp: {
|
|
2016
|
+
offset: 0,
|
|
2017
|
+
bytes: bs58.encode(VaultState.discriminator),
|
|
2018
|
+
},
|
|
2019
|
+
},
|
|
2020
|
+
{
|
|
2021
|
+
memcmp: {
|
|
2022
|
+
offset: 80, // tokenMint offset: 8 + 32 + 32 + 8 (discriminator + vaultAdminAuthority + baseVaultAuthority + baseVaultAuthorityBump)
|
|
2023
|
+
bytes: token.toBase58(),
|
|
2024
|
+
},
|
|
2025
|
+
},
|
|
2026
|
+
];
|
|
2027
|
+
|
|
2028
|
+
return await this.getAllVaultsWithFilter(filters);
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
private async getAllVaultsWithFilter(filters: any): Promise<Array<KaminoVault>> {
|
|
2000
2032
|
const kaminoVaults: GetProgramAccountsResponse = await getProgramAccounts(
|
|
2001
2033
|
this.getConnection(),
|
|
2002
2034
|
this._kaminoVaultProgramId,
|
|
@@ -2012,7 +2044,7 @@ export class KaminoVaultClient {
|
|
|
2012
2044
|
throw new Error(`kaminoVault with pubkey ${kaminoVault.pubkey.toString()} does not exist`);
|
|
2013
2045
|
}
|
|
2014
2046
|
|
|
2015
|
-
const kaminoVaultAccount =
|
|
2047
|
+
const kaminoVaultAccount = decodeVaultState(kaminoVault.account.data);
|
|
2016
2048
|
if (!kaminoVaultAccount) {
|
|
2017
2049
|
throw Error(`kaminoVault with pubkey ${kaminoVault.pubkey.toString()} could not be decoded`);
|
|
2018
2050
|
}
|
|
@@ -1163,6 +1163,18 @@ async function main() {
|
|
|
1163
1163
|
console.log('all vaults', allVaults);
|
|
1164
1164
|
});
|
|
1165
1165
|
|
|
1166
|
+
commands
|
|
1167
|
+
.command('get-all-vaults-for-token')
|
|
1168
|
+
.requiredOption('--token <string>', 'Token address')
|
|
1169
|
+
.action(async ({ token }) => {
|
|
1170
|
+
const env = initializeClient(false, false);
|
|
1171
|
+
const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
|
|
1172
|
+
|
|
1173
|
+
const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
|
|
1174
|
+
const allVaults = await kaminoManager.getAllVaultsForToken(new PublicKey(token));
|
|
1175
|
+
console.log('all vaults for token ', token, allVaults);
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1166
1178
|
commands.command('get-all-vaults-pks').action(async () => {
|
|
1167
1179
|
const env = initializeClient(false, false);
|
|
1168
1180
|
const kaminoManager = new KaminoManager(
|
|
@@ -241,7 +241,7 @@ export class VaultState {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
static decode(data: Buffer): VaultState {
|
|
244
|
-
if (!data.slice(0, 8)
|
|
244
|
+
if (!VaultState.discriminator.equals(data.slice(0, 8))) {
|
|
245
245
|
throw new Error("invalid account discriminator")
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
createAtasIdempotent,
|
|
15
15
|
getComputeBudgetAndPriorityFeeIxs,
|
|
16
|
-
|
|
16
|
+
removeBudgetIxs,
|
|
17
17
|
ScopePriceRefreshConfig,
|
|
18
18
|
U64_MAX,
|
|
19
19
|
uniqueAccountsWithProgramIds,
|
|
@@ -289,8 +289,8 @@ async function buildRepayWithCollateralIxs(
|
|
|
289
289
|
const scopeRefreshIxn = await getScopeRefreshIx(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
290
290
|
|
|
291
291
|
// 2. Flash borrow & repay the debt to repay amount needed
|
|
292
|
-
const {
|
|
293
|
-
|
|
292
|
+
const { flashBorrowIx, flashRepayIx } = getFlashLoanInstructions({
|
|
293
|
+
borrowIxIndex: budgetIxs.length + atasAndIxs.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
|
|
294
294
|
walletPublicKey: obligation.state.owner,
|
|
295
295
|
lendingMarketAuthority: market.getLendingMarketAuthority(),
|
|
296
296
|
lendingMarketAddress: market.getAddress(),
|
|
@@ -354,17 +354,17 @@ async function buildRepayWithCollateralIxs(
|
|
|
354
354
|
|
|
355
355
|
// 4. Swap collateral to debt to repay flash loan
|
|
356
356
|
const { preActionIxs, swapIxs } = swapQuoteIxs;
|
|
357
|
-
const swapInstructions =
|
|
357
|
+
const swapInstructions = removeBudgetIxs(swapIxs);
|
|
358
358
|
|
|
359
359
|
const ixs = [
|
|
360
360
|
...scopeRefreshIxn,
|
|
361
361
|
...budgetIxs,
|
|
362
362
|
...atasAndIxs.map((x) => x.createAtaIx),
|
|
363
|
-
|
|
363
|
+
flashBorrowIx,
|
|
364
364
|
...preActionIxs,
|
|
365
365
|
...KaminoAction.actionToIxs(repayAndWithdrawAction),
|
|
366
366
|
...swapInstructions,
|
|
367
|
-
|
|
367
|
+
flashRepayIx,
|
|
368
368
|
];
|
|
369
369
|
|
|
370
370
|
const res: LeverageIxsOutput = {
|
|
@@ -252,10 +252,10 @@ const FAKE_TARGET_COLL_SWAP_OUT_AMOUNT = new Decimal(1); // see the lengthy `get
|
|
|
252
252
|
|
|
253
253
|
type SwapCollKlendIxs = {
|
|
254
254
|
setupIxs: TransactionInstruction[];
|
|
255
|
-
|
|
255
|
+
targetCollFlashBorrowIx: TransactionInstruction;
|
|
256
256
|
depositTargetCollIxs: TransactionInstruction[];
|
|
257
257
|
withdrawSourceCollIxs: TransactionInstruction[];
|
|
258
|
-
|
|
258
|
+
targetCollFlashRepayIx: TransactionInstruction;
|
|
259
259
|
cleanupIxs: TransactionInstruction[];
|
|
260
260
|
flashLoanInfo: FlashLoanInfo;
|
|
261
261
|
simulationDetails: {
|
|
@@ -284,7 +284,7 @@ async function getKlendIxs(
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
const targetCollFlashBorrowedAmount = calculateTargetCollFlashBorrowedAmount(targetCollSwapOutAmount, context);
|
|
287
|
-
const {
|
|
287
|
+
const { targetCollFlashBorrowIx, targetCollFlashRepayIx } = getTargetCollFlashLoanIxs(
|
|
288
288
|
targetCollFlashBorrowedAmount,
|
|
289
289
|
setupIxs.length,
|
|
290
290
|
targetCollAta,
|
|
@@ -306,10 +306,10 @@ async function getKlendIxs(
|
|
|
306
306
|
flashBorrowReserve: context.targetCollReserve.address,
|
|
307
307
|
flashLoanFee: context.targetCollReserve.getFlashLoanFee(),
|
|
308
308
|
},
|
|
309
|
-
|
|
309
|
+
targetCollFlashBorrowIx,
|
|
310
310
|
depositTargetCollIxs: depositTargetCollIxs.ixs,
|
|
311
311
|
withdrawSourceCollIxs,
|
|
312
|
-
|
|
312
|
+
targetCollFlashRepayIx,
|
|
313
313
|
cleanupIxs,
|
|
314
314
|
simulationDetails: {
|
|
315
315
|
targetCollFlashBorrowedAmount,
|
|
@@ -364,26 +364,24 @@ function getAtaCloseIxs(context: SwapCollContext<any>) {
|
|
|
364
364
|
|
|
365
365
|
function getTargetCollFlashLoanIxs(
|
|
366
366
|
targetCollAmount: Decimal,
|
|
367
|
-
|
|
367
|
+
flashBorrowIxIndex: number,
|
|
368
368
|
destinationAta: PublicKey,
|
|
369
369
|
context: SwapCollContext<any>
|
|
370
370
|
) {
|
|
371
|
-
const {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
);
|
|
386
|
-
return { targetCollFlashBorrowIxn, targetCollFlashRepayIxn };
|
|
371
|
+
const { flashBorrowIx: targetCollFlashBorrowIx, flashRepayIx: targetCollFlashRepayIx } = getFlashLoanInstructions({
|
|
372
|
+
borrowIxIndex: flashBorrowIxIndex,
|
|
373
|
+
walletPublicKey: context.obligation.state.owner,
|
|
374
|
+
lendingMarketAuthority: context.market.getLendingMarketAuthority(),
|
|
375
|
+
lendingMarketAddress: context.market.getAddress(),
|
|
376
|
+
reserve: context.targetCollReserve,
|
|
377
|
+
amountLamports: targetCollAmount.mul(context.targetCollReserve.getMintFactor()),
|
|
378
|
+
destinationAta,
|
|
379
|
+
// TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
|
|
380
|
+
referrerAccount: context.market.programId,
|
|
381
|
+
referrerTokenState: context.market.programId,
|
|
382
|
+
programId: context.market.programId,
|
|
383
|
+
});
|
|
384
|
+
return { targetCollFlashBorrowIx, targetCollFlashRepayIx };
|
|
387
385
|
}
|
|
388
386
|
|
|
389
387
|
type DepositTargetCollIxs = {
|
|
@@ -609,11 +607,11 @@ function checkResultingObligationValid(
|
|
|
609
607
|
function listIxs(klendIxs: SwapCollKlendIxs, externalSwapIxs?: TransactionInstruction[]): TransactionInstruction[] {
|
|
610
608
|
return [
|
|
611
609
|
...klendIxs.setupIxs,
|
|
612
|
-
klendIxs.
|
|
610
|
+
klendIxs.targetCollFlashBorrowIx,
|
|
613
611
|
...klendIxs.depositTargetCollIxs,
|
|
614
612
|
...klendIxs.withdrawSourceCollIxs,
|
|
615
613
|
...(externalSwapIxs || []),
|
|
616
|
-
klendIxs.
|
|
614
|
+
klendIxs.targetCollFlashRepayIx,
|
|
617
615
|
...klendIxs.cleanupIxs,
|
|
618
616
|
];
|
|
619
617
|
}
|
package/src/leverage/calcs.ts
CHANGED
|
@@ -13,14 +13,14 @@ import { fuzzyEqual } from '../utils';
|
|
|
13
13
|
|
|
14
14
|
const closingPositionDiffTolerance = 0.0001;
|
|
15
15
|
|
|
16
|
-
export enum
|
|
16
|
+
export enum LeverageOption {
|
|
17
17
|
deposit = 'Deposit',
|
|
18
18
|
withdraw = 'Withdraw',
|
|
19
19
|
adjust = 'Adjust',
|
|
20
20
|
close = 'Close',
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export interface
|
|
23
|
+
export interface LeverageCalcsArgs {
|
|
24
24
|
depositAmount: Decimal;
|
|
25
25
|
withdrawAmount: Decimal;
|
|
26
26
|
deposited: Decimal;
|
|
@@ -29,14 +29,14 @@ export interface LeverageFormsCalcsArgs {
|
|
|
29
29
|
selectedTokenMint: PublicKey;
|
|
30
30
|
collTokenMint: PublicKey;
|
|
31
31
|
targetLeverage: Decimal;
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
activeLeverageOption: LeverageOption;
|
|
33
|
+
flashLoanFeeRatio: Decimal;
|
|
34
34
|
debtBorrowFactorPct: Decimal;
|
|
35
35
|
priceCollToDebt: Decimal;
|
|
36
36
|
priceDebtToColl: Decimal;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface
|
|
39
|
+
export interface LeverageCalcsResult {
|
|
40
40
|
earned: Decimal;
|
|
41
41
|
totalDeposited: Decimal;
|
|
42
42
|
totalBorrowed: Decimal;
|
|
@@ -56,14 +56,14 @@ export async function calculateMultiplyEffects(
|
|
|
56
56
|
selectedTokenMint,
|
|
57
57
|
collTokenMint,
|
|
58
58
|
targetLeverage,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
activeLeverageOption,
|
|
60
|
+
flashLoanFeeRatio,
|
|
61
61
|
debtBorrowFactorPct,
|
|
62
62
|
priceCollToDebt,
|
|
63
63
|
priceDebtToColl,
|
|
64
|
-
}:
|
|
64
|
+
}: LeverageCalcsArgs,
|
|
65
65
|
logEstimations = false
|
|
66
|
-
): Promise<
|
|
66
|
+
): Promise<LeverageCalcsResult> {
|
|
67
67
|
// calculate estimations for deposit operation
|
|
68
68
|
const {
|
|
69
69
|
adjustDepositPosition: depositModeEstimatedDepositAmount,
|
|
@@ -75,7 +75,7 @@ export async function calculateMultiplyEffects(
|
|
|
75
75
|
targetLeverage,
|
|
76
76
|
selectedTokenMint,
|
|
77
77
|
collTokenMint: collTokenMint,
|
|
78
|
-
flashLoanFee:
|
|
78
|
+
flashLoanFee: flashLoanFeeRatio,
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
// calculate estimations for withdraw operation
|
|
@@ -101,14 +101,14 @@ export async function calculateMultiplyEffects(
|
|
|
101
101
|
collTokenMint,
|
|
102
102
|
totalDeposited: new Decimal(deposited),
|
|
103
103
|
totalBorrowed: new Decimal(borrowed),
|
|
104
|
-
flashLoanFee:
|
|
104
|
+
flashLoanFee: flashLoanFeeRatio, // TODO: is this the right flash borrow?
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
if (logEstimations) {
|
|
108
108
|
console.log(
|
|
109
109
|
'Estimations',
|
|
110
110
|
toJson({
|
|
111
|
-
|
|
111
|
+
activeLeverageOption,
|
|
112
112
|
depositModeEstimatedDepositAmount,
|
|
113
113
|
depositModeEstimatedBorrowAmount,
|
|
114
114
|
withdrawModeEstimatedDepositTokenWithdrawn,
|
|
@@ -121,16 +121,16 @@ export async function calculateMultiplyEffects(
|
|
|
121
121
|
|
|
122
122
|
let [isClosingPosition, totalDeposited, totalBorrowed] = [false, new Decimal(0), new Decimal(0)];
|
|
123
123
|
|
|
124
|
-
switch (
|
|
125
|
-
case
|
|
124
|
+
switch (activeLeverageOption) {
|
|
125
|
+
case LeverageOption.deposit: {
|
|
126
126
|
// Deposit and Adjust never clos the position
|
|
127
127
|
isClosingPosition = false;
|
|
128
128
|
totalDeposited = deposited.add(depositModeEstimatedDepositAmount);
|
|
129
129
|
totalBorrowed = borrowed.add(depositModeEstimatedBorrowAmount);
|
|
130
130
|
break;
|
|
131
131
|
}
|
|
132
|
-
case
|
|
133
|
-
case
|
|
132
|
+
case LeverageOption.close:
|
|
133
|
+
case LeverageOption.withdraw: {
|
|
134
134
|
isClosingPosition =
|
|
135
135
|
(withdrawModeEstimatedDepositTokenWithdrawn.gte(new Decimal(deposited)) ||
|
|
136
136
|
withdrawModeEstimatedBorrowTokenWithdrawn.gte(new Decimal(borrowed)) ||
|
|
@@ -146,7 +146,7 @@ export async function calculateMultiplyEffects(
|
|
|
146
146
|
totalBorrowed = isClosingPosition ? new Decimal(0) : borrowed.sub(withdrawModeEstimatedBorrowTokenWithdrawn);
|
|
147
147
|
break;
|
|
148
148
|
}
|
|
149
|
-
case
|
|
149
|
+
case LeverageOption.adjust: {
|
|
150
150
|
// Deposit and Adjust never clos the position
|
|
151
151
|
isClosingPosition = false;
|
|
152
152
|
totalDeposited = deposited.add(adjustModeEstimatedDepositAmount);
|
|
@@ -186,12 +186,12 @@ export const calcBorrowAmount = ({
|
|
|
186
186
|
depositTokenAmount,
|
|
187
187
|
targetLeverage,
|
|
188
188
|
priceCollToDebt,
|
|
189
|
-
|
|
189
|
+
flashLoanFeeRatio,
|
|
190
190
|
}: {
|
|
191
191
|
depositTokenAmount: Decimal;
|
|
192
192
|
targetLeverage: Decimal;
|
|
193
193
|
priceCollToDebt: Decimal;
|
|
194
|
-
|
|
194
|
+
flashLoanFeeRatio: Decimal;
|
|
195
195
|
}) => {
|
|
196
196
|
const initialCollAmountInCollToken = depositTokenAmount;
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ export const calcBorrowAmount = ({
|
|
|
199
199
|
const finalDebtAmountInCollToken = finalCollAmountInCollToken.sub(initialCollAmountInCollToken);
|
|
200
200
|
const finalDebtAmountInDebtToken = finalDebtAmountInCollToken.mul(priceCollToDebt);
|
|
201
201
|
|
|
202
|
-
const flashFeeFactor = new Decimal(1).add(
|
|
202
|
+
const flashFeeFactor = new Decimal(1).add(flashLoanFeeRatio);
|
|
203
203
|
const debtTokenToBorrow = finalDebtAmountInDebtToken.mul(flashFeeFactor);
|
|
204
204
|
|
|
205
205
|
return debtTokenToBorrow;
|
|
@@ -269,7 +269,7 @@ export function calcWithdrawAmounts(params: WithdrawParams): WithdrawResult {
|
|
|
269
269
|
depositTokenAmount: initialDepositInCollateralToken.minus(amountToWithdrawDepositToken),
|
|
270
270
|
priceCollToDebt: new Decimal(priceCollToDebt),
|
|
271
271
|
targetLeverage: new Decimal(targetLeverage),
|
|
272
|
-
|
|
272
|
+
flashLoanFeeRatio: new Decimal(0),
|
|
273
273
|
});
|
|
274
274
|
|
|
275
275
|
const adjustDepositPosition = currentDepositPosition.minus(targetDeposit);
|
|
@@ -347,7 +347,7 @@ export function calcAdjustAmounts({
|
|
|
347
347
|
depositTokenAmount: initialDeposit,
|
|
348
348
|
priceCollToDebt: new Decimal(priceCollToDebt),
|
|
349
349
|
targetLeverage: new Decimal(targetLeverage),
|
|
350
|
-
|
|
350
|
+
flashLoanFeeRatio: flashLoanFee,
|
|
351
351
|
});
|
|
352
352
|
|
|
353
353
|
const adjustDepositPosition = targetDeposit.minus(currentDepositPosition);
|
|
@@ -393,7 +393,7 @@ export const estimateDepositMode = ({
|
|
|
393
393
|
depositTokenAmount: depositCollTokenAmount,
|
|
394
394
|
targetLeverage: new Decimal(targetLeverage),
|
|
395
395
|
priceCollToDebt: new Decimal(priceCollToDebt),
|
|
396
|
-
|
|
396
|
+
flashLoanFeeRatio: new Decimal(flashLoanFee),
|
|
397
397
|
});
|
|
398
398
|
|
|
399
399
|
const slippageFactor = new Decimal(1).add(slippagePct.div(new Decimal(100)));
|
|
@@ -673,11 +673,11 @@ export function withdrawLeverageCalcs(
|
|
|
673
673
|
// Add slippage for the accrued interest rate amount
|
|
674
674
|
const irSlippageBpsForDebt = obligation!
|
|
675
675
|
.estimateObligationInterestRate(market, debtReserve!, obligation?.state.borrows[0]!, currentSlot)
|
|
676
|
-
.toDecimalPlaces(debtReserve?.
|
|
677
|
-
// add 0.1 to irSlippageBpsForDebt because we don't want to estimate slightly less than SC and end up not
|
|
676
|
+
.toDecimalPlaces(debtReserve?.getMintDecimals()!, Decimal.ROUND_CEIL);
|
|
677
|
+
// add 0.1 to irSlippageBpsForDebt because we don't want to estimate slightly less than SC and end up not repaying enough
|
|
678
678
|
const repayAmount = initialRepayAmount
|
|
679
679
|
.mul(irSlippageBpsForDebt.add('0.1').div('10_000').add('1'))
|
|
680
|
-
.toDecimalPlaces(debtReserve?.
|
|
680
|
+
.toDecimalPlaces(debtReserve?.getMintDecimals()!, Decimal.ROUND_CEIL);
|
|
681
681
|
|
|
682
682
|
// 6. Get swap ixs
|
|
683
683
|
// 5. Get swap estimations to understand how much we need to borrow from borrow reserve
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import Decimal from 'decimal.js';
|
|
13
13
|
|
|
14
14
|
export const getFlashLoanInstructions = (args: {
|
|
15
|
-
|
|
15
|
+
borrowIxIndex: number;
|
|
16
16
|
walletPublicKey: PublicKey;
|
|
17
17
|
lendingMarketAuthority: PublicKey;
|
|
18
18
|
lendingMarketAddress: PublicKey;
|
|
@@ -23,7 +23,7 @@ export const getFlashLoanInstructions = (args: {
|
|
|
23
23
|
referrerTokenState: PublicKey;
|
|
24
24
|
programId: PublicKey;
|
|
25
25
|
}) => {
|
|
26
|
-
const
|
|
26
|
+
const flashBorrowIx = getBorrowFlashLoanInstruction({
|
|
27
27
|
walletPublicKey: args.walletPublicKey,
|
|
28
28
|
lendingMarketAuthority: args.lendingMarketAuthority,
|
|
29
29
|
lendingMarketAddress: args.lendingMarketAddress,
|
|
@@ -34,8 +34,8 @@ export const getFlashLoanInstructions = (args: {
|
|
|
34
34
|
referrerTokenState: args.referrerTokenState,
|
|
35
35
|
programId: args.programId,
|
|
36
36
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const flashRepayIx = getRepayFlashLoanInstruction({
|
|
38
|
+
borrowIxIndex: args.borrowIxIndex,
|
|
39
39
|
walletPublicKey: args.walletPublicKey,
|
|
40
40
|
lendingMarketAuthority: args.lendingMarketAuthority,
|
|
41
41
|
lendingMarketAddress: args.lendingMarketAddress,
|
|
@@ -47,7 +47,7 @@ export const getFlashLoanInstructions = (args: {
|
|
|
47
47
|
programId: args.programId,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
return {
|
|
50
|
+
return { flashBorrowIx, flashRepayIx };
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export const getBorrowFlashLoanInstruction = ({
|
|
@@ -93,7 +93,7 @@ export const getBorrowFlashLoanInstruction = ({
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
export const getRepayFlashLoanInstruction = ({
|
|
96
|
-
|
|
96
|
+
borrowIxIndex,
|
|
97
97
|
walletPublicKey,
|
|
98
98
|
lendingMarketAuthority,
|
|
99
99
|
lendingMarketAddress,
|
|
@@ -104,7 +104,7 @@ export const getRepayFlashLoanInstruction = ({
|
|
|
104
104
|
referrerTokenState,
|
|
105
105
|
programId,
|
|
106
106
|
}: {
|
|
107
|
-
|
|
107
|
+
borrowIxIndex: number;
|
|
108
108
|
walletPublicKey: PublicKey;
|
|
109
109
|
lendingMarketAuthority: PublicKey;
|
|
110
110
|
lendingMarketAddress: PublicKey;
|
|
@@ -116,7 +116,7 @@ export const getRepayFlashLoanInstruction = ({
|
|
|
116
116
|
programId: PublicKey;
|
|
117
117
|
}) => {
|
|
118
118
|
const args: FlashRepayReserveLiquidityArgs = {
|
|
119
|
-
borrowInstructionIndex:
|
|
119
|
+
borrowInstructionIndex: borrowIxIndex,
|
|
120
120
|
liquidityAmount: new anchor.BN(amountLamports.floor().toString()),
|
|
121
121
|
};
|
|
122
122
|
|