@kamino-finance/klend-sdk 5.10.0 → 5.10.2
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/farm_utils.d.ts +22 -0
- package/dist/classes/farm_utils.d.ts.map +1 -0
- package/dist/classes/farm_utils.js +93 -0
- package/dist/classes/farm_utils.js.map +1 -0
- package/dist/classes/lut_utils.d.ts +29 -0
- package/dist/classes/lut_utils.d.ts.map +1 -0
- package/dist/classes/lut_utils.js +62 -0
- package/dist/classes/lut_utils.js.map +1 -0
- package/dist/classes/manager.d.ts +51 -28
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +53 -27
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/types.d.ts +15 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/utils.d.ts +6 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +10 -0
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +84 -56
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +229 -134
- 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 -26
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +1 -0
- package/dist/utils/ata.js.map +1 -1
- package/package.json +6 -6
- package/src/classes/farm_utils.ts +155 -0
- package/src/classes/lut_utils.ts +63 -0
- package/src/classes/manager.ts +75 -31
- package/src/classes/types.ts +18 -0
- package/src/classes/utils.ts +10 -0
- package/src/classes/vault.ts +315 -158
- package/src/client_kamino_manager.ts +19 -33
- package/src/utils/ata.ts +1 -0
package/dist/utils/ata.js
CHANGED
|
@@ -104,6 +104,7 @@ async function getTokenAccountBalance(provider, tokenAccount) {
|
|
|
104
104
|
const tokenAccountBalance = await provider.connection.getTokenAccountBalance(tokenAccount);
|
|
105
105
|
return Number(tokenAccountBalance.value.amount).valueOf();
|
|
106
106
|
}
|
|
107
|
+
/// Get the balance of a token account in decimal format (tokens, not lamports)
|
|
107
108
|
async function getTokenAccountBalanceDecimal(connection, mint, owner, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
|
|
108
109
|
const ata = getAssociatedTokenAddress(mint, owner, true, tokenProgram);
|
|
109
110
|
const accInfo = await connection.getAccountInfo(ata);
|
package/dist/utils/ata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ata.js","sourceRoot":"","sources":["../../src/utils/ata.ts"],"names":[],"mappings":";;;;;;AAmBA,8GAoBC;AAED,8DAeC;AAwBD,oDAkBC;AAED,gDA0BC;AAED,wDAgBC;AAED,wDAIC;
|
|
1
|
+
{"version":3,"file":"ata.js","sourceRoot":"","sources":["../../src/utils/ata.ts"],"names":[],"mappings":";;;;;;AAmBA,8GAoBC;AAED,8DAeC;AAwBD,oDAkBC;AAED,gDA0BC;AAED,wDAgBC;AAED,wDAIC;AAGD,sEAaC;AAtKD,iDAI2B;AAC3B,6CAAqH;AACrH,4DAAiC;AAGjC;;;;;;;;;GASG;AACH,SAAgB,iDAAiD,CAC/D,KAAgB,EAChB,IAAe,EACf,QAAmB,KAAK,EACxB,eAA0B,4BAAgB,EAC1C,GAAe;IAEf,IAAI,UAAU,GAAG,GAAG,CAAC;IACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,yBAAyB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,uCAA2B,CAAC,CAAC;IACvG,CAAC;IACD,MAAM,wBAAwB,GAAG,IAAA,6DAAW,EAC1C,KAAK,EACL,UAAU,EACV,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,uCAA2B,CAC5B,CAAC;IACF,OAAO,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,yBAAyB,CACvC,IAAe,EACf,KAA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,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamino-finance/klend-sdk",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.2",
|
|
4
4
|
"description": "Typescript SDK for interacting with the Kamino Lending (klend) protocol",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "rm -rf dist/; tsc",
|
|
32
32
|
"build:test": "yarn tsc --project ./tests/tsconfig.json",
|
|
33
33
|
"build:watch": "yarn tsc --watch",
|
|
34
|
-
"test": "npx ts-mocha tests/**/*.test.ts --exit",
|
|
34
|
+
"test": "npx ts-mocha ./tests/**/*.test.ts ./tests/*.test.ts --parallel --exit",
|
|
35
35
|
"watch": "tsc --watch",
|
|
36
36
|
"coverage": "jest --coverage",
|
|
37
37
|
"clean": "rm -rf dist/",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@coral-xyz/anchor": "^0.28.0",
|
|
54
54
|
"@coral-xyz/borsh": "^0.28.0",
|
|
55
|
-
"@kamino-finance/farms-sdk": "
|
|
55
|
+
"@kamino-finance/farms-sdk": "2.3.4",
|
|
56
56
|
"@kamino-finance/kliquidity-sdk": "^6.4.0",
|
|
57
57
|
"@kamino-finance/scope-sdk": "^8.0.2",
|
|
58
58
|
"@solana/buffer-layout": "^4.0.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@types/bs58": "^4.0.1",
|
|
79
79
|
"@types/chai": "^4.3.5",
|
|
80
80
|
"@types/jest": "^27.0.3",
|
|
81
|
-
"@types/mocha": "^10.0.
|
|
81
|
+
"@types/mocha": "^10.0.10",
|
|
82
82
|
"@types/node-fetch": "^2.6.7",
|
|
83
83
|
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
84
84
|
"@typescript-eslint/parser": "^5.5.0",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"eslint-plugin-react": "^7.27.1",
|
|
95
95
|
"jest": "^27.4.3",
|
|
96
96
|
"jest-fetch-mock": "^3.0.3",
|
|
97
|
-
"mocha": "^10.
|
|
97
|
+
"mocha": "^10.7.0",
|
|
98
98
|
"nodemon": "^3.1.7",
|
|
99
99
|
"prettier": "^2.8.8",
|
|
100
100
|
"start-server-and-test": "^2.0.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"ts-node": "^10.9.2",
|
|
104
104
|
"tsx": "^4.19.1",
|
|
105
105
|
"typedoc": "^0.22.10",
|
|
106
|
-
"typescript": "^5.
|
|
106
|
+
"typescript": "^5.7.2",
|
|
107
107
|
"typescript-eslint": "^0.0.1-alpha.0"
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Farms,
|
|
3
|
+
FarmState,
|
|
4
|
+
getUserStatePDA,
|
|
5
|
+
UserState,
|
|
6
|
+
FarmConfigOption,
|
|
7
|
+
lamportsToCollDecimal,
|
|
8
|
+
scaleDownWads,
|
|
9
|
+
WAD,
|
|
10
|
+
} from '@kamino-finance/farms-sdk';
|
|
11
|
+
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
12
|
+
import Decimal from 'decimal.js/decimal';
|
|
13
|
+
|
|
14
|
+
export const FARMS_GLOBAL_CONFIG_MAINNET: PublicKey = new PublicKey('6UodrBjL2ZreDy7QdR4YV1oxqMBjVYSEyrFpctqqwGwL');
|
|
15
|
+
|
|
16
|
+
export async function getFarmStakeIxs(
|
|
17
|
+
connection: Connection,
|
|
18
|
+
user: PublicKey,
|
|
19
|
+
lamportsToStake: Decimal,
|
|
20
|
+
farmAddress: PublicKey,
|
|
21
|
+
fetchedFarmState?: FarmState
|
|
22
|
+
): Promise<TransactionInstruction[]> {
|
|
23
|
+
const farmState = fetchedFarmState ? fetchedFarmState : await FarmState.fetch(connection, farmAddress);
|
|
24
|
+
if (!farmState) {
|
|
25
|
+
throw new Error(`Farm state not found for ${farmAddress}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const farmClient = new Farms(connection);
|
|
29
|
+
const scopePricesArg = farmState.scopePrices.equals(PublicKey.default)
|
|
30
|
+
? farmClient.getProgramID()
|
|
31
|
+
: farmState!.scopePrices;
|
|
32
|
+
|
|
33
|
+
const stakeIxs: TransactionInstruction[] = [];
|
|
34
|
+
const userState = getUserStatePDA(farmClient.getProgramID(), farmAddress, user);
|
|
35
|
+
const userStateExists = await connection.getAccountInfo(userState);
|
|
36
|
+
if (!userStateExists) {
|
|
37
|
+
const createUserIx = farmClient.createNewUserIx(user, farmAddress);
|
|
38
|
+
stakeIxs.push(createUserIx);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const stakeIx = farmClient.stakeIx(user, farmAddress, lamportsToStake, farmState.token.mint, scopePricesArg);
|
|
42
|
+
stakeIxs.push(stakeIx);
|
|
43
|
+
|
|
44
|
+
return stakeIxs;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function getFarmUserStatePDA(
|
|
48
|
+
connection: Connection,
|
|
49
|
+
user: PublicKey,
|
|
50
|
+
farm: PublicKey
|
|
51
|
+
): Promise<PublicKey> {
|
|
52
|
+
const farmClient = new Farms(connection);
|
|
53
|
+
return getUserStatePDA(farmClient.getProgramID(), farm, user);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function getFarmUnstakeIx(
|
|
57
|
+
connection: Connection,
|
|
58
|
+
user: PublicKey,
|
|
59
|
+
lamportsToUnstake: Decimal,
|
|
60
|
+
farmAddress: PublicKey,
|
|
61
|
+
fetchedFarmState?: FarmState
|
|
62
|
+
): Promise<TransactionInstruction> {
|
|
63
|
+
const farmState = fetchedFarmState ? fetchedFarmState : await FarmState.fetch(connection, farmAddress);
|
|
64
|
+
if (!farmState) {
|
|
65
|
+
throw new Error(`Farm state not found for ${farmAddress}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const farmClient = new Farms(connection);
|
|
69
|
+
const scopePricesArg = farmState.scopePrices.equals(PublicKey.default)
|
|
70
|
+
? farmClient.getProgramID()
|
|
71
|
+
: farmState!.scopePrices;
|
|
72
|
+
const userState = getUserStatePDA(farmClient.getProgramID(), farmAddress, user);
|
|
73
|
+
if (!userState) {
|
|
74
|
+
throw new Error(`User state not found for ${user}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const x = new Decimal(lamportsToUnstake.toString()).mul(WAD);
|
|
78
|
+
console.log('lamportsToUnstake', lamportsToUnstake.toString());
|
|
79
|
+
return farmClient.unstakeIx(user, farmAddress, x.toString(), scopePricesArg);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// withdrawing from a farm is a 2 step operation: first we unstake the tokens from the farm, then we withdraw them
|
|
83
|
+
export async function getFarmWithdrawUnstakedDepositIx(
|
|
84
|
+
connection: Connection,
|
|
85
|
+
user: PublicKey,
|
|
86
|
+
farm: PublicKey,
|
|
87
|
+
stakeTokenMint: PublicKey
|
|
88
|
+
): Promise<TransactionInstruction> {
|
|
89
|
+
const farmClient = new Farms(connection);
|
|
90
|
+
|
|
91
|
+
const userState = getUserStatePDA(farmClient.getProgramID(), farm, user);
|
|
92
|
+
return farmClient.withdrawUnstakedDepositIx(user, userState, farm, stakeTokenMint);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function getFarmUnstakeAndWithdrawIxs(
|
|
96
|
+
connection: Connection,
|
|
97
|
+
user: PublicKey,
|
|
98
|
+
lamportsToUnstake: Decimal,
|
|
99
|
+
farmAddress: PublicKey,
|
|
100
|
+
fetchedFarmState?: FarmState
|
|
101
|
+
): Promise<UnstakeAndWithdrawFromFarmIxs> {
|
|
102
|
+
const farmState = fetchedFarmState ? fetchedFarmState : await FarmState.fetch(connection, farmAddress);
|
|
103
|
+
if (!farmState) {
|
|
104
|
+
throw new Error(`Farm state not found for ${farmAddress}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const unstakeIx = await getFarmUnstakeIx(connection, user, lamportsToUnstake, farmAddress, farmState);
|
|
108
|
+
const withdrawIx = await getFarmWithdrawUnstakedDepositIx(connection, user, farmAddress, farmState.token.mint);
|
|
109
|
+
return { unstakeIx, withdrawIx };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function getSetupFarmIxsWithFarm(
|
|
113
|
+
connection: Connection,
|
|
114
|
+
farmAdmin: Keypair,
|
|
115
|
+
farmTokenMint: PublicKey
|
|
116
|
+
): Promise<SetupFarmIxsWithFarm> {
|
|
117
|
+
const farmClient = new Farms(connection);
|
|
118
|
+
const farm = new Keypair();
|
|
119
|
+
const ixs = await farmClient.createFarmIx(farmAdmin.publicKey, farm, FARMS_GLOBAL_CONFIG_MAINNET, farmTokenMint);
|
|
120
|
+
return { farm, setupFarmIxs: ixs };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function getUserSharesInFarm(
|
|
124
|
+
connection: Connection,
|
|
125
|
+
user: PublicKey,
|
|
126
|
+
farm: PublicKey,
|
|
127
|
+
farmTokenDecimals: number
|
|
128
|
+
): Promise<Decimal> {
|
|
129
|
+
const farmClient = new Farms(connection);
|
|
130
|
+
return farmClient.getUserTokensInUndelegatedFarm(user, farm, farmTokenDecimals);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function setVaultIdForFarmIx(
|
|
134
|
+
connection: Connection,
|
|
135
|
+
farmAdmin: PublicKey,
|
|
136
|
+
farm: PublicKey,
|
|
137
|
+
vault: PublicKey
|
|
138
|
+
): Promise<TransactionInstruction> {
|
|
139
|
+
const farmClient = new Farms(connection);
|
|
140
|
+
return farmClient.updateFarmConfigIx(farmAdmin, farm, PublicKey.default, new FarmConfigOption.UpdateVaultId(), vault);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getSharesInFarmUserPosition(userState: UserState, tokenDecimals: number): Decimal {
|
|
144
|
+
return lamportsToCollDecimal(new Decimal(scaleDownWads(userState.activeStakeScaled)), tokenDecimals);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type SetupFarmIxsWithFarm = {
|
|
148
|
+
farm: Keypair;
|
|
149
|
+
setupFarmIxs: TransactionInstruction[];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type UnstakeAndWithdrawFromFarmIxs = {
|
|
153
|
+
unstakeIx: TransactionInstruction;
|
|
154
|
+
withdrawIx: TransactionInstruction;
|
|
155
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
|
|
5
|
+
* @param payer - the owner of the lookup table
|
|
6
|
+
* @param slot - the current slot
|
|
7
|
+
* @returns - the instruction to create the lookup table and its address
|
|
8
|
+
*/
|
|
9
|
+
export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
|
|
10
|
+
const [ixn, address] = AddressLookupTableProgram.createLookupTable({
|
|
11
|
+
authority: payer,
|
|
12
|
+
payer,
|
|
13
|
+
recentSlot: slot,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return [ixn, address];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This method retuns an instruction that deactivates a lookup table, which is needed to close it
|
|
21
|
+
* @param payer - the owner of the lookup table
|
|
22
|
+
* @param lookupTable - the lookup table to deactivate
|
|
23
|
+
* @returns - the instruction to deactivate the lookup table
|
|
24
|
+
*/
|
|
25
|
+
export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
26
|
+
const ixn = AddressLookupTableProgram.deactivateLookupTable({
|
|
27
|
+
authority: payer,
|
|
28
|
+
lookupTable: lookupTable,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return ixn;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
|
|
36
|
+
* @param payer - the owner of the lookup table
|
|
37
|
+
* @param lookupTable - the lookup table to close
|
|
38
|
+
* @returns - the instruction to close the lookup table
|
|
39
|
+
*/
|
|
40
|
+
/// this require the LUT to be deactivated at least 500 blocks before
|
|
41
|
+
export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
42
|
+
const ixn = AddressLookupTableProgram.closeLookupTable({
|
|
43
|
+
authority: payer,
|
|
44
|
+
recipient: payer,
|
|
45
|
+
lookupTable: lookupTable,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return ixn;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns the accounts in a lookup table
|
|
53
|
+
* @param lookupTable - lookup table to get the accounts from
|
|
54
|
+
* @returns - an array of accounts in the lookup table
|
|
55
|
+
*/
|
|
56
|
+
export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
|
|
57
|
+
const lutState = await connection.getAddressLookupTable(lookupTable);
|
|
58
|
+
if (!lutState || !lutState.value) {
|
|
59
|
+
throw new Error(`Lookup table ${lookupTable} not found`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return lutState.value.state.addresses;
|
|
63
|
+
}
|
package/src/classes/manager.ts
CHANGED
|
@@ -69,11 +69,15 @@ import { getProgramAccounts } from '../utils/rpc';
|
|
|
69
69
|
import { VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
|
|
70
70
|
import {
|
|
71
71
|
AcceptVaultOwnershipIxs,
|
|
72
|
+
DepositIxs,
|
|
72
73
|
InitVaultIxs,
|
|
73
74
|
SyncVaultLUTIxs,
|
|
74
75
|
UpdateReserveAllocationIxs,
|
|
75
76
|
UpdateVaultConfigIxs,
|
|
77
|
+
UserSharesForVault,
|
|
78
|
+
WithdrawIxs,
|
|
76
79
|
} from './types';
|
|
80
|
+
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
* 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
|
|
@@ -198,7 +202,6 @@ export class KaminoManager {
|
|
|
198
202
|
/**
|
|
199
203
|
* This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
|
|
200
204
|
* @param vaultConfig - the config object used to create a vault
|
|
201
|
-
* @returns vault - keypair, should be used to sign the transaction which creates the vault account
|
|
202
205
|
* @returns vault: the keypair of the vault, used to sign the initialization transaction; initVaultIxs: a struct with ixs to initialize the vault and its lookup table + populateLUTIxs, a list to populate the lookup table which has to be executed in a separate transaction
|
|
203
206
|
*/
|
|
204
207
|
async createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{ vault: Keypair; initVaultIxs: InitVaultIxs }> {
|
|
@@ -209,7 +212,7 @@ export class KaminoManager {
|
|
|
209
212
|
* This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
|
|
210
213
|
* @param vault - vault to be updated
|
|
211
214
|
* @param reserveAllocationConfig - new reserve allocation config
|
|
212
|
-
* @returns - a struct of instructions
|
|
215
|
+
* @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
|
|
213
216
|
*/
|
|
214
217
|
async updateVaultReserveAllocationIxs(
|
|
215
218
|
vault: KaminoVault,
|
|
@@ -325,21 +328,38 @@ export class KaminoManager {
|
|
|
325
328
|
/**
|
|
326
329
|
* This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return
|
|
327
330
|
* @param user - user to deposit
|
|
328
|
-
* @param vault - vault to deposit into
|
|
331
|
+
* @param vault - vault to deposit into (if the state is not provided, it will be fetched)
|
|
329
332
|
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
330
|
-
* @param
|
|
331
|
-
* @param
|
|
332
|
-
* @returns - an
|
|
333
|
+
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
334
|
+
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
335
|
+
* @returns - an instance of DepositIxs which contains the instructions to deposit in vault and the instructions to stake the shares in the farm if the vault has a farm
|
|
333
336
|
*/
|
|
334
337
|
async depositToVaultIxs(
|
|
335
338
|
user: PublicKey,
|
|
336
339
|
vault: KaminoVault,
|
|
337
340
|
tokenAmount: Decimal,
|
|
338
341
|
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
339
|
-
): Promise<
|
|
342
|
+
): Promise<DepositIxs> {
|
|
340
343
|
return this._vaultClient.depositIxs(user, vault, tokenAmount, vaultReservesMap);
|
|
341
344
|
}
|
|
342
345
|
|
|
346
|
+
/**
|
|
347
|
+
* This function creates instructions to stake the shares in the vault farm if the vault has a farm
|
|
348
|
+
* @param user - user to stake
|
|
349
|
+
* @param vault - vault to deposit into its farm (if the state is not provided, it will be fetched)
|
|
350
|
+
* @param [sharesAmount] - token amount to be deposited, in decimals (will be converted in lamports). Optional. If not provided, the user's share balance will be used
|
|
351
|
+
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
352
|
+
* @returns - a list of instructions for the user to stake shares into the vault's farm, including the creation of prerequisite accounts if needed
|
|
353
|
+
*/
|
|
354
|
+
async stakeSharesIxs(
|
|
355
|
+
user: PublicKey,
|
|
356
|
+
vault: KaminoVault,
|
|
357
|
+
sharesAmount?: Decimal,
|
|
358
|
+
farmState?: FarmState
|
|
359
|
+
): Promise<TransactionInstruction[]> {
|
|
360
|
+
return this._vaultClient.stakeSharesIxs(user, vault, sharesAmount, farmState);
|
|
361
|
+
}
|
|
362
|
+
|
|
343
363
|
/**
|
|
344
364
|
* Update a field of the vault. If the field is a pubkey it will return an extra instruction to add that account into the lookup table
|
|
345
365
|
* @param vault the vault to update
|
|
@@ -355,10 +375,23 @@ export class KaminoManager {
|
|
|
355
375
|
return this._vaultClient.updateVaultConfigIxs(vault, mode, value);
|
|
356
376
|
}
|
|
357
377
|
|
|
378
|
+
/** Sets the farm where the shares can be staked. This is store in vault state and a vault can only have one farm, so the new farm will ovveride the old farm
|
|
379
|
+
* @param vault - vault to set the farm for
|
|
380
|
+
* @param farm - the farm where the vault shares can be staked
|
|
381
|
+
* @param [errorOnOverride] - if true, the function will throw an error if the vault already has a farm. If false, it will override the farm
|
|
382
|
+
*/
|
|
383
|
+
async setVaultFarm(
|
|
384
|
+
vault: KaminoVault,
|
|
385
|
+
farm: PublicKey,
|
|
386
|
+
errorOnOverride: boolean = true
|
|
387
|
+
): Promise<UpdateVaultConfigIxs> {
|
|
388
|
+
return this._vaultClient.setVaultFarm(vault, farm, errorOnOverride);
|
|
389
|
+
}
|
|
390
|
+
|
|
358
391
|
/**
|
|
359
|
-
* This function creates the instruction for the `pendingAdmin` of the vault to accept to become the owner of the vault (step 2/2 of the ownership transfer)
|
|
392
|
+
* This function creates the instruction for the `pendingAdmin` of the vault to accept to become the owner of the vault (step 2/2 of the ownership transfer)
|
|
360
393
|
* @param vault - vault to change the ownership for
|
|
361
|
-
* @returns - an instruction to
|
|
394
|
+
* @returns - an instruction to accept the ownership of the vault and a list of instructions to update the lookup table
|
|
362
395
|
*/
|
|
363
396
|
async acceptVaultOwnershipIxs(vault: KaminoVault): Promise<AcceptVaultOwnershipIxs> {
|
|
364
397
|
return this._vaultClient.acceptVaultOwnershipIxs(vault);
|
|
@@ -368,7 +401,7 @@ export class KaminoManager {
|
|
|
368
401
|
* This function creates the instruction for the admin to give up a part of the pending fees (which will be accounted as part of the vault)
|
|
369
402
|
* @param vault - vault to give up pending fees for
|
|
370
403
|
* @param maxAmountToGiveUp - the maximum amount of fees to give up, in tokens
|
|
371
|
-
* @returns - an instruction to
|
|
404
|
+
* @returns - an instruction to give up the specified pending fees
|
|
372
405
|
*/
|
|
373
406
|
async giveUpPendingFeesIx(vault: KaminoVault, maxAmountToGiveUp: Decimal): Promise<TransactionInstruction> {
|
|
374
407
|
return this._vaultClient.giveUpPendingFeesIx(vault, maxAmountToGiveUp);
|
|
@@ -380,14 +413,15 @@ export class KaminoManager {
|
|
|
380
413
|
* @param vault - vault to withdraw from
|
|
381
414
|
* @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount
|
|
382
415
|
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
383
|
-
* @
|
|
416
|
+
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
417
|
+
* @returns an array of instructions to create missing ATAs if needed and the withdraw instructions
|
|
384
418
|
*/
|
|
385
419
|
async withdrawFromVaultIxs(
|
|
386
420
|
user: PublicKey,
|
|
387
421
|
vault: KaminoVault,
|
|
388
422
|
shareAmount: Decimal,
|
|
389
423
|
slot: number
|
|
390
|
-
): Promise<
|
|
424
|
+
): Promise<WithdrawIxs> {
|
|
391
425
|
return this._vaultClient.withdrawIxs(user, vault, shareAmount, slot);
|
|
392
426
|
}
|
|
393
427
|
|
|
@@ -395,20 +429,22 @@ export class KaminoManager {
|
|
|
395
429
|
* This method withdraws all the pending fees from the vault to the owner's token ATA
|
|
396
430
|
* @param vault - vault for which the admin withdraws the pending fees
|
|
397
431
|
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
398
|
-
* @
|
|
432
|
+
* @param [vaultReservesMap] - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
433
|
+
* @returns - list of instructions to withdraw all pending fees, including the ATA creation instructions if needed
|
|
399
434
|
*/
|
|
400
435
|
async withdrawPendingFeesIxs(vault: KaminoVault, slot: number): Promise<TransactionInstruction[]> {
|
|
401
436
|
return this._vaultClient.withdrawPendingFeesIxs(vault, slot);
|
|
402
437
|
}
|
|
403
438
|
|
|
404
439
|
/**
|
|
405
|
-
* This method
|
|
406
|
-
* @param payer -
|
|
407
|
-
* @param
|
|
408
|
-
* @param keys -
|
|
409
|
-
* @
|
|
440
|
+
* This method inserts the missing keys from the provided keys into an existent lookup table
|
|
441
|
+
* @param payer - payer wallet pubkey
|
|
442
|
+
* @param lookupTable - lookup table to insert the keys into
|
|
443
|
+
* @param keys - keys to insert into the lookup table
|
|
444
|
+
* @param [accountsInLUT] - the existent accounts in the lookup table. Optional. If provided, the function will not fetch the accounts in the lookup table
|
|
445
|
+
* @returns - an array of instructions to insert the missing keys into the lookup table
|
|
410
446
|
*/
|
|
411
|
-
async
|
|
447
|
+
async insertIntoLUTIxs(payer: PublicKey, lut: PublicKey, keys: PublicKey[]): Promise<TransactionInstruction[]> {
|
|
412
448
|
return this._vaultClient.insertIntoLookupTableIxs(payer, lut, keys);
|
|
413
449
|
}
|
|
414
450
|
|
|
@@ -416,13 +452,14 @@ export class KaminoManager {
|
|
|
416
452
|
* Sync a vault for lookup table; create and set the LUT for the vault if needed and fill it with all the needed accounts
|
|
417
453
|
* @param vault the vault to sync and set the LUT for if needed
|
|
418
454
|
* @param vaultReserves optional; the state of the reserves in the vault allocation
|
|
455
|
+
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
419
456
|
* @returns a struct that contains a list of ix to create the LUT and assign it to the vault if needed + a list of ixs to insert all the accounts in the LUT
|
|
420
457
|
*/
|
|
421
|
-
async
|
|
458
|
+
async syncVaultLUTIxs(
|
|
422
459
|
vault: KaminoVault,
|
|
423
460
|
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
424
461
|
): Promise<SyncVaultLUTIxs> {
|
|
425
|
-
return this._vaultClient.
|
|
462
|
+
return this._vaultClient.syncVaultLookupTableIxs(vault, vaultReserves);
|
|
426
463
|
}
|
|
427
464
|
|
|
428
465
|
/**
|
|
@@ -451,9 +488,9 @@ export class KaminoManager {
|
|
|
451
488
|
* This method returns the user shares balance for a given vault
|
|
452
489
|
* @param user - user to calculate the shares balance for
|
|
453
490
|
* @param vault - vault to calculate shares balance for
|
|
454
|
-
* @returns - user share balance in decimal (not lamports)
|
|
491
|
+
* @returns - a struct of user share balance (staked in vault farm if the vault has a farm and unstaked) in decimal (not lamports)
|
|
455
492
|
*/
|
|
456
|
-
async getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<
|
|
493
|
+
async getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<UserSharesForVault> {
|
|
457
494
|
return this._vaultClient.getUserSharesBalanceSingleVault(user, vault);
|
|
458
495
|
}
|
|
459
496
|
|
|
@@ -466,7 +503,7 @@ export class KaminoManager {
|
|
|
466
503
|
async getUserSharesBalanceAllVaults(
|
|
467
504
|
user: PublicKey,
|
|
468
505
|
vaultsOverride?: KaminoVault[]
|
|
469
|
-
): Promise<PubkeyHashMap<PublicKey,
|
|
506
|
+
): Promise<PubkeyHashMap<PublicKey, UserSharesForVault>> {
|
|
470
507
|
return this._vaultClient.getUserSharesBalanceAllVaults(user, vaultsOverride);
|
|
471
508
|
}
|
|
472
509
|
|
|
@@ -707,26 +744,30 @@ export class KaminoManager {
|
|
|
707
744
|
* Simulate the current holdings of the vault and the earned interest
|
|
708
745
|
* @param vaultState the kamino vault state to get simulated holdings and earnings for
|
|
709
746
|
* @param vaultReserves optional; the state of the reserves in the vault allocation
|
|
747
|
+
* @param [currentSlot] - the current slot. Optional. If not provided it will fetch the current slot
|
|
710
748
|
* @returns a struct of simulated vault holdings and earned interest
|
|
711
749
|
*/
|
|
712
750
|
async calculateSimulatedHoldingsWithInterest(
|
|
713
751
|
vaultState: VaultState,
|
|
714
|
-
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve
|
|
752
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>,
|
|
753
|
+
currentSlot?: number
|
|
715
754
|
): Promise<SimulatedVaultHoldingsWithEarnedInterest> {
|
|
716
|
-
return this._vaultClient.calculateSimulatedHoldingsWithInterest(vaultState, vaultReserves);
|
|
755
|
+
return this._vaultClient.calculateSimulatedHoldingsWithInterest(vaultState, vaultReserves, currentSlot);
|
|
717
756
|
}
|
|
718
757
|
|
|
719
758
|
/**
|
|
720
759
|
* Simulate the current holdings and compute the fees that would be charged
|
|
721
760
|
* @param vaultState the kamino vault state to get simulated fees for
|
|
722
761
|
* @param simulatedCurrentHoldingsWithInterest optional; the simulated holdings and interest earned by the vault
|
|
762
|
+
* @param [currentTimestamp] the current timestamp. Optional. If not provided it will fetch the current unix timestamp
|
|
723
763
|
* @returns a struct of simulated management and interest fees
|
|
724
764
|
*/
|
|
725
765
|
async calculateSimulatedFees(
|
|
726
766
|
vaultState: VaultState,
|
|
727
|
-
simulatedCurrentHoldingsWithInterest?: SimulatedVaultHoldingsWithEarnedInterest
|
|
767
|
+
simulatedCurrentHoldingsWithInterest?: SimulatedVaultHoldingsWithEarnedInterest,
|
|
768
|
+
currentTimestamp?: number
|
|
728
769
|
): Promise<VaultFees> {
|
|
729
|
-
return this._vaultClient.calculateSimulatedFees(vaultState, simulatedCurrentHoldingsWithInterest);
|
|
770
|
+
return this._vaultClient.calculateSimulatedFees(vaultState, simulatedCurrentHoldingsWithInterest, currentTimestamp);
|
|
730
771
|
}
|
|
731
772
|
|
|
732
773
|
/**
|
|
@@ -777,16 +818,19 @@ export class KaminoManager {
|
|
|
777
818
|
|
|
778
819
|
/**
|
|
779
820
|
* This will trigger invest by balancing, based on weights, the reserve allocation of the vault. It can either withdraw or deposit into the given reserve to balance it
|
|
780
|
-
* @param
|
|
821
|
+
* @param payer wallet pubkey
|
|
822
|
+
* @param vault - vault to invest from
|
|
781
823
|
* @param reserve - reserve to invest into or disinvest from
|
|
824
|
+
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
782
825
|
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
783
826
|
*/
|
|
784
827
|
async investSingleReserve(
|
|
785
828
|
payer: PublicKey,
|
|
786
829
|
kaminoVault: KaminoVault,
|
|
787
|
-
reserveWithAddress: ReserveWithAddress
|
|
830
|
+
reserveWithAddress: ReserveWithAddress,
|
|
831
|
+
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
788
832
|
): Promise<TransactionInstruction[]> {
|
|
789
|
-
return this._vaultClient.investSingleReserveIxs(payer, kaminoVault, reserveWithAddress);
|
|
833
|
+
return this._vaultClient.investSingleReserveIxs(payer, kaminoVault, reserveWithAddress, vaultReservesMap);
|
|
790
834
|
}
|
|
791
835
|
|
|
792
836
|
/**
|
package/src/classes/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
import Decimal from 'decimal.js/decimal';
|
|
2
3
|
|
|
3
4
|
/** the populateLUTIxs should be executed in a separate transaction as we cannot create and populate a lookup table in the same tx */
|
|
4
5
|
export type InitVaultIxs = {
|
|
@@ -21,7 +22,24 @@ export type UpdateVaultConfigIxs = {
|
|
|
21
22
|
updateLUTIxs: TransactionInstruction[];
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
/** If there are ixs to setup the LUT it means it doesn't already exist and it needs to be created in a separate tx before inserting into it */
|
|
24
26
|
export type SyncVaultLUTIxs = {
|
|
25
27
|
setupLUTIfNeededIxs: TransactionInstruction[];
|
|
26
28
|
syncLUTIxs: TransactionInstruction[];
|
|
27
29
|
};
|
|
30
|
+
|
|
31
|
+
export type DepositIxs = {
|
|
32
|
+
depositIxs: TransactionInstruction[];
|
|
33
|
+
stakeInFarmIfNeededIxs: TransactionInstruction[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type WithdrawIxs = {
|
|
37
|
+
unstakeFromFarmIfNeededIxs: TransactionInstruction[];
|
|
38
|
+
withdrawIxs: TransactionInstruction[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** The shares an user has in a vault (staked and unstaked), in tokens */
|
|
42
|
+
export type UserSharesForVault = {
|
|
43
|
+
unstakedShares: Decimal;
|
|
44
|
+
stakedShares: Decimal;
|
|
45
|
+
};
|
package/src/classes/utils.ts
CHANGED
|
@@ -240,3 +240,13 @@ export function getTokenBalanceFromAccountInfoLamports(accountInfo: AccountInfo<
|
|
|
240
240
|
export function bpsToPct(bps: Decimal): Decimal {
|
|
241
241
|
return bps.div(100);
|
|
242
242
|
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Truncate ( not round ) number to keep up to max amount of decimals
|
|
246
|
+
* @param num
|
|
247
|
+
* @param maxDecimals
|
|
248
|
+
*/
|
|
249
|
+
export function truncateDecimals(num: Decimal.Value, maxDecimals: number): Decimal {
|
|
250
|
+
const factor = new Decimal(10).pow(maxDecimals);
|
|
251
|
+
return new Decimal(num).times(factor).floor().dividedBy(factor);
|
|
252
|
+
}
|