@haven-fi/solauto-sdk 1.0.110 → 1.0.112
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +0 -2
- package/dist/generated/instructions/marginfiOpenPosition.d.ts +0 -1
- package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiOpenPosition.js +15 -20
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +1 -1
- package/dist/utils/jupiterUtils.js +1 -1
- package/dist/utils/numberUtils.d.ts +1 -2
- package/dist/utils/numberUtils.d.ts.map +1 -1
- package/dist/utils/numberUtils.js +2 -3
- package/dist/utils/solauto/rebalanceUtils.d.ts +2 -2
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +2 -2
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +0 -1
- package/src/generated/instructions/marginfiOpenPosition.ts +15 -21
- package/src/transactions/transactionUtils.ts +0 -3
- package/src/utils/jupiterUtils.ts +1 -1
- package/src/utils/numberUtils.ts +2 -2
- package/src/utils/solauto/rebalanceUtils.ts +1 -2
- package/tests/unit/rebalanceCalculations.ts +1 -2
@@ -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,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc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5B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAU/B,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
@@ -12,7 +12,6 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
12
12
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
13
13
|
const marginfiUtils_1 = require("../utils/marginfiUtils");
|
14
14
|
const numberUtils_1 = require("../utils/numberUtils");
|
15
|
-
const constants_1 = require("../constants");
|
16
15
|
const utils_1 = require("../utils");
|
17
16
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
18
17
|
constructor() {
|
@@ -118,7 +117,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
118
117
|
return (0, generated_1.marginfiOpenPosition)(this.umi, {
|
119
118
|
signer: this.signer,
|
120
119
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
121
|
-
solautoManager: (0, umi_1.publicKey)(constants_1.SOLAUTO_MANAGER),
|
122
120
|
solautoFeesWallet: (0, umi_1.publicKey)(this.solautoFeesWallet),
|
123
121
|
solautoFeesSupplyTa: (0, umi_1.publicKey)(this.solautoFeesSupplyTa),
|
124
122
|
signerReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
|
@@ -15,7 +15,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
15
15
|
tokenProgram?: PublicKey | Pda;
|
16
16
|
ataProgram?: PublicKey | Pda;
|
17
17
|
rent?: PublicKey | Pda;
|
18
|
-
solautoManager: PublicKey | Pda;
|
19
18
|
solautoFeesWallet: PublicKey | Pda;
|
20
19
|
solautoFeesSupplyTa: PublicKey | Pda;
|
21
20
|
signerReferralState: PublicKey | Pda;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiOpenPosition.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiOpenPosition.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEvB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,uCAAuC,GAAG;IACpD,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,UAAU,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC7B,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACvB,
|
1
|
+
{"version":3,"file":"marginfiOpenPosition.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiOpenPosition.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEvB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,uCAAuC,GAAG;IACpD,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,UAAU,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC7B,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACvB,iBAAiB,EAAE,SAAS,GAAG,GAAG,CAAC;IACnC,mBAAmB,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,mBAAmB,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,eAAe,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,kBAAkB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,eAAe,EAAE,SAAS,GAAG,GAAG,GAAG,MAAM,CAAC;IAC1C,UAAU,EAAE,SAAS,GAAG,GAAG,CAAC;IAC5B,UAAU,EAAE,SAAS,GAAG,GAAG,CAAC;IAC5B,gBAAgB,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,QAAQ,EAAE,SAAS,GAAG,GAAG,CAAC;IAC1B,QAAQ,EAAE,SAAS,GAAG,GAAG,CAAC;IAC1B,cAAc,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;CAChC,CAAC;AAGF,MAAM,MAAM,mCAAmC,GAAG;IAChD,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,kBAAkB,CAAC;IACjC,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,YAAY,EAAE,sBAAsB,CAAC;IACrC,sBAAsB,EAAE,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CAC3D,CAAC;AAEF,wBAAgB,gDAAgD,IAAI,UAAU,CAC5E,uCAAuC,EACvC,mCAAmC,CACpC,CAmBA;AAGD,MAAM,MAAM,mCAAmC,GAC7C,uCAAuC,CAAC;AAG1C,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,KAAK,EAAE,uCAAuC,GAC5C,mCAAmC,GACpC,kBAAkB,CAsKpB"}
|
@@ -52,83 +52,78 @@ function marginfiOpenPosition(context, input) {
|
|
52
52
|
value: input.ataProgram ?? null,
|
53
53
|
},
|
54
54
|
rent: { index: 5, isWritable: false, value: input.rent ?? null },
|
55
|
-
solautoManager: {
|
56
|
-
index: 6,
|
57
|
-
isWritable: true,
|
58
|
-
value: input.solautoManager ?? null,
|
59
|
-
},
|
60
55
|
solautoFeesWallet: {
|
61
|
-
index:
|
56
|
+
index: 6,
|
62
57
|
isWritable: false,
|
63
58
|
value: input.solautoFeesWallet ?? null,
|
64
59
|
},
|
65
60
|
solautoFeesSupplyTa: {
|
66
|
-
index:
|
61
|
+
index: 7,
|
67
62
|
isWritable: true,
|
68
63
|
value: input.solautoFeesSupplyTa ?? null,
|
69
64
|
},
|
70
65
|
signerReferralState: {
|
71
|
-
index:
|
66
|
+
index: 8,
|
72
67
|
isWritable: false,
|
73
68
|
value: input.signerReferralState ?? null,
|
74
69
|
},
|
75
70
|
referredByState: {
|
76
|
-
index:
|
71
|
+
index: 9,
|
77
72
|
isWritable: false,
|
78
73
|
value: input.referredByState ?? null,
|
79
74
|
},
|
80
75
|
referredBySupplyTa: {
|
81
|
-
index:
|
76
|
+
index: 10,
|
82
77
|
isWritable: true,
|
83
78
|
value: input.referredBySupplyTa ?? null,
|
84
79
|
},
|
85
80
|
solautoPosition: {
|
86
|
-
index:
|
81
|
+
index: 11,
|
87
82
|
isWritable: true,
|
88
83
|
value: input.solautoPosition ?? null,
|
89
84
|
},
|
90
85
|
marginfiGroup: {
|
91
|
-
index:
|
86
|
+
index: 12,
|
92
87
|
isWritable: false,
|
93
88
|
value: input.marginfiGroup ?? null,
|
94
89
|
},
|
95
90
|
marginfiAccount: {
|
96
|
-
index:
|
91
|
+
index: 13,
|
97
92
|
isWritable: true,
|
98
93
|
value: input.marginfiAccount ?? null,
|
99
94
|
},
|
100
95
|
supplyMint: {
|
101
|
-
index:
|
96
|
+
index: 14,
|
102
97
|
isWritable: false,
|
103
98
|
value: input.supplyMint ?? null,
|
104
99
|
},
|
105
100
|
supplyBank: {
|
106
|
-
index:
|
101
|
+
index: 15,
|
107
102
|
isWritable: false,
|
108
103
|
value: input.supplyBank ?? null,
|
109
104
|
},
|
110
105
|
positionSupplyTa: {
|
111
|
-
index:
|
106
|
+
index: 16,
|
112
107
|
isWritable: true,
|
113
108
|
value: input.positionSupplyTa ?? null,
|
114
109
|
},
|
115
110
|
debtMint: {
|
116
|
-
index:
|
111
|
+
index: 17,
|
117
112
|
isWritable: false,
|
118
113
|
value: input.debtMint ?? null,
|
119
114
|
},
|
120
115
|
debtBank: {
|
121
|
-
index:
|
116
|
+
index: 18,
|
122
117
|
isWritable: false,
|
123
118
|
value: input.debtBank ?? null,
|
124
119
|
},
|
125
120
|
positionDebtTa: {
|
126
|
-
index:
|
121
|
+
index: 19,
|
127
122
|
isWritable: true,
|
128
123
|
value: input.positionDebtTa ?? null,
|
129
124
|
},
|
130
125
|
signerDebtTa: {
|
131
|
-
index:
|
126
|
+
index: 20,
|
132
127
|
isWritable: true,
|
133
128
|
value: input.signerDebtTa ?? null,
|
134
129
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,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,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC;IACT,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACG,SAAS,CACZ,CAwHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD"}
|
@@ -327,7 +327,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
327
327
|
client.log("Not eligible for a rebalance");
|
328
328
|
return undefined;
|
329
329
|
}
|
330
|
-
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(),
|
330
|
+
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), constants_1.PRICES[client.supplyMint.toString()].price, constants_1.PRICES[client.debtMint.toString()].price, targetLiqUtilizationRateBps);
|
331
331
|
client.log("Rebalance values: ", values);
|
332
332
|
const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
333
333
|
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
@@ -32,7 +32,7 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
32
32
|
? "ExactIn"
|
33
33
|
: undefined,
|
34
34
|
slippageBps: 10,
|
35
|
-
maxAccounts: 60,
|
35
|
+
maxAccounts: !swapDetails.exactOut ? 60 : undefined,
|
36
36
|
}), 3);
|
37
37
|
const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1) *
|
38
38
|
(1 + (swapDetails.slippageBpsIncFactor ?? 0)));
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { FeeType } from "../generated";
|
2
1
|
export declare function getLiqUtilzationRateBps(supplyUsd: number, debtUsd: number, liqThresholdBps: number): number;
|
3
2
|
export declare function toBaseUnit(value: number, decimals: number): bigint;
|
4
3
|
export declare function fromBaseUnit(value: bigint, decimals: number): number;
|
@@ -7,7 +6,7 @@ export declare function toBps(value: number): number;
|
|
7
6
|
export declare function bytesToI80F48(bytes: number[]): number;
|
8
7
|
export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
|
9
8
|
export declare function getDebtAdjustmentUsd(liqThresholdBps: number, supplyUsd: number, debtUsd: number, targetLiqUtilizationRateBps: number, adjustmentFeeBps?: number): number;
|
10
|
-
export declare function getSolautoFeesBps(isReferred: boolean,
|
9
|
+
export declare function getSolautoFeesBps(isReferred: boolean, targetLiqUtilizationRateBps: number | undefined, positionNetWorthUsd: number): {
|
11
10
|
solauto: number;
|
12
11
|
referrer: number;
|
13
12
|
total: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAGA,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,MAAM,CAMR;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAejE;AAED,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,2BAA2B,EAAE,MAAM,EACnC,gBAAgB,CAAC,EAAE,MAAM,UAW1B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,mBAAmB,EAAE,MAAM,GAC1B;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAgCA;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAER;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKzE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE"}
|
@@ -14,7 +14,6 @@ exports.maxRepayFromBps = maxRepayFromBps;
|
|
14
14
|
exports.maxRepayToBps = maxRepayToBps;
|
15
15
|
exports.maxBoostToBps = maxBoostToBps;
|
16
16
|
const constants_1 = require("../constants");
|
17
|
-
const generated_1 = require("../generated");
|
18
17
|
function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
|
19
18
|
if (supplyUsd === 0) {
|
20
19
|
return 0;
|
@@ -67,14 +66,14 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
|
|
67
66
|
(1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
|
68
67
|
return debtAdjustmentUsd;
|
69
68
|
}
|
70
|
-
function getSolautoFeesBps(isReferred,
|
69
|
+
function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetWorthUsd) {
|
71
70
|
const minSize = 10000; // Minimum position size
|
72
71
|
const maxSize = 500000; // Maximum position size
|
73
72
|
const maxFeeBps = 500; // Fee in basis points for minSize (5%)
|
74
73
|
const minFeeBps = 50; // Fee in basis points for maxSize (0.5%)
|
75
74
|
const k = 0.55;
|
76
75
|
let feeBps = 0;
|
77
|
-
if (
|
76
|
+
if (targetLiqUtilizationRateBps !== undefined) {
|
78
77
|
feeBps = minFeeBps;
|
79
78
|
}
|
80
79
|
else if (positionNetWorthUsd <= minSize) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { SolautoClient } from "../../clients/solautoClient";
|
3
|
-
import { DCASettings,
|
3
|
+
import { DCASettings, PositionState, SolautoSettingsParameters } from "../../generated";
|
4
4
|
import { QuoteResponse } from "@jup-ag/api";
|
5
5
|
import { JupSwapDetails } from "../jupiterUtils";
|
6
6
|
export interface RebalanceValues {
|
@@ -9,7 +9,7 @@ export interface RebalanceValues {
|
|
9
9
|
amountToDcaIn: number;
|
10
10
|
amountUsdToDcaIn: number;
|
11
11
|
}
|
12
|
-
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined,
|
12
|
+
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number, limitGapBps?: number): RebalanceValues;
|
13
13
|
export interface FlashLoanDetails {
|
14
14
|
baseUnitAmount: bigint;
|
15
15
|
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,EA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,cAAc,CAkChB"}
|
@@ -79,7 +79,7 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
|
|
79
79
|
};
|
80
80
|
}
|
81
81
|
}
|
82
|
-
function getRebalanceValues(state, settings, dca,
|
82
|
+
function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps, limitGapBps) {
|
83
83
|
if (state === undefined ||
|
84
84
|
state.lastUpdated <
|
85
85
|
BigInt(Math.round((0, generalUtils_2.currentUnixSeconds)() - solautoConstants_1.MIN_POSITION_STATE_FRESHNESS_SECS))) {
|
@@ -91,7 +91,7 @@ function getRebalanceValues(state, settings, dca, feeType, currentUnixTime, supp
|
|
91
91
|
const increasingLeverage = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps;
|
92
92
|
let adjustmentFeeBps = 0;
|
93
93
|
if (increasingLeverage) {
|
94
|
-
adjustmentFeeBps = (0, numberUtils_1.getSolautoFeesBps)(false,
|
94
|
+
adjustmentFeeBps = (0, numberUtils_1.getSolautoFeesBps)(false, targetLiqUtilizationRateBps, (0, numberUtils_1.fromBaseUnit)(state.netWorth.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS)).total;
|
95
95
|
}
|
96
96
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(state.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) +
|
97
97
|
amountUsdToDcaIn;
|
package/package.json
CHANGED
@@ -241,7 +241,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
241
241
|
return marginfiOpenPosition(this.umi, {
|
242
242
|
signer: this.signer,
|
243
243
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
244
|
-
solautoManager: publicKey(SOLAUTO_MANAGER),
|
245
244
|
solautoFeesWallet: publicKey(this.solautoFeesWallet),
|
246
245
|
solautoFeesSupplyTa: publicKey(this.solautoFeesSupplyTa),
|
247
246
|
signerReferralState: publicKey(this.referralStateManager.referralState),
|
@@ -44,7 +44,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
44
44
|
tokenProgram?: PublicKey | Pda;
|
45
45
|
ataProgram?: PublicKey | Pda;
|
46
46
|
rent?: PublicKey | Pda;
|
47
|
-
solautoManager: PublicKey | Pda;
|
48
47
|
solautoFeesWallet: PublicKey | Pda;
|
49
48
|
solautoFeesSupplyTa: PublicKey | Pda;
|
50
49
|
signerReferralState: PublicKey | Pda;
|
@@ -142,83 +141,78 @@ export function marginfiOpenPosition(
|
|
142
141
|
value: input.ataProgram ?? null,
|
143
142
|
},
|
144
143
|
rent: { index: 5, isWritable: false as boolean, value: input.rent ?? null },
|
145
|
-
solautoManager: {
|
146
|
-
index: 6,
|
147
|
-
isWritable: true as boolean,
|
148
|
-
value: input.solautoManager ?? null,
|
149
|
-
},
|
150
144
|
solautoFeesWallet: {
|
151
|
-
index:
|
145
|
+
index: 6,
|
152
146
|
isWritable: false as boolean,
|
153
147
|
value: input.solautoFeesWallet ?? null,
|
154
148
|
},
|
155
149
|
solautoFeesSupplyTa: {
|
156
|
-
index:
|
150
|
+
index: 7,
|
157
151
|
isWritable: true as boolean,
|
158
152
|
value: input.solautoFeesSupplyTa ?? null,
|
159
153
|
},
|
160
154
|
signerReferralState: {
|
161
|
-
index:
|
155
|
+
index: 8,
|
162
156
|
isWritable: false as boolean,
|
163
157
|
value: input.signerReferralState ?? null,
|
164
158
|
},
|
165
159
|
referredByState: {
|
166
|
-
index:
|
160
|
+
index: 9,
|
167
161
|
isWritable: false as boolean,
|
168
162
|
value: input.referredByState ?? null,
|
169
163
|
},
|
170
164
|
referredBySupplyTa: {
|
171
|
-
index:
|
165
|
+
index: 10,
|
172
166
|
isWritable: true as boolean,
|
173
167
|
value: input.referredBySupplyTa ?? null,
|
174
168
|
},
|
175
169
|
solautoPosition: {
|
176
|
-
index:
|
170
|
+
index: 11,
|
177
171
|
isWritable: true as boolean,
|
178
172
|
value: input.solautoPosition ?? null,
|
179
173
|
},
|
180
174
|
marginfiGroup: {
|
181
|
-
index:
|
175
|
+
index: 12,
|
182
176
|
isWritable: false as boolean,
|
183
177
|
value: input.marginfiGroup ?? null,
|
184
178
|
},
|
185
179
|
marginfiAccount: {
|
186
|
-
index:
|
180
|
+
index: 13,
|
187
181
|
isWritable: true as boolean,
|
188
182
|
value: input.marginfiAccount ?? null,
|
189
183
|
},
|
190
184
|
supplyMint: {
|
191
|
-
index:
|
185
|
+
index: 14,
|
192
186
|
isWritable: false as boolean,
|
193
187
|
value: input.supplyMint ?? null,
|
194
188
|
},
|
195
189
|
supplyBank: {
|
196
|
-
index:
|
190
|
+
index: 15,
|
197
191
|
isWritable: false as boolean,
|
198
192
|
value: input.supplyBank ?? null,
|
199
193
|
},
|
200
194
|
positionSupplyTa: {
|
201
|
-
index:
|
195
|
+
index: 16,
|
202
196
|
isWritable: true as boolean,
|
203
197
|
value: input.positionSupplyTa ?? null,
|
204
198
|
},
|
205
199
|
debtMint: {
|
206
|
-
index:
|
200
|
+
index: 17,
|
207
201
|
isWritable: false as boolean,
|
208
202
|
value: input.debtMint ?? null,
|
209
203
|
},
|
210
204
|
debtBank: {
|
211
|
-
index:
|
205
|
+
index: 18,
|
212
206
|
isWritable: false as boolean,
|
213
207
|
value: input.debtBank ?? null,
|
214
208
|
},
|
215
209
|
positionDebtTa: {
|
216
|
-
index:
|
210
|
+
index: 19,
|
217
211
|
isWritable: true as boolean,
|
218
212
|
value: input.positionDebtTa ?? null,
|
219
213
|
},
|
220
214
|
signerDebtTa: {
|
221
|
-
index:
|
215
|
+
index: 20,
|
222
216
|
isWritable: true as boolean,
|
223
217
|
value: input.signerDebtTa ?? null,
|
224
218
|
},
|
@@ -10,10 +10,8 @@ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js";
|
|
10
10
|
import {
|
11
11
|
ACCOUNT_SIZE as TOKEN_ACCOUNT_SIZE,
|
12
12
|
NATIVE_MINT,
|
13
|
-
Account as SplTokenAccount,
|
14
13
|
} from "@solana/spl-token";
|
15
14
|
import {
|
16
|
-
FeeType,
|
17
15
|
LendingPlatform,
|
18
16
|
ReferralState,
|
19
17
|
SOLAUTO_PROGRAM_ID,
|
@@ -578,7 +576,6 @@ export async function buildSolautoRebalanceTransaction(
|
|
578
576
|
client.solautoPositionState!,
|
579
577
|
client.solautoPositionSettings(),
|
580
578
|
client.solautoPositionActiveDca(),
|
581
|
-
client.solautoPositionData?.feeType ?? FeeType.Small,
|
582
579
|
currentUnixSeconds(),
|
583
580
|
PRICES[client.supplyMint.toString()].price,
|
584
581
|
PRICES[client.debtMint.toString()].price,
|
package/src/utils/numberUtils.ts
CHANGED
@@ -89,7 +89,7 @@ export function getDebtAdjustmentUsd(
|
|
89
89
|
|
90
90
|
export function getSolautoFeesBps(
|
91
91
|
isReferred: boolean,
|
92
|
-
|
92
|
+
targetLiqUtilizationRateBps: number | undefined,
|
93
93
|
positionNetWorthUsd: number
|
94
94
|
): {
|
95
95
|
solauto: number;
|
@@ -104,7 +104,7 @@ export function getSolautoFeesBps(
|
|
104
104
|
|
105
105
|
let feeBps: number = 0;
|
106
106
|
|
107
|
-
if (
|
107
|
+
if (targetLiqUtilizationRateBps !== undefined) {
|
108
108
|
feeBps = minFeeBps;
|
109
109
|
} else if (positionNetWorthUsd <= minSize) {
|
110
110
|
feeBps = maxFeeBps;
|
@@ -171,7 +171,6 @@ export function getRebalanceValues(
|
|
171
171
|
state: PositionState,
|
172
172
|
settings: SolautoSettingsParameters | undefined,
|
173
173
|
dca: DCASettings | undefined,
|
174
|
-
feeType: FeeType,
|
175
174
|
currentUnixTime: number,
|
176
175
|
supplyPrice: number,
|
177
176
|
debtPrice: number,
|
@@ -206,7 +205,7 @@ export function getRebalanceValues(
|
|
206
205
|
if (increasingLeverage) {
|
207
206
|
adjustmentFeeBps = getSolautoFeesBps(
|
208
207
|
false,
|
209
|
-
|
208
|
+
targetLiqUtilizationRateBps,
|
210
209
|
fromBaseUnit(state.netWorth.baseAmountUsdValue, USD_DECIMALS)
|
211
210
|
).total;
|
212
211
|
}
|
@@ -49,7 +49,6 @@ function assertAccurateRebalance(
|
|
49
49
|
client.solautoPositionState!,
|
50
50
|
client.solautoPositionSettings(),
|
51
51
|
client.solautoPositionActiveDca(),
|
52
|
-
client.solautoPositionData!.feeType,
|
53
52
|
currentUnixSeconds(),
|
54
53
|
PRICES[client.supplyMint.toString()].price,
|
55
54
|
PRICES[client.debtMint.toString()].price,
|
@@ -60,7 +59,7 @@ function assertAccurateRebalance(
|
|
60
59
|
if (increasingLeverage) {
|
61
60
|
adjustmentFeeBps = getSolautoFeesBps(
|
62
61
|
client.referredByState !== undefined,
|
63
|
-
|
62
|
+
targetLiqUtilizationRateBps,
|
64
63
|
fromBaseUnit(
|
65
64
|
client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
|
66
65
|
USD_DECIMALS
|