@kamino-finance/klend-sdk 5.11.1 → 5.11.2-beta.0
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 +245 -29
- package/dist/classes/action.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 +378 -49
- 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
|
|
|
@@ -56,6 +56,11 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
|
|
|
56
56
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
export enum MaxWithdrawLtvCheck {
|
|
60
|
+
MAX_LTV,
|
|
61
|
+
LIQUIDATION_THRESHOLD,
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
60
65
|
collTokenMint,
|
|
61
66
|
currentSlot,
|
|
@@ -212,8 +217,17 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
212
217
|
const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
|
|
213
218
|
const { inputAmountLamports: collSwapInLamports } = swapInputs;
|
|
214
219
|
|
|
215
|
-
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)
|
|
216
|
-
|
|
220
|
+
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
221
|
+
|
|
222
|
+
if (!collReserve) {
|
|
223
|
+
throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
227
|
+
|
|
228
|
+
if (!debtReserve) {
|
|
229
|
+
throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
230
|
+
}
|
|
217
231
|
|
|
218
232
|
// the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
|
|
219
233
|
// there is also a chance that the tx will consume debt token from the user's ata which they would not expect
|
|
@@ -303,25 +317,48 @@ async function buildRepayWithCollateralIxs(
|
|
|
303
317
|
|
|
304
318
|
const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
|
|
305
319
|
|
|
320
|
+
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
321
|
+
|
|
306
322
|
// 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
let repayAndWithdrawAction;
|
|
324
|
+
if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
|
|
325
|
+
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
|
|
326
|
+
market,
|
|
327
|
+
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
328
|
+
debtReserve.getLiquidityMint(),
|
|
329
|
+
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
330
|
+
collReserve.getLiquidityMint(),
|
|
331
|
+
obligation.state.owner,
|
|
332
|
+
currentSlot,
|
|
333
|
+
obligation,
|
|
334
|
+
useV2Ixs,
|
|
335
|
+
0,
|
|
336
|
+
false,
|
|
337
|
+
requestElevationGroup,
|
|
338
|
+
undefined,
|
|
339
|
+
undefined,
|
|
340
|
+
referrer,
|
|
341
|
+
scopeRefresh
|
|
342
|
+
);
|
|
343
|
+
} else {
|
|
344
|
+
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
|
|
345
|
+
market,
|
|
346
|
+
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
347
|
+
debtReserve.getLiquidityMint(),
|
|
348
|
+
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
349
|
+
collReserve.getLiquidityMint(),
|
|
350
|
+
obligation.state.owner,
|
|
351
|
+
currentSlot,
|
|
352
|
+
obligation,
|
|
353
|
+
0,
|
|
354
|
+
false,
|
|
355
|
+
requestElevationGroup,
|
|
356
|
+
undefined,
|
|
357
|
+
undefined,
|
|
358
|
+
referrer,
|
|
359
|
+
scopeRefresh
|
|
360
|
+
);
|
|
361
|
+
}
|
|
325
362
|
|
|
326
363
|
// 4. Swap collateral to debt to repay flash loan
|
|
327
364
|
const { preActionIxs, swapIxs } = swapQuoteIxs;
|
|
@@ -337,3 +374,9 @@ async function buildRepayWithCollateralIxs(
|
|
|
337
374
|
flashRepayIxn,
|
|
338
375
|
];
|
|
339
376
|
}
|
|
377
|
+
|
|
378
|
+
export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
|
|
379
|
+
return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
|
|
380
|
+
? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
|
|
381
|
+
: MaxWithdrawLtvCheck.MAX_LTV;
|
|
382
|
+
};
|
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
|
}
|
|
@@ -267,18 +267,18 @@ function getMultiplyObligationAndObligationFarmStateAddresses(
|
|
|
267
267
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
268
268
|
farmUserStates.push({
|
|
269
269
|
address: obligationFarmStatePda(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
)
|
|
270
|
+
collReserve.state.farmCollateral!,
|
|
271
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user)
|
|
272
|
+
),
|
|
273
273
|
log: 'collReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
277
277
|
farmUserStates.push({
|
|
278
278
|
address: obligationFarmStatePda(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
)
|
|
279
|
+
debtReserve.state.farmDebt!,
|
|
280
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user)
|
|
281
|
+
),
|
|
282
282
|
log: 'debtReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
283
283
|
});
|
|
284
284
|
}
|
|
@@ -310,18 +310,18 @@ function getLeverageObligationAndObligationFarmStateAddresses(
|
|
|
310
310
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
311
311
|
farmUserStates.push({
|
|
312
312
|
address: obligationFarmStatePda(
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
)
|
|
313
|
+
collReserve.state.farmCollateral!,
|
|
314
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user)
|
|
315
|
+
),
|
|
316
316
|
log: 'collReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
317
317
|
});
|
|
318
318
|
}
|
|
319
319
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
320
320
|
farmUserStates.push({
|
|
321
321
|
address: obligationFarmStatePda(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
)
|
|
322
|
+
debtReserve.state.farmDebt!,
|
|
323
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user)
|
|
324
|
+
),
|
|
325
325
|
log: 'debtReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
326
326
|
});
|
|
327
327
|
}
|
|
@@ -342,7 +342,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
342
342
|
const borrowReserve = kaminoMarket.getReserveByMint(borrow.mintAddress)!;
|
|
343
343
|
if (!borrowReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
344
344
|
farmUserStates.push({
|
|
345
|
-
address: obligationFarmStatePda(
|
|
345
|
+
address: obligationFarmStatePda(borrowReserve.state.farmDebt!, obligation.obligationAddress),
|
|
346
346
|
log: 'debtReserve farmState for vanilla obligation: ' + obligationString,
|
|
347
347
|
});
|
|
348
348
|
}
|
|
@@ -352,7 +352,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
352
352
|
const depositReserve = kaminoMarket.getReserveByMint(deposit.mintAddress)!;
|
|
353
353
|
if (!depositReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
354
354
|
farmUserStates.push({
|
|
355
|
-
address: obligationFarmStatePda(
|
|
355
|
+
address: obligationFarmStatePda(depositReserve.state.farmCollateral!, obligation.obligationAddress),
|
|
356
356
|
log: 'collReserve farmState for vanilla obligation' + obligationString,
|
|
357
357
|
});
|
|
358
358
|
}
|
|
@@ -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
|
-
}
|