@haven-fi/solauto-sdk 1.0.708 → 1.0.710
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/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +14 -18
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceValues.js +0 -2
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +2 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +6 -6
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +2 -4
- package/dist/utils/stringUtils.d.ts +4 -0
- package/dist/utils/stringUtils.d.ts.map +1 -1
- package/dist/utils/stringUtils.js +8 -3
- package/dist/utils/switchboardUtils.js +1 -1
- package/local/logPositions.ts +1 -1
- package/local/txSandbox.ts +6 -46
- package/package.json +1 -1
- package/src/services/rebalance/rebalanceSwapManager.ts +13 -34
- package/src/services/rebalance/rebalanceValues.ts +0 -2
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +6 -6
- package/src/utils/priceUtils.ts +7 -7
- package/src/utils/stringUtils.ts +8 -3
- package/src/utils/switchboardUtils.ts +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceSwapManager.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceSwapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAkB,UAAU,EAAa,MAAM,SAAS,CAAC;AAChE,OAAO,EAA0B,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAA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,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,aAAa,CAAU;gBAGrB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,cAAc,CAAC,EAAE,qBAAqB,YAAA,EACtC,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,SAAS,CAAC,EAAE,SAAS,YAAA;IAU/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAsCnB,OAAO,CAAC,kCAAkC;YAwE5B,mBAAmB;IAyCjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAyEhC,aAAa;;;;;;CAWpB"}
|
@@ -36,10 +36,6 @@ class RebalanceSwapManager {
|
|
36
36
|
const debtPrice = this.client.pos.debtPrice(this.priceType);
|
37
37
|
const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
38
38
|
const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
39
|
-
// const biasedInputPrice = inputPrice;
|
40
|
-
// const biasedOutputPrice = outputPrice;
|
41
|
-
// const priceDiff = (biasedInputPrice - inputPrice) / 2;
|
42
|
-
// const weightedInputPrice = inputPrice + priceDiff;
|
43
39
|
let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / biasedInputPrice, input.decimals);
|
44
40
|
return {
|
45
41
|
inputAmount,
|
@@ -55,7 +51,7 @@ class RebalanceSwapManager {
|
|
55
51
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
56
52
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
57
53
|
// TODO: add token balance change
|
58
|
-
const { input,
|
54
|
+
const { input, biasedInputPrice, output, biasedOutputPrice, } = this.swapDetails();
|
59
55
|
const swapInputAmount = swapInputAmountBaseUnit
|
60
56
|
? (0, utils_1.fromBaseUnit)(swapInputAmountBaseUnit, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint)).decimals)
|
61
57
|
: undefined;
|
@@ -68,12 +64,6 @@ class RebalanceSwapManager {
|
|
68
64
|
const swapOutputUsd = swapOutputAmount
|
69
65
|
? swapOutputAmount * biasedOutputPrice
|
70
66
|
: this.usdToSwap();
|
71
|
-
console.log((swapInputAmount ?? 0) * inputPrice, swapInputUsd, (swapOutputAmount ?? 0) * outputPrice, swapOutputUsd);
|
72
|
-
console.log({
|
73
|
-
isBoost: this.isBoost(),
|
74
|
-
debtAdjustmentUsd: this.isBoost() ? swapInputUsd : swapInputUsd * -1,
|
75
|
-
debtAdjustmentUsdOutput: this.isBoost() ? swapOutputUsd : swapOutputUsd * -1,
|
76
|
-
});
|
77
67
|
const res = (0, rebalanceValues_1.applyDebtAdjustmentUsd)({
|
78
68
|
debtAdjustmentUsd: this.isBoost() ? swapInputUsd : swapInputUsd * -1,
|
79
69
|
debtAdjustmentUsdOutput: this.isBoost() ? swapOutputUsd : swapOutputUsd * -1,
|
@@ -82,12 +72,19 @@ class RebalanceSwapManager {
|
|
82
72
|
flashLoan: this.flRequirements?.flFeeBps ?? 0,
|
83
73
|
lpBorrow: this.client.pos.state.debt.borrowFeeBps,
|
84
74
|
});
|
85
|
-
if (
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
75
|
+
// if (isMarginfiPosition(this.client.pos)) {
|
76
|
+
// console.log(res.newPos.supplyUsd, res.newPos.debtUsd);
|
77
|
+
// console.log(
|
78
|
+
// res.newPos.supplyUsd *
|
79
|
+
// bytesToI80F48(
|
80
|
+
// this.client.pos.supplyBank!.config.assetWeightInit.value
|
81
|
+
// ),
|
82
|
+
// res.newPos.debtUsd *
|
83
|
+
// bytesToI80F48(
|
84
|
+
// this.client.pos.debtBank!.config.liabilityWeightInit.value
|
85
|
+
// )
|
86
|
+
// );
|
87
|
+
// }
|
91
88
|
return (0, utils_1.getLiqUtilzationRateBps)(res.newPos.supplyUsd, res.newPos.debtUsd, this.client.pos.state.liqThresholdBps ?? 0);
|
92
89
|
}
|
93
90
|
async findSufficientQuote(swapInput, criteria) {
|
@@ -106,7 +103,6 @@ class RebalanceSwapManager {
|
|
106
103
|
if (insufficient) {
|
107
104
|
(0, utils_1.consoleLog)("Insufficient swap quote:", swapQuote);
|
108
105
|
const increment = 0.01 + i * 0.01;
|
109
|
-
console.log(increment);
|
110
106
|
swapInput.amount = this.bigIntWithIncrement(swapInput.amount, this.isBoost() ? increment * -1 : increment);
|
111
107
|
}
|
112
108
|
else {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceValues.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,cAAc,CAAC;IAC1B,iCAAiC,EAAE,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,yBAAyB;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,iCAAiC,EAAE,MAAM,CAAC;CAC3C;AAED,wBAAgB,sBAAsB,CACpC,UAAU,EAAE;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,uBAAuB,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3E,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,gBAAgB,GACtB,yBAAyB,CAmC3B;AAED,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,cAAc,EACnB,2BAA2B,EAAE,MAAM,EACnC,IAAI,CAAC,EAAE,gBAAgB,GACtB,cAAc,
|
1
|
+
{"version":3,"file":"rebalanceValues.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,cAAc,CAAC;IAC1B,iCAAiC,EAAE,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,yBAAyB;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,iCAAiC,EAAE,MAAM,CAAC;CAC3C;AAED,wBAAgB,sBAAsB,CACpC,UAAU,EAAE;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,uBAAuB,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3E,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,gBAAgB,GACtB,yBAAyB,CAmC3B;AAED,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,cAAc,EACnB,2BAA2B,EAAE,MAAM,EACnC,IAAI,CAAC,EAAE,gBAAgB,GACtB,cAAc,CAgChB;AA4ED,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACrD,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,iBAAiB,EAClC,SAAS,EAAE,SAAS,EACpB,2BAA2B,CAAC,EAAE,MAAM,EACpC,aAAa,CAAC,EAAE,cAAc,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,eAAe,GAAG,SAAS,CA8C7B"}
|
@@ -45,7 +45,6 @@ function getDebtAdjustment(liqThresholdBps, pos, targetLiqUtilizationRateBps, fe
|
|
45
45
|
: (targetUtilizationRate * liqThreshold * pos.supplyUsd - pos.debtUsd) /
|
46
46
|
(actualizedFee - targetUtilizationRate * liqThreshold * (1.0 + flFee));
|
47
47
|
const endResult = applyDebtAdjustmentUsd({ debtAdjustmentUsd }, pos, liqThreshold, fees);
|
48
|
-
console.log(debtAdjustmentUsd, pos, endResult.newPos);
|
49
48
|
return {
|
50
49
|
debtAdjustmentUsd,
|
51
50
|
endResult: endResult.newPos,
|
@@ -60,7 +59,6 @@ function getTargetLiqUtilizationRateBps(solautoPosition, priceType, targetLiqUti
|
|
60
59
|
if (targetLiqUtilizationRateBps !== undefined) {
|
61
60
|
return targetLiqUtilizationRateBps;
|
62
61
|
}
|
63
|
-
console.log(solautoPosition.liqUtilizationRateBps(generated_1.PriceType.Realtime), solautoPosition.repayFromBps);
|
64
62
|
if (solautoPosition.liqUtilizationRateBps(generated_1.PriceType.Realtime) >=
|
65
63
|
solautoPosition.repayFromBps) {
|
66
64
|
return solautoPosition.settings.repayToBps;
|
@@ -7,6 +7,8 @@ export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
7
7
|
maxLtvPriceType: PriceType;
|
8
8
|
supplyBank: Bank | null;
|
9
9
|
debtBank: Bank | null;
|
10
|
+
supplyPrice(priceType?: PriceType): number | undefined;
|
11
|
+
debtPrice(priceType?: PriceType): number | undefined;
|
10
12
|
private getBankAccounts;
|
11
13
|
getBanks(): Promise<Bank[]>;
|
12
14
|
priceOracles(): Promise<PublicKey[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEzB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAC/B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAQ;
|
1
|
+
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEzB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAC/B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAQ;IAEpC,WAAW,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAItD,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD,OAAO,CAAC,eAAe;IAMjB,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAW3B,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASpC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAa3D,OAAO,CAAC,6BAA6B;IAwBrC,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,eAAe,cAElB;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BjE"}
|
@@ -16,12 +16,12 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
16
16
|
this.supplyBank = null;
|
17
17
|
this.debtBank = null;
|
18
18
|
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
supplyPrice(priceType) {
|
20
|
+
return this._supplyPrice ?? (0, utils_1.safeGetPrice)(this.supplyMint, priceType, marginfi_sdk_1.PriceBias.Low);
|
21
|
+
}
|
22
|
+
debtPrice(priceType) {
|
23
|
+
return this._debtPrice ?? (0, utils_1.safeGetPrice)(this.debtMint, priceType, marginfi_sdk_1.PriceBias.High);
|
24
|
+
}
|
25
25
|
getBankAccounts(mint) {
|
26
26
|
const group = this.lpPoolAccount.toString();
|
27
27
|
const bankAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv).bankAccounts;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAA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AAC,CAAC,CAqDtC;AAkBD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAkDtC;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAiBtC;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,EACnD,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,MAAM,GAAG,SAAS,CAyBpB"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -121,8 +121,8 @@ async function getSwitchboardPrices(mints) {
|
|
121
121
|
prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
122
122
|
const resp = await crossbar.simulateFeeds(mints.map((x) => constants_1.SWITCHBOARD_PRICE_FEED_IDS[x.toString()].feedHash));
|
123
123
|
const data = resp.flatMap((x) => x.results[0]);
|
124
|
-
if (data.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0)
|
125
|
-
|
124
|
+
if (data.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0).length >
|
125
|
+
0) {
|
126
126
|
throw new Error("Unable to fetch Switchboard prices");
|
127
127
|
}
|
128
128
|
const finalMap = {};
|
@@ -132,8 +132,6 @@ async function getSwitchboardPrices(mints) {
|
|
132
132
|
const price = Number(item.results[0]);
|
133
133
|
finalMap[k] = {
|
134
134
|
realtimePrice: price,
|
135
|
-
confInterval: price, // TODO: do we need to change if marginfi fixes their stuff?
|
136
|
-
emaConfInterval: price,
|
137
135
|
};
|
138
136
|
}
|
139
137
|
}
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
export declare const StrategyTypes: readonly ["Long", "Short", "Ratio"];
|
3
3
|
export type StrategyType = (typeof StrategyTypes)[number];
|
4
|
+
export declare function ratioMintDetails(supplyMint?: PublicKey, debtMint?: PublicKey): {
|
5
|
+
order: (PublicKey | undefined)[];
|
6
|
+
strategyName: string;
|
7
|
+
};
|
4
8
|
export declare function ratioName(supplyMint?: PublicKey, debtMint?: PublicKey): string;
|
5
9
|
export declare function solautoStrategyName(supplyMint?: PublicKey, debtMint?: PublicKey): string;
|
6
10
|
export declare function strategyType(supplyMint: PublicKey, debtMint: PublicKey): StrategyType;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../src/utils/stringUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5C,eAAO,MAAM,aAAa,qCAAsC,CAAC;AACjE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAc1D,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,SAAS,
|
1
|
+
{"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../src/utils/stringUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5C,eAAO,MAAM,aAAa,qCAAsC,CAAC;AACjE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAc1D,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,SAAS;;;EAY5E;AAED,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,SAAS,UAGrE;AAED,wBAAgB,mBAAmB,CACjC,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,UAcrB;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,GAClB,YAAY,CAWd"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.StrategyTypes = void 0;
|
4
|
+
exports.ratioMintDetails = ratioMintDetails;
|
4
5
|
exports.ratioName = ratioName;
|
5
6
|
exports.solautoStrategyName = solautoStrategyName;
|
6
7
|
exports.strategyType = strategyType;
|
@@ -21,18 +22,22 @@ function adjustedTicker(mint) {
|
|
21
22
|
return info.ticker;
|
22
23
|
}
|
23
24
|
}
|
24
|
-
function
|
25
|
+
function ratioMintDetails(supplyMint, debtMint) {
|
25
26
|
if (((0, generalUtils_1.tokenInfo)(supplyMint).isLST && debtMint?.equals(spl_token_1.NATIVE_MINT)) ||
|
26
27
|
(supplyMint &&
|
27
28
|
debtMint &&
|
28
29
|
constants_1.MAJORS_PRIO[supplyMint?.toString() ?? ""] >
|
29
30
|
constants_1.MAJORS_PRIO[debtMint?.toString() ?? ""])) {
|
30
|
-
return
|
31
|
+
return { order: [supplyMint, debtMint], strategyName: "Long" };
|
31
32
|
}
|
32
33
|
else {
|
33
|
-
return
|
34
|
+
return { order: [debtMint, supplyMint], strategyName: "Short" };
|
34
35
|
}
|
35
36
|
}
|
37
|
+
function ratioName(supplyMint, debtMint) {
|
38
|
+
const { order, strategyName } = ratioMintDetails(supplyMint, debtMint);
|
39
|
+
return `${adjustedTicker(order[0])}/${adjustedTicker(order[1])} ${strategyName}`;
|
40
|
+
}
|
36
41
|
function solautoStrategyName(supplyMint, debtMint) {
|
37
42
|
const strat = strategyType(supplyMint ?? web3_js_1.PublicKey.default, debtMint ?? web3_js_1.PublicKey.default);
|
38
43
|
if (strat === "Long") {
|
@@ -68,7 +68,7 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
|
68
68
|
const price = responses[0].value.toNumber();
|
69
69
|
constants_1.PRICES[mint.toString()] = {
|
70
70
|
realtimePrice: price,
|
71
|
-
confInterval:
|
71
|
+
confInterval: 0,
|
72
72
|
emaPrice: price,
|
73
73
|
emaConfInterval: 0,
|
74
74
|
time: (0, generalUtils_1.currentUnixSeconds)(),
|
package/local/logPositions.ts
CHANGED
@@ -120,7 +120,7 @@ async function main(filterWhitelist: boolean, programEnv: ProgramEnv = "Prod") {
|
|
120
120
|
const repayFrom = pos.settings!.repayToBps + pos.settings!.repayGap;
|
121
121
|
const unhealthy = actionToTake === "repay";
|
122
122
|
const healthText = unhealthy
|
123
|
-
? `(Unhealthy: ${pos.
|
123
|
+
? `(Unhealthy: ${pos.liqUtilizationRateBps() - repayFrom}bps)`
|
124
124
|
: "";
|
125
125
|
if (unhealthy) {
|
126
126
|
unhealthyPositions += 1;
|
package/local/txSandbox.ts
CHANGED
@@ -3,35 +3,27 @@ import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
5
|
ClientTransactionsManager,
|
6
|
-
closeSolautoPosition,
|
7
6
|
consoleLog,
|
8
|
-
deposit,
|
9
7
|
getBatches,
|
10
8
|
getClient,
|
11
|
-
getMaxLiqUtilizationRateBps,
|
12
9
|
getPositionExBulk,
|
13
10
|
getSolanaRpcConnection,
|
14
11
|
getSolautoManagedPositions,
|
15
12
|
LendingPlatform,
|
16
13
|
LOCAL_IRONFORGE_API_URL,
|
17
|
-
openSolautoPosition,
|
18
14
|
PriceType,
|
19
15
|
PriorityFeeSetting,
|
20
16
|
ProgramEnv,
|
21
17
|
rebalance,
|
22
|
-
RETARDIO,
|
23
18
|
SOLAUTO_PROD_PROGRAM,
|
24
19
|
SOLAUTO_TEST_PROGRAM,
|
25
20
|
SolautoClient,
|
26
|
-
toBaseUnit,
|
27
21
|
TransactionItem,
|
28
|
-
USDC,
|
29
|
-
withdraw,
|
30
22
|
} from "../src";
|
31
23
|
import { getSecretKey } from "./shared";
|
32
24
|
|
33
25
|
const payForTransaction = false;
|
34
|
-
const testProgram =
|
26
|
+
const testProgram = false;
|
35
27
|
const lpEnv: ProgramEnv = "Prod";
|
36
28
|
|
37
29
|
let [, umi] = getSolanaRpcConnection(
|
@@ -42,7 +34,7 @@ let [, umi] = getSolanaRpcConnection(
|
|
42
34
|
|
43
35
|
const signer = createSignerFromKeypair(
|
44
36
|
umi,
|
45
|
-
fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey()))
|
37
|
+
fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey("solauto-manager")))
|
46
38
|
);
|
47
39
|
|
48
40
|
export async function main() {
|
@@ -55,52 +47,20 @@ export async function main() {
|
|
55
47
|
});
|
56
48
|
|
57
49
|
await client.initializeExistingSolautoPosition({
|
58
|
-
positionId:
|
59
|
-
|
50
|
+
positionId: 2,
|
51
|
+
authority: new PublicKey("EBhRj7jbF2EVE21i19JSuCX1BAbnZFYhoKW64HnaZ3kf"),
|
60
52
|
// lpUserAccount: new PublicKey(
|
61
53
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
62
54
|
// ),
|
63
|
-
// lpPoolAccount: new PublicKey(
|
64
|
-
// "EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"
|
65
|
-
// ),
|
66
|
-
// supplyMint: new PublicKey(USDC),
|
67
|
-
// debtMint: new PublicKey(RETARDIO),
|
68
55
|
});
|
69
56
|
|
70
|
-
|
71
|
-
|
72
|
-
// const transactionItems = [
|
73
|
-
// openSolautoPosition(client, {
|
74
|
-
// boostGap: 100,
|
75
|
-
// boostToBps: client.pos.maxBoostToBps,
|
76
|
-
// repayGap: 100,
|
77
|
-
// repayToBps: client.pos.maxRepayToBps,
|
78
|
-
// }),
|
79
|
-
// ];
|
80
|
-
const transactionItems = [
|
81
|
-
// openSolautoPosition(client, {
|
82
|
-
// boostGap: 100,
|
83
|
-
// boostToBps: client.pos.maxBoostToBps,
|
84
|
-
// repayGap: 100,
|
85
|
-
// repayToBps: client.pos.maxRepayToBps,
|
86
|
-
// }),
|
87
|
-
// deposit(client, toBaseUnit(5, client.pos.supplyMintInfo.decimals)),
|
88
|
-
rebalance(client),
|
89
|
-
// withdraw(client, "All"),
|
90
|
-
// closeSolautoPosition(client)
|
91
|
-
// new TransactionItem(
|
92
|
-
// async () => ({ tx: client.refreshIx() }),
|
93
|
-
// `refresh`,
|
94
|
-
// true
|
95
|
-
// ),
|
96
|
-
];
|
57
|
+
const transactionItems = [rebalance(client)];
|
97
58
|
|
98
59
|
const txManager = new ClientTransactionsManager({
|
99
60
|
txHandler: client,
|
100
61
|
txRunType: payForTransaction ? "normal" : "only-simulate",
|
101
62
|
priorityFeeSetting: PriorityFeeSetting.Default,
|
102
|
-
retryConfig: { totalRetries:
|
103
|
-
// atomically: false,
|
63
|
+
retryConfig: { totalRetries: 2 },
|
104
64
|
});
|
105
65
|
const statuses = await txManager.send(transactionItems);
|
106
66
|
consoleLog(statuses);
|
package/package.json
CHANGED
@@ -71,12 +71,6 @@ export class RebalanceSwapManager {
|
|
71
71
|
const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
72
72
|
const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
73
73
|
|
74
|
-
// const biasedInputPrice = inputPrice;
|
75
|
-
// const biasedOutputPrice = outputPrice;
|
76
|
-
|
77
|
-
// const priceDiff = (biasedInputPrice - inputPrice) / 2;
|
78
|
-
// const weightedInputPrice = inputPrice + priceDiff;
|
79
|
-
|
80
74
|
let inputAmount = toBaseUnit(
|
81
75
|
this.usdToSwap() / biasedInputPrice!,
|
82
76
|
input.decimals
|
@@ -103,10 +97,8 @@ export class RebalanceSwapManager {
|
|
103
97
|
|
104
98
|
const {
|
105
99
|
input,
|
106
|
-
inputPrice,
|
107
100
|
biasedInputPrice,
|
108
101
|
output,
|
109
|
-
outputPrice,
|
110
102
|
biasedOutputPrice,
|
111
103
|
} = this.swapDetails();
|
112
104
|
|
@@ -132,18 +124,6 @@ export class RebalanceSwapManager {
|
|
132
124
|
? swapOutputAmount * biasedOutputPrice
|
133
125
|
: this.usdToSwap();
|
134
126
|
|
135
|
-
console.log(
|
136
|
-
(swapInputAmount ?? 0) * inputPrice,
|
137
|
-
swapInputUsd,
|
138
|
-
(swapOutputAmount ?? 0) * outputPrice,
|
139
|
-
swapOutputUsd
|
140
|
-
);
|
141
|
-
|
142
|
-
console.log({
|
143
|
-
isBoost: this.isBoost(),
|
144
|
-
debtAdjustmentUsd: this.isBoost() ? swapInputUsd : swapInputUsd * -1,
|
145
|
-
debtAdjustmentUsdOutput: this.isBoost() ? swapOutputUsd : swapOutputUsd * -1,
|
146
|
-
})
|
147
127
|
const res = applyDebtAdjustmentUsd(
|
148
128
|
{
|
149
129
|
debtAdjustmentUsd: this.isBoost() ? swapInputUsd : swapInputUsd * -1,
|
@@ -158,19 +138,19 @@ export class RebalanceSwapManager {
|
|
158
138
|
}
|
159
139
|
);
|
160
140
|
|
161
|
-
if (isMarginfiPosition(this.client.pos)) {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
}
|
141
|
+
// if (isMarginfiPosition(this.client.pos)) {
|
142
|
+
// console.log(res.newPos.supplyUsd, res.newPos.debtUsd);
|
143
|
+
// console.log(
|
144
|
+
// res.newPos.supplyUsd *
|
145
|
+
// bytesToI80F48(
|
146
|
+
// this.client.pos.supplyBank!.config.assetWeightInit.value
|
147
|
+
// ),
|
148
|
+
// res.newPos.debtUsd *
|
149
|
+
// bytesToI80F48(
|
150
|
+
// this.client.pos.debtBank!.config.liabilityWeightInit.value
|
151
|
+
// )
|
152
|
+
// );
|
153
|
+
// }
|
174
154
|
|
175
155
|
return getLiqUtilzationRateBps(
|
176
156
|
res.newPos.supplyUsd,
|
@@ -208,7 +188,6 @@ export class RebalanceSwapManager {
|
|
208
188
|
consoleLog("Insufficient swap quote:", swapQuote);
|
209
189
|
|
210
190
|
const increment = 0.01 + i * 0.01;
|
211
|
-
console.log(increment);
|
212
191
|
swapInput.amount = this.bigIntWithIncrement(
|
213
192
|
swapInput.amount,
|
214
193
|
this.isBoost() ? increment * -1 : increment
|
@@ -110,7 +110,6 @@ export function getDebtAdjustment(
|
|
110
110
|
liqThreshold,
|
111
111
|
fees
|
112
112
|
);
|
113
|
-
console.log(debtAdjustmentUsd, pos, endResult.newPos);
|
114
113
|
|
115
114
|
return {
|
116
115
|
debtAdjustmentUsd,
|
@@ -134,7 +133,6 @@ function getTargetLiqUtilizationRateBps(
|
|
134
133
|
return targetLiqUtilizationRateBps;
|
135
134
|
}
|
136
135
|
|
137
|
-
console.log(solautoPosition.liqUtilizationRateBps(PriceType.Realtime), solautoPosition.repayFromBps);
|
138
136
|
if (
|
139
137
|
solautoPosition.liqUtilizationRateBps(PriceType.Realtime) >=
|
140
138
|
solautoPosition.repayFromBps
|
@@ -24,13 +24,13 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
24
24
|
public supplyBank: Bank | null = null;
|
25
25
|
public debtBank: Bank | null = null;
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
supplyPrice(priceType?: PriceType): number | undefined {
|
28
|
+
return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType, PriceBias.Low);
|
29
|
+
}
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
debtPrice(priceType?: PriceType): number | undefined {
|
32
|
+
return this._debtPrice ?? safeGetPrice(this.debtMint, priceType, PriceBias.High);
|
33
|
+
}
|
34
34
|
|
35
35
|
private getBankAccounts(mint: PublicKey) {
|
36
36
|
const group = this.lpPoolAccount.toString();
|
package/src/utils/priceUtils.ts
CHANGED
@@ -42,9 +42,11 @@ export async function fetchTokenPrices(
|
|
42
42
|
const newMints = mintStrs
|
43
43
|
.filter((x) => !Object.keys(cachedPrices).includes(x))
|
44
44
|
.map((x) => new PublicKey(x));
|
45
|
-
const pythMints = newMints.filter((x) =>
|
46
|
-
|
47
|
-
|
45
|
+
const pythMints = newMints.filter((x) =>
|
46
|
+
Object.keys(PYTH_PRICE_FEED_IDS).includes(x.toString())
|
47
|
+
);
|
48
|
+
const switchboardMints = newMints.filter((x) =>
|
49
|
+
Object.keys(SWITCHBOARD_PRICE_FEED_IDS).includes(x.toString())
|
48
50
|
);
|
49
51
|
const otherMints = newMints.filter(
|
50
52
|
(x) => !pythMints.includes(x) && !switchboardMints.includes(x)
|
@@ -166,8 +168,8 @@ export async function getSwitchboardPrices(
|
|
166
168
|
|
167
169
|
const data = resp.flatMap((x) => x.results[0]);
|
168
170
|
if (
|
169
|
-
data.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0)
|
170
|
-
|
171
|
+
data.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0).length >
|
172
|
+
0
|
171
173
|
) {
|
172
174
|
throw new Error("Unable to fetch Switchboard prices");
|
173
175
|
}
|
@@ -179,8 +181,6 @@ export async function getSwitchboardPrices(
|
|
179
181
|
const price = Number(item.results[0]);
|
180
182
|
finalMap[k] = {
|
181
183
|
realtimePrice: price,
|
182
|
-
confInterval: price, // TODO: do we need to change if marginfi fixes their stuff?
|
183
|
-
emaConfInterval: price,
|
184
184
|
};
|
185
185
|
}
|
186
186
|
}
|
package/src/utils/stringUtils.ts
CHANGED
@@ -18,7 +18,7 @@ function adjustedTicker(mint?: PublicKey) {
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
-
export function
|
21
|
+
export function ratioMintDetails(supplyMint?: PublicKey, debtMint?: PublicKey) {
|
22
22
|
if (
|
23
23
|
(tokenInfo(supplyMint).isLST && debtMint?.equals(NATIVE_MINT)) ||
|
24
24
|
(supplyMint &&
|
@@ -26,12 +26,17 @@ export function ratioName(supplyMint?: PublicKey, debtMint?: PublicKey) {
|
|
26
26
|
MAJORS_PRIO[supplyMint?.toString() ?? ""] >
|
27
27
|
MAJORS_PRIO[debtMint?.toString() ?? ""])
|
28
28
|
) {
|
29
|
-
return
|
29
|
+
return { order: [supplyMint, debtMint], strategyName: "Long" };
|
30
30
|
} else {
|
31
|
-
return
|
31
|
+
return { order: [debtMint, supplyMint], strategyName: "Short" };
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
|
+
export function ratioName(supplyMint?: PublicKey, debtMint?: PublicKey) {
|
36
|
+
const { order, strategyName } = ratioMintDetails(supplyMint, debtMint);
|
37
|
+
return `${adjustedTicker(order[0])}/${adjustedTicker(order[1])} ${strategyName}`;
|
38
|
+
}
|
39
|
+
|
35
40
|
export function solautoStrategyName(
|
36
41
|
supplyMint?: PublicKey,
|
37
42
|
debtMint?: PublicKey
|
@@ -74,7 +74,7 @@ export async function buildSwbSubmitResponseTx(
|
|
74
74
|
const price = (responses[0].value as Big).toNumber();
|
75
75
|
PRICES[mint.toString()] = {
|
76
76
|
realtimePrice: price,
|
77
|
-
confInterval:
|
77
|
+
confInterval: 0,
|
78
78
|
emaPrice: price,
|
79
79
|
emaConfInterval: 0,
|
80
80
|
time: currentUnixSeconds(),
|