@raac/rpc 2.0.0-beta.16 → 2.0.0-beta.18
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.
- package/dist/RPCLibrary.js +6 -0
- package/dist/configs/chains/11155111.json +15 -0
- package/dist/contracts/curve/common/getPoolState.js +105 -0
- package/dist/contracts/curve/common/index.js +1 -0
- package/dist/contracts/yearn/vault/_helpers.js +86 -0
- package/dist/contracts/yearn/vault/deposit.js +29 -0
- package/dist/contracts/yearn/vault/getApr.js +34 -0
- package/dist/contracts/yearn/vault/getUserInfo.js +48 -0
- package/dist/contracts/yearn/vault/getVaultInfo.js +71 -0
- package/dist/contracts/yearn/vault/getVaults.js +22 -0
- package/dist/contracts/yearn/vault/index.js +29 -0
- package/dist/contracts/yearn/vault/mint.js +29 -0
- package/dist/contracts/yearn/vault/previewDeposit.js +25 -0
- package/dist/contracts/yearn/vault/previewMint.js +25 -0
- package/dist/contracts/yearn/vault/previewRedeem.js +25 -0
- package/dist/contracts/yearn/vault/previewWithdraw.js +25 -0
- package/dist/contracts/yearn/vault/processReport.js +29 -0
- package/dist/contracts/yearn/vault/redeem.js +30 -0
- package/dist/contracts/yearn/vault/withdraw.js +30 -0
- package/dist/types/RPCLibrary.d.ts +4 -0
- package/dist/types/contracts/curve/common/getPoolState.d.ts +43 -0
- package/dist/types/contracts/curve/common/index.d.ts +1 -0
- package/dist/types/contracts/yearn/vault/_helpers.d.ts +24 -0
- package/dist/types/contracts/yearn/vault/deposit.d.ts +14 -0
- package/dist/types/contracts/yearn/vault/getApr.d.ts +14 -0
- package/dist/types/contracts/yearn/vault/getUserInfo.d.ts +29 -0
- package/dist/types/contracts/yearn/vault/getVaultInfo.d.ts +43 -0
- package/dist/types/contracts/yearn/vault/getVaults.d.ts +18 -0
- package/dist/types/contracts/yearn/vault/index.d.ts +13 -0
- package/dist/types/contracts/yearn/vault/mint.d.ts +14 -0
- package/dist/types/contracts/yearn/vault/previewDeposit.d.ts +13 -0
- package/dist/types/contracts/yearn/vault/previewMint.d.ts +13 -0
- package/dist/types/contracts/yearn/vault/previewRedeem.d.ts +13 -0
- package/dist/types/contracts/yearn/vault/previewWithdraw.d.ts +13 -0
- package/dist/types/contracts/yearn/vault/processReport.d.ts +14 -0
- package/dist/types/contracts/yearn/vault/redeem.d.ts +15 -0
- package/dist/types/contracts/yearn/vault/withdraw.d.ts +15 -0
- package/dist/types/user/computeEffectiveReturn.d.ts +3 -3
- package/dist/types/user/getUserPortfolio.d.ts +12 -2
- package/dist/types/user/getUserSavings.d.ts +30 -0
- package/dist/types/user/index.d.ts +1 -0
- package/dist/user/getUserPortfolio.js +16 -6
- package/dist/user/getUserSavings.js +35 -0
- package/dist/user/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processReport = void 0;
|
|
4
|
+
const rpcError_1 = require("../../../utils/rpcError");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Reports a strategy, or with no `strategy` the vault itself. A self-report books any vault asset sent to the vault
|
|
8
|
+
* since the last report as profit and streams it to depositors over `profitMaxUnlockTime`; this is how rewards
|
|
9
|
+
* reach a vault without strategies. The signer needs the vault's REPORTING_MANAGER role.
|
|
10
|
+
*
|
|
11
|
+
* @param chainId - The chain/network to use.
|
|
12
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
13
|
+
* @param strategy - The strategy to report; defaults to the vault (self-report).
|
|
14
|
+
* @param signer - The signer sending the transaction.
|
|
15
|
+
* @returns The mined transaction receipt.
|
|
16
|
+
*/
|
|
17
|
+
const processReport = async (chainId, vaultAddressOrId, strategy, signer) => {
|
|
18
|
+
if (!signer)
|
|
19
|
+
throw new Error("Signer is required");
|
|
20
|
+
const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, signer);
|
|
21
|
+
try {
|
|
22
|
+
const tx = await contract.process_report(strategy ?? entry.contract);
|
|
23
|
+
return await tx.wait();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw (0, rpcError_1.toRpcError)("yearn.processReport", error, { chainId, address: entry.contract });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.processReport = processReport;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redeem = void 0;
|
|
4
|
+
const rpcError_1 = require("../../../utils/rpcError");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Redeems `shares` for the vault asset (see `previewRedeem`). Use this, with the user's full share balance, to
|
|
8
|
+
* exit completely. Uses Yearn's default max loss of 100%, which only matters for a vault with strategies.
|
|
9
|
+
*
|
|
10
|
+
* @param chainId - The chain/network to use.
|
|
11
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
12
|
+
* @param shares - Share amount, in base units.
|
|
13
|
+
* @param receiver - Who receives the assets.
|
|
14
|
+
* @param owner - Whose shares are burnt; the signer, or an owner that approved the signer for the shares.
|
|
15
|
+
* @param signer - The signer sending the transaction.
|
|
16
|
+
* @returns The mined transaction receipt.
|
|
17
|
+
*/
|
|
18
|
+
const redeem = async (chainId, vaultAddressOrId, shares, receiver, owner, signer) => {
|
|
19
|
+
if (!signer)
|
|
20
|
+
throw new Error("Signer is required");
|
|
21
|
+
const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, signer);
|
|
22
|
+
try {
|
|
23
|
+
const tx = await contract.redeem(shares, receiver, owner);
|
|
24
|
+
return await tx.wait();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw (0, rpcError_1.toRpcError)("yearn.redeem", error, { chainId, address: entry.contract });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.redeem = redeem;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withdraw = void 0;
|
|
4
|
+
const rpcError_1 = require("../../../utils/rpcError");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Withdraws exactly `assets` of the vault asset, burning the shares they cost (see `previewWithdraw`). Uses
|
|
8
|
+
* Yearn's default max loss of 0.
|
|
9
|
+
*
|
|
10
|
+
* @param chainId - The chain/network to use.
|
|
11
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
12
|
+
* @param assets - Vault asset amount, in its base units.
|
|
13
|
+
* @param receiver - Who receives the assets.
|
|
14
|
+
* @param owner - Whose shares are burnt; the signer, or an owner that approved the signer for the shares.
|
|
15
|
+
* @param signer - The signer sending the transaction.
|
|
16
|
+
* @returns The mined transaction receipt.
|
|
17
|
+
*/
|
|
18
|
+
const withdraw = async (chainId, vaultAddressOrId, assets, receiver, owner, signer) => {
|
|
19
|
+
if (!signer)
|
|
20
|
+
throw new Error("Signer is required");
|
|
21
|
+
const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, signer);
|
|
22
|
+
try {
|
|
23
|
+
const tx = await contract.withdraw(assets, receiver, owner);
|
|
24
|
+
return await tx.wait();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw (0, rpcError_1.toRpcError)("yearn.withdraw", error, { chainId, address: entry.contract });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.withdraw = withdraw;
|
|
@@ -160,6 +160,7 @@ import * as gaugeMethods from "./contracts/governance/gauge";
|
|
|
160
160
|
import * as controllerMethods from "./contracts/governance/gaugeController";
|
|
161
161
|
import * as gaugeSystemMethods from "./contracts/governance/gaugeSystems";
|
|
162
162
|
import * as curveCommonMethods from "./contracts/curve/common";
|
|
163
|
+
import * as yearnVaultMethods from "./contracts/yearn/vault";
|
|
163
164
|
import * as faucetMethods from "./contracts/faucet";
|
|
164
165
|
import * as userMethods from "./user";
|
|
165
166
|
import { cancel as cancelProposals } from "./contracts/governance/proposals/cancel";
|
|
@@ -342,6 +343,9 @@ declare class RPCLibrary {
|
|
|
342
343
|
curve: {
|
|
343
344
|
common: typeof curveCommonMethods;
|
|
344
345
|
};
|
|
346
|
+
yearn: {
|
|
347
|
+
vault: typeof yearnVaultMethods;
|
|
348
|
+
};
|
|
345
349
|
faucet: typeof faucetMethods;
|
|
346
350
|
user: typeof userMethods;
|
|
347
351
|
prices: {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { ScaledValue, TokenAmount } from "../../../utils/amount";
|
|
4
|
+
import { CurvePool } from "./getPools";
|
|
5
|
+
export interface CurvePoolState {
|
|
6
|
+
pool: CurvePool;
|
|
7
|
+
/** Coin balances in pool index order, each in its own decimals and symbol. */
|
|
8
|
+
balances: TokenAmount[];
|
|
9
|
+
/** LP tokens in circulation (the pool is its own LP token, 18 decimals). */
|
|
10
|
+
totalSupply: TokenAmount;
|
|
11
|
+
/** `get_virtual_price()`: underlying per LP token, only grows with fees. */
|
|
12
|
+
virtualPrice: TokenAmount;
|
|
13
|
+
/** Value of one LP token in coin 0: `lp_price()` on crypto pools, the balances at oracle prices on stableswap pools. */
|
|
14
|
+
lpPrice: TokenAmount;
|
|
15
|
+
/** Price of each coin in coin 0, 18 decimals, from the pool's EMA oracle; `oraclePrices[0]` is 1. */
|
|
16
|
+
oraclePrices: TokenAmount[];
|
|
17
|
+
/** Price of each coin in coin 0 right now: `last_prices` on crypto pools, `get_p` on stableswap pools. */
|
|
18
|
+
spotPrices: TokenAmount[];
|
|
19
|
+
/** Crypto pools only: where liquidity is concentrated (`price_scale`), in coin 0. Null on stableswap pools. */
|
|
20
|
+
priceScale: TokenAmount[] | null;
|
|
21
|
+
/** Each balance valued in coin 0 at the oracle price; their sum is the pool's TVL in coin 0. */
|
|
22
|
+
values: TokenAmount[];
|
|
23
|
+
tvl: TokenAmount;
|
|
24
|
+
/** Current swap fee as a fraction (Curve's 1e10 scale). */
|
|
25
|
+
fee: ScaledValue;
|
|
26
|
+
/** Crypto pools: the fee range the current fee moves in, as fractions. Null on stableswap pools. */
|
|
27
|
+
feeRange: {
|
|
28
|
+
mid: ScaledValue;
|
|
29
|
+
out: ScaledValue;
|
|
30
|
+
} | null;
|
|
31
|
+
/** Amplification, as the pool's `A()` reports it (crypto pools scale it by 10000). */
|
|
32
|
+
A: bigint;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads a Curve pool's composition, prices and fees in one go: balances, LP supply, virtual and LP price, the
|
|
36
|
+
* oracle, spot and (crypto) scale price of every coin in coin 0, each balance's value in coin 0, and the fee and A.
|
|
37
|
+
*
|
|
38
|
+
* @param chainId - The chain/network to use.
|
|
39
|
+
* @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
|
|
40
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
41
|
+
* @returns The pool's state; values and TVL are in coin 0's units at the oracle price.
|
|
42
|
+
*/
|
|
43
|
+
export declare const getPoolState: (chainId: ChainId, poolAddressOrId: string, provider?: Provider) => Promise<CurvePoolState>;
|
|
@@ -4,6 +4,7 @@ export * from "./calcWithdrawOneCoin";
|
|
|
4
4
|
export * from "./exchange";
|
|
5
5
|
export * from "./getDy";
|
|
6
6
|
export * from "./getPools";
|
|
7
|
+
export * from "./getPoolState";
|
|
7
8
|
export * from "./getVirtualPrice";
|
|
8
9
|
export * from "./removeLiquidity";
|
|
9
10
|
export * from "./removeLiquidityOneCoin";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ethers, Provider, Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { YearnVaultEntry, YearnVaults } from "../../../configs/chains/chain";
|
|
4
|
+
/**
|
|
5
|
+
* The Yearn V3 vault surface (VaultV3.vy, API 3.0.x) these methods use. ERC4626 calls use the standard
|
|
6
|
+
* signatures: Yearn's `withdraw` defaults to a 0 max loss and `redeem` to 100%, which only matter for a vault
|
|
7
|
+
* with strategies.
|
|
8
|
+
*/
|
|
9
|
+
export declare const YEARN_VAULT_ABI: string[];
|
|
10
|
+
/** `profitUnlockingRate` is shares per second scaled by this (VaultV3.vy `MAX_BPS_EXTENDED`). */
|
|
11
|
+
export declare const PROFIT_UNLOCKING_RATE_SCALE: bigint;
|
|
12
|
+
/**
|
|
13
|
+
* The APR the vault pays right now: the assets its locked profit releases per second, annualised, over total
|
|
14
|
+
* assets, as a WAD. Zero once the last reported profit has fully unlocked. It reflects the current stream only.
|
|
15
|
+
*/
|
|
16
|
+
export declare function aprFromUnlockingRate(contract: ethers.Contract, profitUnlockingRate: bigint, fullProfitUnlockDate: bigint, totalAssets: bigint, now: bigint): Promise<bigint>;
|
|
17
|
+
export declare const getYearnVaults: (chainId: ChainId) => YearnVaults;
|
|
18
|
+
/** Resolves a Yearn vault by its config key (any casing) or its address. */
|
|
19
|
+
export declare function resolveYearnVault(chainId: ChainId, vaultAddressOrId: string): YearnVaultEntry;
|
|
20
|
+
/** The vault contract bound to `runner`, or to the chain's default RPC when none is given. */
|
|
21
|
+
export declare function getYearnVaultContract(chainId: ChainId, vaultAddressOrId: string, runner?: Provider | Signer): {
|
|
22
|
+
entry: YearnVaultEntry;
|
|
23
|
+
contract: ethers.Contract;
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Deposits `assets` of the vault asset for shares. The signer approves the vault for the asset first
|
|
5
|
+
* (`wallet.assets.approveAsset(chainId, vault.asset, vault.contract, amount, signer)`).
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param assets - Vault asset amount, in its base units.
|
|
10
|
+
* @param receiver - Who receives the shares.
|
|
11
|
+
* @param signer - The signer sending the transaction and paying the assets.
|
|
12
|
+
* @returns The mined transaction receipt.
|
|
13
|
+
*/
|
|
14
|
+
export declare const deposit: (chainId: ChainId, vaultAddressOrId: string, assets: bigint, receiver: string, signer: Signer) => Promise<any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { ScaledValue } from "../../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* The APR a Yearn V3 vault pays right now, from the profit still unlocking: assets released per second,
|
|
6
|
+
* annualised, over total assets. It is 0 once the last report has fully unlocked, so it reflects the current
|
|
7
|
+
* reward stream, not a historical average.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain/network to use.
|
|
10
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
11
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
12
|
+
* @returns The APR as a WAD (0.05e18 = 5%).
|
|
13
|
+
*/
|
|
14
|
+
export declare const getApr: (chainId: ChainId, vaultAddressOrId: string, provider?: Provider) => Promise<ScaledValue>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
export interface YearnVaultUserInfo {
|
|
5
|
+
/** Vault shares held. */
|
|
6
|
+
shares: TokenAmount;
|
|
7
|
+
/** What `shares` redeem for now, in the vault asset. */
|
|
8
|
+
assets: TokenAmount;
|
|
9
|
+
/** Wallet balance of the vault asset. */
|
|
10
|
+
assetBalance: TokenAmount;
|
|
11
|
+
/** Vault asset allowance to the vault, which `deposit` and `mint` pull from. */
|
|
12
|
+
assetAllowance: TokenAmount;
|
|
13
|
+
/** Most the user can deposit now, in the vault asset. */
|
|
14
|
+
maxDeposit: TokenAmount;
|
|
15
|
+
/** Most the user can withdraw now, in the vault asset. */
|
|
16
|
+
maxWithdraw: TokenAmount;
|
|
17
|
+
/** Most shares the user can redeem now; redeem `shares` instead for a full exit, as this can round 1 wei short. */
|
|
18
|
+
maxRedeem: TokenAmount;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets a user's position in a Yearn V3 vault, plus their vault asset balance and allowance.
|
|
22
|
+
*
|
|
23
|
+
* @param chainId - The chain/network to use.
|
|
24
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section (e.g. "spmusd"), or its address.
|
|
25
|
+
* @param account - Address of the user.
|
|
26
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
27
|
+
* @returns The user's shares, their asset value, balances, allowance and limits, in base units.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getUserInfo(chainId: ChainId, vaultAddressOrId: string, account: string, provider?: Provider): Promise<YearnVaultUserInfo>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { YearnVaultEntry } from "../../../configs/chains/chain";
|
|
4
|
+
import { ScaledValue, TokenAmount } from "../../../utils/amount";
|
|
5
|
+
export interface YearnVaultInfo extends YearnVaultEntry {
|
|
6
|
+
/** Address of the vault asset. */
|
|
7
|
+
assetAddress: string;
|
|
8
|
+
apiVersion: string;
|
|
9
|
+
totalAssets: TokenAmount;
|
|
10
|
+
totalSupply: TokenAmount;
|
|
11
|
+
/** Assets held by the vault itself; all of them for a vault without strategies. */
|
|
12
|
+
totalIdle: TokenAmount;
|
|
13
|
+
/** Assets lent to strategies. */
|
|
14
|
+
totalDebt: TokenAmount;
|
|
15
|
+
/** Assets per whole share, in the vault asset's decimals. */
|
|
16
|
+
pricePerShare: ScaledValue;
|
|
17
|
+
/** Current APR from the profit still unlocking, as a WAD (0.05e18 = 5%); 0 when nothing is unlocking. */
|
|
18
|
+
apr: ScaledValue;
|
|
19
|
+
/** Reported profit not yet released to depositors, in the vault asset. */
|
|
20
|
+
lockedProfit: TokenAmount;
|
|
21
|
+
/** Seconds a reported profit takes to unlock. */
|
|
22
|
+
profitMaxUnlockTime: number;
|
|
23
|
+
/** Unix timestamp the locked profit finishes unlocking; 0 or in the past when nothing is unlocking. */
|
|
24
|
+
fullProfitUnlockDate: number;
|
|
25
|
+
/** Unix timestamp of the last report. */
|
|
26
|
+
lastProfitUpdate: number;
|
|
27
|
+
depositLimit: TokenAmount;
|
|
28
|
+
isShutdown: boolean;
|
|
29
|
+
/** Null when no accountant is set (no fees). */
|
|
30
|
+
accountant: string | null;
|
|
31
|
+
roleManager: string;
|
|
32
|
+
/** The default withdrawal queue; empty for a vault without strategies. */
|
|
33
|
+
strategies: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the vault-wide state of a Yearn V3 vault. For a user's position use `getUserInfo`.
|
|
37
|
+
*
|
|
38
|
+
* @param chainId - The chain/network to use.
|
|
39
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section (e.g. "spmusd"), or its address.
|
|
40
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
41
|
+
* @returns The vault state, with amounts in base units.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getVaultInfo(chainId: ChainId, vaultAddressOrId: string, provider?: Provider): Promise<YearnVaultInfo>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ChainId } from "../../../configs/chains";
|
|
2
|
+
import { YearnVaultEntry } from "../../../configs/chains/chain";
|
|
3
|
+
/**
|
|
4
|
+
* Lists the Yearn V3 vaults in the chain config. Reads the config only; no RPC call is made.
|
|
5
|
+
*
|
|
6
|
+
* @param chainId - The chain/network to use.
|
|
7
|
+
* @returns Every configured vault; empty when the chain has none.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getVaults: (chainId: ChainId) => YearnVaultEntry[];
|
|
10
|
+
/**
|
|
11
|
+
* Looks up one Yearn V3 vault in the chain config. Reads the config only; no RPC call is made.
|
|
12
|
+
*
|
|
13
|
+
* @param chainId - The chain/network to use.
|
|
14
|
+
* @param vaultAddressOrId - The vault's config key or its address.
|
|
15
|
+
* @returns The vault entry.
|
|
16
|
+
* @throws If the vault is not configured on the chain.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getVault: (chainId: ChainId, vaultAddressOrId: string) => YearnVaultEntry;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./deposit";
|
|
2
|
+
export * from "./getApr";
|
|
3
|
+
export * from "./getUserInfo";
|
|
4
|
+
export * from "./getVaultInfo";
|
|
5
|
+
export * from "./getVaults";
|
|
6
|
+
export * from "./mint";
|
|
7
|
+
export * from "./previewDeposit";
|
|
8
|
+
export * from "./previewMint";
|
|
9
|
+
export * from "./previewRedeem";
|
|
10
|
+
export * from "./previewWithdraw";
|
|
11
|
+
export * from "./processReport";
|
|
12
|
+
export * from "./redeem";
|
|
13
|
+
export * from "./withdraw";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Mints exactly `shares`, pulling the assets they cost (see `previewMint`). The signer approves the vault for the
|
|
5
|
+
* asset first.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param shares - Share amount, in base units.
|
|
10
|
+
* @param receiver - Who receives the shares.
|
|
11
|
+
* @param signer - The signer sending the transaction and paying the assets.
|
|
12
|
+
* @returns The mined transaction receipt.
|
|
13
|
+
*/
|
|
14
|
+
export declare const mint: (chainId: ChainId, vaultAddressOrId: string, shares: bigint, receiver: string, signer: Signer) => Promise<any>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* Shares a deposit of `assets` would mint now.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param assets - Vault asset amount, in its base units.
|
|
10
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
11
|
+
* @returns The shares, in base units.
|
|
12
|
+
*/
|
|
13
|
+
export declare const previewDeposit: (chainId: ChainId, vaultAddressOrId: string, assets: bigint, provider?: Provider) => Promise<TokenAmount>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* Assets a mint of `shares` would pull now.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param shares - Share amount, in base units.
|
|
10
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
11
|
+
* @returns The vault asset amount, in its base units.
|
|
12
|
+
*/
|
|
13
|
+
export declare const previewMint: (chainId: ChainId, vaultAddressOrId: string, shares: bigint, provider?: Provider) => Promise<TokenAmount>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* Assets a redemption of `shares` would pay out now.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param shares - Share amount, in base units.
|
|
10
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
11
|
+
* @returns The vault asset amount, in its base units.
|
|
12
|
+
*/
|
|
13
|
+
export declare const previewRedeem: (chainId: ChainId, vaultAddressOrId: string, shares: bigint, provider?: Provider) => Promise<TokenAmount>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* Shares a withdrawal of `assets` would burn now.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param assets - Vault asset amount, in its base units.
|
|
10
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
11
|
+
* @returns The shares, in base units.
|
|
12
|
+
*/
|
|
13
|
+
export declare const previewWithdraw: (chainId: ChainId, vaultAddressOrId: string, assets: bigint, provider?: Provider) => Promise<TokenAmount>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Reports a strategy, or with no `strategy` the vault itself. A self-report books any vault asset sent to the vault
|
|
5
|
+
* since the last report as profit and streams it to depositors over `profitMaxUnlockTime`; this is how rewards
|
|
6
|
+
* reach a vault without strategies. The signer needs the vault's REPORTING_MANAGER role.
|
|
7
|
+
*
|
|
8
|
+
* @param chainId - The chain/network to use.
|
|
9
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
10
|
+
* @param strategy - The strategy to report; defaults to the vault (self-report).
|
|
11
|
+
* @param signer - The signer sending the transaction.
|
|
12
|
+
* @returns The mined transaction receipt.
|
|
13
|
+
*/
|
|
14
|
+
export declare const processReport: (chainId: ChainId, vaultAddressOrId: string, strategy: string | undefined, signer: Signer) => Promise<any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Redeems `shares` for the vault asset (see `previewRedeem`). Use this, with the user's full share balance, to
|
|
5
|
+
* exit completely. Uses Yearn's default max loss of 100%, which only matters for a vault with strategies.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param shares - Share amount, in base units.
|
|
10
|
+
* @param receiver - Who receives the assets.
|
|
11
|
+
* @param owner - Whose shares are burnt; the signer, or an owner that approved the signer for the shares.
|
|
12
|
+
* @param signer - The signer sending the transaction.
|
|
13
|
+
* @returns The mined transaction receipt.
|
|
14
|
+
*/
|
|
15
|
+
export declare const redeem: (chainId: ChainId, vaultAddressOrId: string, shares: bigint, receiver: string, owner: string, signer: Signer) => Promise<any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Withdraws exactly `assets` of the vault asset, burning the shares they cost (see `previewWithdraw`). Uses
|
|
5
|
+
* Yearn's default max loss of 0.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
|
|
9
|
+
* @param assets - Vault asset amount, in its base units.
|
|
10
|
+
* @param receiver - Who receives the assets.
|
|
11
|
+
* @param owner - Whose shares are burnt; the signer, or an owner that approved the signer for the shares.
|
|
12
|
+
* @param signer - The signer sending the transaction.
|
|
13
|
+
* @returns The mined transaction receipt.
|
|
14
|
+
*/
|
|
15
|
+
export declare const withdraw: (chainId: ChainId, vaultAddressOrId: string, assets: bigint, receiver: string, owner: string, signer: Signer) => Promise<any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Whether a leg earns income or costs it. */
|
|
2
2
|
export type ReturnLegKind = "earning" | "cost";
|
|
3
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";
|
|
4
|
+
export type ReturnLegYieldType = "supply" | "gauge" | "savings" | "borrow";
|
|
5
5
|
/**
|
|
6
6
|
* One income stream in the user's position, as {@link computeEffectiveReturn} consumes it. Adding a venue (a new
|
|
7
7
|
* gauge, another pmUSD venue) only means adding a leg; the calculator does not change.
|
|
@@ -14,7 +14,7 @@ export interface ReturnLeg {
|
|
|
14
14
|
kind: ReturnLegKind;
|
|
15
15
|
yieldType: ReturnLegYieldType;
|
|
16
16
|
/**
|
|
17
|
-
* True when the leg's value is money the user holds and counts towards net capital (supplied). False for the
|
|
17
|
+
* True when the leg's value is money the user holds and counts towards net capital (supplied, savings). False for the
|
|
18
18
|
* debt itself, and for overlays such as a gauge, whose staked value is already counted in another leg.
|
|
19
19
|
*/
|
|
20
20
|
countsAsCapital: boolean;
|
|
@@ -22,7 +22,7 @@ export interface ReturnLeg {
|
|
|
22
22
|
valueUsd: number;
|
|
23
23
|
/** The projected one-year rate as a fraction, e.g. 0.0077 for 0.77%. */
|
|
24
24
|
rate: number;
|
|
25
|
-
/** How `rate` is quoted: "apy" when it already compounds (borrow), "apr" when it does not (supply, gauge). */
|
|
25
|
+
/** How `rate` is quoted: "apy" when it already compounds (borrow), "apr" when it does not (supply, gauge, savings). */
|
|
26
26
|
rateKind: "apr" | "apy";
|
|
27
27
|
}
|
|
28
28
|
export interface ReturnLegWithIncome extends ReturnLeg {
|
|
@@ -6,6 +6,7 @@ import { UserDebt } from "./getUserDebt";
|
|
|
6
6
|
import { UserWalletBalances } from "./getUserWalletBalances";
|
|
7
7
|
import { UserFarming } from "./getUserFarming";
|
|
8
8
|
import { UserGovernance } from "./getUserGovernance";
|
|
9
|
+
import { UserSavingsVault } from "./getUserSavings";
|
|
9
10
|
import { Section, UsdPrices } from "./_helpers";
|
|
10
11
|
export interface PortfolioCollateral {
|
|
11
12
|
/** iREET deposited in the lending pool's iREET adapter. */
|
|
@@ -28,6 +29,13 @@ export interface PortfolioWallet extends UserWalletBalances {
|
|
|
28
29
|
suppliedUsd: number;
|
|
29
30
|
idleUsd: number;
|
|
30
31
|
}
|
|
32
|
+
export interface PortfolioSavingsVault extends UserSavingsVault {
|
|
33
|
+
valueUsd: number;
|
|
34
|
+
}
|
|
35
|
+
export interface PortfolioSavings {
|
|
36
|
+
vaults: PortfolioSavingsVault[];
|
|
37
|
+
valueUsd: number;
|
|
38
|
+
}
|
|
31
39
|
export interface UserPortfolio {
|
|
32
40
|
chainId: ChainId;
|
|
33
41
|
user: string;
|
|
@@ -37,6 +45,8 @@ export interface UserPortfolio {
|
|
|
37
45
|
wallet: Section<PortfolioWallet>;
|
|
38
46
|
farming: Section<UserFarming>;
|
|
39
47
|
governance: Section<UserGovernance>;
|
|
48
|
+
/** Savings vault (spmUSD) positions. */
|
|
49
|
+
savings: Section<PortfolioSavings>;
|
|
40
50
|
/** Collateral value + wallet RpmUSD + wallet DEpmUSD - debt, in USD. Lending pool only: LP and gauge positions are not included. */
|
|
41
51
|
netPositionUsd: Section<number>;
|
|
42
52
|
/** The legs the effective return is computed from; empty when any read it needs failed. */
|
|
@@ -45,7 +55,7 @@ export interface UserPortfolio {
|
|
|
45
55
|
}
|
|
46
56
|
/**
|
|
47
57
|
* 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
|
|
58
|
+
* gauge positions, savings vault positions, veRAAC governance power, and the projected effective return built from them. Each part is read
|
|
49
59
|
* independently, so one failing read shows as an `error` on that part and the rest still return.
|
|
50
60
|
*
|
|
51
61
|
* Only the user's position data is returned; pool parameters such as the liquidation threshold stay with the callers
|
|
@@ -54,7 +64,7 @@ export interface UserPortfolio {
|
|
|
54
64
|
* @param chainId - The chain/network to use.
|
|
55
65
|
* @param user - The user's address.
|
|
56
66
|
* @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.
|
|
67
|
+
* plus every coin of a Curve pool the user holds. Savings positions are valued at their asset's price (pmUSD).
|
|
58
68
|
* @param provider - Optional ethers.js Provider instance. Read-only is enough.
|
|
59
69
|
* @returns Each part as `{ data, error }`, the effective return legs, and the computed effective return.
|
|
60
70
|
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../configs/chains";
|
|
3
|
+
import { ScaledValue, TokenAmount } from "../utils/amount";
|
|
4
|
+
export interface UserSavingsVault {
|
|
5
|
+
/** The vault's key in the chain config's `yearn` section, e.g. "spmusd". */
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
/** Vault (share token) address. */
|
|
9
|
+
vault: string;
|
|
10
|
+
/** Vault shares held. */
|
|
11
|
+
shares: TokenAmount;
|
|
12
|
+
/** What `shares` redeem for now, in the vault asset. */
|
|
13
|
+
assets: TokenAmount;
|
|
14
|
+
/** The vault's current APR as a WAD, from the reward still unlocking; 0 once it has all unlocked. */
|
|
15
|
+
apr: ScaledValue;
|
|
16
|
+
}
|
|
17
|
+
export interface UserSavings {
|
|
18
|
+
/** Every vault in the chain config's `yearn` section the user holds shares in. */
|
|
19
|
+
vaults: UserSavingsVault[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The user's positions in the chain's savings vaults (the Yearn V3 vaults in the chain config, e.g. spmUSD). Vaults
|
|
23
|
+
* the user holds nothing in are left out; a chain without savings vaults returns none.
|
|
24
|
+
*
|
|
25
|
+
* @param chainId - The chain/network to use.
|
|
26
|
+
* @param user - The user's address.
|
|
27
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
28
|
+
* @returns The vaults the user holds, with what the shares are worth and the vault's current APR.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getUserSavings: (chainId: ChainId, user: string, provider?: Provider) => Promise<UserSavings>;
|
|
@@ -5,5 +5,6 @@ export * from "./getUserDebt";
|
|
|
5
5
|
export * from "./getUserFarming";
|
|
6
6
|
export * from "./getUserGovernance";
|
|
7
7
|
export * from "./getUserPortfolio";
|
|
8
|
+
export * from "./getUserSavings";
|
|
8
9
|
export * from "./getUserWalletBalances";
|
|
9
10
|
export type { UsdPrices, Section } from "./_helpers";
|