@raac/rpc 2.0.0-beta.12 → 2.0.0-beta.14

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 (52) hide show
  1. package/dist/RPCLibrary.js +53 -8
  2. package/dist/configs/chains/11155111.json +13 -0
  3. package/dist/contracts/complianceRegistry/getStatuses.js +40 -0
  4. package/dist/contracts/crvUSDToUSDOracle/getState.js +58 -0
  5. package/dist/contracts/curve/common/_helpers.js +57 -0
  6. package/dist/contracts/curve/common/addLiquidity.js +30 -0
  7. package/dist/contracts/curve/common/calcTokenAmount.js +23 -0
  8. package/dist/contracts/curve/common/calcWithdrawOneCoin.js +21 -0
  9. package/dist/contracts/curve/common/exchange.js +33 -0
  10. package/dist/contracts/curve/common/getDy.js +22 -0
  11. package/dist/contracts/curve/common/index.js +7 -0
  12. package/dist/contracts/curve/common/removeLiquidity.js +30 -0
  13. package/dist/contracts/curve/common/removeLiquidityOneCoin.js +31 -0
  14. package/dist/contracts/faucet/claim.js +37 -0
  15. package/dist/contracts/faucet/index.js +17 -0
  16. package/dist/contracts/feeCollector/getState.js +100 -0
  17. package/dist/contracts/getRoles.js +35 -0
  18. package/dist/contracts/housePrices/getState.js +41 -0
  19. package/dist/contracts/psm/getVaultSettings.js +60 -0
  20. package/dist/contracts/treasury/getState.js +46 -0
  21. package/dist/minter/emissionSchedule.js +90 -0
  22. package/dist/pools/lendingPool/getAdminState.js +47 -0
  23. package/dist/pools/rwaVault/getRegisteredAdapters.js +78 -0
  24. package/dist/pools/rwaVault/getSeedStatus.js +45 -0
  25. package/dist/pools/stabilityPool/getAdminState.js +42 -0
  26. package/dist/pools/stabilityPool/liquidation.js +297 -0
  27. package/dist/types/RPCLibrary.d.ts +44 -0
  28. package/dist/types/contracts/complianceRegistry/getStatuses.d.ts +25 -0
  29. package/dist/types/contracts/crvUSDToUSDOracle/getState.d.ts +36 -0
  30. package/dist/types/contracts/curve/common/_helpers.d.ts +10 -1
  31. package/dist/types/contracts/curve/common/addLiquidity.d.ts +14 -0
  32. package/dist/types/contracts/curve/common/calcTokenAmount.d.ts +10 -0
  33. package/dist/types/contracts/curve/common/calcWithdrawOneCoin.d.ts +8 -0
  34. package/dist/types/contracts/curve/common/exchange.d.ts +16 -0
  35. package/dist/types/contracts/curve/common/getDy.d.ts +8 -0
  36. package/dist/types/contracts/curve/common/index.d.ts +7 -0
  37. package/dist/types/contracts/curve/common/removeLiquidity.d.ts +14 -0
  38. package/dist/types/contracts/curve/common/removeLiquidityOneCoin.d.ts +15 -0
  39. package/dist/types/contracts/faucet/claim.d.ts +18 -0
  40. package/dist/types/contracts/faucet/index.d.ts +1 -0
  41. package/dist/types/contracts/feeCollector/getState.d.ts +42 -0
  42. package/dist/types/contracts/getRoles.d.ts +15 -0
  43. package/dist/types/contracts/housePrices/getState.d.ts +24 -0
  44. package/dist/types/contracts/psm/getVaultSettings.d.ts +38 -0
  45. package/dist/types/contracts/treasury/getState.d.ts +24 -0
  46. package/dist/types/minter/emissionSchedule.d.ts +53 -0
  47. package/dist/types/pools/lendingPool/getAdminState.d.ts +26 -0
  48. package/dist/types/pools/rwaVault/getRegisteredAdapters.d.ts +33 -0
  49. package/dist/types/pools/rwaVault/getSeedStatus.d.ts +27 -0
  50. package/dist/types/pools/stabilityPool/getAdminState.d.ts +25 -0
  51. package/dist/types/pools/stabilityPool/liquidation.d.ts +112 -0
  52. package/package.json +14 -4
@@ -152,6 +152,7 @@ const getScheduled_1 = require("./contracts/rentStreamer/getScheduled");
152
152
  const getEpochProjection_1 = require("./contracts/rentStreamer/getEpochProjection");
153
153
  const sync_1 = require("./contracts/rentStreamer/sync");
154
154
  const release_1 = require("./contracts/rentStreamer/release");
155
+ const getState_2 = __importDefault(require("./contracts/feeCollector/getState"));
155
156
  const getRawUserDepositsInLendingPool_1 = __importDefault(require("./pools/lendingPool/getRawUserDepositsInLendingPool"));
156
157
  const getRawUserDepositsInStabilityPool_1 = __importDefault(require("./pools/stabilityPool/getRawUserDepositsInStabilityPool"));
157
158
  const getEligibleUserDeposits_1 = __importDefault(require("./pools/lendingPool/getEligibleUserDeposits"));
