@reflectmoney/junior 1.1.1 → 1.1.2
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.
|
@@ -564,17 +564,35 @@ class JuniorTranche {
|
|
|
564
564
|
*/
|
|
565
565
|
async fetchOraclePrice(mintOrOracle) {
|
|
566
566
|
// Resolve oracle address — try cached assets first, fall back to treating
|
|
567
|
-
// the input as a direct oracle address.
|
|
567
|
+
// the input as a direct oracle address. `Oracle` is a discriminated union
|
|
568
|
+
// (`Pyth` uses `account`, `Doppler` uses `fields[0]`), so unwrap per-variant.
|
|
568
569
|
let oracleAddress = mintOrOracle;
|
|
569
570
|
const assets = await this.getAssets();
|
|
570
571
|
const assetEntry = assets.find((a) => a.data.mint === mintOrOracle);
|
|
571
572
|
if (assetEntry) {
|
|
572
|
-
|
|
573
|
+
const oracle = assetEntry.data.oracle;
|
|
574
|
+
if (oracle.__kind === "Pyth") {
|
|
575
|
+
oracleAddress = oracle.account;
|
|
576
|
+
}
|
|
577
|
+
else if (oracle.__kind === "Doppler") {
|
|
578
|
+
oracleAddress = oracle.fields[0];
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
// Exhaustiveness guard for future oracle variants.
|
|
582
|
+
throw new Error(`Unsupported oracle variant: ${oracle.__kind}`);
|
|
583
|
+
}
|
|
573
584
|
}
|
|
574
585
|
const account = await (0, kit_1.fetchEncodedAccount)(this.connection, oracleAddress);
|
|
575
586
|
if (!account.exists) {
|
|
576
587
|
throw new Error(`Oracle account not found: ${oracleAddress}`);
|
|
577
588
|
}
|
|
589
|
+
// NOTE: only Pyth accounts are decodable by `deserializePythPrice`. If the
|
|
590
|
+
// asset's oracle is Doppler, the caller must fetch the raw account and use
|
|
591
|
+
// the doppler oracle SDK's `PriceDataSerializer` instead.
|
|
592
|
+
if (assetEntry &&
|
|
593
|
+
assetEntry.data.oracle.__kind !== "Pyth") {
|
|
594
|
+
throw new Error(`fetchOraclePrice only decodes Pyth oracles; asset ${assetEntry.data.mint} uses ${assetEntry.data.oracle.__kind}`);
|
|
595
|
+
}
|
|
578
596
|
return JuniorTranche.deserializePythPrice(new Uint8Array(account.data));
|
|
579
597
|
}
|
|
580
598
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reflectmoney/junior",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "TypeScript SDK for the Reflect Liquid Protection (RLP) program, powering junior tranche of Reflect's two-tranche protection system.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"author": "stablecoinjesus @ Palindrome Engineering",
|