@haven-fi/solauto-sdk 1.0.3 → 1.0.5

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":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAIpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CA4D7B"}
1
+ {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CA+D7B"}
@@ -5,7 +5,6 @@ const umi_1 = require("@metaplex-foundation/umi");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  const solanaUtils_1 = require("./solanaUtils");
7
7
  const numberUtils_1 = require("./numberUtils");
8
- const console_1 = require("console");
9
8
  const api_1 = require("@jup-ag/api");
10
9
  const accountUtils_1 = require("./accountUtils");
11
10
  const jupApi = (0, api_1.createJupiterApiClient)();
@@ -47,7 +46,9 @@ async function getJupSwapTransaction(signer, swapDetails) {
47
46
  destinationTokenAccount: (0, accountUtils_1.getTokenAccount)(swapDetails.destinationWallet, swapDetails.outputMint).toString(),
48
47
  },
49
48
  });
50
- (0, console_1.assert)(instructions.swapInstruction !== undefined);
49
+ if (!instructions.swapInstruction) {
50
+ throw new Error("No swap instruction was returned by Jupiter");
51
+ }
51
52
  return {
52
53
  jupQuote: quoteResponse,
53
54
  lookupTableAddresses: instructions.addressLookupTableAddresses,
@@ -1,8 +1,6 @@
1
1
  import { AddressLookupTableInput, Signer, TransactionBuilder, WrappedInstruction } from "@metaplex-foundation/umi";
2
2
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
3
3
  import { SolautoClient } from "../clients/solautoClient";
4
- export declare function loadSecretKey(keypairPath: string): Uint8Array;
5
- export declare function getSecretKey(keypairFilename?: string): Uint8Array;
6
4
  export declare function currentUnixSecondsSolana(): Promise<number>;
7
5
  export declare function getWrappedInstruction(signer: Signer, ix: TransactionInstruction): WrappedInstruction;
8
6
  export declare function setComputeUnitLimitUmiIx(signer: Signer, maxComputeUnits: number): WrappedInstruction;
@@ -1 +1 @@
1
- {"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAGL,SAAS,EAIT,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAQzD,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,cAGhD;AAED,wBAAgB,YAAY,CAAC,eAAe,GAAE,MAAa,GAAG,UAAU,CAIvE;AAED,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,CAQhE;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,SAA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UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAqDjC"}
@@ -3,10 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendSingleOptimizedTransaction = exports.getComputeUnitPriceEstimate = exports.assembleFinalTransaction = exports.getAdressLookupInputs = exports.splTokenTransferUmiIx = exports.closeTokenAccountUmiIx = exports.systemTransferUmiIx = exports.createAssociatedTokenAccountUmiIx = exports.setComputeUnitPriceUmiIx = exports.setComputeUnitLimitUmiIx = exports.getWrappedInstruction = exports.currentUnixSecondsSolana = exports.getSecretKey = exports.loadSecretKey = void 0;
7
- const fs_1 = __importDefault(require("fs"));
6
+ exports.sendSingleOptimizedTransaction = exports.getComputeUnitPriceEstimate = exports.assembleFinalTransaction = exports.getAdressLookupInputs = exports.splTokenTransferUmiIx = exports.closeTokenAccountUmiIx = exports.systemTransferUmiIx = exports.createAssociatedTokenAccountUmiIx = exports.setComputeUnitPriceUmiIx = exports.setComputeUnitLimitUmiIx = exports.getWrappedInstruction = exports.currentUnixSecondsSolana = void 0;
8
7
  const bs58_1 = __importDefault(require("bs58"));
9
- const path_1 = __importDefault(require("path"));
10
8
  const umi_1 = require("@metaplex-foundation/umi");
11
9
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
12
10
  const web3_js_1 = require("@solana/web3.js");
@@ -15,15 +13,6 @@ const accountUtils_1 = require("./accountUtils");
15
13
  const solautoConstants_1 = require("../constants/solautoConstants");
16
14
  const generalUtils_1 = require("./generalUtils");
17
15
  const marginfi_sdk_1 = require("../marginfi-sdk");
18
- function loadSecretKey(keypairPath) {
19
- const secretKey = JSON.parse(fs_1.default.readFileSync(keypairPath, "utf8"));
20
- return new Uint8Array(secretKey);
21
- }
22
- exports.loadSecretKey = loadSecretKey;
23
- function getSecretKey(keypairFilename = "id") {
24
- return loadSecretKey(path_1.default.join(process.env.HOME, ".config", "solana", keypairFilename + ".json"));
25
- }
26
- exports.getSecretKey = getSecretKey;
27
16
  async function currentUnixSecondsSolana() {
28
17
  return await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
29
18
  const blockTime = await solautoConstants_1.CONNECTION.getBlockTime(await solautoConstants_1.CONNECTION.getSlot());
@@ -152,7 +141,6 @@ async function getComputeUnitPriceEstimate(tx, attemptNum) {
152
141
  },
153
142
  ]);
154
143
  const feeEstimate = Math.round(resp.priorityFeeEstimate);
155
- console.log("Compute unit price: ", feeEstimate);
156
144
  return feeEstimate;
157
145
  }
158
146
  exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
