@haven-fi/solauto-sdk 1.0.721 → 1.0.723
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/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +1 -1
- package/dist/services/rebalance/rebalanceValues.d.ts +1 -1
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceValues.js +5 -5
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +5 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +1 -1
- package/dist/utils/jitoUtils.d.ts +1 -1
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +6 -5
- package/local/logPositions.ts +8 -7
- package/local/txSandbox.ts +16 -12
- package/package.json +1 -1
- package/src/services/rebalance/rebalanceTxBuilder.ts +2 -2
- package/src/services/rebalance/rebalanceValues.ts +9 -9
- package/src/services/transactions/transactionUtils.ts +7 -3
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +1 -1
- package/src/utils/jitoUtils.ts +19 -16
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAgCrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,wBAAwB,CAAC;IAVnC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,wBAAwB,CAAC,EAAE,MAAM,YAAA;IAG3C,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IAsFpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
|
@@ -26,7 +26,7 @@ class RebalanceTxBuilder {
|
|
26
26
|
this.client.pos.eligibleForRebalance(this.bpsDistanceFromRebalance)));
|
27
27
|
}
|
28
28
|
getRebalanceValues() {
|
29
|
-
return (0, rebalanceValues_1.getRebalanceValues)(this.client.pos, this.priceType, this.targetLiqUtilizationRateBps, solautoFees_1.SolautoFeesBps.create(this.client.isReferred, this.targetLiqUtilizationRateBps, this.client.pos.netWorthUsd(this.priceType)), this.flRequirements?.flFeeBps ?? 0);
|
29
|
+
return (0, rebalanceValues_1.getRebalanceValues)(this.client.pos, this.priceType, this.targetLiqUtilizationRateBps, solautoFees_1.SolautoFeesBps.create(this.client.isReferred, this.targetLiqUtilizationRateBps, this.client.pos.netWorthUsd(this.priceType)), this.flRequirements?.flFeeBps ?? 0, this.bpsDistanceFromRebalance);
|
30
30
|
}
|
31
31
|
getFlLiquiditySource(supplyLiquidityAvailable, debtLiquidityAvailable) {
|
32
32
|
const debtAdjustmentUsd = Math.abs(this.values.debtAdjustmentUsd);
|
@@ -29,6 +29,6 @@ export interface RebalanceValues extends DebtAdjustment {
|
|
29
29
|
tokenBalanceChange?: TokenBalanceChange;
|
30
30
|
repayingCloseToMaxLtv: boolean;
|
31
31
|
}
|
32
|
-
export declare function getRebalanceValues(solautoPosition: SolautoPositionEx, priceType: PriceType, targetLiqUtilizationRateBps?: number, solautoFeeBps?: SolautoFeesBps, flFeeBps?: number): RebalanceValues | undefined;
|
32
|
+
export declare function getRebalanceValues(solautoPosition: SolautoPositionEx, priceType: PriceType, targetLiqUtilizationRateBps?: number, solautoFeeBps?: SolautoFeesBps, flFeeBps?: number, bpsDistanceFromRebalance?: number): RebalanceValues | undefined;
|
33
33
|
export {};
|
34
34
|
//# sourceMappingURL=rebalanceValues.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceValues.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceValues.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"rebalanceValues.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceValues.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAMzB,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;AA6ED,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,EACjB,wBAAwB,CAAC,EAAE,MAAM,GAChC,eAAe,GAAG,SAAS,CA+C7B"}
|
@@ -55,15 +55,15 @@ function getTokenBalanceChange() {
|
|
55
55
|
// TODO: DCA, limit orders, take profit, stop loss, etc.
|
56
56
|
return undefined;
|
57
57
|
}
|
58
|
-
function getTargetLiqUtilizationRateBps(solautoPosition, priceType, targetLiqUtilizationRateBps, tokenBalanceChange) {
|
58
|
+
function getTargetLiqUtilizationRateBps(solautoPosition, priceType, targetLiqUtilizationRateBps, tokenBalanceChange, bpsDistanceFromRebalance) {
|
59
59
|
if (targetLiqUtilizationRateBps !== undefined) {
|
60
60
|
return targetLiqUtilizationRateBps;
|
61
61
|
}
|
62
|
-
if (solautoPosition.liqUtilizationRateBps(generated_1.PriceType.Realtime) >=
|
62
|
+
if (solautoPosition.liqUtilizationRateBps(generated_1.PriceType.Realtime) + (bpsDistanceFromRebalance ?? 0) >=
|
63
63
|
solautoPosition.repayFromBps) {
|
64
64
|
return solautoPosition.settings.repayToBps;
|
65
65
|
}
|
66
|
-
else if (solautoPosition.liqUtilizationRateBps(priceType) <=
|
66
|
+
else if (solautoPosition.liqUtilizationRateBps(priceType) - (bpsDistanceFromRebalance ?? 0) <=
|
67
67
|
solautoPosition.boostFromBps) {
|
68
68
|
return solautoPosition.settings.boostToBps;
|
69
69
|
}
|
@@ -101,9 +101,9 @@ function getRebalanceDirection(solautoPosition, targetLtvBps, priceType) {
|
|
101
101
|
? generated_1.RebalanceDirection.Boost
|
102
102
|
: generated_1.RebalanceDirection.Repay;
|
103
103
|
}
|
104
|
-
function getRebalanceValues(solautoPosition, priceType, targetLiqUtilizationRateBps, solautoFeeBps, flFeeBps) {
|
104
|
+
function getRebalanceValues(solautoPosition, priceType, targetLiqUtilizationRateBps, solautoFeeBps, flFeeBps, bpsDistanceFromRebalance) {
|
105
105
|
const tokenBalanceChange = getTokenBalanceChange();
|
106
|
-
const targetRate = getTargetLiqUtilizationRateBps(solautoPosition, priceType, targetLiqUtilizationRateBps, tokenBalanceChange);
|
106
|
+
const targetRate = getTargetLiqUtilizationRateBps(solautoPosition, priceType, targetLiqUtilizationRateBps, tokenBalanceChange, bpsDistanceFromRebalance);
|
107
107
|
if (targetRate === undefined) {
|
108
108
|
return undefined;
|
109
109
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4BjE,OAAO,EACL,qBAAqB,EAErB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAyLrB,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAyF7B;AA+LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO,EAC9B,kBAAkB,CAAC,EAAE,kBAAkB;;;;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4BjE,OAAO,EACL,qBAAqB,EAErB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAyLrB,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAyF7B;AA+LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO,EAC9B,kBAAkB,CAAC,EAAE,kBAAkB;;;;EA2HxC;AAED,wBAAgB,cAAc,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,8JAKrE"}
|
@@ -349,7 +349,11 @@ function getErrorInfo(umi, txs, error, simulationSuccessful, priorityFeeSetting)
|
|
349
349
|
let errCode;
|
350
350
|
let errName;
|
351
351
|
// sub ixs to account for computeUnitLimit and computeUnitPrice that get added
|
352
|
-
const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx],
|
352
|
+
const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx], simulationSuccessful && usePriorityFee(priorityFeeSetting)
|
353
|
+
? 1
|
354
|
+
: undefined, 1).getInstructions().length -
|
355
|
+
txs[txIdx].getInstructions().length -
|
356
|
+
(txs.length > 1 && txIdx === 0 ? 1 : 0); // Account for jito tip IX
|
353
357
|
try {
|
354
358
|
if (error instanceof types_1.BundleSimulationError) {
|
355
359
|
errTxIdx = error.details.transactionIdx;
|
@@ -78,7 +78,7 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
78
78
|
}
|
79
79
|
get supplyUsdWithdrawable() {
|
80
80
|
const deposits = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityUsedBaseUnit)(this.supplyBank, true), this.supplyMintInfo.decimals);
|
81
|
-
const borrows = (0, utils_1.fromBaseUnit)((0, utils_1.
|
81
|
+
const borrows = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityUsedBaseUnit)(this.supplyBank, false), this.supplyMintInfo.decimals);
|
82
82
|
return Math.min((deposits - borrows), this.totalSupply) * this.supplyPrice();
|
83
83
|
}
|
84
84
|
async refreshPositionState(priceType) {
|
@@ -7,5 +7,5 @@ export declare function getAdditionalSigners(message: TransactionMessage): {
|
|
7
7
|
publicKey: string;
|
8
8
|
isWritable: boolean;
|
9
9
|
}[];
|
10
|
-
export declare function sendJitoBundledTransactions(umi: Umi, connection: Connection, userSigner: Signer, otherSigners: Signer[],
|
10
|
+
export declare function sendJitoBundledTransactions(umi: Umi, connection: Connection, userSigner: Signer, otherSigners: Signer[], transactions: TransactionBuilder[], txType?: TransactionRunType, priorityFeeSetting?: PriorityFeeSetting, onAwaitingSign?: () => void, abortController?: AbortController): Promise<string[] | undefined>;
|
11
11
|
//# sourceMappingURL=jitoUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAgBlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AAiGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB/D;AAwHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAgBlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AAiGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB/D;AAwHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,YAAY,EAAE,kBAAkB,EAAE,EAClC,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,EAC3B,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAwG/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -181,7 +181,8 @@ async function sendJitoBundle(umi, transactions) {
|
|
181
181
|
(0, generalUtils_1.consoleLog)("Bundle ID:", bundleId);
|
182
182
|
return bundleId ? await pollBundleStatus(umi, bundleId) : [];
|
183
183
|
}
|
184
|
-
async function sendJitoBundledTransactions(umi, connection, userSigner, otherSigners,
|
184
|
+
async function sendJitoBundledTransactions(umi, connection, userSigner, otherSigners, transactions, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, onAwaitingSign, abortController) {
|
185
|
+
const txs = [...transactions];
|
185
186
|
if (txs.length === 1) {
|
186
187
|
const resp = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(umi, connection, txs[0], txType, priorityFeeSetting, onAwaitingSign, abortController);
|
187
188
|
return resp ? [bs58_1.default.encode(resp)] : undefined;
|
@@ -191,9 +192,6 @@ async function sendJitoBundledTransactions(umi, connection, userSigner, otherSig
|
|
191
192
|
(0, generalUtils_1.consoleLog)(txs.map((tx) => tx.getInstructions().map((x) => x.programId.toString())));
|
192
193
|
(0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
|
193
194
|
txs[0] = txs[0].prepend(getTipInstruction(userSigner, 150000));
|
194
|
-
const feeEstimates = (0, services_1.usePriorityFee)(priorityFeeSetting)
|
195
|
-
? await Promise.all(txs.map(async (x) => (await (0, solanaUtils_1.getComputeUnitPriceEstimate)(umi, x, priorityFeeSetting, true)) ?? 1000000))
|
196
|
-
: undefined;
|
197
195
|
const latestBlockhash = (await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })).blockhash;
|
198
196
|
if (abortController?.signal.aborted) {
|
199
197
|
return;
|
@@ -201,9 +199,12 @@ async function sendJitoBundledTransactions(umi, connection, userSigner, otherSig
|
|
201
199
|
let builtTxs = [];
|
202
200
|
let simulationResults;
|
203
201
|
if (txType !== "skip-simulation") {
|
204
|
-
builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, userSigner, otherSigners, txs, false,
|
202
|
+
builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, userSigner, otherSigners, txs, false, undefined, Array(txs.length).map(_ => 1400000));
|
205
203
|
simulationResults = await simulateJitoBundle(umi, builtTxs);
|
206
204
|
}
|
205
|
+
const feeEstimates = (0, services_1.usePriorityFee)(priorityFeeSetting)
|
206
|
+
? await Promise.all(txs.map(async (x) => (await (0, solanaUtils_1.getComputeUnitPriceEstimate)(umi, x, priorityFeeSetting, true)) ?? 1000000))
|
207
|
+
: undefined;
|
207
208
|
if (abortController?.signal.aborted) {
|
208
209
|
return;
|
209
210
|
}
|
package/local/logPositions.ts
CHANGED
@@ -92,12 +92,10 @@ async function main(filterWhitelist: boolean, programEnv: ProgramEnv = "Prod") {
|
|
92
92
|
);
|
93
93
|
}
|
94
94
|
|
95
|
-
const positionsEx = (
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
)
|
100
|
-
).sort((a, b) => a.netWorthUsd() - b.netWorthUsd());
|
95
|
+
const positionsEx = await getPositionExBulk(
|
96
|
+
umi,
|
97
|
+
positions.map((x) => new PublicKey(x.publicKey!))
|
98
|
+
);
|
101
99
|
|
102
100
|
const tokensUsed = Array.from(
|
103
101
|
new Set(
|
@@ -114,7 +112,10 @@ async function main(filterWhitelist: boolean, programEnv: ProgramEnv = "Prod") {
|
|
114
112
|
let unhealthyPositions = 0;
|
115
113
|
let awaitingBoostPositions = 0;
|
116
114
|
|
117
|
-
|
115
|
+
const sortedPositions = positionsEx.sort(
|
116
|
+
(a, b) => a.netWorthUsd() - b.netWorthUsd()
|
117
|
+
);
|
118
|
+
for (const pos of sortedPositions) {
|
118
119
|
const actionToTake = pos.eligibleForRebalance(0);
|
119
120
|
|
120
121
|
const repayFrom = pos.settings!.repayToBps + pos.settings!.repayGap;
|
package/local/txSandbox.ts
CHANGED
@@ -23,7 +23,7 @@ import {
|
|
23
23
|
import { getSecretKey } from "./shared";
|
24
24
|
|
25
25
|
const payForTransaction = false;
|
26
|
-
const testProgram =
|
26
|
+
const testProgram = true;
|
27
27
|
const lpEnv: ProgramEnv = "Prod";
|
28
28
|
|
29
29
|
let [, umi] = getSolanaRpcConnection(
|
@@ -47,23 +47,27 @@ export async function main() {
|
|
47
47
|
});
|
48
48
|
|
49
49
|
await client.initializeExistingSolautoPosition({
|
50
|
-
positionId:
|
51
|
-
authority: new PublicKey("
|
50
|
+
positionId: 5,
|
51
|
+
authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
|
52
52
|
// lpUserAccount: new PublicKey(
|
53
53
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
54
54
|
// ),
|
55
55
|
});
|
56
56
|
|
57
|
-
|
57
|
+
await client.pos.refreshPositionState();
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
console.log(client.pos.supplyUsdWithdrawable);
|
60
|
+
|
61
|
+
// const transactionItems = [rebalance(client)];
|
62
|
+
|
63
|
+
// const txManager = new ClientTransactionsManager({
|
64
|
+
// txHandler: client,
|
65
|
+
// txRunType: payForTransaction ? "normal" : "only-simulate",
|
66
|
+
// priorityFeeSetting: PriorityFeeSetting.Default,
|
67
|
+
// retryConfig: { totalRetries: 2 },
|
68
|
+
// });
|
69
|
+
// const statuses = await txManager.send(transactionItems);
|
70
|
+
// consoleLog(statuses);
|
67
71
|
}
|
68
72
|
|
69
73
|
async function refreshAll() {
|
package/package.json
CHANGED
@@ -12,7 +12,6 @@ import {
|
|
12
12
|
consoleLog,
|
13
13
|
fromBaseUnit,
|
14
14
|
fromBps,
|
15
|
-
getLiqUtilzationRateBps,
|
16
15
|
getMaxLiqUtilizationRateBps,
|
17
16
|
getTokenAccount,
|
18
17
|
hasFirstRebalance,
|
@@ -77,7 +76,8 @@ export class RebalanceTxBuilder {
|
|
77
76
|
this.targetLiqUtilizationRateBps,
|
78
77
|
this.client.pos.netWorthUsd(this.priceType)
|
79
78
|
),
|
80
|
-
this.flRequirements?.flFeeBps ?? 0
|
79
|
+
this.flRequirements?.flFeeBps ?? 0,
|
80
|
+
this.bpsDistanceFromRebalance
|
81
81
|
);
|
82
82
|
}
|
83
83
|
|
@@ -1,6 +1,4 @@
|
|
1
1
|
import {
|
2
|
-
createSolautoProgram,
|
3
|
-
InvalidRebalanceConditionError,
|
4
2
|
PriceType,
|
5
3
|
RebalanceDirection,
|
6
4
|
TokenBalanceChange,
|
@@ -9,7 +7,6 @@ import {
|
|
9
7
|
import {
|
10
8
|
fromBps,
|
11
9
|
getLiqUtilzationRateBps,
|
12
|
-
maxRepayToBps,
|
13
10
|
toBps,
|
14
11
|
} from "../../utils";
|
15
12
|
import { SolautoPositionEx } from "../../solautoPosition";
|
@@ -126,20 +123,21 @@ function getTokenBalanceChange(): TokenBalanceChange | undefined {
|
|
126
123
|
function getTargetLiqUtilizationRateBps(
|
127
124
|
solautoPosition: SolautoPositionEx,
|
128
125
|
priceType: PriceType,
|
129
|
-
targetLiqUtilizationRateBps
|
130
|
-
tokenBalanceChange
|
126
|
+
targetLiqUtilizationRateBps?: number,
|
127
|
+
tokenBalanceChange?: TokenBalanceChange,
|
128
|
+
bpsDistanceFromRebalance?: number
|
131
129
|
): number | undefined {
|
132
130
|
if (targetLiqUtilizationRateBps !== undefined) {
|
133
131
|
return targetLiqUtilizationRateBps;
|
134
132
|
}
|
135
133
|
|
136
134
|
if (
|
137
|
-
solautoPosition.liqUtilizationRateBps(PriceType.Realtime) >=
|
135
|
+
solautoPosition.liqUtilizationRateBps(PriceType.Realtime) + (bpsDistanceFromRebalance ?? 0) >=
|
138
136
|
solautoPosition.repayFromBps
|
139
137
|
) {
|
140
138
|
return solautoPosition.settings!.repayToBps;
|
141
139
|
} else if (
|
142
|
-
solautoPosition.liqUtilizationRateBps(priceType) <=
|
140
|
+
solautoPosition.liqUtilizationRateBps(priceType) - (bpsDistanceFromRebalance ?? 0) <=
|
143
141
|
solautoPosition.boostFromBps
|
144
142
|
) {
|
145
143
|
return solautoPosition.settings!.boostToBps;
|
@@ -203,7 +201,8 @@ export function getRebalanceValues(
|
|
203
201
|
priceType: PriceType,
|
204
202
|
targetLiqUtilizationRateBps?: number,
|
205
203
|
solautoFeeBps?: SolautoFeesBps,
|
206
|
-
flFeeBps?: number
|
204
|
+
flFeeBps?: number,
|
205
|
+
bpsDistanceFromRebalance?: number
|
207
206
|
): RebalanceValues | undefined {
|
208
207
|
const tokenBalanceChange = getTokenBalanceChange();
|
209
208
|
|
@@ -211,7 +210,8 @@ export function getRebalanceValues(
|
|
211
210
|
solautoPosition,
|
212
211
|
priceType,
|
213
212
|
targetLiqUtilizationRateBps,
|
214
|
-
tokenBalanceChange
|
213
|
+
tokenBalanceChange,
|
214
|
+
bpsDistanceFromRebalance
|
215
215
|
);
|
216
216
|
if (targetRate === undefined) {
|
217
217
|
return undefined;
|
@@ -626,9 +626,13 @@ export function getErrorInfo(
|
|
626
626
|
addTxOptimizations(
|
627
627
|
umi,
|
628
628
|
txs[txIdx],
|
629
|
-
usePriorityFee(priorityFeeSetting)
|
630
|
-
|
631
|
-
|
629
|
+
simulationSuccessful && usePriorityFee(priorityFeeSetting)
|
630
|
+
? 1
|
631
|
+
: undefined,
|
632
|
+
1
|
633
|
+
).getInstructions().length -
|
634
|
+
txs[txIdx].getInstructions().length -
|
635
|
+
(txs.length > 1 && txIdx === 0 ? 1 : 0); // Account for jito tip IX
|
632
636
|
|
633
637
|
try {
|
634
638
|
if (error instanceof BundleSimulationError) {
|
@@ -135,7 +135,7 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
135
135
|
this.supplyMintInfo.decimals
|
136
136
|
);
|
137
137
|
const borrows = fromBaseUnit(
|
138
|
-
|
138
|
+
getBankLiquidityUsedBaseUnit(this.supplyBank, false),
|
139
139
|
this.supplyMintInfo.decimals
|
140
140
|
);
|
141
141
|
return Math.min((deposits - borrows), this.totalSupply) * this.supplyPrice()!;
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -273,12 +273,14 @@ export async function sendJitoBundledTransactions(
|
|
273
273
|
connection: Connection,
|
274
274
|
userSigner: Signer,
|
275
275
|
otherSigners: Signer[],
|
276
|
-
|
276
|
+
transactions: TransactionBuilder[],
|
277
277
|
txType?: TransactionRunType,
|
278
278
|
priorityFeeSetting: PriorityFeeSetting = PriorityFeeSetting.Min,
|
279
279
|
onAwaitingSign?: () => void,
|
280
280
|
abortController?: AbortController
|
281
281
|
): Promise<string[] | undefined> {
|
282
|
+
const txs = [...transactions];
|
283
|
+
|
282
284
|
if (txs.length === 1) {
|
283
285
|
const resp = await sendSingleOptimizedTransaction(
|
284
286
|
umi,
|
@@ -304,20 +306,6 @@ export async function sendJitoBundledTransactions(
|
|
304
306
|
|
305
307
|
txs[0] = txs[0].prepend(getTipInstruction(userSigner, 150_000));
|
306
308
|
|
307
|
-
const feeEstimates = usePriorityFee(priorityFeeSetting)
|
308
|
-
? await Promise.all(
|
309
|
-
txs.map(
|
310
|
-
async (x) =>
|
311
|
-
(await getComputeUnitPriceEstimate(
|
312
|
-
umi,
|
313
|
-
x,
|
314
|
-
priorityFeeSetting,
|
315
|
-
true
|
316
|
-
)) ?? 1000000
|
317
|
-
)
|
318
|
-
)
|
319
|
-
: undefined;
|
320
|
-
|
321
309
|
const latestBlockhash = (
|
322
310
|
await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })
|
323
311
|
).blockhash;
|
@@ -335,11 +323,26 @@ export async function sendJitoBundledTransactions(
|
|
335
323
|
otherSigners,
|
336
324
|
txs,
|
337
325
|
false,
|
338
|
-
|
326
|
+
undefined,
|
327
|
+
Array(txs.length).map(_ => 1_400_000)
|
339
328
|
);
|
340
329
|
simulationResults = await simulateJitoBundle(umi, builtTxs);
|
341
330
|
}
|
342
331
|
|
332
|
+
const feeEstimates = usePriorityFee(priorityFeeSetting)
|
333
|
+
? await Promise.all(
|
334
|
+
txs.map(
|
335
|
+
async (x) =>
|
336
|
+
(await getComputeUnitPriceEstimate(
|
337
|
+
umi,
|
338
|
+
x,
|
339
|
+
priorityFeeSetting,
|
340
|
+
true
|
341
|
+
)) ?? 1000000
|
342
|
+
)
|
343
|
+
)
|
344
|
+
: undefined;
|
345
|
+
|
343
346
|
if (abortController?.signal.aborted) {
|
344
347
|
return;
|
345
348
|
}
|