@reflectmoney/junior 1.0.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.
Files changed (122) hide show
  1. package/README.md +119 -0
  2. package/dist/classes/JuniorTranche.d.ts +201 -0
  3. package/dist/classes/JuniorTranche.js +709 -0
  4. package/dist/classes/PdaClient.d.ts +20 -0
  5. package/dist/classes/PdaClient.js +68 -0
  6. package/dist/classes/index.d.ts +2 -0
  7. package/dist/classes/index.js +18 -0
  8. package/dist/constants/index.d.ts +22 -0
  9. package/dist/constants/index.js +25 -0
  10. package/dist/generated/accounts/asset.d.ts +38 -0
  11. package/dist/generated/accounts/asset.js +74 -0
  12. package/dist/generated/accounts/cooldown.d.ts +40 -0
  13. package/dist/generated/accounts/cooldown.js +79 -0
  14. package/dist/generated/accounts/index.d.ts +12 -0
  15. package/dist/generated/accounts/index.js +28 -0
  16. package/dist/generated/accounts/liquidityPool.d.ts +57 -0
  17. package/dist/generated/accounts/liquidityPool.js +81 -0
  18. package/dist/generated/accounts/settings.d.ts +41 -0
  19. package/dist/generated/accounts/settings.js +80 -0
  20. package/dist/generated/accounts/userPermissions.d.ts +34 -0
  21. package/dist/generated/accounts/userPermissions.js +70 -0
  22. package/dist/generated/errors/index.d.ts +8 -0
  23. package/dist/generated/errors/index.js +24 -0
  24. package/dist/generated/errors/rlp.d.ts +131 -0
  25. package/dist/generated/errors/rlp.js +197 -0
  26. package/dist/generated/index.d.ts +12 -0
  27. package/dist/generated/index.js +28 -0
  28. package/dist/generated/instructions/addAsset.d.ts +80 -0
  29. package/dist/generated/instructions/addAsset.js +188 -0
  30. package/dist/generated/instructions/createPermissionAccount.d.ts +67 -0
  31. package/dist/generated/instructions/createPermissionAccount.js +166 -0
  32. package/dist/generated/instructions/deposit.d.ts +115 -0
  33. package/dist/generated/instructions/deposit.js +294 -0
  34. package/dist/generated/instructions/forceRemoveAsset.d.ts +82 -0
  35. package/dist/generated/instructions/forceRemoveAsset.js +186 -0
  36. package/dist/generated/instructions/freezeFunctionality.d.ts +72 -0
  37. package/dist/generated/instructions/freezeFunctionality.js +175 -0
  38. package/dist/generated/instructions/index.d.ts +23 -0
  39. package/dist/generated/instructions/index.js +39 -0
  40. package/dist/generated/instructions/initializeLp.d.ts +99 -0
  41. package/dist/generated/instructions/initializeLp.js +230 -0
  42. package/dist/generated/instructions/initializePoolReserve.d.ts +83 -0
  43. package/dist/generated/instructions/initializePoolReserve.js +228 -0
  44. package/dist/generated/instructions/initializeRlp.d.ts +67 -0
  45. package/dist/generated/instructions/initializeRlp.js +163 -0
  46. package/dist/generated/instructions/requestWithdrawal.d.ts +99 -0
  47. package/dist/generated/instructions/requestWithdrawal.js +254 -0
  48. package/dist/generated/instructions/slash.d.ts +151 -0
  49. package/dist/generated/instructions/slash.js +212 -0
  50. package/dist/generated/instructions/swap.d.ts +119 -0
  51. package/dist/generated/instructions/swap.js +309 -0
  52. package/dist/generated/instructions/updateActionRole.d.ts +76 -0
  53. package/dist/generated/instructions/updateActionRole.js +174 -0
  54. package/dist/generated/instructions/updateDepositCap.d.ts +71 -0
  55. package/dist/generated/instructions/updateDepositCap.js +156 -0
  56. package/dist/generated/instructions/updateOracle.d.ts +66 -0
  57. package/dist/generated/instructions/updateOracle.js +151 -0
  58. package/dist/generated/instructions/updateRoleHolder.d.ts +80 -0
  59. package/dist/generated/instructions/updateRoleHolder.js +185 -0
  60. package/dist/generated/instructions/withdraw.d.ts +95 -0
  61. package/dist/generated/instructions/withdraw.js +235 -0
  62. package/dist/generated/programs/index.d.ts +8 -0
  63. package/dist/generated/programs/index.js +24 -0
  64. package/dist/generated/programs/rlp.d.ts +75 -0
  65. package/dist/generated/programs/rlp.js +233 -0
  66. package/dist/generated/shared/index.d.ts +49 -0
  67. package/dist/generated/shared/index.js +94 -0
  68. package/dist/generated/types/accessControl.d.ts +20 -0
  69. package/dist/generated/types/accessControl.js +29 -0
  70. package/dist/generated/types/accessLevel.d.ts +16 -0
  71. package/dist/generated/types/accessLevel.js +28 -0
  72. package/dist/generated/types/accessMap.d.ts +20 -0
  73. package/dist/generated/types/accessMap.js +35 -0
  74. package/dist/generated/types/action.d.ts +32 -0
  75. package/dist/generated/types/action.js +44 -0
  76. package/dist/generated/types/actionMapping.d.ts +22 -0
  77. package/dist/generated/types/actionMapping.js +31 -0
  78. package/dist/generated/types/addAssetEvent.d.ts +17 -0
  79. package/dist/generated/types/addAssetEvent.js +30 -0
  80. package/dist/generated/types/createPermissionAccountEvent.d.ts +16 -0
  81. package/dist/generated/types/createPermissionAccountEvent.js +28 -0
  82. package/dist/generated/types/depositEvent.d.ts +27 -0
  83. package/dist/generated/types/depositEvent.js +36 -0
  84. package/dist/generated/types/depositRewardEvent.d.ts +21 -0
  85. package/dist/generated/types/depositRewardEvent.js +30 -0
  86. package/dist/generated/types/forceRemoveAssetEvent.d.ts +18 -0
  87. package/dist/generated/types/forceRemoveAssetEvent.js +32 -0
  88. package/dist/generated/types/freezeProtocolActionEvent.d.ts +20 -0
  89. package/dist/generated/types/freezeProtocolActionEvent.js +29 -0
  90. package/dist/generated/types/index.d.ts +32 -0
  91. package/dist/generated/types/index.js +48 -0
  92. package/dist/generated/types/initializeLiquidityPoolEvent.d.ts +17 -0
  93. package/dist/generated/types/initializeLiquidityPoolEvent.js +30 -0
  94. package/dist/generated/types/initializeRlpEvent.d.ts +15 -0
  95. package/dist/generated/types/initializeRlpEvent.js +22 -0
  96. package/dist/generated/types/killSwitch.d.ts +15 -0
  97. package/dist/generated/types/killSwitch.js +22 -0
  98. package/dist/generated/types/levelRoles.d.ts +18 -0
  99. package/dist/generated/types/levelRoles.js +23 -0
  100. package/dist/generated/types/oracle.d.ts +25 -0
  101. package/dist/generated/types/oracle.js +56 -0
  102. package/dist/generated/types/requestWithdrawEvent.d.ts +21 -0
  103. package/dist/generated/types/requestWithdrawEvent.js +30 -0
  104. package/dist/generated/types/role.d.ts +21 -0
  105. package/dist/generated/types/role.js +33 -0
  106. package/dist/generated/types/slashEvent.d.ts +27 -0
  107. package/dist/generated/types/slashEvent.js +36 -0
  108. package/dist/generated/types/swapEvent.d.ts +23 -0
  109. package/dist/generated/types/swapEvent.js +32 -0
  110. package/dist/generated/types/update.d.ts +16 -0
  111. package/dist/generated/types/update.js +28 -0
  112. package/dist/generated/types/updateActionRoleEvent.d.ts +22 -0
  113. package/dist/generated/types/updateActionRoleEvent.js +31 -0
  114. package/dist/generated/types/updateDepositCapEvent.d.ts +21 -0
  115. package/dist/generated/types/updateDepositCapEvent.js +30 -0
  116. package/dist/generated/types/updateOracleEvent.d.ts +18 -0
  117. package/dist/generated/types/updateOracleEvent.js +32 -0
  118. package/dist/generated/types/updateRoleHolderEvent.d.ts +22 -0
  119. package/dist/generated/types/updateRoleHolderEvent.js +31 -0
  120. package/dist/index.d.ts +3 -0
  121. package/dist/index.js +19 -0
  122. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # @reflectmoney/junior
