@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
|
@@ -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;
|
package/dist/user/index.js
CHANGED
|
@@ -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);
|