@haven-fi/solauto-sdk 1.0.126 → 1.0.128
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/transactions/transactionsManager.js +2 -2
- package/dist/utils/numberUtils.js +2 -2
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +3 -9
- package/package.json +1 -1
- package/src/transactions/transactionsManager.ts +5 -5
- package/src/utils/numberUtils.ts +2 -2
- package/src/utils/solauto/rebalanceUtils.ts +8 -9
- package/tests/transactions/solautoMarginfi.ts +30 -40
@@ -211,13 +211,13 @@ class TransactionsManager {
|
|
211
211
|
choresBefore.prepend(updateLookupTable.updateLutTx);
|
212
212
|
}
|
213
213
|
if (choresBefore.getInstructions().length > 0) {
|
214
|
-
const chore = new TransactionItem(async () => ({ tx: choresBefore })
|
214
|
+
const chore = new TransactionItem(async () => ({ tx: choresBefore }));
|
215
215
|
await chore.initialize();
|
216
216
|
items.unshift(chore);
|
217
217
|
this.txHandler.log("Chores before: ", choresBefore.getInstructions().length);
|
218
218
|
}
|
219
219
|
if (choresAfter.getInstructions().length > 0) {
|
220
|
-
const chore = new TransactionItem(async () => ({ tx: choresAfter }));
|
220
|
+
const chore = new TransactionItem(async () => ({ tx: choresAfter }), "closing temp accounts");
|
221
221
|
await chore.initialize();
|
222
222
|
items.push(chore);
|
223
223
|
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
@@ -69,9 +69,9 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
|
|
69
69
|
function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetWorthUsd) {
|
70
70
|
const minSize = 10000; // Minimum position size
|
71
71
|
const maxSize = 500000; // Maximum position size
|
72
|
-
const maxFeeBps =
|
72
|
+
const maxFeeBps = 200; // Fee in basis points for minSize (2%)
|
73
73
|
const minFeeBps = 50; // Fee in basis points for maxSize (0.5%)
|
74
|
-
const k =
|
74
|
+
const k = 1.5;
|
75
75
|
let feeBps = 0;
|
76
76
|
if (targetLiqUtilizationRateBps !== undefined) {
|
77
77
|
feeBps = minFeeBps;
|
@@ -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,EAC1B,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,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,CA0EjB;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,
|
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,EAC1B,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,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,CA0EjB;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,CAmE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
|
@@ -131,15 +131,9 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
131
131
|
? debtUsd + debtAdjustmentWithSlippage
|
132
132
|
: debtUsd;
|
133
133
|
const tempLiqUtilizationRateBps = (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState.liqThresholdBps);
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
// tempLiqUtilizationRateBps >
|
138
|
-
// getMaxLiqUtilizationRateBps(
|
139
|
-
// client.solautoPositionState!.maxLtvBps,
|
140
|
-
// client.solautoPositionState!.liqThresholdBps,
|
141
|
-
// 0.01
|
142
|
-
// );
|
134
|
+
const requiresFlashLoan = supplyUsd <= 0 ||
|
135
|
+
tempLiqUtilizationRateBps >
|
136
|
+
(0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps, 0.01);
|
143
137
|
let flashLoanToken = undefined;
|
144
138
|
let flashLoanTokenPrice = 0;
|
145
139
|
if (values.increasingLeverage) {
|
package/package.json
CHANGED
@@ -320,10 +320,7 @@ export class TransactionsManager {
|
|
320
320
|
choresBefore.prepend(updateLookupTable.updateLutTx);
|
321
321
|
}
|
322
322
|
if (choresBefore.getInstructions().length > 0) {
|
323
|
-
const chore = new TransactionItem(
|
324
|
-
async () => ({ tx: choresBefore }),
|
325
|
-
"create account(s)"
|
326
|
-
);
|
323
|
+
const chore = new TransactionItem(async () => ({ tx: choresBefore }));
|
327
324
|
await chore.initialize();
|
328
325
|
items.unshift(chore);
|
329
326
|
this.txHandler.log(
|
@@ -332,7 +329,10 @@ export class TransactionsManager {
|
|
332
329
|
);
|
333
330
|
}
|
334
331
|
if (choresAfter.getInstructions().length > 0) {
|
335
|
-
const chore = new TransactionItem(
|
332
|
+
const chore = new TransactionItem(
|
333
|
+
async () => ({ tx: choresAfter }),
|
334
|
+
"closing temp accounts"
|
335
|
+
);
|
336
336
|
await chore.initialize();
|
337
337
|
items.push(chore);
|
338
338
|
this.txHandler.log(
|
package/src/utils/numberUtils.ts
CHANGED
@@ -97,9 +97,9 @@ export function getSolautoFeesBps(
|
|
97
97
|
} {
|
98
98
|
const minSize = 10_000; // Minimum position size
|
99
99
|
const maxSize = 500_000; // Maximum position size
|
100
|
-
const maxFeeBps =
|
100
|
+
const maxFeeBps = 200; // Fee in basis points for minSize (2%)
|
101
101
|
const minFeeBps = 50; // Fee in basis points for maxSize (0.5%)
|
102
|
-
const k =
|
102
|
+
const k = 1.5;
|
103
103
|
|
104
104
|
let feeBps: number = 0;
|
105
105
|
|
@@ -287,15 +287,14 @@ export function getFlashLoanDetails(
|
|
287
287
|
debtUsd,
|
288
288
|
client.solautoPositionState!.liqThresholdBps
|
289
289
|
);
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
// );
|
290
|
+
const requiresFlashLoan =
|
291
|
+
supplyUsd <= 0 ||
|
292
|
+
tempLiqUtilizationRateBps >
|
293
|
+
getMaxLiqUtilizationRateBps(
|
294
|
+
client.solautoPositionState!.maxLtvBps,
|
295
|
+
client.solautoPositionState!.liqThresholdBps,
|
296
|
+
0.01
|
297
|
+
);
|
299
298
|
|
300
299
|
let flashLoanToken: PositionTokenUsage | undefined = undefined;
|
301
300
|
let flashLoanTokenPrice = 0;
|
@@ -1,20 +1,15 @@
|
|
1
1
|
import { describe, it } from "mocha";
|
2
2
|
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
3
3
|
import { setupTest } from "../shared";
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
SolautoMarginfiClient,
|
6
|
+
} from "../../src/clients/solautoMarginfiClient";
|
5
7
|
import {
|
6
8
|
solautoAction,
|
7
9
|
SolautoSettingsParametersInpArgs,
|
8
10
|
} from "../../src/generated";
|
9
11
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
10
|
-
import {
|
11
|
-
getDebtAdjustmentUsd,
|
12
|
-
getLiqUtilzationRateBps,
|
13
|
-
maxBoostToBps,
|
14
|
-
maxRepayFromBps,
|
15
|
-
maxRepayToBps,
|
16
|
-
toBaseUnit,
|
17
|
-
} from "../../src/utils/numberUtils";
|
12
|
+
import { maxBoostToBps, maxRepayFromBps, maxRepayToBps, toBaseUnit } from "../../src/utils/numberUtils";
|
18
13
|
import { NATIVE_MINT } from "@solana/spl-token";
|
19
14
|
import { getTokenPrices } from "../../src/utils/generalUtils";
|
20
15
|
import {
|
@@ -33,22 +28,25 @@ describe("Solauto Marginfi tests", async () => {
|
|
33
28
|
const positionId = 1;
|
34
29
|
|
35
30
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
31
|
+
|
36
32
|
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
37
33
|
|
38
34
|
const supply = NATIVE_MINT;
|
39
35
|
const supplyDecimals = 9;
|
40
36
|
const debtDecimals = 6;
|
41
37
|
|
42
|
-
await client.initialize(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
await client.initialize(
|
39
|
+
{
|
40
|
+
signer,
|
41
|
+
positionId,
|
42
|
+
authority: new PublicKey("AprYCPiVeKMCgjQ2ZufwChMzvQ5kFjJo2ekTLSkXsQDm")
|
43
|
+
// marginfiAccount: new PublicKey(
|
44
|
+
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
45
|
+
// ),
|
46
|
+
// supplyMint: NATIVE_MINT,
|
47
|
+
// debtMint: new PublicKey(USDC_MINT),
|
48
|
+
}
|
49
|
+
);
|
52
50
|
|
53
51
|
const transactionItems: TransactionItem[] = [];
|
54
52
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
@@ -122,13 +120,13 @@ describe("Solauto Marginfi tests", async () => {
|
|
122
120
|
// }, "deposit")
|
123
121
|
// );
|
124
122
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
123
|
+
transactionItems.push(
|
124
|
+
new TransactionItem(
|
125
|
+
async (attemptNum) =>
|
126
|
+
await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
127
|
+
"rebalance"
|
128
|
+
)
|
129
|
+
);
|
132
130
|
|
133
131
|
// transactionItems.push(
|
134
132
|
// new TransactionItem(
|
@@ -157,19 +155,11 @@ describe("Solauto Marginfi tests", async () => {
|
|
157
155
|
// )
|
158
156
|
// );
|
159
157
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
// const debtAdjustment = getDebtAdjustmentUsd(8696, 366, 165, 7000);
|
168
|
-
// const newLiqUtilizationRate = getLiqUtilzationRateBps(366 + debtAdjustment, 165 + debtAdjustment, 8696);
|
169
|
-
// console.log(newLiqUtilizationRate);
|
170
|
-
|
171
|
-
console.log("CURRENT", Number(client.solautoPositionState?.supply.amountUsed.baseUnit));
|
172
|
-
const freshState = await client.getFreshPositionState();
|
173
|
-
console.log("FRESH", Number(freshState!.supply.amountUsed.baseUnit));
|
158
|
+
await new TransactionsManager(
|
159
|
+
client,
|
160
|
+
undefined,
|
161
|
+
!payForTransactions ? "only-simulate" : "normal",
|
162
|
+
useJitoBundle
|
163
|
+
).clientSend(transactionItems);
|
174
164
|
});
|
175
165
|
});
|