@haven-fi/solauto-sdk 1.0.53 → 1.0.54
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK3E,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA+C1E;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC;AAEjE,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACtC,OAAO,GAAE,MAAU,EACnB,KAAK,GAAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB9E,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,GAC7B,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,MAAM,GACzB,yBAAyB,CAgB3B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,OAAO,GACf;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAYA;AAED,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,yBAAyB,EAC3C,WAAW,EAAE,WAAW,GACvB,eAAe,GAAG,SAAS,
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.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.getReferralsByUser = getReferralsByUser;
|
14
14
|
exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
15
15
|
exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
16
17
|
const umi_1 = require("@metaplex-foundation/umi");
|
17
18
|
const generated_1 = require("../../generated");
|
18
19
|
const generalUtils_1 = require("../generalUtils");
|
@@ -68,7 +69,7 @@ function getSolautoFeesBps(isReferred, feeType) {
|
|
68
69
|
function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
69
70
|
if (positionDca.automation.targetPeriods > 0 &&
|
70
71
|
eligibleForNextAutomationPeriod(positionDca.automation)) {
|
71
|
-
return
|
72
|
+
return "dca";
|
72
73
|
}
|
73
74
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
74
75
|
return undefined;
|
@@ -80,10 +81,10 @@ function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
|
80
81
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
81
82
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
82
83
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
83
|
-
return
|
84
|
+
return "boost";
|
84
85
|
}
|
85
86
|
else if (positionState.liqUtilizationRateBps >= repayFrom) {
|
86
|
-
return
|
87
|
+
return "repay";
|
87
88
|
}
|
88
89
|
return undefined;
|
89
90
|
}
|
@@ -194,7 +195,10 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
194
195
|
positionId: x.positionId,
|
195
196
|
lendingPlatform: x.lendingPlatform,
|
196
197
|
})));
|
197
|
-
|
198
|
+
let marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
|
199
|
+
marginfiPositions = marginfiPositions.filter((x) => x.supplyMint &&
|
200
|
+
(x.debtMint.equals(web3_js_1.PublicKey.default) ||
|
201
|
+
constants_1.ALL_SUPPORTED_TOKENS.includes(x.debtMint.toString())));
|
198
202
|
allPositions.push(...marginfiPositions.map((x) => ({
|
199
203
|
publicKey: x.marginfiAccount,
|
200
204
|
authority: user,
|
package/package.json
CHANGED
@@ -3,7 +3,6 @@ import { MaybeRpcAccount, publicKey, Umi } from "@metaplex-foundation/umi";
|
|
3
3
|
import { PYTH_PRICE_FEED_IDS } from "../constants/pythConstants";
|
4
4
|
import { fromBaseUnit, toBaseUnit } from "./numberUtils";
|
5
5
|
import { PRICES } from "../constants/solautoConstants";
|
6
|
-
import { ResponseError } from "@jup-ag/api";
|
7
6
|
|
8
7
|
export function generateRandomU8(): number {
|
9
8
|
return Math.floor(Math.random() * 255 + 1);
|
@@ -22,7 +22,7 @@ import {
|
|
22
22
|
} from "../numberUtils";
|
23
23
|
import { getReferralState } from "../accountUtils";
|
24
24
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
25
|
-
import { USD_DECIMALS } from "../../constants";
|
25
|
+
import { ALL_SUPPORTED_TOKENS, USD_DECIMALS } from "../../constants";
|
26
26
|
import {
|
27
27
|
getAllMarginfiAccountsByAuthority,
|
28
28
|
getMarginfiAccountPositionState,
|
@@ -127,7 +127,7 @@ export function eligibleForRebalance(
|
|
127
127
|
positionDca.automation.targetPeriods > 0 &&
|
128
128
|
eligibleForNextAutomationPeriod(positionDca.automation)
|
129
129
|
) {
|
130
|
-
return
|
130
|
+
return "dca";
|
131
131
|
}
|
132
132
|
|
133
133
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
@@ -148,11 +148,9 @@ export function eligibleForRebalance(
|
|
148
148
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
149
149
|
|
150
150
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
151
|
-
return
|
152
|
-
} else if (
|
153
|
-
|
154
|
-
) {
|
155
|
-
return 'repay';
|
151
|
+
return "boost";
|
152
|
+
} else if (positionState.liqUtilizationRateBps >= repayFrom) {
|
153
|
+
return "repay";
|
156
154
|
}
|
157
155
|
|
158
156
|
return undefined;
|
@@ -293,11 +291,17 @@ export async function getAllPositionsByAuthority(
|
|
293
291
|
}))
|
294
292
|
);
|
295
293
|
|
296
|
-
|
294
|
+
let marginfiPositions = await getAllMarginfiAccountsByAuthority(
|
297
295
|
umi,
|
298
296
|
user,
|
299
297
|
true
|
300
298
|
);
|
299
|
+
marginfiPositions = marginfiPositions.filter(
|
300
|
+
(x) =>
|
301
|
+
x.supplyMint &&
|
302
|
+
(x.debtMint!.equals(PublicKey.default) ||
|
303
|
+
ALL_SUPPORTED_TOKENS.includes(x.debtMint!.toString()))
|
304
|
+
);
|
301
305
|
allPositions.push(
|
302
306
|
...marginfiPositions.map((x) => ({
|
303
307
|
publicKey: x.marginfiAccount,
|
@@ -327,7 +331,7 @@ export async function positionStateWithLatestPrices(
|
|
327
331
|
umi,
|
328
332
|
protocolAccount,
|
329
333
|
toWeb3JsPublicKey(state.supply.mint),
|
330
|
-
toWeb3JsPublicKey(state.debt.mint)
|
334
|
+
toWeb3JsPublicKey(state.debt.mint)
|
331
335
|
);
|
332
336
|
} else {
|
333
337
|
throw new Error("Lending platorm not yet supported");
|