@raac/rpc 2.0.0-beta.16 → 2.0.0-beta.17

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 (41) hide show
  1. package/dist/RPCLibrary.js +6 -0
  2. package/dist/configs/chains/11155111.json +15 -0
  3. package/dist/contracts/yearn/vault/_helpers.js +86 -0
  4. package/dist/contracts/yearn/vault/deposit.js +29 -0
  5. package/dist/contracts/yearn/vault/getApr.js +34 -0
  6. package/dist/contracts/yearn/vault/getUserInfo.js +48 -0
  7. package/dist/contracts/yearn/vault/getVaultInfo.js +71 -0
  8. package/dist/contracts/yearn/vault/getVaults.js +22 -0
  9. package/dist/contracts/yearn/vault/index.js +29 -0
  10. package/dist/contracts/yearn/vault/mint.js +29 -0
  11. package/dist/contracts/yearn/vault/previewDeposit.js +25 -0
  12. package/dist/contracts/yearn/vault/previewMint.js +25 -0
  13. package/dist/contracts/yearn/vault/previewRedeem.js +25 -0
  14. package/dist/contracts/yearn/vault/previewWithdraw.js +25 -0
  15. package/dist/contracts/yearn/vault/processReport.js +29 -0
  16. package/dist/contracts/yearn/vault/redeem.js +30 -0
  17. package/dist/contracts/yearn/vault/withdraw.js +30 -0
  18. package/dist/types/RPCLibrary.d.ts +4 -0
  19. package/dist/types/contracts/yearn/vault/_helpers.d.ts +24 -0
  20. package/dist/types/contracts/yearn/vault/deposit.d.ts +14 -0
  21. package/dist/types/contracts/yearn/vault/getApr.d.ts +14 -0
  22. package/dist/types/contracts/yearn/vault/getUserInfo.d.ts +29 -0
  23. package/dist/types/contracts/yearn/vault/getVaultInfo.d.ts +43 -0
  24. package/dist/types/contracts/yearn/vault/getVaults.d.ts +18 -0
  25. package/dist/types/contracts/yearn/vault/index.d.ts +13 -0
  26. package/dist/types/contracts/yearn/vault/mint.d.ts +14 -0
  27. package/dist/types/contracts/yearn/vault/previewDeposit.d.ts +13 -0
  28. package/dist/types/contracts/yearn/vault/previewMint.d.ts +13 -0
  29. package/dist/types/contracts/yearn/vault/previewRedeem.d.ts +13 -0
  30. package/dist/types/contracts/yearn/vault/previewWithdraw.d.ts +13 -0
  31. package/dist/types/contracts/yearn/vault/processReport.d.ts +14 -0
  32. package/dist/types/contracts/yearn/vault/redeem.d.ts +15 -0
  33. package/dist/types/contracts/yearn/vault/withdraw.d.ts +15 -0
  34. package/dist/types/user/computeEffectiveReturn.d.ts +3 -3
  35. package/dist/types/user/getUserPortfolio.d.ts +12 -2
  36. package/dist/types/user/getUserSavings.d.ts +30 -0
  37. package/dist/types/user/index.d.ts +1 -0
  38. package/dist/user/getUserPortfolio.js +16 -6
  39. package/dist/user/getUserSavings.js +35 -0
  40. package/dist/user/index.js +1 -0
  41. package/package.json +1 -1
