@haven-fi/solauto-sdk 1.0.50 → 1.0.51
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/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 +4 -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/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/transactionsManager.ts +4 -2
- package/src/types/solauto.ts +5 -0
- package/src/utils/numberUtils.ts +1 -1
- package/src/utils/solanaUtils.ts +7 -4
- 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","sour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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) {
|
@@ -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,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,cAAM,YAAY;IAIJ,OAAO,CAAC,MAAM;IAH1B,WAAW,EAAE,MAAM,EAAE,CAAM;IAC3B,KAAK,EAAE,uBAAuB,EAAE,CAAM;gBAElB,MAAM,EAAE,aAAa;IAInC,YAAY,CAChB,mBAAmB,EAAE,MAAM,EAAE,GAC5B,OAAO,CAAC,uBAAuB,EAAE,CAAC;CAqBtC;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;QAAE,EAAE,EAAE,kBAAkB,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CACxE;IACM,IAAI,CAAC;IATd,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;gBAGf,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;Q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C,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
@@ -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"}
|
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,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAGL,UAAU,EACV,SAAS,EAIT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;
|
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,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAGL,UAAU,EACV,SAAS,EAIT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAYzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAO9E;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAQxE;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,sBAAsB,GACzB,kBAAkB,CAMpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,kBAAkB,CAOpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAOpB;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,kBAAkB,CAUpB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,SAAS,EACtB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CASpB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,EACvB,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAKpB;AAED,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 +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> {
|
@@ -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
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(
|
@@ -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,
|