@raac/rpc 2.0.0-beta.21 → 2.0.0-beta.23

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.
@@ -133,6 +133,7 @@
133
133
  "psm": {
134
134
  "rpsm-susds": {
135
135
  "id": "rpsm-sUSDS",
136
+ "version": "1.0.0",
136
137
  "name": "RAAC Peg Stability Module sUSDS",
137
138
  "contract": "0xB2102B4d8802648EC6A9e89ACD46b4B799833469",
138
139
  "rateProvider": "0x9a6b5BDA2128e6341175c79E43Cd2A7E0C5F5b21"
@@ -188,9 +188,10 @@
188
188
  "psm": {
189
189
  "rpsm-susds": {
190
190
  "id": "rpsm-sUSDS",
191
+ "version": "1.0.0",
191
192
  "name": "RAAC Peg Stability Module sUSDS",
192
- "contract": "0xbcA54A6E7BeD62Ad3aA5660c0e51FeA1F6A47289",
193
- "rateProvider": "0xB3b47F65dFeca20991148BAfe8dc34e1aDb6939b"
193
+ "contract": "0x1c7Dfbc9bea1d8b6eb33ce8C715dC5313DC3d8B8",
194
+ "rateProvider": "0xC0508Cf612C507E22E75C89501E7A1F64D634bd9"
194
195
  }
195
196
  },
196
197
  "pools": {
@@ -317,6 +318,20 @@
317
318
  "decimals": 6,
318
319
  "contract": "0xBBfc1B017954e2F65378b189735dd7be279AbC2A"
319
320
  },
321
+ "usds": {
322
+ "id": "usds",
323
+ "name": "USDS",
324
+ "symbol": "USDS",
325
+ "decimals": 18,
326
+ "contract": "0x169e984ec1F8111fA0fe570dD2630621688e82F4"
327
+ },
328
+ "susds": {
329
+ "id": "susds",
330
+ "name": "Savings USDS",
331
+ "symbol": "sUSDS",
332
+ "decimals": 18,
333
+ "contract": "0xAADD480013475e416cAC2F511697060c920bEE67"
334
+ },
320
335
  "rtoken": {
321
336
  "id": "rtoken",
322
337
  "name": "RToken",
@@ -13,8 +13,7 @@ const _tokens_1 = require("./_tokens");
13
13
  const RAW_BALANCE_OF_ABI = ["function rawBalanceOf(address account) view returns (uint256)"];
14
14
  const tokenState = async (chainId, token, user, spender, provider) => {
15
15
  const contract = new ethers_1.ethers.Contract(token, _tokens_1.ERC20_ABI, provider);
16
- const [balance, allowance, { decimals, symbol }] = await Promise.all([
17
- contract.balanceOf(user),
16
+ const [allowance, { decimals, symbol }] = await Promise.all([
18
17
  contract.allowance(user, spender),
19
18
  (0, resolveTokenInfo_1.resolveTokenInfo)(chainId, token, provider),
20
19
  ]);
@@ -22,14 +21,14 @@ const tokenState = async (chainId, token, user, spender, provider) => {
22
21
  address: ethers_1.ethers.getAddress(token),
23
22
  symbol,
24
23
  decimals,
25
- balance: (0, amount_1.toAmount)(balance, decimals, symbol),
26
24
  allowance: (0, amount_1.toAmount)(allowance, decimals, symbol),
27
25
  spender: ethers_1.ethers.getAddress(spender),
28
26
  };
29
27
  };
30
28
  /**
31
- * What a wallet needs to stake in, wrap for, or unstake from a gauge: its stake, its balance of the staking token and its
32
- * allowance to the gauge, and for a wrapped gauge its balance of the underlying and allowance to the wrapper.
29
+ * What a wallet needs to stake in, wrap for, or unstake from a gauge: its stake, its allowance of the staking token to the
30
+ * gauge, and for a wrapped gauge its allowance of the underlying to the wrapper. Read the wallet's token balances with
31
+ * `wallet.assets.getBalance`.
33
32
  *
34
33
  * @param chainId - The chain/network to use.
35
34
  * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
@@ -4,7 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.resolvePsmVault = resolvePsmVault;
7
+ exports.getPsmVaultMajor = getPsmVaultMajor;
7
8
  exports.getPsmVaultContract = getPsmVaultContract;
9
+ exports.getPairingToken = getPairingToken;
10
+ exports.getPairingTokenDecimals = getPairingTokenDecimals;
8
11
  exports.getPsmRateProviderContract = getPsmRateProviderContract;
9
12
  exports.getDefaultProvider = getDefaultProvider;
10
13
  exports.getTokenReaderContract = getTokenReaderContract;
@@ -29,11 +32,38 @@ function resolvePsmVault(chainId, vaultKeyOrAddress) {
29
32
  throw new Error(`PSM vault "${vaultKeyOrAddress}" not configured for chain ${chainId}`);
30
33
  return { key, entry: psm[key] };
31
34
  }
35
+ /** The first PSMVault major that calls the pairing token `pairingToken` instead of `savingsToken`. */
36
+ const PAIRING_TOKEN_RENAME_MAJOR = 3;
37
+ /**
38
+ * Major version of the vault's implementation, from the config entry's `version`.
39
+ * @throws When the version is missing, malformed, or has no ABI in this library.
40
+ */
41
+ function getPsmVaultMajor(entry) {
42
+ const major = Number(entry.version?.split(".")[0]);
43
+ if (!Number.isInteger(major) || !(major in artifacts_1.PSM_VAULT_ABIS)) {
44
+ throw new Error(`PSM vault ${entry.contract} has unsupported version "${entry.version}"`);
45
+ }
46
+ return major;
47
+ }
48
+ /**
49
+ * The vault contract with the ABI of its configured version. Typed as the V1 surface, which every version shares
50
+ * except the pairing token getters; read those through `getPairingToken` and `getPairingTokenDecimals`.
51
+ */
32
52
  function getPsmVaultContract(chainId, vaultKeyOrAddress, providerOrSigner) {
33
- const { key, entry } = resolvePsmVault(chainId, vaultKeyOrAddress);
34
- const abi = (0, artifacts_1.getABI)(key);
53
+ const { entry } = resolvePsmVault(chainId, vaultKeyOrAddress);
54
+ const abi = artifacts_1.PSM_VAULT_ABIS[getPsmVaultMajor(entry)];
35
55
  return new ethers_1.ethers.Contract(entry.contract, abi, providerOrSigner);
36
56
  }
57
+ /** The vault's pairing token address: `pairingToken()` from V3 on, `savingsToken()` before. */
58
+ function getPairingToken(vault, major) {
59
+ return major >= PAIRING_TOKEN_RENAME_MAJOR ? vault.pairingToken() : vault.savingsToken();
60
+ }
61
+ /** The vault's cached pairing token decimals: `pairingTokenDecimals()` from V3 on, `savingsTokenDecimals()` before. */
62
+ function getPairingTokenDecimals(vault, major) {
63
+ return major >= PAIRING_TOKEN_RENAME_MAJOR
64
+ ? vault.pairingTokenDecimals()
65
+ : vault.savingsTokenDecimals();
66
+ }
37
67
  function getPsmRateProviderContract(chainId, vaultKeyOrAddress, providerOrSigner) {
38
68
  const { entry } = resolvePsmVault(chainId, vaultKeyOrAddress);
39
69
  const abi = (0, artifacts_1.getABI)("rateprovider");
@@ -19,6 +19,7 @@ async function getVaultInfo(chainId, vaultKeyOrAddress, userAddress, provider) {
19
19
  const contractAddress = entry.contract;
20
20
  try {
21
21
  const vault = (0, _helpers_1.getPsmVaultContract)(chainId, vaultKeyOrAddress, provider);
22
+ const major = (0, _helpers_1.getPsmVaultMajor)(entry);
22
23
  const [totalAssets, totalSupply, vaultDecimals, depositCap, swapFee, computeWithdrawFee, withdrawTime, withdrawTimeLimit, dripRate, dripEnd, pendingRewards, vaultComposition, minWithdrawFee, maxWithdrawFee, rebalancer, baseAssetModule, reserveRatioFloor, rebalanceThreshold, dripDuration, paused, circuitBreakerEnabled, navFloor, savingsToken, baseAsset,] = await Promise.all([
23
24
  vault.totalAssets(),
24
25
  vault.totalSupply(),
@@ -42,7 +43,7 @@ async function getVaultInfo(chainId, vaultKeyOrAddress, userAddress, provider) {
42
43
  vault.paused(),
43
44
  vault.circuitBreakerEnabled(),
44
45
  vault.navFloor(),
45
- vault.savingsToken(),
46
+ (0, _helpers_1.getPairingToken)(vault, major),
46
47
  vault.asset(),
47
48
  ]);
48
49
  const savingsTokenContract = (0, _helpers_1.getTokenReaderContract)(savingsToken, provider);
@@ -65,14 +66,12 @@ async function getVaultInfo(chainId, vaultKeyOrAddress, userAddress, provider) {
65
66
  let user = null;
66
67
  if (userAddress) {
67
68
  const baseAssetContract = (0, _helpers_1.getTokenReaderContract)(baseAsset, provider);
68
- const [shareBalance, redeemRequest, savingsTokenAllowance, baseAssetAllowance] = await Promise.all([
69
- vault.balanceOf(userAddress),
69
+ const [redeemRequest, savingsTokenAllowance, baseAssetAllowance] = await Promise.all([
70
70
  vault.redeemRequests(userAddress),
71
71
  savingsTokenContract.allowance(userAddress, contractAddress),
72
72
  baseAssetContract.allowance(userAddress, contractAddress),
73
73
  ]);
74
74
  user = {
75
- shareBalance: (0, amount_1.toAmount)(shareBalance, Number(vaultDecimals), entry.id),
76
75
  redeemRequest: {
77
76
  shares: (0, amount_1.toAmount)(redeemRequest[0], Number(vaultDecimals), entry.id),
78
77
  exitTime: Number(redeemRequest[1]),
@@ -82,6 +81,7 @@ async function getVaultInfo(chainId, vaultKeyOrAddress, userAddress, provider) {
82
81
  };
83
82
  }
84
83
  return {
84
+ version: entry.version,
85
85
  totalAssets: (0, amount_1.toTokenAmount)(chainId, "pmusd", totalAssets),
86
86
  totalSupply: (0, amount_1.toAmount)(totalSupply, Number(vaultDecimals), entry.id),
87
87
  depositCap: (0, amount_1.toTokenAmount)(chainId, "susds", depositCap),
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVaultSettings = getVaultSettings;
4
+ const ethers_1 = require("ethers");
4
5
  const _helpers_1 = require("./_helpers");
5
6
  const rpcError_1 = require("../../utils/rpcError");
7
+ const EIP1967_ADMIN_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
6
8
  /**
7
9
  * Reads a PSM vault's settings from its storage getters only. Unlike `getVaultInfo`, nothing here touches the rate
8
10
  * provider, so it still answers when the savings token price is stale (`StalePrice`), which is when an operator
@@ -14,8 +16,10 @@ const rpcError_1 = require("../../utils/rpcError");
14
16
  async function getVaultSettings(chainId, vaultKeyOrAddress, provider) {
15
17
  const { entry } = (0, _helpers_1.resolvePsmVault)(chainId, vaultKeyOrAddress);
16
18
  try {
17
- const vault = (0, _helpers_1.getPsmVaultContract)(chainId, vaultKeyOrAddress, provider ?? (0, _helpers_1.getDefaultProvider)(chainId));
18
- const [paused, swapFee, minWithdrawFee, maxWithdrawFee, withdrawTime, withdrawTimeLimit, circuitBreakerEnabled, navFloor, reserveRatioFloor, rebalanceThreshold, depositCap, savingsTokenDecimals, baseAsset, savingsToken, rateProvider, rebalancer, baseAssetModule,] = await Promise.all([
19
+ const reader = provider ?? (0, _helpers_1.getDefaultProvider)(chainId);
20
+ const vault = (0, _helpers_1.getPsmVaultContract)(chainId, vaultKeyOrAddress, reader);
21
+ const major = (0, _helpers_1.getPsmVaultMajor)(entry);
22
+ const [paused, swapFee, minWithdrawFee, maxWithdrawFee, withdrawTime, withdrawTimeLimit, circuitBreakerEnabled, navFloor, reserveRatioFloor, rebalanceThreshold, depositCap, savingsTokenDecimals, baseAsset, savingsToken, rateProvider, rebalancer, baseAssetModule, adminSlot,] = await Promise.all([
19
23
  vault.paused(),
20
24
  vault.swapFee(),
21
25
  vault.minWithdrawFee(),
@@ -27,14 +31,19 @@ async function getVaultSettings(chainId, vaultKeyOrAddress, provider) {
27
31
  vault.reserveRatioFloor(),
28
32
  vault.rebalanceThreshold(),
29
33
  vault.depositCap(),
30
- vault.savingsTokenDecimals(),
34
+ (0, _helpers_1.getPairingTokenDecimals)(vault, major),
31
35
  vault.baseAsset(),
32
- vault.savingsToken(),
36
+ (0, _helpers_1.getPairingToken)(vault, major),
33
37
  vault.rateProvider(),
34
38
  vault.rebalancer(),
35
39
  vault.baseAssetModule(),
40
+ reader.getStorage(entry.contract, EIP1967_ADMIN_SLOT),
36
41
  ]);
42
+ const admin = ethers_1.ethers.getAddress(ethers_1.ethers.dataSlice(adminSlot, 12));
43
+ const proxyAdmin = admin === ethers_1.ethers.ZeroAddress ? null : admin;
44
+ const proxyAdminOwner = proxyAdmin && (await new ethers_1.ethers.Contract(proxyAdmin, ["function owner() view returns (address)"], reader).owner());
37
45
  return {
46
+ version: entry.version,
38
47
  paused,
39
48
  swapFee,
40
49
  minWithdrawFee,
@@ -52,6 +61,8 @@ async function getVaultSettings(chainId, vaultKeyOrAddress, provider) {
52
61
  rateProvider,
53
62
  rebalancer,
54
63
  baseAssetModule,
64
+ proxyAdmin,
65
+ proxyAdminOwner,
55
66
  };
56
67
  }
57
68
  catch (error) {