@haven-fi/solauto-sdk 1.0.554 → 1.0.556
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/solautoClient.d.ts +2 -2
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +23 -23
- package/dist/clients/solautoMarginfiClient.js +1 -1
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +0 -4
- package/dist/transactions/transactionUtils.js +7 -7
- package/dist/utils/generalUtils.d.ts +1 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +23 -0
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +42 -30
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +5 -5
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +27 -13
- package/dist/utils/solauto/generalUtils.d.ts +4 -4
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +4 -4
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +24 -24
- package/src/clients/solautoMarginfiClient.ts +1 -1
- package/src/constants/solautoConstants.ts +0 -4
- package/src/transactions/transactionUtils.ts +7 -7
- package/src/utils/generalUtils.ts +26 -0
- package/src/utils/jitoUtils.ts +48 -37
- package/src/utils/marginfiUtils.ts +6 -6
- package/src/utils/solanaUtils.ts +31 -14
- package/src/utils/solauto/generalUtils.ts +4 -4
- package/tests/transactions/solautoMarginfi.ts +7 -7
@@ -3,7 +3,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
4
4
|
import { DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, SolautoActionArgs, SolautoPosition, SolautoRebalanceType, SolautoRebalanceTypeArgs, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, UpdatePositionDataArgs } from "../generated";
|
5
5
|
import { FlashLoanDetails, RebalanceValues } from "../utils/solauto/rebalanceUtils";
|
6
|
-
import {
|
6
|
+
import { ContextUpdates } from "../utils/solauto/generalUtils";
|
7
7
|
import { ReferralStateManager, ReferralStateManagerArgs } from "./referralStateManager";
|
8
8
|
import { QuoteResponse } from "@jup-ag/api";
|
9
9
|
export interface SolautoClientArgs extends ReferralStateManagerArgs {
|
@@ -31,7 +31,7 @@ export declare abstract class SolautoClient extends ReferralStateManager {
|
|
31
31
|
solautoFeesSupplyTa: PublicKey;
|
32
32
|
solautoFeesDebtTa: PublicKey;
|
33
33
|
authorityLutAddress?: PublicKey;
|
34
|
-
|
34
|
+
contextUpdates: ContextUpdates;
|
35
35
|
private signerSupplyBalance;
|
36
36
|
private signerDebtBalance;
|
37
37
|
initialize(args: SolautoClientArgs): Promise<void>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAEL,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAEhC,sBAAsB,EAKvB,MAAM,cAAc,CAAC;AAUtB,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM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AAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,aAAa,EAAE,oBAAoB,EACnC,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,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,eAAe,EAAE,eAAe,EAChC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAcjE,QAAQ,CAAC,wBAAwB,IAAI,MAAM;IAC3C,QAAQ,CAAC,0BAA0B,IAAI,MAAM;IAC7C,QAAQ,CAAC,sBAAsB,IAAI,MAAM;CAC1C"}
|
@@ -16,7 +16,7 @@ const referralStateManager_1 = require("./referralStateManager");
|
|
16
16
|
class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
17
17
|
constructor() {
|
18
18
|
super(...arguments);
|
19
|
-
this.
|
19
|
+
this.contextUpdates = new generalUtils_2.ContextUpdates();
|
20
20
|
}
|
21
21
|
async initialize(args) {
|
22
22
|
await super.initialize(args);
|
@@ -75,18 +75,18 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
75
75
|
this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" });
|
76
76
|
}
|
77
77
|
else {
|
78
|
-
if (this.
|
78
|
+
if (this.contextUpdates.activeDca) {
|
79
79
|
this.solautoPositionData.position.dca =
|
80
|
-
this.
|
80
|
+
this.contextUpdates.activeDca;
|
81
81
|
}
|
82
|
-
if (this.
|
82
|
+
if (this.contextUpdates.settings) {
|
83
83
|
this.solautoPositionData.position.settingParams =
|
84
|
-
this.
|
84
|
+
this.contextUpdates.settings;
|
85
85
|
}
|
86
|
-
// All other live position updates can be derived by getting a fresh position state, so we don't need to do anything else form
|
86
|
+
// All other live position updates can be derived by getting a fresh position state, so we don't need to do anything else form contextUpdates
|
87
87
|
}
|
88
88
|
}
|
89
|
-
this.
|
89
|
+
this.contextUpdates.reset();
|
90
90
|
}
|
91
91
|
defaultLookupTables() {
|
92
92
|
return [
|
@@ -185,11 +185,11 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
185
185
|
};
|
186
186
|
}
|
187
187
|
solautoPositionSettings() {
|
188
|
-
return (this.
|
188
|
+
return (this.contextUpdates.settings ??
|
189
189
|
this.solautoPositionData?.position.settingParams);
|
190
190
|
}
|
191
191
|
solautoPositionActiveDca() {
|
192
|
-
return (this.
|
192
|
+
return (this.contextUpdates.activeDca ??
|
193
193
|
this.solautoPositionData?.position.dca);
|
194
194
|
}
|
195
195
|
async maxLtvAndLiqThresholdBps() {
|
@@ -200,7 +200,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
200
200
|
}
|
201
201
|
openPosition(settingParams, dca) {
|
202
202
|
if (dca && dca.dcaInBaseUnit > 0) {
|
203
|
-
this.
|
203
|
+
this.contextUpdates.new({
|
204
204
|
type: "dcaInBalance",
|
205
205
|
value: {
|
206
206
|
amount: BigInt(dca.dcaInBaseUnit),
|
@@ -209,13 +209,13 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
209
209
|
});
|
210
210
|
}
|
211
211
|
if (settingParams) {
|
212
|
-
this.
|
212
|
+
this.contextUpdates.new({
|
213
213
|
type: "settings",
|
214
214
|
value: settingParams,
|
215
215
|
});
|
216
216
|
}
|
217
217
|
if (dca) {
|
218
|
-
this.
|
218
|
+
this.contextUpdates.new({
|
219
219
|
type: "dca",
|
220
220
|
value: dca,
|
221
221
|
});
|
@@ -240,7 +240,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
240
240
|
if ((0, umi_1.isOption)(args.dca) &&
|
241
241
|
(0, umi_1.isSome)(args.dca) &&
|
242
242
|
args.dca.value.dcaInBaseUnit > 0) {
|
243
|
-
this.
|
243
|
+
this.contextUpdates.new({
|
244
244
|
type: "dcaInBalance",
|
245
245
|
value: {
|
246
246
|
amount: BigInt(args.dca.value.dcaInBaseUnit),
|
@@ -250,13 +250,13 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
250
250
|
}
|
251
251
|
}
|
252
252
|
if ((0, umi_1.isOption)(args.settingParams) && (0, umi_1.isSome)(args.settingParams)) {
|
253
|
-
this.
|
253
|
+
this.contextUpdates.new({
|
254
254
|
type: "settings",
|
255
255
|
value: args.settingParams.value,
|
256
256
|
});
|
257
257
|
}
|
258
258
|
if ((0, umi_1.isOption)(args.dca) && (0, umi_1.isSome)(args.dca)) {
|
259
|
-
this.
|
259
|
+
this.contextUpdates.new({
|
260
260
|
type: "dca",
|
261
261
|
value: args.dca.value,
|
262
262
|
});
|
@@ -297,7 +297,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
297
297
|
positionDcaTa = (0, umi_1.publicKey)(this.positionDebtTa);
|
298
298
|
signerDcaTa = (0, umi_1.publicKey)(this.signerDebtTa);
|
299
299
|
}
|
300
|
-
this.
|
300
|
+
this.contextUpdates.new({
|
301
301
|
type: "cancellingDca",
|
302
302
|
value: this.solautoPositionData.position.dca.tokenType,
|
303
303
|
});
|
@@ -327,20 +327,20 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
327
327
|
}
|
328
328
|
}
|
329
329
|
if (args.__kind === "Deposit") {
|
330
|
-
this.
|
330
|
+
this.contextUpdates.new({
|
331
331
|
type: "supply",
|
332
332
|
value: BigInt(args.fields[0]),
|
333
333
|
});
|
334
334
|
}
|
335
335
|
else if (args.__kind === "Withdraw") {
|
336
336
|
if (args.fields[0].__kind === "Some") {
|
337
|
-
this.
|
337
|
+
this.contextUpdates.new({
|
338
338
|
type: "supply",
|
339
339
|
value: BigInt(args.fields[0].fields[0]) * BigInt(-1),
|
340
340
|
});
|
341
341
|
}
|
342
342
|
else {
|
343
|
-
this.
|
343
|
+
this.contextUpdates.new({
|
344
344
|
type: "supply",
|
345
345
|
value: (this.solautoPositionState?.supply.amountUsed.baseUnit ??
|
346
346
|
BigInt(0)) * BigInt(-1),
|
@@ -348,20 +348,20 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
348
348
|
}
|
349
349
|
}
|
350
350
|
else if (args.__kind === "Borrow") {
|
351
|
-
this.
|
351
|
+
this.contextUpdates.new({
|
352
352
|
type: "debt",
|
353
353
|
value: BigInt(args.fields[0]),
|
354
354
|
});
|
355
355
|
}
|
356
356
|
else {
|
357
357
|
if (args.fields[0].__kind === "Some") {
|
358
|
-
this.
|
358
|
+
this.contextUpdates.new({
|
359
359
|
type: "debt",
|
360
360
|
value: BigInt(args.fields[0].fields[0]) * BigInt(-1),
|
361
361
|
});
|
362
362
|
}
|
363
363
|
else {
|
364
|
-
this.
|
364
|
+
this.contextUpdates.new({
|
365
365
|
type: "debt",
|
366
366
|
value: (this.solautoPositionState?.debt.amountUsed.baseUnit ?? BigInt(0)) *
|
367
367
|
BigInt(-1),
|
@@ -375,7 +375,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
375
375
|
Boolean(this.solautoPositionState) &&
|
376
376
|
Number(this.solautoPositionState.lastUpdated) >
|
377
377
|
(0, generalUtils_1.currentUnixSeconds)() - solautoConstants_1.MIN_POSITION_STATE_FRESHNESS_SECS &&
|
378
|
-
!this.
|
378
|
+
!this.contextUpdates.positionUpdates()) {
|
379
379
|
return this.solautoPositionState;
|
380
380
|
}
|
381
381
|
return undefined;
|
@@ -467,7 +467,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
467
467
|
const useDesignatedMint = !this.selfManaged &&
|
468
468
|
(this.solautoPositionData === null ||
|
469
469
|
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey).equals(this.authority));
|
470
|
-
const resp = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.marginfiAccountPk }, this.marginfiGroup, useDesignatedMint ? { mint: this.supplyMint } : undefined, useDesignatedMint ? { mint: this.debtMint } : undefined, this.
|
470
|
+
const resp = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.marginfiAccountPk }, this.marginfiGroup, useDesignatedMint ? { mint: this.supplyMint } : undefined, useDesignatedMint ? { mint: this.debtMint } : undefined, this.contextUpdates);
|
471
471
|
if (resp) {
|
472
472
|
this.supplyBank = resp?.supplyBank;
|
473
473
|
this.debtBank = resp?.debtBank;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AAEzE,eAAO,MAAM,iBAAiB,UAS7B,CAAC;
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AAEzE,eAAO,MAAM,iBAAiB,UAS7B,CAAC;AAEF,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC;AAG3B,eAAO,MAAM,aAAa,UAOzB,CAAA"}
|
@@ -26,10 +26,6 @@ exports.JITO_TIP_ACCOUNTS = [
|
|
26
26
|
"DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL",
|
27
27
|
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT",
|
28
28
|
];
|
29
|
-
// "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
|
30
|
-
// "J97FEQeJzChRnaAjNy3dRvm9FBavKqAdxo8jKXzw17ut"
|
31
|
-
// "ByhmNseaYZXBDcBm6xhbgarwixgjym6H4ddLsvgoL3BL"
|
32
|
-
// "2VJK8AHqtiaiJKYbBtFr3EHV4Hcy1FHCiEYQFmUvxot8"
|
33
29
|
exports.SOLAUTO_LUT = "8b7KefQDroVLGao71J5H3hFwABeyMCgCrLpXWssNFhk9";
|
34
30
|
exports.STANDARD_LUT_ACCOUNTS = [
|
35
31
|
web3_js_1.PublicKey.default,
|
@@ -323,10 +323,10 @@ async function getTransactionChores(client, tx) {
|
|
323
323
|
const accountsGettingCreated = [];
|
324
324
|
const solautoActions = getSolautoActions(client.umi, tx);
|
325
325
|
choresBefore = choresBefore.add([
|
326
|
-
await transactionChoresBefore(client, accountsGettingCreated, solautoActions, client.
|
326
|
+
await transactionChoresBefore(client, accountsGettingCreated, solautoActions, client.contextUpdates.dcaInBalance),
|
327
327
|
await rebalanceChoresBefore(client, tx, accountsGettingCreated),
|
328
328
|
]);
|
329
|
-
choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.
|
329
|
+
choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.contextUpdates.cancellingDca));
|
330
330
|
return [choresBefore, choresAfter];
|
331
331
|
}
|
332
332
|
async function requiresRefreshBeforeRebalance(client) {
|
@@ -341,16 +341,16 @@ async function requiresRefreshBeforeRebalance(client) {
|
|
341
341
|
return true;
|
342
342
|
}
|
343
343
|
else if (client.solautoPositionData && !client.selfManaged) {
|
344
|
-
if (client.
|
345
|
-
client.
|
344
|
+
if (client.contextUpdates.supplyAdjustment > BigInt(0) ||
|
345
|
+
client.contextUpdates.debtAdjustment > BigInt(0)) {
|
346
346
|
return false;
|
347
347
|
}
|
348
348
|
const oldStateWithLatestPrices = await (0, generalUtils_2.positionStateWithLatestPrices)(client.solautoPositionData.state, constants_1.PRICES[client.supplyMint.toString()].price, constants_1.PRICES[client.debtMint.toString()].price);
|
349
349
|
const utilizationRateDiff = Math.abs((client.solautoPositionState?.liqUtilizationRateBps ?? 0) -
|
350
350
|
oldStateWithLatestPrices.liqUtilizationRateBps);
|
351
351
|
client.log("Liq utilization rate diff:", utilizationRateDiff);
|
352
|
-
if (client.
|
353
|
-
client.
|
352
|
+
if (client.contextUpdates.supplyAdjustment === BigInt(0) &&
|
353
|
+
client.contextUpdates.debtAdjustment === BigInt(0) &&
|
354
354
|
utilizationRateDiff >= 10) {
|
355
355
|
client.log("Choosing to refresh before rebalance. Utilization rate diff:", utilizationRateDiff);
|
356
356
|
return true;
|
@@ -365,7 +365,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
365
365
|
const supplyPrice = (0, utils_1.safeGetPrice)(client.supplyMint) ?? 0;
|
366
366
|
const debtPrice = (0, utils_1.safeGetPrice)(client.debtMint) ?? 0;
|
367
367
|
if ((client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) &&
|
368
|
-
client.
|
368
|
+
client.contextUpdates.supplyAdjustment === BigInt(0)) ||
|
369
369
|
(targetLiqUtilizationRateBps === undefined &&
|
370
370
|
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), supplyPrice, debtPrice))) {
|
371
371
|
client.log("Not eligible for a rebalance");
|
@@ -15,4 +15,5 @@ export declare function zip<T, U>(list1: T[], list2: U[]): [T, U][];
|
|
15
15
|
export type ErrorsToThrow = Array<new (...args: any[]) => Error>;
|
16
16
|
export declare function retryWithExponentialBackoff<T>(fn: (attemptNum: number, prevErr?: Error) => Promise<T>, retries?: number, delay?: number, errorsToThrow?: ErrorsToThrow): Promise<T>;
|
17
17
|
export declare function toEnumValue<E extends object>(enumObj: E, value: number): E[keyof E] | undefined;
|
18
|
+
export declare function customRpcCall(umi: Umi, method: string, params?: any): Promise<any>;
|
18
19
|
//# sourceMappingURL=generalUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAc,SAAS,EAAE,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SA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AAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,MAAM,GACZ,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAUxB;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,gBAuBzE"}
|
@@ -1,4 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.consoleLog = consoleLog;
|
4
7
|
exports.tokenInfo = tokenInfo;
|
@@ -13,9 +16,11 @@ exports.arraysAreEqual = arraysAreEqual;
|
|
13
16
|
exports.zip = zip;
|
14
17
|
exports.retryWithExponentialBackoff = retryWithExponentialBackoff;
|
15
18
|
exports.toEnumValue = toEnumValue;
|
19
|
+
exports.customRpcCall = customRpcCall;
|
16
20
|
const web3_js_1 = require("@solana/web3.js");
|
17
21
|
const umi_1 = require("@metaplex-foundation/umi");
|
18
22
|
const constants_1 = require("../constants");
|
23
|
+
const axios_1 = __importDefault(require("axios"));
|
19
24
|
function consoleLog(...args) {
|
20
25
|
if (globalThis.LOCAL_TEST) {
|
21
26
|
console.log(...args);
|
@@ -120,3 +125,21 @@ function toEnumValue(enumObj, value) {
|
|
120
125
|
}
|
121
126
|
return undefined;
|
122
127
|
}
|
128
|
+
async function customRpcCall(umi, method, params) {
|
129
|
+
const data = (await axios_1.default.post(umi.rpc.getEndpoint(), {
|
130
|
+
jsonrpc: "2.0",
|
131
|
+
id: 1,
|
132
|
+
method,
|
133
|
+
params,
|
134
|
+
}, {
|
135
|
+
headers: {
|
136
|
+
"Content-Type": "application/json",
|
137
|
+
},
|
138
|
+
})).data;
|
139
|
+
if ("result" in data) {
|
140
|
+
return data.result;
|
141
|
+
}
|
142
|
+
else {
|
143
|
+
return data;
|
144
|
+
}
|
145
|
+
}
|
@@ -1 +1 @@
|
|
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;AAMzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;
|
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;AAMzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAYlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AA4OD,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,CA+F/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -46,28 +46,45 @@ function parseJitoErrorMessage(message) {
|
|
46
46
|
}
|
47
47
|
async function simulateJitoBundle(umi, txs) {
|
48
48
|
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
49
|
-
const
|
50
|
-
|
51
|
-
|
52
|
-
method: "simulateBundle",
|
53
|
-
params: [
|
54
|
-
{
|
55
|
-
encodedTransactions: txs.map((x) => Buffer.from(x.serialize()).toString("base64")),
|
56
|
-
},
|
57
|
-
{
|
58
|
-
encoding: "base64",
|
59
|
-
commitment: "confirmed",
|
60
|
-
preExecutionAccountsConfigs: txs.map((_) => { }),
|
61
|
-
postExecutionAccountsConfigs: txs.map((_) => { }),
|
62
|
-
skipSigVerify: true,
|
63
|
-
},
|
64
|
-
],
|
65
|
-
}, {
|
66
|
-
headers: {
|
67
|
-
"Content-Type": "application/json",
|
49
|
+
const res = await (0, generalUtils_1.customRpcCall)(umi, "simulateBundle", [
|
50
|
+
{
|
51
|
+
encodedTransactions: txs.map((x) => Buffer.from(x.serialize()).toString("base64")),
|
68
52
|
},
|
69
|
-
|
70
|
-
|
53
|
+
{
|
54
|
+
encoding: "base64",
|
55
|
+
commitment: "confirmed",
|
56
|
+
preExecutionAccountsConfigs: txs.map((_) => { }),
|
57
|
+
postExecutionAccountsConfigs: txs.map((_) => { }),
|
58
|
+
skipSigVerify: true,
|
59
|
+
},
|
60
|
+
]);
|
61
|
+
// const resp = await axios.post(
|
62
|
+
// umi.rpc.getEndpoint(),
|
63
|
+
// {
|
64
|
+
// jsonrpc: "2.0",
|
65
|
+
// id: 1,
|
66
|
+
// method: "simulateBundle",
|
67
|
+
// params: [
|
68
|
+
// {
|
69
|
+
// encodedTransactions: txs.map((x) =>
|
70
|
+
// Buffer.from(x.serialize()).toString("base64")
|
71
|
+
// ),
|
72
|
+
// },
|
73
|
+
// {
|
74
|
+
// encoding: "base64",
|
75
|
+
// commitment: "confirmed",
|
76
|
+
// preExecutionAccountsConfigs: txs.map((_) => {}),
|
77
|
+
// postExecutionAccountsConfigs: txs.map((_) => {}),
|
78
|
+
// skipSigVerify: true,
|
79
|
+
// },
|
80
|
+
// ],
|
81
|
+
// },
|
82
|
+
// {
|
83
|
+
// headers: {
|
84
|
+
// "Content-Type": "application/json",
|
85
|
+
// },
|
86
|
+
// }
|
87
|
+
// );
|
71
88
|
if (res.result && res.result.value && res.result.value.summary.failed) {
|
72
89
|
const resValue = res.result.value;
|
73
90
|
const transactionResults = resValue.transactionResults;
|
@@ -120,16 +137,11 @@ async function umiToVersionedTransactions(umi, blockhash, userSigner, otherSigne
|
|
120
137
|
return builtTxs.map((x) => (0, umi_web3js_adapters_1.toWeb3JsTransaction)(x));
|
121
138
|
}
|
122
139
|
async function getBundleStatus(umi, bundleId) {
|
123
|
-
const res = await
|
124
|
-
|
125
|
-
|
126
|
-
method: "getBundleStatuses",
|
127
|
-
params: [[bundleId]],
|
128
|
-
});
|
129
|
-
if (res.data.error) {
|
130
|
-
throw new Error(`Failed to get bundle status: ${res.data.error}`);
|
140
|
+
const res = await (0, generalUtils_1.customRpcCall)(umi, "getBundleStatuses", [[bundleId]]);
|
141
|
+
if (res.error) {
|
142
|
+
throw new Error(`Failed to get bundle status: ${res.error}`);
|
131
143
|
}
|
132
|
-
return res.
|
144
|
+
return res.result;
|
133
145
|
}
|
134
146
|
async function pollBundleStatus(umi, bundleId, interval = 1000, timeout = 40000) {
|
135
147
|
const endTime = Date.now() + timeout;
|
@@ -3,7 +3,7 @@ import { Umi } from "@metaplex-foundation/umi";
|
|
3
3
|
import { Bank, MarginfiAccount } from "../marginfi-sdk";
|
4
4
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
5
5
|
import { PositionState } from "../generated";
|
6
|
-
import {
|
6
|
+
import { ContextUpdates } from "./solauto/generalUtils";
|
7
7
|
interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {
|
8
8
|
mint: PublicKey;
|
9
9
|
}
|
@@ -34,7 +34,7 @@ type BanksCache = {
|
|
34
34
|
export declare function getMarginfiAccountPositionState(umi: Umi, protocolAccount: {
|
35
35
|
pk: PublicKey;
|
36
36
|
data?: MarginfiAccount;
|
37
|
-
}, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection,
|
37
|
+
}, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection, contextUpdates?: ContextUpdates): Promise<{
|
38
38
|
supplyBank: Bank | null;
|
39
39
|
debtBank: Bank | null;
|
40
40
|
state: PositionState;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAGJ,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAGJ,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAIxD,UAAU,wBAAyB,SAAQ,qBAAqB;IAC9D,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GACd,wBAAwB,CAY1B;AAED,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE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AAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CACN;IAAE,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,GACxE,SAAS,CACZ,CAiMA;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE"}
|
@@ -165,7 +165,7 @@ async function getTokenUsage(bank, isAsset, shares, amountUsedAdjustment) {
|
|
165
165
|
padding: new Uint8Array([]),
|
166
166
|
};
|
167
167
|
}
|
168
|
-
async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGroup, supply, debt,
|
168
|
+
async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGroup, supply, debt, contextUpdates) {
|
169
169
|
let marginfiAccount = protocolAccount.data ??
|
170
170
|
(await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(protocolAccount.pk), {
|
171
171
|
commitment: "confirmed",
|
@@ -208,7 +208,7 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
208
208
|
if (!supply.mint) {
|
209
209
|
supply.mint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint);
|
210
210
|
}
|
211
|
-
supplyUsage = await getTokenUsage(supplyBank, true, (0, numberUtils_1.bytesToI80F48)(supplyBalances[0].assetShares.value),
|
211
|
+
supplyUsage = await getTokenUsage(supplyBank, true, (0, numberUtils_1.bytesToI80F48)(supplyBalances[0].assetShares.value), contextUpdates?.supplyAdjustment);
|
212
212
|
}
|
213
213
|
if (debtBalances.length > 0) {
|
214
214
|
if (debtBank === null) {
|
@@ -219,14 +219,14 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
219
219
|
if (!debt.mint) {
|
220
220
|
debt.mint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(debtBank.mint);
|
221
221
|
}
|
222
|
-
debtUsage = await getTokenUsage(debtBank, false, (0, numberUtils_1.bytesToI80F48)(debtBalances[0].liabilityShares.value),
|
222
|
+
debtUsage = await getTokenUsage(debtBank, false, (0, numberUtils_1.bytesToI80F48)(debtBalances[0].liabilityShares.value), contextUpdates?.debtAdjustment);
|
223
223
|
}
|
224
224
|
}
|
225
225
|
if (supplyBank === null) {
|
226
226
|
return undefined;
|
227
227
|
}
|
228
228
|
if (!supplyUsage) {
|
229
|
-
supplyUsage = await getTokenUsage(supplyBank, true, 0,
|
229
|
+
supplyUsage = await getTokenUsage(supplyBank, true, 0, contextUpdates?.supplyAdjustment);
|
230
230
|
}
|
231
231
|
if (debtBank === null) {
|
232
232
|
return undefined;
|
@@ -243,7 +243,7 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
243
243
|
return undefined;
|
244
244
|
}
|
245
245
|
if (!debtUsage) {
|
246
|
-
debtUsage = await getTokenUsage(debtBank, false, 0,
|
246
|
+
debtUsage = await getTokenUsage(debtBank, false, 0, contextUpdates?.debtAdjustment);
|
247
247
|
}
|
248
248
|
const supplyPrice = (0, priceUtils_1.safeGetPrice)(supply.mint);
|
249
249
|
let [maxLtv, liqThreshold] = await getMarginfiMaxLtvAndLiqThreshold(umi, marginfiGroup ?? new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP), {
|
@@ -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,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const solauto_1 = require("./solauto");
|
33
33
|
const constants_1 = require("../constants");
|
34
|
-
const axios_1 = __importDefault(require("axios"));
|
35
34
|
function buildHeliusApiUrl(heliusApiKey) {
|
36
35
|
return `https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`;
|
37
36
|
}
|
@@ -153,15 +152,10 @@ async function simulateTransaction(umi, connection, transaction) {
|
|
153
152
|
return simulationResult;
|
154
153
|
}
|
155
154
|
async function getQnComputeUnitPriceEstimate(umi, programId, blockheight = 50) {
|
156
|
-
return
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
params: {
|
161
|
-
last_n_blocks: blockheight,
|
162
|
-
account: programId.toString(),
|
163
|
-
},
|
164
|
-
})).data;
|
155
|
+
return await (0, generalUtils_1.customRpcCall)(umi, "qn_estimatePriorityFees", {
|
156
|
+
last_n_blocks: blockheight,
|
157
|
+
account: programId.toString(),
|
158
|
+
});
|
165
159
|
}
|
166
160
|
async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, useAccounts) {
|
167
161
|
const web3Transaction = (0, umi_web3js_adapters_1.toWeb3JsTransaction)((await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi));
|
@@ -170,7 +164,7 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, useAccounts
|
|
170
164
|
.flatMap((x) => x.keys.flatMap((x) => x.pubkey.toString()));
|
171
165
|
let feeEstimate;
|
172
166
|
try {
|
173
|
-
const resp = await
|
167
|
+
const resp = await (0, generalUtils_1.customRpcCall)(umi, "getPriorityFeeEstimate", [
|
174
168
|
{
|
175
169
|
transaction: !useAccounts
|
176
170
|
? bs58_1.default.encode(web3Transaction.serialize())
|
@@ -181,11 +175,23 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, useAccounts
|
|
181
175
|
},
|
182
176
|
},
|
183
177
|
]);
|
178
|
+
// const resp = await umi.rpc.call("getPriorityFeeEstimate", [
|
179
|
+
// {
|
180
|
+
// transaction: !useAccounts
|
181
|
+
// ? bs58.encode(web3Transaction.serialize())
|
182
|
+
// : undefined,
|
183
|
+
// accountKeys: useAccounts ? accountKeys : undefined,
|
184
|
+
// options: {
|
185
|
+
// priorityLevel: prioritySetting.toString(),
|
186
|
+
// },
|
187
|
+
// },
|
188
|
+
// ]);
|
184
189
|
feeEstimate = Math.round(resp.priorityFeeEstimate);
|
190
|
+
console.log(resp);
|
185
191
|
}
|
186
192
|
catch (e) {
|
187
193
|
try {
|
188
|
-
const resp = await
|
194
|
+
const resp = await (0, generalUtils_1.customRpcCall)(umi, "getPriorityFeeEstimate", [
|
189
195
|
{
|
190
196
|
accountKeys,
|
191
197
|
options: {
|
@@ -193,6 +199,14 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, useAccounts
|
|
193
199
|
},
|
194
200
|
},
|
195
201
|
]);
|
202
|
+
// const resp = await umi.rpc.call("getPriorityFeeEstimate", [
|
203
|
+
// {
|
204
|
+
// accountKeys,
|
205
|
+
// options: {
|
206
|
+
// priorityLevel: prioritySetting.toString(),
|
207
|
+
// },
|
208
|
+
// },
|
209
|
+
// ]);
|
196
210
|
feeEstimate = Math.round(resp.priorityFeeEstimate);
|
197
211
|
}
|
198
212
|
catch (e) {
|
@@ -235,7 +249,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, prior
|
|
235
249
|
(0, generalUtils_1.consoleLog)("Sending single optimized transaction...");
|
236
250
|
(0, generalUtils_1.consoleLog)("Instructions: ", tx.getInstructions().length);
|
237
251
|
(0, generalUtils_1.consoleLog)("Serialized transaction size: ", tx.getTransactionSize(umi));
|
238
|
-
(0, generalUtils_1.consoleLog)("Programs: ", tx.getInstructions().map(x => x.programId));
|
252
|
+
(0, generalUtils_1.consoleLog)("Programs: ", tx.getInstructions().map((x) => x.programId));
|
239
253
|
const accounts = tx
|
240
254
|
.getInstructions()
|
241
255
|
.flatMap((x) => [
|
@@ -24,7 +24,7 @@ interface AssetProps {
|
|
24
24
|
}
|
25
25
|
export declare function createFakePositionState(supply: AssetProps, debt: AssetProps, maxLtvBps: number, liqThresholdBps: number): PositionState;
|
26
26
|
export declare function createSolautoSettings(settings: SolautoSettingsParametersInpArgs): SolautoSettingsParameters;
|
27
|
-
type
|
27
|
+
type ContextAdjustment = {
|
28
28
|
type: "supply";
|
29
29
|
value: bigint;
|
30
30
|
} | {
|
@@ -49,7 +49,7 @@ type PositionAdjustment = {
|
|
49
49
|
type: "jupSwap";
|
50
50
|
value: QuoteResponse;
|
51
51
|
};
|
52
|
-
export declare class
|
52
|
+
export declare class ContextUpdates {
|
53
53
|
supplyAdjustment: bigint;
|
54
54
|
debtAdjustment: bigint;
|
55
55
|
settings: SolautoSettingsParameters | undefined;
|
@@ -60,9 +60,9 @@ export declare class LivePositionUpdates {
|
|
60
60
|
};
|
61
61
|
cancellingDca: TokenType | undefined;
|
62
62
|
jupSwap: QuoteResponse | undefined;
|
63
|
-
new(update:
|
63
|
+
new(update: ContextAdjustment): void;
|
64
64
|
reset(): void;
|
65
|
-
|
65
|
+
positionUpdates(): boolean;
|
66
66
|
}
|
67
67
|
export {};
|
68
68
|
//# sourceMappingURL=generalUtils.d.ts.map
|