@@ -226,6 +226,7 @@ const controllerMethods = __importStar(require("./contracts/governance/gaugeCont
226
226
  const gaugeSystemMethods = __importStar(require("./contracts/governance/gaugeSystems"));
227
227
  // ===== Curve =====
228
228
  const curveCommonMethods = __importStar(require("./contracts/curve/common"));
229
+ const yearnVaultMethods = __importStar(require("./contracts/yearn/vault"));
229
230
  const faucetMethods = __importStar(require("./contracts/faucet"));
230
231
  // ===== User aggregates (dashboard) =====
231
232
  const userMethods = __importStar(require("./user"));
@@ -427,6 +428,8 @@ class RPCLibrary {
427
428
  // prices
428
429
  // Curve pools from the chain config's `curve` section
429
430
  curve;
431
+ // Yearn V3 vaults from the chain config's `yearn` section
432
+ yearn;
430
433
  faucet;
431
434
  // Aggregate reads of one user's position and claimables, composed from the methods above
432
435
  user;
@@ -918,6 +921,9 @@ class RPCLibrary {
918
921
  this.curve = {
919
922
  common: curveCommonMethods,
920
923
  };
924
+ this.yearn = {
925
+ vault: yearnVaultMethods,
926
+ };
921
927
  this.faucet = faucetMethods;
922
928
  this.user = userMethods;
923
929
  this.prices = {
@@ -253,6 +253,14 @@
253
253
  "coins": ["pmusd", "raactoken", "leraac"]
254
254
  }
255
255
  },
256
+ "yearn": {
257
+ "spmusd": {
258
+ "id": "spmusd",
259
+ "name": "Savings pmUSD",
260
+ "contract": "0xAC7Db048FB762Dbe714aDE6D3903E6Dd992690a5",
261
+ "asset": "pmusd"
262
+ }
263
+ },
256
264
  "nfts": {
257
265
  "raacnft": {
258
266
  "id": "raacnft",
@@ -295,6 +303,13 @@
295
303
  "decimals": 18,
296
304
  "contract": "0x0D63FFffF740A0B5DbcC6C70774FDA1456195a3c"
297
305
  },
306
+ "spmusd": {
307
+ "id": "spmusd",
308
+ "name": "Savings pmUSD",
309
+ "symbol": "spmUSD",
310
+ "decimals": 18,
311
+ "contract": "0xAC7Db048FB762Dbe714aDE6D3903E6Dd992690a5"
312
+ },
298
313
  "usdc": {
299
314
  "id": "usdc",
300
315
  "name": "USDC",
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getYearnVaults = exports.PROFIT_UNLOCKING_RATE_SCALE = exports.YEARN_VAULT_ABI = void 0;
7
+ exports.aprFromUnlockingRate = aprFromUnlockingRate;
8
+ exports.resolveYearnVault = resolveYearnVault;
9
+ exports.getYearnVaultContract = getYearnVaultContract;
10
+ const ethers_1 = require("ethers");
11
+ const chains_1 = __importDefault(require("../../../configs/chains"));
12
+ /**
13
+ * The Yearn V3 vault surface (VaultV3.vy, API 3.0.x) these methods use. ERC4626 calls use the standard
14
+ * signatures: Yearn's `withdraw` defaults to a 0 max loss and `redeem` to 100%, which only matter for a vault
15
+ * with strategies.
16
+ */
17
+ exports.YEARN_VAULT_ABI = [
18
+ "function asset() view returns (address)",
19
+ "function decimals() view returns (uint8)",
20
+ "function apiVersion() view returns (string)",
21
+ "function totalAssets() view returns (uint256)",
22
+ "function totalSupply() view returns (uint256)",
23
+ "function totalIdle() view returns (uint256)",
24
+ "function totalDebt() view returns (uint256)",
25
+ "function pricePerShare() view returns (uint256)",
26
+ "function balanceOf(address) view returns (uint256)",
27
+ "function allowance(address owner, address spender) view returns (uint256)",
28
+ "function convertToAssets(uint256 shares) view returns (uint256)",
29
+ "function convertToShares(uint256 assets) view returns (uint256)",
30
+ "function previewDeposit(uint256 assets) view returns (uint256)",
31
+ "function previewMint(uint256 shares) view returns (uint256)",
32
+ "function previewWithdraw(uint256 assets) view returns (uint256)",
33
+ "function previewRedeem(uint256 shares) view returns (uint256)",
34
+ "function maxDeposit(address receiver) view returns (uint256)",
35
+ "function maxWithdraw(address owner) view returns (uint256)",
36
+ "function maxRedeem(address owner) view returns (uint256)",
37
+ "function profitMaxUnlockTime() view returns (uint256)",
38
+ "function fullProfitUnlockDate() view returns (uint256)",
39
+ "function profitUnlockingRate() view returns (uint256)",
40
+ "function lastProfitUpdate() view returns (uint256)",
41
+ "function unlockedShares() view returns (uint256)",
42
+ "function deposit_limit() view returns (uint256)",
43
+ "function isShutdown() view returns (bool)",
44
+ "function accountant() view returns (address)",
45
+ "function role_manager() view returns (address)",
46
+ "function roles(address) view returns (uint256)",
47
+ "function get_default_queue() view returns (address[])",
48
+ "function deposit(uint256 assets, address receiver) returns (uint256)",
49
+ "function mint(uint256 shares, address receiver) returns (uint256)",
50
+ "function withdraw(uint256 assets, address receiver, address owner) returns (uint256)",
51
+ "function redeem(uint256 shares, address receiver, address owner) returns (uint256)",
52
+ "function process_report(address strategy) returns (uint256, uint256)",
53
+ ];
54
+ /** `profitUnlockingRate` is shares per second scaled by this (VaultV3.vy `MAX_BPS_EXTENDED`). */
55
+ exports.PROFIT_UNLOCKING_RATE_SCALE = 10n ** 12n;
56
+ const SECONDS_PER_YEAR = 365n * 24n * 60n * 60n;
57
+ /**
58
+ * The APR the vault pays right now: the assets its locked profit releases per second, annualised, over total
59
+ * assets, as a WAD. Zero once the last reported profit has fully unlocked. It reflects the current stream only.
60
+ */
61
+ async function aprFromUnlockingRate(contract, profitUnlockingRate, fullProfitUnlockDate, totalAssets, now) {
62
+ if (fullProfitUnlockDate <= now || profitUnlockingRate === 0n || totalAssets === 0n)
63
+ return 0n;
64
+ const sharesPerYear = (profitUnlockingRate * SECONDS_PER_YEAR) / exports.PROFIT_UNLOCKING_RATE_SCALE;
65
+ const assetsPerYear = await contract.convertToAssets(sharesPerYear);
66
+ return (assetsPerYear * 10n ** 18n) / totalAssets;
67
+ }
68
+ const getYearnVaults = (chainId) => chains_1.default[chainId]?.yearn ?? {};
69
+ exports.getYearnVaults = getYearnVaults;
70
+ /** Resolves a Yearn vault by its config key (any casing) or its address. */
71
+ function resolveYearnVault(chainId, vaultAddressOrId) {
72
+ const vaults = (0, exports.getYearnVaults)(chainId);
73
+ const needle = vaultAddressOrId.toLowerCase();
74
+ const entry = vaults[needle] ?? Object.values(vaults).find((vault) => vault.contract.toLowerCase() === needle);
75
+ if (!entry)
76
+ throw new Error(`Yearn vault "${vaultAddressOrId}" not configured for chain ${chainId}`);
77
+ return entry;
78
+ }
79
+ /** The vault contract bound to `runner`, or to the chain's default RPC when none is given. */
80
+ function getYearnVaultContract(chainId, vaultAddressOrId, runner) {
81
+ const entry = resolveYearnVault(chainId, vaultAddressOrId);
82
+ if (!runner) {
83
+ runner = new ethers_1.ethers.JsonRpcProvider(chains_1.default[chainId].rpcs[0]);
84
+ }
85
+ return { entry, contract: new ethers_1.ethers.Contract(entry.contract, exports.YEARN_VAULT_ABI, runner) };
86
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deposit = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Deposits `assets` of the vault asset for shares. The signer approves the vault for the asset first
8
+ * (`wallet.assets.approveAsset(chainId, vault.asset, vault.contract, amount, signer)`).
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 shares.
14
+ * @param signer - The signer sending the transaction and paying the assets.
15
+ * @returns The mined transaction receipt.
16
+ */
17
+ const deposit = async (chainId, vaultAddressOrId, assets, receiver, 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.deposit(assets, receiver);
23
+ return await tx.wait();
24
+ }
25
+ catch (error) {
26
+ throw (0, rpcError_1.toRpcError)("yearn.deposit", error, { chainId, address: entry.contract });
27
+ }
28
+ };
29
+ exports.deposit = deposit;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getApr = void 0;
4
+ const amount_1 = require("../../../utils/amount");
5
+ const rpcError_1 = require("../../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * The APR a Yearn V3 vault pays right now, from the profit still unlocking: assets released per second,
9
+ * annualised, over total assets. It is 0 once the last report has fully unlocked, so it reflects the current
10
+ * reward stream, not a historical average.
11
+ *
12
+ * @param chainId - The chain/network to use.
13
+ * @param vaultAddressOrId - The vault's key in the chain config's `yearn` section, or its address.
14
+ * @param provider - Optional ethers.js Provider instance.
15
+ * @returns The APR as a WAD (0.05e18 = 5%).
16
+ */
17
+ const getApr = async (chainId, vaultAddressOrId, provider) => {
18
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
19
+ try {
20
+ const [profitUnlockingRate, fullProfitUnlockDate, totalAssets, block] = await Promise.all([
21
+ contract.profitUnlockingRate(),
22
+ contract.fullProfitUnlockDate(),
23
+ contract.totalAssets(),
24
+ contract.runner.provider.getBlock("latest"),
25
+ ]);
26
+ if (!block)
27
+ throw new Error("Latest block unavailable");
28
+ return (0, amount_1.toScaled)(await (0, _helpers_1.aprFromUnlockingRate)(contract, profitUnlockingRate, fullProfitUnlockDate, totalAssets, BigInt(block.timestamp)));
29
+ }
30
+ catch (error) {
31
+ throw (0, rpcError_1.toRpcError)("yearn.getApr", error, { chainId, address: entry.contract });
32
+ }
33
+ };
34
+ exports.getApr = getApr;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserInfo = getUserInfo;
4
+ const ethers_1 = require("ethers");
5
+ const amount_1 = require("../../../utils/amount");
6
+ const rpcError_1 = require("../../../utils/rpcError");
7
+ const _helpers_1 = require("./_helpers");
8
+ const ERC20_READ_ABI = [
9
+ "function balanceOf(address) view returns (uint256)",
10
+ "function allowance(address owner, address spender) view returns (uint256)",
11
+ ];
12
+ /**
13
+ * Gets a user's position in a Yearn V3 vault, plus their vault asset balance and allowance.
14
+ *
15
+ * @param chainId - The chain/network to use.
16
+ * @param vaultAddressOrId - The vault's key in the chain config's `yearn` section (e.g. "spmusd"), or its address.
17
+ * @param account - Address of the user.
18
+ * @param provider - Optional ethers.js Provider instance.
19
+ * @returns The user's shares, their asset value, balances, allowance and limits, in base units.
20
+ */
21
+ async function getUserInfo(chainId, vaultAddressOrId, account, provider) {
22
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
23
+ const asset = (value) => (0, amount_1.toTokenAmount)(chainId, entry.asset, value);
24
+ const shares = (value) => (0, amount_1.toTokenAmount)(chainId, entry.contract, value);
25
+ try {
26
+ const token = new ethers_1.ethers.Contract(await contract.asset(), ERC20_READ_ABI, contract.runner);
27
+ const [userShares, assetBalance, assetAllowance, maxDeposit, maxWithdraw, maxRedeem] = await Promise.all([
28
+ contract.balanceOf(account),
29
+ token.balanceOf(account),
30
+ token.allowance(account, entry.contract),
31
+ contract.maxDeposit(account),
32
+ contract.maxWithdraw(account),
33
+ contract.maxRedeem(account),
34
+ ]);
35
+ return {
36
+ shares: shares(userShares),
37
+ assets: asset(await contract.convertToAssets(userShares)),
38
+ assetBalance: asset(assetBalance),
39
+ assetAllowance: asset(assetAllowance),
40
+ maxDeposit: asset(maxDeposit),
41
+ maxWithdraw: asset(maxWithdraw),
42
+ maxRedeem: shares(maxRedeem),
43
+ };
44
+ }
45
+ catch (error) {
46
+ throw (0, rpcError_1.toRpcError)("yearn.getUserInfo", error, { chainId, address: entry.contract });
47
+ }
48
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVaultInfo = getVaultInfo;
4
+ const amount_1 = require("../../../utils/amount");
5
+ const rpcError_1 = require("../../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
8
+ /**
9
+ * Gets the vault-wide state of a Yearn V3 vault. For a user's position use `getUserInfo`.
10
+ *
11
+ * @param chainId - The chain/network to use.
12
+ * @param vaultAddressOrId - The vault's key in the chain config's `yearn` section (e.g. "spmusd"), or its address.
13
+ * @param provider - Optional ethers.js Provider instance.
14
+ * @returns The vault state, with amounts in base units.
15
+ */
16
+ async function getVaultInfo(chainId, vaultAddressOrId, provider) {
17
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
18
+ const asset = (value) => (0, amount_1.toTokenAmount)(chainId, entry.asset, value);
19
+ const shares = (value) => (0, amount_1.toTokenAmount)(chainId, entry.contract, value);
20
+ try {
21
+ const [assetAddress, apiVersion, totalAssets, totalSupply, totalIdle, totalDebt, pricePerShare, lockedShares, profitMaxUnlockTime, fullProfitUnlockDate, profitUnlockingRate, lastProfitUpdate, depositLimit, isShutdown, accountant, roleManager, strategies, block,] = await Promise.all([
22
+ contract.asset(),
23
+ contract.apiVersion(),
24
+ contract.totalAssets(),
25
+ contract.totalSupply(),
26
+ contract.totalIdle(),
27
+ contract.totalDebt(),
28
+ contract.pricePerShare(),
29
+ contract.balanceOf(entry.contract),
30
+ contract.profitMaxUnlockTime(),
31
+ contract.fullProfitUnlockDate(),
32
+ contract.profitUnlockingRate(),
33
+ contract.lastProfitUpdate(),
34
+ contract.deposit_limit(),
35
+ contract.isShutdown(),
36
+ contract.accountant(),
37
+ contract.role_manager(),
38
+ contract.get_default_queue(),
39
+ contract.runner.provider.getBlock("latest"),
40
+ ]);
41
+ if (!block)
42
+ throw new Error("Latest block unavailable");
43
+ const [lockedProfit, apr] = await Promise.all([
44
+ contract.convertToAssets(lockedShares),
45
+ (0, _helpers_1.aprFromUnlockingRate)(contract, profitUnlockingRate, fullProfitUnlockDate, totalAssets, BigInt(block.timestamp)),
46
+ ]);
47
+ return {
48
+ ...entry,
49
+ assetAddress,
50
+ apiVersion,
51
+ totalAssets: asset(totalAssets),
52
+ totalSupply: shares(totalSupply),
53
+ totalIdle: asset(totalIdle),
54
+ totalDebt: asset(totalDebt),
55
+ pricePerShare: (0, amount_1.toScaled)(pricePerShare, (0, amount_1.getAssetDecimals)(chainId, entry.asset)),
56
+ apr: (0, amount_1.toScaled)(apr),
57
+ lockedProfit: asset(lockedProfit),
58
+ profitMaxUnlockTime: Number(profitMaxUnlockTime),
59
+ fullProfitUnlockDate: Number(fullProfitUnlockDate),
60
+ lastProfitUpdate: Number(lastProfitUpdate),
61
+ depositLimit: asset(depositLimit),
62
+ isShutdown,
63
+ accountant: accountant === ZERO_ADDRESS ? null : accountant,
64
+ roleManager,
65
+ strategies: [...strategies],
66
+ };
67
+ }
68
+ catch (error) {
69
+ throw (0, rpcError_1.toRpcError)("yearn.getVaultInfo", error, { chainId, address: entry.contract });
70
+ }
71
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVault = exports.getVaults = void 0;
4
+ const _helpers_1 = require("./_helpers");
5
+ /**
6
+ * Lists the Yearn V3 vaults in the chain config. Reads the config only; no RPC call is made.
7
+ *
8
+ * @param chainId - The chain/network to use.
9
+ * @returns Every configured vault; empty when the chain has none.
10
+ */
11
+ const getVaults = (chainId) => Object.values((0, _helpers_1.getYearnVaults)(chainId));
12
+ exports.getVaults = getVaults;
13
+ /**
14
+ * Looks up one Yearn V3 vault in the chain config. Reads the config only; no RPC call is made.
15
+ *
16
+ * @param chainId - The chain/network to use.
17
+ * @param vaultAddressOrId - The vault's config key or its address.
18
+ * @returns The vault entry.
19
+ * @throws If the vault is not configured on the chain.
20
+ */
21
+ const getVault = (chainId, vaultAddressOrId) => (0, _helpers_1.resolveYearnVault)(chainId, vaultAddressOrId);
22
+ exports.getVault = getVault;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./deposit"), exports);
18
+ __exportStar(require("./getApr"), exports);
19
+ __exportStar(require("./getUserInfo"), exports);
20
+ __exportStar(require("./getVaultInfo"), exports);
21
+ __exportStar(require("./getVaults"), exports);
22
+ __exportStar(require("./mint"), exports);
23
+ __exportStar(require("./previewDeposit"), exports);
24
+ __exportStar(require("./previewMint"), exports);
25
+ __exportStar(require("./previewRedeem"), exports);
26
+ __exportStar(require("./previewWithdraw"), exports);
27
+ __exportStar(require("./processReport"), exports);
28
+ __exportStar(require("./redeem"), exports);
29
+ __exportStar(require("./withdraw"), exports);
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mint = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Mints exactly `shares`, pulling the assets they cost (see `previewMint`). The signer approves the vault for the
8
+ * asset first.
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 shares.
14
+ * @param signer - The signer sending the transaction and paying the assets.
15
+ * @returns The mined transaction receipt.
16
+ */
17
+ const mint = async (chainId, vaultAddressOrId, shares, receiver, 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.mint(shares, receiver);
23
+ return await tx.wait();
24
+ }
25
+ catch (error) {
26
+ throw (0, rpcError_1.toRpcError)("yearn.mint", error, { chainId, address: entry.contract });
27
+ }
28
+ };
29
+ exports.mint = mint;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.previewDeposit = void 0;
4
+ const amount_1 = require("../../../utils/amount");
5
+ const rpcError_1 = require("../../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Shares a deposit of `assets` would mint now.
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 provider - Optional ethers.js Provider instance.
14
+ * @returns The shares, in base units.
15
+ */
16
+ const previewDeposit = async (chainId, vaultAddressOrId, assets, provider) => {
17
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
18
+ try {
19
+ return (0, amount_1.toTokenAmount)(chainId, entry.contract, await contract.previewDeposit(assets));
20
+ }
21
+ catch (error) {
22
+ throw (0, rpcError_1.toRpcError)("yearn.previewDeposit", error, { chainId, address: entry.contract });
23
+ }
24
+ };
25
+ exports.previewDeposit = previewDeposit;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.previewMint = void 0;
4
+ const amount_1 = require("../../../utils/amount");
5
+ const rpcError_1 = require("../../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Assets a mint of `shares` would pull now.
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 provider - Optional ethers.js Provider instance.
14
+ * @returns The vault asset amount, in its base units.
15
+ */
16
+ const previewMint = async (chainId, vaultAddressOrId, shares, provider) => {
17
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
18
+ try {
19
+ return (0, amount_1.toTokenAmount)(chainId, entry.asset, await contract.previewMint(shares));
20
+ }
21
+ catch (error) {
22
+ throw (0, rpcError_1.toRpcError)("yearn.previewMint", error, { chainId, address: entry.contract });
23
+ }
24
+ };
25
+ exports.previewMint = previewMint;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.previewRedeem = void 0;
4
+ const amount_1 = require("../../../utils/amount");
5
+ const rpcError_1 = require("../../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Assets a redemption of `shares` would pay out now.
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 provider - Optional ethers.js Provider instance.
14
+ * @returns The vault asset amount, in its base units.
15
+ */
16
+ const previewRedeem = async (chainId, vaultAddressOrId, shares, provider) => {
17
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
18
+ try {
19
+ return (0, amount_1.toTokenAmount)(chainId, entry.asset, await contract.previewRedeem(shares));
20
+ }
21
+ catch (error) {
22
+ throw (0, rpcError_1.toRpcError)("yearn.previewRedeem", error, { chainId, address: entry.contract });
23
+ }
24
+ };
25
+ exports.previewRedeem = previewRedeem;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.previewWithdraw = void 0;
4
+ const amount_1 = require("../../../utils/amount");
5
+ const rpcError_1 = require("../../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Shares a withdrawal of `assets` would burn now.
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 provider - Optional ethers.js Provider instance.
14
+ * @returns The shares, in base units.
15
+ */
16
+ const previewWithdraw = async (chainId, vaultAddressOrId, assets, provider) => {
17
+ const { entry, contract } = (0, _helpers_1.getYearnVaultContract)(chainId, vaultAddressOrId, provider);
18
+ try {
19
+ return (0, amount_1.toTokenAmount)(chainId, entry.contract, await contract.previewWithdraw(assets));
20
+ }
21
+ catch (error) {
22
+ throw (0, rpcError_1.toRpcError)("yearn.previewWithdraw", error, { chainId, address: entry.contract });
23
+ }
24
+ };
25
+ exports.previewWithdraw = previewWithdraw;
@@ -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,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";
@@ -14,13 +14,14 @@ const getUserDebt_1 = require("./getUserDebt");
14
14
  const getUserWalletBalances_1 = require("./getUserWalletBalances");
15
15
  const getUserFarming_1 = require("./getUserFarming");
16
16
  const getUserGovernance_1 = require("./getUserGovernance");
17
+ const getUserSavings_1 = require("./getUserSavings");
17
18
  const _helpers_1 = require("./_helpers");
18
19
  const unavailable = (what, sections) => {
19
20
  const failed = sections.filter((section) => section.error);
20
21
  return failed.length ? new Error(`${what} needs data that could not be read: ${failed.map((section) => section.error.message).join("; ")}`) : null;
21
22
  };
22
23
  /** Builds the effective return legs from the reads. Each unit of capital earns each yield once. */
23
- function buildLegs(debt, rates, wallet, farming) {
24
+ function buildLegs(debt, rates, wallet, farming, savings) {
24
25
  const legs = [];
25
26
  if (debt.valueUsd > 0) {
26
27
  legs.push({ id: "borrow", source: "Borrow pmUSD", kind: "cost", yieldType: "borrow", countsAsCapital: false, valueUsd: debt.valueUsd, rate: (0, amount_1.toNumber)(rates.borrowApy), rateKind: "apy" });
@@ -37,12 +38,16 @@ function buildLegs(debt, rates, wallet, farming) {
37
38
  continue;
38
39
  legs.push({ id: `gauge:${gauge.id}`, source: gauge.name, kind: "earning", yieldType: "gauge", countsAsCapital: false, valueUsd: gauge.valueUsd, rate: gauge.apr ?? 0, rateKind: "apr" });
39
40
  }
41
+ // Savings shares are pmUSD the user holds, so they count as capital; the rate is the vault's current reward stream.
42
+ for (const vault of savings.vaults) {
43
+ legs.push({ id: `savings:${vault.id}`, source: vault.name, kind: "earning", yieldType: "savings", countsAsCapital: true, valueUsd: vault.valueUsd, rate: (0, amount_1.toNumber)(vault.apr), rateKind: "apr" });
44
+ }
40
45
  const idleUsd = wallet.idleUsd + coins.filter((coin) => coin.yield === "none").reduce((sum, coin) => sum + coin.valueUsd, 0);
41
46
  return { legs, idleUsd };
42
47
  }
43
48
  /**
44
49
  * The user's position across the app: iREET collateral, debt and health factor, wallet RpmUSD/DEpmUSD/pmUSD, LP and
45
- * gauge positions, veRAAC governance power, and the projected effective return built from them. Each part is read
50
+ * gauge positions, savings vault positions, veRAAC governance power, and the projected effective return built from them. Each part is read
46
51
  * independently, so one failing read shows as an `error` on that part and the rest still return.
47
52
  *
48
53
  * Only the user's position data is returned; pool parameters such as the liquidation threshold stay with the callers
@@ -51,7 +56,7 @@ function buildLegs(debt, rates, wallet, farming) {
51
56
  * @param chainId - The chain/network to use.
52
57
  * @param user - The user's address.
53
58
  * @param prices - USD per whole token, keyed by lowercase symbol. iREET, pmUSD, RpmUSD, DEpmUSD and RAAC are needed,
54
- * plus every coin of a Curve pool the user holds.
59
+ * plus every coin of a Curve pool the user holds. Savings positions are valued at their asset's price (pmUSD).
55
60
  * @param provider - Optional ethers.js Provider instance. Read-only is enough.
56
61
  * @returns Each part as `{ data, error }`, the effective return legs, and the computed effective return.
57
62
  */
@@ -63,7 +68,7 @@ const getUserPortfolio = async (chainId, user, prices, provider) => {
63
68
  const rpc = chains_1.default[chainId].rpcs[0];
64
69
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
65
70
  }
66
- const [collateral, debt, rates, wallet, farming, governance] = await Promise.all([
71
+ const [collateral, debt, rates, wallet, farming, governance, savings] = await Promise.all([
67
72
  (0, _helpers_1.settled)((0, getUserCollateral_1.getUserCollateral)(chainId, user, provider).then((amount) => ({ amount, valueUsd: (0, _helpers_1.requireUsd)(prices, amount, "rwaindextoken") }))),
68
73
  (0, _helpers_1.settled)((0, getUserDebt_1.getUserDebt)(chainId, user, provider).then((debt) => ({ ...debt, valueUsd: (0, _helpers_1.requireUsd)(prices, debt.amount, chains_1.default[chainId].pools.lendingpool.asset ?? "debt") }))),
69
74
  (0, _helpers_1.settled)((0, getLendingPoolInfo_1.default)(chainId, undefined, provider).then(({ borrowRate, borrowApy, supplyApy }) => ({ borrowRate, borrowApy, supplyApy }))),
@@ -74,6 +79,10 @@ const getUserPortfolio = async (chainId, user, prices, provider) => {
74
79
  }))),
75
80
  (0, _helpers_1.settled)((0, getUserFarming_1.getUserFarming)(chainId, user, prices, provider)),
76
81
  (0, _helpers_1.settled)((0, getUserGovernance_1.getUserGovernance)(chainId, user, provider)),
82
+ (0, _helpers_1.settled)((0, getUserSavings_1.getUserSavings)(chainId, user, provider).then((read) => {
83
+ const vaults = read.vaults.map((vault) => ({ ...vault, valueUsd: (0, _helpers_1.requireUsd)(prices, vault.assets, vault.id) }));
84
+ return { vaults, valueUsd: vaults.reduce((sum, vault) => sum + vault.valueUsd, 0) };
85
+ })),
77
86
  ]);
78
87
  const netPositionError = unavailable("Net RAACLend position", [collateral, debt, wallet]);
79
88
  const netPositionUsd = netPositionError
@@ -83,12 +92,12 @@ const getUserPortfolio = async (chainId, user, prices, provider) => {
83
92
  const farmingErrors = (farming.data?.errors ?? []).map(({ pool, error }) => ({ data: null, error: new Error(`Curve pool ${pool}: ${error.message}`) }));
84
93
  let legs = [];
85
94
  let effectiveReturn;
86
- const returnError = unavailable("Effective return", [collateral, debt, rates, wallet, farming, ...farmingErrors]);
95
+ const returnError = unavailable("Effective return", [collateral, debt, rates, wallet, farming, savings, ...farmingErrors]);
87
96
  if (returnError) {
88
97
  effectiveReturn = { data: null, error: returnError };
89
98
  }
90
99
  else {
91
- const built = buildLegs(debt.data, rates.data, wallet.data, farming.data);
100
+ const built = buildLegs(debt.data, rates.data, wallet.data, farming.data, savings.data);
92
101
  legs = built.legs;
93
102
  effectiveReturn = { data: (0, computeEffectiveReturn_1.computeEffectiveReturn)({ legs, collateralUsd: collateral.data.valueUsd, idleUsd: built.idleUsd }), error: null };
94
103
  }
@@ -101,6 +110,7 @@ const getUserPortfolio = async (chainId, user, prices, provider) => {
101
110
  wallet,
102
111
  farming,
103
112
  governance,
113
+ savings,
104
114
  netPositionUsd,
105
115
  legs,
106
116
  effectiveReturn,
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getUserSavings = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const chains_1 = __importDefault(require("../configs/chains"));
9
+ const getApr_1 = require("../contracts/yearn/vault/getApr");
10
+ const getUserInfo_1 = require("../contracts/yearn/vault/getUserInfo");
11
+ const getVaults_1 = require("../contracts/yearn/vault/getVaults");
12
+ /**
13
+ * The user's positions in the chain's savings vaults (the Yearn V3 vaults in the chain config, e.g. spmUSD). Vaults
14
+ * the user holds nothing in are left out; a chain without savings vaults returns none.
15
+ *
16
+ * @param chainId - The chain/network to use.
17
+ * @param user - The user's address.
18
+ * @param provider - Optional ethers.js Provider instance.
19
+ * @returns The vaults the user holds, with what the shares are worth and the vault's current APR.
20
+ */
21
+ const getUserSavings = async (chainId, user, provider) => {
22
+ if (!provider) {
23
+ const rpc = chains_1.default[chainId].rpcs[0];
24
+ provider = new ethers_1.ethers.JsonRpcProvider(rpc);
25
+ }
26
+ const held = await Promise.all((0, getVaults_1.getVaults)(chainId).map(async (entry) => {
27
+ const info = await (0, getUserInfo_1.getUserInfo)(chainId, entry.contract, user, provider);
28
+ if (info.shares.value === 0n)
29
+ return null;
30
+ const apr = await (0, getApr_1.getApr)(chainId, entry.contract, provider);
31
+ return { id: entry.id, name: entry.name, vault: entry.contract, shares: info.shares, assets: info.assets, apr };
32
+ }));
33
+ return { vaults: held.filter((vault) => vault !== null) };
34
+ };
35
+ exports.getUserSavings = getUserSavings;
@@ -21,4 +21,5 @@ __exportStar(require("./getUserDebt"), exports);
21
21
  __exportStar(require("./getUserFarming"), exports);
22
22
  __exportStar(require("./getUserGovernance"), exports);
23
23
  __exportStar(require("./getUserPortfolio"), exports);
24
+ __exportStar(require("./getUserSavings"), exports);
24
25
  __exportStar(require("./getUserWalletBalances"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raac/rpc",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.17",
4
4
  "description": "RPC Library for RAAC",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",