@raac/rpc 2.0.0-beta.5 → 2.0.0-beta.7

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 (70) hide show
  1. package/dist/RPCLibrary.js +46 -8
  2. package/dist/configs/chains/11155111.json +32 -2
  3. package/dist/configs/chains/8453.json +23 -2
  4. package/dist/contracts/curve/common/_helpers.js +39 -0
  5. package/dist/contracts/curve/common/getPools.js +36 -0
  6. package/dist/contracts/curve/common/getVirtualPrice.js +26 -0
  7. package/dist/contracts/curve/common/index.js +18 -0
  8. package/dist/contracts/findContract.js +3 -3
  9. package/dist/contracts/getContractAddress.js +1 -0
  10. package/dist/contracts/governance/gaugeSystems/_helpers.js +2 -2
  11. package/dist/contracts/zeno/_helpers.js +43 -0
  12. package/dist/contracts/zeno/buy.js +27 -0
  13. package/dist/contracts/zeno/getAuctionState.js +45 -0
  14. package/dist/contracts/zeno/getAuctions.js +7 -4
  15. package/dist/contracts/zeno/getBondState.js +47 -0
  16. package/dist/contracts/zeno/getPrice.js +23 -0
  17. package/dist/contracts/zeno/getZenos.js +6 -6
  18. package/dist/contracts/zeno/grantRole.js +46 -0
  19. package/dist/contracts/zeno/pause.js +42 -0
  20. package/dist/contracts/zeno/priceAt.js +20 -0
  21. package/dist/contracts/zeno/quoteBuy.js +33 -0
  22. package/dist/contracts/zeno/redeem.js +44 -0
  23. package/dist/contracts/zeno/setAuction.js +25 -0
  24. package/dist/contracts/zeno/sweepSurplus.js +26 -0
  25. package/dist/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.js +4 -4
  26. package/dist/types/RPCLibrary.d.ts +33 -1
  27. package/dist/types/contracts/curve/common/_helpers.d.ts +16 -0
  28. package/dist/types/contracts/curve/common/getPools.d.ts +30 -0
  29. package/dist/types/contracts/curve/common/getVirtualPrice.d.ts +13 -0
  30. package/dist/types/contracts/curve/common/index.d.ts +2 -0
  31. package/dist/types/contracts/zeno/_helpers.d.ts +17 -0
  32. package/dist/types/contracts/zeno/buy.d.ts +15 -0
  33. package/dist/types/contracts/zeno/getAuctionState.d.ts +45 -0
  34. package/dist/types/contracts/zeno/getAuctions.d.ts +3 -2
  35. package/dist/types/contracts/zeno/getBondState.d.ts +42 -0
  36. package/dist/types/contracts/zeno/getPrice.d.ts +12 -0
  37. package/dist/types/contracts/zeno/getZenos.d.ts +2 -2
  38. package/dist/types/contracts/zeno/grantRole.d.ts +22 -0
  39. package/dist/types/contracts/zeno/pause.d.ts +18 -0
  40. package/dist/types/contracts/zeno/priceAt.d.ts +20 -0
  41. package/dist/types/contracts/zeno/quoteBuy.d.ts +34 -0
  42. package/dist/types/contracts/zeno/redeem.d.ts +20 -0
  43. package/dist/types/contracts/zeno/setAuction.d.ts +13 -0
  44. package/dist/types/contracts/zeno/sweepSurplus.d.ts +14 -0
  45. package/dist/types/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.d.ts +3 -3
  46. package/dist/types/user/_helpers.d.ts +23 -0
  47. package/dist/types/user/computeEffectiveReturn.d.ts +67 -0
  48. package/dist/types/user/getUserClaimables.d.ts +55 -0
  49. package/dist/types/user/getUserCollateral.d.ts +12 -0
  50. package/dist/types/user/getUserDebt.d.ts +18 -0
  51. package/dist/types/user/getUserFarming.d.ts +64 -0
  52. package/dist/types/user/getUserGovernance.d.ts +20 -0
  53. package/dist/types/user/getUserPortfolio.d.ts +61 -0
  54. package/dist/types/user/getUserWalletBalances.d.ts +20 -0
  55. package/dist/types/user/index.d.ts +9 -0
  56. package/dist/types/utils/amount.d.ts +7 -0
  57. package/dist/types/utils/contracts.d.ts +2 -0
  58. package/dist/user/_helpers.js +22 -0
  59. package/dist/user/computeEffectiveReturn.js +33 -0
  60. package/dist/user/getUserClaimables.js +97 -0
  61. package/dist/user/getUserCollateral.js +29 -0
  62. package/dist/user/getUserDebt.js +32 -0
  63. package/dist/user/getUserFarming.js +100 -0
  64. package/dist/user/getUserGovernance.js +35 -0
  65. package/dist/user/getUserPortfolio.js +109 -0
  66. package/dist/user/getUserWalletBalances.js +30 -0
  67. package/dist/user/index.js +24 -0
  68. package/dist/utils/amount.js +10 -0
  69. package/dist/utils/contracts.js +5 -2
  70. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Halts `buy` on an auction. PAUSER_ROLE only. A Dutch price keeps falling while paused.
