@haven-fi/solauto-sdk 1.0.146 → 1.0.147

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ export declare class ReferralStateManager extends TxHandler {
15
15
  referralAuthority: PublicKey;
16
16
  referralState: PublicKey;
17
17
  referralStateData: ReferralState | null;
18
- constructor(heliusApiKey: string, localTest?: boolean | undefined);
18
+ constructor(heliusApiUrl: string, localTest?: boolean | undefined);
19
19
  initialize(args: ReferralStateManagerArgs): Promise<void>;
20
20
  defaultLookupTables(): string[];
21
21
  updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder;
@@ -9,8 +9,8 @@ const generated_1 = require("../generated");
9
9
  const utils_1 = require("../utils");
10
10
  const txHandler_1 = require("./txHandler");
11
11
  class ReferralStateManager extends txHandler_1.TxHandler {
12
- constructor(heliusApiKey, localTest) {
13
- super(heliusApiKey, localTest);
12
+ constructor(heliusApiUrl, localTest) {
13
+ super(heliusApiUrl, localTest);
14
14
  this.localTest = localTest;
15
15
  this.umi = this.umi.use({
16
16
  install(umi) {
@@ -41,7 +41,7 @@ export declare abstract class SolautoClient extends TxHandler {
41
41
  solautoFeesSupplyTa: PublicKey;
42
42
  authorityLutAddress?: PublicKey;
43
43
  livePositionUpdates: LivePositionUpdates;
44
- constructor(heliusApiKey: string, localTest?: boolean | undefined);
44
+ constructor(heliusApiUrl: string, localTest?: boolean | undefined);
45
45
  initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform): Promise<void>;
46
46
  resetLiveTxUpdates(success?: boolean): Promise<void>;
47
47
  abstract protocolAccount(): PublicKey;
@@ -16,8 +16,8 @@ const generalUtils_2 = require("../utils/solauto/generalUtils");
16
16
  const referralStateManager_1 = require("./referralStateManager");
17
17
  const txHandler_1 = require("./txHandler");
18
18
  class SolautoClient extends txHandler_1.TxHandler {
19
- constructor(heliusApiKey, localTest) {
20
- super(heliusApiKey, localTest);
19
+ constructor(heliusApiUrl, localTest) {
20
+ super(heliusApiUrl, localTest);
21
21
  this.localTest = localTest;
22
22
  this.livePositionUpdates = new generalUtils_2.LivePositionUpdates();
23
23
  this.umi = this.umi.use({
@@ -55,7 +55,7 @@ class SolautoClient extends txHandler_1.TxHandler {
55
55
  : web3_js_1.PublicKey.default);
56
56
  this.positionDebtTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtMint);
57
57
  this.signerDebtTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtMint);
58
- this.referralStateManager = new referralStateManager_1.ReferralStateManager(this.heliusApiKey);
58
+ this.referralStateManager = new referralStateManager_1.ReferralStateManager(this.heliusApiUrl);
59
59
  await this.referralStateManager.initialize({
60
60
  referralAuthority: this.authority,
61
61
  signer: args.signer,
@@ -2,10 +2,10 @@ import { Umi } from "@metaplex-foundation/umi";
2
2
  import { Connection } from "@solana/web3.js";
3
3
  export declare abstract class TxHandler {
4
4
  localTest?: boolean | undefined;
5
- heliusApiKey: string;
5
+ heliusApiUrl: string;
6
6
  umi: Umi;
7
7
  connection: Connection;
8
- constructor(heliusApiKey: string, localTest?: boolean | undefined);
8
+ constructor(heliusApiUrl: string, localTest?: boolean | undefined);
9
9
  log(...args: any[]): void;
10
10
  abstract defaultLookupTables(): string[];
11
11
  abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../src/clients/txHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C,8BAAsB,SAAS;IAMpB,SAAS,CAAC,EAAE,OAAO;IALrB,YAAY,EAAG,MAAM,CAAC;IACtB,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;gBAEnB,YAAY,EAAE,MAAM,EACvB,SAAS,CAAC,EAAE,OAAO,YAAA;IAO5B,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAMzB,QAAQ,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAExC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAC9D"}
1
+ {"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../src/clients/txHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,8BAAsB,SAAS;IAOpB,SAAS,CAAC,EAAE,OAAO;IANrB,YAAY,EAAG,MAAM,CAAC;IACtB,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;gBAG7B,YAAY,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,OAAO,YAAA;IAQ5B,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAMzB,QAAQ,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAExC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAC9D"}
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TxHandler = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  class TxHandler {
6
- constructor(heliusApiKey, localTest) {
6
+ constructor(heliusApiUrl, localTest) {
7
7
  this.localTest = localTest;
8
- this.heliusApiKey = heliusApiKey;
9
- const [connection, umi] = (0, utils_1.getSolanaRpcConnection)(this.heliusApiKey);
8
+ this.heliusApiUrl = heliusApiUrl;
9
+ const [connection, umi] = (0, utils_1.getSolanaRpcConnection)(this.heliusApiUrl);
10
10
  this.connection = connection;
11
11
  this.umi = umi;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiUt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nD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAsJpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3B"}
@@ -81,6 +81,8 @@ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithS
81
81
  state: await getMarginfiAccountPositionState(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey)),
82
82
  })));
83
83
  return positionStates
84
+ .sort((a, b) => (0, numberUtils_1.fromBaseUnit)(b.state?.netWorth.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS) -
85
+ (0, numberUtils_1.fromBaseUnit)(a.state?.netWorth.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS))
84
86
  .filter((x) => x.state !== undefined)
85
87
  .map((x) => ({
86
88
  marginfiAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey),
@@ -153,7 +155,9 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
153
155
  }
154
156
  if (supplyBalances.length > 0) {
155
157
  if (supplyBank === null) {
156
- supplyBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, supplyBalances[0].bankPk, { commitment: "confirmed" });
158
+ supplyBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, supplyBalances[0].bankPk, {
159
+ commitment: "confirmed",
160
+ });
157
161
  }
158
162
  if (!supplyMint) {
159
163
  supplyMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint);
@@ -162,7 +166,9 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
162
166
  }
163
167
  if (debtBalances.length > 0) {
164
168
  if (debtBank === null) {
165
- debtBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, debtBalances[0].bankPk, { commitment: "confirmed" });
169
+ debtBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, debtBalances[0].bankPk, {
170
+ commitment: "confirmed",
171
+ });
166
172
  }
167
173
  if (!debtMint) {
168
174
  debtMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(debtBank.mint);
@@ -1,7 +1,8 @@
1
1
  import { AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
2
2
  import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
3
3
  import { PriorityFeeSetting, TransactionRunType } from "../types";
4
- export declare function getSolanaRpcConnection(heliusApiKey: string): [Connection, Umi];
4
+ export declare function buildHeliusApiUrl(heliusApiKey: string): string;
5
+ export declare function getSolanaRpcConnection(heliusApiUrl: string): [Connection, Umi];
5
6
  export declare function getWrappedInstruction(signer: Signer, ix: TransactionInstruction): WrappedInstruction;
6
7
  export declare function setComputeUnitLimitUmiIx(signer: Signer, maxComputeUnits: number): WrappedInstruction;
7
8
  export declare function setComputeUnitPriceUmiIx(signer: Signer, lamports: number): WrappedInstruction;
@@ -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,wBAAgB,qBAAqB,CACn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AS,EACvB,SAAS,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"}
@@ -3,6 +3,7 @@ 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.buildHeliusApiUrl = buildHeliusApiUrl;
6
7
  exports.getSolanaRpcConnection = getSolanaRpcConnection;
7
8
  exports.getWrappedInstruction = getWrappedInstruction;
8
9
  exports.setComputeUnitLimitUmiIx = setComputeUnitLimitUmiIx;
@@ -25,8 +26,11 @@ const accountUtils_1 = require("./accountUtils");
25
26
  const generalUtils_1 = require("./generalUtils");
26
27
  const marginfi_sdk_1 = require("../marginfi-sdk");
27
28
  const types_1 = require("../types");
28
- function getSolanaRpcConnection(heliusApiKey) {
29
- const connection = new web3_js_1.Connection(`https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`, "confirmed");
29
+ function buildHeliusApiUrl(heliusApiKey) {
30
+ return `https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`;
31
+ }
32
+ function getSolanaRpcConnection(heliusApiUrl) {
33
+ const connection = new web3_js_1.Connection(heliusApiUrl, "confirmed");
30
34
  const umi = (0, umi_bundle_defaults_1.createUmi)(connection);
31
35
  return [connection, umi];
32
36
  }
@@ -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,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAW1D;AAgBD,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,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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"}
@@ -5,6 +5,7 @@ import {
5
5
  transactionBuilder,
6
6
  } from "@metaplex-foundation/umi";
7
7
  import {
8
+ buildHeliusApiUrl,
8
9
  getSolanaRpcConnection,
9
10
  sendSingleOptimizedTransaction,
10
11
  } from "../src/utils/solanaUtils";
@@ -14,7 +15,7 @@ import { getSecretKey } from "./shared";
14
15
  import { updateSolautoLut } from "./updateSolautoLUT";
15
16
 
16
17
  async function create() {
17
- let [connection, umi] = getSolanaRpcConnection(process.env.HELIUS_API_KEY!);
18
+ let [connection, umi] = getSolanaRpcConnection(buildHeliusApiUrl(process.env.HELIUS_API_KEY!));
18
19
 
19
20
  const secretKey = getSecretKey("solauto-manager");
20
21
  const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
package/local/shared.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  VersionedTransaction,
9
9
  PublicKey,
10
10
  } from "@solana/web3.js";
11
- import { getSolanaRpcConnection } from "../src/utils/solanaUtils";
11
+ import { buildHeliusApiUrl, getSolanaRpcConnection } from "../src/utils/solanaUtils";
12
12
 
13
13
  function loadSecretKey(keypairPath: string) {
14
14
  const secretKey = JSON.parse(fs.readFileSync(keypairPath, "utf8"));
@@ -22,7 +22,7 @@ export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
22
22
  }
23
23
 
24
24
  const keypair = Keypair.fromSecretKey(getSecretKey());
25
- const [connection, _] = getSolanaRpcConnection(process.env.HELIUS_API_KEY ?? "");
25
+ const [connection, _] = getSolanaRpcConnection(buildHeliusApiUrl(process.env.HELIUS_API_KEY ?? ""));
26
26
 
27
27
  async function createAndSendV0Tx(txInstructions: TransactionInstruction[]) {
28
28
  let latestBlockhash = await connection.getLatestBlockhash("finalized");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.146",
3
+ "version": "1.0.147",
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",
@@ -21,8 +21,8 @@ export class ReferralStateManager extends TxHandler {
21
21
  public referralState!: PublicKey;
22
22
  public referralStateData!: ReferralState | null;
23
23
 
24
- constructor(heliusApiKey: string, public localTest?: boolean) {
25
- super(heliusApiKey, localTest)
24
+ constructor(heliusApiUrl: string, public localTest?: boolean) {
25
+ super(heliusApiUrl, localTest)
26
26
  this.umi = this.umi.use({
27
27
  install(umi) {
28
28
  umi.programs.add(createSolautoProgram(), false);
@@ -100,10 +100,10 @@ export abstract class SolautoClient extends TxHandler {
100
100
  public livePositionUpdates: LivePositionUpdates = new LivePositionUpdates();
101
101
 
102
102
  constructor(
103
- heliusApiKey: string,
103
+ heliusApiUrl: string,
104
104
  public localTest?: boolean
105
105
  ) {
106
- super(heliusApiKey, localTest);
106
+ super(heliusApiUrl, localTest);
107
107
 
108
108
  this.umi = this.umi.use({
109
109
  install(umi) {
@@ -164,7 +164,7 @@ export abstract class SolautoClient extends TxHandler {
164
164
  this.debtMint
165
165
  );
166
166
 
167
- this.referralStateManager = new ReferralStateManager(this.heliusApiKey);
167
+ this.referralStateManager = new ReferralStateManager(this.heliusApiUrl);
168
168
  await this.referralStateManager.initialize({
169
169
  referralAuthority: this.authority,
170
170
  signer: args.signer,
@@ -2,18 +2,19 @@ import { Umi } from "@metaplex-foundation/umi";
2
2
  import { Connection } from "@solana/web3.js";
3
3
  import { getSolanaRpcConnection } from "../utils";
4
4
 
5
-
6
5
  export abstract class TxHandler {
7
- public heliusApiKey!: string;
6
+ public heliusApiUrl!: string;
8
7
  public umi!: Umi;
9
8
  public connection!: Connection;
10
9
 
11
- constructor(heliusApiKey: string,
12
- public localTest?: boolean) {
13
- this.heliusApiKey = heliusApiKey;
14
- const [connection, umi] = getSolanaRpcConnection(this.heliusApiKey);
15
- this.connection = connection;
16
- this.umi = umi;
10
+ constructor(
11
+ heliusApiUrl: string,
12
+ public localTest?: boolean
13
+ ) {
14
+ this.heliusApiUrl = heliusApiUrl;
15
+ const [connection, umi] = getSolanaRpcConnection(this.heliusApiUrl);
16
+ this.connection = connection;
17
+ this.umi = umi;
17
18
  }
18
19
 
19
20
  log(...args: any[]): void {
@@ -25,4 +26,4 @@ export abstract class TxHandler {
25
26
  abstract defaultLookupTables(): string[];
26
27
 
27
28
  abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
28
- }
29
+ }
@@ -8,7 +8,11 @@ import {
8
8
  safeFetchBank,
9
9
  safeFetchMarginfiAccount,
10
10
  } from "../marginfi-sdk";
11
- import { currentUnixSeconds, fetchTokenPrices, safeGetPrice } from "./generalUtils";
11
+ import {
12
+ currentUnixSeconds,
13
+ fetchTokenPrices,
14
+ safeGetPrice,
15
+ } from "./generalUtils";
12
16
  import {
13
17
  bytesToI80F48,
14
18
  fromBaseUnit,
@@ -64,9 +68,7 @@ export async function getMaxLtvAndLiqThreshold(
64
68
  ) {
65
69
  debt.bank = await safeFetchBank(
66
70
  umi,
67
- publicKey(
68
- MARGINFI_ACCOUNTS[debt.mint.toString()].bank
69
- ),
71
+ publicKey(MARGINFI_ACCOUNTS[debt.mint.toString()].bank),
70
72
  { commitment: "confirmed" }
71
73
  );
72
74
  }
@@ -94,7 +96,7 @@ export async function getMaxLtvAndLiqThreshold(
94
96
  BigInt(
95
97
  Math.round(
96
98
  bytesToI80F48(supply.bank!.totalAssetShares.value) *
97
- bytesToI80F48(supply.bank!.assetShareValue.value)
99
+ bytesToI80F48(supply.bank!.assetShareValue.value)
98
100
  )
99
101
  ),
100
102
  supply.bank!.mintDecimals
@@ -152,6 +154,17 @@ export async function getAllMarginfiAccountsByAuthority(
152
154
  }))
153
155
  );
154
156
  return positionStates
157
+ .sort(
158
+ (a, b) =>
159
+ fromBaseUnit(
160
+ b.state?.netWorth.baseAmountUsdValue ?? BigInt(0),
161
+ USD_DECIMALS
162
+ ) -
163
+ fromBaseUnit(
164
+ a.state?.netWorth.baseAmountUsdValue ?? BigInt(0),
165
+ USD_DECIMALS
166
+ )
167
+ )
155
168
  .filter((x) => x.state !== undefined)
156
169
  .map((x) => ({
157
170
  marginfiAccount: toWeb3JsPublicKey(x.publicKey),
@@ -190,7 +203,7 @@ async function getTokenUsage(
190
203
  amountCanBeUsed = isAsset
191
204
  ? Number(bank.config.depositLimit) - totalDeposited
192
205
  : totalDeposited -
193
- bytesToI80F48(bank.totalLiabilityShares.value) * liabilityShareValue;
206
+ bytesToI80F48(bank.totalLiabilityShares.value) * liabilityShareValue;
194
207
  }
195
208
 
196
209
  return {
@@ -200,22 +213,22 @@ async function getTokenUsage(
200
213
  baseUnit: BigInt(Math.round(amountUsed)),
201
214
  baseAmountUsdValue: bank
202
215
  ? toBaseUnit(
203
- fromBaseUnit(BigInt(Math.round(amountUsed)), bank.mintDecimals) *
204
- marketPrice,
205
- USD_DECIMALS
206
- )
216
+ fromBaseUnit(BigInt(Math.round(amountUsed)), bank.mintDecimals) *
217
+ marketPrice,
218
+ USD_DECIMALS
219
+ )
207
220
  : BigInt(0),
208
221
  },
209
222
  amountCanBeUsed: {
210
223
  baseUnit: BigInt(Math.round(amountCanBeUsed)),
211
224
  baseAmountUsdValue: bank
212
225
  ? toBaseUnit(
213
- fromBaseUnit(
214
- BigInt(Math.round(amountCanBeUsed)),
215
- bank.mintDecimals
216
- ) * marketPrice,
217
- USD_DECIMALS
218
- )
226
+ fromBaseUnit(
227
+ BigInt(Math.round(amountCanBeUsed)),
228
+ bank.mintDecimals
229
+ ) * marketPrice,
230
+ USD_DECIMALS
231
+ )
219
232
  : BigInt(0),
220
233
  },
221
234
  baseAmountMarketPriceUsd: toBaseUnit(marketPrice, USD_DECIMALS),
@@ -243,18 +256,18 @@ export async function getMarginfiAccountPositionState(
243
256
  let supplyBank: Bank | null =
244
257
  supplyMint && supplyMint !== PublicKey.default
245
258
  ? await safeFetchBank(
246
- umi,
247
- publicKey(MARGINFI_ACCOUNTS[supplyMint.toString()].bank),
248
- { commitment: "confirmed" }
249
- )
259
+ umi,
260
+ publicKey(MARGINFI_ACCOUNTS[supplyMint.toString()].bank),
261
+ { commitment: "confirmed" }
262
+ )
250
263
  : null;
251
264
  let debtBank: Bank | null =
252
265
  debtMint && debtMint !== PublicKey.default
253
266
  ? await safeFetchBank(
254
- umi,
255
- publicKey(MARGINFI_ACCOUNTS[debtMint.toString()].bank),
256
- { commitment: "confirmed" }
257
- )
267
+ umi,
268
+ publicKey(MARGINFI_ACCOUNTS[debtMint.toString()].bank),
269
+ { commitment: "confirmed" }
270
+ )
258
271
  : null;
259
272
 
260
273
  let supplyUsage: PositionTokenUsage | undefined = undefined;
@@ -280,7 +293,9 @@ export async function getMarginfiAccountPositionState(
280
293
 
281
294
  if (supplyBalances.length > 0) {
282
295
  if (supplyBank === null) {
283
- supplyBank = await safeFetchBank(umi, supplyBalances[0].bankPk, { commitment: "confirmed" });
296
+ supplyBank = await safeFetchBank(umi, supplyBalances[0].bankPk, {
297
+ commitment: "confirmed",
298
+ });
284
299
  }
285
300
  if (!supplyMint) {
286
301
  supplyMint = toWeb3JsPublicKey(supplyBank!.mint);
@@ -296,7 +311,9 @@ export async function getMarginfiAccountPositionState(
296
311
 
297
312
  if (debtBalances.length > 0) {
298
313
  if (debtBank === null) {
299
- debtBank = await safeFetchBank(umi, debtBalances[0].bankPk, { commitment: "confirmed" });
314
+ debtBank = await safeFetchBank(umi, debtBalances[0].bankPk, {
315
+ commitment: "confirmed",
316
+ });
300
317
  }
301
318
  if (!debtMint) {
302
319
  debtMint = toWeb3JsPublicKey(debtBank!.mint);
@@ -38,13 +38,14 @@ import {
38
38
  } from "../marginfi-sdk";
39
39
  import { PriorityFeeSetting, TransactionRunType } from "../types";
40
40
 
41
+ export function buildHeliusApiUrl(heliusApiKey: string) {
42
+ return `https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`;
43
+ }
44
+
41
45
  export function getSolanaRpcConnection(
42
- heliusApiKey: string
46
+ heliusApiUrl: string
43
47
  ): [Connection, Umi] {
44
- const connection = new Connection(
45
- `https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`,
46
- "confirmed"
47
- );
48
+ const connection = new Connection(heliusApiUrl, "confirmed");
48
49
  const umi = createUmi(connection);
49
50
  return [connection, umi];
50
51
  }
@@ -306,7 +307,7 @@ export async function sendSingleOptimizedTransaction(
306
307
  ),
307
308
  3
308
309
  );
309
-
310
+
310
311
  const computeUnitLimit = Math.round(
311
312
  simulationResult.value.unitsConsumed! * 1.1
312
313
  );
@@ -328,7 +329,7 @@ export async function sendSingleOptimizedTransaction(
328
329
  confirm: { commitment: "confirmed" },
329
330
  });
330
331
  const txSig = bs58.encode(result.signature);
331
- console.log(`Transaction signature: ${txSig}`)
332
+ console.log(`Transaction signature: ${txSig}`);
332
333
  console.log(`https://solscan.io/tx/${txSig}`);
333
334
  if (result.result.value.err !== null) {
334
335
  throw new Error(result.result.value.err.toString());
@@ -13,7 +13,6 @@ import {
13
13
  getReferralStateSize,
14
14
  getSolautoPositionAccountDataSerializer,
15
15
  getSolautoPositionSize,
16
- safeFetchAllSolautoPosition,
17
16
  } from "../../generated";
18
17
  import { currentUnixSeconds, fetchTokenPrices } from "../generalUtils";
19
18
  import {
@@ -18,6 +18,7 @@ import {
18
18
  } from "../../src/transactions/transactionsManager";
19
19
  import { PublicKey } from "@solana/web3.js";
20
20
  import { USDC_MINT } from "../../src/constants";
21
+ import { buildHeliusApiUrl } from "../../src/utils";
21
22
 
22
23
  describe("Solauto Marginfi tests", async () => {
23
24
  // const signer = setupTest();
@@ -29,7 +30,7 @@ describe("Solauto Marginfi tests", async () => {
29
30
 
30
31
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
31
32
 
32
- const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
33
+ const client = new SolautoMarginfiClient(buildHeliusApiUrl(process.env.HELIUS_API_KEY!), true);
33
34
 
34
35
  const supply = NATIVE_MINT;
35
36
  const supplyDecimals = 9;
@@ -39,7 +40,7 @@ describe("Solauto Marginfi tests", async () => {
39
40
  {
40
41
  signer,
41
42
  positionId,
42
- // authority: new PublicKey("")
43
+ authority: new PublicKey("AprYCPiVeKMCgjQ2ZufwChMzvQ5kFjJo2ekTLSkXsQDm")
43
44
  // marginfiAccount: new PublicKey(
44
45
  // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
45
46
  // ),