@kamino-finance/klend-sdk 5.0.7 → 5.1.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/README_KAMINO_MANAGER.md +24 -3
- package/dist/classes/action.d.ts +5 -1
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +39 -26
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +45 -2
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +54 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/vault.d.ts +56 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +107 -3
- 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 -0
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +9 -3
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +42 -32
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +10 -10
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +51 -52
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +4 -4
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -1
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +3 -9
- package/dist/leverage/operations.js.map +1 -1
- package/dist/referrals/instructions.d.ts +2 -1
- package/dist/referrals/instructions.d.ts.map +1 -1
- package/dist/referrals/instructions.js +13 -8
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -2
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +8 -15
- package/dist/utils/ata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +41 -33
- package/src/classes/manager.ts +80 -1
- package/src/classes/vault.ts +158 -4
- package/src/client.ts +4 -20
- package/src/client_kamino_manager.ts +8 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +178 -175
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +117 -116
- package/src/idl_codegen_kamino_vault/types/WithdrawalCaps.ts +30 -30
- package/src/leverage/operations.ts +3 -9
- package/src/referrals/instructions.ts +16 -9
- package/src/utils/ata.ts +8 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/referrals/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqC,sBAAsB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAU1C,eAAO,MAAM,gCAAgC,
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/referrals/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqC,sBAAsB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAU1C,eAAO,MAAM,gCAAgC,uCAI1C;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,sCA0CA,CAAC;AAEF,eAAO,MAAM,mCAAmC,uCAI7C;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;CACtB,2BAsBA,CAAC;AAGF,eAAO,MAAM,qCAAqC,yCAI/C;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;CACtB,oCAgBA,CAAC"}
|
|
@@ -4,30 +4,35 @@ exports.getDeleteReferrerStateAndShortUrlIxns = exports.getInitReferrerStateAndS
|
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const lib_1 = require("../lib");
|
|
7
|
-
const getInitAllReferrerTokenStateIxns = async ({ referrer, kaminoMarket, }) => {
|
|
7
|
+
const getInitAllReferrerTokenStateIxns = async ({ referrer, kaminoMarket, payer = referrer, }) => {
|
|
8
8
|
if (referrer.equals(web3_js_1.PublicKey.default)) {
|
|
9
9
|
throw new Error('Referrer not set');
|
|
10
10
|
}
|
|
11
11
|
await kaminoMarket.loadReserves();
|
|
12
12
|
const initReferrerTokenStateIxns = [];
|
|
13
13
|
const tokenStatesToCreate = [];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const reserves = kaminoMarket.getReserves();
|
|
15
|
+
const referrerTokenStates = reserves.map((reserve) => {
|
|
16
|
+
return (0, utils_1.referrerTokenStatePda)(referrer, reserve.address, kaminoMarket.programId)[0];
|
|
17
|
+
});
|
|
18
|
+
const uniqueReferrerTokenStates = new utils_1.PublicKeySet(referrerTokenStates).toArray();
|
|
19
|
+
const accounts = await kaminoMarket.getConnection().getMultipleAccountsInfo(uniqueReferrerTokenStates);
|
|
20
|
+
for (let i = 0; i < uniqueReferrerTokenStates.length; i++) {
|
|
21
|
+
if (!accounts[i]) {
|
|
22
|
+
tokenStatesToCreate.push([uniqueReferrerTokenStates[i], reserves[i].address]);
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
|
|
21
26
|
const initReferrerTokenStateIx = (0, lib_1.initReferrerTokenState)({
|
|
22
|
-
referrer
|
|
27
|
+
referrer,
|
|
23
28
|
}, {
|
|
24
29
|
lendingMarket: kaminoMarket.getAddress(),
|
|
25
|
-
payer
|
|
30
|
+
payer,
|
|
26
31
|
reserve: reserveAddress,
|
|
27
32
|
referrerTokenState: referrerTokenStateAddress,
|
|
28
33
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
29
34
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
30
|
-
});
|
|
35
|
+
}, kaminoMarket.programId);
|
|
31
36
|
initReferrerTokenStateIxns.push(initReferrerTokenStateIx);
|
|
32
37
|
});
|
|
33
38
|
return initReferrerTokenStateIxns;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/referrals/instructions.ts"],"names":[],"mappings":";;;AAAA,6CAAmH;AAEnH,
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/referrals/instructions.ts"],"names":[],"mappings":";;;AAAA,6CAAmH;AAEnH,oCAA+G;AAC/G,gCAMgB;AAET,MAAM,gCAAgC,GAAG,KAAK,EAAE,EACrD,QAAQ,EACR,YAAY,EACZ,KAAK,GAAG,QAAQ,GAKjB,EAAE,EAAE;IACH,IAAI,QAAQ,CAAC,MAAM,CAAC,mBAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,YAAY,CAAC,YAAY,EAAE,CAAC;IAElC,MAAM,0BAA0B,GAA6B,EAAE,CAAC;IAEhE,MAAM,mBAAmB,GAA6B,EAAE,CAAC;IACzD,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,mBAAmB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACnD,OAAO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AA,qCAAqC,yCAwBhD"}
|
package/dist/utils/ata.d.ts
CHANGED
|
@@ -27,9 +27,8 @@ export declare function createAtasIdempotent(user: PublicKey, mints: Array<{
|
|
|
27
27
|
ata: PublicKey;
|
|
28
28
|
createAtaIx: TransactionInstruction;
|
|
29
29
|
}>;
|
|
30
|
-
export declare const checkIfAccountExists: (connection: Connection, account: PublicKey) => Promise<boolean>;
|
|
31
30
|
export declare function getDepositWsolIxns(owner: PublicKey, ata: PublicKey, amountLamports: Decimal): TransactionInstruction[];
|
|
32
31
|
export declare function removeBudgetAndAtaIxns(ixns: TransactionInstruction[], mints: string[]): TransactionInstruction[];
|
|
33
32
|
export declare function getTokenAccountBalance(provider: AnchorProvider, tokenAccount: PublicKey): Promise<number>;
|
|
34
|
-
export declare function getTokenAccountBalanceDecimal(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<Decimal>;
|
|
33
|
+
export declare function getTokenAccountBalanceDecimal(connection: Connection, mint: PublicKey, owner: PublicKey, tokenProgram?: PublicKey): Promise<Decimal>;
|
|
35
34
|
//# sourceMappingURL=ata.d.ts.map
|
package/dist/utils/ata.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ata.d.ts","sourceRoot":"","sources":["../../src/utils/ata.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwB,UAAU,EAAE,SAAS,EAAiB,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;;;;;;;GASG;AACH,wBAAgB,iDAAiD,CAC/D,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,SAAS,EACf,KAAK,GAAE,SAAiB,EACxB,YAAY,GAAE,SAA4B,EAC1C,GAAG,CAAC,EAAE,SAAS,GACd,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAcrC;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAA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eAAO,MAAM,8BAA8B,eAC7B,UAAU,QAChB,SAAS,SACR,KAAK,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,CAAC,KACzD,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAAC,YAAY,EAAE,sBAAsB,EAAE,CAAA;CAAE,CAgBvE,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,CAAC,GACzD,KAAK,CAAC;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,sBAAsB,CAAA;CAAE,CAAC,CAehE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,4BA0B3F;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,sBAAsB,EAAE,CAgBhH;AAED,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/G;AAED,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAA4B,GACzC,OAAO,CAAC,OAAO,CAAC,CAQlB"}
|
package/dist/utils/ata.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getAtasWithCreateIxnsIfMissing = void 0;
|
|
7
7
|
exports.createAssociatedTokenAccountIdempotentInstruction = createAssociatedTokenAccountIdempotentInstruction;
|
|
8
8
|
exports.getAssociatedTokenAddress = getAssociatedTokenAddress;
|
|
9
9
|
exports.createAtasIdempotent = createAtasIdempotent;
|
|
@@ -67,11 +67,6 @@ function createAtasIdempotent(user, mints) {
|
|
|
67
67
|
}
|
|
68
68
|
return res;
|
|
69
69
|
}
|
|
70
|
-
const checkIfAccountExists = async (connection, account) => {
|
|
71
|
-
const acc = await connection.getAccountInfo(account);
|
|
72
|
-
return acc !== null;
|
|
73
|
-
};
|
|
74
|
-
exports.checkIfAccountExists = checkIfAccountExists;
|
|
75
70
|
function getDepositWsolIxns(owner, ata, amountLamports) {
|
|
76
71
|
const ixns = [];
|
|
77
72
|
ixns.push(web3_js_1.SystemProgram.transfer({
|
|
@@ -109,15 +104,13 @@ async function getTokenAccountBalance(provider, tokenAccount) {
|
|
|
109
104
|
const tokenAccountBalance = await provider.connection.getTokenAccountBalance(tokenAccount);
|
|
110
105
|
return Number(tokenAccountBalance.value.amount).valueOf();
|
|
111
106
|
}
|
|
112
|
-
async function getTokenAccountBalanceDecimal(connection, mint, owner) {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
return new decimal_js_1.default(0);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
const tokenData = (await connection.getTokenAccountBalance(tokenAta)).value;
|
|
120
|
-
return new decimal_js_1.default(tokenData.uiAmountString);
|
|
107
|
+
async function getTokenAccountBalanceDecimal(connection, mint, owner, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
|
|
108
|
+
const ata = getAssociatedTokenAddress(mint, owner, true, tokenProgram);
|
|
109
|
+
const accInfo = await connection.getAccountInfo(ata);
|
|
110
|
+
if (accInfo === null) {
|
|
111
|
+
return new decimal_js_1.default('0');
|
|
121
112
|
}
|
|
113
|
+
const { value } = await connection.getTokenAccountBalance(ata);
|
|
114
|
+
return new decimal_js_1.default(value.uiAmountString);
|
|
122
115
|
}
|
|
123
116
|
//# sourceMappingURL=ata.js.map
|
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;
|
|
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;AAED,sEAaC;AArKD,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,KAAgB,EAChB,kBAAkB,GAAG,IAAI,EACzB,SAAS,GAAG,4BAAgB,EAC5B,wBAAwB,GAAG,uCAA2B;IAEtD,IAAI,CAAC,kBAAkB,IAAI,CAAC,mBAAS,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAE5G,MAAM,CAAC,OAAO,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C;YAClD,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAAC,QAAwB,EAAE,YAAuB;IAC5F,MAAM,mBAAmB,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAE3F,OAAO,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;AAC5D,CAAC;AAEM,KAAK,UAAU,6BAA6B,CACjD,UAAsB,EACtB,IAAe,EACf,KAAgB,EAChB,eAA0B,4BAAgB;IAE1C,MAAM,GAAG,GAAG,yBAAyB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,IAAI,oBAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC/D,OAAO,IAAI,oBAAO,CAAC,KAAK,CAAC,cAAe,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
package/src/classes/action.ts
CHANGED
|
@@ -52,7 +52,6 @@ import {
|
|
|
52
52
|
referrerTokenStatePda,
|
|
53
53
|
userMetadataPda,
|
|
54
54
|
getAtasWithCreateIxnsIfMissing,
|
|
55
|
-
checkIfAccountExists,
|
|
56
55
|
createLookupTableIx,
|
|
57
56
|
isNotNullPubkey,
|
|
58
57
|
PublicKeySet,
|
|
@@ -127,6 +126,9 @@ export class KaminoAction {
|
|
|
127
126
|
amount: BN;
|
|
128
127
|
outflowAmount?: BN;
|
|
129
128
|
|
|
129
|
+
computeBudgetIxs: Array<TransactionInstruction>;
|
|
130
|
+
computeBudgetIxsLabels: Array<string>;
|
|
131
|
+
|
|
130
132
|
setupIxs: Array<TransactionInstruction>;
|
|
131
133
|
setupIxsLabels: Array<string>;
|
|
132
134
|
|
|
@@ -190,6 +192,8 @@ export class KaminoAction {
|
|
|
190
192
|
this.positions = positions;
|
|
191
193
|
this.userTokenAccountAddress = userTokenAccountAddress;
|
|
192
194
|
this.userCollateralAccountAddress = userCollateralAccountAddress;
|
|
195
|
+
this.computeBudgetIxs = [];
|
|
196
|
+
this.computeBudgetIxsLabels = [];
|
|
193
197
|
this.setupIxs = [];
|
|
194
198
|
this.setupIxsLabels = [];
|
|
195
199
|
this.inBetweenIxs = [];
|
|
@@ -1920,7 +1924,11 @@ export class KaminoAction {
|
|
|
1920
1924
|
await this.addInitUserMetadataIxs();
|
|
1921
1925
|
}
|
|
1922
1926
|
|
|
1923
|
-
|
|
1927
|
+
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
1928
|
+
await this.addInitReferrerTokenStateIx(this.reserve);
|
|
1929
|
+
} if (action === 'deposit' && this.outflowReserve) { // depositAndBorrow
|
|
1930
|
+
await this.addInitReferrerTokenStateIx(this.outflowReserve);
|
|
1931
|
+
}
|
|
1924
1932
|
await this.addInitObligationIxs();
|
|
1925
1933
|
}
|
|
1926
1934
|
|
|
@@ -2361,51 +2369,33 @@ export class KaminoAction {
|
|
|
2361
2369
|
this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
|
|
2362
2370
|
}
|
|
2363
2371
|
|
|
2364
|
-
private async
|
|
2372
|
+
private async addInitReferrerTokenStateIx(reserve: KaminoReserve) {
|
|
2365
2373
|
if (this.referrer.equals(PublicKey.default)) {
|
|
2366
2374
|
return;
|
|
2367
2375
|
}
|
|
2368
2376
|
|
|
2369
|
-
const
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
? reservesArr.map((reserve) => reserve.address)
|
|
2374
|
-
: new PublicKeySet<PublicKey>([this.reserve.address, ...outflowReserve]).toArray();
|
|
2375
|
-
const tokenStatesToCreate: [PublicKey, PublicKey][] = [];
|
|
2376
|
-
for (const reserve of reserves) {
|
|
2377
|
-
if (!reserve) {
|
|
2378
|
-
continue;
|
|
2379
|
-
}
|
|
2380
|
-
|
|
2381
|
-
const referrerTokenStateAddress = referrerTokenStatePda(this.referrer, reserve, this.kaminoMarket.programId)[0];
|
|
2382
|
-
|
|
2383
|
-
if (!(await checkIfAccountExists(this.kaminoMarket.getConnection(), referrerTokenStateAddress))) {
|
|
2384
|
-
tokenStatesToCreate.push([referrerTokenStateAddress, reserve]);
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
|
|
2389
|
-
const initreferrerTokenStateIx = initReferrerTokenState(
|
|
2377
|
+
const referrerTokenState = referrerTokenStatePda(this.referrer, reserve.address, this.kaminoMarket.programId)[0];
|
|
2378
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
2379
|
+
if (!account) {
|
|
2380
|
+
const initReferrerTokenStateIx = initReferrerTokenState(
|
|
2390
2381
|
{
|
|
2391
2382
|
referrer: this.referrer,
|
|
2392
2383
|
},
|
|
2393
2384
|
{
|
|
2394
2385
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2395
2386
|
payer: this.owner,
|
|
2396
|
-
reserve:
|
|
2397
|
-
referrerTokenState
|
|
2387
|
+
reserve: reserve.address,
|
|
2388
|
+
referrerTokenState,
|
|
2398
2389
|
rent: SYSVAR_RENT_PUBKEY,
|
|
2399
2390
|
systemProgram: SystemProgram.programId,
|
|
2400
2391
|
},
|
|
2401
2392
|
this.kaminoMarket.programId
|
|
2402
2393
|
);
|
|
2403
|
-
|
|
2404
|
-
this.setupIxs.unshift(initreferrerTokenStateIx);
|
|
2394
|
+
this.setupIxs.unshift(initReferrerTokenStateIx);
|
|
2405
2395
|
this.setupIxsLabels.unshift(
|
|
2406
|
-
`InitReferrerTokenState[${
|
|
2396
|
+
`InitReferrerTokenState[${referrerTokenState.toString()} res=${reserve.address}]`
|
|
2407
2397
|
);
|
|
2408
|
-
}
|
|
2398
|
+
}
|
|
2409
2399
|
}
|
|
2410
2400
|
|
|
2411
2401
|
private addWithdrawReferrerFeesIxs() {
|
|
@@ -2435,8 +2425,8 @@ export class KaminoAction {
|
|
|
2435
2425
|
}
|
|
2436
2426
|
|
|
2437
2427
|
private addComputeBudgetIxn(units: number) {
|
|
2438
|
-
this.
|
|
2439
|
-
this.
|
|
2428
|
+
this.computeBudgetIxs.push(buildComputeBudgetIx(units));
|
|
2429
|
+
this.computeBudgetIxsLabels.push(`AddComputeBudget[${units}]`);
|
|
2440
2430
|
}
|
|
2441
2431
|
|
|
2442
2432
|
private async addAtaIxs(action: ActionType) {
|
|
@@ -2859,7 +2849,7 @@ export class KaminoAction {
|
|
|
2859
2849
|
}
|
|
2860
2850
|
|
|
2861
2851
|
public static actionToIxs(action: KaminoAction): Array<TransactionInstruction> {
|
|
2862
|
-
const ixs: TransactionInstruction[] = [...action.setupIxs];
|
|
2852
|
+
const ixs: TransactionInstruction[] = [...action.computeBudgetIxs, ...action.setupIxs];
|
|
2863
2853
|
ixs.push(...KaminoAction.actionToLendingIxs(action));
|
|
2864
2854
|
ixs.push(...action.cleanupIxs);
|
|
2865
2855
|
return ixs;
|
|
@@ -2875,4 +2865,22 @@ export class KaminoAction {
|
|
|
2875
2865
|
}
|
|
2876
2866
|
return ixs;
|
|
2877
2867
|
}
|
|
2868
|
+
|
|
2869
|
+
public static actionToIxLabels(action: KaminoAction): Array<string> {
|
|
2870
|
+
const labels: string[] = [...action.computeBudgetIxsLabels, ...action.setupIxsLabels];
|
|
2871
|
+
labels.push(...KaminoAction.actionToLendingIxLabels(action));
|
|
2872
|
+
labels.push(...action.cleanupIxsLabels);
|
|
2873
|
+
return labels;
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
public static actionToLendingIxLabels(action: KaminoAction): Array<string> {
|
|
2877
|
+
const lables: string[] = [];
|
|
2878
|
+
for (let i = 0; i < action.lendingIxsLabels.length; i++) {
|
|
2879
|
+
lables.push(action.lendingIxsLabels[i]);
|
|
2880
|
+
if (i !== action.lendingIxsLabels.length - 1) {
|
|
2881
|
+
lables.push(...action.inBetweenIxsLabels);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
return lables;
|
|
2885
|
+
}
|
|
2878
2886
|
}
|
package/src/classes/manager.ts
CHANGED
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
KaminoVaultConfig,
|
|
15
15
|
kaminoVaultId,
|
|
16
16
|
ReserveAllocationConfig,
|
|
17
|
+
ReserveOverview,
|
|
17
18
|
VaultHolder,
|
|
19
|
+
VaultHoldings,
|
|
18
20
|
} from './vault';
|
|
19
21
|
import {
|
|
20
22
|
AddAssetToMarketParams,
|
|
@@ -26,6 +28,7 @@ import {
|
|
|
26
28
|
initLendingMarket,
|
|
27
29
|
InitLendingMarketAccounts,
|
|
28
30
|
InitLendingMarketArgs,
|
|
31
|
+
KaminoReserve,
|
|
29
32
|
LendingMarket,
|
|
30
33
|
lendingMarketAuthPda,
|
|
31
34
|
MarketWithAddress,
|
|
@@ -318,7 +321,11 @@ export class KaminoManager {
|
|
|
318
321
|
return this._vaultClient.depositIxs(user, vault, tokenAmount);
|
|
319
322
|
}
|
|
320
323
|
|
|
321
|
-
async updateVaultConfigIx(
|
|
324
|
+
async updateVaultConfigIx(
|
|
325
|
+
vault: KaminoVault,
|
|
326
|
+
mode: VaultConfigFieldKind,
|
|
327
|
+
value: string
|
|
328
|
+
): Promise<TransactionInstruction> {
|
|
322
329
|
return this._vaultClient.updateVaultConfigIx(vault, mode, value);
|
|
323
330
|
}
|
|
324
331
|
|
|
@@ -507,6 +514,78 @@ export class KaminoManager {
|
|
|
507
514
|
return result;
|
|
508
515
|
};
|
|
509
516
|
|
|
517
|
+
/**
|
|
518
|
+
* This will return an Holdings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
|
|
519
|
+
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
520
|
+
* @param slot - current slot
|
|
521
|
+
* @param vaultReserves - 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
|
|
522
|
+
* @returns an Holdings object
|
|
523
|
+
*/
|
|
524
|
+
async getVaultHoldings(
|
|
525
|
+
vault: VaultState,
|
|
526
|
+
slot: number,
|
|
527
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
528
|
+
): Promise<VaultHoldings> {
|
|
529
|
+
return this._vaultClient.getVaultHoldings(vault, slot, vaultReserves);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* This will return an overview of each reserve that is part of the vault allocation
|
|
534
|
+
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
535
|
+
* @param slot - current slot
|
|
536
|
+
* @param vaultReserves - 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
|
|
537
|
+
* @returns a hashmap from vault reserve pubkey to ReserveOverview object
|
|
538
|
+
*/
|
|
539
|
+
async getVaultReservesDetails(
|
|
540
|
+
vault: VaultState,
|
|
541
|
+
slot: number,
|
|
542
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
543
|
+
): Promise<PubkeyHashMap<PublicKey, ReserveOverview>> {
|
|
544
|
+
return this._vaultClient.getVaultReservesDetails(vault, slot, vaultReserves);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves
|
|
549
|
+
* @param vault - the kamino vault to get APY for
|
|
550
|
+
* @param slot - current slot
|
|
551
|
+
* @param vaultReserves - 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
|
|
552
|
+
* @returns APY for the vault
|
|
553
|
+
*/
|
|
554
|
+
async getVaultTheoreticalAPY(
|
|
555
|
+
vault: VaultState,
|
|
556
|
+
slot: number,
|
|
557
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
558
|
+
): Promise<Decimal> {
|
|
559
|
+
return this._vaultClient.getVaultTheoreticalAPY(vault, slot, vaultReserves);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* This will load the onchain state for all the reserves that the vault has allocations for
|
|
564
|
+
* @param vaultState - the vault state to load reserves for
|
|
565
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
566
|
+
*/
|
|
567
|
+
async loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
|
|
568
|
+
return this._vaultClient.loadVaultReserves(vaultState);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* This will get the list of all reserve pubkeys that the vault has allocations for
|
|
573
|
+
* @param vaultState - the vault state to load reserves for
|
|
574
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
575
|
+
*/
|
|
576
|
+
getAllVaultReserves(vault: VaultState): PublicKey[] {
|
|
577
|
+
return this._vaultClient.getAllVaultReserves(vault);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* This will load the onchain state for all the reserves that the vault has allocations for
|
|
582
|
+
* @param vaultState - the vault state to load reserves for
|
|
583
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
584
|
+
*/
|
|
585
|
+
getVaultReserves(vault: VaultState): PublicKey[] {
|
|
586
|
+
return this._vaultClient.getVaultReserves(vault);
|
|
587
|
+
}
|
|
588
|
+
|
|
510
589
|
/**
|
|
511
590
|
* This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked
|
|
512
591
|
* @param kaminoVault - vault to invest from
|
package/src/classes/vault.ts
CHANGED
|
@@ -61,6 +61,7 @@ import bs58 from 'bs58';
|
|
|
61
61
|
import { getProgramAccounts } from '../utils/rpc';
|
|
62
62
|
|
|
63
63
|
export const kaminoVaultId = new PublicKey('kvauTFR8qm1dhniz6pYuBZkuene3Hfrs1VQhVRgCNrr');
|
|
64
|
+
export const kaminoVaultStagingId = new PublicKey('STkvh7ostar39Fwr4uZKASs1RNNuYMFMTsE77FiRsL2');
|
|
64
65
|
|
|
65
66
|
const TOKEN_VAULT_SEED = 'token_vault';
|
|
66
67
|
const CTOKEN_VAULT_SEED = 'ctoken_vault';
|
|
@@ -391,7 +392,12 @@ export class KaminoVaultClient {
|
|
|
391
392
|
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
392
393
|
* @returns - an array of instructions to be used to be executed
|
|
393
394
|
*/
|
|
394
|
-
async depositIxs(
|
|
395
|
+
async depositIxs(
|
|
396
|
+
user: PublicKey,
|
|
397
|
+
vault: KaminoVault,
|
|
398
|
+
tokenAmount: Decimal,
|
|
399
|
+
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
400
|
+
): Promise<TransactionInstruction[]> {
|
|
395
401
|
const vaultState = await vault.getState(this._connection);
|
|
396
402
|
|
|
397
403
|
const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user);
|
|
@@ -450,7 +456,7 @@ export class KaminoVaultClient {
|
|
|
450
456
|
|
|
451
457
|
const vaultReserves = this.getVaultReserves(vaultState);
|
|
452
458
|
|
|
453
|
-
const vaultReservesState = await this.loadVaultReserves(vaultState);
|
|
459
|
+
const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
|
|
454
460
|
|
|
455
461
|
let vaultReservesAccountMetas: AccountMeta[] = [];
|
|
456
462
|
let vaultReservesLendingMarkets: AccountMeta[] = [];
|
|
@@ -983,13 +989,32 @@ export class KaminoVaultClient {
|
|
|
983
989
|
return reserveAllocationAvailableLiquidityToWithdraw;
|
|
984
990
|
}
|
|
985
991
|
|
|
986
|
-
|
|
992
|
+
/**
|
|
993
|
+
* This will get the list of all reserve pubkeys that the vault has allocations for
|
|
994
|
+
* @param vaultState - the vault state to load reserves for
|
|
995
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
996
|
+
*/
|
|
997
|
+
getAllVaultReserves(vault: VaultState): PublicKey[] {
|
|
998
|
+
return vault.vaultAllocationStrategy.map((vaultAllocation) => vaultAllocation.reserve);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* This will get the list of all reserve pubkeys that the vault has allocations for ex
|
|
1003
|
+
* @param vaultState - the vault state to load reserves for
|
|
1004
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
1005
|
+
*/
|
|
1006
|
+
getVaultReserves(vault: VaultState): PublicKey[] {
|
|
987
1007
|
return vault.vaultAllocationStrategy
|
|
988
1008
|
.filter((vaultAllocation) => !vaultAllocation.reserve.equals(PublicKey.default))
|
|
989
1009
|
.map((vaultAllocation) => vaultAllocation.reserve);
|
|
990
1010
|
}
|
|
991
1011
|
|
|
992
|
-
|
|
1012
|
+
/**
|
|
1013
|
+
* This will load the onchain state for all the reserves that the vault has allocations for
|
|
1014
|
+
* @param vaultState - the vault state to load reserves for
|
|
1015
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
1016
|
+
*/
|
|
1017
|
+
async loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
|
|
993
1018
|
const vaultReservesAddresses = this.getVaultReserves(vaultState);
|
|
994
1019
|
const reserveAccounts = await this._connection.getMultipleAccountsInfo(vaultReservesAddresses, 'processed');
|
|
995
1020
|
|
|
@@ -1026,6 +1051,122 @@ export class KaminoVaultClient {
|
|
|
1026
1051
|
|
|
1027
1052
|
return kaminoReserves;
|
|
1028
1053
|
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* This will return an Holdings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
|
|
1057
|
+
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
1058
|
+
* @param slot - current slot
|
|
1059
|
+
* @param vaultReserves - 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
|
|
1060
|
+
* @returns an Holdings object
|
|
1061
|
+
*/
|
|
1062
|
+
async getVaultHoldings(
|
|
1063
|
+
vault: VaultState,
|
|
1064
|
+
slot: number,
|
|
1065
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
1066
|
+
): Promise<VaultHoldings> {
|
|
1067
|
+
const vaultHoldings: VaultHoldings = {
|
|
1068
|
+
available: new Decimal(vault.tokenAvailable.toString()),
|
|
1069
|
+
invested: new Decimal(0),
|
|
1070
|
+
investedInReserves: new PubkeyHashMap<PublicKey, Decimal>(),
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
|
|
1074
|
+
|
|
1075
|
+
vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
|
|
1076
|
+
if (allocationStrategy.reserve.equals(PublicKey.default)) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
const reserve = vaultReservesState.get(allocationStrategy.reserve);
|
|
1081
|
+
if (reserve === undefined) {
|
|
1082
|
+
throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
const reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(slot, 0);
|
|
1086
|
+
const reserveAllocationLiquidityAmount = new Decimal(allocationStrategy.cTokenAllocation.toString()).mul(
|
|
1087
|
+
reserveCollExchangeRate
|
|
1088
|
+
);
|
|
1089
|
+
|
|
1090
|
+
vaultHoldings.invested = vaultHoldings.invested.add(reserveAllocationLiquidityAmount);
|
|
1091
|
+
vaultHoldings.investedInReserves.set(allocationStrategy.reserve, reserveAllocationLiquidityAmount);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
return vaultHoldings;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* This will return an overview of each reserve that is part of the vault allocation
|
|
1099
|
+
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
1100
|
+
* @param slot - current slot
|
|
1101
|
+
* @param vaultReserves - 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
|
|
1102
|
+
* @returns a hashmap from vault reserve pubkey to ReserveOverview object
|
|
1103
|
+
*/
|
|
1104
|
+
async getVaultReservesDetails(
|
|
1105
|
+
vault: VaultState,
|
|
1106
|
+
slot: number,
|
|
1107
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
1108
|
+
): Promise<PubkeyHashMap<PublicKey, ReserveOverview>> {
|
|
1109
|
+
const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
|
|
1110
|
+
const reservesDetails = new PubkeyHashMap<PublicKey, ReserveOverview>();
|
|
1111
|
+
|
|
1112
|
+
vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
|
|
1113
|
+
if (allocationStrategy.reserve.equals(PublicKey.default)) {
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
const reserve = vaultReservesState.get(allocationStrategy.reserve);
|
|
1118
|
+
if (reserve === undefined) {
|
|
1119
|
+
throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
reserve.getBorrowedAmount();
|
|
1123
|
+
const reserveOverview: ReserveOverview = {
|
|
1124
|
+
supplyAPY: new Decimal(reserve.totalSupplyAPY(slot)),
|
|
1125
|
+
uUtilizationRatio: new Decimal(reserve.getEstimatedUtilizationRatio(slot, 0)),
|
|
1126
|
+
liquidationThresholdPct: new Decimal(reserve.state.config.liquidationThresholdPct),
|
|
1127
|
+
borrowedAmount: reserve.getBorrowedAmount(),
|
|
1128
|
+
};
|
|
1129
|
+
reservesDetails.set(allocationStrategy.reserve, reserveOverview);
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
return reservesDetails;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves
|
|
1137
|
+
* @param vault - the kamino vault to get APY for
|
|
1138
|
+
* @param slot - current slot
|
|
1139
|
+
* @param vaultReserves - 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
|
|
1140
|
+
* @returns APY for the vault
|
|
1141
|
+
*/
|
|
1142
|
+
async getVaultTheoreticalAPY(
|
|
1143
|
+
vault: VaultState,
|
|
1144
|
+
slot: number,
|
|
1145
|
+
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
1146
|
+
): Promise<Decimal> {
|
|
1147
|
+
const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
|
|
1148
|
+
|
|
1149
|
+
let totalWeights = new Decimal(0);
|
|
1150
|
+
let totalAPY = new Decimal(0);
|
|
1151
|
+
vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
|
|
1152
|
+
if (allocationStrategy.reserve.equals(PublicKey.default)) {
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
const reserve = vaultReservesState.get(allocationStrategy.reserve);
|
|
1157
|
+
if (reserve === undefined) {
|
|
1158
|
+
throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
const reserveAPY = new Decimal(reserve.totalSupplyAPY(slot));
|
|
1162
|
+
const weight = new Decimal(allocationStrategy.targetAllocationWeight.toString());
|
|
1163
|
+
const weightedAPY = reserveAPY.mul(weight);
|
|
1164
|
+
totalAPY = totalAPY.add(weightedAPY);
|
|
1165
|
+
totalWeights = totalWeights.add(weight);
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
return totalAPY.div(totalWeights);
|
|
1169
|
+
}
|
|
1029
1170
|
} // KaminoVaultClient
|
|
1030
1171
|
|
|
1031
1172
|
export class KaminoVault {
|
|
@@ -1134,3 +1275,16 @@ export type VaultHolder = {
|
|
|
1134
1275
|
holderPubkey: PublicKey;
|
|
1135
1276
|
amount: Decimal;
|
|
1136
1277
|
};
|
|
1278
|
+
|
|
1279
|
+
export type VaultHoldings = {
|
|
1280
|
+
available: Decimal;
|
|
1281
|
+
invested: Decimal;
|
|
1282
|
+
investedInReserves: PubkeyHashMap<PublicKey, Decimal>;
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
export type ReserveOverview = {
|
|
1286
|
+
supplyAPY: Decimal;
|
|
1287
|
+
uUtilizationRatio: Decimal;
|
|
1288
|
+
liquidationThresholdPct: Decimal;
|
|
1289
|
+
borrowedAmount: Decimal;
|
|
1290
|
+
};
|