@haven-fi/solauto-sdk 1.0.192 → 1.0.194
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts +2 -1
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.d.ts +2 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +12 -7
- package/dist/constants/solautoConstants.d.ts +0 -1
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +1 -2
- package/dist/generated/instructions/marginfiRebalance.d.ts +0 -2
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +0 -1
- package/dist/generated/types/lendingPlatform.d.ts +1 -2
- package/dist/generated/types/lendingPlatform.d.ts.map +1 -1
- package/dist/generated/types/lendingPlatform.js +0 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +6 -7
- package/dist/types/accounts.d.ts +1 -0
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +4 -0
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +0 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts +1 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +2 -16
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +2 -1
- package/src/clients/solautoMarginfiClient.ts +17 -9
- package/src/constants/solautoConstants.ts +0 -1
- package/src/generated/instructions/marginfiRebalance.ts +0 -3
- package/src/generated/types/lendingPlatform.ts +0 -1
- package/src/transactions/transactionUtils.ts +6 -3
- package/src/types/accounts.ts +1 -0
- package/src/utils/marginfiUtils.ts +6 -1
- package/src/utils/solauto/generalUtils.ts +0 -1
- package/src/utils/solauto/rebalanceUtils.ts +3 -24
@@ -8,6 +8,7 @@ import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
|
8
8
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
9
9
|
import { ReferralStateManager } from "./referralStateManager";
|
10
10
|
import { TxHandler } from "./txHandler";
|
11
|
+
import { QuoteResponse } from "@jup-ag/api";
|
11
12
|
export interface SolautoClientArgs {
|
12
13
|
authority?: PublicKey;
|
13
14
|
positionId?: number;
|
@@ -64,7 +65,7 @@ export declare abstract class SolautoClient extends TxHandler {
|
|
64
65
|
protocolInteraction(args: SolautoActionArgs): TransactionBuilder;
|
65
66
|
abstract flashBorrow(flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
66
67
|
abstract flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
67
|
-
abstract rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number
|
68
|
+
abstract rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, jupQuote: QuoteResponse, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number): TransactionBuilder;
|
68
69
|
getFreshPositionState(): Promise<PositionState | undefined>;
|
69
70
|
}
|
70
71
|
//# sourceMappingURL=solautoClient.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,MAAM,EACN,kBAAkB,EAOnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EAC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ebalanceT
|
|
6
6
|
import { MarginfiAccount } from "../marginfi-sdk";
|
7
7
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
8
8
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
9
|
+
import { QuoteResponse } from "@jup-ag/api";
|
9
10
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
10
11
|
marginfiAccount?: PublicKey | Signer;
|
11
12
|
marginfiAccountSeedIdx?: bigint;
|
@@ -38,7 +39,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
38
39
|
protocolInteraction(args: SolautoActionArgs): TransactionBuilder;
|
39
40
|
private marginfiProtocolInteractionIx;
|
40
41
|
private marginfiSolautoProtocolInteractionIx;
|
41
|
-
rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number
|
42
|
+
rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, jupQuote: QuoteResponse, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number): TransactionBuilder;
|
42
43
|
flashBorrow(flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
43
44
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
44
45
|
createIntermediaryMarginfiAccount(): TransactionBuilder;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,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,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CA4ClE"}
|
@@ -37,9 +37,11 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
37
37
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.marginfiAccount.publicKey)
|
38
38
|
: this.marginfiAccount;
|
39
39
|
const marginfiAccountData = await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(this.umi, (0, umi_1.publicKey)(this.marginfiAccountPk), { commitment: "confirmed" });
|
40
|
-
this.marginfiGroup = marginfiAccountData
|
41
|
-
?
|
42
|
-
: args.marginfiGroup ??
|
40
|
+
this.marginfiGroup = new web3_js_1.PublicKey(marginfiAccountData
|
41
|
+
? marginfiAccountData.group.toString()
|
42
|
+
: args.marginfiGroup ??
|
43
|
+
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.supplyMint.toString()].marginfiGroup ??
|
44
|
+
marginfiAccounts_1.DEFAULT_MARGINFI_GROUP);
|
43
45
|
this.marginfiSupplyAccounts =
|
44
46
|
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.supplyMint.toString()];
|
45
47
|
this.marginfiDebtAccounts = marginfiAccounts_1.MARGINFI_ACCOUNTS[this.debtMint.toString()];
|
@@ -289,7 +291,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
289
291
|
solautoAction: args,
|
290
292
|
});
|
291
293
|
}
|
292
|
-
rebalance(rebalanceStep, swapDetails, rebalanceType, flashLoan, targetLiqUtilizationRateBps
|
294
|
+
rebalance(rebalanceStep, swapDetails, jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps) {
|
293
295
|
const inputIsSupply = swapDetails.inputMint.equals(this.supplyMint);
|
294
296
|
const outputIsSupply = swapDetails.outputMint.equals(this.supplyMint);
|
295
297
|
const needSupplyAccounts = (inputIsSupply && rebalanceStep === "A") ||
|
@@ -334,8 +336,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
334
336
|
: undefined,
|
335
337
|
rebalanceType,
|
336
338
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
337
|
-
targetInAmountBaseUnit: rebalanceStep === "A" ?
|
338
|
-
limitGapBps: limitGapBps ?? null,
|
339
|
+
targetInAmountBaseUnit: rebalanceStep === "A" ? parseInt(jupQuote.inAmount) : null,
|
339
340
|
});
|
340
341
|
}
|
341
342
|
flashBorrow(flashLoanDetails, destinationTokenAccount) {
|
@@ -434,7 +435,11 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
434
435
|
if (state) {
|
435
436
|
return state;
|
436
437
|
}
|
437
|
-
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, !this.selfManaged && this.solautoPositionData === null
|
438
|
+
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, !this.selfManaged && this.solautoPositionData === null
|
439
|
+
? this.supplyMint
|
440
|
+
: undefined, !this.selfManaged && this.solautoPositionData === null
|
441
|
+
? this.debtMint
|
442
|
+
: undefined, this.livePositionUpdates);
|
438
443
|
if (freshState) {
|
439
444
|
this.log("Fresh state", freshState);
|
440
445
|
const supplyPrice = (0, generalUtils_1.safeGetPrice)(freshState?.supply.mint);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAQpC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAE1E,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.
|
3
|
+
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = void 0;
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
6
6
|
// import { JitoRpcConnection } from "jito-ts";
|
@@ -9,7 +9,6 @@ const generalAccounts_1 = require("./generalAccounts");
|
|
9
9
|
const jupiter_sdk_1 = require("../jupiter-sdk");
|
10
10
|
globalThis.LOCAL_TEST = false;
|
11
11
|
exports.BASIS_POINTS = 10000;
|
12
|
-
exports.DEFAULT_LIMIT_GAP_BPS = 1000;
|
13
12
|
exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
14
13
|
exports.MIN_REPAY_GAP_BPS = 50;
|
15
14
|
exports.MIN_BOOST_GAP_BPS = 50;
|
@@ -40,13 +40,11 @@ export type MarginfiRebalanceInstructionData = {
|
|
40
40
|
rebalanceType: SolautoRebalanceType;
|
41
41
|
targetLiqUtilizationRateBps: Option<number>;
|
42
42
|
targetInAmountBaseUnit: Option<bigint>;
|
43
|
-
limitGapBps: Option<number>;
|
44
43
|
};
|
45
44
|
export type MarginfiRebalanceInstructionDataArgs = {
|
46
45
|
rebalanceType: SolautoRebalanceTypeArgs;
|
47
46
|
targetLiqUtilizationRateBps: OptionOrNullable<number>;
|
48
47
|
targetInAmountBaseUnit: OptionOrNullable<number | bigint>;
|
49
|
-
limitGapBps: OptionOrNullable<number>;
|
50
48
|
};
|
51
49
|
export declare function getMarginfiRebalanceInstructionDataSerializer(): Serializer<MarginfiRebalanceInstructionDataArgs, MarginfiRebalanceInstructionData>;
|
52
50
|
export type MarginfiRebalanceInstructionArgs = MarginfiRebalanceInstructionDataArgs;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiRebalance.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiRebalance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAOX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EAEzB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,oCAAoC,GAAG;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;IAC3B,mBAAmB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACtC,sBAAsB,EAAE,SAAS,GAAG,GAAG,CAAC;IACxC,kBAAkB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,iBAAiB,EAAE,SAAS,GAAG,GAAG,CAAC;IACnC,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,cAAc,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,UAAU,EAAE,SAAS,GAAG,GAAG,CAAC;IAC5B,iBAAiB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACpC,gBAAgB,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,iBAAiB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACpC,aAAa,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,oBAAoB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACvC,QAAQ,EAAE,SAAS,GAAG,GAAG,CAAC;IAC1B,eAAe,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,cAAc,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,eAAe,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,WAAW,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC9B,kBAAkB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;CACtC,CAAC;AAGF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,oBAAoB,CAAC;IACpC,2BAA2B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"marginfiRebalance.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiRebalance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAOX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,oBAAoB,EACpB,wBAAwB,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AAM,gCAAgC,GAAG;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,oBAAoB,CAAC;IACpC,2BAA2B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,aAAa,EAAE,wBAAwB,CAAC;IACxC,2BAA2B,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtD,sBAAsB,EAAE,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CAC3D,CAAC;AAEF,wBAAgB,6CAA6C,IAAI,UAAU,CACzE,oCAAoC,EACpC,gCAAgC,CACjC,CAoBA;AAGD,MAAM,MAAM,gCAAgC,GAC1C,oCAAoC,CAAC;AAGvC,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,KAAK,EAAE,oCAAoC,GAAG,gCAAgC,GAC7E,kBAAkB,CAkLpB"}
|
@@ -19,7 +19,6 @@ function getMarginfiRebalanceInstructionDataSerializer() {
|
|
19
19
|
['rebalanceType', (0, types_1.getSolautoRebalanceTypeSerializer)()],
|
20
20
|
['targetLiqUtilizationRateBps', (0, serializers_1.option)((0, serializers_1.u16)())],
|
21
21
|
['targetInAmountBaseUnit', (0, serializers_1.option)((0, serializers_1.u64)())],
|
22
|
-
['limitGapBps', (0, serializers_1.option)((0, serializers_1.u16)())],
|
23
22
|
], { description: 'MarginfiRebalanceInstructionData' }), (value) => ({ ...value, discriminator: 9 }));
|
24
23
|
}
|
25
24
|
// Instruction.
|
@@ -7,8 +7,7 @@
|
|
7
7
|
*/
|
8
8
|
import { Serializer } from '@metaplex-foundation/umi/serializers';
|
9
9
|
export declare enum LendingPlatform {
|
10
|
-
Marginfi = 0
|
11
|
-
Kamino = 1
|
10
|
+
Marginfi = 0
|
12
11
|
}
|
13
12
|
export type LendingPlatformArgs = LendingPlatform;
|
14
13
|
export declare function getLendingPlatformSerializer(): Serializer<LendingPlatformArgs, LendingPlatform>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"lendingPlatform.d.ts","sourceRoot":"","sources":["../../../src/generated/types/lendingPlatform.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,eAAe;IACzB,QAAQ,IAAA;
|
1
|
+
{"version":3,"file":"lendingPlatform.d.ts","sourceRoot":"","sources":["../../../src/generated/types/lendingPlatform.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,eAAe;IACzB,QAAQ,IAAA;CACT;AAED,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAElD,wBAAgB,4BAA4B,IAAI,UAAU,CACxD,mBAAmB,EACnB,eAAe,CAChB,CAIA"}
|
@@ -13,7 +13,6 @@ const serializers_1 = require("@metaplex-foundation/umi/serializers");
|
|
13
13
|
var LendingPlatform;
|
14
14
|
(function (LendingPlatform) {
|
15
15
|
LendingPlatform[LendingPlatform["Marginfi"] = 0] = "Marginfi";
|
16
|
-
LendingPlatform[LendingPlatform["Kamino"] = 1] = "Kamino";
|
17
16
|
})(LendingPlatform || (exports.LendingPlatform = LendingPlatform = {}));
|
18
17
|
function getLendingPlatformSerializer() {
|
19
18
|
return (0, serializers_1.scalarEnum)(LendingPlatform, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAGL,aAAa,EAYd,MAAM,cAAc,CAAC;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AG,SAAS,CAAC,CAmCrD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
|
@@ -67,7 +67,7 @@ async function transactionChoresBefore(client, accountsGettingCreated, solautoAc
|
|
67
67
|
!(await (0, generalUtils_1.getSolanaAccountCreated)(client.umi, client.marginfiAccountPk))) {
|
68
68
|
chores = chores.add(client.marginfiAccountInitialize());
|
69
69
|
}
|
70
|
-
// TODO:
|
70
|
+
// TODO: PF
|
71
71
|
}
|
72
72
|
const wSolUsage = getWSolUsage(client, solautoActions, initiatingDcaIn, undefined);
|
73
73
|
if (wSolUsage !== undefined) {
|
@@ -188,7 +188,6 @@ function getRebalanceInstructions(tx) {
|
|
188
188
|
try {
|
189
189
|
const serializer = (0, generated_1.getMarginfiRebalanceInstructionDataSerializer)();
|
190
190
|
const discriminator = serializer.serialize({
|
191
|
-
limitGapBps: 0,
|
192
191
|
targetInAmountBaseUnit: 0,
|
193
192
|
rebalanceType: generated_1.SolautoRebalanceType.None,
|
194
193
|
targetLiqUtilizationRateBps: 0,
|
@@ -309,7 +308,7 @@ function getSolautoActions(tx) {
|
|
309
308
|
}
|
310
309
|
catch { }
|
311
310
|
}
|
312
|
-
// TODO
|
311
|
+
// TODO: PF
|
313
312
|
});
|
314
313
|
return solautoActions;
|
315
314
|
}
|
@@ -379,11 +378,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
379
378
|
client.flashBorrow(flashLoan, (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), swapDetails.inputMint)),
|
380
379
|
...(addFirstRebalance
|
381
380
|
? [
|
382
|
-
client.rebalance("A", swapDetails, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
381
|
+
client.rebalance("A", swapDetails, jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
383
382
|
]
|
384
383
|
: []),
|
385
384
|
swapIx,
|
386
|
-
client.rebalance("B", swapDetails, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
385
|
+
client.rebalance("B", swapDetails, jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
387
386
|
client.flashRepay(flashLoan),
|
388
387
|
]);
|
389
388
|
}
|
@@ -392,9 +391,9 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
392
391
|
tx = tx.add([
|
393
392
|
setupInstructions,
|
394
393
|
tokenLedgerIx,
|
395
|
-
client.rebalance("A", swapDetails, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
394
|
+
client.rebalance("A", swapDetails, jupQuote, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
396
395
|
swapIx,
|
397
|
-
client.rebalance("B", swapDetails, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
396
|
+
client.rebalance("B", swapDetails, jupQuote, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
398
397
|
]);
|
399
398
|
}
|
400
399
|
return {
|
package/dist/types/accounts.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":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aAAa,GAAG,SAAS,CAAC,CAkKpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3B"}
|
@@ -180,6 +180,10 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
|
|
180
180
|
if (supplyBank === null) {
|
181
181
|
return undefined;
|
182
182
|
}
|
183
|
+
if (!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.group).equals(new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP))) {
|
184
|
+
// Temporarily disabled for now
|
185
|
+
return undefined;
|
186
|
+
}
|
183
187
|
if (!supplyUsage) {
|
184
188
|
supplyUsage = await getTokenUsage(umi, supplyBank, true, 0, livePositionUpdates?.supplyAdjustment);
|
185
189
|
}
|
@@ -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,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EACb,YAAY,EAEZ,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAezB,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,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU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WAAW,GAAG,SAAS,CAAa;IAC/C,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAC;KAAE,CAAa;IACrE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAa;IAExD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA6B9B,KAAK;IASL,UAAU,IAAI,OAAO;CAStB"}
|
@@ -11,7 +11,7 @@ export interface RebalanceValues {
|
|
11
11
|
amountUsdToDcaIn: number;
|
12
12
|
dcaTokenType?: TokenType;
|
13
13
|
}
|
14
|
-
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number
|
14
|
+
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
|
15
15
|
export interface FlashLoanDetails {
|
16
16
|
baseUnitAmount: bigint;
|
17
17
|
mint: PublicKey;
|
@@ -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,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
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,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA8IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,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;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,GACnC,eAAe,CAiDjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CA0D9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAyChB"}
|
@@ -9,7 +9,6 @@ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters"
|
|
9
9
|
const generalUtils_2 = require("../generalUtils");
|
10
10
|
const numberUtils_1 = require("../numberUtils");
|
11
11
|
const generalAccounts_1 = require("../../constants/generalAccounts");
|
12
|
-
const solautoConstants_1 = require("../../constants/solautoConstants");
|
13
12
|
function getAdditionalAmountToDcaIn(dca) {
|
14
13
|
if (dca.dcaInBaseUnit === BigInt(0)) {
|
15
14
|
return 0;
|
@@ -80,10 +79,10 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
|
|
80
79
|
};
|
81
80
|
}
|
82
81
|
}
|
83
|
-
function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps
|
82
|
+
function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
|
84
83
|
const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
|
85
84
|
const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
|
86
|
-
debtPrice;
|
85
|
+
(dca?.tokenType === generated_1.TokenType.Debt ? debtPrice : supplyPrice);
|
87
86
|
const increasingLeverage = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps;
|
88
87
|
let adjustmentFeeBps = 0;
|
89
88
|
if (increasingLeverage) {
|
@@ -93,19 +92,6 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
93
92
|
amountUsdToDcaIn;
|
94
93
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(state.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
95
94
|
let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(state.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
|
96
|
-
const input = increasingLeverage ? state.debt : state.supply;
|
97
|
-
const inputMarketPrice = increasingLeverage ? debtPrice : supplyPrice;
|
98
|
-
const limitGap = limitGapBps
|
99
|
-
? (0, numberUtils_1.fromBps)(limitGapBps)
|
100
|
-
: (0, numberUtils_1.fromBps)(solautoConstants_1.DEFAULT_LIMIT_GAP_BPS);
|
101
|
-
if (debtAdjustmentUsd > 0 &&
|
102
|
-
(0, numberUtils_1.toBaseUnit)(debtAdjustmentUsd / inputMarketPrice, input.decimals) >
|
103
|
-
input.amountCanBeUsed.baseUnit) {
|
104
|
-
const maxUsageUsd = (0, numberUtils_1.fromBaseUnit)(input.amountCanBeUsed.baseUnit, input.decimals) *
|
105
|
-
inputMarketPrice *
|
106
|
-
limitGap;
|
107
|
-
debtAdjustmentUsd = maxUsageUsd - maxUsageUsd * limitGap;
|
108
|
-
}
|
109
95
|
const maxRepayTo = (0, numberUtils_1.maxRepayToBps)(state.maxLtvBps, state.liqThresholdBps);
|
110
96
|
return {
|
111
97
|
increasingLeverage,
|
package/package.json
CHANGED
@@ -53,6 +53,7 @@ import { currentUnixSeconds } from "../utils/generalUtils";
|
|
53
53
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
54
54
|
import { ReferralStateManager } from "./referralStateManager";
|
55
55
|
import { TxHandler } from "./txHandler";
|
56
|
+
import { QuoteResponse } from "@jup-ag/api";
|
56
57
|
|
57
58
|
export interface SolautoClientArgs {
|
58
59
|
authority?: PublicKey;
|
@@ -596,10 +597,10 @@ export abstract class SolautoClient extends TxHandler {
|
|
596
597
|
abstract rebalance(
|
597
598
|
rebalanceStep: "A" | "B",
|
598
599
|
swapDetails: JupSwapDetails,
|
600
|
+
jupQuote: QuoteResponse,
|
599
601
|
rebalanceType: SolautoRebalanceTypeArgs,
|
600
602
|
flashLoan?: FlashLoanDetails,
|
601
603
|
targetLiqUtilizationRateBps?: number,
|
602
|
-
limitGapBps?: number,
|
603
604
|
): TransactionBuilder;
|
604
605
|
|
605
606
|
async getFreshPositionState(): Promise<PositionState | undefined> {
|
@@ -57,6 +57,7 @@ import {
|
|
57
57
|
} from "../utils/marginfiUtils";
|
58
58
|
import { bytesToI80F48, fromBaseUnit, toBps } from "../utils/numberUtils";
|
59
59
|
import { createFakePositionState } from "../utils";
|
60
|
+
import { QuoteResponse } from "@jup-ag/api";
|
60
61
|
|
61
62
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
62
63
|
marginfiAccount?: PublicKey | Signer;
|
@@ -111,9 +112,13 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
111
112
|
publicKey(this.marginfiAccountPk),
|
112
113
|
{ commitment: "confirmed" }
|
113
114
|
);
|
114
|
-
this.marginfiGroup =
|
115
|
-
|
116
|
-
|
115
|
+
this.marginfiGroup = new PublicKey(
|
116
|
+
marginfiAccountData
|
117
|
+
? marginfiAccountData.group.toString()
|
118
|
+
: args.marginfiGroup ??
|
119
|
+
MARGINFI_ACCOUNTS[this.supplyMint.toString()].marginfiGroup ??
|
120
|
+
DEFAULT_MARGINFI_GROUP
|
121
|
+
);
|
117
122
|
|
118
123
|
this.marginfiSupplyAccounts =
|
119
124
|
MARGINFI_ACCOUNTS[this.supplyMint.toString()]!;
|
@@ -450,10 +455,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
450
455
|
rebalance(
|
451
456
|
rebalanceStep: "A" | "B",
|
452
457
|
swapDetails: JupSwapDetails,
|
458
|
+
jupQuote: QuoteResponse,
|
453
459
|
rebalanceType: SolautoRebalanceTypeArgs,
|
454
460
|
flashLoan?: FlashLoanDetails,
|
455
|
-
targetLiqUtilizationRateBps?: number
|
456
|
-
limitGapBps?: number
|
461
|
+
targetLiqUtilizationRateBps?: number
|
457
462
|
): TransactionBuilder {
|
458
463
|
const inputIsSupply = swapDetails.inputMint.equals(this.supplyMint);
|
459
464
|
const outputIsSupply = swapDetails.outputMint.equals(this.supplyMint);
|
@@ -514,8 +519,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
514
519
|
: undefined,
|
515
520
|
rebalanceType,
|
516
521
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
517
|
-
targetInAmountBaseUnit: rebalanceStep === "A" ?
|
518
|
-
limitGapBps: limitGapBps ?? null,
|
522
|
+
targetInAmountBaseUnit: rebalanceStep === "A" ? parseInt(jupQuote.inAmount) : null,
|
519
523
|
});
|
520
524
|
}
|
521
525
|
|
@@ -651,8 +655,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
651
655
|
const freshState = await getMarginfiAccountPositionState(
|
652
656
|
this.umi,
|
653
657
|
this.marginfiAccountPk,
|
654
|
-
!this.selfManaged && this.solautoPositionData === null
|
655
|
-
|
658
|
+
!this.selfManaged && this.solautoPositionData === null
|
659
|
+
? this.supplyMint
|
660
|
+
: undefined,
|
661
|
+
!this.selfManaged && this.solautoPositionData === null
|
662
|
+
? this.debtMint
|
663
|
+
: undefined,
|
656
664
|
this.livePositionUpdates
|
657
665
|
);
|
658
666
|
|
@@ -18,7 +18,6 @@ import { JUPITER_PROGRAM_ID } from "../jupiter-sdk";
|
|
18
18
|
|
19
19
|
export const BASIS_POINTS = 10000;
|
20
20
|
|
21
|
-
export const DEFAULT_LIMIT_GAP_BPS = 1000;
|
22
21
|
export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
23
22
|
export const MIN_REPAY_GAP_BPS = 50;
|
24
23
|
export const MIN_BOOST_GAP_BPS = 50;
|
@@ -71,14 +71,12 @@ export type MarginfiRebalanceInstructionData = {
|
|
71
71
|
rebalanceType: SolautoRebalanceType;
|
72
72
|
targetLiqUtilizationRateBps: Option<number>;
|
73
73
|
targetInAmountBaseUnit: Option<bigint>;
|
74
|
-
limitGapBps: Option<number>;
|
75
74
|
};
|
76
75
|
|
77
76
|
export type MarginfiRebalanceInstructionDataArgs = {
|
78
77
|
rebalanceType: SolautoRebalanceTypeArgs;
|
79
78
|
targetLiqUtilizationRateBps: OptionOrNullable<number>;
|
80
79
|
targetInAmountBaseUnit: OptionOrNullable<number | bigint>;
|
81
|
-
limitGapBps: OptionOrNullable<number>;
|
82
80
|
};
|
83
81
|
|
84
82
|
export function getMarginfiRebalanceInstructionDataSerializer(): Serializer<
|
@@ -96,7 +94,6 @@ export function getMarginfiRebalanceInstructionDataSerializer(): Serializer<
|
|
96
94
|
['rebalanceType', getSolautoRebalanceTypeSerializer()],
|
97
95
|
['targetLiqUtilizationRateBps', option(u16())],
|
98
96
|
['targetInAmountBaseUnit', option(u64())],
|
99
|
-
['limitGapBps', option(u16())],
|
100
97
|
],
|
101
98
|
{ description: 'MarginfiRebalanceInstructionData' }
|
102
99
|
),
|
@@ -163,7 +163,7 @@ async function transactionChoresBefore(
|
|
163
163
|
(client as SolautoMarginfiClient).marginfiAccountInitialize()
|
164
164
|
);
|
165
165
|
}
|
166
|
-
// TODO:
|
166
|
+
// TODO: PF
|
167
167
|
}
|
168
168
|
|
169
169
|
const wSolUsage = getWSolUsage(
|
@@ -402,7 +402,6 @@ function getRebalanceInstructions(tx: TransactionBuilder): Instruction[] {
|
|
402
402
|
try {
|
403
403
|
const serializer = getMarginfiRebalanceInstructionDataSerializer();
|
404
404
|
const discriminator = serializer.serialize({
|
405
|
-
limitGapBps: 0,
|
406
405
|
targetInAmountBaseUnit: 0,
|
407
406
|
rebalanceType: SolautoRebalanceType.None,
|
408
407
|
targetLiqUtilizationRateBps: 0,
|
@@ -541,7 +540,7 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
|
|
541
540
|
} catch {}
|
542
541
|
}
|
543
542
|
|
544
|
-
// TODO
|
543
|
+
// TODO: PF
|
545
544
|
});
|
546
545
|
|
547
546
|
return solautoActions;
|
@@ -701,6 +700,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
701
700
|
client.rebalance(
|
702
701
|
"A",
|
703
702
|
swapDetails,
|
703
|
+
jupQuote,
|
704
704
|
rebalanceType,
|
705
705
|
flashLoan,
|
706
706
|
targetLiqUtilizationRateBps
|
@@ -711,6 +711,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
711
711
|
client.rebalance(
|
712
712
|
"B",
|
713
713
|
swapDetails,
|
714
|
+
jupQuote,
|
714
715
|
rebalanceType,
|
715
716
|
flashLoan,
|
716
717
|
targetLiqUtilizationRateBps
|
@@ -725,6 +726,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
725
726
|
client.rebalance(
|
726
727
|
"A",
|
727
728
|
swapDetails,
|
729
|
+
jupQuote,
|
728
730
|
rebalanceType,
|
729
731
|
undefined,
|
730
732
|
targetLiqUtilizationRateBps
|
@@ -733,6 +735,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
733
735
|
client.rebalance(
|
734
736
|
"B",
|
735
737
|
swapDetails,
|
738
|
+
jupQuote,
|
736
739
|
rebalanceType,
|
737
740
|
undefined,
|
738
741
|
targetLiqUtilizationRateBps
|
package/src/types/accounts.ts
CHANGED
@@ -20,7 +20,7 @@ import {
|
|
20
20
|
toBaseUnit,
|
21
21
|
toBps,
|
22
22
|
} from "./numberUtils";
|
23
|
-
import { MARGINFI_ACCOUNTS } from "../constants/marginfiAccounts";
|
23
|
+
import { DEFAULT_MARGINFI_GROUP, MARGINFI_ACCOUNTS } from "../constants/marginfiAccounts";
|
24
24
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
25
25
|
import { PositionState, PositionTokenUsage } from "../generated";
|
26
26
|
import { USD_DECIMALS } from "../constants/generalAccounts";
|
@@ -333,6 +333,11 @@ export async function getMarginfiAccountPositionState(
|
|
333
333
|
return undefined;
|
334
334
|
}
|
335
335
|
|
336
|
+
if (!toWeb3JsPublicKey(supplyBank.group).equals(new PublicKey(DEFAULT_MARGINFI_GROUP))) {
|
337
|
+
// Temporarily disabled for now
|
338
|
+
return undefined;
|
339
|
+
}
|
340
|
+
|
336
341
|
if (!supplyUsage) {
|
337
342
|
supplyUsage = await getTokenUsage(
|
338
343
|
umi,
|
@@ -27,7 +27,6 @@ import {
|
|
27
27
|
toBaseUnit,
|
28
28
|
} from "../numberUtils";
|
29
29
|
import { USD_DECIMALS } from "../../constants/generalAccounts";
|
30
|
-
import { DEFAULT_LIMIT_GAP_BPS } from "../../constants/solautoConstants";
|
31
30
|
|
32
31
|
function getAdditionalAmountToDcaIn(dca: DCASettings): number {
|
33
32
|
if (dca.dcaInBaseUnit === BigInt(0)) {
|
@@ -173,8 +172,7 @@ export function getRebalanceValues(
|
|
173
172
|
currentUnixTime: number,
|
174
173
|
supplyPrice: number,
|
175
174
|
debtPrice: number,
|
176
|
-
targetLiqUtilizationRateBps?: number
|
177
|
-
limitGapBps?: number
|
175
|
+
targetLiqUtilizationRateBps?: number
|
178
176
|
): RebalanceValues {
|
179
177
|
const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(
|
180
178
|
state,
|
@@ -186,7 +184,7 @@ export function getRebalanceValues(
|
|
186
184
|
|
187
185
|
const amountUsdToDcaIn =
|
188
186
|
fromBaseUnit(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
|
189
|
-
debtPrice;
|
187
|
+
(dca?.tokenType === TokenType.Debt ? debtPrice : supplyPrice);
|
190
188
|
|
191
189
|
const increasingLeverage =
|
192
190
|
amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps;
|
@@ -214,25 +212,6 @@ export function getRebalanceValues(
|
|
214
212
|
adjustmentFeeBps
|
215
213
|
);
|
216
214
|
|
217
|
-
const input = increasingLeverage ? state.debt : state.supply;
|
218
|
-
const inputMarketPrice = increasingLeverage ? debtPrice : supplyPrice;
|
219
|
-
|
220
|
-
const limitGap = limitGapBps
|
221
|
-
? fromBps(limitGapBps)
|
222
|
-
: fromBps(DEFAULT_LIMIT_GAP_BPS);
|
223
|
-
|
224
|
-
if (
|
225
|
-
debtAdjustmentUsd > 0 &&
|
226
|
-
toBaseUnit(debtAdjustmentUsd / inputMarketPrice, input.decimals) >
|
227
|
-
input.amountCanBeUsed.baseUnit
|
228
|
-
) {
|
229
|
-
const maxUsageUsd =
|
230
|
-
fromBaseUnit(input.amountCanBeUsed.baseUnit, input.decimals) *
|
231
|
-
inputMarketPrice *
|
232
|
-
limitGap;
|
233
|
-
debtAdjustmentUsd = maxUsageUsd - maxUsageUsd * limitGap;
|
234
|
-
}
|
235
|
-
|
236
215
|
const maxRepayTo = maxRepayToBps(state.maxLtvBps, state.liqThresholdBps);
|
237
216
|
return {
|
238
217
|
increasingLeverage,
|
@@ -253,7 +232,7 @@ export interface FlashLoanDetails {
|
|
253
232
|
export function getFlashLoanDetails(
|
254
233
|
client: SolautoClient,
|
255
234
|
values: RebalanceValues,
|
256
|
-
jupQuote: QuoteResponse
|
235
|
+
jupQuote: QuoteResponse
|
257
236
|
): FlashLoanDetails | undefined {
|
258
237
|
let supplyUsd =
|
259
238
|
fromBaseUnit(
|