@reflectmoney/junior 1.1.0 → 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.
|
@@ -58,14 +58,19 @@ class JuniorTranche {
|
|
|
58
58
|
if (this.assets?.length > 0) {
|
|
59
59
|
return this.assets;
|
|
60
60
|
}
|
|
61
|
-
const encoder = (0, generated_1.getAssetEncoder)();
|
|
62
61
|
const decoder = (0, generated_1.getAssetDecoder)();
|
|
63
62
|
const programAccounts = await this.connection
|
|
64
63
|
.getProgramAccounts(generated_1.RLP_PROGRAM_ADDRESS, {
|
|
65
64
|
encoding: "base64",
|
|
66
65
|
withContext: false,
|
|
67
66
|
filters: [
|
|
68
|
-
{
|
|
67
|
+
{
|
|
68
|
+
memcmp: {
|
|
69
|
+
encoding: "base64",
|
|
70
|
+
offset: BigInt(0),
|
|
71
|
+
bytes: Buffer.from(generated_1.ASSET_DISCRIMINATOR).toString("base64"),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
69
74
|
],
|
|
70
75
|
})
|
|
71
76
|
.send();
|
|
@@ -559,17 +564,35 @@ class JuniorTranche {
|
|
|
559
564
|
*/
|
|
560
565
|
async fetchOraclePrice(mintOrOracle) {
|
|
561
566
|
// Resolve oracle address — try cached assets first, fall back to treating
|
|
562
|
-
// 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.
|
|
563
569
|
let oracleAddress = mintOrOracle;
|
|
564
570
|
const assets = await this.getAssets();
|
|
565
571
|
const assetEntry = assets.find((a) => a.data.mint === mintOrOracle);
|
|
566
572
|
if (assetEntry) {
|
|
567
|
-
|
|
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
|
+
}
|
|
568
584
|
}
|
|
569
585
|
const account = await (0, kit_1.fetchEncodedAccount)(this.connection, oracleAddress);
|
|
570
586
|
if (!account.exists) {
|
|
571
587
|
throw new Error(`Oracle account not found: ${oracleAddress}`);
|
|
572
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
|
+
}
|
|
573
596
|
return JuniorTranche.deserializePythPrice(new Uint8Array(account.data));
|
|
574
597
|
}
|
|
575
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",
|