@haven-fi/solauto-sdk 1.0.50 → 1.0.52
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +7 -3
- package/dist/transactions/transactionUtils.js +1 -1
- package/dist/transactions/transactionsManager.d.ts +2 -1
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +2 -2
- package/dist/types/solauto.d.ts +5 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/types/solauto.js +6 -0
- package/dist/utils/numberUtils.js +1 -1
- package/dist/utils/solanaUtils.d.ts +3 -2
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +5 -4
- package/dist/utils/solauto/generalUtils.d.ts +2 -2
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +8 -9
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +1 -2
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +22 -6
- package/src/transactions/transactionUtils.ts +2 -2
- package/src/transactions/transactionsManager.ts +4 -2
- package/src/types/solauto.ts +8 -1
- package/src/utils/numberUtils.ts +1 -1
- package/src/utils/solanaUtils.ts +7 -4
- package/src/utils/solauto/generalUtils.ts +8 -9
- package/src/utils/solauto/rebalanceUtils.ts +1 -2
- package/tests/transactions/solautoMarginfi.ts +10 -10
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;AAUtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAOvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAGpE,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,oBAAoB,CAAC,EAAE,SAAS,CAAC;IACjC,mBAAmB,CAAC,EAAE,SAAS,CAAC;CACjC;AAED,8BAAsB,aAAa;IAyCxB,SAAS,CAAC;IAxCZ,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;IACxB,eAAe,EAAG,eA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AAE,WAAW,EAAE,kBAAkB,CAAC;QAAC,iBAAiB,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAC5E;IA2DD,uBAAuB,IAAI,yBAAyB,GAAG,SAAS;IAOhE,wBAAwB,IAAI,WAAW,GAAG,SAAS;IAOnD,sBAAsB,IAAI,kBAAkB;IAiB5C,mBAAmB,IAAI,kBAAkB;IAmBzC,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAgCrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IA2DlE,eAAe,IAAI,kBAAkB;IAWrC,WAAW,IAAI,kBAAkB;IA4BjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,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;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
|
@@ -14,6 +14,7 @@ const spl_token_1 = require("@solana/spl-token");
|
|
14
14
|
const solautoConstants_1 = require("../constants/solautoConstants");
|
15
15
|
const generalUtils_1 = require("../utils/generalUtils");
|
16
16
|
const generalUtils_2 = require("../utils/solauto/generalUtils");
|
17
|
+
const utils_1 = require("../utils");
|
17
18
|
class SolautoClient {
|
18
19
|
constructor(heliusApiKey, localTest) {
|
19
20
|
this.localTest = localTest;
|
@@ -34,8 +35,7 @@ class SolautoClient {
|
|
34
35
|
? (0, umi_1.signerIdentity)(args.signer)
|
35
36
|
: (0, umi_signer_wallet_adapters_1.walletAdapterIdentity)(args.wallet, true));
|
36
37
|
this.signer = this.umi.identity;
|
37
|
-
this.authority =
|
38
|
-
args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey);
|
38
|
+
this.authority = args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey);
|
39
39
|
this.positionId = args.positionId;
|
40
40
|
this.selfManaged = this.positionId === 0;
|
41
41
|
this.lendingPlatform = lendingPlatform;
|
@@ -216,7 +216,7 @@ class SolautoClient {
|
|
216
216
|
});
|
217
217
|
}
|
218
218
|
openPosition(settingParams, dca) {
|
219
|
-
|
219
|
+
let tx = (0, umi_1.transactionBuilder)();
|
220
220
|
if (dca && dca.debtToAddBaseUnit > 0) {
|
221
221
|
this.livePositionUpdates.new({
|
222
222
|
type: "debtDcaIn",
|
@@ -235,6 +235,10 @@ class SolautoClient {
|
|
235
235
|
value: dca,
|
236
236
|
});
|
237
237
|
}
|
238
|
+
if (!this.selfManaged) {
|
239
|
+
// Tip Solauto Manager
|
240
|
+
tx = tx.add((0, solanaUtils_1.systemTransferUmiIx)(this.signer, generalAccounts_1.SOLAUTO_MANAGER, (0, utils_1.toBaseUnit)(0.1, 9)));
|
241
|
+
}
|
238
242
|
return tx;
|
239
243
|
}
|
240
244
|
updatePositionIx(args) {
|
@@ -321,7 +321,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
321
321
|
client.solautoPositionState = await client.getFreshPositionState();
|
322
322
|
if (client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) ||
|
323
323
|
(targetLiqUtilizationRateBps === undefined &&
|
324
|
-
!(0, generalUtils_2.
|
324
|
+
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.livePositionUpdates.settings ??
|
325
325
|
client.solautoPositionData?.position.settingParams, client.livePositionUpdates.activeDca ??
|
326
326
|
client.solautoPositionData?.position.dca))) {
|
327
327
|
client.log("Not eligible for a rebalance");
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { AddressLookupTableInput, TransactionBuilder } from "@metaplex-foundation/umi";
|
2
2
|
import { SolautoClient } from "../clients/solautoClient";
|
3
3
|
import { ErrorsToThrow } from "../utils/generalUtils";
|
4
|
+
import { PriorityFeeSetting } from "../types";
|
4
5
|
declare class LookupTables {
|
5
6
|
private client;
|
6
7
|
defaultLuts: string[];
|
@@ -60,7 +61,7 @@ export declare class TransactionsManager {
|
|
60
61
|
private assembleTransactionSets;
|
61
62
|
updateStatus(name: string, status: TransactionStatus, txSig?: string): void;
|
62
63
|
debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder): Promise<void>;
|
63
|
-
send(): Promise<void>;
|
64
|
+
send(prioritySetting?: PriorityFeeSetting): Promise<void>;
|
64
65
|
}
|
65
66
|
export {};
|
66
67
|
//# sourceMappingURL=transactionsManager.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,kBAAk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I,IAAI,MAAM;CAYf;AAED,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,aAAa,CAAC;IATxB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,eAAe,EAAE,EACxB,cAAc,CAAC,6CAA4C,IAAI,aAAA,EAC/D,YAAY,CAAC,qBAAS,EACtB,YAAY,CAAC,qBAAS,EACtB,aAAa,CAAC,2BAAe;YAKzB,uBAAuB;IA0CrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;IAiB9D,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IAkB7D,IAAI,CAAC,eAAe,CAAC,EAAE,kBAAkB;CA6JhD"}
|
@@ -196,7 +196,7 @@ class TransactionsManager {
|
|
196
196
|
}
|
197
197
|
}
|
198
198
|
}
|
199
|
-
async send() {
|
199
|
+
async send(prioritySetting) {
|
200
200
|
const updateLookupTable = await this.client.updateLookupTable();
|
201
201
|
if (updateLookupTable &&
|
202
202
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
@@ -285,7 +285,7 @@ class TransactionsManager {
|
|
285
285
|
if (this.client.localTest) {
|
286
286
|
await this.debugAccounts(itemSet, tx);
|
287
287
|
}
|
288
|
-
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.client.umi, this.client.connection, tx, this.simulateOnly, attemptNum);
|
288
|
+
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.client.umi, this.client.connection, tx, this.simulateOnly, attemptNum, prioritySetting);
|
289
289
|
this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
|
290
290
|
}
|
291
291
|
}, 4, 150, this.errorsToThrow);
|
package/dist/types/solauto.d.ts
CHANGED
@@ -9,4 +9,9 @@ export interface SolautoPositionDetails {
|
|
9
9
|
supplyMint?: PublicKey;
|
10
10
|
debtMint?: PublicKey;
|
11
11
|
}
|
12
|
+
export declare enum PriorityFeeSetting {
|
13
|
+
Default = "Medium",
|
14
|
+
High = "High"
|
15
|
+
}
|
16
|
+
export type RebalanceAction = "boost" | "repay" | "dca";
|
12
17
|
//# sourceMappingURL=solauto.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB"}
|
1
|
+
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC"}
|
package/dist/types/solauto.js
CHANGED
@@ -1,2 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PriorityFeeSetting = void 0;
|
4
|
+
var PriorityFeeSetting;
|
5
|
+
(function (PriorityFeeSetting) {
|
6
|
+
PriorityFeeSetting["Default"] = "Medium";
|
7
|
+
PriorityFeeSetting["High"] = "High";
|
8
|
+
})(PriorityFeeSetting = exports.PriorityFeeSetting || (exports.PriorityFeeSetting = {}));
|
@@ -62,7 +62,7 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
|
|
62
62
|
}
|
63
63
|
exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
|
64
64
|
function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
|
65
|
-
return toBps((fromBps(maxLtvBps) - 0.
|
65
|
+
return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
|
66
66
|
}
|
67
67
|
exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
|
68
68
|
function maxRepayFrom(maxLtvBps, liqThresholdBps) {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
|
2
2
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
3
|
+
import { PriorityFeeSetting } from "../types";
|
3
4
|
export declare function getSolanaRpcConnection(heliusApiKey: string): [Connection, Umi];
|
4
5
|
export declare function currentUnixSecondsSolana(umi: Umi): Promise<number>;
|
5
6
|
export declare function getWrappedInstruction(signer: Signer, ix: TransactionInstruction): WrappedInstruction;
|
@@ -11,6 +12,6 @@ export declare function closeTokenAccountUmiIx(signer: Signer, tokenAccount: Pub
|
|
11
12
|
export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey, toTa: PublicKey, authority: PublicKey, amount: bigint): WrappedInstruction;
|
12
13
|
export declare function getAdressLookupInputs(umi: Umi, lookupTableAddresses: string[]): Promise<AddressLookupTableInput[]>;
|
13
14
|
export declare function assembleFinalTransaction(signer: Signer, tx: TransactionBuilder, computeUnitPrice: number, computeUnitLimit?: number): TransactionBuilder;
|
14
|
-
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, attemptNum?: number): Promise<number>;
|
15
|
-
export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, simulateOnly?: boolean, attemptNum?: number): Promise<Uint8Array | undefined>;
|
15
|
+
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting, attemptNum?: number): Promise<number>;
|
16
|
+
export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, simulateOnly?: boolean, attemptNum?: number, prioritySetting?: PriorityFeeSetting): Promise<Uint8Array | undefined>;
|
16
17
|
//# sourceMappingURL=solanaUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,E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wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,GACb,kBAAkB,CAKpB;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,oBAAoB,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAkBpC;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,kBAAkB,EACtB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,MAAM,sBA4D1B;AAmBD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,EACnC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,YAAY,CAAC,EAAE,OAAO,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,GAAE,kBAA+C,GAC/D,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAmDjC"}
|
@@ -13,6 +13,7 @@ const spl_token_1 = require("@solana/spl-token");
|
|
13
13
|
const accountUtils_1 = require("./accountUtils");
|
14
14
|
const generalUtils_1 = require("./generalUtils");
|
15
15
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
16
|
+
const types_1 = require("../types");
|
16
17
|
function getSolanaRpcConnection(heliusApiKey) {
|
17
18
|
const connection = new web3_js_1.Connection(`https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`, "finalized");
|
18
19
|
const umi = (0, umi_bundle_defaults_1.createUmi)(connection);
|
@@ -138,14 +139,14 @@ async function simulateTransaction(connection, transaction) {
|
|
138
139
|
}
|
139
140
|
return simulationResult;
|
140
141
|
}
|
141
|
-
async function getComputeUnitPriceEstimate(umi, tx, attemptNum) {
|
142
|
+
async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, attemptNum) {
|
142
143
|
const web3Transaction = (0, umi_web3js_adapters_1.toWeb3JsTransaction)((await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi));
|
143
144
|
const serializedTransaction = bs58_1.default.encode(web3Transaction.serialize());
|
144
145
|
const resp = await umi.rpc.call("getPriorityFeeEstimate", [
|
145
146
|
{
|
146
147
|
transaction: serializedTransaction,
|
147
148
|
options: {
|
148
|
-
priorityLevel:
|
149
|
+
priorityLevel: prioritySetting.toString(),
|
149
150
|
},
|
150
151
|
},
|
151
152
|
]);
|
@@ -153,11 +154,11 @@ async function getComputeUnitPriceEstimate(umi, tx, attemptNum) {
|
|
153
154
|
return feeEstimate;
|
154
155
|
}
|
155
156
|
exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
|
156
|
-
async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly, attemptNum) {
|
157
|
+
async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly, attemptNum, prioritySetting = types_1.PriorityFeeSetting.Default) {
|
157
158
|
console.log("Sending single optimized transaction...");
|
158
159
|
console.log("Instructions: ", tx.getInstructions().length);
|
159
160
|
console.log("Serialized transaction size: ", tx.getTransactionSize(umi));
|
160
|
-
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
|
161
|
+
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting, attemptNum);
|
161
162
|
console.log("Compute unit price: ", feeEstimate);
|
162
163
|
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(umi.identity, tx, feeEstimate, 1400000).setLatestBlockhash(umi)).build(umi))));
|
163
164
|
const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
|
4
|
-
import { SolautoPositionDetails } from "../../types/solauto";
|
4
|
+
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
5
5
|
export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
|
6
6
|
export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings): boolean;
|
7
7
|
export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
|
@@ -11,7 +11,7 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
|
|
11
11
|
referrer: number;
|
12
12
|
total: number;
|
13
13
|
};
|
14
|
-
export declare function
|
14
|
+
export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): RebalanceAction | undefined;
|
15
15
|
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
|
16
16
|
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
|
17
17
|
export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
|
@@ -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,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAA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AM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.LivePositionUpdates = exports.positionStateWithLatestPrices = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.
|
3
|
+
exports.LivePositionUpdates = exports.positionStateWithLatestPrices = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibleForRebalance = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
|
4
4
|
const umi_1 = require("@metaplex-foundation/umi");
|
5
5
|
const generated_1 = require("../../generated");
|
6
6
|
const generalUtils_1 = require("../generalUtils");
|
@@ -58,13 +58,13 @@ function getSolautoFeesBps(isReferred, feeType) {
|
|
58
58
|
};
|
59
59
|
}
|
60
60
|
exports.getSolautoFeesBps = getSolautoFeesBps;
|
61
|
-
function
|
61
|
+
function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
62
62
|
if (positionDca.automation.targetPeriods > 0 &&
|
63
63
|
eligibleForNextAutomationPeriod(positionDca.automation)) {
|
64
|
-
return
|
64
|
+
return 'dca';
|
65
65
|
}
|
66
66
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
67
|
-
return
|
67
|
+
return undefined;
|
68
68
|
}
|
69
69
|
const boostToBps = eligibleForRefresh(positionState, positionSettings) &&
|
70
70
|
positionSettings.automation.targetPeriods > 0
|
@@ -73,15 +73,14 @@ function eligibileForRebalance(positionState, positionSettings, positionDca) {
|
|
73
73
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
74
74
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
75
75
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
76
|
-
return
|
76
|
+
return 'boost';
|
77
77
|
}
|
78
78
|
else if (positionState.liqUtilizationRateBps >= repayFrom) {
|
79
|
-
|
80
|
-
return true;
|
79
|
+
return 'repay';
|
81
80
|
}
|
82
|
-
return
|
81
|
+
return undefined;
|
83
82
|
}
|
84
|
-
exports.
|
83
|
+
exports.eligibleForRebalance = eligibleForRebalance;
|
85
84
|
function eligibleForRefresh(positionState, positionSettings) {
|
86
85
|
if (positionSettings.automation.targetPeriods > 0) {
|
87
86
|
return eligibleForNextAutomationPeriod(positionSettings.automation);
|
@@ -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;AAS5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CA8EjB;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,CAkE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,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;AAS5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CA8EjB;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,CAkE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
|
@@ -186,8 +186,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
186
186
|
inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
|
187
187
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
188
188
|
destinationWallet: client.solautoPosition,
|
189
|
-
|
190
|
-
slippageBpsIncFactor: (attemptNum ?? 0) * 0.2,
|
189
|
+
slippageBpsIncFactor: 0.1 + ((attemptNum ?? 0) * 0.2),
|
191
190
|
amount: rebalancingToZero
|
192
191
|
? client.solautoPositionState.debt.amountUsed.baseUnit +
|
193
192
|
BigInt(Math.round(Number(client.solautoPositionState.debt.amountUsed.baseUnit) *
|
package/package.json
CHANGED
@@ -47,18 +47,26 @@ import {
|
|
47
47
|
getSolautoPositionAccount,
|
48
48
|
getTokenAccount,
|
49
49
|
} from "../utils/accountUtils";
|
50
|
-
import {
|
50
|
+
import {
|
51
|
+
SOLAUTO_FEES_WALLET,
|
52
|
+
SOLAUTO_MANAGER,
|
53
|
+
} from "../constants/generalAccounts";
|
51
54
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
52
55
|
import {
|
53
56
|
getSolanaRpcConnection,
|
54
57
|
getWrappedInstruction,
|
55
58
|
splTokenTransferUmiIx,
|
59
|
+
systemTransferUmiIx,
|
56
60
|
} from "../utils/solanaUtils";
|
57
61
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
58
62
|
import { NATIVE_MINT } from "@solana/spl-token";
|
59
|
-
import {
|
63
|
+
import {
|
64
|
+
MIN_POSITION_STATE_FRESHNESS_SECS,
|
65
|
+
SOLAUTO_LUT,
|
66
|
+
} from "../constants/solautoConstants";
|
60
67
|
import { currentUnixSeconds } from "../utils/generalUtils";
|
61
68
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
69
|
+
import { toBaseUnit } from "../utils";
|
62
70
|
|
63
71
|
export interface SolautoClientArgs {
|
64
72
|
authority?: PublicKey;
|
@@ -136,8 +144,7 @@ export abstract class SolautoClient {
|
|
136
144
|
);
|
137
145
|
|
138
146
|
this.signer = this.umi.identity;
|
139
|
-
this.authority =
|
140
|
-
args.authority ?? toWeb3JsPublicKey(this.signer.publicKey);
|
147
|
+
this.authority = args.authority ?? toWeb3JsPublicKey(this.signer.publicKey);
|
141
148
|
|
142
149
|
this.positionId = args.positionId;
|
143
150
|
this.selfManaged = this.positionId === 0;
|
@@ -412,7 +419,8 @@ export abstract class SolautoClient {
|
|
412
419
|
settingParams?: SolautoSettingsParametersInpArgs,
|
413
420
|
dca?: DCASettingsInpArgs
|
414
421
|
): TransactionBuilder {
|
415
|
-
|
422
|
+
let tx = transactionBuilder();
|
423
|
+
|
416
424
|
if (dca && dca.debtToAddBaseUnit > 0) {
|
417
425
|
this.livePositionUpdates.new({
|
418
426
|
type: "debtDcaIn",
|
@@ -431,6 +439,14 @@ export abstract class SolautoClient {
|
|
431
439
|
value: dca,
|
432
440
|
});
|
433
441
|
}
|
442
|
+
|
443
|
+
if (!this.selfManaged) {
|
444
|
+
// Tip Solauto Manager
|
445
|
+
tx = tx.add(
|
446
|
+
systemTransferUmiIx(this.signer, SOLAUTO_MANAGER, toBaseUnit(0.1, 9))
|
447
|
+
);
|
448
|
+
}
|
449
|
+
|
434
450
|
return tx;
|
435
451
|
}
|
436
452
|
|
@@ -634,7 +650,7 @@ export abstract class SolautoClient {
|
|
634
650
|
rebalanceType: SolautoRebalanceTypeArgs,
|
635
651
|
flashLoan?: FlashLoanDetails,
|
636
652
|
targetLiqUtilizationRateBps?: number,
|
637
|
-
limitGapBps?: number
|
653
|
+
limitGapBps?: number
|
638
654
|
): TransactionBuilder;
|
639
655
|
|
640
656
|
async getFreshPositionState(): Promise<PositionState | undefined> {
|
@@ -46,7 +46,7 @@ import {
|
|
46
46
|
getMaxLiqUtilizationRate,
|
47
47
|
uint8ArrayToBigInt,
|
48
48
|
} from "../utils/numberUtils";
|
49
|
-
import {
|
49
|
+
import { eligibleForRebalance } from "../utils/solauto/generalUtils";
|
50
50
|
import { getTokenAccount } from "../utils/accountUtils";
|
51
51
|
import {
|
52
52
|
getLendingAccountBorrowInstructionDataSerializer,
|
@@ -563,7 +563,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
563
563
|
if (
|
564
564
|
client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) ||
|
565
565
|
(targetLiqUtilizationRateBps === undefined &&
|
566
|
-
!
|
566
|
+
!eligibleForRebalance(
|
567
567
|
client.solautoPositionState!,
|
568
568
|
client.livePositionUpdates.settings ??
|
569
569
|
client.solautoPositionData?.position.settingParams!,
|
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
} from "../utils/generalUtils";
|
17
17
|
import { getTransactionChores } from "./transactionUtils";
|
18
18
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
19
|
+
import { PriorityFeeSetting } from "../types";
|
19
20
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
20
21
|
|
21
22
|
class LookupTables {
|
@@ -271,7 +272,7 @@ export class TransactionsManager {
|
|
271
272
|
}
|
272
273
|
}
|
273
274
|
|
274
|
-
async send() {
|
275
|
+
async send(prioritySetting?: PriorityFeeSetting) {
|
275
276
|
const updateLookupTable = await this.client.updateLookupTable();
|
276
277
|
if (
|
277
278
|
updateLookupTable &&
|
@@ -407,7 +408,8 @@ export class TransactionsManager {
|
|
407
408
|
this.client.connection,
|
408
409
|
tx,
|
409
410
|
this.simulateOnly,
|
410
|
-
attemptNum
|
411
|
+
attemptNum,
|
412
|
+
prioritySetting
|
411
413
|
);
|
412
414
|
this.updateStatus(
|
413
415
|
itemSet.name(),
|
package/src/types/solauto.ts
CHANGED
@@ -9,4 +9,11 @@ export interface SolautoPositionDetails {
|
|
9
9
|
protocolAccount?: PublicKey;
|
10
10
|
supplyMint?: PublicKey;
|
11
11
|
debtMint?: PublicKey;
|
12
|
-
}
|
12
|
+
}
|
13
|
+
|
14
|
+
export enum PriorityFeeSetting {
|
15
|
+
Default = "Medium",
|
16
|
+
High = "High"
|
17
|
+
}
|
18
|
+
|
19
|
+
export type RebalanceAction = "boost" | "repay" | "dca";
|
package/src/utils/numberUtils.ts
CHANGED
@@ -81,7 +81,7 @@ export function getMaxLiqUtilizationRate(
|
|
81
81
|
maxLtvBps: number,
|
82
82
|
liqThresholdBps: number
|
83
83
|
): number {
|
84
|
-
return toBps((fromBps(maxLtvBps) - 0.
|
84
|
+
return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
|
85
85
|
}
|
86
86
|
|
87
87
|
export function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number) {
|
package/src/utils/solanaUtils.ts
CHANGED
@@ -36,6 +36,7 @@ import {
|
|
36
36
|
getLendingAccountEndFlashloanInstructionDataSerializer,
|
37
37
|
getLendingAccountStartFlashloanInstructionDataSerializer,
|
38
38
|
} from "../marginfi-sdk";
|
39
|
+
import { PriorityFeeSetting } from "../types";
|
39
40
|
|
40
41
|
export function getSolanaRpcConnection(heliusApiKey: string): [Connection, Umi] {
|
41
42
|
const connection = new Connection(
|
@@ -255,7 +256,8 @@ async function simulateTransaction(
|
|
255
256
|
export async function getComputeUnitPriceEstimate(
|
256
257
|
umi: Umi,
|
257
258
|
tx: TransactionBuilder,
|
258
|
-
|
259
|
+
prioritySetting: PriorityFeeSetting,
|
260
|
+
attemptNum?: number,
|
259
261
|
): Promise<number> {
|
260
262
|
const web3Transaction = toWeb3JsTransaction(
|
261
263
|
(await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi)
|
@@ -265,7 +267,7 @@ export async function getComputeUnitPriceEstimate(
|
|
265
267
|
{
|
266
268
|
transaction: serializedTransaction,
|
267
269
|
options: {
|
268
|
-
priorityLevel:
|
270
|
+
priorityLevel: prioritySetting.toString(),
|
269
271
|
},
|
270
272
|
},
|
271
273
|
]);
|
@@ -279,13 +281,14 @@ export async function sendSingleOptimizedTransaction(
|
|
279
281
|
connection: Connection,
|
280
282
|
tx: TransactionBuilder,
|
281
283
|
simulateOnly?: boolean,
|
282
|
-
attemptNum?: number
|
284
|
+
attemptNum?: number,
|
285
|
+
prioritySetting: PriorityFeeSetting = PriorityFeeSetting.Default
|
283
286
|
): Promise<Uint8Array | undefined> {
|
284
287
|
console.log("Sending single optimized transaction...");
|
285
288
|
console.log("Instructions: ", tx.getInstructions().length);
|
286
289
|
console.log("Serialized transaction size: ", tx.getTransactionSize(umi));
|
287
290
|
|
288
|
-
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
|
291
|
+
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting, attemptNum);
|
289
292
|
console.log("Compute unit price: ", feeEstimate);
|
290
293
|
|
291
294
|
const simulationResult = await retryWithExponentialBackoff(
|
@@ -27,7 +27,7 @@ import {
|
|
27
27
|
getAllMarginfiAccountsByAuthority,
|
28
28
|
getMarginfiAccountPositionState,
|
29
29
|
} from "../marginfiUtils";
|
30
|
-
import { SolautoPositionDetails } from "../../types/solauto";
|
30
|
+
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
31
31
|
|
32
32
|
function newPeriodsPassed(
|
33
33
|
automation: AutomationSettings,
|
@@ -118,20 +118,20 @@ export function getSolautoFeesBps(
|
|
118
118
|
};
|
119
119
|
}
|
120
120
|
|
121
|
-
export function
|
121
|
+
export function eligibleForRebalance(
|
122
122
|
positionState: PositionState,
|
123
123
|
positionSettings: SolautoSettingsParameters,
|
124
124
|
positionDca: DCASettings
|
125
|
-
):
|
125
|
+
): RebalanceAction | undefined {
|
126
126
|
if (
|
127
127
|
positionDca.automation.targetPeriods > 0 &&
|
128
128
|
eligibleForNextAutomationPeriod(positionDca.automation)
|
129
129
|
) {
|
130
|
-
return
|
130
|
+
return 'dca';
|
131
131
|
}
|
132
132
|
|
133
133
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
134
|
-
return
|
134
|
+
return undefined;
|
135
135
|
}
|
136
136
|
|
137
137
|
const boostToBps =
|
@@ -148,15 +148,14 @@ export function eligibileForRebalance(
|
|
148
148
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
149
149
|
|
150
150
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
151
|
-
return
|
151
|
+
return 'boost';
|
152
152
|
} else if (
|
153
153
|
positionState.liqUtilizationRateBps >= repayFrom
|
154
154
|
) {
|
155
|
-
|
156
|
-
return true;
|
155
|
+
return 'repay';
|
157
156
|
}
|
158
157
|
|
159
|
-
return
|
158
|
+
return undefined;
|
160
159
|
}
|
161
160
|
|
162
161
|
export function eligibleForRefresh(
|
@@ -342,8 +342,7 @@ export function getJupSwapRebalanceDetails(
|
|
342
342
|
inputMint: toWeb3JsPublicKey(input.mint),
|
343
343
|
outputMint: toWeb3JsPublicKey(output.mint),
|
344
344
|
destinationWallet: client.solautoPosition,
|
345
|
-
|
346
|
-
slippageBpsIncFactor: (attemptNum ?? 0) * 0.2,
|
345
|
+
slippageBpsIncFactor: 0.1 + ((attemptNum ?? 0) * 0.2),
|
347
346
|
amount: rebalancingToZero
|
348
347
|
? client.solautoPositionState!.debt.amountUsed.baseUnit +
|
349
348
|
BigInt(
|
@@ -27,7 +27,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
27
27
|
|
28
28
|
const payForTransactions = false;
|
29
29
|
const useJitoBundle = false;
|
30
|
-
const positionId =
|
30
|
+
const positionId = 1;
|
31
31
|
|
32
32
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
33
33
|
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
@@ -50,14 +50,14 @@ describe("Solauto Marginfi tests", async () => {
|
|
50
50
|
);
|
51
51
|
|
52
52
|
const transactionItems: TransactionItem[] = [];
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
const settingParams: SolautoSettingsParametersInpArgs = {
|
54
|
+
boostToBps: 4000,
|
55
|
+
boostGap: 500,
|
56
|
+
repayToBps: 7456,
|
57
|
+
repayGap: 500,
|
58
|
+
automation: none(),
|
59
|
+
targetBoostToBps: none(),
|
60
|
+
};
|
61
61
|
|
62
62
|
// if (client.solautoPositionData === null) {
|
63
63
|
// transactionItems.push(
|
@@ -93,7 +93,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
93
93
|
// ...settingParams,
|
94
94
|
// boostGap: 50,
|
95
95
|
// boostToBps: maxLiqRate,
|
96
|
-
// repayGap:
|
96
|
+
// repayGap: 100,
|
97
97
|
// repayToBps: maxLiqRate
|
98
98
|
// }),
|
99
99
|
// dca: null,
|