@haven-fi/solauto-sdk 1.0.640 → 1.0.642
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/constants/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +2 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +2 -2
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +1 -0
- package/dist/utils/numberUtils.js +3 -3
- package/package.json +1 -1
- package/src/constants/solautoConstants.ts +2 -0
- package/src/services/flashLoans/marginfiFlProvider.ts +1 -0
- package/src/services/rebalance/rebalanceSwapManager.ts +2 -2
- package/src/services/rebalance/rebalanceTxBuilder.ts +1 -0
- package/src/utils/numberUtils.ts +4 -4
@@ -5,6 +5,7 @@ export declare const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
|
5
5
|
export declare const MIN_REPAY_GAP_BPS = 50;
|
6
6
|
export declare const MIN_BOOST_GAP_BPS = 50;
|
7
7
|
export declare const MIN_USD_SUPPORTED_POSITION = 1000;
|
8
|
+
export declare const OFFSET_FROM_MAX_LTV = 0.005;
|
8
9
|
export declare const REFERRER_PERCENTAGE = 0.15;
|
9
10
|
export declare const PRICES: {
|
10
11
|
[key: string]: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAEvG,eAAO,MAAM,iBAAiB,UAS7B,CAAC;AAEF,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAEvG,eAAO,MAAM,iBAAiB,UAS7B,CAAC;AAEF,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.JITO_TIP_ACCOUNTS = exports.PRICES = exports.REFERRER_PERCENTAGE = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
|
3
|
+
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.JITO_TIP_ACCOUNTS = exports.PRICES = exports.REFERRER_PERCENTAGE = exports.OFFSET_FROM_MAX_LTV = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
6
6
|
const generalConstants_1 = require("./generalConstants");
|
@@ -12,6 +12,7 @@ exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
|
12
12
|
exports.MIN_REPAY_GAP_BPS = 50;
|
13
13
|
exports.MIN_BOOST_GAP_BPS = 50;
|
14
14
|
exports.MIN_USD_SUPPORTED_POSITION = 1000;
|
15
|
+
exports.OFFSET_FROM_MAX_LTV = 0.005;
|
15
16
|
exports.REFERRER_PERCENTAGE = 0.15;
|
16
17
|
exports.PRICES = {};
|
17
18
|
exports.JITO_TIP_ACCOUNTS = [
|
@@ -109,7 +109,7 @@ class RebalanceSwapManager {
|
|
109
109
|
exactIn,
|
110
110
|
exactOut,
|
111
111
|
amount: swapAmount,
|
112
|
-
slippageBps: swappingMeme ?
|
112
|
+
slippageBps: swappingMeme ? 200 : 50,
|
113
113
|
};
|
114
114
|
(0, utils_1.consoleLog)("Swap input:", swapInput);
|
115
115
|
if (exactIn && (rebalanceToZero || this.values.repayingCloseToMaxLtv)) {
|
@@ -129,7 +129,7 @@ class RebalanceSwapManager {
|
|
129
129
|
}
|
130
130
|
this.swapParams = {
|
131
131
|
...swapInput,
|
132
|
-
destinationWallet:
|
132
|
+
destinationWallet: exactOut
|
133
133
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.client.signer.publicKey)
|
134
134
|
: this.client.pos.publicKey,
|
135
135
|
slippageIncFactor: 0.2 + attemptNum * 0.25,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AA0BrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IARtC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA;IAG9C,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;YAyCd,qBAAqB;IAyCnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,yBAAyB;YA4BnB,mBAAmB;YAwBnB,sBAAsB;YAyBtB,mBAAmB;
|
1
|
+
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AA0BrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IARtC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA;IAG9C,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;YAyCd,qBAAqB;IAyCnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,yBAAyB;YA4BnB,mBAAmB;YAwBnB,sBAAsB;YAyBtB,mBAAmB;IAmEpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
|
@@ -195,6 +195,7 @@ class RebalanceTxBuilder {
|
|
195
195
|
const flashBorrowDest = exactOut
|
196
196
|
? (0, utils_1.getTokenAccount)(this.client.pos.publicKey, new web3_js_1.PublicKey(swapQuote.outputMint))
|
197
197
|
: (0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.client.signer.publicKey), new web3_js_1.PublicKey(swapQuote.inputMint));
|
198
|
+
(0, utils_1.consoleLog)("Flash borrow dest:", flashBorrowDest.toString());
|
198
199
|
tx = tx.add([
|
199
200
|
setupIx,
|
200
201
|
this.client.flProvider.flashBorrow(flashLoanDetails, flashBorrowDest),
|
@@ -120,11 +120,11 @@ function getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, offsetFromMaxLt
|
|
120
120
|
1); // -1 to account for any rounding issues
|
121
121
|
}
|
122
122
|
function maxRepayFromBps(maxLtvBps, liqThresholdBps) {
|
123
|
-
return Math.min(9000, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000,
|
123
|
+
return Math.min(9000, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000, constants_1.OFFSET_FROM_MAX_LTV));
|
124
124
|
}
|
125
125
|
function maxRepayToBps(maxLtvBps, liqThresholdBps) {
|
126
|
-
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.MIN_REPAY_GAP_BPS, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps,
|
126
|
+
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.MIN_REPAY_GAP_BPS, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, constants_1.OFFSET_FROM_MAX_LTV));
|
127
127
|
}
|
128
128
|
function maxBoostToBps(maxLtvBps, liqThresholdBps) {
|
129
|
-
return Math.min(maxRepayToBps(maxLtvBps, liqThresholdBps), getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps,
|
129
|
+
return Math.min(maxRepayToBps(maxLtvBps, liqThresholdBps), getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, constants_1.OFFSET_FROM_MAX_LTV));
|
130
130
|
}
|
package/package.json
CHANGED
@@ -26,6 +26,8 @@ export const MIN_REPAY_GAP_BPS = 50;
|
|
26
26
|
export const MIN_BOOST_GAP_BPS = 50;
|
27
27
|
export const MIN_USD_SUPPORTED_POSITION = 1000;
|
28
28
|
|
29
|
+
export const OFFSET_FROM_MAX_LTV = 0.005;
|
30
|
+
|
29
31
|
export const REFERRER_PERCENTAGE = 0.15;
|
30
32
|
|
31
33
|
export const PRICES: { [key: string]: { realtimePrice: number; emaPrice: number; time: number } } = {};
|
@@ -253,6 +253,7 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
253
253
|
);
|
254
254
|
const iMfiAccount = this.iMfiAccount(flashLoan.liquiditySource)!;
|
255
255
|
|
256
|
+
consoleLog(bank.publicKey.toString(), associatedBankAccs);
|
256
257
|
return transactionBuilder()
|
257
258
|
.add(
|
258
259
|
lendingAccountStartFlashloan(this.umi, {
|
@@ -174,7 +174,7 @@ export class RebalanceSwapManager {
|
|
174
174
|
exactIn,
|
175
175
|
exactOut,
|
176
176
|
amount: swapAmount,
|
177
|
-
slippageBps: swappingMeme ?
|
177
|
+
slippageBps: swappingMeme ? 200 : 50,
|
178
178
|
};
|
179
179
|
consoleLog("Swap input:", swapInput);
|
180
180
|
|
@@ -197,7 +197,7 @@ export class RebalanceSwapManager {
|
|
197
197
|
|
198
198
|
this.swapParams = {
|
199
199
|
...swapInput,
|
200
|
-
destinationWallet:
|
200
|
+
destinationWallet: exactOut
|
201
201
|
? toWeb3JsPublicKey(this.client.signer.publicKey)
|
202
202
|
: this.client.pos.publicKey,
|
203
203
|
slippageIncFactor: 0.2 + attemptNum * 0.25,
|
@@ -337,6 +337,7 @@ export class RebalanceTxBuilder {
|
|
337
337
|
new PublicKey(swapQuote.inputMint)
|
338
338
|
);
|
339
339
|
|
340
|
+
consoleLog("Flash borrow dest:", flashBorrowDest.toString());
|
340
341
|
tx = tx.add([
|
341
342
|
setupIx,
|
342
343
|
this.client.flProvider.flashBorrow(flashLoanDetails, flashBorrowDest),
|
package/src/utils/numberUtils.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BASIS_POINTS, MIN_REPAY_GAP_BPS, USD_DECIMALS } from "../constants";
|
1
|
+
import { BASIS_POINTS, MIN_REPAY_GAP_BPS, OFFSET_FROM_MAX_LTV, USD_DECIMALS } from "../constants";
|
2
2
|
import { PositionState } from "../generated";
|
3
3
|
|
4
4
|
export function calcNetWorthUsd(state?: PositionState) {
|
@@ -169,20 +169,20 @@ export function getMaxLiqUtilizationRateBps(
|
|
169
169
|
export function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number) {
|
170
170
|
return Math.min(
|
171
171
|
9000,
|
172
|
-
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000,
|
172
|
+
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000, OFFSET_FROM_MAX_LTV)
|
173
173
|
);
|
174
174
|
}
|
175
175
|
|
176
176
|
export function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number) {
|
177
177
|
return Math.min(
|
178
178
|
maxRepayFromBps(maxLtvBps, liqThresholdBps) - MIN_REPAY_GAP_BPS,
|
179
|
-
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps,
|
179
|
+
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, OFFSET_FROM_MAX_LTV)
|
180
180
|
);
|
181
181
|
}
|
182
182
|
|
183
183
|
export function maxBoostToBps(maxLtvBps: number, liqThresholdBps: number) {
|
184
184
|
return Math.min(
|
185
185
|
maxRepayToBps(maxLtvBps, liqThresholdBps),
|
186
|
-
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps,
|
186
|
+
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, OFFSET_FROM_MAX_LTV)
|
187
187
|
);
|
188
188
|
}
|