5
+ * @param chainId The chain id.
6
+ * @param auction The auction address.
7
+ * @param signer A PAUSER_ROLE holder.
8
+ * @returns The transaction receipt.
9
+ */
10
+ export declare function pause(chainId: ChainId, auction: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
11
+ /**
12
+ * Resumes `buy` on an auction. DEFAULT_ADMIN_ROLE only, so a compromised pauser cannot reopen buying.
13
+ * @param chainId The chain id.
14
+ * @param auction The auction address.
15
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
16
+ * @returns The transaction receipt.
17
+ */
18
+ export declare function unpause(chainId: ChainId, auction: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
@@ -0,0 +1,20 @@
1
+ /** The auction terms that set its price. All values as the contract stores them. */
2
+ export interface AuctionPriceTerms {
3
+ /** UNIX timestamp (seconds). */
4
+ startTime: bigint;
5
+ /** UNIX timestamp (seconds). */
6
+ endTime: bigint;
7
+ /** Payment token base units per whole ZENO. */
8
+ startingPrice: bigint;
9
+ /** Payment token base units per whole ZENO. */
10
+ reservePrice: bigint;
11
+ }
12
+ /**
13
+ * An auction's price at `now`, computed locally without an RPC call. Mirrors `Auction.getPrice()` exactly, truncating
14
+ * division included: the starting price before the window, the reserve from `endTime` on, a linear fall between.
15
+ *
16
+ * @param terms The auction's price terms, e.g. from `getAuctionState` or the subgraph's `BondAuction`.
17
+ * @param now UNIX timestamp (seconds). Use the latest block timestamp to match the contract exactly.
18
+ * @returns The price in payment token base units per whole ZENO.
19
+ */
20
+ export declare const priceAt: (terms: AuctionPriceTerms, now: bigint) => bigint;
@@ -0,0 +1,34 @@
1
+ export interface BuyQuoteInput {
2
+ /** Price in payment token base units per whole ZENO, from `priceAt` or `getPrice`. */
3
+ price: bigint;
4
+ /** Payment token to spend, in base units. */
5
+ paymentAmount: bigint;
6
+ /** ZENO decimals, equal to the underlying's. */
7
+ zenoDecimals: number;
8
+ /** ZENO left to sell, in base units (`totalRemaining`). */
9
+ totalRemaining: bigint;
10
+ /** Tolerance below `zenoOut` for `minZenoOut`, in basis points (10000 = 100%). Defaults to 0. */
11
+ slippageBps?: bigint;
12
+ }
13
+ export interface BuyQuote {
14
+ /** ZENO minted for `paymentAmount` at `price`, in base units. */
15
+ zenoOut: bigint;
16
+ /** `zenoOut` less the slippage tolerance; pass it to `buy` as `minZenoOut`. */
17
+ minZenoOut: bigint;
18
+ /** The largest payment `buy` accepts at `price`; anything above mints more than `totalRemaining` and reverts. */
19
+ maxPayment: bigint;
20
+ /** True when `paymentAmount` is above `maxPayment`. */
21
+ exceedsRemaining: boolean;
22
+ }
23
+ /**
24
+ * What a buy mints, computed locally without an RPC call with `Auction.buy`'s integer maths:
25
+ * `zenoOut = paymentAmount * 10^zenoDecimals / price`, truncated.
26
+ *
27
+ * A Dutch price only falls, so a buy mined after the quote mints at least `zenoOut`; `minZenoOut` guards against a
28
+ * fixed price or a stale quote. The same fall means a payment at exactly `maxPayment` can revert a block later, so
29
+ * leave headroom when buying out the remainder.
30
+ *
31
+ * @param input The price, payment, ZENO decimals, remaining supply and slippage tolerance.
32
+ * @returns The ZENO out, the `minZenoOut` to send, and the payment ceiling.
33
+ */
34
+ export declare const quoteBuy: (input: BuyQuoteInput) => BuyQuote;
@@ -0,0 +1,20 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Redeems ZENO 1:1 for the underlying. Reverts before maturity, and while the bond's collateral is short of its
5
+ * outstanding supply (`getBondState(...).isFunded`).
6
+ * @param chainId The chain id.
7
+ * @param zeno The ZENO bond address.
8
+ * @param amount ZENO to redeem, in base units.
9
+ * @param signer The holder, who receives the underlying.
10
+ * @returns The transaction receipt.
11
+ */
12
+ export declare function redeem(chainId: ChainId, zeno: string, amount: bigint, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
13
+ /**
14
+ * Redeems the signer's whole ZENO balance for the underlying. Same conditions as `redeem`.
15
+ * @param chainId The chain id.
16
+ * @param zeno The ZENO bond address.
17
+ * @param signer The holder, who receives the underlying.
18
+ * @returns The transaction receipt.
19
+ */
20
+ export declare function redeemAll(chainId: ChainId, zeno: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
@@ -0,0 +1,13 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Binds a ZENO to the auction that sells it. One-shot, ZENO owner only; reverts unless the auction's `zeno()` points
5
+ * back at this ZENO. Until it is set, the auction's buys revert.
6
+ * @param chainId The chain id.
7
+ * @param zeno The ZENO bond address.
8
+ * @param auction The auction created for it.
9
+ * @param signer The ZENO owner.
10
+ * @returns The transaction receipt.
11
+ */
12
+ declare function setAuction(chainId: ChainId, zeno: string, auction: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
13
+ export default setAuction;
@@ -0,0 +1,14 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Sweeps underlying held above the ZENO's outstanding supply: unsold prefill, overpayments and post-maturity residue.
5
+ * ZENO owner only, and only once the bound auction has ended. `getBondState(...).sweepableSurplus` is the most it takes.
6
+ * @param chainId The chain id.
7
+ * @param zeno The ZENO bond address.
8
+ * @param to The recipient of the underlying.
9
+ * @param amount Underlying to sweep, in base units.
10
+ * @param signer The ZENO owner.
11
+ * @returns The transaction receipt.
12
+ */
13
+ declare function sweepSurplus(chainId: ChainId, zeno: string, to: string, amount: bigint, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
14
+ export default sweepSurplus;
@@ -1,4 +1,4 @@
1
- import { Signer } from "ethers";
1
+ import { Provider, Signer } from "ethers";
2
2
  import { ChainId } from "../../../../configs/chains";
3
3
  import { TokenAmount } from "../../../../utils/amount";
4
4
  /**
@@ -6,8 +6,8 @@ import { TokenAmount } from "../../../../utils/amount";
6
6
  * @param chainId The chain id, used to look up the adapter token's decimals in the token registry.
7
7
  * @param adapterAddress The ERC20 asset adapter address.
8
8
  * @param userAddress The user.
9
- * @param signer The signer to read with.
9
+ * @param runner The signer or provider to read with. A read-only provider is enough.
10
10
  * @returns The deposited balance in base units of the adapter's token, with its registry decimals and symbol (18 decimals if the token is not in the registry).
11
11
  */
12
- declare function getERC20AdapterBalance(chainId: ChainId, adapterAddress: string, userAddress: string, signer: Signer): Promise<TokenAmount>;
12
+ declare function getERC20AdapterBalance(chainId: ChainId, adapterAddress: string, userAddress: string, runner: Signer | Provider): Promise<TokenAmount>;
13
13
  export default getERC20AdapterBalance;
@@ -0,0 +1,23 @@
1
+ import { TokenAmount } from "../utils/amount";
2
+ /**
3
+ * USD price of one whole token, keyed by lowercase symbol, e.g. `{ raac: 5, pmusd: 1, ireet: 0.995 }`. The app
4
+ * builds it with its `usePrices` hook, so the rpc and the UI value everything identically.
5
+ */
6
+ export type UsdPrices = Record<string, number>;
7
+ /** A read that settled independently of the others: its data, or why it failed. One failure never blanks the rest. */
8
+ export type Section<T> = {
9
+ data: T;
10
+ error: null;
11
+ } | {
12
+ data: null;
13
+ error: Error;
14
+ };
15
+ /** Settles one read into a {@link Section}: never rejects, so reads awaited together fail independently. */
16
+ export declare const settled: <T>(read: Promise<T>) => Promise<Section<T>>;
17
+ /**
18
+ * USD value of an amount from `prices`, by the symbol `toTokenAmount` gave it from the chain config's token registry.
19
+ * Throws when there is no price, so the section fails visibly instead of reading 0.
20
+ *
21
+ * @param token - The amount's asset key or token address, named in the error.
22
+ */
23
+ export declare function requireUsd(prices: UsdPrices, amount: TokenAmount, token: string): number;
@@ -0,0 +1,67 @@
1
+ /** Whether a leg earns income or costs it. */
2
+ export type ReturnLegKind = "earning" | "cost";
3
+ /** What a leg earns or costs. A unit of capital earns each yield type at most once. */
4
+ export type ReturnLegYieldType = "supply" | "gauge" | "borrow";
5
+ /**
6
+ * One income stream in the user's position, as {@link computeEffectiveReturn} consumes it. Adding a venue (a new
7
+ * gauge, another pmUSD venue) only means adding a leg; the calculator does not change.
8
+ */
9
+ export interface ReturnLeg {
10
+ /** Stable key, e.g. "borrow", "supply", "gauge:r-rpmdepmUSD". */
11
+ id: string;
12
+ /** Display name, e.g. "Borrow pmUSD". */
13
+ source: string;
14
+ kind: ReturnLegKind;
15
+ yieldType: ReturnLegYieldType;
16
+ /**
17
+ * True when the leg's value is money the user holds and counts towards net capital (supplied). False for the
18
+ * debt itself, and for overlays such as a gauge, whose staked value is already counted in another leg.
19
+ */
20
+ countsAsCapital: boolean;
21
+ /** USD value the rate applies to. Never negative. */
22
+ valueUsd: number;
23
+ /** The projected one-year rate as a fraction, e.g. 0.0077 for 0.77%. */
24
+ rate: number;
25
+ /** How `rate` is quoted: "apy" when it already compounds (borrow), "apr" when it does not (supply, gauge). */
26
+ rateKind: "apr" | "apy";
27
+ }
28
+ export interface ReturnLegWithIncome extends ReturnLeg {
29
+ /** Projected income over one year in USD: `valueUsd * rate`, negative for a cost leg. */
30
+ income1y: number;
31
+ }
32
+ export interface EffectiveReturnInput {
33
+ legs: readonly ReturnLeg[];
34
+ /** USD value of the collateral backing the debt. */
35
+ collateralUsd: number;
36
+ /**
37
+ * USD value of capital that earns nothing, e.g. idle pmUSD in the wallet or a non-yielding coin inside a staked
38
+ * LP. It is not a leg (no income, not listed in a breakdown); it only adds to net capital.
39
+ */
40
+ idleUsd?: number;
41
+ }
42
+ export interface EffectiveReturn {
43
+ /** Earning legs' income minus cost legs' cost over one year, in USD. */
44
+ netIncome1y: number;
45
+ /** `netIncome1y / debtUsd` as a fraction; null when there is no debt. */
46
+ onDebt: number | null;
47
+ /** `netIncome1y / netCapitalUsd` as a fraction; null when net capital is zero or negative. */
48
+ onNetCapital: number | null;
49
+ /** Sum of the cost legs' values. */
50
+ debtUsd: number;
51
+ /** Collateral + capital legs + idle - debt. */
52
+ netCapitalUsd: number;
53
+ legs: ReturnLegWithIncome[];
54
+ }
55
+ /**
56
+ * Projects the user's net return over one year from a list of legs. Pure: no reads.
57
+ *
58
+ * netIncome1y = sum(earning valueUsd * rate) - sum(cost valueUsd * rate)
59
+ * onDebt = netIncome1y / total debt
60
+ * onNetCapital = netIncome1y / (collateral + capital legs + idle - total debt)
61
+ *
62
+ * The legs do not reinvest into each other, so this is a projected net return, not an APY.
63
+ *
64
+ * @param input - The legs, the collateral value and any idle capital, all in USD.
65
+ * @returns The net income, both returns and each leg with its own projected income.
66
+ */
67
+ export declare function computeEffectiveReturn({ legs, collateralUsd, idleUsd }: EffectiveReturnInput): EffectiveReturn;
@@ -0,0 +1,55 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { GaugeSystemId } from "../configs/chains/chain";
4
+ import { TokenAmount } from "../utils/amount";
5
+ export interface ClaimableToken {
6
+ /** Token address. */
7
+ token: string;
8
+ amount: TokenAmount;
9
+ }
10
+ export interface ClaimableSource {
11
+ /** False when the source is not deployed on this chain. Nothing to show. */
12
+ available: boolean;
13
+ /** Tokens with a non-zero claimable amount. */
14
+ tokens: ClaimableToken[];
15
+ /** Why the source could not be read. The UI shows it on this row, never a silent zero. */
16
+ error: Error | null;
17
+ }
18
+ export interface GaugeClaimable extends ClaimableSource {
19
+ gauge: string;
20
+ id: string;
21
+ name: string;
22
+ system: GaugeSystemId;
23
+ }
24
+ export interface GaugeClaimables extends ClaimableSource {
25
+ /** One entry per configured gauge, including those with nothing to claim or a failed read. */
26
+ items: GaugeClaimable[];
27
+ /** Number of gauges with something to claim. */
28
+ claimableCount: number;
29
+ }
30
+ export interface UserClaimables {
31
+ chainId: ChainId;
32
+ user: string;
33
+ /** Main and extra rewards on every configured gauge of both systems. Claimed gauge RAAC goes to the liquid locker. */
34
+ gauges: GaugeClaimables;
35
+ /** veRAAC fee distributions, one token per reward token. */
36
+ veRAAC: ClaimableSource;
37
+ /** Realised RAAC in the maturity vault. */
38
+ maturityVault: ClaimableSource;
39
+ /** Bot locker rewards, every reward token. */
40
+ botLocker: ClaimableSource;
41
+ }
42
+ /**
43
+ * Everything a user can claim right now, across gauges, veRAAC fees, the maturity vault and the bot locker. Amounts
44
+ * only: the caller values them in USD with its own prices. Each source (and each gauge) is read independently, so one
45
+ * failing read shows as an error on that source and every other source still returns.
46
+ *
47
+ * Every configured gauge is scanned, not only those the user is staked in: a user can still have rewards after fully
48
+ * unstaking.
49
+ *
50
+ * @param chainId - The chain/network to use.
51
+ * @param user - The user's address.
52
+ * @param provider - Optional ethers.js Provider instance.
53
+ * @returns Per source: the non-zero claimable tokens, and an `error` when it failed.
54
+ */
55
+ export declare const getUserClaimables: (chainId: ChainId, user: string, provider?: Provider) => Promise<UserClaimables>;
@@ -0,0 +1,12 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { TokenAmount } from "../utils/amount";
4
+ /**
5
+ * The iREET a user has deposited as collateral in the lending pool's iREET adapter. NFT collateral is not included.
6
+ *
7
+ * @param chainId - The chain/network to use.
8
+ * @param user - The user's address.
9
+ * @param provider - Optional ethers.js Provider instance.
10
+ * @returns The deposited iREET, with its registry decimals and symbol.
11
+ */
12
+ export declare const getUserCollateral: (chainId: ChainId, user: string, provider?: Provider) => Promise<TokenAmount>;
@@ -0,0 +1,18 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { ScaledValue, TokenAmount } from "../utils/amount";
4
+ export interface UserDebt {
5
+ /** Current debt including accrued interest, in reserve units (pmUSD). */
6
+ amount: TokenAmount;
7
+ /** WAD health factor (liquidatable below 1e18); null when there is no debt. */
8
+ healthFactor: ScaledValue | null;
9
+ }
10
+ /**
11
+ * The debt and health factor of a user's iREET position in the lending pool.
12
+ *
13
+ * @param chainId - The chain/network to use.
14
+ * @param user - The user's address.
15
+ * @param provider - Optional ethers.js Provider instance.
16
+ * @returns The debt, and the health factor when there is debt.
17
+ */
18
+ export declare const getUserDebt: (chainId: ChainId, user: string, provider?: Provider) => Promise<UserDebt>;
@@ -0,0 +1,64 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { TokenAmount } from "../utils/amount";
4
+ import { UsdPrices } from "./_helpers";
5
+ /** What a coin earns on its own while it sits in a pool. */
6
+ export type UnderlyingYield =
7
+ /** Earns the lending pool supply rate (RpmUSD, DEpmUSD), wherever it sits. */
8
+ "supply"
9
+ /** Earns nothing on its own (pmUSD, RAAC; iREET for now, with fixed pricing). Counts only as capital. */
10
+ | "none";
11
+ export interface FarmingPoolCoin {
12
+ asset: string;
13
+ /** The user's share of the pool's balance of this coin, through LP in the wallet and staked in gauges. */
14
+ amount: TokenAmount;
15
+ valueUsd: number;
16
+ yield: UnderlyingYield;
17
+ }
18
+ export interface FarmingPool {
19
+ /** Curve pool id in the chain config. */
20
+ pool: string;
21
+ address: string;
22
+ /** LP held in the wallet. */
23
+ walletLp: TokenAmount;
24
+ /** LP staked in the pool's gauges. */
25
+ stakedLp: TokenAmount;
26
+ /** The user's share of each coin; empty when the user holds none of the pool's LP. */
27
+ coins: FarmingPoolCoin[];
28
+ }
29
+ export interface FarmingGauge {
30
+ /** Gauge id in the chain config. */
31
+ id: string;
32
+ gauge: string;
33
+ name: string;
34
+ pool: string;
35
+ /** LP staked (raw balance, not boosted). */
36
+ staked: TokenAmount;
37
+ /** Staked LP valued through the pool's coins at the passed prices. */
38
+ valueUsd: number;
39
+ /** The user's current boosted reward APR as a fraction; null with no stake. */
40
+ apr: number | null;
41
+ }
42
+ export interface UserFarming {
43
+ pools: FarmingPool[];
44
+ /** Every gauge on a read pool, including those the user has no stake in. */
45
+ gauges: FarmingGauge[];
46
+ /** Pools that could not be read. They and their gauges are left out of `pools` and `gauges`. */
47
+ errors: {
48
+ pool: string;
49
+ error: Error;
50
+ }[];
51
+ }
52
+ /**
53
+ * A user's Curve LP and gauge positions: every configured Curve pool that a configured gauge stakes, the user's share
54
+ * of each pool's coins, and their stake and boosted APR in each gauge. Each pool is read independently, so one failing
55
+ * pool shows in `errors` and the rest still return. Reserves, prices and APRs are only read for pools the user holds.
56
+ *
57
+ * @param chainId - The chain/network to use.
58
+ * @param user - The user's address.
59
+ * @param prices - USD per whole token, keyed by lowercase symbol. Needs every coin of a pool the user holds, and the
60
+ * reward tokens of a gauge the user is staked in.
61
+ * @param provider - Optional ethers.js Provider instance.
62
+ * @returns The pools and gauges read, and the pools that failed.
63
+ */
64
+ export declare const getUserFarming: (chainId: ChainId, user: string, prices: UsdPrices, provider?: Provider) => Promise<UserFarming>;
@@ -0,0 +1,20 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { TokenAmount } from "../utils/amount";
4
+ export interface UserGovernance {
5
+ votingPower: TokenAmount;
6
+ totalVotingPower: TokenAmount;
7
+ /** votingPower / totalVotingPower as a fraction; null when the total is zero. */
8
+ share: number | null;
9
+ /** RAAC locked in veRAAC. */
10
+ locked: TokenAmount;
11
+ }
12
+ /**
13
+ * A user's veRAAC governance position: voting power, its share of the total, and the RAAC locked.
14
+ *
15
+ * @param chainId - The chain/network to use.
16
+ * @param user - The user's address.
17
+ * @param provider - Optional ethers.js Provider instance.
18
+ * @returns The voting power, total voting power, share and locked RAAC.
19
+ */
20
+ export declare const getUserGovernance: (chainId: ChainId, user: string, provider?: Provider) => Promise<UserGovernance>;
@@ -0,0 +1,61 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { ScaledValue, TokenAmount } from "../utils/amount";
4
+ import { EffectiveReturn, ReturnLeg } from "./computeEffectiveReturn";
5
+ import { UserDebt } from "./getUserDebt";
6
+ import { UserWalletBalances } from "./getUserWalletBalances";
7
+ import { UserFarming } from "./getUserFarming";
8
+ import { UserGovernance } from "./getUserGovernance";
9
+ import { Section, UsdPrices } from "./_helpers";
10
+ export interface PortfolioCollateral {
11
+ /** iREET deposited in the lending pool's iREET adapter. */
12
+ amount: TokenAmount;
13
+ valueUsd: number;
14
+ }
15
+ export interface PortfolioDebt extends UserDebt {
16
+ valueUsd: number;
17
+ }
18
+ export interface PortfolioRates {
19
+ /** Current borrow rate (APR) as a ray: what the debt accrues per second, e.g. for interest per day. */
20
+ borrowRate: ScaledValue;
21
+ /** Projected borrow APY as a ray (the usage index compounds: e^rate - 1). */
22
+ borrowApy: ScaledValue;
23
+ /** Projected supply APY as a ray (the liquidity index accrues linearly, so it equals the supply rate). */
24
+ supplyApy: ScaledValue;
25
+ }
26
+ export interface PortfolioWallet extends UserWalletBalances {
27
+ /** RpmUSD + DEpmUSD in the wallet, in USD: the "Supplied" of the borrow/lend position panel. */
28
+ suppliedUsd: number;
29
+ idleUsd: number;
30
+ }
31
+ export interface UserPortfolio {
32
+ chainId: ChainId;
33
+ user: string;
34
+ collateral: Section<PortfolioCollateral>;
35
+ debt: Section<PortfolioDebt>;
36
+ rates: Section<PortfolioRates>;
37
+ wallet: Section<PortfolioWallet>;
38
+ farming: Section<UserFarming>;
39
+ governance: Section<UserGovernance>;
40
+ /** Collateral value + wallet RpmUSD + wallet DEpmUSD - debt, in USD. Lending pool only: LP and gauge positions are not included. */
41
+ netPositionUsd: Section<number>;
42
+ /** The legs the effective return is computed from; empty when any read it needs failed. */
43
+ legs: ReturnLeg[];
44
+ effectiveReturn: Section<EffectiveReturn>;
45
+ }
46
+ /**
47
+ * The user's position across the app: iREET collateral, debt and health factor, wallet RpmUSD/DEpmUSD/pmUSD, LP and
48
+ * gauge positions, veRAAC governance power, and the projected effective return built from them. Each part is read
49
+ * independently, so one failing read shows as an `error` on that part and the rest still return.
50
+ *
51
+ * Only the user's position data is returned; pool parameters such as the liquidation threshold stay with the callers
52
+ * that need them. iREET is the only collateral read (NFT positions are out of scope).
53
+ *
54
+ * @param chainId - The chain/network to use.
55
+ * @param user - The user's address.
56
+ * @param prices - USD per whole token, keyed by lowercase symbol. iREET, pmUSD, RpmUSD, DEpmUSD and RAAC are needed,
57
+ * plus every coin of a Curve pool the user holds.
58
+ * @param provider - Optional ethers.js Provider instance. Read-only is enough.
59
+ * @returns Each part as `{ data, error }`, the effective return legs, and the computed effective return.
60
+ */
61
+ export declare const getUserPortfolio: (chainId: ChainId, user: string, prices: UsdPrices, provider?: Provider) => Promise<UserPortfolio>;
@@ -0,0 +1,20 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains";
3
+ import { TokenAmount } from "../utils/amount";
4
+ export interface UserWalletBalances {
5
+ /** RpmUSD in the wallet, including the liquidity index. */
6
+ rtoken: TokenAmount;
7
+ /** DEpmUSD in the wallet, including interest. */
8
+ detoken: TokenAmount;
9
+ /** Idle pmUSD in the wallet. Earns nothing. */
10
+ pmusd: TokenAmount;
11
+ }
12
+ /**
13
+ * The lending tokens a user holds in their wallet: RpmUSD, DEpmUSD and idle pmUSD.
14
+ *
15
+ * @param chainId - The chain/network to use.
16
+ * @param user - The user's address.
17
+ * @param provider - Optional ethers.js Provider instance.
18
+ * @returns Each balance, with its registry decimals and symbol.
19
+ */
20
+ export declare const getUserWalletBalances: (chainId: ChainId, user: string, provider?: Provider) => Promise<UserWalletBalances>;
@@ -0,0 +1,9 @@
1
+ export * from "./computeEffectiveReturn";
2
+ export * from "./getUserClaimables";
3
+ export * from "./getUserCollateral";
4
+ export * from "./getUserDebt";
5
+ export * from "./getUserFarming";
6
+ export * from "./getUserGovernance";
7
+ export * from "./getUserPortfolio";
8
+ export * from "./getUserWalletBalances";
9
+ export type { UsdPrices, Section } from "./_helpers";
@@ -57,6 +57,13 @@ export declare function parseAmount(text: string, decimals: number): bigint;
57
57
  * @returns The decimal string, e.g. `"1.5"` or `"2.0"`.
58
58
  */
59
59
  export declare function toDecimalString(amount: ScaledValue): string;
60
+ /**
61
+ * An amount or scaled value as a JavaScript number, for USD and rate maths. Lossy past about 15 significant digits,
62
+ * so keep on-chain values as `bigint` and use this only for computed figures.
63
+ * @param amount The amount or scaled value, e.g. a ray rate of 3.5e25 becomes 0.035.
64
+ * @returns The value in whole units.
65
+ */
66
+ export declare function toNumber(amount: ScaledValue): number;
60
67
  /**
61
68
  * Converts an amount to a JSON-safe form, since `bigint` does not survive `JSON.stringify`.
62
69
  * @param amount The amount.
@@ -544,3 +544,5 @@ declare const _default: {
544
544
  };
545
545
  };
546
546
  export default _default;
547
+ /** Whether a config address is set and deployed: a valid, non-zero address. */
548
+ export declare const isDeployed: (address: string | null | undefined) => address is string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.settled = void 0;
4
+ exports.requireUsd = requireUsd;
5
+ const amount_1 = require("../utils/amount");
6
+ /** Settles one read into a {@link Section}: never rejects, so reads awaited together fail independently. */
7
+ const settled = (read) => read.then((data) => ({ data, error: null }), (reason) => ({ data: null, error: reason instanceof Error ? reason : new Error(String(reason)) }));
8
+ exports.settled = settled;
9
+ /**
10
+ * USD value of an amount from `prices`, by the symbol `toTokenAmount` gave it from the chain config's token registry.
11
+ * Throws when there is no price, so the section fails visibly instead of reading 0.
12
+ *
13
+ * @param token - The amount's asset key or token address, named in the error.
14
+ */
15
+ function requireUsd(prices, amount, token) {
16
+ if (amount.symbol === undefined)
17
+ throw new Error(`No USD price for ${token}: it has no symbol in the chain config's assets`);
18
+ const price = prices[amount.symbol.toLowerCase()];
19
+ if (typeof price !== "number" || !Number.isFinite(price))
20
+ throw new Error(`No USD price for ${amount.symbol}`);
21
+ return (0, amount_1.toNumber)(amount) * price;
22
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeEffectiveReturn = computeEffectiveReturn;
4
+ /**
5
+ * Projects the user's net return over one year from a list of legs. Pure: no reads.
6
+ *
7
+ * netIncome1y = sum(earning valueUsd * rate) - sum(cost valueUsd * rate)
8
+ * onDebt = netIncome1y / total debt
9
+ * onNetCapital = netIncome1y / (collateral + capital legs + idle - total debt)
10
+ *
11
+ * The legs do not reinvest into each other, so this is a projected net return, not an APY.
12
+ *
13
+ * @param input - The legs, the collateral value and any idle capital, all in USD.
14
+ * @returns The net income, both returns and each leg with its own projected income.
15
+ */
16
+ function computeEffectiveReturn({ legs, collateralUsd, idleUsd = 0 }) {
17
+ const withIncome = legs.map((leg) => {
18
+ const income = leg.valueUsd * leg.rate;
19
+ return { ...leg, income1y: leg.kind === "cost" ? -income : income };
20
+ });
21
+ const netIncome1y = withIncome.reduce((sum, leg) => sum + leg.income1y, 0);
22
+ const debtUsd = legs.filter((leg) => leg.kind === "cost").reduce((sum, leg) => sum + leg.valueUsd, 0);
23
+ const capitalUsd = legs.filter((leg) => leg.countsAsCapital).reduce((sum, leg) => sum + leg.valueUsd, 0);
24
+ const netCapitalUsd = collateralUsd + capitalUsd + idleUsd - debtUsd;
25
+ return {
26
+ netIncome1y,
27
+ onDebt: debtUsd > 0 ? netIncome1y / debtUsd : null,
28
+ onNetCapital: netCapitalUsd > 0 ? netIncome1y / netCapitalUsd : null,
29
+ debtUsd,
30
+ netCapitalUsd,
31
+ legs: withIncome,
32
+ };
33
+ }