@kamino-finance/klend-sdk 7.3.10-beta.0 → 7.4.0-beta.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/dist/classes/action.d.ts +21 -91
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +152 -139
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +310 -0
- package/dist/classes/actionTypes.d.ts.map +1 -0
- package/dist/classes/actionTypes.js +3 -0
- package/dist/classes/actionTypes.js.map +1 -0
- package/dist/classes/configItems.d.ts +1 -6
- package/dist/classes/configItems.d.ts.map +1 -1
- package/dist/classes/configItems.js +1 -93
- package/dist/classes/configItems.js.map +1 -1
- package/dist/classes/farm_utils.d.ts +1 -1
- package/dist/classes/farm_utils.d.ts.map +1 -1
- package/dist/classes/farm_utils.js +3 -1
- package/dist/classes/farm_utils.js.map +1 -1
- package/dist/classes/market.d.ts +5 -5
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +29 -13
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +9 -9
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +48 -50
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +6 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.d.ts +7 -3
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +31 -43
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +3 -2
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +28 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +103 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/vault_types.d.ts +2 -1
- package/dist/classes/vault_types.d.ts.map +1 -1
- package/dist/client/commands/borrow.d.ts +1 -1
- package/dist/client/commands/borrow.d.ts.map +1 -1
- package/dist/client/commands/borrow.js +11 -2
- package/dist/client/commands/borrow.js.map +1 -1
- package/dist/client/commands/deposit.d.ts +1 -1
- package/dist/client/commands/deposit.d.ts.map +1 -1
- package/dist/client/commands/deposit.js +11 -2
- package/dist/client/commands/deposit.js.map +1 -1
- package/dist/client/commands/printReserve.d.ts +1 -1
- package/dist/client/commands/printReserve.d.ts.map +1 -1
- package/dist/client/commands/printReserve.js +2 -4
- package/dist/client/commands/printReserve.js.map +1 -1
- package/dist/client/commands/repay.d.ts +1 -1
- package/dist/client/commands/repay.d.ts.map +1 -1
- package/dist/client/commands/repay.js +12 -2
- package/dist/client/commands/repay.js.map +1 -1
- package/dist/client/commands/withdraw.d.ts +1 -1
- package/dist/client/commands/withdraw.d.ts.map +1 -1
- package/dist/client/commands/withdraw.js +11 -2
- package/dist/client/commands/withdraw.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +40 -21
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +6 -6
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +167 -52
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +2 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/obligation_orders/price_based.js +1 -0
- package/dist/obligation_orders/price_based.js.map +1 -1
- package/dist/utils/Logger.d.ts +14 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/ObligationType.d.ts +33 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js +81 -2
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/api.d.ts +13 -4
- package/dist/utils/api.d.ts.map +1 -1
- package/dist/utils/api.js +33 -31
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +2 -2
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +49 -25
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +346 -372
- package/src/classes/actionTypes.ts +295 -0
- package/src/classes/configItems.ts +1 -99
- package/src/classes/farm_utils.ts +5 -1
- package/src/classes/market.ts +42 -16
- package/src/classes/obligation.ts +54 -53
- package/src/classes/obligationOrder.ts +6 -3
- package/src/classes/reserve.ts +118 -122
- package/src/classes/shared.ts +4 -2
- package/src/classes/vault.ts +160 -7
- package/src/classes/vault_types.ts +2 -1
- package/src/client/client.ts +17 -18
- package/src/client/commands/borrow.ts +10 -9
- package/src/client/commands/deposit.ts +10 -9
- package/src/client/commands/printReserve.ts +2 -4
- package/src/client/commands/repay.ts +11 -10
- package/src/client/commands/withdraw.ts +15 -9
- package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
- package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
- package/src/lending_operations/swap_collateral_operations.ts +47 -41
- package/src/leverage/operations.ts +168 -129
- package/src/leverage/types.ts +2 -2
- package/src/obligation_orders/price_based.ts +1 -0
- package/src/utils/Logger.ts +14 -0
- package/src/utils/ObligationType.ts +92 -1
- package/src/utils/api.ts +56 -33
- package/src/utils/userMetadata.ts +64 -30
package/src/classes/action.ts
CHANGED
|
@@ -76,9 +76,31 @@ import { Scope } from '@kamino-finance/scope-sdk';
|
|
|
76
76
|
import { ObligationOrderAtIndex } from './obligationOrder';
|
|
77
77
|
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
78
78
|
import { SYSVAR_INSTRUCTIONS_ADDRESS, SYSVAR_RENT_ADDRESS } from '@solana/sysvars';
|
|
79
|
-
import {
|
|
79
|
+
import {
|
|
80
|
+
getCloseAccountInstruction,
|
|
81
|
+
getSyncNativeInstruction,
|
|
82
|
+
TOKEN_2022_PROGRAM_ADDRESS,
|
|
83
|
+
} from '@solana-program/token-2022';
|
|
80
84
|
import { getTransferSolInstruction, SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';
|
|
81
85
|
import { noopSigner } from '../utils/signer';
|
|
86
|
+
import {
|
|
87
|
+
BuildDepositTxnsProps,
|
|
88
|
+
BuildBorrowTxnsProps,
|
|
89
|
+
BuildDepositReserveLiquidityTxnsProps,
|
|
90
|
+
BuildRedeemReserveCollateralTxnsProps,
|
|
91
|
+
BuildWithdrawTxnsProps,
|
|
92
|
+
BuildRepayTxnsProps,
|
|
93
|
+
BuildDepositAndBorrowTxnsProps,
|
|
94
|
+
BuildRefreshObligationTxnsProps,
|
|
95
|
+
BuildRequestElevationGroupTxnsProps,
|
|
96
|
+
BuildDepositAndWithdrawV2TxnsProps,
|
|
97
|
+
BuildRepayAndWithdrawTxnsProps,
|
|
98
|
+
BuildRepayAndWithdrawV2TxnsProps,
|
|
99
|
+
BuildLiquidateTxnsProps,
|
|
100
|
+
BuildWithdrawReferrerFeeTxnsProps,
|
|
101
|
+
BuildDepositObligationCollateralTxnsProps,
|
|
102
|
+
InitializeActionProps,
|
|
103
|
+
} from './actionTypes';
|
|
82
104
|
|
|
83
105
|
export type ActionType =
|
|
84
106
|
| 'deposit'
|
|
@@ -199,20 +221,22 @@ export class KaminoAction {
|
|
|
199
221
|
this.currentSlot = currentSlot;
|
|
200
222
|
}
|
|
201
223
|
|
|
202
|
-
static async initialize(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
224
|
+
static async initialize(props: InitializeActionProps) {
|
|
225
|
+
const {
|
|
226
|
+
kaminoMarket,
|
|
227
|
+
action,
|
|
228
|
+
amount,
|
|
229
|
+
reserveAddress,
|
|
230
|
+
owner,
|
|
231
|
+
obligation,
|
|
232
|
+
referrer = none(),
|
|
233
|
+
currentSlot = 0n,
|
|
234
|
+
payer = owner,
|
|
235
|
+
} = props;
|
|
236
|
+
|
|
237
|
+
const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
|
|
214
238
|
if (reserve === undefined) {
|
|
215
|
-
throw new Error(`Reserve ${
|
|
239
|
+
throw new Error(`Reserve ${reserveAddress} not found in market ${kaminoMarket.getAddress()}`);
|
|
216
240
|
}
|
|
217
241
|
|
|
218
242
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } =
|
|
@@ -224,7 +248,7 @@ export class KaminoAction {
|
|
|
224
248
|
kaminoMarket,
|
|
225
249
|
owner,
|
|
226
250
|
kaminoObligation || obligation,
|
|
227
|
-
|
|
251
|
+
reserve.getLiquidityMint(),
|
|
228
252
|
distinctReserveCount,
|
|
229
253
|
amount,
|
|
230
254
|
depositReserves,
|
|
@@ -305,29 +329,23 @@ export class KaminoAction {
|
|
|
305
329
|
};
|
|
306
330
|
}
|
|
307
331
|
|
|
308
|
-
static async buildRefreshObligationTxns(
|
|
309
|
-
kaminoMarket
|
|
310
|
-
payer: TransactionSigner,
|
|
311
|
-
obligation: KaminoObligation,
|
|
312
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
313
|
-
currentSlot: Slot = 0n
|
|
314
|
-
) {
|
|
332
|
+
static async buildRefreshObligationTxns(props: BuildRefreshObligationTxnsProps) {
|
|
333
|
+
const { kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, currentSlot = 0n } = props;
|
|
315
334
|
// placeholder for action initialization
|
|
316
335
|
const firstReserve = obligation.getDeposits()[0].reserveAddress;
|
|
317
336
|
const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
|
|
318
337
|
if (!firstKaminoReserve) {
|
|
319
338
|
throw new Error(`Reserve ${firstReserve} not found`);
|
|
320
339
|
}
|
|
321
|
-
const axn = await KaminoAction.initialize(
|
|
322
|
-
'refreshObligation',
|
|
323
|
-
'0',
|
|
324
|
-
firstKaminoReserve?.getLiquidityMint(),
|
|
325
|
-
noopSigner(obligation.state.owner), // owner does not need to sign for refresh
|
|
340
|
+
const axn = await KaminoAction.initialize({
|
|
326
341
|
kaminoMarket,
|
|
342
|
+
action: 'refreshObligation',
|
|
343
|
+
amount: '0',
|
|
344
|
+
reserveAddress: firstKaminoReserve.address,
|
|
345
|
+
owner: noopSigner(obligation.state.owner), // owner does not need to sign for refresh
|
|
327
346
|
obligation,
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
);
|
|
347
|
+
currentSlot,
|
|
348
|
+
});
|
|
331
349
|
|
|
332
350
|
if (extraComputeBudget > 0) {
|
|
333
351
|
axn.addComputeBudgetIx(extraComputeBudget);
|
|
@@ -338,29 +356,22 @@ export class KaminoAction {
|
|
|
338
356
|
return axn;
|
|
339
357
|
}
|
|
340
358
|
|
|
341
|
-
static async buildRequestElevationGroupTxns(
|
|
342
|
-
kaminoMarket
|
|
343
|
-
owner: TransactionSigner,
|
|
344
|
-
obligation: KaminoObligation,
|
|
345
|
-
elevationGroup: number,
|
|
346
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
347
|
-
currentSlot: Slot = 0n
|
|
348
|
-
) {
|
|
359
|
+
static async buildRequestElevationGroupTxns(props: BuildRequestElevationGroupTxnsProps) {
|
|
360
|
+
const { kaminoMarket, owner, obligation, elevationGroup, extraComputeBudget = 1_000_000, currentSlot = 0n } = props;
|
|
349
361
|
const firstReserve = obligation.state.deposits.find((x) => x.depositReserve !== DEFAULT_PUBLIC_KEY)!.depositReserve;
|
|
350
362
|
const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
|
|
351
363
|
if (!firstKaminoReserve) {
|
|
352
364
|
throw new Error(`Reserve ${firstReserve} not found`);
|
|
353
365
|
}
|
|
354
|
-
const axn = await KaminoAction.initialize(
|
|
355
|
-
'requestElevationGroup',
|
|
356
|
-
'0',
|
|
357
|
-
firstKaminoReserve?.getLiquidityMint(),
|
|
358
|
-
owner,
|
|
366
|
+
const axn = await KaminoAction.initialize({
|
|
359
367
|
kaminoMarket,
|
|
368
|
+
action: 'requestElevationGroup',
|
|
369
|
+
amount: '0',
|
|
370
|
+
reserveAddress: firstKaminoReserve.address,
|
|
371
|
+
owner,
|
|
360
372
|
obligation,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
);
|
|
373
|
+
currentSlot,
|
|
374
|
+
});
|
|
364
375
|
|
|
365
376
|
if (extraComputeBudget > 0) {
|
|
366
377
|
axn.addComputeBudgetIx(extraComputeBudget);
|
|
@@ -372,35 +383,34 @@ export class KaminoAction {
|
|
|
372
383
|
return axn;
|
|
373
384
|
}
|
|
374
385
|
|
|
375
|
-
static async buildDepositTxns(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
mint: Address,
|
|
379
|
-
owner: TransactionSigner,
|
|
380
|
-
obligation: KaminoObligation | ObligationType,
|
|
381
|
-
useV2Ixs: boolean,
|
|
382
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
383
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
384
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
|
|
385
|
-
requestElevationGroup: boolean = false, // to be requested *before* the deposit
|
|
386
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
387
|
-
skipInitialization: false,
|
|
388
|
-
skipLutCreation: false,
|
|
389
|
-
},
|
|
390
|
-
referrer: Option<Address> = none(),
|
|
391
|
-
currentSlot: Slot = 0n,
|
|
392
|
-
overrideElevationGroupRequest: number | undefined = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
393
|
-
) {
|
|
394
|
-
const axn = await KaminoAction.initialize(
|
|
395
|
-
'deposit',
|
|
386
|
+
static async buildDepositTxns(props: BuildDepositTxnsProps) {
|
|
387
|
+
const {
|
|
388
|
+
kaminoMarket,
|
|
396
389
|
amount,
|
|
397
|
-
|
|
390
|
+
reserveAddress,
|
|
398
391
|
owner,
|
|
392
|
+
obligation,
|
|
393
|
+
useV2Ixs,
|
|
394
|
+
scopeRefreshConfig,
|
|
395
|
+
extraComputeBudget = 1_000_000,
|
|
396
|
+
includeAtaIxs = true,
|
|
397
|
+
requestElevationGroup = false,
|
|
398
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
399
|
+
referrer = none(),
|
|
400
|
+
currentSlot = 0n,
|
|
401
|
+
overrideElevationGroupRequest,
|
|
402
|
+
} = props;
|
|
403
|
+
|
|
404
|
+
const axn = await KaminoAction.initialize({
|
|
399
405
|
kaminoMarket,
|
|
406
|
+
action: 'deposit',
|
|
407
|
+
amount,
|
|
408
|
+
reserveAddress,
|
|
409
|
+
owner,
|
|
400
410
|
obligation,
|
|
401
411
|
referrer,
|
|
402
|
-
currentSlot
|
|
403
|
-
);
|
|
412
|
+
currentSlot,
|
|
413
|
+
});
|
|
404
414
|
const addInitObligationForFarm = true;
|
|
405
415
|
|
|
406
416
|
if (extraComputeBudget > 0) {
|
|
@@ -436,35 +446,34 @@ export class KaminoAction {
|
|
|
436
446
|
}
|
|
437
447
|
}
|
|
438
448
|
|
|
439
|
-
static async buildBorrowTxns(
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
mint: Address,
|
|
443
|
-
owner: TransactionSigner,
|
|
444
|
-
obligation: KaminoObligation | ObligationType,
|
|
445
|
-
useV2Ixs: boolean,
|
|
446
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
447
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
448
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
|
|
449
|
-
requestElevationGroup: boolean = false,
|
|
450
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
451
|
-
skipInitialization: false,
|
|
452
|
-
skipLutCreation: false,
|
|
453
|
-
},
|
|
454
|
-
referrer: Option<Address> = none(),
|
|
455
|
-
currentSlot: Slot = 0n,
|
|
456
|
-
overrideElevationGroupRequest: number | undefined = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
457
|
-
) {
|
|
458
|
-
const axn = await KaminoAction.initialize(
|
|
459
|
-
'borrow',
|
|
449
|
+
static async buildBorrowTxns(props: BuildBorrowTxnsProps) {
|
|
450
|
+
const {
|
|
451
|
+
kaminoMarket,
|
|
460
452
|
amount,
|
|
461
|
-
|
|
453
|
+
reserveAddress,
|
|
462
454
|
owner,
|
|
455
|
+
obligation,
|
|
456
|
+
useV2Ixs,
|
|
457
|
+
scopeRefreshConfig,
|
|
458
|
+
extraComputeBudget = 1_000_000,
|
|
459
|
+
includeAtaIxs = true,
|
|
460
|
+
requestElevationGroup = false,
|
|
461
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
462
|
+
referrer = none(),
|
|
463
|
+
currentSlot = 0n,
|
|
464
|
+
overrideElevationGroupRequest,
|
|
465
|
+
} = props;
|
|
466
|
+
|
|
467
|
+
const axn = await KaminoAction.initialize({
|
|
463
468
|
kaminoMarket,
|
|
469
|
+
action: 'borrow',
|
|
470
|
+
amount,
|
|
471
|
+
reserveAddress,
|
|
472
|
+
owner,
|
|
464
473
|
obligation,
|
|
465
474
|
referrer,
|
|
466
|
-
currentSlot
|
|
467
|
-
);
|
|
475
|
+
currentSlot,
|
|
476
|
+
});
|
|
468
477
|
const addInitObligationForFarm = true;
|
|
469
478
|
if (extraComputeBudget > 0) {
|
|
470
479
|
axn.addComputeBudgetIx(extraComputeBudget);
|
|
@@ -503,29 +512,31 @@ export class KaminoAction {
|
|
|
503
512
|
return axn;
|
|
504
513
|
}
|
|
505
514
|
|
|
506
|
-
static async buildDepositReserveLiquidityTxns(
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
mint: Address,
|
|
510
|
-
owner: TransactionSigner,
|
|
511
|
-
obligation: KaminoObligation | ObligationType,
|
|
512
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
513
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
514
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas
|
|
515
|
-
requestElevationGroup: boolean = false,
|
|
516
|
-
referrer: Option<Address> = none(),
|
|
517
|
-
currentSlot: Slot = 0n
|
|
518
|
-
) {
|
|
519
|
-
const axn = await KaminoAction.initialize(
|
|
520
|
-
'mint',
|
|
515
|
+
static async buildDepositReserveLiquidityTxns(props: BuildDepositReserveLiquidityTxnsProps) {
|
|
516
|
+
const {
|
|
517
|
+
kaminoMarket,
|
|
521
518
|
amount,
|
|
522
|
-
|
|
519
|
+
reserveAddress,
|
|
523
520
|
owner,
|
|
521
|
+
obligation,
|
|
522
|
+
scopeRefreshConfig,
|
|
523
|
+
extraComputeBudget = 1_000_000,
|
|
524
|
+
includeAtaIxs = true,
|
|
525
|
+
requestElevationGroup = false,
|
|
526
|
+
referrer = none(),
|
|
527
|
+
currentSlot = 0n,
|
|
528
|
+
} = props;
|
|
529
|
+
|
|
530
|
+
const axn = await KaminoAction.initialize({
|
|
524
531
|
kaminoMarket,
|
|
532
|
+
action: 'mint',
|
|
533
|
+
amount,
|
|
534
|
+
reserveAddress,
|
|
535
|
+
owner,
|
|
525
536
|
obligation,
|
|
526
537
|
referrer,
|
|
527
|
-
currentSlot
|
|
528
|
-
);
|
|
538
|
+
currentSlot,
|
|
539
|
+
});
|
|
529
540
|
const addInitObligationForFarm = true;
|
|
530
541
|
|
|
531
542
|
if (extraComputeBudget > 0) {
|
|
@@ -546,29 +557,31 @@ export class KaminoAction {
|
|
|
546
557
|
return axn;
|
|
547
558
|
}
|
|
548
559
|
|
|
549
|
-
static async buildRedeemReserveCollateralTxns(
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
mint: Address,
|
|
553
|
-
owner: TransactionSigner,
|
|
554
|
-
obligation: KaminoObligation | ObligationType,
|
|
555
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
556
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
557
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas
|
|
558
|
-
requestElevationGroup: boolean = false,
|
|
559
|
-
referrer: Option<Address> = none(),
|
|
560
|
-
currentSlot: Slot = 0n
|
|
561
|
-
) {
|
|
562
|
-
const axn = await KaminoAction.initialize(
|
|
563
|
-
'redeem',
|
|
560
|
+
static async buildRedeemReserveCollateralTxns(props: BuildRedeemReserveCollateralTxnsProps) {
|
|
561
|
+
const {
|
|
562
|
+
kaminoMarket,
|
|
564
563
|
amount,
|
|
565
|
-
|
|
564
|
+
reserveAddress,
|
|
566
565
|
owner,
|
|
566
|
+
obligation,
|
|
567
|
+
scopeRefreshConfig,
|
|
568
|
+
extraComputeBudget = 1_000_000,
|
|
569
|
+
includeAtaIxs = true,
|
|
570
|
+
requestElevationGroup = false,
|
|
571
|
+
referrer = none(),
|
|
572
|
+
currentSlot = 0n,
|
|
573
|
+
} = props;
|
|
574
|
+
|
|
575
|
+
const axn = await KaminoAction.initialize({
|
|
567
576
|
kaminoMarket,
|
|
577
|
+
action: 'redeem',
|
|
578
|
+
amount,
|
|
579
|
+
reserveAddress,
|
|
580
|
+
owner,
|
|
568
581
|
obligation,
|
|
569
582
|
referrer,
|
|
570
|
-
currentSlot
|
|
571
|
-
);
|
|
583
|
+
currentSlot,
|
|
584
|
+
});
|
|
572
585
|
const addInitObligationForFarm = true;
|
|
573
586
|
|
|
574
587
|
if (extraComputeBudget > 0) {
|
|
@@ -589,34 +602,32 @@ export class KaminoAction {
|
|
|
589
602
|
return axn;
|
|
590
603
|
}
|
|
591
604
|
|
|
592
|
-
static async buildDepositObligationCollateralTxns(
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
mint: Address,
|
|
596
|
-
owner: TransactionSigner,
|
|
597
|
-
obligation: KaminoObligation | ObligationType,
|
|
598
|
-
useV2Ixs: boolean,
|
|
599
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
600
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
601
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas
|
|
602
|
-
requestElevationGroup: boolean = false,
|
|
603
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
604
|
-
skipInitialization: false,
|
|
605
|
-
skipLutCreation: false,
|
|
606
|
-
},
|
|
607
|
-
referrer: Option<Address> = none(),
|
|
608
|
-
currentSlot: Slot = 0n
|
|
609
|
-
) {
|
|
610
|
-
const axn = await KaminoAction.initialize(
|
|
611
|
-
'depositCollateral',
|
|
605
|
+
static async buildDepositObligationCollateralTxns(props: BuildDepositObligationCollateralTxnsProps) {
|
|
606
|
+
const {
|
|
607
|
+
kaminoMarket,
|
|
612
608
|
amount,
|
|
613
|
-
|
|
609
|
+
reserveAddress,
|
|
614
610
|
owner,
|
|
611
|
+
obligation,
|
|
612
|
+
useV2Ixs,
|
|
613
|
+
scopeRefreshConfig,
|
|
614
|
+
extraComputeBudget = 1_000_000,
|
|
615
|
+
includeAtaIxs = true,
|
|
616
|
+
requestElevationGroup = false,
|
|
617
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
618
|
+
referrer = none(),
|
|
619
|
+
currentSlot = 0n,
|
|
620
|
+
} = props;
|
|
621
|
+
const axn = await KaminoAction.initialize({
|
|
615
622
|
kaminoMarket,
|
|
623
|
+
action: 'depositCollateral',
|
|
624
|
+
amount,
|
|
625
|
+
reserveAddress,
|
|
626
|
+
owner,
|
|
616
627
|
obligation,
|
|
617
628
|
referrer,
|
|
618
|
-
currentSlot
|
|
619
|
-
);
|
|
629
|
+
currentSlot,
|
|
630
|
+
});
|
|
620
631
|
const addInitObligationForFarm = true;
|
|
621
632
|
|
|
622
633
|
if (extraComputeBudget > 0) {
|
|
@@ -641,32 +652,30 @@ export class KaminoAction {
|
|
|
641
652
|
return axn;
|
|
642
653
|
}
|
|
643
654
|
|
|
644
|
-
static async buildDepositAndBorrowTxns(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
skipInitialization: false,
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
currentSlot: Slot = 0n
|
|
663
|
-
) {
|
|
655
|
+
static async buildDepositAndBorrowTxns(props: BuildDepositAndBorrowTxnsProps) {
|
|
656
|
+
const {
|
|
657
|
+
kaminoMarket,
|
|
658
|
+
depositAmount,
|
|
659
|
+
depositReserveAddress,
|
|
660
|
+
borrowAmount,
|
|
661
|
+
borrowReserveAddress,
|
|
662
|
+
owner,
|
|
663
|
+
obligation,
|
|
664
|
+
useV2Ixs,
|
|
665
|
+
scopeRefreshConfig,
|
|
666
|
+
extraComputeBudget = 1_000_000,
|
|
667
|
+
includeAtaIxs = true,
|
|
668
|
+
requestElevationGroup = false,
|
|
669
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
670
|
+
referrer = none(),
|
|
671
|
+
currentSlot = 0n,
|
|
672
|
+
} = props;
|
|
664
673
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
665
674
|
kaminoMarket,
|
|
666
675
|
'depositAndBorrow',
|
|
667
676
|
depositAmount,
|
|
668
|
-
|
|
669
|
-
|
|
677
|
+
depositReserveAddress,
|
|
678
|
+
borrowReserveAddress,
|
|
670
679
|
owner,
|
|
671
680
|
owner.address,
|
|
672
681
|
obligation,
|
|
@@ -741,31 +750,29 @@ export class KaminoAction {
|
|
|
741
750
|
return axn;
|
|
742
751
|
}
|
|
743
752
|
|
|
744
|
-
static async buildDepositAndWithdrawV2Txns(
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
skipInitialization: false,
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
referrer: Option<Address> = none()
|
|
762
|
-
) {
|
|
753
|
+
static async buildDepositAndWithdrawV2Txns(props: BuildDepositAndWithdrawV2TxnsProps) {
|
|
754
|
+
const {
|
|
755
|
+
kaminoMarket,
|
|
756
|
+
depositAmount,
|
|
757
|
+
depositReserveAddress,
|
|
758
|
+
withdrawAmount,
|
|
759
|
+
withdrawReserveAddress,
|
|
760
|
+
owner,
|
|
761
|
+
currentSlot,
|
|
762
|
+
obligation,
|
|
763
|
+
scopeRefreshConfig,
|
|
764
|
+
extraComputeBudget = 1_000_000,
|
|
765
|
+
includeAtaIxs = true,
|
|
766
|
+
requestElevationGroup = false,
|
|
767
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
768
|
+
referrer = none(),
|
|
769
|
+
} = props;
|
|
763
770
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
764
771
|
kaminoMarket,
|
|
765
772
|
'depositAndWithdraw',
|
|
766
773
|
depositAmount,
|
|
767
|
-
|
|
768
|
-
|
|
774
|
+
depositReserveAddress,
|
|
775
|
+
withdrawReserveAddress,
|
|
769
776
|
owner,
|
|
770
777
|
owner.address,
|
|
771
778
|
obligation,
|
|
@@ -795,31 +802,29 @@ export class KaminoAction {
|
|
|
795
802
|
return axn;
|
|
796
803
|
}
|
|
797
804
|
|
|
798
|
-
static async buildRepayAndWithdrawV2Txns(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
skipInitialization: false,
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
referrer: Option<Address> = none()
|
|
816
|
-
) {
|
|
805
|
+
static async buildRepayAndWithdrawV2Txns(props: BuildRepayAndWithdrawV2TxnsProps) {
|
|
806
|
+
const {
|
|
807
|
+
kaminoMarket,
|
|
808
|
+
repayAmount,
|
|
809
|
+
repayReserveAddress,
|
|
810
|
+
withdrawAmount,
|
|
811
|
+
withdrawReserveAddress,
|
|
812
|
+
payer,
|
|
813
|
+
currentSlot,
|
|
814
|
+
obligation,
|
|
815
|
+
scopeRefreshConfig,
|
|
816
|
+
extraComputeBudget = 1_000_000,
|
|
817
|
+
includeAtaIxs = true,
|
|
818
|
+
requestElevationGroup = false,
|
|
819
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
820
|
+
referrer = none(),
|
|
821
|
+
} = props;
|
|
817
822
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
818
823
|
kaminoMarket,
|
|
819
824
|
'repayAndWithdrawV2',
|
|
820
825
|
repayAmount,
|
|
821
|
-
|
|
822
|
-
|
|
826
|
+
repayReserveAddress,
|
|
827
|
+
withdrawReserveAddress,
|
|
823
828
|
payer,
|
|
824
829
|
payer.address,
|
|
825
830
|
obligation,
|
|
@@ -849,32 +854,30 @@ export class KaminoAction {
|
|
|
849
854
|
return axn;
|
|
850
855
|
}
|
|
851
856
|
|
|
852
|
-
static async buildRepayAndWithdrawTxns(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
skipInitialization: false,
|
|
868
|
-
|
|
869
|
-
}
|
|
870
|
-
referrer: Option<Address> = none()
|
|
871
|
-
) {
|
|
857
|
+
static async buildRepayAndWithdrawTxns(props: BuildRepayAndWithdrawTxnsProps) {
|
|
858
|
+
const {
|
|
859
|
+
kaminoMarket,
|
|
860
|
+
repayAmount,
|
|
861
|
+
repayReserveAddress,
|
|
862
|
+
withdrawAmount,
|
|
863
|
+
withdrawReserveAddress,
|
|
864
|
+
payer,
|
|
865
|
+
currentSlot,
|
|
866
|
+
obligation,
|
|
867
|
+
useV2Ixs,
|
|
868
|
+
scopeRefreshConfig,
|
|
869
|
+
extraComputeBudget = 1_000_000,
|
|
870
|
+
includeAtaIxs = true,
|
|
871
|
+
requestElevationGroup = false,
|
|
872
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
873
|
+
referrer = none(),
|
|
874
|
+
} = props;
|
|
872
875
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
873
876
|
kaminoMarket,
|
|
874
877
|
'repayAndWithdraw',
|
|
875
878
|
repayAmount,
|
|
876
|
-
|
|
877
|
-
|
|
879
|
+
repayReserveAddress,
|
|
880
|
+
withdrawReserveAddress,
|
|
878
881
|
payer,
|
|
879
882
|
payer.address,
|
|
880
883
|
obligation,
|
|
@@ -938,40 +941,35 @@ export class KaminoAction {
|
|
|
938
941
|
return axn;
|
|
939
942
|
}
|
|
940
943
|
|
|
941
|
-
static async buildWithdrawTxns(
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
mint: Address,
|
|
945
|
-
owner: TransactionSigner,
|
|
946
|
-
obligation: KaminoObligation | ObligationType,
|
|
947
|
-
useV2Ixs: boolean,
|
|
948
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
949
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
950
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
|
|
951
|
-
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
952
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
953
|
-
skipInitialization: false,
|
|
954
|
-
skipLutCreation: false,
|
|
955
|
-
},
|
|
956
|
-
referrer: Option<Address> = none(),
|
|
957
|
-
currentSlot: Slot = 0n,
|
|
958
|
-
overrideElevationGroupRequest?: number,
|
|
959
|
-
// Optional customizations which may be needed if the obligation was mutated by some previous ix.
|
|
960
|
-
obligationCustomizations?: {
|
|
961
|
-
// Any newly-added deposit reserves.
|
|
962
|
-
addedDepositReserves?: Address[];
|
|
963
|
-
}
|
|
964
|
-
) {
|
|
965
|
-
const axn = await KaminoAction.initialize(
|
|
966
|
-
'withdraw',
|
|
944
|
+
static async buildWithdrawTxns(props: BuildWithdrawTxnsProps) {
|
|
945
|
+
const {
|
|
946
|
+
kaminoMarket,
|
|
967
947
|
amount,
|
|
968
|
-
|
|
948
|
+
reserveAddress,
|
|
969
949
|
owner,
|
|
950
|
+
obligation,
|
|
951
|
+
useV2Ixs,
|
|
952
|
+
scopeRefreshConfig,
|
|
953
|
+
extraComputeBudget = 1_000_000,
|
|
954
|
+
includeAtaIxs = true,
|
|
955
|
+
requestElevationGroup = false,
|
|
956
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
957
|
+
referrer = none(),
|
|
958
|
+
currentSlot = 0n,
|
|
959
|
+
overrideElevationGroupRequest,
|
|
960
|
+
obligationCustomizations,
|
|
961
|
+
} = props;
|
|
962
|
+
|
|
963
|
+
const axn = await KaminoAction.initialize({
|
|
970
964
|
kaminoMarket,
|
|
965
|
+
action: 'withdraw',
|
|
966
|
+
amount,
|
|
967
|
+
reserveAddress,
|
|
968
|
+
owner,
|
|
971
969
|
obligation,
|
|
972
970
|
referrer,
|
|
973
|
-
currentSlot
|
|
974
|
-
);
|
|
971
|
+
currentSlot,
|
|
972
|
+
});
|
|
975
973
|
const addInitObligationForFarm = true;
|
|
976
974
|
|
|
977
975
|
if (extraComputeBudget > 0) {
|
|
@@ -1005,52 +1003,38 @@ export class KaminoAction {
|
|
|
1005
1003
|
}
|
|
1006
1004
|
|
|
1007
1005
|
/**
|
|
1008
|
-
*
|
|
1009
|
-
* @param
|
|
1010
|
-
* @param amount
|
|
1011
|
-
* @param mint
|
|
1012
|
-
* @param owner
|
|
1013
|
-
* @param obligation - obligation to repay or the PDA seeds
|
|
1014
|
-
* @param useV2Ixs
|
|
1015
|
-
* @param scopeRefreshConfig
|
|
1016
|
-
* @param currentSlot
|
|
1017
|
-
* @param payer - if not set then owner is used
|
|
1018
|
-
* @param extraComputeBudget - if > 0 then adds the ix
|
|
1019
|
-
* @param includeAtaIxs - if true it includes create and close wsol and token atas
|
|
1020
|
-
* @param requestElevationGroup
|
|
1021
|
-
* @param initUserMetadata
|
|
1022
|
-
* @param referrer
|
|
1006
|
+
* Build repay transactions
|
|
1007
|
+
* @param props - BuildRepayTxnsProps containing all required and optional parameters
|
|
1023
1008
|
*/
|
|
1024
|
-
static async buildRepayTxns(
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
mint: Address,
|
|
1028
|
-
owner: TransactionSigner,
|
|
1029
|
-
obligation: KaminoObligation | ObligationType,
|
|
1030
|
-
useV2Ixs: boolean,
|
|
1031
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1032
|
-
currentSlot: Slot,
|
|
1033
|
-
payer: TransactionSigner = owner,
|
|
1034
|
-
extraComputeBudget: number = 1_000_000,
|
|
1035
|
-
includeAtaIxs: boolean = true,
|
|
1036
|
-
requestElevationGroup: boolean = false,
|
|
1037
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
1038
|
-
skipInitialization: false,
|
|
1039
|
-
skipLutCreation: false,
|
|
1040
|
-
},
|
|
1041
|
-
referrer: Option<Address> = none()
|
|
1042
|
-
) {
|
|
1043
|
-
const axn = await KaminoAction.initialize(
|
|
1044
|
-
'repay',
|
|
1009
|
+
static async buildRepayTxns(props: BuildRepayTxnsProps) {
|
|
1010
|
+
const {
|
|
1011
|
+
kaminoMarket,
|
|
1045
1012
|
amount,
|
|
1046
|
-
|
|
1013
|
+
reserveAddress,
|
|
1047
1014
|
owner,
|
|
1015
|
+
obligation,
|
|
1016
|
+
useV2Ixs,
|
|
1017
|
+
scopeRefreshConfig,
|
|
1018
|
+
currentSlot,
|
|
1019
|
+
payer = owner,
|
|
1020
|
+
extraComputeBudget = 1_000_000,
|
|
1021
|
+
includeAtaIxs = true,
|
|
1022
|
+
requestElevationGroup = false,
|
|
1023
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
1024
|
+
referrer = none(),
|
|
1025
|
+
} = props;
|
|
1026
|
+
|
|
1027
|
+
const axn = await KaminoAction.initialize({
|
|
1048
1028
|
kaminoMarket,
|
|
1029
|
+
action: 'repay',
|
|
1030
|
+
amount,
|
|
1031
|
+
reserveAddress,
|
|
1032
|
+
owner,
|
|
1049
1033
|
obligation,
|
|
1050
1034
|
referrer,
|
|
1051
1035
|
currentSlot,
|
|
1052
|
-
payer
|
|
1053
|
-
);
|
|
1036
|
+
payer,
|
|
1037
|
+
});
|
|
1054
1038
|
const addInitObligationForFarm = true;
|
|
1055
1039
|
|
|
1056
1040
|
if (extraComputeBudget > 0) {
|
|
@@ -1076,34 +1060,32 @@ export class KaminoAction {
|
|
|
1076
1060
|
return axn;
|
|
1077
1061
|
}
|
|
1078
1062
|
|
|
1079
|
-
static async buildLiquidateTxns(
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
skipInitialization: false,
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
currentSlot: Slot = 0n
|
|
1100
|
-
): Promise<KaminoAction> {
|
|
1063
|
+
static async buildLiquidateTxns(props: BuildLiquidateTxnsProps): Promise<KaminoAction> {
|
|
1064
|
+
const {
|
|
1065
|
+
kaminoMarket,
|
|
1066
|
+
amount,
|
|
1067
|
+
minCollateralReceiveAmount,
|
|
1068
|
+
repayReserveAddress,
|
|
1069
|
+
withdrawReserveAddress,
|
|
1070
|
+
liquidator,
|
|
1071
|
+
obligationOwner,
|
|
1072
|
+
obligation,
|
|
1073
|
+
useV2Ixs,
|
|
1074
|
+
scopeRefreshConfig,
|
|
1075
|
+
extraComputeBudget = 1_000_000,
|
|
1076
|
+
includeAtaIxs = true,
|
|
1077
|
+
requestElevationGroup = false,
|
|
1078
|
+
initUserMetadata = { skipInitialization: false, skipLutCreation: false },
|
|
1079
|
+
referrer = none(),
|
|
1080
|
+
maxAllowedLtvOverridePercent = 0,
|
|
1081
|
+
currentSlot = 0n,
|
|
1082
|
+
} = props;
|
|
1101
1083
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
1102
1084
|
kaminoMarket,
|
|
1103
1085
|
'liquidate',
|
|
1104
1086
|
amount,
|
|
1105
|
-
|
|
1106
|
-
|
|
1087
|
+
repayReserveAddress,
|
|
1088
|
+
withdrawReserveAddress,
|
|
1107
1089
|
liquidator,
|
|
1108
1090
|
obligationOwner,
|
|
1109
1091
|
obligation,
|
|
@@ -1136,14 +1118,10 @@ export class KaminoAction {
|
|
|
1136
1118
|
return axn;
|
|
1137
1119
|
}
|
|
1138
1120
|
|
|
1139
|
-
static async buildWithdrawReferrerFeeTxns(
|
|
1140
|
-
owner
|
|
1141
|
-
tokenMint: Address,
|
|
1142
|
-
kaminoMarket: KaminoMarket,
|
|
1143
|
-
currentSlot: Slot = 0n
|
|
1144
|
-
) {
|
|
1121
|
+
static async buildWithdrawReferrerFeeTxns(props: BuildWithdrawReferrerFeeTxnsProps) {
|
|
1122
|
+
const { owner, reserveAddress, kaminoMarket, currentSlot = 0n } = props;
|
|
1145
1123
|
const { axn, createAtaIxs } = await KaminoAction.initializeWithdrawReferrerFees(
|
|
1146
|
-
|
|
1124
|
+
reserveAddress,
|
|
1147
1125
|
owner,
|
|
1148
1126
|
kaminoMarket,
|
|
1149
1127
|
currentSlot
|
|
@@ -3289,8 +3267,13 @@ export class KaminoAction {
|
|
|
3289
3267
|
action === 'mint' ||
|
|
3290
3268
|
(action === 'liquidate' && this.mint === WRAPPED_SOL_MINT); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
3291
3269
|
|
|
3270
|
+
const isValidTokenAccount =
|
|
3271
|
+
userWSOLAccountInfo.exists &&
|
|
3272
|
+
(userWSOLAccountInfo.programAddress === TOKEN_PROGRAM_ADDRESS ||
|
|
3273
|
+
userWSOLAccountInfo.programAddress === TOKEN_2022_PROGRAM_ADDRESS);
|
|
3274
|
+
|
|
3292
3275
|
const transferLamportsIx = getTransferSolInstruction({
|
|
3293
|
-
amount: (
|
|
3276
|
+
amount: (isValidTokenAccount ? 0n : rentExemptLamports) + (sendAction ? BigInt(safeRepay.toString()) : 0n),
|
|
3294
3277
|
source: this.owner,
|
|
3295
3278
|
destination: userTokenAccountAddress,
|
|
3296
3279
|
});
|
|
@@ -3312,29 +3295,20 @@ export class KaminoAction {
|
|
|
3312
3295
|
},
|
|
3313
3296
|
{ programAddress: TOKEN_PROGRAM_ADDRESS }
|
|
3314
3297
|
);
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
userTokenAccountAddress
|
|
3330
|
-
);
|
|
3331
|
-
preIxs.push(createUserWSOLAccountIx);
|
|
3332
|
-
preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3333
|
-
preIxs.push(syncIx);
|
|
3334
|
-
preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3335
|
-
postIxs.push(closeWSOLAccountIx);
|
|
3336
|
-
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3337
|
-
}
|
|
3298
|
+
|
|
3299
|
+
const [, createUserWSOLAccountIx] = await createAssociatedTokenAccountIdempotentInstruction(
|
|
3300
|
+
this.owner,
|
|
3301
|
+
WRAPPED_SOL_MINT,
|
|
3302
|
+
this.owner.address,
|
|
3303
|
+
TOKEN_PROGRAM_ADDRESS,
|
|
3304
|
+
userTokenAccountAddress
|
|
3305
|
+
);
|
|
3306
|
+
preIxs.push(createUserWSOLAccountIx);
|
|
3307
|
+
preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3308
|
+
preIxs.push(syncIx);
|
|
3309
|
+
preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3310
|
+
postIxs.push(closeWSOLAccountIx);
|
|
3311
|
+
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3338
3312
|
|
|
3339
3313
|
this.setupIxs.unshift(...preIxs);
|
|
3340
3314
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
@@ -3346,8 +3320,8 @@ export class KaminoAction {
|
|
|
3346
3320
|
kaminoMarket: KaminoMarket,
|
|
3347
3321
|
action: ActionType,
|
|
3348
3322
|
inflowAmount: string | BN,
|
|
3349
|
-
|
|
3350
|
-
|
|
3323
|
+
inflowReserveAddress: Address,
|
|
3324
|
+
outflowReserveAddress: Address,
|
|
3351
3325
|
signer: TransactionSigner,
|
|
3352
3326
|
obligationOwner: Address,
|
|
3353
3327
|
obligation: KaminoObligation | ObligationType,
|
|
@@ -3355,8 +3329,8 @@ export class KaminoAction {
|
|
|
3355
3329
|
referrer: Option<Address> = none(),
|
|
3356
3330
|
currentSlot: Slot = 0n
|
|
3357
3331
|
) {
|
|
3358
|
-
const inflowReserve = kaminoMarket.
|
|
3359
|
-
const outflowReserve = kaminoMarket.
|
|
3332
|
+
const inflowReserve = kaminoMarket.getExistingReserveByAddress(inflowReserveAddress);
|
|
3333
|
+
const outflowReserve = kaminoMarket.getExistingReserveByAddress(outflowReserveAddress);
|
|
3360
3334
|
|
|
3361
3335
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } =
|
|
3362
3336
|
await KaminoAction.loadObligation(
|
|
@@ -3378,8 +3352,8 @@ export class KaminoAction {
|
|
|
3378
3352
|
action === 'repayAndWithdraw' ||
|
|
3379
3353
|
action === 'repayAndWithdrawV2'
|
|
3380
3354
|
) {
|
|
3381
|
-
primaryMint =
|
|
3382
|
-
secondaryMint =
|
|
3355
|
+
primaryMint = inflowReserve.getLiquidityMint();
|
|
3356
|
+
secondaryMint = outflowReserve.getLiquidityMint();
|
|
3383
3357
|
} else {
|
|
3384
3358
|
throw new Error('Invalid action');
|
|
3385
3359
|
}
|
|
@@ -3403,14 +3377,14 @@ export class KaminoAction {
|
|
|
3403
3377
|
}
|
|
3404
3378
|
|
|
3405
3379
|
static async initializeWithdrawReferrerFees(
|
|
3406
|
-
|
|
3380
|
+
reserveAddress: Address,
|
|
3407
3381
|
owner: TransactionSigner,
|
|
3408
3382
|
kaminoMarket: KaminoMarket,
|
|
3409
3383
|
currentSlot: Slot = 0n
|
|
3410
3384
|
) {
|
|
3411
|
-
const reserve = kaminoMarket.
|
|
3385
|
+
const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
|
|
3412
3386
|
if (reserve === undefined) {
|
|
3413
|
-
throw new Error(`Reserve ${
|
|
3387
|
+
throw new Error(`Reserve ${reserveAddress} not found in market ${kaminoMarket.getAddress()}`);
|
|
3414
3388
|
}
|
|
3415
3389
|
|
|
3416
3390
|
const [{ createAtaIx }] = await createAtasIdempotent(owner, [
|
|
@@ -3425,7 +3399,7 @@ export class KaminoAction {
|
|
|
3425
3399
|
kaminoMarket,
|
|
3426
3400
|
owner,
|
|
3427
3401
|
new VanillaObligation(kaminoMarket.programId),
|
|
3428
|
-
|
|
3402
|
+
reserve.getLiquidityMint(),
|
|
3429
3403
|
0,
|
|
3430
3404
|
new BN(0),
|
|
3431
3405
|
[],
|