@haven-fi/solauto-sdk 1.0.396 → 1.0.398

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.
@@ -1 +1 @@
1
- {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AA2MD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,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,CAuE/B"}
1
+ {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AAiND,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,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,CAwE/B"}
@@ -89,7 +89,7 @@ async function simulateJitoBundle(umi, txs) {
89
89
  if (txFailure) {
90
90
  const info = parseJitoErrorMessage(txFailure[1]);
91
91
  if (info) {
92
- throw new transactions_1.BundleSimulationError("Failed to simulate transaction", 400, {
92
+ throw new transactions_1.BundleSimulationError(`Failed to simulate transaction: TX: ${failedTxIdx}, IX: ${info.instructionIndex}, Error: ${info.errorCode}`, 400, {
93
93
  transactionIdx: failedTxIdx,
94
94
  instructionIdx: info.instructionIndex,
95
95
  errorCode: info.errorCode,
@@ -98,7 +98,7 @@ async function simulateJitoBundle(umi, txs) {
98
98
  }
99
99
  throw new Error(txFailure ? txFailure[1] : resValue.summary.failed.toString());
100
100
  }
101
- else if (res.error.message) {
101
+ else if (res.error && res.error.message) {
102
102
  throw new Error(res.error.message);
103
103
  }
104
104
  return res;
@@ -149,10 +149,10 @@ async function pollBundleStatus(bundleId, interval = 1000, timeout = 40000) {
149
149
  }
150
150
  throw new web3_js_1.TransactionExpiredBlockheightExceededError("Unable to confirm transaction. Try a higher priority fee.");
151
151
  }
152
- async function sendJitoBundle(transactions) {
152
+ async function sendJitoBundle(umi, transactions) {
153
153
  let resp;
154
154
  try {
155
- resp = await axios_1.default.post(`${solautoConstants_1.JITO_BLOCK_ENGINE}/api/v1/bundles`, {
155
+ resp = await axios_1.default.post(umi.rpc.getEndpoint(), {
156
156
  jsonrpc: "2.0",
157
157
  id: 1,
158
158
  method: "sendBundle",
@@ -198,7 +198,7 @@ async function sendJitoBundledTransactions(umi, signer, txs, txType, priorityFee
198
198
  throw new Error("A transaction is too large");
199
199
  }
200
200
  onAwaitingSign?.();
201
- const txSigs = await sendJitoBundle(serializedTxs.map((x) => bs58_1.default.encode(x)));
201
+ const txSigs = await sendJitoBundle(umi, serializedTxs.map((x) => bs58_1.default.encode(x)));
202
202
  return txSigs.length > 0 ? txSigs : undefined;
203
203
  }
204
204
  return undefined;
@@ -14,6 +14,6 @@ export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey,
14
14
  export declare function getAddressLookupInputs(umi: Umi, lookupTableAddresses: string[]): Promise<AddressLookupTableInput[]>;
15
15
  export declare function addTxOptimizations(signer: Signer, transaction: TransactionBuilder, computeUnitPrice?: number, computeUnitLimit?: number): TransactionBuilder;
16
16
  export declare function assembleFinalTransaction(signer: Signer, transaction: TransactionBuilder, computeUnitPrice?: number, computeUnitLimit?: number): TransactionBuilder;
17
- export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting): Promise<number | undefined>;
17
+ export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting, useAccounts?: boolean): Promise<number | undefined>;
18
18
  export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, txType?: TransactionRunType, prioritySetting?: PriorityFeeSetting, onAwaitingSign?: () => void): Promise<Uint8Array | undefined>;
19
19
  //# 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,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAgBzB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,UAErD;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,MAAM,UAE3D;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAgC,GAC1C,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AAe,GAAE,kBAA2C,EAC5D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAoEjC"}
@@ -150,13 +150,19 @@ async function simulateTransaction(umi, connection, transaction) {
150
150
  }
151
151
  return simulationResult;
152
152
  }
153
- async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
153
+ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, useAccounts) {
154
154
  const web3Transaction = (0, umi_web3js_adapters_1.toWeb3JsTransaction)((await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi));
155
+ const accountKeys = tx
156
+ .getInstructions()
157
+ .flatMap((x) => x.keys.flatMap((x) => x.pubkey.toString()));
155
158
  let feeEstimate;
156
159
  try {
157
160
  const resp = await umi.rpc.call("getPriorityFeeEstimate", [
158
161
  {
159
- transaction: bs58_1.default.encode(web3Transaction.serialize()),
162
+ transaction: !useAccounts
163
+ ? bs58_1.default.encode(web3Transaction.serialize())
164
+ : undefined,
165
+ accountKeys: useAccounts ? accountKeys : undefined,
160
166
  options: {
161
167
  priorityLevel: prioritySetting.toString(),
162
168
  },
@@ -168,9 +174,7 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
168
174
  try {
169
175
  const resp = await umi.rpc.call("getPriorityFeeEstimate", [
170
176
  {
171
- accountKeys: tx
172
- .getInstructions()
173
- .flatMap((x) => x.keys.flatMap((x) => x.pubkey.toString())),
177
+ accountKeys,
174
178
  options: {
175
179
  priorityLevel: prioritySetting.toString(),
176
180
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.396",
3
+ "version": "1.0.398",
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",
@@ -121,16 +121,22 @@ async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
121
121
  if (txFailure) {
122
122
  const info = parseJitoErrorMessage(txFailure[1] as string);
123
123
  if (info) {
124
- throw new BundleSimulationError("Failed to simulate transaction", 400, {
125
- transactionIdx: failedTxIdx,
126
- instructionIdx: info.instructionIndex,
127
- errorCode: info.errorCode,
128
- });
124
+ throw new BundleSimulationError(
125
+ `Failed to simulate transaction: TX: ${failedTxIdx}, IX: ${info.instructionIndex}, Error: ${info.errorCode}`,
126
+ 400,
127
+ {
128
+ transactionIdx: failedTxIdx,
129
+ instructionIdx: info.instructionIndex,
130
+ errorCode: info.errorCode,
131
+ }
132
+ );
129
133
  }
130
134
  }
131
135
 
132
- throw new Error(txFailure ? txFailure[1] : resValue.summary.failed.toString());
133
- } else if (res.error.message) {
136
+ throw new Error(
137
+ txFailure ? txFailure[1] : resValue.summary.failed.toString()
138
+ );
139
+ } else if (res.error && res.error.message) {
134
140
  throw new Error(res.error.message);
135
141
  }
136
142
 
@@ -213,18 +219,18 @@ async function pollBundleStatus(
213
219
  );
214
220
  }
215
221
 
216
- async function sendJitoBundle(transactions: string[]): Promise<string[]> {
222
+ async function sendJitoBundle(
223
+ umi: Umi,
224
+ transactions: string[]
225
+ ): Promise<string[]> {
217
226
  let resp: any;
218
227
  try {
219
- resp = await axios.post<{ result: string }>(
220
- `${JITO_BLOCK_ENGINE}/api/v1/bundles`,
221
- {
222
- jsonrpc: "2.0",
223
- id: 1,
224
- method: "sendBundle",
225
- params: [transactions],
226
- }
227
- );
228
+ resp = await axios.post<{ result: string }>(umi.rpc.getEndpoint(), {
229
+ jsonrpc: "2.0",
230
+ id: 1,
231
+ method: "sendBundle",
232
+ params: [transactions],
233
+ });
228
234
  } catch (e: any) {
229
235
  if (e.response.data.error) {
230
236
  console.error("Jito send bundle error:", e.response.data.error);
@@ -311,6 +317,7 @@ export async function sendJitoBundledTransactions(
311
317
 
312
318
  onAwaitingSign?.();
313
319
  const txSigs = await sendJitoBundle(
320
+ umi,
314
321
  serializedTxs.map((x) => base58.encode(x))
315
322
  );
316
323
  return txSigs.length > 0 ? txSigs : undefined;
@@ -288,17 +288,25 @@ async function simulateTransaction(
288
288
  export async function getComputeUnitPriceEstimate(
289
289
  umi: Umi,
290
290
  tx: TransactionBuilder,
291
- prioritySetting: PriorityFeeSetting
291
+ prioritySetting: PriorityFeeSetting,
292
+ useAccounts?: boolean
292
293
  ): Promise<number | undefined> {
293
294
  const web3Transaction = toWeb3JsTransaction(
294
295
  (await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi)
295
296
  );
296
297
 
298
+ const accountKeys = tx
299
+ .getInstructions()
300
+ .flatMap((x) => x.keys.flatMap((x) => x.pubkey.toString()));
301
+
297
302
  let feeEstimate: number | undefined;
298
303
  try {
299
304
  const resp = await umi.rpc.call("getPriorityFeeEstimate", [
300
305
  {
301
- transaction: bs58.encode(web3Transaction.serialize()),
306
+ transaction: !useAccounts
307
+ ? bs58.encode(web3Transaction.serialize())
308
+ : undefined,
309
+ accountKeys: useAccounts ? accountKeys : undefined,
302
310
  options: {
303
311
  priorityLevel: prioritySetting.toString(),
304
312
  },
@@ -309,9 +317,7 @@ export async function getComputeUnitPriceEstimate(
309
317
  try {
310
318
  const resp = await umi.rpc.call("getPriorityFeeEstimate", [
311
319
  {
312
- accountKeys: tx
313
- .getInstructions()
314
- .flatMap((x) => x.keys.flatMap((x) => x.pubkey.toString())),
320
+ accountKeys,
315
321
  options: {
316
322
  priorityLevel: prioritySetting.toString(),
317
323
  },
@@ -60,12 +60,12 @@ export function getLeverageFactor(
60
60
  }
61
61
 
62
62
  describe("Solauto Marginfi tests", async () => {
63
- // const signer = setupTest();
64
- const signer = setupTest("solauto-manager");
63
+ const signer = setupTest();
64
+ // const signer = setupTest("solauto-manager");
65
65
 
66
- const payForTransactions = false;
67
- const testProgram = false;
68
- const positionId = 4;
66
+ const payForTransactions = true;
67
+ const testProgram = true;
68
+ const positionId = 1;
69
69
 
70
70
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
71
71
  const client = new SolautoMarginfiClient(
@@ -81,7 +81,7 @@ describe("Solauto Marginfi tests", async () => {
81
81
  await client.initialize({
82
82
  signer,
83
83
  positionId,
84
- authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
84
+ authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
85
85
  // new: true,
86
86
  // marginfiAccount: new PublicKey(
87
87
  // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
@@ -91,7 +91,8 @@ describe("Solauto Marginfi tests", async () => {
91
91
  // debtMint: new PublicKey(USDC),
92
92
  });
93
93
 
94
- console.log(await client.getFreshPositionState());
94
+ // console.log(await getAllPositionsByAuthority(client.umi, new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"), PositionType.Leverage));
95
+
95
96
 
96
97
  // console.log(JSON.stringify(await getJupPriceData([new PublicKey("7JhmUcZrrfhyt5nTSu3AfsrUq2L9992a7AhwdSDxdoL2")], true), null, 2));
97
98
  // console.log(JSON.stringify(await getJupPriceData([new PublicKey(POPCAT)], true), null, 2));
@@ -221,16 +222,16 @@ describe("Solauto Marginfi tests", async () => {
221
222
  // )
222
223
  // );
223
224
 
224
- // transactionItems.push(
225
- // new TransactionItem(
226
- // async () => ({
227
- // tx: client.protocolInteraction(
228
- // solautoAction("Withdraw", [{ __kind: "Some", fields: [toBaseUnit(0.03, 9)] }])
229
- // ),
230
- // }),
231
- // "withdraw"
232
- // )
233
- // );
225
+ transactionItems.push(
226
+ new TransactionItem(
227
+ async () => ({
228
+ tx: client.protocolInteraction(
229
+ solautoAction("Withdraw", [{ __kind: "Some", fields: [toBaseUnit(0.03, 9)] }])
230
+ ),
231
+ }),
232
+ "withdraw"
233
+ )
234
+ );
234
235
  // transactionItems.push(
235
236
  // new TransactionItem(
236
237
  // async () => ({