@haven-fi/solauto-sdk 1.0.206 → 1.0.208

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,7 +1,7 @@
1
- import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
1
+ import { TransactionBuilder } from "@metaplex-foundation/umi";
2
2
  import { PublicKey } from "@solana/web3.js";
3
- import { ReferralState } from "../generated";
4
3
  import { SolautoClient } from "../clients/solautoClient";
4
+ import { ReferralStateManager } from "../clients";
5
5
  export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
6
6
  export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
7
7
  export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
@@ -9,7 +9,7 @@ export declare function buildSolautoRebalanceTransaction(client: SolautoClient,
9
9
  tx: TransactionBuilder;
10
10
  lookupTableAddresses: string[];
11
11
  } | undefined>;
12
- export declare function convertReferralFeesToDestination(umi: Umi, referralState: ReferralState, tokenAccount: PublicKey): Promise<[TransactionBuilder, string[]] | undefined>;
12
+ export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<[TransactionBuilder, string[]] | undefined>;
13
13
  export declare function getErrorInfo(tx: TransactionBuilder, error: any): {
14
14
  errorName: string | undefined;
15
15
  errorInfo: undefined;
@@ -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;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAGL,aAAa,EAYd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqOzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBAwCzE;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,CAkHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
1
+ {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAInB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAsBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAgM7D,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBAwCzE;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,CAkHA;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
@@ -400,26 +400,26 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
400
400
  lookupTableAddresses,
401
401
  };
402
402
  }
403
- async function convertReferralFeesToDestination(umi, referralState, tokenAccount) {
404
- const tokenAccountData = await (0, accountUtils_1.getTokenAccountData)(umi, tokenAccount);
403
+ async function convertReferralFeesToDestination(referralManager, tokenAccount, destinationMint) {
404
+ const tokenAccountData = await (0, accountUtils_1.getTokenAccountData)(referralManager.umi, tokenAccount);
405
405
  if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
406
406
  return undefined;
407
407
  }
408
- const { lookupTableAddresses, setupInstructions, swapIx } = await (0, jupiterUtils_1.getJupSwapTransaction)(umi.identity, {
408
+ const { lookupTableAddresses, setupInstructions, swapIx } = await (0, jupiterUtils_1.getJupSwapTransaction)(referralManager.umi.identity, {
409
409
  amount: tokenAccountData.amount,
410
- destinationWallet: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.publicKey),
410
+ destinationWallet: referralManager.referralState,
411
411
  inputMint: tokenAccountData.mint,
412
- outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.destFeesMint),
412
+ outputMint: destinationMint,
413
413
  exactIn: true,
414
414
  slippageIncFactor: 0.25,
415
415
  });
416
416
  let tx = (0, umi_1.transactionBuilder)()
417
417
  .add(setupInstructions)
418
- .add((0, generated_1.convertReferralFees)(umi, {
419
- signer: umi.identity,
420
- intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(umi.identity.publicKey), tokenAccountData.mint)),
418
+ .add((0, generated_1.convertReferralFees)(referralManager.umi, {
419
+ signer: referralManager.umi.identity,
420
+ intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralManager.umi.identity.publicKey), tokenAccountData.mint)),
421
421
  ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
422
- referralState: referralState.publicKey,
422
+ referralState: (0, umi_1.publicKey)(referralManager.referralState),
423
423
  referralFeesTa: (0, umi_1.publicKey)(tokenAccount),
424
424
  }))
425
425
  .add(swapIx);
@@ -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/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;AAiBzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,qBAAqB,CAY3E;AAED,wBAAgB,gCAAgC,CAC9C,UAAU,E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;IAAE,eAAe,EAAE,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,EAAE,CAC/E,CAwDA;AA6DD,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,KAAK,UAAU,GAAG;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,CAAC;AAEhE,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,eAAe,EAAE;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,eAAe,CAAA;CAAE,EAC1D,aAAa,CAAC,EAAE,SAAS,EACzB,MAAM,CAAC,EAAE,aAAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA0LpC;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,IAAI,GACT,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.208",
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",
@@ -22,7 +22,6 @@
22
22
  "@metaplex-foundation/umi-web3js-adapters": "^0.9.1",
23
23
  "@solana/spl-token": "^0.4.0",
24
24
  "@solana/web3.js": "^1.92.1",
25
- "@sqds/multisig": "^2.1.3",
26
25
  "bs58": "^5.0.0",
27
26
  "cross-fetch": "^4.0.0",
28
27
  "rpc-websockets": "7.11.0"
@@ -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 }
@@ -26,6 +26,7 @@ import {
26
26
  getMarginfiRebalanceInstructionDataSerializer,
27
27
  getSolautoErrorFromCode,
28
28
  isSolautoAction,
29
+ safeFetchReferralState,
29
30
  solautoAction,
30
31
  } from "../generated";
31
32
  import { SolautoClient } from "../clients/solautoClient";
@@ -65,7 +66,7 @@ import {
65
66
  getMarginfiErrorFromName,
66
67
  MARGINFI_PROGRAM_ID,
67
68
  } from "../marginfi-sdk";
68
- import { TxHandler } from "../clients";
69
+ import { ReferralStateManager, TxHandler } from "../clients";
69
70
  import {
70
71
  createJupiterProgram,
71
72
  getJupiterErrorFromName,
@@ -750,21 +751,21 @@ export async function buildSolautoRebalanceTransaction(
750
751
  }
751
752
 
752
753
  export async function convertReferralFeesToDestination(
753
- umi: Umi,
754
- referralState: ReferralState,
755
- tokenAccount: PublicKey
754
+ referralManager: ReferralStateManager,
755
+ tokenAccount: PublicKey,
756
+ destinationMint: PublicKey
756
757
  ): Promise<[TransactionBuilder, string[]] | undefined> {
757
- const tokenAccountData = await getTokenAccountData(umi, tokenAccount);
758
+ const tokenAccountData = await getTokenAccountData(referralManager.umi, tokenAccount);
758
759
  if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
759
760
  return undefined;
760
761
  }
761
762
 
762
763
  const { lookupTableAddresses, setupInstructions, swapIx } =
763
- await getJupSwapTransaction(umi.identity, {
764
+ await getJupSwapTransaction(referralManager.umi.identity, {
764
765
  amount: tokenAccountData.amount,
765
- destinationWallet: toWeb3JsPublicKey(referralState.publicKey),
766
+ destinationWallet: referralManager.referralState,
766
767
  inputMint: tokenAccountData.mint,
767
- outputMint: toWeb3JsPublicKey(referralState.destFeesMint),
768
+ outputMint: destinationMint,
768
769
  exactIn: true,
769
770
  slippageIncFactor: 0.25,
770
771
  });
@@ -772,16 +773,16 @@ export async function convertReferralFeesToDestination(
772
773
  let tx = transactionBuilder()
773
774
  .add(setupInstructions)
774
775
  .add(
775
- convertReferralFees(umi, {
776
- signer: umi.identity,
776
+ convertReferralFees(referralManager.umi, {
777
+ signer: referralManager.umi.identity,
777
778
  intermediaryTa: publicKey(
778
779
  getTokenAccount(
779
- toWeb3JsPublicKey(umi.identity.publicKey),
780
+ toWeb3JsPublicKey(referralManager.umi.identity.publicKey),
780
781
  tokenAccountData.mint
781
782
  )
782
783
  ),
783
784
  ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
784
- referralState: referralState.publicKey,
785
+ referralState: publicKey(referralManager.referralState),
785
786
  referralFeesTa: publicKey(tokenAccount),
786
787
  })
787
788
  )
@@ -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();