@haven-fi/solauto-sdk 1.0.157 → 1.0.159
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +2 -2
- package/dist/transactions/transactionsManager.js +2 -2
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +7 -4
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +2 -6
- package/src/transactions/transactionsManager.ts +2 -2
- package/src/utils/solauto/rebalanceUtils.ts +14 -14
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EAEb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAUnE,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,OAAO,CAAC,WAAW,CAAkB;IAE9B,eAAe,EAAG,SAAS,CAAC;IAE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gB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAwClE"}
|
@@ -53,7 +53,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
53
53
|
this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
54
54
|
this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
|
55
55
|
if (!this.solautoPositionState) {
|
56
|
-
const [maxLtv, liqThreshold] = await
|
56
|
+
const [maxLtv, liqThreshold] = (await this.maxLtvAndLiqThreshold());
|
57
57
|
this.solautoPositionState = (0, utils_1.createFakePositionState)({ mint: this.supplyMint }, { mint: this.debtMint }, (0, numberUtils_1.toBps)(maxLtv), (0, numberUtils_1.toBps)(liqThreshold));
|
58
58
|
}
|
59
59
|
if (!this.initialized) {
|
@@ -336,7 +336,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
336
336
|
: undefined,
|
337
337
|
rebalanceType,
|
338
338
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
339
|
-
targetInAmountBaseUnit: targetLiqUtilizationRateBps
|
339
|
+
targetInAmountBaseUnit: targetLiqUtilizationRateBps && rebalanceStep === "A"
|
340
340
|
? swapDetails.amount
|
341
341
|
: null,
|
342
342
|
limitGapBps: limitGapBps ?? null,
|
@@ -217,7 +217,7 @@ class TransactionsManager {
|
|
217
217
|
if (updateLookupTable &&
|
218
218
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
219
219
|
updateLookupTable?.needsToBeIsolated) {
|
220
|
-
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => this.sendTransaction(updateLookupTable.updateLutTx, updateLutTxName, attemptNum, prioritySetting), 3, 150, this.errorsToThrow);
|
220
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await this.sendTransaction(updateLookupTable.updateLutTx, updateLutTxName, attemptNum, prioritySetting), 3, 150, this.errorsToThrow);
|
221
221
|
}
|
222
222
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
223
223
|
for (const item of items) {
|
@@ -317,7 +317,7 @@ class TransactionsManager {
|
|
317
317
|
if (this.txHandler.localTest) {
|
318
318
|
await this.debugAccounts(itemSet, tx);
|
319
319
|
}
|
320
|
-
this.sendTransaction(tx, itemSet.name(), attemptNum, prioritySetting);
|
320
|
+
await this.sendTransaction(tx, itemSet.name(), attemptNum, prioritySetting);
|
321
321
|
}
|
322
322
|
}, this.retries, this.retryDelay, this.errorsToThrow);
|
323
323
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA8IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CAiEjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,EACvB,cAAc,EAAE,MAAM,GACrB,gBAAgB,GAAG,SAAS,CAoE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAsChB"}
|
@@ -111,11 +111,12 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
111
111
|
debtAdjustmentUsd,
|
112
112
|
amountToDcaIn: amountToDcaIn ?? 0,
|
113
113
|
amountUsdToDcaIn,
|
114
|
-
dcaTokenType: dca?.tokenType
|
114
|
+
dcaTokenType: dca?.tokenType,
|
115
115
|
};
|
116
116
|
}
|
117
117
|
function getFlashLoanDetails(client, values, jupQuote, priceImpactBps) {
|
118
|
-
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) +
|
118
|
+
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) +
|
119
|
+
(values.dcaTokenType === generated_1.TokenType.Supply ? values.amountUsdToDcaIn : 0);
|
119
120
|
let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
120
121
|
const debtAdjustmentWithSlippage = Math.abs(values.debtAdjustmentUsd) +
|
121
122
|
Math.abs(values.debtAdjustmentUsd) * (0, numberUtils_1.fromBps)(priceImpactBps);
|
@@ -141,7 +142,8 @@ function getFlashLoanDetails(client, values, jupQuote, priceImpactBps) {
|
|
141
142
|
flashLoanToken = client.solautoPositionState.supply;
|
142
143
|
flashLoanTokenPrice = (0, generalUtils_2.safeGetPrice)(client.supplyMint);
|
143
144
|
}
|
144
|
-
const exactAmountBaseUnit = jupQuote &&
|
145
|
+
const exactAmountBaseUnit = jupQuote &&
|
146
|
+
(jupQuote.swapMode === "ExactOut" || jupQuote.swapMode === "ExactIn")
|
145
147
|
? BigInt(parseInt(jupQuote.inAmount))
|
146
148
|
: undefined;
|
147
149
|
return requiresFlashLoan
|
@@ -161,7 +163,8 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
161
163
|
const output = values.increasingLeverage
|
162
164
|
? client.solautoPositionState.supply
|
163
165
|
: client.solautoPositionState.debt;
|
164
|
-
const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
|
166
|
+
const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
|
167
|
+
(values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
165
168
|
const inputPrice = values.increasingLeverage
|
166
169
|
? (0, generalUtils_2.safeGetPrice)(client.debtMint)
|
167
170
|
: (0, generalUtils_2.safeGetPrice)(client.supplyMint);
|
package/package.json
CHANGED
@@ -133,11 +133,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
133
133
|
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
134
134
|
|
135
135
|
if (!this.solautoPositionState) {
|
136
|
-
const [maxLtv, liqThreshold] = await
|
137
|
-
this.umi,
|
138
|
-
{ mint: this.supplyMint },
|
139
|
-
{ mint: this.debtMint }
|
140
|
-
);
|
136
|
+
const [maxLtv, liqThreshold] = (await this.maxLtvAndLiqThreshold())!;
|
141
137
|
this.solautoPositionState = createFakePositionState(
|
142
138
|
{ mint: this.supplyMint },
|
143
139
|
{ mint: this.debtMint },
|
@@ -521,7 +517,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
521
517
|
: undefined,
|
522
518
|
rebalanceType,
|
523
519
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
524
|
-
targetInAmountBaseUnit: targetLiqUtilizationRateBps
|
520
|
+
targetInAmountBaseUnit: targetLiqUtilizationRateBps && rebalanceStep === "A"
|
525
521
|
? swapDetails.amount
|
526
522
|
: null,
|
527
523
|
limitGapBps: limitGapBps ?? null,
|
@@ -320,7 +320,7 @@ export class TransactionsManager {
|
|
320
320
|
) {
|
321
321
|
await retryWithExponentialBackoff(
|
322
322
|
async (attemptNum) =>
|
323
|
-
this.sendTransaction(
|
323
|
+
await this.sendTransaction(
|
324
324
|
updateLookupTable.updateLutTx,
|
325
325
|
updateLutTxName,
|
326
326
|
attemptNum,
|
@@ -472,7 +472,7 @@ export class TransactionsManager {
|
|
472
472
|
if (this.txHandler.localTest) {
|
473
473
|
await this.debugAccounts(itemSet, tx);
|
474
474
|
}
|
475
|
-
this.sendTransaction(
|
475
|
+
await this.sendTransaction(
|
476
476
|
tx,
|
477
477
|
itemSet.name(),
|
478
478
|
attemptNum,
|
@@ -26,9 +26,7 @@ import {
|
|
26
26
|
toBaseUnit,
|
27
27
|
} from "../numberUtils";
|
28
28
|
import { USD_DECIMALS } from "../../constants/generalAccounts";
|
29
|
-
import {
|
30
|
-
DEFAULT_LIMIT_GAP_BPS,
|
31
|
-
} from "../../constants/solautoConstants";
|
29
|
+
import { DEFAULT_LIMIT_GAP_BPS } from "../../constants/solautoConstants";
|
32
30
|
|
33
31
|
function getAdditionalAmountToDcaIn(dca: DCASettings): number {
|
34
32
|
if (dca.dcaInBaseUnit === BigInt(0)) {
|
@@ -125,7 +123,7 @@ function getTargetRateAndDcaAmount(
|
|
125
123
|
dca: DCASettings | undefined,
|
126
124
|
currentUnixTime: number,
|
127
125
|
targetLiqUtilizationRateBps?: number
|
128
|
-
): { targetRateBps: number; amountToDcaIn?: number
|
126
|
+
): { targetRateBps: number; amountToDcaIn?: number } {
|
129
127
|
if (targetLiqUtilizationRateBps !== undefined) {
|
130
128
|
return {
|
131
129
|
targetRateBps: targetLiqUtilizationRateBps,
|
@@ -238,7 +236,7 @@ export function getRebalanceValues(
|
|
238
236
|
debtAdjustmentUsd,
|
239
237
|
amountToDcaIn: amountToDcaIn ?? 0,
|
240
238
|
amountUsdToDcaIn,
|
241
|
-
dcaTokenType: dca?.tokenType
|
239
|
+
dcaTokenType: dca?.tokenType,
|
242
240
|
};
|
243
241
|
}
|
244
242
|
|
@@ -253,10 +251,12 @@ export function getFlashLoanDetails(
|
|
253
251
|
jupQuote: QuoteResponse,
|
254
252
|
priceImpactBps: number
|
255
253
|
): FlashLoanDetails | undefined {
|
256
|
-
let supplyUsd =
|
257
|
-
|
258
|
-
|
259
|
-
|
254
|
+
let supplyUsd =
|
255
|
+
fromBaseUnit(
|
256
|
+
client.solautoPositionState!.supply.amountUsed.baseAmountUsdValue,
|
257
|
+
USD_DECIMALS
|
258
|
+
) +
|
259
|
+
(values.dcaTokenType === TokenType.Supply ? values.amountUsdToDcaIn : 0);
|
260
260
|
let debtUsd = fromBaseUnit(
|
261
261
|
client.solautoPositionState!.debt.amountUsed.baseAmountUsdValue,
|
262
262
|
USD_DECIMALS
|
@@ -299,7 +299,8 @@ export function getFlashLoanDetails(
|
|
299
299
|
}
|
300
300
|
|
301
301
|
const exactAmountBaseUnit =
|
302
|
-
jupQuote &&
|
302
|
+
jupQuote &&
|
303
|
+
(jupQuote.swapMode === "ExactOut" || jupQuote.swapMode === "ExactIn")
|
303
304
|
? BigInt(parseInt(jupQuote.inAmount))
|
304
305
|
: undefined;
|
305
306
|
|
@@ -308,9 +309,7 @@ export function getFlashLoanDetails(
|
|
308
309
|
baseUnitAmount: exactAmountBaseUnit
|
309
310
|
? exactAmountBaseUnit +
|
310
311
|
BigInt(
|
311
|
-
Math.round(
|
312
|
-
Number(exactAmountBaseUnit) * fromBps(priceImpactBps)
|
313
|
-
)
|
312
|
+
Math.round(Number(exactAmountBaseUnit) * fromBps(priceImpactBps))
|
314
313
|
)
|
315
314
|
: toBaseUnit(
|
316
315
|
debtAdjustmentWithSlippage / flashLoanTokenPrice,
|
@@ -335,7 +334,8 @@ export function getJupSwapRebalanceDetails(
|
|
335
334
|
: client.solautoPositionState!.debt;
|
336
335
|
|
337
336
|
const usdToSwap =
|
338
|
-
Math.abs(values.debtAdjustmentUsd) +
|
337
|
+
Math.abs(values.debtAdjustmentUsd) +
|
338
|
+
(values.dcaTokenType === TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
339
339
|
|
340
340
|
const inputPrice = values.increasingLeverage
|
341
341
|
? safeGetPrice(client.debtMint)
|