@haven-fi/solauto-sdk 1.0.46 → 1.0.49

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,7 @@ class SolautoClient {
35
35
  : (0, umi_signer_wallet_adapters_1.walletAdapterIdentity)(args.wallet, true));
36
36
  this.signer = this.umi.identity;
37
37
  this.authority =
38
- args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.umi.identity.publicKey);
38
+ 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;
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CAgHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
1
+ {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAGD,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CAgHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../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AC,kBAAkB,CAAC;IAYzD,YAAY,IAAI,MAAM,EAAE;IAMxB,IAAI,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;CA4JX"}
@@ -184,10 +184,6 @@ class TransactionsManager {
184
184
  async debugAccounts(itemSet, tx) {
185
185
  const lutInputs = await itemSet.lookupTables.getLutInputs([]);
186
186
  const lutAccounts = lutInputs.map((x) => x.addresses).flat();
187
- const keys = tx
188
- .getInstructions()
189
- .map((x) => x.keys)
190
- .flat();
191
187
  for (const ix of tx.getInstructions()) {
192
188
  const ixAccounts = ix.keys.map((x) => x.pubkey);
193
189
  const accountsNotInLut = ixAccounts.filter((x) => !lutAccounts.includes(x));
@@ -269,7 +265,7 @@ class TransactionsManager {
269
265
  this.client.log(this.statuses);
270
266
  itemSets.splice(i + 1, itemSets.length - i - 1, ...newItemSets.slice(1));
271
267
  }
272
- return newItemSets[0];
268
+ return newItemSets.length > 0 ? newItemSets[0] : undefined;
273
269
  };
274
270
  let itemSet = itemSets[i];
275
271
  await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => {
@@ -277,6 +273,9 @@ class TransactionsManager {
277
273
  i > 0 || attemptNum > 0
278
274
  ? await getFreshItemSet(itemSet, attemptNum)
279
275
  : itemSet;
276
+ if (!itemSet) {
277
+ return;
278
+ }
280
279
  const tx = await itemSet.getSingleTransaction();
281
280
  if (tx.getInstructions().length === 0) {
282
281
  this.updateStatus(itemSet.name(), TransactionStatus.Skipped);
@@ -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;AAM3E,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAiD1E;AAED,MAAM,MAAM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,EACnB,KAAK,GAAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ"}
@@ -47,10 +47,8 @@ async function getTokenPrices(mints) {
47
47
  const currentTime = currentUnixSeconds();
48
48
  if (!mints.some((mint) => !(mint.toString() in solautoConstants_1.PRICES) ||
49
49
  currentTime - solautoConstants_1.PRICES[mint.toString()].time > 3)) {
50
- console.log("Accessing price cache");
51
50
  return mints.map((mint) => solautoConstants_1.PRICES[mint.toString()].price);
52
51
  }
53
- console.log(`Fetching prices for ${mints.join(", ")}`);
54
52
  const priceFeedIds = mints.map((mint) => pythConstants_1.PYTH_PRICE_FEED_IDS[mint.toString()]);
55
53
  const getReq = async () => await fetch(`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`);
56
54
  let resp = await getReq();
@@ -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.01) / fromBps(liqThresholdBps)) - 1;
65
+ return toBps((fromBps(maxLtvBps) - 0.02) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
66
66
  }
67
67
  exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
68
68
  function maxRepayFrom(maxLtvBps, liqThresholdBps) {
@@ -159,26 +159,9 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
159
159
  console.log("Serialized transaction size: ", tx.getTransactionSize(umi));
160
160
  const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
161
161
  console.log("Compute unit price: ", feeEstimate);
162
- // const simulationResult = await retryWithExponentialBackoff(
163
- // async () =>
164
- // await simulateTransaction(
165
- // connection,
166
- // toWeb3JsTransaction(
167
- // await (
168
- // await assembleFinalTransaction(
169
- // umi.identity,
170
- // tx,
171
- // feeEstimate,
172
- // 1_400_000
173
- // ).setLatestBlockhash(umi)
174
- // ).build(umi)
175
- // )
176
- // )
177
- // );
178
- // const computeUnitLimit = Math.round(
179
- // simulationResult.value.unitsConsumed! * 1.1
180
- // );
181
- // console.log("Compute unit limit: ", computeUnitLimit);
162
+ 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
+ const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
164
+ console.log("Compute unit limit: ", computeUnitLimit);
182
165
  if (!simulateOnly) {
183
166
  const result = await assembleFinalTransaction(umi.identity, tx, feeEstimate, 800000).sendAndConfirm(umi, {
184
167
  send: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.46",
3
+ "version": "1.0.49",
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",
@@ -137,7 +137,7 @@ export abstract class SolautoClient {
137
137
 
138
138
  this.signer = this.umi.identity;
139
139
  this.authority =
140
- args.authority ?? toWeb3JsPublicKey(this.umi.identity.publicKey);
140
+ args.authority ?? toWeb3JsPublicKey(this.signer.publicKey);
141
141
 
142
142
  this.positionId = args.positionId;
143
143
  this.selfManaged = this.positionId === 0;
@@ -547,6 +547,7 @@ export async function getTransactionChores(
547
547
  return [choresBefore, choresAfter];
548
548
  }
549
549
 
550
+
550
551
  export async function buildSolautoRebalanceTransaction(
551
552
  client: SolautoClient,
552
553
  targetLiqUtilizationRateBps?: number,
@@ -256,10 +256,6 @@ export class TransactionsManager {
256
256
  async debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder) {
257
257
  const lutInputs = await itemSet.lookupTables.getLutInputs([]);
258
258
  const lutAccounts = lutInputs.map((x) => x.addresses).flat();
259
- const keys = tx
260
- .getInstructions()
261
- .map((x) => x.keys)
262
- .flat();
263
259
  for (const ix of tx.getInstructions()) {
264
260
  const ixAccounts = ix.keys.map((x) => x.pubkey);
265
261
  const accountsNotInLut = ixAccounts.filter(
@@ -382,16 +378,19 @@ export class TransactionsManager {
382
378
  ...newItemSets.slice(1)
383
379
  );
384
380
  }
385
- return newItemSets[0];
381
+ return newItemSets.length > 0 ? newItemSets[0] : undefined;
386
382
  };
387
383
 
388
- let itemSet = itemSets[i];
384
+ let itemSet: TransactionSet | undefined = itemSets[i];
389
385
  await retryWithExponentialBackoff(
390
386
  async (attemptNum) => {
391
387
  itemSet =
392
388
  i > 0 || attemptNum > 0
393
- ? await getFreshItemSet(itemSet, attemptNum)
389
+ ? await getFreshItemSet(itemSet!, attemptNum)
394
390
  : itemSet;
391
+ if (!itemSet) {
392
+ return;
393
+ }
395
394
  const tx = await itemSet.getSingleTransaction();
396
395
 
397
396
  if (tx.getInstructions().length === 0) {
@@ -55,11 +55,9 @@ export async function getTokenPrices(mints: PublicKey[]): Promise<number[]> {
55
55
  currentTime - PRICES[mint.toString()].time > 3
56
56
  )
57
57
  ) {
58
- console.log("Accessing price cache");
59
58
  return mints.map((mint) => PRICES[mint.toString()].price);
60
59
  }
61
60
 
62
- console.log(`Fetching prices for ${mints.join(", ")}`);
63
61
  const priceFeedIds = mints.map(
64
62
  (mint) => PYTH_PRICE_FEED_IDS[mint.toString()]
65
63
  );
@@ -81,7 +81,7 @@ export function getMaxLiqUtilizationRate(
81
81
  maxLtvBps: number,
82
82
  liqThresholdBps: number
83
83
  ): number {
84
- return toBps((fromBps(maxLtvBps) - 0.01) / fromBps(liqThresholdBps)) - 1;
84
+ return toBps((fromBps(maxLtvBps) - 0.02) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
85
85
  }
86
86
 
87
87
  export function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number) {
@@ -288,27 +288,27 @@ export async function sendSingleOptimizedTransaction(
288
288
  const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
289
289
  console.log("Compute unit price: ", feeEstimate);
290
290
 
291
- // const simulationResult = await retryWithExponentialBackoff(
292
- // async () =>
293
- // await simulateTransaction(
294
- // connection,
295
- // toWeb3JsTransaction(
296
- // await (
297
- // await assembleFinalTransaction(
298
- // umi.identity,
299
- // tx,
300
- // feeEstimate,
301
- // 1_400_000
302
- // ).setLatestBlockhash(umi)
303
- // ).build(umi)
304
- // )
305
- // )
306
- // );
291
+ const simulationResult = await retryWithExponentialBackoff(
292
+ async () =>
293
+ await simulateTransaction(
294
+ connection,
295
+ toWeb3JsTransaction(
296
+ await (
297
+ await assembleFinalTransaction(
298
+ umi.identity,
299
+ tx,
300
+ feeEstimate,
301
+ 1_400_000
302
+ ).setLatestBlockhash(umi)
303
+ ).build(umi)
304
+ )
305
+ )
306
+ );
307
307
 
308
- // const computeUnitLimit = Math.round(
309
- // simulationResult.value.unitsConsumed! * 1.1
310
- // );
311
- // console.log("Compute unit limit: ", computeUnitLimit);
308
+ const computeUnitLimit = Math.round(
309
+ simulationResult.value.unitsConsumed! * 1.1
310
+ );
311
+ console.log("Compute unit limit: ", computeUnitLimit);
312
312
 
313
313
  if (!simulateOnly) {
314
314
  const result = await assembleFinalTransaction(
@@ -9,7 +9,7 @@ import {
9
9
  SolautoSettingsParametersInpArgs,
10
10
  } from "../../src/generated";
11
11
  import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
12
- import { toBaseUnit } from "../../src/utils/numberUtils";
12
+ import { getMaxLiqUtilizationRate, toBaseUnit } from "../../src/utils/numberUtils";
13
13
  import { NATIVE_MINT } from "@solana/spl-token";
14
14
  import { getTokenPrices } from "../../src/utils/generalUtils";
15
15
  import {
@@ -20,8 +20,8 @@ import { PublicKey } from "@solana/web3.js";
20
20
  import { USDC_MINT } from "../../src/constants";
21
21
 
22
22
  describe("Solauto Marginfi tests", async () => {
23
- const signer = setupTest();
24
- // const signer = setupTest("solauto-manager");
23
+ // const signer = setupTest();
24
+ const signer = setupTest("solauto-manager");
25
25
 
26
26
  const payForTransactions = false;
27
27
  const useJitoBundle = false;
@@ -48,14 +48,14 @@ describe("Solauto Marginfi tests", async () => {
48
48
  );
49
49
 
50
50
  const transactionItems: TransactionItem[] = [];
51
- const settingParams: SolautoSettingsParametersInpArgs = {
52
- boostToBps: 4000,
53
- boostGap: 500,
54
- repayToBps: 7456,
55
- repayGap: 500,
56
- automation: none(),
57
- targetBoostToBps: none(),
58
- };
51
+ // const settingParams: SolautoSettingsParametersInpArgs = {
52
+ // boostToBps: 4000,
53
+ // boostGap: 500,
54
+ // repayToBps: 7456,
55
+ // repayGap: 500,
56
+ // automation: none(),
57
+ // targetBoostToBps: none(),
58
+ // };
59
59
 
60
60
  // if (client.solautoPositionData === null) {
61
61
  // transactionItems.push(
@@ -81,6 +81,7 @@ describe("Solauto Marginfi tests", async () => {
81
81
  // );
82
82
  // }
83
83
 
84
+ // const maxLiqRate = getMaxLiqUtilizationRate(client.solautoPositionState!.maxLtvBps, client.solautoPositionState!.liqThresholdBps);
84
85
  // transactionItems.push(
85
86
  // new TransactionItem(
86
87
  // async () => ({