@raac/rpc 2.0.0-beta.15 → 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.
- package/dist/RPCLibrary.js +9 -0
- package/dist/configs/chains/11155111.json +15 -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/nfts/getPriceStaleness.js +51 -0
- package/dist/types/RPCLibrary.d.ts +7 -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/nfts/getPriceStaleness.d.ts +22 -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
package/dist/RPCLibrary.js
CHANGED
|
@@ -158,6 +158,7 @@ const getRawUserDepositsInStabilityPool_1 = __importDefault(require("./pools/sta
|
|
|
158
158
|
const getEligibleUserDeposits_1 = __importDefault(require("./pools/lendingPool/getEligibleUserDeposits"));
|
|
159
159
|
const getMintPrice_1 = __importDefault(require("./nfts/getMintPrice"));
|
|
160
160
|
const getMintFeePercentage_1 = __importDefault(require("./nfts/getMintFeePercentage"));
|
|
161
|
+
const getPriceStaleness_1 = __importStar(require("./nfts/getPriceStaleness"));
|
|
161
162
|
const getAllTokens_1 = __importDefault(require("./nfts/getAllTokens"));
|
|
162
163
|
const totalNFTSupply_1 = __importDefault(require("./nfts/totalNFTSupply"));
|
|
163
164
|
const getTokenURI_1 = __importDefault(require("./nfts/getTokenURI"));
|
|
@@ -225,6 +226,7 @@ const controllerMethods = __importStar(require("./contracts/governance/gaugeCont
|
|
|
225
226
|
const gaugeSystemMethods = __importStar(require("./contracts/governance/gaugeSystems"));
|
|
226
227
|
// ===== Curve =====
|
|
227
228
|
const curveCommonMethods = __importStar(require("./contracts/curve/common"));
|
|
229
|
+
const yearnVaultMethods = __importStar(require("./contracts/yearn/vault"));
|
|
228
230
|
const faucetMethods = __importStar(require("./contracts/faucet"));
|
|
229
231
|
// ===== User aggregates (dashboard) =====
|
|
230
232
|
const userMethods = __importStar(require("./user"));
|
|
@@ -426,6 +428,8 @@ class RPCLibrary {
|
|
|
426
428
|
// prices
|
|
427
429
|
// Curve pools from the chain config's `curve` section
|
|
428
430
|
curve;
|
|
431
|
+
// Yearn V3 vaults from the chain config's `yearn` section
|
|
432
|
+
yearn;
|
|
429
433
|
faucet;
|
|
430
434
|
// Aggregate reads of one user's position and claimables, composed from the methods above
|
|
431
435
|
user;
|
|
@@ -497,6 +501,8 @@ class RPCLibrary {
|
|
|
497
501
|
totalSupply: totalNFTSupply_1.default,
|
|
498
502
|
getMintPrice: getMintPrice_1.default,
|
|
499
503
|
getMintFeePercentage: getMintFeePercentage_1.default,
|
|
504
|
+
getPriceStalenessThreshold: getPriceStaleness_1.default,
|
|
505
|
+
isHousePriceStale: getPriceStaleness_1.isHousePriceStale,
|
|
500
506
|
getAllTokens: getAllTokens_1.default,
|
|
501
507
|
getTokenURI: getTokenURI_1.default,
|
|
502
508
|
getTotalPropertiesCount: getTotalPropertiesCount_1.default,
|
|
@@ -915,6 +921,9 @@ class RPCLibrary {
|
|
|
915
921
|
this.curve = {
|
|
916
922
|
common: curveCommonMethods,
|
|
917
923
|
};
|
|
924
|
+
this.yearn = {
|
|
925
|
+
vault: yearnVaultMethods,
|
|
926
|
+
};
|
|
918
927
|
this.faucet = faucetMethods;
|
|
919
928
|
this.user = userMethods;
|
|
920
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;
|