@0dotxyz/p0-ts-sdk 2.5.0 → 2.5.2-alpha.0
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.
- package/dist/index.cjs +34 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -9
- package/dist/index.d.ts +30 -9
- package/dist/index.js +33 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24720,17 +24720,17 @@ var mapSwbBanksToOraclePrices = (banks, swbOracleAiDataByKey, crossbarResponse)
|
|
|
24720
24720
|
});
|
|
24721
24721
|
return bankOraclePriceMap;
|
|
24722
24722
|
};
|
|
24723
|
-
var mapBrokenFeedsToOraclePrices = (banks, swbOracleAiDataByKey,
|
|
24723
|
+
var mapBrokenFeedsToOraclePrices = (banks, swbOracleAiDataByKey, fallbackPricesByFeedId) => {
|
|
24724
24724
|
const bankOraclePriceMap = /* @__PURE__ */ new Map();
|
|
24725
24725
|
banks.forEach((bank) => {
|
|
24726
24726
|
const oracleKey = bank.config.oracleKeys[0].toBase58();
|
|
24727
24727
|
const oracleData = swbOracleAiDataByKey[oracleKey];
|
|
24728
24728
|
const oracleFeed = oracleData?.feedHash;
|
|
24729
|
-
const
|
|
24730
|
-
if (oracleFeed && oracleData &&
|
|
24729
|
+
const fallbackPrice = oracleFeed ? fallbackPricesByFeedId[oracleFeed] : void 0;
|
|
24730
|
+
if (oracleFeed && oracleData && fallbackPrice) {
|
|
24731
24731
|
const timestamp = (/* @__PURE__ */ new Date()).getTime().toString();
|
|
24732
24732
|
const oraclePrice = parseSwbOraclePriceData(
|
|
24733
|
-
[
|
|
24733
|
+
[fallbackPrice],
|
|
24734
24734
|
new BN9__default.default(oracleData.stdev),
|
|
24735
24735
|
timestamp,
|
|
24736
24736
|
oracleData
|
|
@@ -25246,8 +25246,8 @@ function partitionBanksByCrankability(banks, crankabilityResults) {
|
|
|
25246
25246
|
return { crankable, uncrankable };
|
|
25247
25247
|
}
|
|
25248
25248
|
|
|
25249
|
-
// src/services/price/utils/
|
|
25250
|
-
async function
|
|
25249
|
+
// src/services/price/utils/price-fallback.utils.ts
|
|
25250
|
+
async function getFallbackPricesForMints(mintAddresses, apiEndpoint, opts) {
|
|
25251
25251
|
const queryKey = opts?.queryKey ?? "mintList";
|
|
25252
25252
|
try {
|
|
25253
25253
|
const url = `${apiEndpoint}?${queryKey}=${mintAddresses.join(",")}`;
|
|
@@ -25266,13 +25266,14 @@ async function getBirdeyePricesForMints(mintAddresses, apiEndpoint, opts) {
|
|
|
25266
25266
|
});
|
|
25267
25267
|
return extractedPrices;
|
|
25268
25268
|
} catch (error) {
|
|
25269
|
-
console.warn("Error fetching
|
|
25269
|
+
console.warn("Error fetching fallback prices for static feeds:", error);
|
|
25270
25270
|
return {};
|
|
25271
25271
|
}
|
|
25272
25272
|
}
|
|
25273
|
-
var
|
|
25273
|
+
var getBirdeyePricesForMints = getFallbackPricesForMints;
|
|
25274
|
+
var getFallbackPricesByFeedId = async (feedMint, apiEndpoint, opts) => {
|
|
25274
25275
|
const mintAddresses = feedMint.map((feedMint2) => feedMint2.mintAddress);
|
|
25275
|
-
const prices = await
|
|
25276
|
+
const prices = await getFallbackPricesForMints(
|
|
25276
25277
|
mintAddresses,
|
|
25277
25278
|
apiEndpoint,
|
|
25278
25279
|
opts
|
|
@@ -25288,6 +25289,7 @@ var getBirdeyeFallbackPricesByFeedId = async (feedMint, apiEndpoint, opts) => {
|
|
|
25288
25289
|
});
|
|
25289
25290
|
return priceByFeedId;
|
|
25290
25291
|
};
|
|
25292
|
+
var getBirdeyeFallbackPricesByFeedId = getFallbackPricesByFeedId;
|
|
25291
25293
|
|
|
25292
25294
|
// src/services/account/types/account.types.ts
|
|
25293
25295
|
var HealthCacheFlags = /* @__PURE__ */ ((HealthCacheFlags3) => {
|
|
@@ -70724,6 +70726,13 @@ async function computeSmartCrank({
|
|
|
70724
70726
|
isCrankable: true
|
|
70725
70727
|
});
|
|
70726
70728
|
}
|
|
70729
|
+
const activeEmodeWeightsByBank = computeLowestEmodeWeights(
|
|
70730
|
+
computeActiveEmodePairs(
|
|
70731
|
+
getEmodePairs(Array.from(bankMap.values())),
|
|
70732
|
+
liabilityBalances.map((b) => b.bankPk),
|
|
70733
|
+
assetBalances.map((b) => b.bankPk)
|
|
70734
|
+
)
|
|
70735
|
+
);
|
|
70727
70736
|
const getBanks = (balances) => balances.map((b) => bankMap.get(b.bankPk.toBase58())).filter((bank) => bank !== void 0);
|
|
70728
70737
|
const projectedAssetBanks = getBanks(assetBalances);
|
|
70729
70738
|
const liabilityBanks = getBanks(liabilityBalances);
|
|
@@ -70808,7 +70817,8 @@ async function computeSmartCrank({
|
|
|
70808
70817
|
oraclePricesByBank: oraclePrices,
|
|
70809
70818
|
assetBanks: nonSWBAssets.map((b) => b.address),
|
|
70810
70819
|
marginRequirement: 0 /* Initial */,
|
|
70811
|
-
assetShareValueMultiplierByBank
|
|
70820
|
+
assetShareValueMultiplierByBank,
|
|
70821
|
+
activeEmodeWeightsByBank
|
|
70812
70822
|
});
|
|
70813
70823
|
const healthDiff = nonSWBAssetsHealth.minus(totalLiabilitiesInitHealth);
|
|
70814
70824
|
if (healthDiff.gt(0)) {
|
|
@@ -70848,7 +70858,8 @@ async function computeSmartCrank({
|
|
|
70848
70858
|
oraclePricesByBank: oraclePrices,
|
|
70849
70859
|
assetBanks: allAvailableAssetAddresses,
|
|
70850
70860
|
marginRequirement: 0 /* Initial */,
|
|
70851
|
-
assetShareValueMultiplierByBank
|
|
70861
|
+
assetShareValueMultiplierByBank,
|
|
70862
|
+
activeEmodeWeightsByBank
|
|
70852
70863
|
});
|
|
70853
70864
|
const healthWithAllAssets = allAssetsHealth.minus(totalLiabilitiesInitHealth);
|
|
70854
70865
|
if (!healthWithAllAssets.gt(0)) {
|
|
@@ -70885,7 +70896,8 @@ async function computeSmartCrank({
|
|
|
70885
70896
|
oraclePricesByBank: oraclePrices,
|
|
70886
70897
|
assetBanks: [...nonSWBAssetAddresses, ...comboAddresses],
|
|
70887
70898
|
marginRequirement: 0 /* Initial */,
|
|
70888
|
-
assetShareValueMultiplierByBank
|
|
70899
|
+
assetShareValueMultiplierByBank,
|
|
70900
|
+
activeEmodeWeightsByBank
|
|
70889
70901
|
});
|
|
70890
70902
|
const health = comboHealth.minus(totalLiabilitiesInitHealth);
|
|
70891
70903
|
if (!health.gt(0)) continue;
|
|
@@ -71516,18 +71528,19 @@ var fetchSwbOracleData = async (banks, opts) => {
|
|
|
71516
71528
|
}
|
|
71517
71529
|
});
|
|
71518
71530
|
let crossbarResponse;
|
|
71519
|
-
let
|
|
71531
|
+
let fallbackPricesByFeedId = {};
|
|
71520
71532
|
if (opts.mode === "api") {
|
|
71521
71533
|
crossbarResponse = await fetchSwbOraclePricesFromAPI(
|
|
71522
71534
|
swbFeedIds,
|
|
71523
71535
|
opts.swbCrossbarPrice.endpoint,
|
|
71524
71536
|
{ queryKey: opts.swbCrossbarPrice.queryKey }
|
|
71525
71537
|
);
|
|
71526
|
-
|
|
71527
|
-
|
|
71538
|
+
const priceFallback = opts.priceFallback ?? opts.birdeyeFallback;
|
|
71539
|
+
if (brokenSwbFeeds.length > 0 && priceFallback) {
|
|
71540
|
+
fallbackPricesByFeedId = await getFallbackPricesByFeedId(
|
|
71528
71541
|
brokenSwbFeeds,
|
|
71529
|
-
|
|
71530
|
-
{ queryKey:
|
|
71542
|
+
priceFallback.endpoint,
|
|
71543
|
+
{ queryKey: priceFallback.queryKey }
|
|
71531
71544
|
);
|
|
71532
71545
|
}
|
|
71533
71546
|
} else {
|
|
@@ -71536,7 +71549,7 @@ var fetchSwbOracleData = async (banks, opts) => {
|
|
|
71536
71549
|
opts.crossbarEndpoint || "https://crossbar.0.xyz",
|
|
71537
71550
|
"https://crossbar.switchboard.xyz"
|
|
71538
71551
|
);
|
|
71539
|
-
|
|
71552
|
+
fallbackPricesByFeedId = {};
|
|
71540
71553
|
}
|
|
71541
71554
|
const bankOraclePriceMap = mapSwbBanksToOraclePrices(
|
|
71542
71555
|
switchboardBanks,
|
|
@@ -71546,7 +71559,7 @@ var fetchSwbOracleData = async (banks, opts) => {
|
|
|
71546
71559
|
const brokenFeedOraclePriceMap = mapBrokenFeedsToOraclePrices(
|
|
71547
71560
|
switchboardBanks,
|
|
71548
71561
|
swbOracleAiDataByKey,
|
|
71549
|
-
|
|
71562
|
+
fallbackPricesByFeedId
|
|
71550
71563
|
);
|
|
71551
71564
|
const combinedOraclePriceMap = /* @__PURE__ */ new Map();
|
|
71552
71565
|
bankOraclePriceMap.forEach((oraclePrice, bankAddress) => {
|
|
@@ -75409,6 +75422,8 @@ exports.getDriftMetadata = getDriftMetadata;
|
|
|
75409
75422
|
exports.getDriftStatesDto = getDriftStatesDto;
|
|
75410
75423
|
exports.getEmodePairs = getEmodePairs;
|
|
75411
75424
|
exports.getExactOutEstimate = getExactOutEstimate;
|
|
75425
|
+
exports.getFallbackPricesByFeedId = getFallbackPricesByFeedId;
|
|
75426
|
+
exports.getFallbackPricesForMints = getFallbackPricesForMints;
|
|
75412
75427
|
exports.getHealthCacheStatusDescription = getHealthCacheStatusDescription;
|
|
75413
75428
|
exports.getHealthSimulationTransactions = getHealthSimulationTransactions;
|
|
75414
75429
|
exports.getJupLendFTokenMultiplier = getJupLendFTokenMultiplier;
|