@haven-fi/solauto-sdk 1.0.787 → 1.0.789

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":"general.d.ts","sourceRoot":"","sources":["../../../src/utils/marginfi/general.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAKhF,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAGL,uBAAuB,EAExB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,OAAO,EACP,IAAI,EAIJ,eAAe,EAGhB,MAAM,6BAA6B,CAAC;AAMrC,wBAAgB,4BAA4B,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CActE;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,UAAU,OASxE;AAED,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,GAAG,EACR,eAAe,EAAE,uBAAuB,GACvC,OAAO,CAAC,SAAS,EAAE,CAAC,CAyBtB;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS;;;;;GAanE;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE;IAAE,EAAE,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,sBAOtC;AAED,UAAU,wBAAyB,SAAQ,qBAAqB;IAC9D,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GACd,wBAAwB,CAyB1B;AAED,wBAAsB,0CAA0C,CAC9D,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OA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AAQ,qBAAqB;IAC9D,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GACd,wBAAwB,CAyB1B;AAED,wBAAsB,0CAA0C,CAC9D,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,WAAW,EAAE,CAAC,CAWxB;AAED,wBAAgB,oCAAoC,CAClD,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,MAAM,GAClB,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BlB;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAW3E"}
@@ -17,7 +17,9 @@ const constants_1 = require("../../constants");
17
17
  const marginfi_1 = require("../../externalSdks/marginfi");
18
18
  const numberUtils_1 = require("../numberUtils");
19
19
  const accountUtils_1 = require("../accountUtils");
20
+ const pythUtils_1 = require("../pythUtils");
20
21
  const solanaUtils_1 = require("../solanaUtils");
22
+ const generalUtils_1 = require("../generalUtils");
21
23
  function createDynamicMarginfiProgram(env) {
22
24
  return {
23
25
  name: "marginfi",
@@ -44,7 +46,10 @@ async function getAllBankRelatedAccounts(umi, bankAccountsMap) {
44
46
  const banks = Object.values(bankAccountsMap).flatMap((group) => Object.values(group).map((accounts) => accounts.bank));
45
47
  const banksData = await (0, marginfi_1.safeFetchAllBank)(umi, banks.map((x) => (0, umi_1.publicKey)(x)));
46
48
  const oracles = banksData
47
- .map((bank) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.config.oracleKeys[0]))
49
+ .map((bank) => bank.config.oracleKeys
50
+ .map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x))
51
+ .filter((x) => (0, generalUtils_1.validPubkey)(x)))
52
+ .flat()
48
53
  .map((x) => x.toString());
49
54
  const otherAccounts = Object.entries(bankAccountsMap).flatMap(([groupName, tokenMap]) => Object.values(tokenMap).flatMap((accounts) => [
50
55
  groupName,
@@ -72,7 +77,12 @@ async function getMarginfiPriceOracle(umi, bank) {
72
77
  if (!bank.data) {
73
78
  bank.data = await (0, marginfi_1.fetchBank)(umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(bank.pk));
74
79
  }
75
- return (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.data.config.oracleKeys[0]);
80
+ const priceOracle = bank.data.config.oracleSetup === marginfi_1.OracleSetup.PythPushOracle
81
+ ? await (0, pythUtils_1.getMostUpToDatePythOracle)(umi, bank.data.config.oracleKeys
82
+ .map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x))
83
+ .filter((x) => (0, generalUtils_1.validPubkey)(x)))
84
+ : (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.data.config.oracleKeys[0]);
85
+ return priceOracle;
76
86
  }
77
87
  function findMarginfiAccounts(bank) {
78
88
  const search = (bankAccounts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.787",
3
+ "version": "1.0.789",
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",
@@ -23,8 +23,12 @@ import {
23
23
  } from "../../externalSdks/marginfi";
24
24
  import { bytesToI80F48, fromBaseUnit, toBps } from "../numberUtils";
25
25
  import { getTokenAccountData } from "../accountUtils";
26
- import { getPythPushOracleAddress } from "../pythUtils";
26
+ import {
27
+ getMostUpToDatePythOracle,
28
+ getPythPushOracleAddress,
29
+ } from "../pythUtils";
27
30
  import { getAccountMeta } from "../solanaUtils";
31
+ import { validPubkey } from "../generalUtils";
28
32
 
29
33
  export function createDynamicMarginfiProgram(env?: ProgramEnv): Program {
30
34
  return {
@@ -66,7 +70,12 @@ export async function getAllBankRelatedAccounts(
66
70
  );
67
71
 
68
72
  const oracles = banksData
69
- .map((bank) => toWeb3JsPublicKey(bank.config.oracleKeys[0]))
73
+ .map((bank) =>
74
+ bank.config.oracleKeys
75
+ .map((x) => toWeb3JsPublicKey(x))
76
+ .filter((x) => validPubkey(x))
77
+ )
78
+ .flat()
70
79
  .map((x) => x.toString());
71
80
 
72
81
  const otherAccounts = Object.entries(bankAccountsMap).flatMap(
@@ -106,7 +115,17 @@ export async function getMarginfiPriceOracle(
106
115
  bank.data = await fetchBank(umi, fromWeb3JsPublicKey(bank.pk!));
107
116
  }
108
117
 
109
- return toWeb3JsPublicKey(bank.data.config.oracleKeys[0]);
118
+ const priceOracle =
119
+ bank.data.config.oracleSetup === OracleSetup.PythPushOracle
120
+ ? await getMostUpToDatePythOracle(
121
+ umi,
122
+ bank.data.config.oracleKeys
123
+ .map((x) => toWeb3JsPublicKey(x))
124
+ .filter((x) => validPubkey(x))
125
+ )
126
+ : toWeb3JsPublicKey(bank.data.config.oracleKeys[0]);
127
+
128
+ return priceOracle;
110
129
  }
111
130
 
112
131
  interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {