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