@haven-fi/solauto-sdk 1.0.468 → 1.0.469
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 +5 -1
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +1 -2
- package/local/logPositions.ts +14 -6
- package/package.json +1 -1
- package/src/utils/jupiterUtils.ts +5 -1
- package/src/utils/priceUtils.ts +6 -8
@@ -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;AAOrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAiG7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;
|
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;AAOrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAiG7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA0B5E"}
|
@@ -85,7 +85,11 @@ async function getJupPriceData(mints, extraInfo) {
|
|
85
85
|
if (!result ||
|
86
86
|
result === null ||
|
87
87
|
(typeof result === "object" &&
|
88
|
-
Boolean(Object.values(result).filter((x) => x === null).length))
|
88
|
+
Boolean(Object.values(result).filter((x) => x === null).length)) ||
|
89
|
+
(typeof result === "object" &&
|
90
|
+
Object.values(result)
|
91
|
+
.map((x) => parseFloat(x.price))
|
92
|
+
.includes(0))) {
|
89
93
|
throw new Error("Failed to get token prices using Jupiter");
|
90
94
|
}
|
91
95
|
return result;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAcrE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,
|
1
|
+
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAcrE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAgDnB;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAQzD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -120,8 +120,7 @@ async function getJupTokenPrices(mints) {
|
|
120
120
|
return [];
|
121
121
|
}
|
122
122
|
const data = await (0, jupiterUtils_1.getJupPriceData)(mints);
|
123
|
-
|
124
|
-
return prices;
|
123
|
+
return Object.values(data).map((x) => parseFloat(x.price));
|
125
124
|
}
|
126
125
|
function safeGetPrice(mint) {
|
127
126
|
if (mint && mint?.toString() in solautoConstants_1.PRICES) {
|
package/local/logPositions.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { publicKey } from "@metaplex-foundation/umi";
|
2
2
|
import {
|
3
3
|
buildHeliusApiUrl,
|
4
|
+
currentUnixSeconds,
|
5
|
+
eligibleForRebalance,
|
4
6
|
fetchTokenPrices,
|
5
7
|
fromBaseUnit,
|
6
8
|
getSolanaRpcConnection,
|
@@ -203,10 +205,20 @@ async function main(filterWhitelist: boolean) {
|
|
203
205
|
toWeb3JsPublicKey(pos.state.debt.mint)
|
204
206
|
);
|
205
207
|
|
208
|
+
const actionToTake = eligibleForRebalance(
|
209
|
+
pos.state,
|
210
|
+
pos.position.settingParams,
|
211
|
+
pos.position.dca,
|
212
|
+
currentUnixSeconds(),
|
213
|
+
safeGetPrice(pos.state.supply.mint)!,
|
214
|
+
safeGetPrice(pos.state.debt.mint)!,
|
215
|
+
0
|
216
|
+
);
|
217
|
+
|
206
218
|
const repayFrom =
|
207
219
|
pos.position.settingParams.repayToBps +
|
208
220
|
pos.position.settingParams.repayGap;
|
209
|
-
const unhealthy =
|
221
|
+
const unhealthy = actionToTake === "repay";
|
210
222
|
const healthText = unhealthy
|
211
223
|
? `(Unhealthy: ${latestState.liqUtilizationRateBps - repayFrom}bps)`
|
212
224
|
: "";
|
@@ -214,10 +226,7 @@ async function main(filterWhitelist: boolean) {
|
|
214
226
|
unhealthyPositions += 1;
|
215
227
|
}
|
216
228
|
|
217
|
-
const awaitingBoost =
|
218
|
-
latestState.liqUtilizationRateBps <
|
219
|
-
pos.position.settingParams.boostToBps -
|
220
|
-
pos.position.settingParams.boostGap;
|
229
|
+
const awaitingBoost = actionToTake === "boost";
|
221
230
|
const boostText = awaitingBoost ? " (awaiting boost)" : "";
|
222
231
|
if (awaitingBoost) {
|
223
232
|
awaitingBoostPositions += 1;
|
@@ -230,7 +239,6 @@ async function main(filterWhitelist: boolean) {
|
|
230
239
|
console.log(
|
231
240
|
`${strategy}: $${formatNumber(fromBaseUnit(latestState.netWorth.baseAmountUsdValue, USD_DECIMALS), 2, 10000, 2)} ${healthText} ${boostText}`
|
232
241
|
);
|
233
|
-
// console.log(latestState.liqUtilizationRateBps, repayFrom);
|
234
242
|
}
|
235
243
|
|
236
244
|
console.log(
|
package/package.json
CHANGED
@@ -168,7 +168,11 @@ export async function getJupPriceData(mints: PublicKey[], extraInfo?: boolean) {
|
|
168
168
|
!result ||
|
169
169
|
result === null ||
|
170
170
|
(typeof result === "object" &&
|
171
|
-
Boolean(Object.values(result).filter((x) => x === null).length))
|
171
|
+
Boolean(Object.values(result).filter((x) => x === null).length)) ||
|
172
|
+
(typeof result === "object" &&
|
173
|
+
Object.values(result)
|
174
|
+
.map((x) => parseFloat((x as any).price))
|
175
|
+
.includes(0))
|
172
176
|
) {
|
173
177
|
throw new Error("Failed to get token prices using Jupiter");
|
174
178
|
}
|
package/src/utils/priceUtils.ts
CHANGED
@@ -112,12 +112,12 @@ export async function getSwitchboardPrices(
|
|
112
112
|
"mainnet",
|
113
113
|
mints.map((x) => SWITCHBOARD_PRICE_FEED_IDS[x.toString()])
|
114
114
|
);
|
115
|
-
|
115
|
+
|
116
116
|
const p = res.flatMap((x) => x.results[0]);
|
117
117
|
if (p.filter((x) => !x || isNaN(Number(x))).length > 0) {
|
118
118
|
throw new Error("Unable to fetch Switchboard prices");
|
119
119
|
}
|
120
|
-
|
120
|
+
|
121
121
|
return p;
|
122
122
|
},
|
123
123
|
2,
|
@@ -131,7 +131,9 @@ export async function getSwitchboardPrices(
|
|
131
131
|
prices = Array(mints.length).fill(0);
|
132
132
|
}
|
133
133
|
|
134
|
-
const missingPrices = zip(mints, prices).filter(
|
134
|
+
const missingPrices = zip(mints, prices).filter(
|
135
|
+
(x) => !x[1] || isNaN(Number(x))
|
136
|
+
);
|
135
137
|
const jupPrices = zip(
|
136
138
|
missingPrices.map((x) => x[0]),
|
137
139
|
await getJupTokenPrices(missingPrices.map((x) => x[0]))
|
@@ -151,11 +153,7 @@ export async function getJupTokenPrices(mints: PublicKey[]) {
|
|
151
153
|
|
152
154
|
const data = await getJupPriceData(mints);
|
153
155
|
|
154
|
-
|
155
|
-
(x) => parseFloat(x.price as string) as number
|
156
|
-
);
|
157
|
-
|
158
|
-
return prices;
|
156
|
+
return Object.values(data).map((x) => parseFloat(x.price as string));
|
159
157
|
}
|
160
158
|
|
161
159
|
export function safeGetPrice(
|