@kamino-finance/klend-sdk 5.13.8 → 5.13.10
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.map +1 -1
- package/dist/classes/action.js +0 -1
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +17 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +20 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +4 -0
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +8 -2
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +9 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +34 -5
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +5 -5
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +9 -9
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +8 -8
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +25 -25
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/instructions.d.ts +5 -5
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +6 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +5 -0
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +131 -304
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +35 -57
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +1 -1
- package/dist/leverage/utils.js +5 -5
- package/dist/leverage/utils.js.map +1 -1
- package/dist/utils/ata.d.ts +0 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +0 -14
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +10 -0
- package/dist/utils/instruction.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +0 -1
- package/src/classes/manager.ts +31 -0
- package/src/classes/reserve.ts +9 -2
- package/src/classes/vault.ts +45 -5
- package/src/lending_operations/repay_with_collateral_operations.ts +6 -6
- package/src/lending_operations/swap_collateral_operations.ts +22 -24
- package/src/leverage/calcs.ts +26 -26
- package/src/leverage/instructions.ts +8 -8
- package/src/leverage/operations.ts +232 -325
- package/src/leverage/types.ts +38 -67
- package/src/leverage/utils.ts +5 -5
- package/src/utils/ata.ts +1 -26
- package/src/utils/instruction.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;AAwBA,0DAuCC;AAED,0CAWC;AAED,gFA6BC;AAED,kCAkBC;AAED,oDAEC;AAUD,8CAsBC;AAED,sDAqBC;AA6BD,wDAmBC;AAkBD,4BAQC;AAED,oEAoBC;
|
|
1
|
+
{"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;AAwBA,0DAuCC;AAED,0CAWC;AAED,gFA6BC;AAED,kCAkBC;AAED,oDAEC;AAUD,8CAsBC;AAED,sDAqBC;AA6BD,wDAmBC;AAkBD,4BAQC;AAED,oEAoBC;AAED,0CAUC;AApSD,6CAgByB;AACzB,kDAAoD;AACpD,4CAAyC;AACzC,mEAA4D;AAC5D,qCAAwC;AAEjC,KAAK,UAAU,uBAAuB,CAC3C,CAAa,EACb,EAAwB,EACxB,KAAc,EACd,OAAiB,EACjB,oBAA6B,KAAK,EAClC,kBAA0B,EAAE,EAC5B,eAAwB,KAAK,CAAC,8IAA8I;;IAE5K,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAE7B,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;QAEzB,IAAI,SAAS,CAAC,MAAM,CAAC,8BAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/classes/action.ts
CHANGED
package/src/classes/manager.ts
CHANGED
|
@@ -89,6 +89,7 @@ import {
|
|
|
89
89
|
UpdateReserveAllocationIxs,
|
|
90
90
|
UpdateVaultConfigIxs,
|
|
91
91
|
UserSharesForVault,
|
|
92
|
+
WithdrawAndBlockReserveIxs,
|
|
92
93
|
WithdrawIxs,
|
|
93
94
|
} from './vault_types';
|
|
94
95
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
@@ -271,6 +272,36 @@ export class KaminoManager {
|
|
|
271
272
|
return this._vaultClient.removeReserveFromAllocationIx(vault, reserve);
|
|
272
273
|
}
|
|
273
274
|
|
|
275
|
+
/**
|
|
276
|
+
* This method withdraws all the funds from a reserve and blocks it from being invested by setting its weight and ctoken allocation to 0
|
|
277
|
+
* @param vault - the vault to withdraw the funds from
|
|
278
|
+
* @param reserve - the reserve to withdraw the funds from
|
|
279
|
+
* @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
|
|
280
|
+
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
|
|
281
|
+
*/
|
|
282
|
+
async withdrawEverythingAndBlockInvestReserve(
|
|
283
|
+
vault: KaminoVault,
|
|
284
|
+
reserve: PublicKey,
|
|
285
|
+
payer?: PublicKey
|
|
286
|
+
): Promise<WithdrawAndBlockReserveIxs> {
|
|
287
|
+
return this._vaultClient.withdrawEverythingAndBlockInvestReserve(vault, reserve, payer);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* This method withdraws all the funds from all the reserves and blocks them from being invested by setting their weight and ctoken allocation to 0
|
|
292
|
+
* @param vault - the vault to withdraw the invested funds from
|
|
293
|
+
* @param [vaultReservesMap] - optional parameter to pass a map of the vault reserves. If not provided, the reserves will be loaded from the vault
|
|
294
|
+
* @param [payer] - optional parameter to pass a different payer for the transaction. If not provided, the admin of the vault will be used; this is the payer for the invest ixs and it should have an ATA and some lamports (2x no_of_reserves) of the token vault
|
|
295
|
+
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
|
|
296
|
+
*/
|
|
297
|
+
async withdrawEverythingFromAllReservesAndBlockInvest(
|
|
298
|
+
vault: KaminoVault,
|
|
299
|
+
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
|
|
300
|
+
payer?: PublicKey
|
|
301
|
+
): Promise<WithdrawAndBlockReserveIxs> {
|
|
302
|
+
return this._vaultClient.withdrawEverythingFromAllReservesAndBlockInvest(vault, vaultReservesMap, payer);
|
|
303
|
+
}
|
|
304
|
+
|
|
274
305
|
// async closeVault(vault: KaminoVault): Promise<TransactionInstruction> {
|
|
275
306
|
// return this._vaultClient.closeVaultIx(vault);
|
|
276
307
|
// }
|
package/src/classes/reserve.ts
CHANGED
|
@@ -276,7 +276,14 @@ export class KaminoReserve {
|
|
|
276
276
|
* @returns 10^mint_decimals
|
|
277
277
|
*/
|
|
278
278
|
getMintFactor(): Decimal {
|
|
279
|
-
return new Decimal(10).pow(this.
|
|
279
|
+
return new Decimal(10).pow(this.getMintDecimals());
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @returns mint_decimals of the liquidity token
|
|
284
|
+
*/
|
|
285
|
+
getMintDecimals(): number {
|
|
286
|
+
return this.state.liquidity.mintDecimals.toNumber();
|
|
280
287
|
}
|
|
281
288
|
|
|
282
289
|
/**
|
|
@@ -875,7 +882,7 @@ export class KaminoReserve {
|
|
|
875
882
|
|
|
876
883
|
// Reserve info
|
|
877
884
|
symbol: parseTokenSymbol(parsedData.config.tokenInfo.name),
|
|
878
|
-
decimals: this.
|
|
885
|
+
decimals: this.getMintDecimals(),
|
|
879
886
|
accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),
|
|
880
887
|
mintTotalSupply,
|
|
881
888
|
depositLimitCrossedTimestamp: parsedData.liquidity.depositLimitCrossedTimestamp.toNumber(),
|
package/src/classes/vault.ts
CHANGED
|
@@ -451,7 +451,7 @@ export class KaminoVaultClient {
|
|
|
451
451
|
* @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
|
|
452
452
|
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
|
|
453
453
|
*/
|
|
454
|
-
async
|
|
454
|
+
async withdrawEverythingAndBlockInvestReserve(
|
|
455
455
|
vault: KaminoVault,
|
|
456
456
|
reserve: PublicKey,
|
|
457
457
|
payer?: PublicKey
|
|
@@ -485,15 +485,55 @@ export class KaminoVaultClient {
|
|
|
485
485
|
|
|
486
486
|
const investPayer = payer ? payer : vaultState.vaultAdminAuthority;
|
|
487
487
|
const investIx = await this.investSingleReserveIxs(investPayer, vault, reserveWithAddress);
|
|
488
|
-
withdrawAndBlockReserveIxs.updateReserveAllocationIxs = [
|
|
489
|
-
updateAllocIxs.updateReserveAllocationIx,
|
|
490
|
-
...updateAllocIxs.updateLUTIxs,
|
|
491
|
-
];
|
|
488
|
+
withdrawAndBlockReserveIxs.updateReserveAllocationIxs = [updateAllocIxs.updateReserveAllocationIx];
|
|
492
489
|
withdrawAndBlockReserveIxs.investIxs = investIx;
|
|
493
490
|
|
|
494
491
|
return withdrawAndBlockReserveIxs;
|
|
495
492
|
}
|
|
496
493
|
|
|
494
|
+
/**
|
|
495
|
+
* This method withdraws all the funds from all the reserves and blocks them from being invested by setting their weight and ctoken allocation to 0
|
|
496
|
+
* @param vault - the vault to withdraw the invested funds from
|
|
497
|
+
* @param [vaultReservesMap] - optional parameter to pass a map of the vault reserves. If not provided, the reserves will be loaded from the vault
|
|
498
|
+
* @param [payer] - optional parameter to pass a different payer for the transaction. If not provided, the admin of the vault will be used; this is the payer for the invest ixs and it should have an ATA and some lamports (2x no_of_reserves) of the token vault
|
|
499
|
+
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
|
|
500
|
+
*/
|
|
501
|
+
async withdrawEverythingFromAllReservesAndBlockInvest(
|
|
502
|
+
vault: KaminoVault,
|
|
503
|
+
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
|
|
504
|
+
payer?: PublicKey
|
|
505
|
+
): Promise<WithdrawAndBlockReserveIxs> {
|
|
506
|
+
const vaultState = await vault.getState(this.getConnection());
|
|
507
|
+
|
|
508
|
+
const reserves = this.getVaultReserves(vaultState);
|
|
509
|
+
const withdrawAndBlockReserveIxs: WithdrawAndBlockReserveIxs = {
|
|
510
|
+
updateReserveAllocationIxs: [],
|
|
511
|
+
investIxs: [],
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
if (!vaultReservesMap) {
|
|
515
|
+
vaultReservesMap = await this.loadVaultReserves(vaultState);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
for (const reserve of reserves) {
|
|
519
|
+
const reserveWithAddress: ReserveWithAddress = {
|
|
520
|
+
address: reserve,
|
|
521
|
+
state: vaultReservesMap.get(reserve)!.state,
|
|
522
|
+
};
|
|
523
|
+
const reserveAllocationConfig = new ReserveAllocationConfig(reserveWithAddress, 0, new Decimal(0));
|
|
524
|
+
|
|
525
|
+
// update allocation to have 0 weight and 0 cap
|
|
526
|
+
const updateAllocIxs = await this.updateReserveAllocationIxs(vault, reserveAllocationConfig);
|
|
527
|
+
withdrawAndBlockReserveIxs.updateReserveAllocationIxs.push(updateAllocIxs.updateReserveAllocationIx);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const investPayer = payer ? payer : vaultState.vaultAdminAuthority;
|
|
531
|
+
const investIxs = await this.investAllReservesIxs(investPayer, vault);
|
|
532
|
+
withdrawAndBlockReserveIxs.investIxs = investIxs;
|
|
533
|
+
|
|
534
|
+
return withdrawAndBlockReserveIxs;
|
|
535
|
+
}
|
|
536
|
+
|
|
497
537
|
/**
|
|
498
538
|
* This method removes a reserve from the vault allocation strategy if already part of the allocation strategy
|
|
499
539
|
* @param vault - vault to remove the reserve from
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
createAtasIdempotent,
|
|
15
15
|
getComputeBudgetAndPriorityFeeIxs,
|
|
16
|
-
|
|
16
|
+
removeBudgetIxs,
|
|
17
17
|
ScopePriceRefreshConfig,
|
|
18
18
|
U64_MAX,
|
|
19
19
|
uniqueAccountsWithProgramIds,
|
|
@@ -289,8 +289,8 @@ async function buildRepayWithCollateralIxs(
|
|
|
289
289
|
const scopeRefreshIxn = await getScopeRefreshIx(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
290
290
|
|
|
291
291
|
// 2. Flash borrow & repay the debt to repay amount needed
|
|
292
|
-
const {
|
|
293
|
-
|
|
292
|
+
const { flashBorrowIx, flashRepayIx } = getFlashLoanInstructions({
|
|
293
|
+
borrowIxIndex: budgetIxs.length + atasAndIxs.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
|
|
294
294
|
walletPublicKey: obligation.state.owner,
|
|
295
295
|
lendingMarketAuthority: market.getLendingMarketAuthority(),
|
|
296
296
|
lendingMarketAddress: market.getAddress(),
|
|
@@ -354,17 +354,17 @@ async function buildRepayWithCollateralIxs(
|
|
|
354
354
|
|
|
355
355
|
// 4. Swap collateral to debt to repay flash loan
|
|
356
356
|
const { preActionIxs, swapIxs } = swapQuoteIxs;
|
|
357
|
-
const swapInstructions =
|
|
357
|
+
const swapInstructions = removeBudgetIxs(swapIxs);
|
|
358
358
|
|
|
359
359
|
const ixs = [
|
|
360
360
|
...scopeRefreshIxn,
|
|
361
361
|
...budgetIxs,
|
|
362
362
|
...atasAndIxs.map((x) => x.createAtaIx),
|
|
363
|
-
|
|
363
|
+
flashBorrowIx,
|
|
364
364
|
...preActionIxs,
|
|
365
365
|
...KaminoAction.actionToIxs(repayAndWithdrawAction),
|
|
366
366
|
...swapInstructions,
|
|
367
|
-
|
|
367
|
+
flashRepayIx,
|
|
368
368
|
];
|
|
369
369
|
|
|
370
370
|
const res: LeverageIxsOutput = {
|
|
@@ -252,10 +252,10 @@ const FAKE_TARGET_COLL_SWAP_OUT_AMOUNT = new Decimal(1); // see the lengthy `get
|
|
|
252
252
|
|
|
253
253
|
type SwapCollKlendIxs = {
|
|
254
254
|
setupIxs: TransactionInstruction[];
|
|
255
|
-
|
|
255
|
+
targetCollFlashBorrowIx: TransactionInstruction;
|
|
256
256
|
depositTargetCollIxs: TransactionInstruction[];
|
|
257
257
|
withdrawSourceCollIxs: TransactionInstruction[];
|
|
258
|
-
|
|
258
|
+
targetCollFlashRepayIx: TransactionInstruction;
|
|
259
259
|
cleanupIxs: TransactionInstruction[];
|
|
260
260
|
flashLoanInfo: FlashLoanInfo;
|
|
261
261
|
simulationDetails: {
|
|
@@ -284,7 +284,7 @@ async function getKlendIxs(
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
const targetCollFlashBorrowedAmount = calculateTargetCollFlashBorrowedAmount(targetCollSwapOutAmount, context);
|
|
287
|
-
const {
|
|
287
|
+
const { targetCollFlashBorrowIx, targetCollFlashRepayIx } = getTargetCollFlashLoanIxs(
|
|
288
288
|
targetCollFlashBorrowedAmount,
|
|
289
289
|
setupIxs.length,
|
|
290
290
|
targetCollAta,
|
|
@@ -306,10 +306,10 @@ async function getKlendIxs(
|
|
|
306
306
|
flashBorrowReserve: context.targetCollReserve.address,
|
|
307
307
|
flashLoanFee: context.targetCollReserve.getFlashLoanFee(),
|
|
308
308
|
},
|
|
309
|
-
|
|
309
|
+
targetCollFlashBorrowIx,
|
|
310
310
|
depositTargetCollIxs: depositTargetCollIxs.ixs,
|
|
311
311
|
withdrawSourceCollIxs,
|
|
312
|
-
|
|
312
|
+
targetCollFlashRepayIx,
|
|
313
313
|
cleanupIxs,
|
|
314
314
|
simulationDetails: {
|
|
315
315
|
targetCollFlashBorrowedAmount,
|
|
@@ -364,26 +364,24 @@ function getAtaCloseIxs(context: SwapCollContext<any>) {
|
|
|
364
364
|
|
|
365
365
|
function getTargetCollFlashLoanIxs(
|
|
366
366
|
targetCollAmount: Decimal,
|
|
367
|
-
|
|
367
|
+
flashBorrowIxIndex: number,
|
|
368
368
|
destinationAta: PublicKey,
|
|
369
369
|
context: SwapCollContext<any>
|
|
370
370
|
) {
|
|
371
|
-
const {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
);
|
|
386
|
-
return { targetCollFlashBorrowIxn, targetCollFlashRepayIxn };
|
|
371
|
+
const { flashBorrowIx: targetCollFlashBorrowIx, flashRepayIx: targetCollFlashRepayIx } = getFlashLoanInstructions({
|
|
372
|
+
borrowIxIndex: flashBorrowIxIndex,
|
|
373
|
+
walletPublicKey: context.obligation.state.owner,
|
|
374
|
+
lendingMarketAuthority: context.market.getLendingMarketAuthority(),
|
|
375
|
+
lendingMarketAddress: context.market.getAddress(),
|
|
376
|
+
reserve: context.targetCollReserve,
|
|
377
|
+
amountLamports: targetCollAmount.mul(context.targetCollReserve.getMintFactor()),
|
|
378
|
+
destinationAta,
|
|
379
|
+
// TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
|
|
380
|
+
referrerAccount: context.market.programId,
|
|
381
|
+
referrerTokenState: context.market.programId,
|
|
382
|
+
programId: context.market.programId,
|
|
383
|
+
});
|
|
384
|
+
return { targetCollFlashBorrowIx, targetCollFlashRepayIx };
|
|
387
385
|
}
|
|
388
386
|
|
|
389
387
|
type DepositTargetCollIxs = {
|
|
@@ -609,11 +607,11 @@ function checkResultingObligationValid(
|
|
|
609
607
|
function listIxs(klendIxs: SwapCollKlendIxs, externalSwapIxs?: TransactionInstruction[]): TransactionInstruction[] {
|
|
610
608
|
return [
|
|
611
609
|
...klendIxs.setupIxs,
|
|
612
|
-
klendIxs.
|
|
610
|
+
klendIxs.targetCollFlashBorrowIx,
|
|
613
611
|
...klendIxs.depositTargetCollIxs,
|
|
614
612
|
...klendIxs.withdrawSourceCollIxs,
|
|
615
613
|
...(externalSwapIxs || []),
|
|
616
|
-
klendIxs.
|
|
614
|
+
klendIxs.targetCollFlashRepayIx,
|
|
617
615
|
...klendIxs.cleanupIxs,
|
|
618
616
|
];
|
|
619
617
|
}
|
package/src/leverage/calcs.ts
CHANGED
|
@@ -13,14 +13,14 @@ import { fuzzyEqual } from '../utils';
|
|
|
13
13
|
|
|
14
14
|
const closingPositionDiffTolerance = 0.0001;
|
|
15
15
|
|
|
16
|
-
export enum
|
|
16
|
+
export enum LeverageOption {
|
|
17
17
|
deposit = 'Deposit',
|
|
18
18
|
withdraw = 'Withdraw',
|
|
19
19
|
adjust = 'Adjust',
|
|
20
20
|
close = 'Close',
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export interface
|
|
23
|
+
export interface LeverageCalcsArgs {
|
|
24
24
|
depositAmount: Decimal;
|
|
25
25
|
withdrawAmount: Decimal;
|
|
26
26
|
deposited: Decimal;
|
|
@@ -29,14 +29,14 @@ export interface LeverageFormsCalcsArgs {
|
|
|
29
29
|
selectedTokenMint: PublicKey;
|
|
30
30
|
collTokenMint: PublicKey;
|
|
31
31
|
targetLeverage: Decimal;
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
activeLeverageOption: LeverageOption;
|
|
33
|
+
flashLoanFeeRatio: Decimal;
|
|
34
34
|
debtBorrowFactorPct: Decimal;
|
|
35
35
|
priceCollToDebt: Decimal;
|
|
36
36
|
priceDebtToColl: Decimal;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface
|
|
39
|
+
export interface LeverageCalcsResult {
|
|
40
40
|
earned: Decimal;
|
|
41
41
|
totalDeposited: Decimal;
|
|
42
42
|
totalBorrowed: Decimal;
|
|
@@ -56,14 +56,14 @@ export async function calculateMultiplyEffects(
|
|
|
56
56
|
selectedTokenMint,
|
|
57
57
|
collTokenMint,
|
|
58
58
|
targetLeverage,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
activeLeverageOption,
|
|
60
|
+
flashLoanFeeRatio,
|
|
61
61
|
debtBorrowFactorPct,
|
|
62
62
|
priceCollToDebt,
|
|
63
63
|
priceDebtToColl,
|
|
64
|
-
}:
|
|
64
|
+
}: LeverageCalcsArgs,
|
|
65
65
|
logEstimations = false
|
|
66
|
-
): Promise<
|
|
66
|
+
): Promise<LeverageCalcsResult> {
|
|
67
67
|
// calculate estimations for deposit operation
|
|
68
68
|
const {
|
|
69
69
|
adjustDepositPosition: depositModeEstimatedDepositAmount,
|
|
@@ -75,7 +75,7 @@ export async function calculateMultiplyEffects(
|
|
|
75
75
|
targetLeverage,
|
|
76
76
|
selectedTokenMint,
|
|
77
77
|
collTokenMint: collTokenMint,
|
|
78
|
-
flashLoanFee:
|
|
78
|
+
flashLoanFee: flashLoanFeeRatio,
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
// calculate estimations for withdraw operation
|
|
@@ -101,14 +101,14 @@ export async function calculateMultiplyEffects(
|
|
|
101
101
|
collTokenMint,
|
|
102
102
|
totalDeposited: new Decimal(deposited),
|
|
103
103
|
totalBorrowed: new Decimal(borrowed),
|
|
104
|
-
flashLoanFee:
|
|
104
|
+
flashLoanFee: flashLoanFeeRatio, // TODO: is this the right flash borrow?
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
if (logEstimations) {
|
|
108
108
|
console.log(
|
|
109
109
|
'Estimations',
|
|
110
110
|
toJson({
|
|
111
|
-
|
|
111
|
+
activeLeverageOption,
|
|
112
112
|
depositModeEstimatedDepositAmount,
|
|
113
113
|
depositModeEstimatedBorrowAmount,
|
|
114
114
|
withdrawModeEstimatedDepositTokenWithdrawn,
|
|
@@ -121,16 +121,16 @@ export async function calculateMultiplyEffects(
|
|
|
121
121
|
|
|
122
122
|
let [isClosingPosition, totalDeposited, totalBorrowed] = [false, new Decimal(0), new Decimal(0)];
|
|
123
123
|
|
|
124
|
-
switch (
|
|
125
|
-
case
|
|
124
|
+
switch (activeLeverageOption) {
|
|
125
|
+
case LeverageOption.deposit: {
|
|
126
126
|
// Deposit and Adjust never clos the position
|
|
127
127
|
isClosingPosition = false;
|
|
128
128
|
totalDeposited = deposited.add(depositModeEstimatedDepositAmount);
|
|
129
129
|
totalBorrowed = borrowed.add(depositModeEstimatedBorrowAmount);
|
|
130
130
|
break;
|
|
131
131
|
}
|
|
132
|
-
case
|
|
133
|
-
case
|
|
132
|
+
case LeverageOption.close:
|
|
133
|
+
case LeverageOption.withdraw: {
|
|
134
134
|
isClosingPosition =
|
|
135
135
|
(withdrawModeEstimatedDepositTokenWithdrawn.gte(new Decimal(deposited)) ||
|
|
136
136
|
withdrawModeEstimatedBorrowTokenWithdrawn.gte(new Decimal(borrowed)) ||
|
|
@@ -146,7 +146,7 @@ export async function calculateMultiplyEffects(
|
|
|
146
146
|
totalBorrowed = isClosingPosition ? new Decimal(0) : borrowed.sub(withdrawModeEstimatedBorrowTokenWithdrawn);
|
|
147
147
|
break;
|
|
148
148
|
}
|
|
149
|
-
case
|
|
149
|
+
case LeverageOption.adjust: {
|
|
150
150
|
// Deposit and Adjust never clos the position
|
|
151
151
|
isClosingPosition = false;
|
|
152
152
|
totalDeposited = deposited.add(adjustModeEstimatedDepositAmount);
|
|
@@ -186,12 +186,12 @@ export const calcBorrowAmount = ({
|
|
|
186
186
|
depositTokenAmount,
|
|
187
187
|
targetLeverage,
|
|
188
188
|
priceCollToDebt,
|
|
189
|
-
|
|
189
|
+
flashLoanFeeRatio,
|
|
190
190
|
}: {
|
|
191
191
|
depositTokenAmount: Decimal;
|
|
192
192
|
targetLeverage: Decimal;
|
|
193
193
|
priceCollToDebt: Decimal;
|
|
194
|
-
|
|
194
|
+
flashLoanFeeRatio: Decimal;
|
|
195
195
|
}) => {
|
|
196
196
|
const initialCollAmountInCollToken = depositTokenAmount;
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ export const calcBorrowAmount = ({
|
|
|
199
199
|
const finalDebtAmountInCollToken = finalCollAmountInCollToken.sub(initialCollAmountInCollToken);
|
|
200
200
|
const finalDebtAmountInDebtToken = finalDebtAmountInCollToken.mul(priceCollToDebt);
|
|
201
201
|
|
|
202
|
-
const flashFeeFactor = new Decimal(1).add(
|
|
202
|
+
const flashFeeFactor = new Decimal(1).add(flashLoanFeeRatio);
|
|
203
203
|
const debtTokenToBorrow = finalDebtAmountInDebtToken.mul(flashFeeFactor);
|
|
204
204
|
|
|
205
205
|
return debtTokenToBorrow;
|
|
@@ -269,7 +269,7 @@ export function calcWithdrawAmounts(params: WithdrawParams): WithdrawResult {
|
|
|
269
269
|
depositTokenAmount: initialDepositInCollateralToken.minus(amountToWithdrawDepositToken),
|
|
270
270
|
priceCollToDebt: new Decimal(priceCollToDebt),
|
|
271
271
|
targetLeverage: new Decimal(targetLeverage),
|
|
272
|
-
|
|
272
|
+
flashLoanFeeRatio: new Decimal(0),
|
|
273
273
|
});
|
|
274
274
|
|
|
275
275
|
const adjustDepositPosition = currentDepositPosition.minus(targetDeposit);
|
|
@@ -347,7 +347,7 @@ export function calcAdjustAmounts({
|
|
|
347
347
|
depositTokenAmount: initialDeposit,
|
|
348
348
|
priceCollToDebt: new Decimal(priceCollToDebt),
|
|
349
349
|
targetLeverage: new Decimal(targetLeverage),
|
|
350
|
-
|
|
350
|
+
flashLoanFeeRatio: flashLoanFee,
|
|
351
351
|
});
|
|
352
352
|
|
|
353
353
|
const adjustDepositPosition = targetDeposit.minus(currentDepositPosition);
|
|
@@ -393,7 +393,7 @@ export const estimateDepositMode = ({
|
|
|
393
393
|
depositTokenAmount: depositCollTokenAmount,
|
|
394
394
|
targetLeverage: new Decimal(targetLeverage),
|
|
395
395
|
priceCollToDebt: new Decimal(priceCollToDebt),
|
|
396
|
-
|
|
396
|
+
flashLoanFeeRatio: new Decimal(flashLoanFee),
|
|
397
397
|
});
|
|
398
398
|
|
|
399
399
|
const slippageFactor = new Decimal(1).add(slippagePct.div(new Decimal(100)));
|
|
@@ -673,11 +673,11 @@ export function withdrawLeverageCalcs(
|
|
|
673
673
|
// Add slippage for the accrued interest rate amount
|
|
674
674
|
const irSlippageBpsForDebt = obligation!
|
|
675
675
|
.estimateObligationInterestRate(market, debtReserve!, obligation?.state.borrows[0]!, currentSlot)
|
|
676
|
-
.toDecimalPlaces(debtReserve?.
|
|
677
|
-
// add 0.1 to irSlippageBpsForDebt because we don't want to estimate slightly less than SC and end up not
|
|
676
|
+
.toDecimalPlaces(debtReserve?.getMintDecimals()!, Decimal.ROUND_CEIL);
|
|
677
|
+
// add 0.1 to irSlippageBpsForDebt because we don't want to estimate slightly less than SC and end up not repaying enough
|
|
678
678
|
const repayAmount = initialRepayAmount
|
|
679
679
|
.mul(irSlippageBpsForDebt.add('0.1').div('10_000').add('1'))
|
|
680
|
-
.toDecimalPlaces(debtReserve?.
|
|
680
|
+
.toDecimalPlaces(debtReserve?.getMintDecimals()!, Decimal.ROUND_CEIL);
|
|
681
681
|
|
|
682
682
|
// 6. Get swap ixs
|
|
683
683
|
// 5. Get swap estimations to understand how much we need to borrow from borrow reserve
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import Decimal from 'decimal.js';
|
|
13
13
|
|
|
14
14
|
export const getFlashLoanInstructions = (args: {
|
|
15
|
-
|
|
15
|
+
borrowIxIndex: number;
|
|
16
16
|
walletPublicKey: PublicKey;
|
|
17
17
|
lendingMarketAuthority: PublicKey;
|
|
18
18
|
lendingMarketAddress: PublicKey;
|
|
@@ -23,7 +23,7 @@ export const getFlashLoanInstructions = (args: {
|
|
|
23
23
|
referrerTokenState: PublicKey;
|
|
24
24
|
programId: PublicKey;
|
|
25
25
|
}) => {
|
|
26
|
-
const
|
|
26
|
+
const flashBorrowIx = getBorrowFlashLoanInstruction({
|
|
27
27
|
walletPublicKey: args.walletPublicKey,
|
|
28
28
|
lendingMarketAuthority: args.lendingMarketAuthority,
|
|
29
29
|
lendingMarketAddress: args.lendingMarketAddress,
|
|
@@ -34,8 +34,8 @@ export const getFlashLoanInstructions = (args: {
|
|
|
34
34
|
referrerTokenState: args.referrerTokenState,
|
|
35
35
|
programId: args.programId,
|
|
36
36
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const flashRepayIx = getRepayFlashLoanInstruction({
|
|
38
|
+
borrowIxIndex: args.borrowIxIndex,
|
|
39
39
|
walletPublicKey: args.walletPublicKey,
|
|
40
40
|
lendingMarketAuthority: args.lendingMarketAuthority,
|
|
41
41
|
lendingMarketAddress: args.lendingMarketAddress,
|
|
@@ -47,7 +47,7 @@ export const getFlashLoanInstructions = (args: {
|
|
|
47
47
|
programId: args.programId,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
return {
|
|
50
|
+
return { flashBorrowIx, flashRepayIx };
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export const getBorrowFlashLoanInstruction = ({
|
|
@@ -93,7 +93,7 @@ export const getBorrowFlashLoanInstruction = ({
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
export const getRepayFlashLoanInstruction = ({
|
|
96
|
-
|
|
96
|
+
borrowIxIndex,
|
|
97
97
|
walletPublicKey,
|
|
98
98
|
lendingMarketAuthority,
|
|
99
99
|
lendingMarketAddress,
|
|
@@ -104,7 +104,7 @@ export const getRepayFlashLoanInstruction = ({
|
|
|
104
104
|
referrerTokenState,
|
|
105
105
|
programId,
|
|
106
106
|
}: {
|
|
107
|
-
|
|
107
|
+
borrowIxIndex: number;
|
|
108
108
|
walletPublicKey: PublicKey;
|
|
109
109
|
lendingMarketAuthority: PublicKey;
|
|
110
110
|
lendingMarketAddress: PublicKey;
|
|
@@ -116,7 +116,7 @@ export const getRepayFlashLoanInstruction = ({
|
|
|
116
116
|
programId: PublicKey;
|
|
117
117
|
}) => {
|
|
118
118
|
const args: FlashRepayReserveLiquidityArgs = {
|
|
119
|
-
borrowInstructionIndex:
|
|
119
|
+
borrowInstructionIndex: borrowIxIndex,
|
|
120
120
|
liquidityAmount: new anchor.BN(amountLamports.floor().toString()),
|
|
121
121
|
};
|
|
122
122
|
|