@haven-fi/solauto-sdk 1.0.120 → 1.0.122
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 +12 -0
- package/dist/utils/jupiterUtils.js +1 -3
- package/dist/utils/solauto/rebalanceUtils.js +1 -1
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +14 -2
- package/src/utils/jupiterUtils.ts +1 -1
- package/src/utils/solauto/rebalanceUtils.ts +1 -1
- package/tests/transactions/solautoMarginfi.ts +42 -32
@@ -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,EACb,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;AAWnE,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;IAE5B,sBAAs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S,CAAC;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IAkE1C,8BAA8B;IA0CpC,eAAe,IAAI,SAAS;IAI5B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAU/B,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,WAAW,CACT,gBAAgB,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;CA4BlE"}
|
@@ -12,6 +12,7 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
12
12
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
13
13
|
const marginfiUtils_1 = require("../utils/marginfiUtils");
|
14
14
|
const numberUtils_1 = require("../utils/numberUtils");
|
15
|
+
const constants_1 = require("../constants");
|
15
16
|
const utils_1 = require("../utils");
|
16
17
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
17
18
|
constructor() {
|
@@ -414,6 +415,17 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
414
415
|
return state;
|
415
416
|
}
|
416
417
|
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.supplyMint, this.debtMint, this.livePositionUpdates);
|
418
|
+
if (freshState) {
|
419
|
+
const supplyPrice = constants_1.PRICES[(freshState?.supply.mint ?? web3_js_1.PublicKey.default).toString()].price;
|
420
|
+
const debtPrice = constants_1.PRICES[(freshState?.debt.mint ?? web3_js_1.PublicKey.default).toString()].price;
|
421
|
+
console.log("Supply price: ", supplyPrice);
|
422
|
+
console.log("Debt price: ", supplyPrice);
|
423
|
+
console.log("Fresh state", freshState);
|
424
|
+
console.log("Liq threshold bps:", freshState.liqUtilizationRateBps);
|
425
|
+
console.log("Liq utilization rate bps:", freshState.liqUtilizationRateBps);
|
426
|
+
console.log("Supply USD:", (0, numberUtils_1.fromBaseUnit)(freshState.supply.amountUsed.baseUnit, freshState.supply.decimals) * supplyPrice);
|
427
|
+
console.log("Debt USD:", (0, numberUtils_1.fromBaseUnit)(freshState.debt.amountUsed.baseUnit, freshState.supply.decimals) * debtPrice);
|
428
|
+
}
|
417
429
|
return freshState;
|
418
430
|
}
|
419
431
|
}
|
@@ -34,9 +34,7 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
34
34
|
slippageBps: 10,
|
35
35
|
maxAccounts: !swapDetails.exactOut ? 60 : undefined,
|
36
36
|
}), 3);
|
37
|
-
const finalPriceSlippageBps = Math.round(Math.max(
|
38
|
-
// 50,
|
39
|
-
quoteResponse.slippageBps, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1) *
|
37
|
+
const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1) *
|
40
38
|
(1 + (swapDetails.slippageBpsIncFactor ?? 0)));
|
41
39
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
42
40
|
console.log(quoteResponse);
|
@@ -174,7 +174,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
174
174
|
inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
|
175
175
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
176
176
|
destinationWallet: client.solautoPosition,
|
177
|
-
|
177
|
+
slippageBpsIncFactor: 0.25 + (attemptNum ?? 0) * 0.2,
|
178
178
|
amount: rebalancingToZero
|
179
179
|
? client.solautoPositionState.debt.amountUsed.baseUnit +
|
180
180
|
BigInt(Math.round(Number(client.solautoPositionState.debt.amountUsed.baseUnit) *
|
package/package.json
CHANGED
@@ -54,8 +54,8 @@ import {
|
|
54
54
|
getMarginfiAccountPositionState,
|
55
55
|
getMaxLtvAndLiqThreshold,
|
56
56
|
} from "../utils/marginfiUtils";
|
57
|
-
import { bytesToI80F48, toBps } from "../utils/numberUtils";
|
58
|
-
import { SOLAUTO_MANAGER } from "../constants";
|
57
|
+
import { bytesToI80F48, fromBaseUnit, toBps } from "../utils/numberUtils";
|
58
|
+
import { PRICES, SOLAUTO_MANAGER } from "../constants";
|
59
59
|
import { createFakePositionState } from "../utils";
|
60
60
|
|
61
61
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
@@ -626,6 +626,18 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
626
626
|
this.livePositionUpdates
|
627
627
|
);
|
628
628
|
|
629
|
+
if (freshState) {
|
630
|
+
const supplyPrice = PRICES[(freshState?.supply.mint ?? PublicKey.default).toString()].price;
|
631
|
+
const debtPrice = PRICES[(freshState?.debt.mint ?? PublicKey.default).toString()].price;
|
632
|
+
console.log("Supply price: ", supplyPrice);
|
633
|
+
console.log("Debt price: ", supplyPrice);
|
634
|
+
console.log("Fresh state", freshState);
|
635
|
+
console.log("Liq threshold bps:", freshState.liqUtilizationRateBps);
|
636
|
+
console.log("Liq utilization rate bps:", freshState.liqUtilizationRateBps);
|
637
|
+
console.log("Supply USD:", fromBaseUnit(freshState.supply.amountUsed.baseUnit, freshState.supply.decimals) * supplyPrice);
|
638
|
+
console.log("Debt USD:", fromBaseUnit(freshState.debt.amountUsed.baseUnit, freshState.supply.decimals) * debtPrice);
|
639
|
+
}
|
640
|
+
|
629
641
|
return freshState;
|
630
642
|
}
|
631
643
|
}
|
@@ -355,7 +355,7 @@ export function getJupSwapRebalanceDetails(
|
|
355
355
|
inputMint: toWeb3JsPublicKey(input.mint),
|
356
356
|
outputMint: toWeb3JsPublicKey(output.mint),
|
357
357
|
destinationWallet: client.solautoPosition,
|
358
|
-
|
358
|
+
slippageBpsIncFactor: 0.25 + (attemptNum ?? 0) * 0.2,
|
359
359
|
amount: rebalancingToZero
|
360
360
|
? client.solautoPositionState!.debt.amountUsed.baseUnit +
|
361
361
|
BigInt(
|
@@ -1,15 +1,20 @@
|
|
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 {
|
5
|
-
SolautoMarginfiClient,
|
6
|
-
} from "../../src/clients/solautoMarginfiClient";
|
4
|
+
import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
|
7
5
|
import {
|
8
6
|
solautoAction,
|
9
7
|
SolautoSettingsParametersInpArgs,
|
10
8
|
} from "../../src/generated";
|
11
9
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
12
|
-
import {
|
10
|
+
import {
|
11
|
+
getDebtAdjustmentUsd,
|
12
|
+
getLiqUtilzationRateBps,
|
13
|
+
maxBoostToBps,
|
14
|
+
maxRepayFromBps,
|
15
|
+
maxRepayToBps,
|
16
|
+
toBaseUnit,
|
17
|
+
} from "../../src/utils/numberUtils";
|
13
18
|
import { NATIVE_MINT } from "@solana/spl-token";
|
14
19
|
import { getTokenPrices } from "../../src/utils/generalUtils";
|
15
20
|
import {
|
@@ -20,33 +25,30 @@ import { PublicKey } from "@solana/web3.js";
|
|
20
25
|
import { USDC_MINT } from "../../src/constants";
|
21
26
|
|
22
27
|
describe("Solauto Marginfi tests", async () => {
|
23
|
-
const signer = setupTest();
|
24
|
-
|
28
|
+
// const signer = setupTest();
|
29
|
+
const signer = setupTest("solauto-manager");
|
25
30
|
|
26
31
|
const payForTransactions = false;
|
27
32
|
const useJitoBundle = false;
|
28
33
|
const positionId = 1;
|
29
34
|
|
30
35
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
31
|
-
|
32
36
|
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
33
37
|
|
34
38
|
const supply = NATIVE_MINT;
|
35
39
|
const supplyDecimals = 9;
|
36
40
|
const debtDecimals = 6;
|
37
41
|
|
38
|
-
await client.initialize(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
}
|
49
|
-
);
|
42
|
+
await client.initialize({
|
43
|
+
signer,
|
44
|
+
positionId,
|
45
|
+
authority: new PublicKey("E5BBsR1sUToPc3jXVwhrK5ttSiy6xhWJDMdQLvkgNppe")
|
46
|
+
// marginfiAccount: new PublicKey(
|
47
|
+
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
48
|
+
// ),
|
49
|
+
// supplyMint: NATIVE_MINT,
|
50
|
+
// debtMint: new PublicKey(USDC_MINT),
|
51
|
+
});
|
50
52
|
|
51
53
|
const transactionItems: TransactionItem[] = [];
|
52
54
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
@@ -120,13 +122,13 @@ describe("Solauto Marginfi tests", async () => {
|
|
120
122
|
// }, "deposit")
|
121
123
|
// );
|
122
124
|
|
123
|
-
transactionItems.push(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
);
|
125
|
+
// transactionItems.push(
|
126
|
+
// new TransactionItem(
|
127
|
+
// async (attemptNum) =>
|
128
|
+
// await buildSolautoRebalanceTransaction(client, 1500, attemptNum),
|
129
|
+
// "rebalance"
|
130
|
+
// )
|
131
|
+
// );
|
130
132
|
|
131
133
|
// transactionItems.push(
|
132
134
|
// new TransactionItem(
|
@@ -155,11 +157,19 @@ describe("Solauto Marginfi tests", async () => {
|
|
155
157
|
// )
|
156
158
|
// );
|
157
159
|
|
158
|
-
await new TransactionsManager(
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
).clientSend(transactionItems);
|
160
|
+
// await new TransactionsManager(
|
161
|
+
// client,
|
162
|
+
// undefined,
|
163
|
+
// !payForTransactions ? "only-simulate" : "normal",
|
164
|
+
// useJitoBundle
|
165
|
+
// ).clientSend(transactionItems);
|
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));
|
164
174
|
});
|
165
175
|
});
|