@haven-fi/solauto-sdk 1.0.139 → 1.0.141

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@ declare class LookupTables {
9
9
  cache: AddressLookupTableInput[];
10
10
  constructor(defaultLuts: string[], umi: Umi);
11
11
  getLutInputs(additionalAddresses: string[]): Promise<AddressLookupTableInput[]>;
12
+ reset(): void;
12
13
  }
13
14
  export declare class TransactionItem {
14
15
  fetchTx: (attemptNum: number) => Promise<{
@@ -42,12 +43,14 @@ export declare enum TransactionStatus {
42
43
  Skipped = "Skipped",
43
44
  Processing = "Processing",
44
45
  Queued = "Queued",
45
- Successful = "Successful"
46
+ Successful = "Successful",
47
+ Failed = "Failed"
46
48
  }
47
49
  export type TransactionManagerStatuses = {
48
50
  name: string;
49
51
  status: TransactionStatus;
50
52
  txSig?: string;
53
+ attemptNum: number;
51
54
  }[];
52
55
  export declare class TransactionsManager {
53
56
  private txHandler;
@@ -59,10 +62,10 @@ export declare class TransactionsManager {
59
62
  private lookupTables;
60
63
  constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined);
61
64
  private assembleTransactionSets;
62
- updateStatus(name: string, status: TransactionStatus, txSig?: string): void;
65
+ updateStatus(name: string, status: TransactionStatus, attemptNum: number, txSig?: string): void;
63
66
  debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder): Promise<void>;
64
- clientSend(transactions: TransactionItem[], prioritySetting?: PriorityFeeSetting): Promise<void>;
65
- send(items: TransactionItem[], prioritySetting?: PriorityFeeSetting, initialized?: boolean): Promise<void>;
67
+ clientSend(transactions: TransactionItem[], prioritySetting?: PriorityFeeSetting): Promise<TransactionManagerStatuses>;
68
+ send(items: TransactionItem[], prioritySetting?: PriorityFeeSetting, initialized?: boolean): Promise<TransactionManagerStatuses>;
66
69
  }
67
70
  export {};
68
71
  //# 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,EAEvB,kBAAkB,EAClB,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG7D,cAAM,YAAY;IAIP,WAAW,EAAE,MAAM,EAAE;IAC5B,OAAO,CAAC,GAAG;IAJb,KAAK,EAAE,uBAAuB,EAAE,CAAM;gBAG7B,WAAW,EAAE,MAAM,EAAE,EACpB,GAAG,EAAE,GAAG;IAGZ,YAAY,CAChB,mBAAmB,EAAE,MAAM,EAAE,GAC5B,OAAO,CAAC,uBAAuB,EAAE,CAAC;CAiBtC;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,EAAE,MAAM;IATtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;gBAGf,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,EACM,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAIV,OAAO,CAAC,UAAU,EAAE,MAAM;IAMhC,cAAc,IAAI,MAAM,EAAE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;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,aAAa,CAAC,EAAE,aAAa,YAAA;YAQzB,uBAAuB;IAwCrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAiBlF,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IAoB7D,UAAU,CACd,YAAY,EAAE,eAAe,EAAE,EAC/B,eAAe,CAAC,EAAE,kBAAkB,GACnC,OAAO,CAAC,0BAA0B,CAAC;IAmFhC,IAAI,CACR,KAAK,EAAE,eAAe,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,EACpC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,0BAA0B,CAAC;CAgHvC"}
@@ -26,6 +26,9 @@ class LookupTables {
26
26
  }
27
27
  return this.cache;
28
28
  }
29
+ reset() {
30
+ this.cache = this.cache.filter(x => this.defaultLuts.includes(x.publicKey.toString()));
31
+ }
29
32
  }
30
33
  class TransactionItem {
31
34
  constructor(fetchTx, name) {
@@ -113,6 +116,7 @@ var TransactionStatus;
113
116
  TransactionStatus["Processing"] = "Processing";
114
117
  TransactionStatus["Queued"] = "Queued";
115
118
  TransactionStatus["Successful"] = "Successful";
119
+ TransactionStatus["Failed"] = "Failed";
116
120
  })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
