@haven-fi/solauto-sdk 1.0.206 → 1.0.207

Sign up to get free protection for your applications and to get access to all the features.
@@ -429,7 +429,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
429
429
  if (state) {
430
430
  return state;
431
431
  }
432
- const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.marginfiGroup, !this.selfManaged && this.solautoPositionData === null
432
+ const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.marginfiAccountPk }, this.marginfiGroup, !this.selfManaged && this.solautoPositionData === null
433
433
  ? { mint: this.supplyMint }
434
434
  : undefined, !this.selfManaged && this.solautoPositionData === null
435
435
  ? { mint: this.debtMint }
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Umi } from "@metaplex-foundation/umi";
3
- import { Bank } from "../marginfi-sdk";
3
+ import { Bank, MarginfiAccount } from "../marginfi-sdk";
4
4
  import { MarginfiAssetAccounts } from "../types/accounts";
5
5
  import { PositionState } from "../generated";
6
6
  import { LivePositionUpdates } from "./solauto/generalUtils";
@@ -27,7 +27,10 @@ type BanksCache = {
27
27
  [mint: string]: Bank;
28
28
  };
29
29
  };
30
- export declare function getMarginfiAccountPositionState(umi: Umi, marginfiAccountPk: PublicKey, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
30
+ export declare function getMarginfiAccountPositionState(umi: Umi, protocolAccount: {
31
+ pk: PublicKey;
32
+ data?: MarginfiAccount;
33
+ }, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
31
34
  export declare function calculateAnnualAPYs(bank: Bank): [number, number];
32
35
  export declare function getUpToDateShareValues(bank: Bank): Promise<[number, number]>;
33
36
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src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,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgB3B"}
@@ -86,7 +86,7 @@ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithS
86
86
  if (compatibleWithSolauto) {
87
87
  const positionStates = await Promise.all(marginfiAccounts.map(async (x) => ({
88
88
  publicKey: x.publicKey,
89
- state: await getMarginfiAccountPositionState(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey)),
89
+ state: await getMarginfiAccountPositionState(umi, { pk: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey) }),
90
90
  })));
91
91
  return positionStates
92
92
  .sort((a, b) => (0, numberUtils_1.fromBaseUnit)(b.state?.netWorth.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS) -
@@ -143,8 +143,11 @@ async function getTokenUsage(bank, isAsset, shares, amountUsedAdjustment) {
143
143
  padding: new Uint8Array([]),
144
144
  };
145
145
  }
146
- async function getMarginfiAccountPositionState(umi, marginfiAccountPk, marginfiGroup, supply, debt, livePositionUpdates) {
147
- let marginfiAccount = await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(marginfiAccountPk), { commitment: "confirmed" });
146
+ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGroup, supply, debt, livePositionUpdates) {
147
+ let marginfiAccount = protocolAccount.data ??
148
+ (await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(protocolAccount.pk), {
149
+ commitment: "confirmed",
150
+ }));
148
151
  if (!supply) {
149
152
  supply = {};
150
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.206",
3
+ "version": "1.0.207",
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",
@@ -649,7 +649,7 @@ export class SolautoMarginfiClient extends SolautoClient {
649
649
 
650
650
  const freshState = await getMarginfiAccountPositionState(
651
651
  this.umi,
652
- this.marginfiAccountPk,
652
+ { pk: this.marginfiAccountPk },
653
653
  this.marginfiGroup,
654
654
  !this.selfManaged && this.solautoPositionData === null
655
655
  ? { mint: this.supplyMint }
@@ -5,6 +5,7 @@ import {
5
5
  Bank,
6
6
  getMarginfiAccountSize,
7
7
  MARGINFI_PROGRAM_ID,
8
+ MarginfiAccount,
8
9
  safeFetchBank,
9
10
  safeFetchMarginfiAccount,
10
11
  } from "../marginfi-sdk";
@@ -168,7 +169,7 @@ export async function getAllMarginfiAccountsByAuthority(
168
169
  publicKey: x.publicKey,
169
170
  state: await getMarginfiAccountPositionState(
170
171
  umi,
171
- toWeb3JsPublicKey(x.publicKey)
172
+ { pk: toWeb3JsPublicKey(x.publicKey) }
172
173
  ),
173
174
  }))
174
175
  );
@@ -265,17 +266,17 @@ type BanksCache = { [group: string]: { [mint: string]: Bank } };
265
266
 
266
267
  export async function getMarginfiAccountPositionState(
267
268
  umi: Umi,
268
- marginfiAccountPk: PublicKey,
269
+ protocolAccount: { pk: PublicKey; data?: MarginfiAccount },
269
270
  marginfiGroup?: PublicKey,
270
271
  supply?: BankSelection,
271
272
  debt?: BankSelection,
272
273
  livePositionUpdates?: LivePositionUpdates
273
274
  ): Promise<PositionState | undefined> {
274
- let marginfiAccount = await safeFetchMarginfiAccount(
275
- umi,
276
- publicKey(marginfiAccountPk),
277
- { commitment: "confirmed" }
278
- );
275
+ let marginfiAccount =
276
+ protocolAccount.data ??
277
+ (await safeFetchMarginfiAccount(umi, publicKey(protocolAccount.pk), {
278
+ commitment: "confirmed",
279
+ }));
279
280
 
280
281
  if (!supply) {
281
282
  supply = {};
@@ -3,8 +3,6 @@ import { none, publicKey, some } from "@metaplex-foundation/umi";
3
3
  import { setupTest } from "../shared";
4
4
  import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
5
5
  import {
6
- PositionType,
7
- safeFetchAllSolautoPosition,
8
6
  solautoAction,
9
7
  SolautoSettingsParametersInpArgs,
10
8
  } from "../../src/generated";
@@ -15,7 +13,7 @@ import {
15
13
  maxRepayToBps,
16
14
  toBaseUnit,
17
15
  } from "../../src/utils/numberUtils";
18
- import { getAssociatedTokenAddress, NATIVE_MINT } from "@solana/spl-token";
16
+ import { NATIVE_MINT } from "@solana/spl-token";
19
17
  import { fetchTokenPrices } from "../../src/utils/generalUtils";
20
18
  import {
21
19
  TransactionItem,
@@ -23,13 +21,7 @@ import {
23
21
  } from "../../src/transactions/transactionsManager";
24
22
  import { PublicKey } from "@solana/web3.js";
25
23
  import { USDC } from "../../src/constants";
26
- import {
27
- buildHeliusApiUrl,
28
- getAllPositionsByAuthority,
29
- getMarginfiAccountPositionState,
30
- getSolautoManagedPositions,
31
- } from "../../src/utils";
32
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
24
+ import { buildHeliusApiUrl } from "../../src/utils";
33
25
 
34
26
  describe("Solauto Marginfi tests", async () => {
35
27
  // const signer = setupTest();