@reflectmoney/junior 1.1.2 → 1.1.3

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.
@@ -98,7 +98,7 @@ export declare class JuniorTranche {
98
98
  * returning a new instruction with the extra accounts.
99
99
  */
100
100
  private appendRemainingAccounts;
101
- deposit(signer: TransactionSigner, amount: number | bigint, mint: Address, liquidityPoolId: number, minLpTokens?: number | bigint | null): Promise<import("../generated").DepositInstruction<Address<"JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av">, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", string, string, string, string, string, string, string, any, string, string, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", []>>;
101
+ deposit(signer: TransactionSigner, amount: number | bigint, mint: Address, liquidityPoolId: number, minLpTokens?: number | bigint | null): Promise<import("../generated").DepositInstruction<Address<"JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av">, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", string, string, string, string, string, string, string, string, string, string, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", []>>;
102
102
  requestWithdrawal(signer: TransactionSigner, liquidityPoolId: number, amount: number | bigint): Promise<import("../generated").RequestWithdrawalInstruction<Address<"JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av">, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", string, string, string, string, string, string, string, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", []>>;
103
103
  withdraw(signer: TransactionSigner, liquidityPoolId: number, cooldownId: number | bigint): Promise<import("../generated").WithdrawInstruction<Address<"JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av">, string, string, string, string, string, string, string, string, string, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", []>>;
104
104
  swap(signer: TransactionSigner, liquidityPoolId: number, tokenFromMint: Address, tokenToMint: Address, amountIn: number | bigint, minOut?: number | bigint | null): Promise<import("../generated").SwapInstruction<Address<"JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av">, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, "JrXLmS6aYJNJDVxdAfjNJE5wikT8ubf3TA9iL2JA9Av", []>>;
@@ -5,6 +5,20 @@ const token_1 = require("@solana-program/token");
5
5
  const kit_1 = require("@solana/kit");
6
6
  const generated_1 = require("../generated");
7
7
  const PdaClient_1 = require("./PdaClient");
8
+ /**
9
+ * Resolve the on-chain oracle account address from an `Oracle` discriminated
10
+ * union. Codama emits the two variants with different field shapes:
11
+ * - Pyth → { __kind: "Pyth"; account: Address; feedId: [u8;32] }
12
+ * - Doppler → { __kind: "Doppler"; fields: readonly [Address] }
13
+ *
14
+ * Old code did `(oracle as any).fields[0]` uniformly, which returns `undefined`
15
+ * for the Pyth variant (no `.fields` — the address lives at `.account`). Every
16
+ * deposit / slash / swap on a Pyth-priced asset was therefore passing an
17
+ * undefined oracle account to the program.
18
+ */
19
+ function oracleAccountAddress(oracle) {
20
+ return oracle.__kind === "Pyth" ? oracle.account : oracle.fields[0];
21
+ }
8
22
  class JuniorTranche {
9
23
  connection;
10
24
  settings;
@@ -249,7 +263,7 @@ class JuniorTranche {
249
263
  const assetEntry = assets.find((a) => a.data.mint === stablecoinMint);
250
264
  if (!assetEntry)
251
265
  throw new Error(`Asset not found for stablecoin mint ${stablecoinMint}`);
252
- const oracleAddress = assetEntry.data.oracle.fields[0];
266
+ const oracleAddress = oracleAccountAddress(assetEntry.data.oracle);
253
267
  const [liquidityPoolTokenAccount] = await (0, token_1.findAssociatedTokenPda)({
254
268
  mint: stablecoinMint,
255
269
  owner: liquidityPoolAddress,
@@ -312,7 +326,7 @@ class JuniorTranche {
312
326
  owner: liquidityPoolAddress,
313
327
  tokenProgram: token_1.TOKEN_PROGRAM_ADDRESS,
314
328
  });
315
- const oracleAddress = asset.data.oracle.fields[0];
329
+ const oracleAddress = oracleAccountAddress(asset.data.oracle);
316
330
  remaining.push({ address: poolAta, role: kit_1.AccountRole.READONLY }, { address: asset.address, role: kit_1.AccountRole.READONLY }, { address: oracleAddress, role: kit_1.AccountRole.READONLY }, { address: asset.data.mint, role: kit_1.AccountRole.READONLY });
317
331
  }
318
332
  return remaining;
@@ -364,7 +378,7 @@ class JuniorTranche {
364
378
  const assetEntry = assets.find((a) => a.data.mint === mint);
365
379
  if (!assetEntry)
366
380
  throw new Error(`Asset not found for mint ${mint}`);
367
- const oracleAddress = assetEntry.data.oracle.fields[0];
381
+ const oracleAddress = oracleAccountAddress(assetEntry.data.oracle);
368
382
  const lpEntry = this.liquidityPools.find((lp) => lp.data.index === liquidityPoolId);
369
383
  if (!lpEntry)
370
384
  throw new Error(`Liquidity pool ${liquidityPoolId} not found`);
@@ -444,10 +458,8 @@ class JuniorTranche {
444
458
  const tokenToEntry = assets.find((a) => a.data.mint === tokenToMint);
445
459
  if (!tokenToEntry)
446
460
  throw new Error(`Asset not found for mint ${tokenToMint}`);
447
- const tokenFromOracle = tokenFromEntry.data.oracle
448
- .fields[0];
449
- const tokenToOracle = tokenToEntry.data.oracle
450
- .fields[0];
461
+ const tokenFromOracle = oracleAccountAddress(tokenFromEntry.data.oracle);
462
+ const tokenToOracle = oracleAccountAddress(tokenToEntry.data.oracle);
451
463
  const lpEntry = this.liquidityPools.find((lp) => lp.data.index === liquidityPoolId);
452
464
  if (!lpEntry)
453
465
  throw new Error(`Liquidity pool ${liquidityPoolId} not found`);
@@ -570,17 +582,7 @@ class JuniorTranche {
570
582
  const assets = await this.getAssets();
571
583
  const assetEntry = assets.find((a) => a.data.mint === mintOrOracle);
572
584
  if (assetEntry) {
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
- }
585
+ oracleAddress = oracleAccountAddress(assetEntry.data.oracle);
584
586
  }
585
587
  const account = await (0, kit_1.fetchEncodedAccount)(this.connection, oracleAddress);
586
588
  if (!account.exists) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/junior",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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",