@haven-fi/solauto-sdk 1.0.432 → 1.0.434
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/clients/solautoMarginfiClient.js +3 -3
- package/dist/generated/types/solautoRebalanceType.d.ts +2 -1
- package/dist/generated/types/solautoRebalanceType.d.ts.map +1 -1
- package/dist/generated/types/solautoRebalanceType.js +2 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +16 -9
- package/dist/utils/jitoUtils.d.ts +3 -3
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +10 -3
- 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 +9 -7
- package/local/logPositions.ts +13 -40
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +3 -3
- package/src/generated/types/solautoRebalanceType.ts +2 -1
- package/src/transactions/transactionUtils.ts +47 -31
- package/src/utils/jitoUtils.ts +14 -4
- package/src/utils/solauto/rebalanceUtils.ts +16 -11
@@ -384,9 +384,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
384
384
|
}));
|
385
385
|
}
|
386
386
|
flashRepay(flashLoanDetails) {
|
387
|
-
const accounts = flashLoanDetails.
|
388
|
-
? { data: this.
|
389
|
-
: { data: this.
|
387
|
+
const accounts = flashLoanDetails.useDebtLiquidity
|
388
|
+
? { data: this.marginfiDebtAccounts, oracle: this.debtPriceOracle }
|
389
|
+
: { data: this.marginfiSupplyAccounts, oracle: this.supplyPriceOracle };
|
390
390
|
const remainingAccounts = [];
|
391
391
|
let includedFlashLoanToken = false;
|
392
392
|
if (this.intermediaryMarginfiAccount) {
|
@@ -10,7 +10,8 @@ export declare enum SolautoRebalanceType {
|
|
10
10
|
None = 0,
|
11
11
|
Regular = 1,
|
12
12
|
DoubleRebalanceWithFL = 2,
|
13
|
-
|
13
|
+
FLSwapThenRebalance = 3,
|
14
|
+
FLRebalanceThenSwap = 4
|
14
15
|
}
|
15
16
|
export type SolautoRebalanceTypeArgs = SolautoRebalanceType;
|
16
17
|
export declare function getSolautoRebalanceTypeSerializer(): Serializer<SolautoRebalanceTypeArgs, SolautoRebalanceType>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoRebalanceType.d.ts","sourceRoot":"","sources":["../../../src/generated/types/solautoRebalanceType.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,oBAAoB;IAC9B,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,qBAAqB,IAAA;IACrB,
|
1
|
+
{"version":3,"file":"solautoRebalanceType.d.ts","sourceRoot":"","sources":["../../../src/generated/types/solautoRebalanceType.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,oBAAoB;IAC9B,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,qBAAqB,IAAA;IACrB,mBAAmB,IAAA;IACnB,mBAAmB,IAAA;CACpB;AAED,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AAE5D,wBAAgB,iCAAiC,IAAI,UAAU,CAC7D,wBAAwB,EACxB,oBAAoB,CACrB,CAIA"}
|
@@ -15,7 +15,8 @@ var SolautoRebalanceType;
|
|
15
15
|
SolautoRebalanceType[SolautoRebalanceType["None"] = 0] = "None";
|
16
16
|
SolautoRebalanceType[SolautoRebalanceType["Regular"] = 1] = "Regular";
|
17
17
|
SolautoRebalanceType[SolautoRebalanceType["DoubleRebalanceWithFL"] = 2] = "DoubleRebalanceWithFL";
|
18
|
-
SolautoRebalanceType[SolautoRebalanceType["
|
18
|
+
SolautoRebalanceType[SolautoRebalanceType["FLSwapThenRebalance"] = 3] = "FLSwapThenRebalance";
|
19
|
+
SolautoRebalanceType[SolautoRebalanceType["FLRebalanceThenSwap"] = 4] = "FLRebalanceThenSwap";
|
19
20
|
})(SolautoRebalanceType || (exports.SolautoRebalanceType = SolautoRebalanceType = {}));
|
20
21
|
function getSolautoRebalanceTypeSerializer() {
|
21
22
|
return (0, serializers_1.scalarEnum)(SolautoRebalanceType, {
|
@@ -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;AAoBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA4LjD,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,oBAqDzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAoI5C;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"}
|
@@ -383,20 +383,27 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
383
383
|
if (flashLoan) {
|
384
384
|
client.log("Flash loan details: ", flashLoan);
|
385
385
|
const addFirstRebalance = values.amountUsdToDcaIn > 0;
|
386
|
+
const rebalanceThenSwap = values.rebalanceDirection === generated_1.RebalanceDirection.Repay &&
|
387
|
+
flashLoan.useDebtLiquidity;
|
386
388
|
const rebalanceType = addFirstRebalance
|
387
389
|
? generated_1.SolautoRebalanceType.DoubleRebalanceWithFL
|
388
|
-
:
|
390
|
+
: rebalanceThenSwap
|
391
|
+
? generated_1.SolautoRebalanceType.FLRebalanceThenSwap
|
392
|
+
: generated_1.SolautoRebalanceType.FLSwapThenRebalance;
|
393
|
+
client.log("Rebalance type:", rebalanceType);
|
394
|
+
const firstRebalance = client.rebalance("A", jupQuote, rebalanceType, values, flashLoan, targetLiqUtilizationRateBps);
|
395
|
+
const lastRebalance = client.rebalance("B", jupQuote, rebalanceType, values, flashLoan, targetLiqUtilizationRateBps);
|
396
|
+
const flashBorrowDest = (0, accountUtils_1.getTokenAccount)(rebalanceThenSwap
|
397
|
+
? client.solautoPosition
|
398
|
+
: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), rebalanceThenSwap ? swapDetails.outputMint : swapDetails.inputMint);
|
389
399
|
tx = tx.add([
|
390
400
|
setupInstructions,
|
391
401
|
tokenLedgerIx,
|
392
|
-
client.flashBorrow(flashLoan,
|
393
|
-
...(addFirstRebalance
|
394
|
-
|
395
|
-
|
396
|
-
]
|
397
|
-
: []),
|
398
|
-
swapIx,
|
399
|
-
client.rebalance("B", jupQuote, rebalanceType, values, flashLoan, targetLiqUtilizationRateBps),
|
402
|
+
client.flashBorrow(flashLoan, flashBorrowDest),
|
403
|
+
...(addFirstRebalance ? [firstRebalance] : []),
|
404
|
+
...(rebalanceThenSwap
|
405
|
+
? [lastRebalance, swapIx]
|
406
|
+
: [swapIx, lastRebalance]),
|
400
407
|
client.flashRepay(flashLoan),
|
401
408
|
]);
|
402
409
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Connection, PublicKey
|
2
|
-
import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
2
|
+
import { Signer, TransactionBuilder, Umi, TransactionMessage } from "@metaplex-foundation/umi";
|
3
3
|
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
4
4
|
export declare function getRandomTipAccount(): PublicKey;
|
5
|
-
export declare function getRequiredSigners(message:
|
5
|
+
export declare function getRequiredSigners(message: TransactionMessage): {
|
6
6
|
index: number;
|
7
7
|
publicKey: string;
|
8
8
|
isWritable: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAKV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMlE,wBAAgB,mBAAmB,IAAI,SAAS,CAa/C;AA8ND,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB7D;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA8F/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -116,8 +116,15 @@ async function umiToVersionedTransactions(umi, blockhash, userSigner, otherSigne
|
|
116
116
|
}));
|
117
117
|
if (sign) {
|
118
118
|
builtTxs = await userSigner.signAllTransactions(builtTxs);
|
119
|
-
for (const
|
120
|
-
|
119
|
+
for (const signer of otherSigners) {
|
120
|
+
for (let i = 0; i < builtTxs.length; i++) {
|
121
|
+
const requiredSigners = getRequiredSigners(builtTxs[i].message);
|
122
|
+
if (requiredSigners
|
123
|
+
.map((x) => x.publicKey)
|
124
|
+
.includes(signer.publicKey.toString())) {
|
125
|
+
builtTxs[i] = await signer.signTransaction(builtTxs[i]);
|
126
|
+
}
|
127
|
+
}
|
121
128
|
}
|
122
129
|
}
|
123
130
|
return builtTxs.map((x) => (0, umi_web3js_adapters_1.toWeb3JsTransaction)(x));
|
@@ -182,7 +189,7 @@ function getRequiredSigners(message) {
|
|
182
189
|
const numWritableSigners = numRequiredSignatures - numReadonlySignedAccounts;
|
183
190
|
const signersInfo = [];
|
184
191
|
for (let i = 0; i < numRequiredSignatures; i++) {
|
185
|
-
const publicKey = message.
|
192
|
+
const publicKey = message.accounts[i].toString();
|
186
193
|
const isWritable = i < numWritableSigners;
|
187
194
|
signersInfo.push({
|
188
195
|
index: i,
|
@@ -18,6 +18,7 @@ export declare function getRebalanceValues(state: PositionState, settings: Solau
|
|
18
18
|
export interface FlashLoanDetails {
|
19
19
|
baseUnitAmount: bigint;
|
20
20
|
mint: PublicKey;
|
21
|
+
useDebtLiquidity: boolean;
|
21
22
|
}
|
22
23
|
export declare function getFlashLoanDetails(client: SolautoClient, values: RebalanceValues, jupQuote: QuoteResponse): FlashLoanDetails | undefined;
|
23
24
|
export declare function getJupSwapRebalanceDetails(client: SolautoClient, values: RebalanceValues, targetLiqUtilizationRateBps?: number, attemptNum?: number): JupSwapDetails;
|
@@ -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;AAajD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmI9C,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;CACjB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAy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,MAAM,GACnC,eAAe,CAwDjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CA2E9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CA8ChB"}
|
@@ -128,7 +128,10 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
128
128
|
(0, generalUtils_2.consoleLog)("Intermediary liq utilization rate:", tempLiqUtilizationRateBps, `$${supplyUsd}`, `$${debtUsd}`, "Max:", maxLiqUtilizationRateBps);
|
129
129
|
let flashLoanToken = undefined;
|
130
130
|
let flashLoanTokenPrice = 0;
|
131
|
-
|
131
|
+
const baseUnitAmount = BigInt(parseInt(jupQuote.inAmount));
|
132
|
+
if (values.rebalanceDirection === generated_1.RebalanceDirection.Boost ||
|
133
|
+
baseUnitAmount <=
|
134
|
+
(client.solautoPositionState?.debt.amountCanBeUsed.baseUnit ?? BigInt(0))) {
|
132
135
|
flashLoanToken = client.solautoPositionState.debt;
|
133
136
|
flashLoanTokenPrice = (0, priceUtils_1.safeGetPrice)(client.debtMint);
|
134
137
|
}
|
@@ -136,15 +139,14 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
136
139
|
flashLoanToken = client.solautoPositionState.supply;
|
137
140
|
flashLoanTokenPrice = (0, priceUtils_1.safeGetPrice)(client.supplyMint);
|
138
141
|
}
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
+
if (jupQuote.swapMode !== "ExactOut" && jupQuote.swapMode !== "ExactIn") {
|
143
|
+
throw new Error("Token ledger swap not currently supported");
|
144
|
+
}
|
142
145
|
return requiresFlashLoan
|
143
146
|
? {
|
144
|
-
baseUnitAmount
|
145
|
-
? exactAmountBaseUnit
|
146
|
-
: (0, numberUtils_1.toBaseUnit)(debtAdjustmentUsdAbs / flashLoanTokenPrice, flashLoanToken.decimals),
|
147
|
+
baseUnitAmount,
|
147
148
|
mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(flashLoanToken.mint),
|
149
|
+
useDebtLiquidity: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(flashLoanToken.mint).equals(client.debtMint),
|
148
150
|
}
|
149
151
|
: undefined;
|
150
152
|
}
|
package/local/logPositions.ts
CHANGED
@@ -7,7 +7,6 @@ import {
|
|
7
7
|
getSolautoManagedPositions,
|
8
8
|
PositionState,
|
9
9
|
positionStateWithLatestPrices,
|
10
|
-
PRICES,
|
11
10
|
retryWithExponentialBackoff,
|
12
11
|
safeFetchAllSolautoPosition,
|
13
12
|
safeGetPrice,
|
@@ -15,7 +14,7 @@ import {
|
|
15
14
|
TOKEN_INFO,
|
16
15
|
USD_DECIMALS,
|
17
16
|
} from "../src";
|
18
|
-
import { PublicKey
|
17
|
+
import { PublicKey } from "@solana/web3.js";
|
19
18
|
import { NATIVE_MINT } from "@solana/spl-token";
|
20
19
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
21
20
|
import path from "path";
|
@@ -187,6 +186,7 @@ async function main(filterWhitelist: boolean) {
|
|
187
186
|
console.log("\n\n");
|
188
187
|
|
189
188
|
const latestStates: PositionState[] = [];
|
189
|
+
let unhealthyPositions = 0;
|
190
190
|
for (const pos of solautoPositionsData) {
|
191
191
|
const latestState = await positionStateWithLatestPrices(
|
192
192
|
pos.state,
|
@@ -200,15 +200,20 @@ async function main(filterWhitelist: boolean) {
|
|
200
200
|
toWeb3JsPublicKey(pos.state.debt.mint)
|
201
201
|
);
|
202
202
|
|
203
|
-
|
204
|
-
|
203
|
+
const repayFrom = pos.position.settingParams.repayToBps + pos.position.settingParams.repayGap;
|
204
|
+
const unhealthy = pos.state.liqUtilizationRateBps > repayFrom;
|
205
|
+
const healthText = unhealthy ? `(Unhealthy: ${pos.state.liqUtilizationRateBps - repayFrom}` : "";
|
206
|
+
if (unhealthy) {
|
207
|
+
unhealthyPositions += 1;
|
208
|
+
}
|
209
|
+
|
210
|
+
console.log(pos.publicKey.toString(), `(${pos.authority.toString()})`);
|
205
211
|
console.log(
|
206
|
-
`${strategy}: $${formatNumber(fromBaseUnit(latestState.netWorth.baseAmountUsdValue, USD_DECIMALS), 2, 10000, 2)}`
|
212
|
+
`${strategy}: $${formatNumber(fromBaseUnit(latestState.netWorth.baseAmountUsdValue, USD_DECIMALS), 2, 10000, 2)} ${healthText}`
|
207
213
|
);
|
208
|
-
console.log("\n");
|
209
214
|
}
|
210
215
|
|
211
|
-
console.log("
|
216
|
+
console.log("\nTotal positions:", solautoPositionsData.length, unhealthyPositions ? ` (unhealthy: ${unhealthyPositions})` : "");
|
212
217
|
console.log(
|
213
218
|
"Total users:",
|
214
219
|
Array.from(new Set(solautoPositionsData.map((x) => x.authority.toString())))
|
@@ -221,37 +226,5 @@ async function main(filterWhitelist: boolean) {
|
|
221
226
|
console.log(`Total TVL: $${formatNumber(tvl, 2, 10000, 2)}`);
|
222
227
|
}
|
223
228
|
|
224
|
-
import { Transaction } from "@solana/web3.js";
|
225
|
-
import * as bs58 from "bs58";
|
226
|
-
|
227
|
-
function decodeVersionedTx(base58Tx: string) {
|
228
|
-
// 1) Decode base58 into raw bytes
|
229
|
-
const txBuffer = bs58.decode(base58Tx);
|
230
|
-
|
231
|
-
// 2) Parse as versioned transaction
|
232
|
-
const versionedTx = VersionedTransaction.deserialize(txBuffer);
|
233
|
-
|
234
|
-
// 3) Extract signatures or do other things with `versionedTx`
|
235
|
-
const signatures = versionedTx.signatures.map((sigBytes, index) => ({
|
236
|
-
index,
|
237
|
-
signature: bs58.encode(sigBytes), // convert signature bytes to base58 string
|
238
|
-
}));
|
239
|
-
|
240
|
-
return { versionedTx, signatures };
|
241
|
-
}
|
242
|
-
|
243
229
|
const filterWhitelist = true;
|
244
|
-
main(filterWhitelist).then((x) => x);
|
245
|
-
|
246
|
-
// console.log(
|
247
|
-
// decodeVersionedTx(
|
248
|
-
// "mQkqpyEB1JEkGUsowzhUXvn2v1kwdGYApNGDUsRZ1BmpmKJhMUXQhmyZoDXKPtVhcjgWQHqN6S94p2fNiPxyRhBUvN1Vs5HjbhdVjhhG4XEDCXRw4K2PPEeTowWf7N5GjQ4wZdpdP8UZtnz3CXtbkCYGnxfjt6AtanQXsJpWUpC84g7ZSfYiNAYRv2geHp6E13yNXya9FGFekmsN3S9UcmWJTQgLu9vFxmL9S6DD6npDK7wPyZ66dcKWTMg2nb8Drig8aLAiFRnkqC99QjN7YYG65qq9VkzTC7o8EbGddddrfLu6Hyk2SgEqebMvhiV729y3sWpDpbbKakknJj4PUodasfKza4XNg3jRGBoVRxvSb3QGFdhbDJa86YvQbsP7pWLqMuJcoaGX3uLgsBFA2z8kGmZBuzGAS3FtgnmE7L8dFMLWGDDKTdFwsTbeZQJsGGtn5sy627onUqyTxHy9UfuBz57h3kd26yUBUmbR9RVgCX2WMSHdEW58uYd2BYbAG4NVQYCzgcWzZEjayXn73fo2Y72Y4BrxnKcqJ8WixHjaj7PPRdvX87wxiHy9b8CxsngKhYM5sWoXVWj5CAq6drS2g7b4b7CZzjeQYkCF"
|
249
|
-
// )
|
250
|
-
// );
|
251
|
-
// console.log(
|
252
|
-
// decodeVersionedTx(
|
253
|
-
// "e6uLxBWUSbPnkYKPWoyoR6YZw7Qt4NnZcabGwaAChdAN4N4GFwvxMxwq3mrxoRM3CDzPHhAh7rbEmzAzyA8pJAhGAaDWfCG3CjnVoWbpdDQvpwUxRffK3xFDGqJeoQvQBvQtZidwaDvDnnkJ6xRgsnpujS65jcGP5AsECsaJ2uRMSsLt8ucynZjQzVw24jqaYRRmUN4otF2mSgbgkXLu9G82g8sfcj3VQu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KUAxjKpYQ3AmdjnseE23njArKaEwrRQA4NnxpUUazzsWJqHymHPJG73GQhQtxNtvfDDMVSj95UkiscssHNEpkt6dqLeohDR1rP2kg41EBGQMNEdeYtUt1JkzdjZBsvU1oV81GG1tEQoSUR1skjq9tWpfoiSPVN9QTQC3kQUgZQQPR9arK5XWqj6y5iPnusQk8zdzoHJt5EFm7aagfLG3uJxdd9ZF7Gk4tMzijx5d1fV1uGhcxAyb5B5m8nkCdap"
|
254
|
-
// )
|
255
|
-
// );
|
256
|
-
|
257
|
-
// console.log(SystemProgram.programId.toString());
|
230
|
+
main(filterWhitelist).then((x) => x);
|
package/package.json
CHANGED
@@ -594,9 +594,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
594
594
|
}
|
595
595
|
|
596
596
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder {
|
597
|
-
const accounts = flashLoanDetails.
|
598
|
-
? { data: this.
|
599
|
-
: { data: this.
|
597
|
+
const accounts = flashLoanDetails.useDebtLiquidity
|
598
|
+
? { data: this.marginfiDebtAccounts, oracle: this.debtPriceOracle }
|
599
|
+
: { data: this.marginfiSupplyAccounts, oracle: this.supplyPriceOracle };
|
600
600
|
|
601
601
|
const remainingAccounts: AccountMeta[] = [];
|
602
602
|
let includedFlashLoanToken = false;
|
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
import {
|
17
17
|
InvalidRebalanceConditionError,
|
18
18
|
LendingPlatform,
|
19
|
+
RebalanceDirection,
|
19
20
|
SolautoAction,
|
20
21
|
SolautoRebalanceType,
|
21
22
|
TokenType,
|
@@ -713,41 +714,50 @@ export async function buildSolautoRebalanceTransaction(
|
|
713
714
|
if (flashLoan) {
|
714
715
|
client.log("Flash loan details: ", flashLoan);
|
715
716
|
const addFirstRebalance = values.amountUsdToDcaIn > 0;
|
717
|
+
|
718
|
+
const rebalanceThenSwap =
|
719
|
+
values.rebalanceDirection === RebalanceDirection.Repay &&
|
720
|
+
flashLoan.useDebtLiquidity;
|
721
|
+
|
716
722
|
const rebalanceType = addFirstRebalance
|
717
723
|
? SolautoRebalanceType.DoubleRebalanceWithFL
|
718
|
-
:
|
724
|
+
: rebalanceThenSwap
|
725
|
+
? SolautoRebalanceType.FLRebalanceThenSwap
|
726
|
+
: SolautoRebalanceType.FLSwapThenRebalance;
|
727
|
+
|
728
|
+
client.log("Rebalance type:", rebalanceType);
|
729
|
+
const firstRebalance = client.rebalance(
|
730
|
+
"A",
|
731
|
+
jupQuote,
|
732
|
+
rebalanceType,
|
733
|
+
values,
|
734
|
+
flashLoan,
|
735
|
+
targetLiqUtilizationRateBps
|
736
|
+
);
|
737
|
+
const lastRebalance = client.rebalance(
|
738
|
+
"B",
|
739
|
+
jupQuote,
|
740
|
+
rebalanceType,
|
741
|
+
values,
|
742
|
+
flashLoan,
|
743
|
+
targetLiqUtilizationRateBps
|
744
|
+
);
|
745
|
+
|
746
|
+
const flashBorrowDest = getTokenAccount(
|
747
|
+
rebalanceThenSwap
|
748
|
+
? client.solautoPosition
|
749
|
+
: toWeb3JsPublicKey(client.signer.publicKey),
|
750
|
+
rebalanceThenSwap ? swapDetails.outputMint : swapDetails.inputMint
|
751
|
+
);
|
719
752
|
|
720
753
|
tx = tx.add([
|
721
754
|
setupInstructions,
|
722
755
|
tokenLedgerIx,
|
723
|
-
client.flashBorrow(
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
)
|
729
|
-
),
|
730
|
-
...(addFirstRebalance
|
731
|
-
? [
|
732
|
-
client.rebalance(
|
733
|
-
"A",
|
734
|
-
jupQuote,
|
735
|
-
rebalanceType,
|
736
|
-
values,
|
737
|
-
flashLoan,
|
738
|
-
targetLiqUtilizationRateBps
|
739
|
-
),
|
740
|
-
]
|
741
|
-
: []),
|
742
|
-
swapIx,
|
743
|
-
client.rebalance(
|
744
|
-
"B",
|
745
|
-
jupQuote,
|
746
|
-
rebalanceType,
|
747
|
-
values,
|
748
|
-
flashLoan,
|
749
|
-
targetLiqUtilizationRateBps
|
750
|
-
),
|
756
|
+
client.flashBorrow(flashLoan, flashBorrowDest),
|
757
|
+
...(addFirstRebalance ? [firstRebalance] : []),
|
758
|
+
...(rebalanceThenSwap
|
759
|
+
? [lastRebalance, swapIx]
|
760
|
+
: [swapIx, lastRebalance]),
|
751
761
|
client.flashRepay(flashLoan),
|
752
762
|
]);
|
753
763
|
} else {
|
@@ -880,8 +890,14 @@ export function getErrorInfo(
|
|
880
890
|
consoleLog("Error code:", errCode);
|
881
891
|
consoleLog("Error instruction program:", errIx?.programId.toString());
|
882
892
|
|
883
|
-
const solautoError = getSolautoErrorFromCode(
|
884
|
-
|
893
|
+
const solautoError = getSolautoErrorFromCode(
|
894
|
+
errCode ?? -1,
|
895
|
+
createSolautoProgram()
|
896
|
+
);
|
897
|
+
const marginfiError = getMarginfiErrorFromCode(
|
898
|
+
errCode ?? -1,
|
899
|
+
createMarginfiProgram()
|
900
|
+
);
|
885
901
|
|
886
902
|
if (
|
887
903
|
errCode &&
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -13,6 +13,7 @@ import {
|
|
13
13
|
TransactionBuilder,
|
14
14
|
Umi,
|
15
15
|
WrappedInstruction,
|
16
|
+
TransactionMessage,
|
16
17
|
} from "@metaplex-foundation/umi";
|
17
18
|
import {
|
18
19
|
assembleFinalTransaction,
|
@@ -178,8 +179,17 @@ async function umiToVersionedTransactions(
|
|
178
179
|
|
179
180
|
if (sign) {
|
180
181
|
builtTxs = await userSigner.signAllTransactions(builtTxs);
|
181
|
-
for (const
|
182
|
-
|
182
|
+
for (const signer of otherSigners) {
|
183
|
+
for (let i = 0; i < builtTxs.length; i++) {
|
184
|
+
const requiredSigners = getRequiredSigners(builtTxs[i].message);
|
185
|
+
if (
|
186
|
+
requiredSigners
|
187
|
+
.map((x) => x.publicKey)
|
188
|
+
.includes(signer.publicKey.toString())
|
189
|
+
) {
|
190
|
+
builtTxs[i] = await signer.signTransaction(builtTxs[i]);
|
191
|
+
}
|
192
|
+
}
|
183
193
|
}
|
184
194
|
}
|
185
195
|
|
@@ -253,14 +263,14 @@ async function sendJitoBundle(
|
|
253
263
|
return bundleId ? await pollBundleStatus(bundleId) : [];
|
254
264
|
}
|
255
265
|
|
256
|
-
export function getRequiredSigners(message:
|
266
|
+
export function getRequiredSigners(message: TransactionMessage) {
|
257
267
|
const { numRequiredSignatures, numReadonlySignedAccounts } = message.header;
|
258
268
|
|
259
269
|
const numWritableSigners = numRequiredSignatures - numReadonlySignedAccounts;
|
260
270
|
|
261
271
|
const signersInfo = [];
|
262
272
|
for (let i = 0; i < numRequiredSignatures; i++) {
|
263
|
-
const publicKey = message.
|
273
|
+
const publicKey = message.accounts[i].toString();
|
264
274
|
const isWritable = i < numWritableSigners;
|
265
275
|
|
266
276
|
signersInfo.push({
|
@@ -239,6 +239,7 @@ export function getRebalanceValues(
|
|
239
239
|
export interface FlashLoanDetails {
|
240
240
|
baseUnitAmount: bigint;
|
241
241
|
mint: PublicKey;
|
242
|
+
useDebtLiquidity: boolean;
|
242
243
|
}
|
243
244
|
|
244
245
|
export function getFlashLoanDetails(
|
@@ -292,7 +293,14 @@ export function getFlashLoanDetails(
|
|
292
293
|
|
293
294
|
let flashLoanToken: PositionTokenUsage | undefined = undefined;
|
294
295
|
let flashLoanTokenPrice = 0;
|
295
|
-
|
296
|
+
|
297
|
+
const baseUnitAmount = BigInt(parseInt(jupQuote.inAmount));
|
298
|
+
|
299
|
+
if (
|
300
|
+
values.rebalanceDirection === RebalanceDirection.Boost ||
|
301
|
+
baseUnitAmount <=
|
302
|
+
(client.solautoPositionState?.debt.amountCanBeUsed.baseUnit ?? BigInt(0))
|
303
|
+
) {
|
296
304
|
flashLoanToken = client.solautoPositionState!.debt;
|
297
305
|
flashLoanTokenPrice = safeGetPrice(client.debtMint)!;
|
298
306
|
} else {
|
@@ -300,20 +308,17 @@ export function getFlashLoanDetails(
|
|
300
308
|
flashLoanTokenPrice = safeGetPrice(client.supplyMint)!;
|
301
309
|
}
|
302
310
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
: undefined;
|
311
|
+
if (jupQuote.swapMode !== "ExactOut" && jupQuote.swapMode !== "ExactIn") {
|
312
|
+
throw new Error("Token ledger swap not currently supported");
|
313
|
+
}
|
307
314
|
|
308
315
|
return requiresFlashLoan
|
309
316
|
? {
|
310
|
-
baseUnitAmount
|
311
|
-
? exactAmountBaseUnit
|
312
|
-
: toBaseUnit(
|
313
|
-
debtAdjustmentUsdAbs / flashLoanTokenPrice,
|
314
|
-
flashLoanToken.decimals
|
315
|
-
),
|
317
|
+
baseUnitAmount,
|
316
318
|
mint: toWeb3JsPublicKey(flashLoanToken.mint),
|
319
|
+
useDebtLiquidity: toWeb3JsPublicKey(flashLoanToken.mint).equals(
|
320
|
+
client.debtMint
|
321
|
+
),
|
317
322
|
}
|
318
323
|
: undefined;
|
319
324
|
}
|