@@ -189,6 +190,18 @@ const getWithdrawTimelockConfig_1 = require("./pools/stabilityPool/getWithdrawTi
189
190
  const requestWithdraw_1 = require("./pools/stabilityPool/requestWithdraw");
190
191
  // PSM
191
192
  const getVaultInfo_1 = require("./contracts/psm/getVaultInfo");
193
+ const getVaultSettings_1 = require("./contracts/psm/getVaultSettings");
194
+ const getState_3 = __importDefault(require("./contracts/housePrices/getState"));
195
+ const getState_4 = __importDefault(require("./contracts/crvUSDToUSDOracle/getState"));
196
+ const getRoles_1 = __importDefault(require("./contracts/getRoles"));
197
+ const getState_5 = __importDefault(require("./contracts/treasury/getState"));
198
+ const getStatuses_1 = __importDefault(require("./contracts/complianceRegistry/getStatuses"));
199
+ const getAdminState_1 = __importDefault(require("./pools/stabilityPool/getAdminState"));
200
+ const liquidation_1 = require("./pools/stabilityPool/liquidation");
201
+ const emissionSchedule_1 = require("./minter/emissionSchedule");
202
+ const getRegisteredAdapters_1 = __importDefault(require("./pools/rwaVault/getRegisteredAdapters"));
203
+ const getSeedStatus_1 = __importDefault(require("./pools/rwaVault/getSeedStatus"));
204
+ const getAdminState_2 = __importDefault(require("./pools/lendingPool/getAdminState"));
192
205
  const previewDeposit_2 = require("./contracts/psm/previewDeposit");
193
206
  const previewRedeem_1 = require("./contracts/psm/previewRedeem");
194
207
  const previewSwap_1 = require("./contracts/psm/previewSwap");
@@ -212,6 +225,7 @@ const controllerMethods = __importStar(require("./contracts/governance/gaugeCont
212
225
  const gaugeSystemMethods = __importStar(require("./contracts/governance/gaugeSystems"));
213
226
  // ===== Curve =====
214
227
  const curveCommonMethods = __importStar(require("./contracts/curve/common"));
228
+ const faucetMethods = __importStar(require("./contracts/faucet"));
215
229
  // ===== User aggregates (dashboard) =====
216
230
  const userMethods = __importStar(require("./user"));
217
231
  // Proposals
@@ -220,7 +234,7 @@ const getQuorumNumerator_1 = require("./contracts/governance/proposals/getQuorum
220
234
  const getVotingPeriod_1 = require("./contracts/governance/proposals/getVotingPeriod");
221
235
  const castVote_1 = require("./contracts/governance/proposals/castVote");
222
236
  const getProposalInfo_1 = require("./contracts/governance/proposals/getProposalInfo");
223
- const getState_2 = require("./contracts/governance/proposals/getState");
237
+ const getState_6 = require("./contracts/governance/proposals/getState");
224
238
  const execute_1 = require("./contracts/governance/proposals/execute");
225
239
  const getProposalThreshold_1 = require("./contracts/governance/proposals/getProposalThreshold");
226
240
  const getVotes_1 = require("./contracts/governance/proposals/getVotes");
@@ -234,7 +248,7 @@ const hasVoted_1 = require("./contracts/governance/proposals/hasVoted");
234
248
  const getVoteReceipt_1 = require("./contracts/governance/proposals/getVoteReceipt");
235
249
  const getProposalEta_1 = require("./contracts/governance/proposals/getProposalEta");
236
250
  const getLabel_1 = require("./contracts/governance/proposals/getLabel");
237
- const getRoles_1 = require("./contracts/governance/proposals/getRoles");
251
+ const getRoles_2 = require("./contracts/governance/proposals/getRoles");
238
252
  const hasRole_1 = require("./contracts/governance/proposals/hasRole");
239
253
  const setParameter_1 = require("./contracts/governance/proposals/setParameter");
240
254
  const setTimelock_1 = require("./contracts/governance/proposals/setTimelock");
@@ -246,7 +260,7 @@ const hashOperationBatch_1 = require("./contracts/governance/timelock/hashOperat
246
260
  const isOperationDone_1 = require("./contracts/governance/timelock/isOperationDone");
247
261
  const isOperationReady_1 = require("./contracts/governance/timelock/isOperationReady");
248
262
  const isOperationPending_1 = require("./contracts/governance/timelock/isOperationPending");
249
- const getRoles_2 = require("./contracts/governance/timelock/getRoles");
263
+ const getRoles_3 = require("./contracts/governance/timelock/getRoles");
250
264
  const hasRole_2 = require("./contracts/governance/timelock/hasRole");
251
265
  // Tokens
252
266
  // PMUSD
@@ -347,7 +361,7 @@ const getLocks_2 = require("./contracts/lockers/botLocker/getLocks");
347
361
  const getLockedTokenIds_1 = require("./contracts/lockers/botLocker/getLockedTokenIds");
348
362
  const getConfig_3 = require("./contracts/lockers/botLocker/getConfig");
349
363
  const getUnlockWindow_1 = require("./contracts/lockers/botLocker/getUnlockWindow");
350
- const getRoles_3 = require("./contracts/lockers/botLocker/getRoles");
364
+ const getRoles_4 = require("./contracts/lockers/botLocker/getRoles");
351
365
  const hasRole_3 = require("./contracts/lockers/botLocker/hasRole");
352
366
  const grantRole_2 = require("./contracts/lockers/botLocker/grantRole");
353
367
  const addRewardTokens_1 = require("./contracts/lockers/botLocker/addRewardTokens");
@@ -412,6 +426,7 @@ class RPCLibrary {
412
426
  // prices
413
427
  // Curve pools from the chain config's `curve` section
414
428
  curve;
429
+ faucet;
415
430
  // Aggregate reads of one user's position and claimables, composed from the methods above
416
431
  user;
417
432
  prices;
@@ -495,8 +510,19 @@ class RPCLibrary {
495
510
  this.contracts = {
496
511
  housePrices: {
497
512
  getLatestPrice: getLatestPrice_1.default,
513
+ getState: getState_3.default,
498
514
  setOracle: setOracle_1.default,
499
515
  },
516
+ crvUSDToUSDOracle: {
517
+ getState: getState_4.default,
518
+ },
519
+ treasury: {
520
+ getState: getState_5.default,
521
+ },
522
+ complianceRegistry: {
523
+ getStatuses: getStatuses_1.default,
524
+ },
525
+ getRoles: getRoles_1.default,
500
526
  minter: {
501
527
  tick: tick_1.default,
502
528
  get: get_1.default,
@@ -512,6 +538,10 @@ class RPCLibrary {
512
538
  calculateScheduledMintableAmount: calculateScheduledMintableAmount_1.calculateScheduledMintableAmount,
513
539
  getEmissionPerSecond: getEmissionPerSecond_1.getEmissionPerSecond,
514
540
  isPaused: isPaused_1.isPaused,
541
+ getEmissionSchedule: emissionSchedule_1.getEmissionSchedule,
542
+ getSchedulePosition: emissionSchedule_1.getSchedulePosition,
543
+ getEmissionPerSecondForWeek: emissionSchedule_1.getEmissionPerSecondForWeek,
544
+ getMintingWeekForTimestamp: emissionSchedule_1.getMintingWeekForTimestamp,
515
545
  },
516
546
  getContractAddress: getContractAddress_1.default,
517
547
  getContract: getContract_1.default,
@@ -522,6 +552,7 @@ class RPCLibrary {
522
552
  getTokenMetadata: getTokenMetadata_1.getTokenMetadata,
523
553
  feeCollector: {
524
554
  claimRewardFromPool: claimRewardFromPool_1.default,
555
+ getState: getState_2.default,
525
556
  },
526
557
  rentStreamer: {
527
558
  getState: getState_1.getState,
@@ -675,7 +706,7 @@ class RPCLibrary {
675
706
  getLockedTokenIds: getLockedTokenIds_1.getLockedTokenIds,
676
707
  getConfig: getConfig_3.getConfig,
677
708
  getUnlockWindow: getUnlockWindow_1.getUnlockWindow,
678
- getRoles: getRoles_3.getRoles,
709
+ getRoles: getRoles_4.getRoles,
679
710
  hasRole: hasRole_3.hasRole,
680
711
  grantRole: grantRole_2.grantRole,
681
712
  revokeRole: grantRole_2.revokeRole,
@@ -725,7 +756,7 @@ class RPCLibrary {
725
756
  getVotingPeriod: getVotingPeriod_1.getVotingPeriod,
726
757
  castVote: castVote_1.castVote,
727
758
  getProposalInfo: getProposalInfo_1.getProposalInfo,
728
- getState: getState_2.getState,
759
+ getState: getState_6.getState,
729
760
  execute: execute_1.execute,
730
761
  getProposalThreshold: getProposalThreshold_1.getProposalThreshold,
731
762
  getVotes: getVotes_1.getVotes,
@@ -739,7 +770,7 @@ class RPCLibrary {
739
770
  getVoteReceipt: getVoteReceipt_1.getVoteReceipt,
740
771
  getProposalEta: getProposalEta_1.getProposalEta,
741
772
  getLabel: getLabel_1.getLabel,
742
- getRoles: getRoles_1.getRoles,
773
+ getRoles: getRoles_2.getRoles,
743
774
  hasRole: hasRole_1.hasRole,
744
775
  setParameter: setParameter_1.setParameter,
745
776
  setTimelock: setTimelock_1.setTimelock,
@@ -752,12 +783,13 @@ class RPCLibrary {
752
783
  isOperationDone: isOperationDone_1.isOperationDone,
753
784
  isOperationReady: isOperationReady_1.isOperationReady,
754
785
  isOperationPending: isOperationPending_1.isOperationPending,
755
- getRoles: getRoles_2.getRoles,
786
+ getRoles: getRoles_3.getRoles,
756
787
  hasRole: hasRole_2.hasRole,
757
788
  },
758
789
  };
759
790
  this.psm = {
760
791
  getVaultInfo: getVaultInfo_1.getVaultInfo,
792
+ getVaultSettings: getVaultSettings_1.getVaultSettings,
761
793
  previewDeposit: previewDeposit_2.previewDeposit,
762
794
  previewRedeem: previewRedeem_1.previewRedeem,
763
795
  previewSwap: previewSwap_1.previewSwap,
@@ -777,6 +809,15 @@ class RPCLibrary {
777
809
  getWithdrawRequestInfo: getWithdrawRequestInfo_1.getWithdrawRequestInfo,
778
810
  getWithdrawTimelockConfig: getWithdrawTimelockConfig_1.getWithdrawTimelockConfig,
779
811
  requestWithdraw: requestWithdraw_1.requestWithdraw,
812
+ getAdminState: getAdminState_1.default,
813
+ liquidation: {
814
+ getContext: liquidation_1.readLiquidationContext,
815
+ getTarget: liquidation_1.readLiquidationTarget,
816
+ quote: liquidation_1.quoteLiquidation,
817
+ suggestSplit: liquidation_1.suggestSplit,
818
+ simulateWithSplit: liquidation_1.simulateWithSplit,
819
+ minSharesOut: liquidation_1.minSharesOut,
820
+ },
780
821
  },
781
822
  // LendingPool
782
823
  lendingPool: {
@@ -788,6 +829,7 @@ class RPCLibrary {
788
829
  depositAssetToLendingPool: depositAssetToLendingPool_1.default,
789
830
  withdrawAssetFromLendingPool: withdrawAssetFromLendingPool_1.default,
790
831
  getLendingPoolInfo: getLendingPoolInfo_1.default,
832
+ getAdminState: getAdminState_2.default,
791
833
  getRawUserDepositsInLendingPool: getRawUserDepositsInLendingPool_1.default,
792
834
  getEligibleUserDeposits: getEligibleUserDeposits_1.default,
793
835
  getHealthFactor: getHealthFactor_1.default,
@@ -818,6 +860,8 @@ class RPCLibrary {
818
860
  depositToRWAVault: depositToRWAVault_1.default,
819
861
  redeemNFTFromRWAVault: redeemNFTFromRWAVault_1.default,
820
862
  getRWAVaultInfo: getRWAVaultInfo_1.default,
863
+ getRegisteredAdapters: getRegisteredAdapters_1.default,
864
+ getSeedStatus: getSeedStatus_1.default,
821
865
  getNextRandomNFT: getNextRandomNFT_1.default,
822
866
  checkRedeemEligibility: checkRedeemEligibility_1.checkRedeemEligibility,
823
867
  requestRandomSeed: requestRandomSeed_1.default,
@@ -871,6 +915,7 @@ class RPCLibrary {
871
915
  this.curve = {
872
916
  common: curveCommonMethods,
873
917
  };
918
+ this.faucet = faucetMethods;
874
919
  this.user = userMethods;
875
920
  this.prices = {
876
921
  getPrices: getPrices_1.getPrices,
@@ -14,6 +14,11 @@
14
14
  }
15
15
  ],
16
16
  "contracts": {
17
+ "faucet": {
18
+ "id": "faucet",
19
+ "name": "Testnet Faucet",
20
+ "contract": "0xcFcAE14bC0Ef0CB5CD4466b916F518A393d7f2a7"
21
+ },
17
22
  "raachouseprices": {
18
23
  "id": "raachouseprices",
19
24
  "name": "RAAC House Prices",
@@ -180,6 +185,14 @@
180
185
  "timelock": "0x16fe0d26550aEEca53f5eF2FFE2DBc9319B3F212"
181
186
  }
182
187
  ],
188
+ "psm": {
189
+ "rpsm-susds": {
190
+ "id": "rpsm-sUSDS",
191
+ "name": "RAAC Peg Stability Module sUSDS",
192
+ "contract": "0xbcA54A6E7BeD62Ad3aA5660c0e51FeA1F6A47289",
193
+ "rateProvider": "0xB3b47F65dFeca20991148BAfe8dc34e1aDb6939b"
194
+ }
195
+ },
183
196
  "pools": {
184
197
  "stabilitypool": {
185
198
  "id": "stabilitypool",
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const contracts_1 = require("../../utils/contracts");
5
+ const artifacts_1 = require("../../utils/artifacts");
6
+ const rpcError_1 = require("../../utils/rpcError");
7
+ // ComplianceRegistry storage: AccessControl._roles at slot 0, _blacklisted at slot 1, sanctionsList at slot 2.
8
+ const BLACKLIST_SLOT = 1;
9
+ const SANCTIONS_SLOT = 2;
10
+ const listedSlot = (user) => ethers_1.ethers.keccak256(ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(["address", "uint256"], [user, BLACKLIST_SLOT]));
11
+ /**
12
+ * Reads the sanctions list and each address's compliance status. `_blacklisted` is private, so the own-list flag is
13
+ * read from storage, trusted only when slot 2 matches `sanctionsList()`; otherwise `listed` is null where it cannot
14
+ * be told apart from a sanction.
15
+ * @param chainId The chain id.
16
+ * @param addresses The addresses to check.
17
+ * @param provider The provider to read with.
18
+ */
19
+ async function getStatuses(chainId, addresses, provider) {
20
+ const at = (0, contracts_1.getContractAddress)(chainId, "complianceregistry");
21
+ try {
22
+ const reg = new ethers_1.ethers.Contract(at, (0, artifacts_1.getABI)("complianceregistry"), provider);
23
+ const [list, slot2] = await Promise.all([reg.sanctionsList(), provider.getStorage(at, SANCTIONS_SLOT).catch(() => null)]);
24
+ const layoutOk = slot2 !== null && BigInt(slot2) === BigInt(list);
25
+ const sanctions = list === ethers_1.ethers.ZeroAddress ? null : new ethers_1.ethers.Contract(list, ["function isSanctioned(address) view returns (bool)"], provider);
26
+ const statuses = await Promise.all(addresses.map(async (address) => {
27
+ const [blocked, sanctioned, listed] = await Promise.all([
28
+ reg.isBlacklisted(address),
29
+ sanctions ? sanctions.isSanctioned(address) : false,
30
+ layoutOk ? provider.getStorage(at, listedSlot(address)).then((v) => BigInt(v) !== BigInt(0)) : null,
31
+ ]);
32
+ return { address, blocked, listed: listed ?? (sanctioned ? null : blocked), sanctioned };
33
+ }));
34
+ return { sanctionsList: list, statuses };
35
+ }
36
+ catch (error) {
37
+ throw (0, rpcError_1.toRpcError)("complianceRegistry.getStatuses", error, { chainId, address: at });
38
+ }
39
+ }
40
+ exports.default = getStatuses;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CRVUSD_PRICE_SOURCES = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("../../utils/contracts");
6
+ const artifacts_1 = require("../../utils/artifacts");
7
+ const rpcError_1 = require("../../utils/rpcError");
8
+ /** Which route the crvUSD/USD price came from, as `getLatestPrice`'s third value reports it. */
9
+ exports.CRVUSD_PRICE_SOURCES = ["chainlink", "curve", "fallback"];
10
+ /**
11
+ * Reads the crvUSD/USD oracle's current price and route and every setting behind them. A reverting price read gives
12
+ * `price: null` instead of failing, since that is exactly when the settings matter.
13
+ * @param chainId The chain id.
14
+ * @param provider The provider to read with.
15
+ * @param oracleAddress Optional address, e.g. from `housePrices.getState`; defaults to the registry's `crvusdtousdoracle`.
16
+ */
17
+ async function getState(chainId, provider, oracleAddress) {
18
+ const address = oracleAddress ?? (0, contracts_1.getContractAddress)(chainId, "crvusdtousdoracle");
19
+ try {
20
+ const oracle = new ethers_1.ethers.Contract(address, (0, artifacts_1.getABI)("crvusdtousdoracle"), provider);
21
+ const [owner, latest, circuitBreakerEnabled, minPriceThreshold, maxPriceThreshold, fallbackPriceInUSD, lastFallbackUpdateTimestamp, maxStableStaleTime, maxUnstableStaleTime, crvUSDDataFeed, ethDataFeed, curveOracle, K] = await Promise.all([
22
+ oracle.owner(),
23
+ oracle.getLatestPrice().catch(() => null),
24
+ oracle.circuitBreakerEnabled(),
25
+ oracle.minPriceThreshold(),
26
+ oracle.maxPriceThreshold(),
27
+ oracle.fallbackPriceInUSD(),
28
+ oracle.lastFallbackUpdateTimestamp(),
29
+ oracle.maxStableStaleTime(),
30
+ oracle.maxUnstableStaleTime(),
31
+ oracle.crvUSDDataFeed(),
32
+ oracle.ethDataFeed(),
33
+ oracle.curveOracle(),
34
+ oracle.K(),
35
+ ]);
36
+ return {
37
+ owner,
38
+ price: latest ? latest[0] : null,
39
+ priceTimestamp: latest ? Number(latest[1]) : null,
40
+ source: latest ? (exports.CRVUSD_PRICE_SOURCES[Number(latest[2])] ?? null) : null,
41
+ circuitBreakerEnabled,
42
+ minPriceThreshold,
43
+ maxPriceThreshold,
44
+ fallbackPriceInUSD,
45
+ lastFallbackUpdateTimestamp: Number(lastFallbackUpdateTimestamp),
46
+ maxStableStaleTime,
47
+ maxUnstableStaleTime,
48
+ crvUSDDataFeed,
49
+ ethDataFeed,
50
+ curveOracle,
51
+ K,
52
+ };
53
+ }
54
+ catch (error) {
55
+ throw (0, rpcError_1.toRpcError)("crvUSDToUSDOracle.getState", error, { chainId, address });
56
+ }
57
+ }
58
+ exports.default = getState;
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getCurvePools = exports.CURVE_POOL_READ_ABI = void 0;
7
7
  exports.resolveCurvePool = resolveCurvePool;
8
8
  exports.getCurvePoolContract = getCurvePoolContract;
9
+ exports.getCurvePoolFlavourContract = getCurvePoolFlavourContract;
10
+ exports.assertCoinCount = assertCoinCount;
11
+ exports.assertCoinIndex = assertCoinIndex;
9
12
  const ethers_1 = require("ethers");
10
13
  const chains_1 = __importDefault(require("../../../configs/chains"));
11
14
  /**
@@ -37,3 +40,57 @@ function getCurvePoolContract(chainId, poolAddressOrId, provider) {
37
40
  const entry = resolveCurvePool(chainId, poolAddressOrId);
38
41
  return { entry, contract: new ethers_1.ethers.Contract(entry.contract, exports.CURVE_POOL_READ_ABI, provider), provider };
39
42
  }
43
+ /**
44
+ * Swap and liquidity methods per flavour. twocrypto-ng and tricrypto-ng index coins with uint256 and take fixed
45
+ * uint256[2] / uint256[3] arrays; stableswap-ng indexes with int128 and takes a dynamic uint256[]. Encoding one
46
+ * against another reverts, so the pool's configured flavour picks the ABI.
47
+ */
48
+ const CURVE_POOL_WRITE_ABI = {
49
+ twocrypto: [
50
+ "function get_dy(uint256 i, uint256 j, uint256 dx) view returns (uint256)",
51
+ "function calc_withdraw_one_coin(uint256 token_amount, uint256 i) view returns (uint256)",
52
+ "function calc_token_amount(uint256[2] amounts, bool deposit) view returns (uint256)",
53
+ "function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy, address receiver) returns (uint256)",
54
+ "function add_liquidity(uint256[2] amounts, uint256 min_mint_amount, address receiver) returns (uint256)",
55
+ "function remove_liquidity(uint256 _amount, uint256[2] min_amounts, address receiver) returns (uint256[2])",
56
+ "function remove_liquidity_one_coin(uint256 token_amount, uint256 i, uint256 min_amount, address receiver) returns (uint256)",
57
+ ],
58
+ tricrypto: [
59
+ "function get_dy(uint256 i, uint256 j, uint256 dx) view returns (uint256)",
60
+ "function calc_withdraw_one_coin(uint256 token_amount, uint256 i) view returns (uint256)",
61
+ "function calc_token_amount(uint256[3] amounts, bool deposit) view returns (uint256)",
62
+ "function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy, address receiver) returns (uint256)",
63
+ "function add_liquidity(uint256[3] amounts, uint256 min_mint_amount, address receiver) returns (uint256)",
64
+ "function remove_liquidity(uint256 _amount, uint256[3] min_amounts, address receiver) returns (uint256[3])",
65
+ "function remove_liquidity_one_coin(uint256 token_amount, uint256 i, uint256 min_amount, address receiver) returns (uint256)",
66
+ ],
67
+ stableswap: [
68
+ "function get_dy(int128 i, int128 j, uint256 dx) view returns (uint256)",
69
+ "function calc_withdraw_one_coin(uint256 token_amount, int128 i) view returns (uint256)",
70
+ "function calc_token_amount(uint256[] amounts, bool is_deposit) view returns (uint256)",
71
+ "function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy, address receiver) returns (uint256)",
72
+ "function add_liquidity(uint256[] amounts, uint256 min_mint_amount, address receiver) returns (uint256)",
73
+ "function remove_liquidity(uint256 _amount, uint256[] min_amounts, address receiver) returns (uint256[])",
74
+ "function remove_liquidity_one_coin(uint256 token_amount, int128 i, uint256 min_amount, address receiver) returns (uint256)",
75
+ ],
76
+ };
77
+ /** The pool contract with its flavour's swap and liquidity ABI, bound to a signer or provider. */
78
+ function getCurvePoolFlavourContract(chainId, poolAddressOrId, runner) {
79
+ const entry = resolveCurvePool(chainId, poolAddressOrId);
80
+ if (!runner) {
81
+ runner = new ethers_1.ethers.JsonRpcProvider(chains_1.default[chainId].rpcs[0]);
82
+ }
83
+ return { entry, contract: new ethers_1.ethers.Contract(entry.contract, CURVE_POOL_WRITE_ABI[entry.flavour], runner) };
84
+ }
85
+ /** Checks an amounts array matches the pool's coin count before it reaches the encoder. */
86
+ function assertCoinCount(entry, amounts, what) {
87
+ if (amounts.length !== entry.coins.length) {
88
+ throw new Error(`${what} needs ${entry.coins.length} amounts for ${entry.id}, got ${amounts.length}`);
89
+ }
90
+ }
91
+ /** Checks a coin index is inside the pool. */
92
+ function assertCoinIndex(entry, index) {
93
+ if (!Number.isInteger(index) || index < 0 || index >= entry.coins.length) {
94
+ throw new Error(`Coin index ${index} is out of range for ${entry.id} (${entry.coins.length} coins)`);
95
+ }
96
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addLiquidity = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Deposits coins into a Curve pool for LP tokens. The caller approves each non-zero coin to the pool first.
8
+ *
9
+ * @param chainId - The chain/network to use.
10
+ * @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
11
+ * @param amounts - One amount per coin, in pool order and each coin's base units; 0 for a coin not deposited.
12
+ * @param minMintAmount - The least LP to accept (18 decimals); the deposit reverts below it. See `calcTokenAmount`.
13
+ * @param receiver - Who receives the LP tokens.
14
+ * @param signer - The signer sending the transaction.
15
+ * @returns The mined transaction receipt.
16
+ */
17
+ const addLiquidity = async (chainId, poolAddressOrId, amounts, minMintAmount, receiver, signer) => {
18
+ if (!signer)
19
+ throw new Error("Signer is required");
20
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, signer);
21
+ (0, _helpers_1.assertCoinCount)(entry, amounts, "addLiquidity");
22
+ try {
23
+ const tx = await contract.add_liquidity(amounts, minMintAmount, receiver);
24
+ return await tx.wait();
25
+ }
26
+ catch (error) {
27
+ throw (0, rpcError_1.toRpcError)("curve.addLiquidity", error, { chainId, address: entry.contract });
28
+ }
29
+ };
30
+ exports.addLiquidity = addLiquidity;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calcTokenAmount = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * LP tokens a deposit (or, with `isDeposit` false, a proportional withdrawal) of `amounts` mints or burns at the
8
+ * pool's current state. Fees are not included, so apply a slippage margin before using it as a minimum.
9
+ *
10
+ * @param amounts - One amount per coin, in pool order and each coin's base units.
11
+ * @returns LP tokens (18 decimals).
12
+ */
13
+ const calcTokenAmount = async (chainId, poolAddressOrId, amounts, isDeposit, provider) => {
14
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, provider);
15
+ (0, _helpers_1.assertCoinCount)(entry, amounts, "calcTokenAmount");
16
+ try {
17
+ return await contract.calc_token_amount(amounts, isDeposit);
18
+ }
19
+ catch (error) {
20
+ throw (0, rpcError_1.toRpcError)("curve.calcTokenAmount", error, { chainId, address: entry.contract });
21
+ }
22
+ };
23
+ exports.calcTokenAmount = calcTokenAmount;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calcWithdrawOneCoin = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * How much of coin `i` burning `lpAmount` LP tokens returns at the pool's current state.
8
+ *
9
+ * @returns The output amount in coin `i`'s base units.
10
+ */
11
+ const calcWithdrawOneCoin = async (chainId, poolAddressOrId, lpAmount, i, provider) => {
12
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, provider);
13
+ (0, _helpers_1.assertCoinIndex)(entry, i);
14
+ try {
15
+ return await contract.calc_withdraw_one_coin(lpAmount, i);
16
+ }
17
+ catch (error) {
18
+ throw (0, rpcError_1.toRpcError)("curve.calcWithdrawOneCoin", error, { chainId, address: entry.contract });
19
+ }
20
+ };
21
+ exports.calcWithdrawOneCoin = calcWithdrawOneCoin;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exchange = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Swaps `amountIn` of coin `i` for coin `j` in a Curve pool. The caller approves coin `i` to the pool first.
8
+ *
9
+ * @param chainId - The chain/network to use.
10
+ * @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
11
+ * @param i - Index of the coin sold, in pool order.
12
+ * @param j - Index of the coin bought, in pool order.
13
+ * @param amountIn - Amount of coin `i`, in its base units.
14
+ * @param minAmountOut - The least of coin `j` to accept, in its base units; the swap reverts below it.
15
+ * @param receiver - Who receives coin `j`.
16
+ * @param signer - The signer sending the transaction.
17
+ * @returns The mined transaction receipt.
18
+ */
19
+ const exchange = async (chainId, poolAddressOrId, i, j, amountIn, minAmountOut, receiver, signer) => {
20
+ if (!signer)
21
+ throw new Error("Signer is required");
22
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, signer);
23
+ (0, _helpers_1.assertCoinIndex)(entry, i);
24
+ (0, _helpers_1.assertCoinIndex)(entry, j);
25
+ try {
26
+ const tx = await contract.exchange(i, j, amountIn, minAmountOut, receiver);
27
+ return await tx.wait();
28
+ }
29
+ catch (error) {
30
+ throw (0, rpcError_1.toRpcError)("curve.exchange", error, { chainId, address: entry.contract });
31
+ }
32
+ };
33
+ exports.exchange = exchange;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDy = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * How much of coin `j` a swap of `amountIn` of coin `i` returns at the pool's current state, before slippage.
8
+ *
9
+ * @returns The output amount in coin `j`'s base units.
10
+ */
11
+ const getDy = async (chainId, poolAddressOrId, i, j, amountIn, provider) => {
12
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, provider);
13
+ (0, _helpers_1.assertCoinIndex)(entry, i);
14
+ (0, _helpers_1.assertCoinIndex)(entry, j);
15
+ try {
16
+ return await contract.get_dy(i, j, amountIn);
17
+ }
18
+ catch (error) {
19
+ throw (0, rpcError_1.toRpcError)("curve.getDy", error, { chainId, address: entry.contract });
20
+ }
21
+ };
22
+ exports.getDy = getDy;
@@ -14,5 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./addLiquidity"), exports);
18
+ __exportStar(require("./calcTokenAmount"), exports);
19
+ __exportStar(require("./calcWithdrawOneCoin"), exports);
20
+ __exportStar(require("./exchange"), exports);
21
+ __exportStar(require("./getDy"), exports);
17
22
  __exportStar(require("./getPools"), exports);
18
23
  __exportStar(require("./getVirtualPrice"), exports);
24
+ __exportStar(require("./removeLiquidity"), exports);
25
+ __exportStar(require("./removeLiquidityOneCoin"), exports);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeLiquidity = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Burns LP tokens for every coin of a Curve pool in proportion to its balances.
8
+ *
9
+ * @param chainId - The chain/network to use.
10
+ * @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
11
+ * @param lpAmount - LP tokens to burn (18 decimals).
12
+ * @param minAmounts - The least of each coin to accept, in pool order and each coin's base units.
13
+ * @param receiver - Who receives the coins.
14
+ * @param signer - The signer sending the transaction.
15
+ * @returns The mined transaction receipt.
16
+ */
17
+ const removeLiquidity = async (chainId, poolAddressOrId, lpAmount, minAmounts, receiver, signer) => {
18
+ if (!signer)
19
+ throw new Error("Signer is required");
20
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, signer);
21
+ (0, _helpers_1.assertCoinCount)(entry, minAmounts, "removeLiquidity");
22
+ try {
23
+ const tx = await contract.remove_liquidity(lpAmount, minAmounts, receiver);
24
+ return await tx.wait();
25
+ }
26
+ catch (error) {
27
+ throw (0, rpcError_1.toRpcError)("curve.removeLiquidity", error, { chainId, address: entry.contract });
28
+ }
29
+ };
30
+ exports.removeLiquidity = removeLiquidity;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeLiquidityOneCoin = void 0;
4
+ const rpcError_1 = require("../../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Burns LP tokens for a single coin of a Curve pool.
8
+ *
9
+ * @param chainId - The chain/network to use.
10
+ * @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
11
+ * @param lpAmount - LP tokens to burn (18 decimals).
12
+ * @param i - Index of the coin to receive, in pool order.
13
+ * @param minAmount - The least of coin `i` to accept, in its base units. See `calcWithdrawOneCoin`.
14
+ * @param receiver - Who receives the coin.
15
+ * @param signer - The signer sending the transaction.
16
+ * @returns The mined transaction receipt.
17
+ */
18
+ const removeLiquidityOneCoin = async (chainId, poolAddressOrId, lpAmount, i, minAmount, receiver, signer) => {
19
+ if (!signer)
20
+ throw new Error("Signer is required");
21
+ const { entry, contract } = (0, _helpers_1.getCurvePoolFlavourContract)(chainId, poolAddressOrId, signer);
22
+ (0, _helpers_1.assertCoinIndex)(entry, i);
23
+ try {
24
+ const tx = await contract.remove_liquidity_one_coin(lpAmount, i, minAmount, receiver);
25
+ return await tx.wait();
26
+ }
27
+ catch (error) {
28
+ throw (0, rpcError_1.toRpcError)("curve.removeLiquidityOneCoin", error, { chainId, address: entry.contract });
29
+ }
30
+ };
31
+ exports.removeLiquidityOneCoin = removeLiquidityOneCoin;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.claim = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("../../utils/contracts");
6
+ const rpcError_1 = require("../../utils/rpcError");
7
+ const FAUCET_CLAIM_ABI = [
8
+ "function claim(address token, uint256 amount)",
9
+ "function claimMultiple(address[] tokens, uint256[] amounts)",
10
+ ];
11
+ /**
12
+ * Claims testnet tokens from the faucet: one `claim` for a single token, one `claimMultiple` for several.
13
+ *
14
+ * @param chainId - The chain/network to use; only chains with a `faucet` contract in their config.
15
+ * @param claims - The tokens and amounts to claim.
16
+ * @param signer - The signer sending the transaction; the tokens go to its address.
17
+ * @returns The mined transaction receipt.
18
+ * @throws If the chain has no faucet, `claims` is empty, or the transaction fails.
19
+ */
20
+ const claim = async (chainId, claims, signer) => {
21
+ if (!signer)
22
+ throw new Error("Signer is required");
23
+ if (claims.length === 0)
24
+ throw new Error("Nothing to claim");
25
+ const address = (0, contracts_1.getContractAddress)(chainId, "faucet");
26
+ try {
27
+ const faucet = new ethers_1.ethers.Contract(address, FAUCET_CLAIM_ABI, signer);
28
+ const tx = claims.length === 1
29
+ ? await faucet.claim(claims[0].token, claims[0].amount)
30
+ : await faucet.claimMultiple(claims.map(({ token }) => token), claims.map(({ amount }) => amount));
31
+ return await tx.wait();
32
+ }
33
+ catch (error) {
34
+ throw (0, rpcError_1.toRpcError)("faucet.claim", error, { chainId, address });
35
+ }
36
+ };
37
+ exports.claim = claim;