@kamino-finance/klend-sdk 5.11.7 → 5.11.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 +12 -2
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +225 -30
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.js +1 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/vault.js +6 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +26 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +27 -0
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +58 -0
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/seeds.d.ts +11 -1
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +13 -3
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.js +6 -6
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +358 -50
- package/src/classes/manager.ts +1 -1
- package/src/classes/obligation.ts +1 -1
- package/src/classes/vault.ts +1 -1
- package/src/lending_operations/repay_with_collateral_calcs.ts +14 -5
- package/src/lending_operations/repay_with_collateral_operations.ts +63 -20
- package/src/utils/lookupTable.ts +62 -0
- package/src/utils/seeds.ts +14 -4
- package/src/utils/userMetadata.ts +14 -14
- package/dist/classes/lut_utils.d.ts +0 -29
- package/dist/classes/lut_utils.d.ts.map +0 -1
- package/dist/classes/lut_utils.js +0 -62
- package/dist/classes/lut_utils.js.map +0 -1
- package/src/classes/lut_utils.ts +0 -63
|
@@ -2,6 +2,7 @@ import Decimal from 'decimal.js';
|
|
|
2
2
|
import { KaminoMarket, KaminoObligation, KaminoReserve, numberToLamportsDecimal } from '../classes';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { lamportsToDecimal } from '../classes/utils';
|
|
5
|
+
import { MaxWithdrawLtvCheck, getMaxWithdrawLtvCheck } from './repay_with_collateral_operations';
|
|
5
6
|
|
|
6
7
|
export function calcRepayAmountWithSlippage(
|
|
7
8
|
kaminoMarket: KaminoMarket,
|
|
@@ -102,6 +103,7 @@ export function calcMaxWithdrawCollateral(
|
|
|
102
103
|
.filter((p) => !p.reserveAddress.equals(borrow.reserveAddress))
|
|
103
104
|
.reduce((acc, b) => acc.add(b.marketValueRefreshed), new Decimal('0'));
|
|
104
105
|
}
|
|
106
|
+
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
105
107
|
|
|
106
108
|
let remainingDepositsValueWithLtv = new Decimal('0');
|
|
107
109
|
if (obligation.getDeposits().length > 1) {
|
|
@@ -109,8 +111,13 @@ export function calcMaxWithdrawCollateral(
|
|
|
109
111
|
.getDeposits()
|
|
110
112
|
.filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
|
|
111
113
|
.reduce((acc, d) => {
|
|
112
|
-
const { maxLtv } = obligation.getLtvForReserve(
|
|
113
|
-
|
|
114
|
+
const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
|
|
115
|
+
market,
|
|
116
|
+
market.getReserveByAddress(d.reserveAddress)!
|
|
117
|
+
);
|
|
118
|
+
const maxWithdrawLtv =
|
|
119
|
+
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
|
|
120
|
+
return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
|
|
114
121
|
}, new Decimal('0'));
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -123,16 +130,18 @@ export function calcMaxWithdrawCollateral(
|
|
|
123
130
|
repayingAllDebt: repayAmountLamports.gte(borrow.amount),
|
|
124
131
|
};
|
|
125
132
|
} else {
|
|
126
|
-
const { maxLtv: collMaxLtv } = obligation.getLtvForReserve(
|
|
133
|
+
const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
|
|
127
134
|
market,
|
|
128
135
|
market.getReserveByAddress(depositReserve.address)!
|
|
129
136
|
);
|
|
137
|
+
const maxWithdrawLtv =
|
|
138
|
+
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
|
|
130
139
|
const numerator = deposit.marketValueRefreshed
|
|
131
|
-
.mul(
|
|
140
|
+
.mul(maxWithdrawLtv)
|
|
132
141
|
.add(remainingDepositsValueWithLtv)
|
|
133
142
|
.sub(remainingBorrowsValue);
|
|
134
143
|
|
|
135
|
-
const denominator = depositReserve.getOracleMarketPrice().mul(
|
|
144
|
+
const denominator = depositReserve.getOracleMarketPrice().mul(maxWithdrawLtv);
|
|
136
145
|
const maxCollWithdrawAmount = numerator.div(denominator);
|
|
137
146
|
const withdrawableCollLamports = maxCollWithdrawAmount.mul(depositReserve.getMintFactor()).floor();
|
|
138
147
|
|
|
@@ -57,6 +57,11 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
|
|
|
57
57
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
export enum MaxWithdrawLtvCheck {
|
|
61
|
+
MAX_LTV,
|
|
62
|
+
LIQUIDATION_THRESHOLD,
|
|
63
|
+
}
|
|
64
|
+
|
|
60
65
|
export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
61
66
|
collTokenMint,
|
|
62
67
|
currentSlot,
|
|
@@ -213,8 +218,17 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
213
218
|
const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
|
|
214
219
|
const { inputAmountLamports: collSwapInLamports } = swapInputs;
|
|
215
220
|
|
|
216
|
-
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)
|
|
217
|
-
|
|
221
|
+
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
222
|
+
|
|
223
|
+
if (!collReserve) {
|
|
224
|
+
throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
228
|
+
|
|
229
|
+
if (!debtReserve) {
|
|
230
|
+
throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
231
|
+
}
|
|
218
232
|
|
|
219
233
|
// the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
|
|
220
234
|
// there is also a chance that the tx will consume debt token from the user's ata which they would not expect
|
|
@@ -306,25 +320,48 @@ async function buildRepayWithCollateralIxs(
|
|
|
306
320
|
|
|
307
321
|
const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
|
|
308
322
|
|
|
323
|
+
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
324
|
+
|
|
309
325
|
// 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
326
|
+
let repayAndWithdrawAction;
|
|
327
|
+
if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
|
|
328
|
+
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
|
|
329
|
+
market,
|
|
330
|
+
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
331
|
+
debtReserve.getLiquidityMint(),
|
|
332
|
+
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
333
|
+
collReserve.getLiquidityMint(),
|
|
334
|
+
obligation.state.owner,
|
|
335
|
+
currentSlot,
|
|
336
|
+
obligation,
|
|
337
|
+
useV2Ixs,
|
|
338
|
+
undefined,
|
|
339
|
+
0,
|
|
340
|
+
false,
|
|
341
|
+
requestElevationGroup,
|
|
342
|
+
undefined,
|
|
343
|
+
undefined,
|
|
344
|
+
referrer
|
|
345
|
+
);
|
|
346
|
+
} else {
|
|
347
|
+
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
|
|
348
|
+
market,
|
|
349
|
+
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
350
|
+
debtReserve.getLiquidityMint(),
|
|
351
|
+
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
352
|
+
collReserve.getLiquidityMint(),
|
|
353
|
+
obligation.state.owner,
|
|
354
|
+
currentSlot,
|
|
355
|
+
obligation,
|
|
356
|
+
undefined,
|
|
357
|
+
0,
|
|
358
|
+
false,
|
|
359
|
+
requestElevationGroup,
|
|
360
|
+
undefined,
|
|
361
|
+
undefined,
|
|
362
|
+
referrer
|
|
363
|
+
);
|
|
364
|
+
}
|
|
328
365
|
|
|
329
366
|
// 4. Swap collateral to debt to repay flash loan
|
|
330
367
|
const { preActionIxs, swapIxs } = swapQuoteIxs;
|
|
@@ -341,3 +378,9 @@ async function buildRepayWithCollateralIxs(
|
|
|
341
378
|
flashRepayIxn,
|
|
342
379
|
];
|
|
343
380
|
}
|
|
381
|
+
|
|
382
|
+
export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
|
|
383
|
+
return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
|
|
384
|
+
? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
|
|
385
|
+
: MaxWithdrawLtvCheck.MAX_LTV;
|
|
386
|
+
};
|
package/src/utils/lookupTable.ts
CHANGED
|
@@ -53,3 +53,65 @@ export const extendLookupTableIxs = (
|
|
|
53
53
|
|
|
54
54
|
return extendLookupIxs;
|
|
55
55
|
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
|
|
59
|
+
* @param payer - the owner of the lookup table
|
|
60
|
+
* @param slot - the current slot
|
|
61
|
+
* @returns - the instruction to create the lookup table and its address
|
|
62
|
+
*/
|
|
63
|
+
export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
|
|
64
|
+
const [ixn, address] = AddressLookupTableProgram.createLookupTable({
|
|
65
|
+
authority: payer,
|
|
66
|
+
payer,
|
|
67
|
+
recentSlot: slot,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return [ixn, address];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* This method retuns an instruction that deactivates a lookup table, which is needed to close it
|
|
75
|
+
* @param payer - the owner of the lookup table
|
|
76
|
+
* @param lookupTable - the lookup table to deactivate
|
|
77
|
+
* @returns - the instruction to deactivate the lookup table
|
|
78
|
+
*/
|
|
79
|
+
export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
80
|
+
const ixn = AddressLookupTableProgram.deactivateLookupTable({
|
|
81
|
+
authority: payer,
|
|
82
|
+
lookupTable: lookupTable,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return ixn;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
|
|
90
|
+
* @param payer - the owner of the lookup table
|
|
91
|
+
* @param lookupTable - the lookup table to close
|
|
92
|
+
* @returns - the instruction to close the lookup table
|
|
93
|
+
*/
|
|
94
|
+
/// this require the LUT to be deactivated at least 500 blocks before
|
|
95
|
+
export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
|
|
96
|
+
const ixn = AddressLookupTableProgram.closeLookupTable({
|
|
97
|
+
authority: payer,
|
|
98
|
+
recipient: payer,
|
|
99
|
+
lookupTable: lookupTable,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return ixn;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns the accounts in a lookup table
|
|
107
|
+
* @param lookupTable - lookup table to get the accounts from
|
|
108
|
+
* @returns - an array of accounts in the lookup table
|
|
109
|
+
*/
|
|
110
|
+
export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
|
|
111
|
+
const lutState = await connection.getAddressLookupTable(lookupTable);
|
|
112
|
+
if (!lutState || !lutState.value) {
|
|
113
|
+
throw new Error(`Lookup table ${lookupTable} not found`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return lutState.value.state.addresses;
|
|
117
|
+
}
|
package/src/utils/seeds.ts
CHANGED
|
@@ -38,6 +38,10 @@ export const BASE_SEED_REFERRER_STATE = 'ref_state';
|
|
|
38
38
|
* Short url seed
|
|
39
39
|
*/
|
|
40
40
|
export const BASE_SEED_SHORT_URL = 'short_url';
|
|
41
|
+
/**
|
|
42
|
+
* Farm user state seed
|
|
43
|
+
*/
|
|
44
|
+
export const BASE_SEED_USER_STATE = 'user';
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
47
|
* User farm state seed
|
|
@@ -188,9 +192,15 @@ export function shortUrlPda(shortUrl: string, programId: PublicKey = PROGRAM_ID)
|
|
|
188
192
|
return PublicKey.findProgramAddressSync([Buffer.from(BASE_SEED_SHORT_URL), Buffer.from(shortUrl)], programId);
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Returns the PDA for the obligation farm state
|
|
197
|
+
* @param farm
|
|
198
|
+
* @param obligation
|
|
199
|
+
* @returns pda
|
|
200
|
+
*/
|
|
201
|
+
export function obligationFarmStatePda(farm: PublicKey, obligation: PublicKey) {
|
|
192
202
|
return PublicKey.findProgramAddressSync(
|
|
193
|
-
[Buffer.from(
|
|
194
|
-
|
|
195
|
-
);
|
|
203
|
+
[Buffer.from(BASE_SEED_USER_STATE), farm.toBytes(), obligation.toBytes()],
|
|
204
|
+
farmsId
|
|
205
|
+
)[0];
|
|
196
206
|
}
|
|
@@ -266,18 +266,18 @@ function getMultiplyObligationAndObligationFarmStateAddresses(
|
|
|
266
266
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
267
267
|
farmUserStates.push({
|
|
268
268
|
address: obligationFarmStatePda(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
)
|
|
269
|
+
collReserve.state.farmCollateral!,
|
|
270
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user)
|
|
271
|
+
),
|
|
272
272
|
log: 'collReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
276
276
|
farmUserStates.push({
|
|
277
277
|
address: obligationFarmStatePda(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
)
|
|
278
|
+
debtReserve.state.farmDebt!,
|
|
279
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user)
|
|
280
|
+
),
|
|
281
281
|
log: 'debtReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
282
282
|
});
|
|
283
283
|
}
|
|
@@ -309,18 +309,18 @@ function getLeverageObligationAndObligationFarmStateAddresses(
|
|
|
309
309
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
310
310
|
farmUserStates.push({
|
|
311
311
|
address: obligationFarmStatePda(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
)
|
|
312
|
+
collReserve.state.farmCollateral!,
|
|
313
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user)
|
|
314
|
+
),
|
|
315
315
|
log: 'collReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
318
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
319
319
|
farmUserStates.push({
|
|
320
320
|
address: obligationFarmStatePda(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
)
|
|
321
|
+
debtReserve.state.farmDebt!,
|
|
322
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user)
|
|
323
|
+
),
|
|
324
324
|
log: 'debtReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
325
325
|
});
|
|
326
326
|
}
|
|
@@ -341,7 +341,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
341
341
|
const borrowReserve = kaminoMarket.getReserveByMint(borrow.mintAddress)!;
|
|
342
342
|
if (!borrowReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
343
343
|
farmUserStates.push({
|
|
344
|
-
address: obligationFarmStatePda(
|
|
344
|
+
address: obligationFarmStatePda(borrowReserve.state.farmDebt!, obligation.obligationAddress),
|
|
345
345
|
log: 'debtReserve farmState for vanilla obligation: ' + obligationString,
|
|
346
346
|
});
|
|
347
347
|
}
|
|
@@ -351,7 +351,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
351
351
|
const depositReserve = kaminoMarket.getReserveByMint(deposit.mintAddress)!;
|
|
352
352
|
if (!depositReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
353
353
|
farmUserStates.push({
|
|
354
|
-
address: obligationFarmStatePda(
|
|
354
|
+
address: obligationFarmStatePda(depositReserve.state.farmCollateral!, obligation.obligationAddress),
|
|
355
355
|
log: 'collReserve farmState for vanilla obligation' + obligationString,
|
|
356
356
|
});
|
|
357
357
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
/**
|
|
3
|
-
* This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
|
|
4
|
-
* @param payer - the owner of the lookup table
|
|
5
|
-
* @param slot - the current slot
|
|
6
|
-
* @returns - the instruction to create the lookup table and its address
|
|
7
|
-
*/
|
|
8
|
-
export declare function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey];
|
|
9
|
-
/**
|
|
10
|
-
* This method retuns an instruction that deactivates a lookup table, which is needed to close it
|
|
11
|
-
* @param payer - the owner of the lookup table
|
|
12
|
-
* @param lookupTable - the lookup table to deactivate
|
|
13
|
-
* @returns - the instruction to deactivate the lookup table
|
|
14
|
-
*/
|
|
15
|
-
export declare function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction;
|
|
16
|
-
/**
|
|
17
|
-
* This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
|
|
18
|
-
* @param payer - the owner of the lookup table
|
|
19
|
-
* @param lookupTable - the lookup table to close
|
|
20
|
-
* @returns - the instruction to close the lookup table
|
|
21
|
-
*/
|
|
22
|
-
export declare function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction;
|
|
23
|
-
/**
|
|
24
|
-
* Returns the accounts in a lookup table
|
|
25
|
-
* @param lookupTable - lookup table to get the accounts from
|
|
26
|
-
* @returns - an array of accounts in the lookup table
|
|
27
|
-
*/
|
|
28
|
-
export declare function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]>;
|
|
29
|
-
//# sourceMappingURL=lut_utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lut_utils.d.ts","sourceRoot":"","sources":["../../src/classes/lut_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,UAAU,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE3G;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,sBAAsB,EAAE,SAAS,CAAC,CAQrG;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,sBAAsB,CAOxG;AAED;;;;;GAKG;AAEH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,sBAAsB,CAQnG;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAO3G"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initLookupTableIx = initLookupTableIx;
|
|
4
|
-
exports.deactivateLookupTableIx = deactivateLookupTableIx;
|
|
5
|
-
exports.closeLookupTableIx = closeLookupTableIx;
|
|
6
|
-
exports.getAccountsInLUT = getAccountsInLUT;
|
|
7
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
-
/**
|
|
9
|
-
* This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
|
|
10
|
-
* @param payer - the owner of the lookup table
|
|
11
|
-
* @param slot - the current slot
|
|
12
|
-
* @returns - the instruction to create the lookup table and its address
|
|
13
|
-
*/
|
|
14
|
-
function initLookupTableIx(payer, slot) {
|
|
15
|
-
const [ixn, address] = web3_js_1.AddressLookupTableProgram.createLookupTable({
|
|
16
|
-
authority: payer,
|
|
17
|
-
payer,
|
|
18
|
-
recentSlot: slot,
|
|
19
|
-
});
|
|
20
|
-
return [ixn, address];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* This method retuns an instruction that deactivates a lookup table, which is needed to close it
|
|
24
|
-
* @param payer - the owner of the lookup table
|
|
25
|
-
* @param lookupTable - the lookup table to deactivate
|
|
26
|
-
* @returns - the instruction to deactivate the lookup table
|
|
27
|
-
*/
|
|
28
|
-
function deactivateLookupTableIx(payer, lookupTable) {
|
|
29
|
-
const ixn = web3_js_1.AddressLookupTableProgram.deactivateLookupTable({
|
|
30
|
-
authority: payer,
|
|
31
|
-
lookupTable: lookupTable,
|
|
32
|
-
});
|
|
33
|
-
return ixn;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
|
|
37
|
-
* @param payer - the owner of the lookup table
|
|
38
|
-
* @param lookupTable - the lookup table to close
|
|
39
|
-
* @returns - the instruction to close the lookup table
|
|
40
|
-
*/
|
|
41
|
-
/// this require the LUT to be deactivated at least 500 blocks before
|
|
42
|
-
function closeLookupTableIx(payer, lookupTable) {
|
|
43
|
-
const ixn = web3_js_1.AddressLookupTableProgram.closeLookupTable({
|
|
44
|
-
authority: payer,
|
|
45
|
-
recipient: payer,
|
|
46
|
-
lookupTable: lookupTable,
|
|
47
|
-
});
|
|
48
|
-
return ixn;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns the accounts in a lookup table
|
|
52
|
-
* @param lookupTable - lookup table to get the accounts from
|
|
53
|
-
* @returns - an array of accounts in the lookup table
|
|
54
|
-
*/
|
|
55
|
-
async function getAccountsInLUT(connection, lookupTable) {
|
|
56
|
-
const lutState = await connection.getAddressLookupTable(lookupTable);
|
|
57
|
-
if (!lutState || !lutState.value) {
|
|
58
|
-
throw new Error(`Lookup table ${lookupTable} not found`);
|
|
59
|
-
}
|
|
60
|
-
return lutState.value.state.addresses;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=lut_utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lut_utils.js","sourceRoot":"","sources":["../../src/classes/lut_utils.ts"],"names":[],"mappings":";;AAQA,8CAQC;AAQD,0DAOC;AASD,gDAQC;AAOD,4CAOC;AA9DD,6CAA2G;AAE3G;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAgB,EAAE,IAAY;IAC9D,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,mCAAyB,CAAC,iBAAiB,CAAC;QACjE,SAAS,EAAE,KAAK;QAChB,KAAK;QACL,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,KAAgB,EAAE,WAAsB;IAC9E,MAAM,GAAG,GAAG,mCAAyB,CAAC,qBAAqB,CAAC;QAC1D,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,WAAW;KACzB,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,qEAAqE;AACrE,SAAgB,kBAAkB,CAAC,KAAgB,EAAE,WAAsB;IACzE,MAAM,GAAG,GAAG,mCAAyB,CAAC,gBAAgB,CAAC;QACrD,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,WAAW;KACzB,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,gBAAgB,CAAC,UAAsB,EAAE,WAAsB;IACnF,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;IACrE,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,WAAW,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC;AACxC,CAAC"}
|
package/src/classes/lut_utils.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
}
|