@kamino-finance/klend-sdk 6.0.5-beta.5 → 6.0.5-beta.8
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 +1 -1
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +28 -13
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +29 -18
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +65 -47
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +2 -3
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +8 -9
- package/dist/classes/market.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +30 -22
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/leverage/operations.d.ts +3 -2
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +17 -12
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +1 -0
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -2
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +9 -9
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +2 -2
- package/dist/utils/oracle.d.ts.map +1 -1
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/pubkey.d.ts +1 -0
- package/dist/utils/pubkey.d.ts.map +1 -1
- package/dist/utils/pubkey.js +10 -0
- package/dist/utils/pubkey.js.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +28 -12
- package/src/classes/manager.ts +80 -51
- package/src/classes/market.ts +14 -19
- package/src/client.ts +4 -4
- package/src/client_kamino_manager.ts +40 -35
- package/src/leverage/operations.ts +21 -14
- package/src/leverage/types.ts +1 -0
- package/src/utils/managerTypes.ts +1 -2
- package/src/utils/oracle.ts +2 -2
- package/src/utils/pubkey.ts +9 -0
|
@@ -52,18 +52,18 @@ import {
|
|
|
52
52
|
TokenInfo,
|
|
53
53
|
WithdrawalCaps,
|
|
54
54
|
} from './idl_codegen/types';
|
|
55
|
-
import { Fraction } from './classes
|
|
55
|
+
import { Fraction } from './classes';
|
|
56
56
|
import Decimal from 'decimal.js';
|
|
57
57
|
import { BN } from '@coral-xyz/anchor';
|
|
58
58
|
import { PythConfiguration, SwitchboardConfiguration } from './idl_codegen_kamino_vault/types';
|
|
59
59
|
import * as fs from 'fs';
|
|
60
|
-
import { MarketWithAddress } from './utils
|
|
60
|
+
import { MarketWithAddress } from './utils';
|
|
61
61
|
import {
|
|
62
62
|
ManagementFeeBps,
|
|
63
63
|
PendingVaultAdmin,
|
|
64
64
|
PerformanceFeeBps,
|
|
65
65
|
} from './idl_codegen_kamino_vault/types/VaultConfigField';
|
|
66
|
-
import { getAccountOwner } from './utils
|
|
66
|
+
import { getAccountOwner } from './utils';
|
|
67
67
|
import { getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
68
68
|
|
|
69
69
|
dotenv.config({
|
|
@@ -157,12 +157,12 @@ async function main() {
|
|
|
157
157
|
|
|
158
158
|
console.log('reserve: ', reserve.publicKey);
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
await processTxn(env.client, env.payer, txnIxs[0], mode, 2500, [reserve]);
|
|
161
161
|
|
|
162
162
|
const [lut, createLutIxs] = await createUpdateReserveConfigLutIxs(env, marketAddress, reserve.publicKey);
|
|
163
163
|
await processTxn(env.client, env.payer, createLutIxs, mode, 2500, []);
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
await processTxn(env.client, env.payer, txnIxs[1], mode, 2500, [], 400_000, 1000, [lut]);
|
|
166
166
|
|
|
167
167
|
mode === 'execute' &&
|
|
168
168
|
console.log(
|
|
@@ -224,7 +224,7 @@ async function main() {
|
|
|
224
224
|
updateEntireConfig
|
|
225
225
|
);
|
|
226
226
|
|
|
227
|
-
|
|
227
|
+
await processTxn(env.client, env.payer, ixs, mode, 2500, [], 400_000);
|
|
228
228
|
|
|
229
229
|
mode === 'execute' && console.log('Reserve Updated with config -> ', JSON.parse(JSON.stringify(reserveConfig)));
|
|
230
230
|
});
|
|
@@ -296,7 +296,7 @@ async function main() {
|
|
|
296
296
|
|
|
297
297
|
const { vault: vaultKp, initVaultIxs: instructions } = await kaminoManager.createVaultIxs(kaminoVaultConfig);
|
|
298
298
|
|
|
299
|
-
|
|
299
|
+
await processTxn(
|
|
300
300
|
env.client,
|
|
301
301
|
env.payer,
|
|
302
302
|
[...instructions.createAtaIfNeededIxs, ...instructions.initVaultIxs, instructions.createLUTIx],
|
|
@@ -305,7 +305,7 @@ async function main() {
|
|
|
305
305
|
[vaultKp]
|
|
306
306
|
);
|
|
307
307
|
await sleep(2000);
|
|
308
|
-
|
|
308
|
+
await processTxn(
|
|
309
309
|
env.client,
|
|
310
310
|
env.payer,
|
|
311
311
|
[...instructions.populateLUTIxs, ...instructions.cleanupIxs],
|
|
@@ -314,14 +314,7 @@ async function main() {
|
|
|
314
314
|
[]
|
|
315
315
|
);
|
|
316
316
|
|
|
317
|
-
|
|
318
|
-
env.client,
|
|
319
|
-
env.payer,
|
|
320
|
-
[instructions.initSharesMetadataIx],
|
|
321
|
-
mode,
|
|
322
|
-
2500,
|
|
323
|
-
[]
|
|
324
|
-
);
|
|
317
|
+
await processTxn(env.client, env.payer, [instructions.initSharesMetadataIx], mode, 2500, []);
|
|
325
318
|
mode === 'execute' && console.log('Vault created:', vaultKp.publicKey.toBase58());
|
|
326
319
|
});
|
|
327
320
|
|
|
@@ -1173,19 +1166,33 @@ async function main() {
|
|
|
1173
1166
|
}
|
|
1174
1167
|
});
|
|
1175
1168
|
|
|
1176
|
-
commands
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1169
|
+
commands
|
|
1170
|
+
.command('get-oracle-mappings')
|
|
1171
|
+
.requiredOption('--lending-market <string>', 'Lending Market Address')
|
|
1172
|
+
.action(async ({ lendingMarket }) => {
|
|
1173
|
+
const env = initializeClient(false, false);
|
|
1174
|
+
const kaminoManager = new KaminoManager(
|
|
1175
|
+
env.connection,
|
|
1176
|
+
DEFAULT_RECENT_SLOT_DURATION_MS,
|
|
1177
|
+
env.kLendProgramId,
|
|
1178
|
+
env.kVaultProgramId
|
|
1179
|
+
);
|
|
1180
|
+
const market = await KaminoMarket.load(
|
|
1181
|
+
env.connection,
|
|
1182
|
+
new PublicKey(lendingMarket),
|
|
1183
|
+
DEFAULT_RECENT_SLOT_DURATION_MS,
|
|
1184
|
+
env.kLendProgramId
|
|
1185
|
+
);
|
|
1186
|
+
if (!market) {
|
|
1187
|
+
throw Error(`Lending market ${lendingMarket} not found`);
|
|
1188
|
+
}
|
|
1184
1189
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1190
|
+
console.log('Getting oracle mappings');
|
|
1191
|
+
const oracleConfigs = await kaminoManager.getScopeOracleConfigs(market);
|
|
1192
|
+
for (const [oraclePrices, configs] of oracleConfigs.entries()) {
|
|
1193
|
+
console.log(`OraclePrices pubkey: ${oraclePrices.toString()}`, 'Configs:', JSON.parse(JSON.stringify(configs)));
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1189
1196
|
|
|
1190
1197
|
commands.command('get-all-vaults').action(async () => {
|
|
1191
1198
|
const env = initializeClient(false, false);
|
|
@@ -1370,7 +1377,7 @@ async function main() {
|
|
|
1370
1377
|
// executing 6 ixs in a txn to make sure they fit
|
|
1371
1378
|
for (let ixnIndex = 0; ixnIndex < ixs.length; ixnIndex += 6) {
|
|
1372
1379
|
const ixnToExecute = ixs.slice(ixnIndex, ixnIndex + 6);
|
|
1373
|
-
|
|
1380
|
+
await processTxn(env.client, env.payer, ixnToExecute, mode, 2500, [], 400_000);
|
|
1374
1381
|
}
|
|
1375
1382
|
|
|
1376
1383
|
mode === 'execute' &&
|
|
@@ -1410,7 +1417,7 @@ async function main() {
|
|
|
1410
1417
|
|
|
1411
1418
|
const ix = kaminoManager.updateLendingMarketOwnerIxs(marketWithAddress);
|
|
1412
1419
|
|
|
1413
|
-
|
|
1420
|
+
await processTxn(env.client, env.payer, [ix], mode, 2500, [], 400_000);
|
|
1414
1421
|
|
|
1415
1422
|
mode === 'execute' &&
|
|
1416
1423
|
console.log(
|
|
@@ -1465,7 +1472,7 @@ async function main() {
|
|
|
1465
1472
|
|
|
1466
1473
|
const ixs = kaminoManager.updateLendingMarketIxs(marketWithAddress, newLendingMarket);
|
|
1467
1474
|
|
|
1468
|
-
|
|
1475
|
+
await processTxn(env.client, env.payer, ixs, mode, 2500, [], 400_000);
|
|
1469
1476
|
|
|
1470
1477
|
mode === 'execute' &&
|
|
1471
1478
|
console.log(
|
|
@@ -1520,7 +1527,7 @@ async function main() {
|
|
|
1520
1527
|
|
|
1521
1528
|
const ixs = await kaminoManager.updateReserveIxs(marketWithAddress, reserveAddress, newReserveConfig);
|
|
1522
1529
|
|
|
1523
|
-
|
|
1530
|
+
await processTxn(env.client, env.payer, ixs, mode, 2500, [], 400_000);
|
|
1524
1531
|
|
|
1525
1532
|
mode === 'execute' &&
|
|
1526
1533
|
console.log(
|
|
@@ -1811,9 +1818,7 @@ function parseBorrowRateCurve(reserveConfigFromFile: any): BorrowRateCurve {
|
|
|
1811
1818
|
|
|
1812
1819
|
curvePoints.forEach((curvePoint, index) => (finalCurvePoints[index] = curvePoint));
|
|
1813
1820
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
return borrowRateCurve;
|
|
1821
|
+
return new BorrowRateCurve({ points: finalCurvePoints });
|
|
1817
1822
|
}
|
|
1818
1823
|
|
|
1819
1824
|
function parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile: any): BN[] {
|
|
@@ -71,6 +71,8 @@ import {
|
|
|
71
71
|
FlashLoanInfo,
|
|
72
72
|
} from './types';
|
|
73
73
|
|
|
74
|
+
export const WITHDRAW_SLOT_OFFSET = 150; // Offset for the withdraw slot to ensure it is after the deposit slot
|
|
75
|
+
|
|
74
76
|
export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
75
77
|
owner,
|
|
76
78
|
kaminoMarket,
|
|
@@ -951,6 +953,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
951
953
|
isKtoken,
|
|
952
954
|
quoter,
|
|
953
955
|
useV2Ixs,
|
|
956
|
+
withdrawSlotOffset,
|
|
954
957
|
}: AdjustLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
955
958
|
swapInputs: SwapInputs;
|
|
956
959
|
flashLoanInfo: FlashLoanInfo;
|
|
@@ -1138,7 +1141,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1138
1141
|
},
|
|
1139
1142
|
],
|
|
1140
1143
|
budgetAndPriorityFeeIxs,
|
|
1141
|
-
useV2Ixs
|
|
1144
|
+
useV2Ixs,
|
|
1145
|
+
withdrawSlotOffset
|
|
1142
1146
|
)
|
|
1143
1147
|
)[0];
|
|
1144
1148
|
|
|
@@ -1227,6 +1231,7 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1227
1231
|
quoter,
|
|
1228
1232
|
swapper,
|
|
1229
1233
|
useV2Ixs,
|
|
1234
|
+
withdrawSlotOffset,
|
|
1230
1235
|
}: AdjustLeverageProps<QuoteResponse>): Promise<Array<AdjustLeverageIxsResponse<QuoteResponse>>> {
|
|
1231
1236
|
const { swapInputs, initialInputs } = await getAdjustLeverageSwapInputs({
|
|
1232
1237
|
owner,
|
|
@@ -1346,7 +1351,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1346
1351
|
};
|
|
1347
1352
|
}),
|
|
1348
1353
|
budgetAndPriorityFeeIxs,
|
|
1349
|
-
useV2Ixs
|
|
1354
|
+
useV2Ixs,
|
|
1355
|
+
withdrawSlotOffset
|
|
1350
1356
|
);
|
|
1351
1357
|
|
|
1352
1358
|
return decreaseLeverageIxs.map((ixs, index) => {
|
|
@@ -1507,7 +1513,8 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1507
1513
|
collIsKtoken: boolean,
|
|
1508
1514
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
1509
1515
|
budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
|
|
1510
|
-
useV2Ixs: boolean
|
|
1516
|
+
useV2Ixs: boolean,
|
|
1517
|
+
withdrawSlotOffset: number = WITHDRAW_SLOT_OFFSET
|
|
1511
1518
|
): Promise<LeverageIxsOutput[]> {
|
|
1512
1519
|
const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
|
|
1513
1520
|
const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
|
|
@@ -1583,6 +1590,7 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1583
1590
|
referrer
|
|
1584
1591
|
);
|
|
1585
1592
|
|
|
1593
|
+
const withdrawSlot = currentSlot - withdrawSlotOffset;
|
|
1586
1594
|
// 6. Withdraw collateral (a little bit more to be able to pay for the slippage on swap)
|
|
1587
1595
|
const withdrawAction = await KaminoAction.buildWithdrawTxns(
|
|
1588
1596
|
kaminoMarket,
|
|
@@ -1597,7 +1605,7 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1597
1605
|
false,
|
|
1598
1606
|
{ skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1599
1607
|
referrer,
|
|
1600
|
-
|
|
1608
|
+
withdrawSlot
|
|
1601
1609
|
);
|
|
1602
1610
|
|
|
1603
1611
|
return swapQuoteIxsArray.map((swapQuoteIxs) => {
|
|
@@ -1685,18 +1693,17 @@ export const getScopeRefreshIx = async (
|
|
|
1685
1693
|
debtReserve.address,
|
|
1686
1694
|
]).toArray()
|
|
1687
1695
|
: new PublicKeySet<PublicKey>([collReserve.address, debtReserve.address]).toArray();
|
|
1688
|
-
const tokenIds = getTokenIdsForScopeRefresh(market, allReserves);
|
|
1689
1696
|
|
|
1690
1697
|
const scopeRefreshIxs: TransactionInstruction[] = [];
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
tokenIds
|
|
1698
|
-
|
|
1699
|
-
|
|
1698
|
+
const scopeTokensMap = getTokenIdsForScopeRefresh(market, allReserves);
|
|
1699
|
+
|
|
1700
|
+
if (scopeTokensMap.size > 0 && scopeRefreshConfig) {
|
|
1701
|
+
for (const [configPubkey, config] of scopeRefreshConfig.scopeConfigurations) {
|
|
1702
|
+
const tokenIds = scopeTokensMap.get(config.oraclePrices);
|
|
1703
|
+
if (tokenIds && tokenIds.length > 0) {
|
|
1704
|
+
scopeRefreshIxs.push(await scopeRefreshConfig.scope.refreshPriceListIx({ config: configPubkey }, tokenIds));
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1700
1707
|
}
|
|
1701
1708
|
|
|
1702
1709
|
return scopeRefreshIxs;
|
package/src/leverage/types.ts
CHANGED
|
@@ -188,6 +188,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> extends BaseLevera
|
|
|
188
188
|
priceCollToDebt: Decimal;
|
|
189
189
|
priceDebtToColl: Decimal;
|
|
190
190
|
priceAinB: PriceAinBProvider;
|
|
191
|
+
withdrawSlotOffset?: number;
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
WithdrawalCaps,
|
|
14
14
|
} from '../idl_codegen/types';
|
|
15
15
|
import Decimal from 'decimal.js';
|
|
16
|
-
import { Fraction, ZERO_FRACTION } from '../classes
|
|
16
|
+
import { Fraction, ZERO_FRACTION } from '../classes';
|
|
17
17
|
import BN from 'bn.js';
|
|
18
18
|
import { numberToLamportsDecimal } from '../classes';
|
|
19
19
|
import { NULL_PUBKEY } from './pubkey';
|
|
@@ -21,7 +21,6 @@ import { OracleType, U16_MAX } from '@kamino-finance/scope-sdk';
|
|
|
21
21
|
import { LendingMarket } from '../lib';
|
|
22
22
|
|
|
23
23
|
export type ScopeOracleConfig = {
|
|
24
|
-
scopePriceConfigAddress: PublicKey;
|
|
25
24
|
name: string;
|
|
26
25
|
oracleType: string;
|
|
27
26
|
oracleId: number;
|
package/src/utils/oracle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AccountInfo, Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
3
|
+
import { Configuration, OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
4
4
|
import { isNotNullPubkey, PubkeyHashMap, PublicKeySet } from './pubkey';
|
|
5
5
|
import { parseTokenSymbol } from '../classes';
|
|
6
6
|
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
@@ -37,7 +37,7 @@ export type CandidatePrice = {
|
|
|
37
37
|
|
|
38
38
|
export type ScopePriceRefreshConfig = {
|
|
39
39
|
scope: Scope;
|
|
40
|
-
|
|
40
|
+
scopeConfigurations: [PublicKey, Configuration][];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export function getTokenOracleDataSync(
|
package/src/utils/pubkey.ts
CHANGED
|
@@ -253,6 +253,15 @@ export class PubkeyHashMap<K extends PublicKey, V> implements Map<K, V> {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
export function setOrAppend<K, V>(map: Map<K, V[]>, key: K, value: V): void {
|
|
257
|
+
const existing = map.get(key);
|
|
258
|
+
if (existing) {
|
|
259
|
+
existing.push(value);
|
|
260
|
+
} else {
|
|
261
|
+
map.set(key, [value]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
256
265
|
export class HashablePublicKey extends PublicKey implements IEquality<HashablePublicKey> {
|
|
257
266
|
// We only use the last 32 bits of the public key for hashing
|
|
258
267
|
static MASK = new BN(1).shln(32).subn(1);
|