@haven-fi/solauto-sdk 1.0.341 → 1.0.343
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/utils/jitoUtils.js +1 -1
- package/dist/utils/solauto/generalUtils.js +21 -11
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +4 -3
- package/package.json +1 -1
- package/src/utils/jitoUtils.ts +1 -1
- package/src/utils/solauto/generalUtils.ts +21 -21
- package/src/utils/solauto/rebalanceUtils.ts +17 -8
- package/tests/transactions/solautoMarginfi.ts +31 -21
package/dist/utils/jitoUtils.js
CHANGED
@@ -135,7 +135,7 @@ async function sendJitoBundledTransactions(umi, connection, signer, txs, txType,
|
|
135
135
|
// );
|
136
136
|
const serializedTxs = builtTxs.map((x) => x.serialize());
|
137
137
|
if (serializedTxs.find(x => x.length > 1232)) {
|
138
|
-
throw new Error("A transaction too large");
|
138
|
+
throw new Error("A transaction is too large");
|
139
139
|
}
|
140
140
|
onAwaitingSign?.();
|
141
141
|
const txSigs = await sendJitoBundle(serializedTxs.map((x) => bs58_1.default.encode(x)));
|
@@ -25,7 +25,6 @@ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters"
|
|
25
25
|
const constants_1 = require("../../constants");
|
26
26
|
const marginfiUtils_1 = require("../marginfiUtils");
|
27
27
|
const priceUtils_1 = require("../priceUtils");
|
28
|
-
const rebalanceUtils_1 = require("./rebalanceUtils");
|
29
28
|
function createDynamicSolautoProgram(programId) {
|
30
29
|
return {
|
31
30
|
name: "solauto",
|
@@ -92,16 +91,27 @@ function eligibleForRebalance(positionState, positionSettings, positionDca, curr
|
|
92
91
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
93
92
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
94
93
|
if (positionState.liqUtilizationRateBps - boostFrom <= bpsDistanceThreshold) {
|
95
|
-
if (positionState.liqUtilizationRateBps < boostFrom) {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
94
|
+
// if (positionState.liqUtilizationRateBps < boostFrom) {
|
95
|
+
// const values = getRebalanceValues(
|
96
|
+
// positionState!,
|
97
|
+
// positionSettings,
|
98
|
+
// positionDca,
|
99
|
+
// currentUnixSeconds(),
|
100
|
+
// supplyMintPrice,
|
101
|
+
// debtMintPrice
|
102
|
+
// );
|
103
|
+
// const sufficientLiquidity =
|
104
|
+
// fromBaseUnit(
|
105
|
+
// positionState.debt.amountCanBeUsed.baseAmountUsdValue,
|
106
|
+
// USD_DECIMALS
|
107
|
+
// ) *
|
108
|
+
// 0.95 >
|
109
|
+
// values.debtAdjustmentUsd;
|
110
|
+
// if (!sufficientLiquidity) {
|
111
|
+
// consoleLog("Insufficient debt liquidity to further boost");
|
112
|
+
// }
|
113
|
+
// return sufficientLiquidity ? "boost" : undefined;
|
114
|
+
// }
|
105
115
|
return "boost";
|
106
116
|
}
|
107
117
|
else if (repayFrom - positionState.liqUtilizationRateBps <=
|
@@ -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,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmI9C,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,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B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;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,GACnC,eAAe,CAwDjB;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,GACtB,gBAAgB,GAAG,SAAS,CAuE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CA2ChB"}
|
@@ -122,9 +122,10 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
122
122
|
? debtUsd + debtAdjustmentUsdAbs
|
123
123
|
: debtUsd;
|
124
124
|
const tempLiqUtilizationRateBps = (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState.liqThresholdBps);
|
125
|
-
const
|
126
|
-
|
127
|
-
|
125
|
+
const maxLiqUtilizationRateBps = (0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps, 0.015);
|
126
|
+
const requiresFlashLoan = supplyUsd <= 0 || tempLiqUtilizationRateBps > maxLiqUtilizationRateBps;
|
127
|
+
(0, generalUtils_2.consoleLog)("Requires flash loan:", requiresFlashLoan);
|
128
|
+
(0, generalUtils_2.consoleLog)("Intermediary liq utilization rate:", tempLiqUtilizationRateBps, `$${supplyUsd}`, `$${debtUsd}`, "Max:", maxLiqUtilizationRateBps);
|
128
129
|
let flashLoanToken = undefined;
|
129
130
|
let flashLoanTokenPrice = 0;
|
130
131
|
if (values.rebalanceDirection === generated_1.RebalanceDirection.Boost) {
|
package/package.json
CHANGED
package/src/utils/jitoUtils.ts
CHANGED
@@ -214,7 +214,7 @@ export async function sendJitoBundledTransactions(
|
|
214
214
|
|
215
215
|
const serializedTxs = builtTxs.map((x) => x.serialize());
|
216
216
|
if (serializedTxs.find(x => x.length > 1232)) {
|
217
|
-
throw new Error("A transaction too large");
|
217
|
+
throw new Error("A transaction is too large");
|
218
218
|
}
|
219
219
|
|
220
220
|
onAwaitingSign?.();
|
@@ -167,27 +167,27 @@ export function eligibleForRebalance(
|
|
167
167
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
168
168
|
|
169
169
|
if (positionState.liqUtilizationRateBps - boostFrom <= bpsDistanceThreshold) {
|
170
|
-
if (positionState.liqUtilizationRateBps < boostFrom) {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
}
|
170
|
+
// if (positionState.liqUtilizationRateBps < boostFrom) {
|
171
|
+
// const values = getRebalanceValues(
|
172
|
+
// positionState!,
|
173
|
+
// positionSettings,
|
174
|
+
// positionDca,
|
175
|
+
// currentUnixSeconds(),
|
176
|
+
// supplyMintPrice,
|
177
|
+
// debtMintPrice
|
178
|
+
// );
|
179
|
+
// const sufficientLiquidity =
|
180
|
+
// fromBaseUnit(
|
181
|
+
// positionState.debt.amountCanBeUsed.baseAmountUsdValue,
|
182
|
+
// USD_DECIMALS
|
183
|
+
// ) *
|
184
|
+
// 0.95 >
|
185
|
+
// values.debtAdjustmentUsd;
|
186
|
+
// if (!sufficientLiquidity) {
|
187
|
+
// consoleLog("Insufficient debt liquidity to further boost");
|
188
|
+
// }
|
189
|
+
// return sufficientLiquidity ? "boost" : undefined;
|
190
|
+
// }
|
191
191
|
|
192
192
|
return "boost";
|
193
193
|
} else if (
|
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
17
17
|
import { QuoteResponse } from "@jup-ag/api";
|
18
18
|
import { JupSwapDetails } from "../jupiterUtils";
|
19
|
-
import { currentUnixSeconds } from "../generalUtils";
|
19
|
+
import { consoleLog, currentUnixSeconds } from "../generalUtils";
|
20
20
|
import {
|
21
21
|
fromBaseUnit,
|
22
22
|
fromBps,
|
@@ -272,14 +272,23 @@ export function getFlashLoanDetails(
|
|
272
272
|
debtUsd,
|
273
273
|
client.solautoPositionState!.liqThresholdBps
|
274
274
|
);
|
275
|
+
const maxLiqUtilizationRateBps = getMaxLiqUtilizationRateBps(
|
276
|
+
client.solautoPositionState!.maxLtvBps,
|
277
|
+
client.solautoPositionState!.liqThresholdBps,
|
278
|
+
0.015
|
279
|
+
);
|
275
280
|
const requiresFlashLoan =
|
276
|
-
supplyUsd <= 0 ||
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
281
|
+
supplyUsd <= 0 || tempLiqUtilizationRateBps > maxLiqUtilizationRateBps;
|
282
|
+
|
283
|
+
consoleLog("Requires flash loan:", requiresFlashLoan);
|
284
|
+
consoleLog(
|
285
|
+
"Intermediary liq utilization rate:",
|
286
|
+
tempLiqUtilizationRateBps,
|
287
|
+
`$${supplyUsd}`,
|
288
|
+
`$${debtUsd}`,
|
289
|
+
"Max:",
|
290
|
+
maxLiqUtilizationRateBps
|
291
|
+
);
|
283
292
|
|
284
293
|
let flashLoanToken: PositionTokenUsage | undefined = undefined;
|
285
294
|
let flashLoanTokenPrice = 0;
|
@@ -26,15 +26,18 @@ import {
|
|
26
26
|
SOLAUTO_TEST_PROGRAM,
|
27
27
|
USDC,
|
28
28
|
} from "../../src/constants";
|
29
|
-
import {
|
29
|
+
import {
|
30
|
+
buildHeliusApiUrl,
|
31
|
+
positionStateWithLatestPrices,
|
32
|
+
} from "../../src/utils";
|
30
33
|
import { PriorityFeeSetting } from "../../src/types";
|
31
34
|
|
32
35
|
describe("Solauto Marginfi tests", async () => {
|
33
|
-
const signer = setupTest();
|
34
|
-
|
36
|
+
// const signer = setupTest();
|
37
|
+
const signer = setupTest("solauto-manager");
|
35
38
|
|
36
|
-
const payForTransactions =
|
37
|
-
const testProgram =
|
39
|
+
const payForTransactions = true;
|
40
|
+
const testProgram = false;
|
38
41
|
const positionId = 1;
|
39
42
|
|
40
43
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
@@ -51,7 +54,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
51
54
|
await client.initialize({
|
52
55
|
signer,
|
53
56
|
positionId,
|
54
|
-
authority: new PublicKey("
|
57
|
+
authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
|
55
58
|
// new: true,
|
56
59
|
// marginfiAccount: new PublicKey(
|
57
60
|
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
@@ -61,6 +64,13 @@ describe("Solauto Marginfi tests", async () => {
|
|
61
64
|
// debtMint: new PublicKey(USDC),
|
62
65
|
});
|
63
66
|
|
67
|
+
const data = client.solautoPositionData;
|
68
|
+
console.log(data);
|
69
|
+
console.log(data?.state.supply.amountCanBeUsed);
|
70
|
+
console.log(data?.state.debt.amountCanBeUsed);
|
71
|
+
|
72
|
+
console.log(await positionStateWithLatestPrices(data!.state));
|
73
|
+
|
64
74
|
const transactionItems: TransactionItem[] = [];
|
65
75
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
66
76
|
// boostToBps: maxBoostToBps(
|
@@ -119,13 +129,13 @@ describe("Solauto Marginfi tests", async () => {
|
|
119
129
|
// )
|
120
130
|
// );
|
121
131
|
|
122
|
-
transactionItems.push(
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
);
|
132
|
+
// transactionItems.push(
|
133
|
+
// new TransactionItem(
|
134
|
+
// async (attemptNum) =>
|
135
|
+
// await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
136
|
+
// "rebalance"
|
137
|
+
// )
|
138
|
+
// );
|
129
139
|
|
130
140
|
// transactionItems.push(
|
131
141
|
// new TransactionItem(
|
@@ -155,14 +165,14 @@ describe("Solauto Marginfi tests", async () => {
|
|
155
165
|
// )
|
156
166
|
// );
|
157
167
|
|
158
|
-
const statuses = await new TransactionsManager(
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
).clientSend(transactionItems);
|
168
|
+
// const statuses = await new TransactionsManager(
|
169
|
+
// client,
|
170
|
+
// undefined,
|
171
|
+
// !payForTransactions ? "only-simulate" : "normal",
|
172
|
+
// PriorityFeeSetting.Low,
|
173
|
+
// true
|
174
|
+
// ).clientSend(transactionItems);
|
165
175
|
|
166
|
-
console.log(statuses);
|
176
|
+
// console.log(statuses);
|
167
177
|
});
|
168
178
|
});
|