117
121
  class TransactionsManager {
118
122
  constructor(txHandler, statusCallback, txType, mustBeAtomic, errorsToThrow) {
@@ -155,18 +159,18 @@ class TransactionsManager {
155
159
  }
156
160
  return transactionSets;
157
161
  }
158
- updateStatus(name, status, txSig) {
162
+ updateStatus(name, status, attemptNum, txSig) {
159
163
  if (!this.statuses.filter((x) => x.name === name)) {
160
- this.statuses.push({ name, status, txSig });
164
+ this.statuses.push({ name, status, txSig, attemptNum });
161
165
  }
162
166
  else {
163
- const idx = this.statuses.findIndex((x) => x.name === name);
167
+ const idx = this.statuses.findIndex((x) => x.name === name && x.attemptNum === attemptNum);
164
168
  if (idx !== -1) {
165
169
  this.statuses[idx].status = status;
166
170
  this.statuses[idx].txSig = txSig;
167
171
  }
168
172
  else {
169
- this.statuses.push({ name, status, txSig });
173
+ this.statuses.push({ name, status, txSig, attemptNum });
170
174
  }
171
175
  }
172
176
  this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
@@ -196,9 +200,17 @@ class TransactionsManager {
196
200
  if (updateLookupTable &&
197
201
  updateLookupTable.updateLutTx.getInstructions().length > 0 &&
198
202
  updateLookupTable?.needsToBeIsolated) {
199
- this.updateStatus(updateLutTxName, TransactionStatus.Processing);
200
- await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.txType, attemptNum, prioritySetting), 3, 150, this.errorsToThrow);
201
- this.updateStatus(updateLutTxName, TransactionStatus.Successful);
203
+ await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => {
204
+ this.updateStatus(updateLutTxName, TransactionStatus.Processing, attemptNum);
205
+ try {
206
+ const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.txType, attemptNum, prioritySetting);
207
+ this.updateStatus(updateLutTxName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
208
+ }
209
+ catch (e) {
210
+ this.updateStatus(updateLutTxName, TransactionStatus.Failed, attemptNum);
211
+ throw e;
212
+ }
213
+ }, 3, 150, this.errorsToThrow);
202
214
  }
203
215
  this.lookupTables.defaultLuts = client.defaultLookupTables();
204
216
  for (const item of items) {
@@ -217,20 +229,23 @@ class TransactionsManager {
217
229
  this.txHandler.log("Chores before: ", choresBefore.getInstructions().length);
218
230
  }
219
231
  if (choresAfter.getInstructions().length > 0) {
220
- const chore = new TransactionItem(async () => ({ tx: choresAfter }), "close temp accounts");
232
+ const chore = new TransactionItem(async () => ({ tx: choresAfter }));
221
233
  await chore.initialize();
222
234
  items.push(chore);
223
235
  this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
224
236
  }
225
- await this.send(items, prioritySetting, true).catch((e) => {
237
+ const result = await this.send(items, prioritySetting, true).catch((e) => {
226
238
  client.resetLiveTxUpdates(false);
227
239
  throw e;
228
240
  });
229
241
  if (this.txType !== "only-simulate") {
230
242
  await client.resetLiveTxUpdates();
231
243
  }
244
+ return result;
232
245
  }
233
246
  async send(items, prioritySetting, initialized) {
247
+ this.statuses = [];
248
+ this.lookupTables.reset();
234
249
  if (!initialized) {
235
250
  for (const item of items) {
236
251
  await item.initialize();
@@ -239,7 +254,7 @@ class TransactionsManager {
239
254
  const itemSets = await this.assembleTransactionSets(items);
240
255
  const statusesStartIdx = this.statuses.length;
241
256
  for (const itemSet of itemSets) {
242
- this.updateStatus(itemSet.name(), TransactionStatus.Queued);
257
+ this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
243
258
  }
244
259
  if (this.mustBeAtomic && itemSets.length > 1) {
245
260
  throw new Error(`${itemSets.length} transactions required but jito bundles are not currently supported`);
@@ -271,6 +286,7 @@ class TransactionsManager {
271
286
  this.statuses.splice(statusesStartIdx + i, itemSets.length - i, ...newItemSets.map((x) => ({
272
287
  name: x.name(),
273
288
  status: TransactionStatus.Queued,
289
+ attemptNum: 0.
274
290
  })));
275
291
  this.txHandler.log(this.statuses);
276
292
  itemSets.splice(i + 1, itemSets.length - i - 1, ...newItemSets.slice(1));
@@ -288,19 +304,20 @@ class TransactionsManager {
288
304
  }
289
305
  const tx = await itemSet.getSingleTransaction();
290
306
  if (tx.getInstructions().length === 0) {
291
- this.updateStatus(itemSet.name(), TransactionStatus.Skipped);
307
+ this.updateStatus(itemSet.name(), TransactionStatus.Skipped, attemptNum);
292
308
  }
293
309
  else {
294
- this.updateStatus(itemSet.name(), TransactionStatus.Processing);
310
+ this.updateStatus(itemSet.name(), TransactionStatus.Processing, attemptNum);
295
311
  if (this.txHandler.localTest) {
296
312
  await this.debugAccounts(itemSet, tx);
297
313
  }
298
314
  const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, attemptNum, prioritySetting);
299
- this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
315
+ this.updateStatus(itemSet.name(), TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
300
316
  }
301
317
  }, 4, 150, this.errorsToThrow);
302
318
  }
303
319
  }
320
+ return this.statuses;
304
321
  }
305
322
  }
306
323
  exports.TransactionsManager = TransactionsManager;
@@ -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;AAYzB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAElE,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,GACnB,CAAC,UAAU,EAAE,GAAG,CAAC,CAOnB;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAQxE;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,sBAAs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AAS,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,GAClC,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,GAAE,kBAA+C,EAChE,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CA8DjC"}
@@ -33,7 +33,7 @@ function getSolanaRpcConnection(heliusApiKey) {
33
33
  }
34
34
  async function currentUnixSecondsSolana(umi) {
35
35
  return await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
36
- const blockTime = await umi.rpc.getBlockTime(await umi.rpc.getSlot());
36
+ const blockTime = await umi.rpc.getBlockTime(await umi.rpc.getSlot(), { commitment: "confirmed" });
37
37
  if (blockTime === null) {
38
38
  throw new Error("Unable to retrieve block time");
39
39
  }
@@ -175,7 +175,9 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, attem
175
175
  },
176
176
  confirm: { commitment: "confirmed" },
177
177
  });
178
- console.log(`https://solscan.io/tx/${bs58_1.default.encode(result.signature)}`);
178
+ const txSig = bs58_1.default.encode(result.signature);
179
+ console.log(`Transaction signature: ${txSig}`);
180
+ console.log(`https://solscan.io/tx/${txSig}`);
179
181
  if (result.result.value.err !== null) {
180
182
  throw new Error(result.result.value.err.toString());
181
183
  }
@@ -7,7 +7,7 @@ export declare function nextAutomationPeriodTimestamp(automation: AutomationSett
7
7
  export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings, currentUnixTime: number): boolean;
8
8
  export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
9
9
  export declare function getAdjustedSettingsFromAutomation(settings: SolautoSettingsParameters, currentUnixTime: number): SolautoSettingsParameters;
10
- export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings | undefined, currentUnixTime: number): RebalanceAction | undefined;
10
+ export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings | undefined, currentUnixTime: number, bpsDistanceThreshold?: number): RebalanceAction | undefined;
11
11
  export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters, currentUnixTime: number): boolean;