@@ -161,9 +149,10 @@ async function sendSingleOptimizedTransaction(client, tx, simulateOnly, attemptN
161
149
  client.log("Instructions: ", tx.getInstructions().length);
162
150
  client.log("Serialized transaction size: ", tx.getTransactionSize(solautoConstants_1.UMI));
163
151
  const feeEstimate = await getComputeUnitPriceEstimate(tx, attemptNum);
152
+ client.log("Compute unit price: ", feeEstimate);
164
153
  const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction((0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(client.signer, tx, feeEstimate, 1400000).setLatestBlockhash(solautoConstants_1.UMI)).buildAndSign(solautoConstants_1.UMI))));
165
154
  const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.15);
166
- console.log("Compute unit limit: ", computeUnitLimit);
155
+ client.log("Compute unit limit: ", computeUnitLimit);
167
156
  if (!simulateOnly) {
168
157
  const result = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await assembleFinalTransaction(client.signer, tx, feeEstimate, computeUnitLimit).sendAndConfirm(solautoConstants_1.UMI, {
169
158
  send: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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",
@@ -6,7 +6,6 @@ import {
6
6
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
7
7
  import { getWrappedInstruction } from "./solanaUtils";
8
8
  import { toBps } from "./numberUtils";
9
- import { assert } from "console";
10
9
  import {
11
10
  createJupiterApiClient,
12
11
  Instruction,
@@ -87,7 +86,10 @@ export async function getJupSwapTransaction(
87
86
  },
88
87
  });
89
88
 
90
- assert(instructions.swapInstruction !== undefined);
89
+ if (!instructions.swapInstruction) {
90
+ throw new Error("No swap instruction was returned by Jupiter");
91
+ }
92
+
91
93
  return {
92
94
  jupQuote: quoteResponse,
93
95
  lookupTableAddresses: instructions.addressLookupTableAddresses,
@@ -1,6 +1,4 @@
1
- import fs from "fs";
2
1
  import bs58 from "bs58";
3
- import path from "path";
4
2
  import {
5
3
  AddressLookupTableInput,
6
4
  Signer,
@@ -23,7 +21,6 @@ import {
23
21
  SystemProgram,
24
22
  TransactionInstruction,
25
23
  VersionedTransaction,
26
- TransactionError,
27
24
  } from "@solana/web3.js";
28
25
  import {
29
26
  createAssociatedTokenAccountIdempotentInstruction,
@@ -39,17 +36,6 @@ import {
39
36
  getLendingAccountStartFlashloanInstructionDataSerializer,
40
37
  } from "../marginfi-sdk";
41
38
 
42
- export function loadSecretKey(keypairPath: string) {
43
- const secretKey = JSON.parse(fs.readFileSync(keypairPath, "utf8"));
44
- return new Uint8Array(secretKey);
45
- }
46
-
47
- export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
48
- return loadSecretKey(
49
- path.join(process.env.HOME!, ".config", "solana", keypairFilename + ".json")
50
- );
51
- }
52
-
53
39
  export async function currentUnixSecondsSolana(): Promise<number> {
54
40
  return await retryWithExponentialBackoff(async () => {
55
41
  const blockTime = await CONNECTION.getBlockTime(await CONNECTION.getSlot());
@@ -268,7 +254,6 @@ export async function getComputeUnitPriceEstimate(
268
254
  },
269
255
  ]);
270
256
  const feeEstimate = Math.round((resp as any).priorityFeeEstimate as number);
271
- console.log("Compute unit price: ", feeEstimate);
272
257
 
273
258
  return feeEstimate;
274
259
  }
@@ -284,6 +269,7 @@ export async function sendSingleOptimizedTransaction(
284
269
  client.log("Serialized transaction size: ", tx.getTransactionSize(UMI));
285
270
 
286
271
  const feeEstimate = await getComputeUnitPriceEstimate(tx, attemptNum);
272
+ client.log("Compute unit price: ", feeEstimate);
287
273
 
288
274
  const simulationResult = await retryWithExponentialBackoff(
289
275
  async () =>
@@ -304,7 +290,7 @@ export async function sendSingleOptimizedTransaction(
304
290
  const computeUnitLimit = Math.round(
305
291
  simulationResult.value.unitsConsumed! * 1.15
306
292
  );
307
- console.log("Compute unit limit: ", computeUnitLimit);
293
+ client.log("Compute unit limit: ", computeUnitLimit);
308
294
 
309
295
  if (!simulateOnly) {
310
296
  const result = await retryWithExponentialBackoff(
package/tests/shared.ts CHANGED
@@ -1,7 +1,19 @@
1
+ import path from "path";
2
+ import fs from "fs";
1
3
  import { Signer, createSignerFromKeypair } from "@metaplex-foundation/umi";
2
4
  import { Connection, clusterApiUrl } from "@solana/web3.js";
3
5
  import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
4
- import { getSecretKey } from "../src/utils/solanaUtils";
6
+
7
+ export function loadSecretKey(keypairPath: string) {
8
+ const secretKey = JSON.parse(fs.readFileSync(keypairPath, "utf8"));
9
+ return new Uint8Array(secretKey);
10
+ }
11
+
12
+ export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
13
+ return loadSecretKey(
14
+ path.join(process.env.HOME!, ".config", "solana", keypairFilename + ".json")
15
+ );
16
+ }
5
17
 
6
18
  export function setupTest(keypairFilename?: string): Signer {
7
19
  const umi = createUmi(