@haven-fi/solauto-sdk 1.0.531 → 1.0.532
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/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +8 -8
- package/dist/utils/priceUtils.js +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +2 -2
- package/package.json +1 -1
- package/src/utils/jupiterUtils.ts +12 -9
- package/src/utils/priceUtils.ts +1 -1
- package/src/utils/solauto/rebalanceUtils.ts +2 -2
- package/tests/transactions/solautoMarginfi.ts +2 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAUrB,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,iBAAiB,EAAE,SAAS,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAgBD,wBAAsB,WAAW,CAAC,WAAW,EAAE,YAAY,0BAsB1D;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,E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;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAmF7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA6B5E"}
|
@@ -91,16 +91,16 @@ async function getJupPriceData(mints, extraInfo) {
|
|
91
91
|
mints.map((x) => x.toString()).join(",") +
|
92
92
|
(extraInfo ? "&showExtraInfo=true" : ""))).json();
|
93
93
|
const result = res.data;
|
94
|
-
if (!result ||
|
95
|
-
result === null ||
|
96
|
-
(typeof result === "object" &&
|
97
|
-
Boolean(Object.values(result).filter((x) => x === null).length)) ||
|
98
|
-
(typeof result === "object" &&
|
99
|
-
Object.values(result)
|
100
|
-
.map((x) => parseFloat(x.price))
|
101
|
-
.includes(0))) {
|
94
|
+
if (!result || result === null || typeof result !== "object") {
|
102
95
|
throw new Error("Failed to get token prices using Jupiter");
|
103
96
|
}
|
97
|
+
const invalidValues = Boolean(Object.values(result).filter((x) => x === null).length) ||
|
98
|
+
Boolean(Object.values(result)
|
99
|
+
.map((x) => parseFloat(x.price))
|
100
|
+
.filter((x) => x <= 0).length);
|
101
|
+
if (invalidValues) {
|
102
|
+
throw new Error("Invalid price values");
|
103
|
+
}
|
104
104
|
return result;
|
105
105
|
}, 8);
|
106
106
|
return data;
|
package/dist/utils/priceUtils.js
CHANGED
@@ -99,7 +99,7 @@ async function getSwitchboardPrices(mints) {
|
|
99
99
|
prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
100
100
|
const res = await crossbar.simulateSolanaFeeds("mainnet", mints.map((x) => switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[x.toString()]));
|
101
101
|
const p = res.flatMap((x) => x.results[0]);
|
102
|
-
if (p.filter((x) => !x || isNaN(Number(x))).length > 0) {
|
102
|
+
if (p.filter((x) => !x || isNaN(Number(x)) || Number(x) < 0).length > 0) {
|
103
103
|
throw new Error("Unable to fetch Switchboard prices");
|
104
104
|
}
|
105
105
|
return p;
|
@@ -144,8 +144,8 @@ function postRebalanceLiqUtilizationRateBps(client, values, swapOutputAmount) {
|
|
144
144
|
debtUsd = boost ? debtUsd + debtAdjustmentUsdAbs : debtUsd - swapOutputUsd;
|
145
145
|
return (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState?.liqThresholdBps ?? 0);
|
146
146
|
}
|
147
|
-
function insufficientLiquidity(
|
148
|
-
return
|
147
|
+
function insufficientLiquidity(amountNeededUsd, liquidity, tokenDecimals, tokenPrice) {
|
148
|
+
return amountNeededUsd > (0, numberUtils_1.fromBaseUnit)(liquidity, tokenDecimals) * tokenPrice;
|
149
149
|
}
|
150
150
|
async function getFlashLoanRequirements(client, values, attemptNum) {
|
151
151
|
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) +
|
package/package.json
CHANGED
@@ -181,18 +181,21 @@ export async function getJupPriceData(mints: PublicKey[], extraInfo?: boolean) {
|
|
181
181
|
)
|
182
182
|
).json();
|
183
183
|
const result = res.data;
|
184
|
-
if (
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
(
|
184
|
+
if (!result || result === null || typeof result !== "object") {
|
185
|
+
throw new Error("Failed to get token prices using Jupiter");
|
186
|
+
}
|
187
|
+
|
188
|
+
const invalidValues =
|
189
|
+
Boolean(Object.values(result).filter((x) => x === null).length) ||
|
190
|
+
Boolean(
|
190
191
|
Object.values(result)
|
191
192
|
.map((x) => parseFloat((x as any).price))
|
192
|
-
.
|
193
|
-
|
194
|
-
|
193
|
+
.filter((x) => x <= 0).length
|
194
|
+
);
|
195
|
+
if (invalidValues) {
|
196
|
+
throw new Error("Invalid price values");
|
195
197
|
}
|
198
|
+
|
196
199
|
return result;
|
197
200
|
}, 8);
|
198
201
|
|
package/src/utils/priceUtils.ts
CHANGED
@@ -115,7 +115,7 @@ export async function getSwitchboardPrices(
|
|
115
115
|
);
|
116
116
|
|
117
117
|
const p = res.flatMap((x) => x.results[0]);
|
118
|
-
if (p.filter((x) => !x || isNaN(Number(x))).length > 0) {
|
118
|
+
if (p.filter((x) => !x || isNaN(Number(x)) || Number(x) < 0).length > 0) {
|
119
119
|
throw new Error("Unable to fetch Switchboard prices");
|
120
120
|
}
|
121
121
|
|
@@ -302,12 +302,12 @@ function postRebalanceLiqUtilizationRateBps(
|
|
302
302
|
}
|
303
303
|
|
304
304
|
function insufficientLiquidity(
|
305
|
-
|
305
|
+
amountNeededUsd: number,
|
306
306
|
liquidity: bigint,
|
307
307
|
tokenDecimals: number,
|
308
308
|
tokenPrice: number
|
309
309
|
) {
|
310
|
-
return
|
310
|
+
return amountNeededUsd > fromBaseUnit(liquidity, tokenDecimals) * tokenPrice;
|
311
311
|
}
|
312
312
|
|
313
313
|
export interface FlashLoanRequirements {
|
@@ -42,7 +42,6 @@ import {
|
|
42
42
|
} from "../../src/utils";
|
43
43
|
import { PriorityFeeSetting } from "../../src/types";
|
44
44
|
import { buildIronforgeApiUrl, fromBaseUnit, tokenInfo, USD_DECIMALS } from "../../dist";
|
45
|
-
import { JUPITER_PROGRAM_ID } from "../../src/jupiter-sdk";
|
46
45
|
|
47
46
|
describe("Solauto Marginfi tests", async () => {
|
48
47
|
// const signer = setupTest();
|
@@ -50,7 +49,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
50
49
|
|
51
50
|
const payForTransactions = true;
|
52
51
|
const testProgram = false;
|
53
|
-
const positionId =
|
52
|
+
const positionId = 3;
|
54
53
|
|
55
54
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
56
55
|
const client = new SolautoMarginfiClient(
|
@@ -66,7 +65,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
66
65
|
await client.initialize({
|
67
66
|
signer,
|
68
67
|
positionId,
|
69
|
-
authority: new PublicKey("
|
68
|
+
authority: new PublicKey("FKYQs7KgRvaKQHxXwb8HKfoBcFdSxLL3JvHWpPdVQ16v"),
|
70
69
|
// new: true,
|
71
70
|
// marginfiAccount: new PublicKey(
|
72
71
|
// ""
|