@haven-fi/solauto-sdk 1.0.453 → 1.0.456
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/transactions/transactionUtils.d.ts +2 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +13 -2
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +10 -8
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +0 -2
- package/dist/utils/solauto/rebalanceUtils.d.ts +1 -0
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +3 -1
- package/local/logPositions.ts +29 -6
- package/package.json +1 -1
- package/src/transactions/transactionUtils.ts +21 -3
- package/src/transactions/transactionsManager.ts +12 -8
- package/src/utils/marginfiUtils.ts +0 -3
- package/src/utils/solauto/rebalanceUtils.ts +4 -1
- package/tests/transactions/solautoMarginfi.ts +57 -12
@@ -1,11 +1,12 @@
|
|
1
1
|
import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
3
3
|
import { SolautoClient } from "../clients/solautoClient";
|
4
|
+
import { RebalanceValues } from "../utils/solauto/rebalanceUtils";
|
4
5
|
import { ReferralStateManager } from "../clients";
|
5
6
|
import { TransactionItemInputs } from "../types";
|
6
7
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
7
8
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
8
|
-
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
|
9
|
+
export declare function requiresRefreshBeforeRebalance(client: SolautoClient, values: RebalanceValues): Promise<boolean>;
|
9
10
|
export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<TransactionItemInputs | undefined>;
|
10
11
|
export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
11
12
|
export declare function getErrorInfo(umi: Umi, txs: TransactionBuilder[], error: Error, simulationSuccessful?: boolean): {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAqBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAOzD,OAAO,EAIL,eAAe,EAChB,MAAM,iCAAiC,CAAC;AA2BzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA6LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAoH7B;AA2LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,oBAkElG;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAqI5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO;;;;EAiG/B"}
|
@@ -329,7 +329,17 @@ async function getTransactionChores(client, tx) {
|
|
329
329
|
choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.livePositionUpdates.cancellingDca));
|
330
330
|
return [choresBefore, choresAfter];
|
331
331
|
}
|
332
|
-
async function requiresRefreshBeforeRebalance(client) {
|
332
|
+
async function requiresRefreshBeforeRebalance(client, values) {
|
333
|
+
// REMOVE ME
|
334
|
+
const state = client.solautoPositionState;
|
335
|
+
const settings = client.solautoPositionSettings();
|
336
|
+
if ((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint).equals(new web3_js_1.PublicKey(constants_1.JUP)) &&
|
337
|
+
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint).equals(new web3_js_1.PublicKey(constants_1.USDC)) &&
|
338
|
+
settings &&
|
339
|
+
settings.boostToBps ===
|
340
|
+
(0, numberUtils_1.maxBoostToBps)(state.maxLtvBps, state.liqThresholdBps) && values.targetRateBps === 6500) {
|
341
|
+
return true;
|
342
|
+
}
|
333
343
|
const neverRefreshedBefore = client.solautoPositionData &&
|
334
344
|
client.solautoPositionData.state.supply.amountCanBeUsed.baseUnit ===
|
335
345
|
BigInt(0) &&
|
@@ -377,7 +387,8 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
377
387
|
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
378
388
|
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
|
379
389
|
let tx = (0, umi_1.transactionBuilder)();
|
380
|
-
|
390
|
+
// REVERT ME
|
391
|
+
if (await requiresRefreshBeforeRebalance(client, values)) {
|
381
392
|
tx = tx.add(client.refresh());
|
382
393
|
}
|
383
394
|
if (flashLoan) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAW7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,WAAW,EAAE,OAAO,CAAS;gBAG3B,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAKV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AY;YA6CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,mBAAmB;YAoBb,SAAS;IAiBV,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IA+FzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA4BxB,6BAA6B;
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAW7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,WAAW,EAAE,OAAO,CAAS;gBAG3B,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAKV,OAAO,CAAC,UAAU,EAAE,MAAM;IAMhC,cAAc,IAAI,MAAM,EAAE;CAY3B;AA0FD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;I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,0BAA0B,CAAC;IA+FzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA4BxB,6BAA6B;YAmI7B,qBAAqB;YAmDrB,cAAc;YAqCd,eAAe;CA4D9B"}
|
@@ -379,13 +379,14 @@ class TransactionsManager {
|
|
379
379
|
this.txHandler.log("Capturing error info...");
|
380
380
|
const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, transactions, e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful).length === itemSets.length);
|
381
381
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
382
|
+
const errorInfo = errorDetails.errorName || errorDetails.errorInfo
|
383
|
+
? errorString
|
384
|
+
: e.message;
|
382
385
|
this.updateStatusForSets(itemSets, errorDetails.canBeIgnored
|
383
386
|
? TransactionStatus.Skipped
|
384
|
-
: TransactionStatus.Failed, num, undefined, undefined,
|
385
|
-
? errorString
|
386
|
-
: e.message);
|
387
|
+
: TransactionStatus.Failed, num, undefined, undefined, errorInfo);
|
387
388
|
if (!errorDetails.canBeIgnored) {
|
388
|
-
throw
|
389
|
+
throw new Error(errorInfo);
|
389
390
|
}
|
390
391
|
});
|
391
392
|
}
|
@@ -442,13 +443,14 @@ class TransactionsManager {
|
|
442
443
|
this.txHandler.log("Capturing error info...");
|
443
444
|
const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, [tx], e, this.statuses.find((x) => x.name === txName)?.simulationSuccessful);
|
444
445
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
446
|
+
const errorInfo = errorDetails.errorName || errorDetails.errorInfo
|
447
|
+
? errorString
|
448
|
+
: e.message;
|
445
449
|
this.updateStatus(txName, errorDetails.canBeIgnored
|
446
450
|
? TransactionStatus.Skipped
|
447
|
-
: TransactionStatus.Failed, attemptNum, undefined, undefined,
|
448
|
-
? errorString
|
449
|
-
: e.message);
|
451
|
+
: TransactionStatus.Failed, attemptNum, undefined, undefined, errorInfo);
|
450
452
|
if (!errorDetails.canBeIgnored) {
|
451
|
-
throw
|
453
|
+
throw new Error(errorInfo);
|
452
454
|
}
|
453
455
|
}
|
454
456
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAGJ,eAAe,EAGhB,MAAM,iBAAiB,CAAC;AAazB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,UAAU,wBAAyB,SAAQ,qBAAqB;IAC9D,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GACd,wBAAwB,CAY1B;AAED,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,MAAM,GAClB,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BlB;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,SAAS,EACxB,MAAM,EAAE;IACN,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,IAAI,EAAE;IACJ,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,WAAW,CAAC,EAAE,MAAM,GACnB,OAA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,CAAC;CACzB;AAED,KAAK,UAAU,GAAG;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,CAAC;AAEhE,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,eAAe,EAAE;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,eAAe,CAAA;CAAE,EAC1D,aAAa,CAAC,EAAE,SAAS,EACzB,MAAM,CAAC,EAAE,aAAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA0LpC;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE"}
|
@@ -253,8 +253,6 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
253
253
|
}, supplyPrice);
|
254
254
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(supplyUsage.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
255
255
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(debtUsage?.amountUsed?.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS);
|
256
|
-
console.log("Asset weight init", (0, numberUtils_1.bytesToI80F48)(supplyBank.config.assetWeightInit.value));
|
257
|
-
console.log("Liability weight init", (0, numberUtils_1.bytesToI80F48)(debtBank.config.liabilityWeightInit.value));
|
258
256
|
return {
|
259
257
|
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, (0, numberUtils_1.toBps)(liqThreshold)),
|
260
258
|
netWorth: {
|
@@ -13,6 +13,7 @@ export interface RebalanceValues {
|
|
13
13
|
rebalanceAction: RebalanceAction;
|
14
14
|
rebalanceDirection: RebalanceDirection;
|
15
15
|
feesUsd: number;
|
16
|
+
targetRateBps: number;
|
16
17
|
}
|
17
18
|
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
|
18
19
|
export declare function rebalanceRequiresFlashLoan(client: SolautoClient, values: RebalanceValues): {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAcjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoI9C,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE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9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CA4DhB"}
|
@@ -85,6 +85,7 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
|
|
85
85
|
}
|
86
86
|
function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
|
87
87
|
let { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
|
88
|
+
// REVERT ME AND GET TO THE ROOT OF THIS ISSUE
|
88
89
|
if ((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint).equals(new web3_js_1.PublicKey(constants_1.JUP)) &&
|
89
90
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint).equals(new web3_js_1.PublicKey(constants_1.USDC)) &&
|
90
91
|
settings &&
|
@@ -102,7 +103,7 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
102
103
|
amountUsdToDcaIn;
|
103
104
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(state.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
104
105
|
let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(state.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
|
105
|
-
(0, generalUtils_2.consoleLog)("Target rate:", targetRateBps);
|
106
|
+
(0, generalUtils_2.consoleLog)("Target rate:", targetRateBps, (0, numberUtils_1.maxBoostToBps)(state.maxLtvBps, state.liqThresholdBps));
|
106
107
|
const maxRepayTo = (0, numberUtils_1.maxRepayToBps)(state.maxLtvBps, state.liqThresholdBps);
|
107
108
|
return {
|
108
109
|
debtAdjustmentUsd,
|
@@ -117,6 +118,7 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
117
118
|
: "repay",
|
118
119
|
rebalanceDirection,
|
119
120
|
feesUsd: Math.abs(debtAdjustmentUsd * (0, numberUtils_1.fromBps)(adjustmentFeeBps)),
|
121
|
+
targetRateBps
|
120
122
|
};
|
121
123
|
}
|
122
124
|
function rebalanceRequiresFlashLoan(client, values) {
|
package/local/logPositions.ts
CHANGED
@@ -188,6 +188,8 @@ async function main(filterWhitelist: boolean) {
|
|
188
188
|
|
189
189
|
const latestStates: PositionState[] = [];
|
190
190
|
let unhealthyPositions = 0;
|
191
|
+
let awaitingBoostPositions = 0;
|
192
|
+
|
191
193
|
for (const pos of solautoPositionsData) {
|
192
194
|
const latestState = await positionStateWithLatestPrices(
|
193
195
|
pos.state,
|
@@ -201,21 +203,42 @@ async function main(filterWhitelist: boolean) {
|
|
201
203
|
toWeb3JsPublicKey(pos.state.debt.mint)
|
202
204
|
);
|
203
205
|
|
204
|
-
const repayFrom =
|
206
|
+
const repayFrom =
|
207
|
+
pos.position.settingParams.repayToBps +
|
208
|
+
pos.position.settingParams.repayGap;
|
205
209
|
const unhealthy = latestState.liqUtilizationRateBps > repayFrom;
|
206
|
-
const healthText = unhealthy
|
210
|
+
const healthText = unhealthy
|
211
|
+
? `(Unhealthy: ${latestState.liqUtilizationRateBps - repayFrom}bps)`
|
212
|
+
: "";
|
207
213
|
if (unhealthy) {
|
208
214
|
unhealthyPositions += 1;
|
209
215
|
}
|
210
216
|
|
211
|
-
|
217
|
+
const awaitingBoost =
|
218
|
+
latestState.liqUtilizationRateBps <
|
219
|
+
pos.position.settingParams.boostToBps -
|
220
|
+
pos.position.settingParams.boostGap;
|
221
|
+
const boostText = awaitingBoost ? " (awaiting boost)" : "";
|
222
|
+
if (awaitingBoost) {
|
223
|
+
awaitingBoostPositions += 1;
|
224
|
+
}
|
225
|
+
|
212
226
|
console.log(
|
213
|
-
|
227
|
+
pos.publicKey.toString(),
|
228
|
+
`(${pos.authority.toString()} ${pos.positionId})`
|
229
|
+
);
|
230
|
+
console.log(
|
231
|
+
`${strategy}: $${formatNumber(fromBaseUnit(latestState.netWorth.baseAmountUsdValue, USD_DECIMALS), 2, 10000, 2)} ${healthText} ${boostText}`
|
214
232
|
);
|
215
233
|
// console.log(latestState.liqUtilizationRateBps, repayFrom);
|
216
234
|
}
|
217
235
|
|
218
|
-
console.log(
|
236
|
+
console.log(
|
237
|
+
"\nTotal positions:",
|
238
|
+
solautoPositionsData.length,
|
239
|
+
unhealthyPositions ? ` (unhealthy: ${unhealthyPositions})` : "",
|
240
|
+
awaitingBoostPositions ? ` (awaiting boost: ${awaitingBoostPositions})` : ""
|
241
|
+
);
|
219
242
|
console.log(
|
220
243
|
"Total users:",
|
221
244
|
Array.from(new Set(solautoPositionsData.map((x) => x.authority.toString())))
|
@@ -229,4 +252,4 @@ async function main(filterWhitelist: boolean) {
|
|
229
252
|
}
|
230
253
|
|
231
254
|
const filterWhitelist = true;
|
232
|
-
main(filterWhitelist).then((x) => x);
|
255
|
+
main(filterWhitelist).then((x) => x);
|
package/package.json
CHANGED
@@ -19,6 +19,7 @@ import {
|
|
19
19
|
RebalanceDirection,
|
20
20
|
SolautoAction,
|
21
21
|
SolautoRebalanceType,
|
22
|
+
SolautoSettingsParameters,
|
22
23
|
TokenType,
|
23
24
|
convertReferralFees,
|
24
25
|
createSolautoProgram,
|
@@ -39,6 +40,7 @@ import {
|
|
39
40
|
getFlashLoanDetails,
|
40
41
|
getJupSwapRebalanceDetails,
|
41
42
|
getRebalanceValues,
|
43
|
+
RebalanceValues,
|
42
44
|
} from "../utils/solauto/rebalanceUtils";
|
43
45
|
import {
|
44
46
|
consoleLog,
|
@@ -49,6 +51,7 @@ import {
|
|
49
51
|
import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
|
50
52
|
import {
|
51
53
|
getMaxLiqUtilizationRateBps,
|
54
|
+
maxBoostToBps,
|
52
55
|
uint8ArrayToBigInt,
|
53
56
|
} from "../utils/numberUtils";
|
54
57
|
import {
|
@@ -71,10 +74,11 @@ import {
|
|
71
74
|
getJupiterErrorFromCode,
|
72
75
|
JUPITER_PROGRAM_ID,
|
73
76
|
} from "../jupiter-sdk";
|
74
|
-
import { PRICES } from "../constants";
|
77
|
+
import { JUP, PRICES, USDC } from "../constants";
|
75
78
|
import { TransactionItemInputs } from "../types";
|
76
79
|
import { safeGetPrice } from "../utils";
|
77
80
|
import { BundleSimulationError } from "../types/transactions";
|
81
|
+
import { getPackedSettings } from "http2";
|
78
82
|
|
79
83
|
interface wSolTokenUsage {
|
80
84
|
wSolTokenAccount: PublicKey;
|
@@ -598,7 +602,20 @@ export async function getTransactionChores(
|
|
598
602
|
return [choresBefore, choresAfter];
|
599
603
|
}
|
600
604
|
|
601
|
-
export async function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
605
|
+
export async function requiresRefreshBeforeRebalance(client: SolautoClient, values: RebalanceValues) {
|
606
|
+
// REMOVE ME
|
607
|
+
const state = client.solautoPositionState!;
|
608
|
+
const settings = client.solautoPositionSettings();
|
609
|
+
if (
|
610
|
+
toWeb3JsPublicKey(state.supply.mint).equals(new PublicKey(JUP)) &&
|
611
|
+
toWeb3JsPublicKey(state.debt.mint).equals(new PublicKey(USDC)) &&
|
612
|
+
settings &&
|
613
|
+
settings.boostToBps ===
|
614
|
+
maxBoostToBps(state.maxLtvBps, state.liqThresholdBps) && values.targetRateBps === 6500
|
615
|
+
) {
|
616
|
+
return true;
|
617
|
+
}
|
618
|
+
|
602
619
|
const neverRefreshedBefore =
|
603
620
|
client.solautoPositionData &&
|
604
621
|
client.solautoPositionData.state.supply.amountCanBeUsed.baseUnit ===
|
@@ -707,7 +724,8 @@ export async function buildSolautoRebalanceTransaction(
|
|
707
724
|
|
708
725
|
let tx = transactionBuilder();
|
709
726
|
|
710
|
-
|
727
|
+
// REVERT ME
|
728
|
+
if (await requiresRefreshBeforeRebalance(client, values)) {
|
711
729
|
tx = tx.add(client.refresh());
|
712
730
|
}
|
713
731
|
|
@@ -646,6 +646,10 @@ export class TransactionsManager {
|
|
646
646
|
);
|
647
647
|
|
648
648
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
649
|
+
const errorInfo =
|
650
|
+
errorDetails.errorName || errorDetails.errorInfo
|
651
|
+
? errorString
|
652
|
+
: e.message;
|
649
653
|
this.updateStatusForSets(
|
650
654
|
itemSets,
|
651
655
|
errorDetails.canBeIgnored
|
@@ -654,13 +658,11 @@ export class TransactionsManager {
|
|
654
658
|
num,
|
655
659
|
undefined,
|
656
660
|
undefined,
|
657
|
-
|
658
|
-
? errorString
|
659
|
-
: e.message
|
661
|
+
errorInfo
|
660
662
|
);
|
661
663
|
|
662
664
|
if (!errorDetails.canBeIgnored) {
|
663
|
-
throw
|
665
|
+
throw new Error(errorInfo);
|
664
666
|
}
|
665
667
|
});
|
666
668
|
}
|
@@ -793,6 +795,10 @@ export class TransactionsManager {
|
|
793
795
|
);
|
794
796
|
|
795
797
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
798
|
+
const errorInfo =
|
799
|
+
errorDetails.errorName || errorDetails.errorInfo
|
800
|
+
? errorString
|
801
|
+
: e.message;
|
796
802
|
this.updateStatus(
|
797
803
|
txName,
|
798
804
|
errorDetails.canBeIgnored
|
@@ -801,13 +807,11 @@ export class TransactionsManager {
|
|
801
807
|
attemptNum,
|
802
808
|
undefined,
|
803
809
|
undefined,
|
804
|
-
|
805
|
-
? errorString
|
806
|
-
: e.message
|
810
|
+
errorInfo
|
807
811
|
);
|
808
812
|
|
809
813
|
if (!errorDetails.canBeIgnored) {
|
810
|
-
throw
|
814
|
+
throw new Error(errorInfo);
|
811
815
|
}
|
812
816
|
}
|
813
817
|
}
|
@@ -464,9 +464,6 @@ export async function getMarginfiAccountPositionState(
|
|
464
464
|
USD_DECIMALS
|
465
465
|
);
|
466
466
|
|
467
|
-
console.log("Asset weight init", bytesToI80F48(supplyBank.config.assetWeightInit.value));
|
468
|
-
console.log("Liability weight init", bytesToI80F48(debtBank.config.liabilityWeightInit.value));
|
469
|
-
|
470
467
|
return {
|
471
468
|
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
472
469
|
supplyUsd,
|
@@ -170,6 +170,7 @@ export interface RebalanceValues {
|
|
170
170
|
rebalanceAction: RebalanceAction;
|
171
171
|
rebalanceDirection: RebalanceDirection;
|
172
172
|
feesUsd: number;
|
173
|
+
targetRateBps: number;
|
173
174
|
}
|
174
175
|
|
175
176
|
export function getRebalanceValues(
|
@@ -189,6 +190,7 @@ export function getRebalanceValues(
|
|
189
190
|
targetLiqUtilizationRateBps
|
190
191
|
);
|
191
192
|
|
193
|
+
// REVERT ME AND GET TO THE ROOT OF THIS ISSUE
|
192
194
|
if (
|
193
195
|
toWeb3JsPublicKey(state.supply.mint).equals(new PublicKey(JUP)) &&
|
194
196
|
toWeb3JsPublicKey(state.debt.mint).equals(new PublicKey(USDC)) &&
|
@@ -229,7 +231,7 @@ export function getRebalanceValues(
|
|
229
231
|
adjustmentFeeBps
|
230
232
|
);
|
231
233
|
|
232
|
-
consoleLog("Target rate:", targetRateBps);
|
234
|
+
consoleLog("Target rate:", targetRateBps, maxBoostToBps(state.maxLtvBps, state.liqThresholdBps));
|
233
235
|
const maxRepayTo = maxRepayToBps(state.maxLtvBps, state.liqThresholdBps);
|
234
236
|
return {
|
235
237
|
debtAdjustmentUsd,
|
@@ -246,6 +248,7 @@ export function getRebalanceValues(
|
|
246
248
|
: "repay",
|
247
249
|
rebalanceDirection,
|
248
250
|
feesUsd: Math.abs(debtAdjustmentUsd * fromBps(adjustmentFeeBps)),
|
251
|
+
targetRateBps
|
249
252
|
};
|
250
253
|
}
|
251
254
|
|
@@ -1,9 +1,5 @@
|
|
1
1
|
import { describe, it } from "mocha";
|
2
|
-
import {
|
3
|
-
none,
|
4
|
-
publicKey,
|
5
|
-
some,
|
6
|
-
} from "@metaplex-foundation/umi";
|
2
|
+
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
7
3
|
import { setupTest } from "../shared";
|
8
4
|
import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
|
9
5
|
import {
|
@@ -13,6 +9,9 @@ import {
|
|
13
9
|
} from "../../src/generated";
|
14
10
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
15
11
|
import {
|
12
|
+
bytesToI80F48,
|
13
|
+
getLiqUtilzationRateBps,
|
14
|
+
getMaxLiqUtilizationRateBps,
|
16
15
|
maxBoostToBps,
|
17
16
|
maxRepayFromBps,
|
18
17
|
maxRepayToBps,
|
@@ -25,24 +24,39 @@ import {
|
|
25
24
|
} from "../../src/transactions/transactionsManager";
|
26
25
|
import { PublicKey } from "@solana/web3.js";
|
27
26
|
import {
|
27
|
+
DEFAULT_MARGINFI_GROUP,
|
28
|
+
MARGINFI_ACCOUNTS,
|
28
29
|
SOLAUTO_PROD_PROGRAM,
|
29
30
|
SOLAUTO_TEST_PROGRAM,
|
30
31
|
USDC,
|
32
|
+
USDT,
|
31
33
|
} from "../../src/constants";
|
32
34
|
import {
|
33
35
|
buildHeliusApiUrl,
|
36
|
+
getMarginfiAccountPositionState,
|
34
37
|
getSolautoManagedPositions,
|
38
|
+
retryWithExponentialBackoff,
|
35
39
|
} from "../../src/utils";
|
36
40
|
import { PriorityFeeSetting } from "../../src/types";
|
37
|
-
import { buildIronforgeApiUrl } from "../../dist";
|
41
|
+
import { buildIronforgeApiUrl, fetchSolautoPosition, fetchTokenPrices } from "../../dist";
|
42
|
+
import { safeFetchBank } from "../../src/marginfi-sdk";
|
43
|
+
|
44
|
+
export function getFlooredTimestampByMinute(
|
45
|
+
unixSeconds: number,
|
46
|
+
intervalInMinutes: number = 1
|
47
|
+
): number {
|
48
|
+
const unixTime = Math.floor(new Date(unixSeconds * 1000).getTime() / 1000);
|
49
|
+
const interval = intervalInMinutes * 60;
|
50
|
+
return Math.floor(unixTime / interval) * interval;
|
51
|
+
}
|
38
52
|
|
39
53
|
describe("Solauto Marginfi tests", async () => {
|
40
|
-
|
41
|
-
const signer = setupTest("solauto-manager");
|
54
|
+
const signer = setupTest();
|
55
|
+
// const signer = setupTest("solauto-manager");
|
42
56
|
|
43
|
-
const payForTransactions =
|
57
|
+
const payForTransactions = false;
|
44
58
|
const testProgram = false;
|
45
|
-
const positionId =
|
59
|
+
const positionId = 3;
|
46
60
|
|
47
61
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
48
62
|
const client = new SolautoMarginfiClient(
|
@@ -68,7 +82,22 @@ describe("Solauto Marginfi tests", async () => {
|
|
68
82
|
// debtMint: new PublicKey(USDC),
|
69
83
|
});
|
70
84
|
|
71
|
-
// console.log(await
|
85
|
+
// console.log(await client.getFreshPositionState());
|
86
|
+
|
87
|
+
// const debtBank = await safeFetchBank(
|
88
|
+
// client.umi,
|
89
|
+
// publicKey(MARGINFI_ACCOUNTS[DEFAULT_MARGINFI_GROUP][USDC].bank)
|
90
|
+
// );
|
91
|
+
// const state = await getMarginfiAccountPositionState(client.umi, {
|
92
|
+
// pk: new PublicKey("85YaXXB1uyDMLYf4ob6jfV1kr29muVNm7mpmM8qjbVq6"),
|
93
|
+
// });
|
94
|
+
// console.log(state);
|
95
|
+
// console.log(maxBoostToBps(state.maxLtvBps, state.liqThresholdBps));
|
96
|
+
// console.log(
|
97
|
+
// getMaxLiqUtilizationRateBps(state.maxLtvBps, state.liqThresholdBps, 0)
|
98
|
+
// );
|
99
|
+
// console.log(getLiqUtilzationRateBps(18.78, 7.47, state.liqThresholdBps));
|
100
|
+
// return;
|
72
101
|
|
73
102
|
const transactionItems: TransactionItem[] = [];
|
74
103
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
@@ -86,6 +115,15 @@ describe("Solauto Marginfi tests", async () => {
|
|
86
115
|
// targetBoostToBps: none(),
|
87
116
|
// };
|
88
117
|
|
118
|
+
const settingParams: SolautoSettingsParametersInpArgs = {
|
119
|
+
boostToBps: client.solautoPositionSettings().boostToBps - 150,
|
120
|
+
boostGap: 50,
|
121
|
+
repayToBps: client.solautoPositionSettings().repayToBps - 150,
|
122
|
+
repayGap: 50,
|
123
|
+
automation: none(),
|
124
|
+
targetBoostToBps: none(),
|
125
|
+
};
|
126
|
+
|
89
127
|
// if (client.solautoPositionData === null) {
|
90
128
|
// transactionItems.push(
|
91
129
|
// new TransactionItem(async () => {
|
@@ -131,11 +169,18 @@ describe("Solauto Marginfi tests", async () => {
|
|
131
169
|
transactionItems.push(
|
132
170
|
new TransactionItem(
|
133
171
|
async (attemptNum) =>
|
134
|
-
await buildSolautoRebalanceTransaction(client,
|
172
|
+
await buildSolautoRebalanceTransaction(client, 4000, attemptNum),
|
135
173
|
"rebalance"
|
136
174
|
)
|
137
175
|
);
|
138
176
|
|
177
|
+
// transactionItems.push(
|
178
|
+
// new TransactionItem(
|
179
|
+
// async () => ({ tx: client.refresh() }),
|
180
|
+
// "refresh"
|
181
|
+
// )
|
182
|
+
// );
|
183
|
+
|
139
184
|
// transactionItems.push(
|
140
185
|
// new TransactionItem(
|
141
186
|
// async (attemptNum) =>
|