12
12
  export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
13
13
  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,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,EAKV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IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAC;KAAE,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,SAAS,CAAC;CAAE,CAAC;AAEjD,qBAAa,mBAAmB;IACvB,gBAAgB,SAAa;IAC7B,cAAc,SAAa;IAC3B,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAC/C,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAC;KAAE,CAAa;IACrE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAa;IAExD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA6B9B,KAAK;IASL,UAAU,IAAI,OAAO;CAStB"}
@@ -66,7 +66,7 @@ function getAdjustedSettingsFromAutomation(settings, currentUnixTime) {
66
66
  boostToBps,
67
67
  };
68
68
  }
69
- function eligibleForRebalance(positionState, positionSettings, positionDca, currentUnixTime) {
69
+ function eligibleForRebalance(positionState, positionSettings, positionDca, currentUnixTime, bpsDistanceThreshold = 0) {
70
70
  if (positionDca &&
71
71
  positionDca.automation.targetPeriods > 0 &&
72
72
  eligibleForNextAutomationPeriod(positionDca.automation, currentUnixTime)) {
@@ -81,10 +81,10 @@ function eligibleForRebalance(positionState, positionSettings, positionDca, curr
81
81
  : positionSettings.boostToBps;
82
82
  const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
83
83
  const boostFrom = boostToBps - positionSettings.boostGap;
84
- if (positionState.liqUtilizationRateBps < boostFrom) {
84
+ if (Math.max(0, positionState.liqUtilizationRateBps - boostFrom) / boostFrom >= bpsDistanceThreshold) {
85
85
  return "boost";
86
86
  }
87
- else if (positionState.liqUtilizationRateBps > repayFrom) {
87
+ else if (Math.max(0, repayFrom - positionState.liqUtilizationRateBps) >= bpsDistanceThreshold) {
88
88
  return "repay";
89
89
  }
90
90
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.139",
3
+ "version": "1.0.141",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -46,6 +46,10 @@ class LookupTables {
46
46
 
47
47
  return this.cache;
48
48
  }
49
+
50
+ reset() {
51
+ this.cache = this.cache.filter(x => this.defaultLuts.includes(x.publicKey.toString()));
52
+ }
49
53
  }
50
54
 
51
55
  export class TransactionItem {
@@ -168,12 +172,14 @@ export enum TransactionStatus {
168
172
  Processing = "Processing",
169
173
  Queued = "Queued",
170
174
  Successful = "Successful",
175
+ Failed = "Failed",
171
176
  }
172
177
 
173
178
  export type TransactionManagerStatuses = {
174
179
  name: string;
175
180
  status: TransactionStatus;
176
181
  txSig?: string;
182
+ attemptNum: number;
177
183
  }[];
178
184
 
179
185
  export class TransactionsManager {
@@ -233,16 +239,16 @@ export class TransactionsManager {
233
239
  return transactionSets;
234
240
  }
235
241
 
236
- updateStatus(name: string, status: TransactionStatus, txSig?: string) {
242
+ updateStatus(name: string, status: TransactionStatus, attemptNum: number, txSig?: string) {
237
243
  if (!this.statuses.filter((x) => x.name === name)) {
238
- this.statuses.push({ name, status, txSig });
244
+ this.statuses.push({ name, status, txSig, attemptNum });
239
245
  } else {
240
- const idx = this.statuses.findIndex((x) => x.name === name);
246
+ const idx = this.statuses.findIndex((x) => x.name === name && x.attemptNum === attemptNum);
241
247
  if (idx !== -1) {
242
248
  this.statuses[idx].status = status;
243
249
  this.statuses[idx].txSig = txSig;
244
250
  } else {
245
- this.statuses.push({ name, status, txSig });
251
+ this.statuses.push({ name, status, txSig, attemptNum });
246
252
  }
247
253
  }
248
254
  this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
@@ -273,7 +279,7 @@ export class TransactionsManager {
273
279
  async clientSend(
274
280
  transactions: TransactionItem[],
275
281
  prioritySetting?: PriorityFeeSetting
276
- ) {
282
+ ): Promise<TransactionManagerStatuses> {
277
283
  const items = [...transactions];
278
284
  const client = this.txHandler as SolautoClient;
279
285
 
@@ -284,22 +290,28 @@ export class TransactionsManager {
284
290
  updateLookupTable.updateLutTx.getInstructions().length > 0 &&
285
291
  updateLookupTable?.needsToBeIsolated
286
292
  ) {
287
- this.updateStatus(updateLutTxName, TransactionStatus.Processing);
288
293
  await retryWithExponentialBackoff(
289
- async (attemptNum) =>
290
- await sendSingleOptimizedTransaction(
291
- this.txHandler.umi,
292
- this.txHandler.connection,
293
- updateLookupTable.updateLutTx,
294
- this.txType,
295
- attemptNum,
296
- prioritySetting
297
- ),
294
+ async (attemptNum) => {
295
+ this.updateStatus(updateLutTxName, TransactionStatus.Processing, attemptNum);
296
+ try {
297
+ const txSig = await sendSingleOptimizedTransaction(
298
+ this.txHandler.umi,
299
+ this.txHandler.connection,
300
+ updateLookupTable.updateLutTx,
301
+ this.txType,
302
+ attemptNum,
303
+ prioritySetting
304
+ );
305
+ this.updateStatus(updateLutTxName, TransactionStatus.Successful, attemptNum, txSig ? bs58.encode(txSig) : undefined);
306
+ } catch (e) {
307
+ this.updateStatus(updateLutTxName, TransactionStatus.Failed, attemptNum);
308
+ throw e;
309
+ }
310
+ },
298
311
  3,
299
312
  150,
300
313
  this.errorsToThrow
301
314
  );
302
- this.updateStatus(updateLutTxName, TransactionStatus.Successful);
303
315
  }
304
316
 
305
317
  this.lookupTables.defaultLuts = client.defaultLookupTables();
@@ -329,10 +341,7 @@ export class TransactionsManager {
329
341
  );
330
342
  }
331
343
  if (choresAfter.getInstructions().length > 0) {
332
- const chore = new TransactionItem(
333
- async () => ({ tx: choresAfter }),
334
- "close temp accounts"
335
- );
344
+ const chore = new TransactionItem(async () => ({ tx: choresAfter }));
336
345
  await chore.initialize();
337
346
  items.push(chore);
338
347
  this.txHandler.log(
@@ -341,7 +350,7 @@ export class TransactionsManager {
341
350
  );
342
351
  }
343
352
 
344
- await this.send(items, prioritySetting, true).catch((e) => {
353
+ const result = await this.send(items, prioritySetting, true).catch((e) => {
345
354
  client.resetLiveTxUpdates(false);
346
355
  throw e;
347
356
  });
@@ -349,13 +358,18 @@ export class TransactionsManager {
349
358
  if (this.txType !== "only-simulate") {
350
359
  await client.resetLiveTxUpdates();
351
360
  }
361
+
362
+ return result;
352
363
  }
353
364
 
354
365
  async send(
355
366
  items: TransactionItem[],
356
367
  prioritySetting?: PriorityFeeSetting,
357
368
  initialized?: boolean
358
- ) {
369
+ ): Promise<TransactionManagerStatuses> {
370
+ this.statuses = []
371
+ this.lookupTables.reset();
372
+
359
373
  if (!initialized) {
360
374
  for (const item of items) {
361
375
  await item.initialize();
@@ -365,7 +379,7 @@ export class TransactionsManager {
365
379
  const itemSets = await this.assembleTransactionSets(items);
366
380
  const statusesStartIdx = this.statuses.length;
367
381
  for (const itemSet of itemSets) {
368
- this.updateStatus(itemSet.name(), TransactionStatus.Queued);
382
+ this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
369
383
  }
370
384
 
371
385
  if (this.mustBeAtomic && itemSets.length > 1) {
@@ -405,6 +419,7 @@ export class TransactionsManager {
405
419
  ...newItemSets.map((x) => ({
406
420
  name: x.name(),
407
421
  status: TransactionStatus.Queued,
422
+ attemptNum: 0.
408
423
  }))
409
424
  );
410
425
  this.txHandler.log(this.statuses);
@@ -430,9 +445,9 @@ export class TransactionsManager {
430
445
  const tx = await itemSet.getSingleTransaction();
431
446
 
432
447
  if (tx.getInstructions().length === 0) {
433
- this.updateStatus(itemSet.name(), TransactionStatus.Skipped);
448
+ this.updateStatus(itemSet.name(), TransactionStatus.Skipped, attemptNum);
434
449
  } else {
435
- this.updateStatus(itemSet.name(), TransactionStatus.Processing);
450
+ this.updateStatus(itemSet.name(), TransactionStatus.Processing, attemptNum);
436
451
 
437
452
  if (this.txHandler.localTest) {
438
453
  await this.debugAccounts(itemSet, tx);
@@ -449,7 +464,8 @@ export class TransactionsManager {
449
464
  this.updateStatus(
450
465
  itemSet.name(),
451
466
  TransactionStatus.Successful,
452
- txSig ? bs58.encode(txSig) : undefined
467
+ attemptNum,
468
+ txSig ? bs58.encode(txSig) : undefined,
453
469
  );
454
470
  }
455
471
  },
@@ -459,5 +475,7 @@ export class TransactionsManager {
459
475
  );
460
476
  }
461
477
  }
478
+
479
+ return this.statuses;
462
480
  }
463
481
  }
@@ -51,7 +51,7 @@ export function getSolanaRpcConnection(
51
51
 
52
52
  export async function currentUnixSecondsSolana(umi: Umi): Promise<number> {
53
53
  return await retryWithExponentialBackoff(async () => {
54
- const blockTime = await umi.rpc.getBlockTime(await umi.rpc.getSlot());
54
+ const blockTime = await umi.rpc.getBlockTime(await umi.rpc.getSlot(), { commitment: "confirmed" });
55
55
  if (blockTime === null) {
56
56
  throw new Error("Unable to retrieve block time");
57
57
  }
@@ -337,7 +337,9 @@ export async function sendSingleOptimizedTransaction(
337
337
  },
338
338
  confirm: { commitment: "confirmed" },
339
339
  });
340
- console.log(`https://solscan.io/tx/${bs58.encode(result.signature)}`);
340
+ const txSig = bs58.encode(result.signature);
341
+ console.log(`Transaction signature: ${txSig}`)
342
+ console.log(`https://solscan.io/tx/${txSig}`);
341
343
  if (result.result.value.err !== null) {
342
344
  throw new Error(result.result.value.err.toString());
343
345
  }
@@ -117,7 +117,8 @@ export function eligibleForRebalance(
117
117
  positionState: PositionState,
118
118
  positionSettings: SolautoSettingsParameters,
119
119
  positionDca: DCASettings | undefined,
120
- currentUnixTime: number
120
+ currentUnixTime: number,
121
+ bpsDistanceThreshold = 0
121
122
  ): RebalanceAction | undefined {
122
123
  if (
123
124
  positionDca &&
@@ -144,9 +145,9 @@ export function eligibleForRebalance(
144
145
  const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
145
146
  const boostFrom = boostToBps - positionSettings.boostGap;
146
147
 
147
- if (positionState.liqUtilizationRateBps < boostFrom) {
148
+ if (Math.max(0, positionState.liqUtilizationRateBps - boostFrom) / boostFrom >= bpsDistanceThreshold) {
148
149
  return "boost";
149
- } else if (positionState.liqUtilizationRateBps > repayFrom) {
150
+ } else if (Math.max(0, repayFrom - positionState.liqUtilizationRateBps) >= bpsDistanceThreshold) {
150
151
  return "repay";
151
152
  }
152
153
 
@@ -120,8 +120,6 @@ describe("Solauto Marginfi tests", async () => {
120
120
  // }, "deposit")
121
121
  // );
122
122
 
123
- console.log("POSITION SUPPLY TA:", client.positionSupplyTa);
124
- console.log("POSITION DEBT TA:", client.positionDebtTa);
125
123
  transactionItems.push(
126
124
  new TransactionItem(
127
125
  async (attemptNum) =>