2
+
3
+ TypeScript SDK for the **Reflect Liquid Protection (RLP)** Solana program — the junior tranche of Reflect's two-tranche stablecoin protection system.
4
+
5
+ Wraps Codama-generated instruction builders and provides higher-level helpers for pool lifecycle, deposits, cooldown-gated withdrawals, NAV-based slashing, and admin operations.
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @reflectmoney/junior @solana/kit
13
+ ```
14
+
15
+ Peer expectations: a `@solana/kit` `Rpc<SolanaRpcApi>` for read paths, and a `TransactionSigner` for writes.
16
+
17
+ ---
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import { createSolanaRpc } from "@solana/kit";
23
+ import { JuniorTranche, PdaClient } from "@reflectmoney/junior";
24
+
25
+ const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
26
+ const juniorTranche = new JuniorTranche(rpc);
27
+ await juniorTranche.load();
28
+
29
+ // Deposit into liquidity pool 0
30
+ const ix = await juniorTranche.deposit(
31
+ signer,
32
+ 1_000_000_000n, // amount in raw asset units
33
+ USDC_MINT,
34
+ 0, // liquidity pool id
35
+ null, // minLpTokens slippage guard (null = no minimum)
36
+ );
37
+ ```
38
+
39
+ ---
40
+
41
+ ## What this SDK covers
42
+
43
+ ### Pool lifecycle (admin)
44
+
45
+ | Method | Notes |
46
+ | --- | --- |
47
+ | `initializeRlp(signer, swapFeeBps)` | One-time program bootstrap. |
48
+ | `addAsset(signer, mint, oracle, accessLevel)` | Whitelist a deposit/swap asset. |
49
+ | `updateOracle(signer, assetMint, newOracle)` | Rotate an asset's Pyth feed. |
50
+ | `initializeLiquidityPool(signer, lpToken, cooldownDuration, assets, protectedVault?)` | Create a pool. `protectedVault` opts the pool into NAV-based slashing (audit-M06). |
51
+ | `initializePoolReserve(signer, liquidityPoolId, assetMint)` | Pre-create the pool's ATA for a whitelisted asset. Idempotent. |
52
+ | `forceRemoveAsset(signer, liquidityPoolId, assetMint)` | Recovery path for a pool reserve that has been permanently frozen by the mint authority (audit-M02). |
53
+ | `updateDepositCap(signer, liquidityPoolId, newCap)` | Set or clear per-pool deposit cap. |
54
+
55
+ ### User flow
56
+
57
+ | Method | Notes |
58
+ | --- | --- |
59
+ | `deposit(signer, amount, mint, liquidityPoolId, minLpTokens?)` | Mints LP tokens proportional to NAV. `minLpTokens` is a slippage guard. |
60
+ | `requestWithdrawal(signer, liquidityPoolId, amount)` | Burns LP tokens and opens a per-pool cooldown account. |
61
+ | `withdraw(signer, liquidityPoolId, cooldownId)` | Settles a matured cooldown. Excess LP tokens (if pool grew during cooldown) are refunded automatically (audit-1). |
62
+ | `swap(signer, liquidityPoolId, tokenFrom, tokenTo, amountIn, minOut?)` | Oracle-priced rebalance between pool assets. |
63
+
64
+ ### Slashing (NAV-based — audit-M06)
65
+
66
+ | Method | Notes |
67
+ | --- | --- |
68
+ | `slash(signer, liquidityPoolId, assetMint, proxyState, maxAmount)` | RLP (junior) covers losses of the senior proxy tranche. Pool must have been initialized with a `protectedVault`. The instruction computes `loss = max(0, principal + integratorsCommission − vaultValue)` from the `ProxyState` account and transfers up to `maxAmount` of `assetMint` into the proxy vault. |
69
+
70
+ The legacy operator-discretion slash has been removed.
71
+
72
+ ### Permissions
73
+
74
+ | Method | Notes |
75
+ | --- | --- |
76
+ | `createPermissionAccount(signer, target)` | Create a user-permissions PDA. |
77
+ | `updateRoleHolder(signer, target, role, add)` | Grant/revoke a role for a user. |
78
+ | `updateActionRole(signer, action, role, add)` | Bind an action (Deposit/Withdraw/Swap/Slash/etc.) to a role. **Slash cannot be assigned to `Role.PUBLIC`.** |
79
+
80
+ ### PDAs
81
+
82
+ `PdaClient` exposes pure helpers:
83
+
84
+ ```ts
85
+ const [settings] = await PdaClient.deriveSettings();
86
+ const [permissions] = await PdaClient.deriveUserPermissions(user);
87
+ const [pool] = await PdaClient.deriveLiquidityPool(0);
88
+ const [asset] = await PdaClient.deriveAsset(mint);
89
+ const [cooldown] = await PdaClient.deriveCooldown(poolId, cooldownId);
90
+ const [eventAuthority] = await PdaClient.deriveEventAuthority();
91
+ const [proxyState] = await PdaClient.deriveProxyState(brandedMint);
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Audit fixes in this release
97
+
98
+ The SDK is aligned with the integrated audit-fixes branch. Notable behavioral changes that callers may need to know about:
99
+
100
+ - **NAV-based slash** replaces the operator-discretion slash. Call signature is different — see above.
101
+ - **`initializeLiquidityPool` accepts `protectedVault`.** Pass `null` for a pool that is not protecting any proxy vault. Pass the proxy state PDA otherwise.
102
+ - **`withdraw` refunds excess LP tokens.** No caller change, but the on-chain math now redeems against the *current* NAV at withdraw time, capped by what the cooldown originally locked.
103
+ - **`Action.Slash` is not publicly assignable.** Attempting `updateActionRole(Action.Slash, Role.PUBLIC, …)` is rejected by the program.
104
+ - **`forceRemoveAsset` + `initializePoolReserve`** are new admin wrappers for the frozen-pool-reserve recovery path.
105
+ - **Cooldowns are now per-pool** (a separate counter on each `LiquidityPool` rather than the program-wide settings counter).
106
+
107
+ ---
108
+
109
+ ## Development
110
+
111
+ ```sh
112
+ npm install
113
+ npm run build # tsc → dist/
114
+ npm test # mocha + litesvm + the in-tree rlp.so
115
+ ```
116
+
117
+ The test suite uses [LiteSVM](https://github.com/LiteSVM/litesvm) and loads `../target/deploy/rlp.so`, so make sure the program is built (`anchor build` or `cargo-build-sbf`) before running.
118
+
119
+ `npm publish` runs `prepublishOnly` which cleans `dist`, rebuilds, and runs the test suite — publish will fail if any of those steps fail.
@@ -0,0 +1,201 @@
1
+ import { Rpc, SolanaRpcApi, Address, TransactionSigner } from "@solana/kit";
2
+ import { type Settings, type LiquidityPool, type Asset, type Cooldown, type UserPermissions, type AccessLevel, type Action, type Role, type Update } from "../generated";
3
+ export type AccountWithAddress<T> = {
4
+ data: T;
5
+ address: Address;
6
+ };
7
+ export declare class JuniorTranche {
8
+ private connection;
9
+ private settings;
10
+ private liquidityPools;
11
+ private assets;
12
+ constructor(connection: Rpc<SolanaRpcApi>);
13
+ load(): Promise<void>;
14
+ getSettingsData(): Promise<Settings>;
15
+ getLiquidityPools(): Promise<AccountWithAddress<LiquidityPool>[]>;
16
+ getLiquidityPoolData(liquidityPoolId: number): Promise<LiquidityPool>;
17
+ getAssets(): Promise<AccountWithAddress<Asset>[]>;
18
+ getCooldowns(): Promise<AccountWithAddress<Cooldown>[]>;
19
+ getCooldownsByUser(user: Address): Promise<AccountWithAddress<Cooldown>[]>;
20
+ getUserPermissions(): Promise<AccountWithAddress<UserPermissions>[]>;
21
+ getUserPermissionsFromAddress(address: Address): Promise<AccountWithAddress<UserPermissions>[]>;
22
+ initializeRlp(signer: TransactionSigner, swapFeeBps: number): Promise<import("../generated").InitializeRlpInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
23
+ initializeLiquidityPool(signer: TransactionSigner, args: {
24
+ lpTokenMint: Address;
25
+ cooldownDuration: number | bigint;
26
+ depositCap: number | bigint | null;
27
+ assets: number[];
28
+ /**
29
+ * Optional senior-tranche ProxyState account this pool covers.
30
+ * When set, the pool's `slash` flow becomes NAV-coverage-based:
31
+ * slashed tokens go directly into the proxy vault, capped at the
32
+ * proxy's current mark-to-market loss (principal + commission -
33
+ * vault_value). Pools with `None` are un-slashable by design.
34
+ */
35
+ protectedVault?: Address | null;
36
+ }): Promise<import("../generated").InitializeLpInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
37
+ /**
38
+ * Create the canonical pool reserve ATA for a single asset. Required after
39
+ * `initialize_lp` before any deposit/withdraw/swap against that asset can
40
+ * succeed (audit-E02). Idempotent: safe to call again on an already-
41
+ * initialized reserve.
42
+ */
43
+ initializePoolReserve(signer: TransactionSigner, liquidityPoolId: number, assetMint: Address): Promise<import("../generated").InitializePoolReserveInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, string, string, []>>;
44
+ /**
45
+ * Admin recovery for a permanently-frozen pool asset (audit-M02). Drops the
46
+ * asset from the pool's reserve list. Requires the asset's pool reserve ATA
47
+ * to actually be in the SPL `Frozen` state.
48
+ */
49
+ forceRemoveAsset(signer: TransactionSigner, liquidityPoolId: number, assetMint: Address): Promise<import("../generated").ForceRemoveAssetInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
50
+ addAsset(signer: TransactionSigner, assetMint: Address, oracle: Address, accessLevel: AccessLevel): Promise<import("../generated").AddAssetInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
51
+ updateOracle(signer: TransactionSigner, assetMint: Address, oracle: Address): Promise<import("../generated").UpdateOracleInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
52
+ /**
53
+ * NAV-based junior-tranche slash (audit-M06 redesign). Pulls from this
54
+ * pool's reserve of the proxy's `stablecoinMint` directly into the proxy's
55
+ * vault, capped on-chain at the current mark-to-market loss
56
+ * `principal + commission - vault_value`.
57
+ *
58
+ * The pool must have been initialized with `protectedVault` pinned to the
59
+ * supplied `proxyState`. The proxy's stablecoin_mint must equal the
60
+ * `stablecoinMint` arg, and the pool must whitelist that mint as one of
61
+ * its assets.
62
+ *
63
+ * @param signer Caller (must hold the Slash action role).
64
+ * @param liquidityPoolId The pool index.
65
+ * @param stablecoinMint The proxy's underlying stablecoin (USDC+).
66
+ * @param proxyState The senior tranche's ProxyState account.
67
+ * @param amount Requested amount in raw stablecoin_mint units.
68
+ * Capped at the current gap; pass any positive
69
+ * value up to that cap.
70
+ */
71
+ slash(signer: TransactionSigner, liquidityPoolId: number, stablecoinMint: Address, proxyState: Address, amount: number | bigint): Promise<import("../generated").SlashInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
72
+ /**
73
+ * Inject pre-fetched state (useful for testing without an RPC connection).
74
+ */
75
+ loadFromCache(settings: Settings, liquidityPools: AccountWithAddress<LiquidityPool>[], assets: AccountWithAddress<Asset>[]): void;
76
+ /**
77
+ * Return the assets that belong to a specific liquidity pool,
78
+ * ordered by the pool's `assets` array.
79
+ */
80
+ private getPoolAssets;
81
+ /**
82
+ * Build the remaining accounts needed by calculate_total_pool_value().
83
+ * Per asset (in pool asset order): [pool_ata, asset_pda, oracle, mint]
84
+ */
85
+ private buildPoolValueRemainingAccounts;
86
+ /**
87
+ * Build the remaining accounts needed by withdraw's load_assets,
88
+ * load_reserves, and load_user_token_accounts.
89
+ *
90
+ * Layout (must match on-chain expectations):
91
+ * - First N: asset PDAs (positional, for load_assets)
92
+ * - Then N: pool reserve ATAs (searched by load_reserves)
93
+ * - Then N: user token ATAs (searched by load_user_token_accounts)
94
+ */
95
+ private buildWithdrawRemainingAccounts;
96
+ /**
97
+ * Append remaining account metas to a frozen instruction object,
98
+ * returning a new instruction with the extra accounts.
99
+ */
100
+ private appendRemainingAccounts;
101
+ deposit(signer: TransactionSigner, amount: number | bigint, mint: Address, liquidityPoolId: number, minLpTokens?: number | bigint | null): Promise<import("../generated").DepositInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", string, string, string, string, string, string, string, any, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
102
+ requestWithdrawal(signer: TransactionSigner, liquidityPoolId: number, amount: number | bigint): Promise<import("../generated").RequestWithdrawalInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", string, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
103
+ withdraw(signer: TransactionSigner, liquidityPoolId: number, cooldownId: number | bigint): Promise<import("../generated").WithdrawInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
104
+ swap(signer: TransactionSigner, liquidityPoolId: number, tokenFromMint: Address, tokenToMint: Address, amountIn: number | bigint, minOut?: number | bigint | null): Promise<import("../generated").SwapInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
105
+ createPermissionAccount(caller: TransactionSigner, newAdmin: Address): Promise<import("../generated").CreatePermissionAccountInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
106
+ updateRoleHolder(admin: TransactionSigner, targetAddress: Address, role: Role, update: Update): Promise<import("../generated").UpdateRoleHolderInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
107
+ updateActionRole(admin: TransactionSigner, action: Action, role: Role, update: Update): Promise<import("../generated").UpdateActionRoleInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
108
+ updateDepositCap(signer: TransactionSigner, liquidityPoolId: number, newCap: number | bigint | null): Promise<import("../generated").UpdateDepositCapInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
109
+ freezeFunctionality(admin: TransactionSigner, action: Action, freeze: boolean): Promise<import("../generated").FreezeFunctionalityInstruction<Address<"RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz">, string, string, string, string, string, "RLptfFmhKtGLrJ9fD4o8VCHGWZZLSRrpaTKzJXdCCWz", []>>;
110
+ findAssetFromMint(mint: Address): Promise<Address>;
111
+ getSettings(): Settings;
112
+ getCachedLiquidityPools(): AccountWithAddress<LiquidityPool>[];
113
+ getCachedAssets(): AccountWithAddress<Asset>[];
114
+ /**
115
+ * Fetch and deserialize the Pyth PriceUpdateV2 oracle account for a given
116
+ * asset, returning `{ price, exponent }` ready to pass into
117
+ * `simulateDepositMath`.
118
+ *
119
+ * @param mint The asset mint whose oracle to read, OR a direct oracle
120
+ * address. When a mint is provided the oracle address is
121
+ * looked up from the cached asset list.
122
+ */
123
+ fetchOraclePrice(mintOrOracle: Address): Promise<{
124
+ price: bigint;
125
+ exponent: number;
126
+ publishTime: bigint;
127
+ }>;
128
+ /**
129
+ * Deserialize a raw Pyth PriceUpdateV2 account buffer into price fields.
130
+ *
131
+ * Borsh layout (after 8-byte Anchor discriminator):
132
+ * write_authority: Pubkey (32)
133
+ * verification_level: Full=[1] (1 byte) | Partial=[0,u8] (2 bytes)
134
+ * price_message {
135
+ * feed_id: [u8;32], price: i64, conf: u64, exponent: i32,
136
+ * publish_time: i64, ...
137
+ * }
138
+ */
139
+ static deserializePythPrice(data: Uint8Array): {
140
+ price: bigint;
141
+ exponent: number;
142
+ publishTime: bigint;
143
+ };
144
+ /**
145
+ * Simulate deposit math off-chain.
146
+ *
147
+ * Mirrors the on-chain logic in:
148
+ * - `OraclePrice::mul` (oracle_price.rs)
149
+ * - `LiquidityPool::calculate_total_pool_value`
150
+ * - `LiquidityPool::calculate_lp_tokens_on_deposit`
151
+ *
152
+ * @param depositAmount Raw token amount to deposit (base units).
153
+ * @param depositAssetPrice Oracle price of the deposit asset (`{ price, exponent }`).
154
+ * @param depositAssetDecimals Decimals of the deposit token mint.
155
+ * @param poolReserves Array of { balance, price, exponent, decimals } for every
156
+ * asset currently in the pool (BEFORE the deposit).
157
+ * @param lpTokenSupply Current total supply of the LP token (includes dead shares).
158
+ * @param lpTokenDecimals Decimals of the LP token mint (typically 9).
159
+ * @returns The number of LP tokens the depositor would receive (bigint).
160
+ */
161
+ static simulateDepositMath(params: {
162
+ depositAmount: bigint;
163
+ depositAssetPrice: {
164
+ price: bigint;
165
+ exponent: number;
166
+ };
167
+ depositAssetDecimals: number;
168
+ poolReserves: {
169
+ balance: bigint;
170
+ price: bigint;
171
+ exponent: number;
172
+ decimals: number;
173
+ }[];
174
+ lpTokenSupply: bigint;
175
+ lpTokenDecimals: number;
176
+ }): bigint;
177
+ /**
178
+ * Simulate withdrawal math off-chain.
179
+ *
180
+ * Mirrors the on-chain logic in `withdraw()` which computes:
181
+ * `user_share_per_asset = reserve_amount * lp_token_amount / lp_token_supply`
182
+ *
183
+ * Uses PreciseNumber arithmetic to match on-chain rounding.
184
+ *
185
+ * @param lpTokenAmount Amount of LP tokens the user is redeeming.
186
+ * @param lpTokenSupply Current total supply of the LP token.
187
+ * @param reserves Array of { mint, balance } for each pool asset.
188
+ * @returns Array of { mint, amount } the user would receive per asset.
189
+ */
190
+ static simulateWithdrawMath(params: {
191
+ lpTokenAmount: bigint;
192
+ lpTokenSupply: bigint;
193
+ reserves: {
194
+ mint: Address;
195
+ balance: bigint;
196
+ }[];
197
+ }): {
198
+ mint: Address;
199
+ amount: bigint;
200
+ }[];
201
+ }