diff --git a/.gitmodules b/.gitmodules index 71e2578..fc05ab8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,9 @@ [submodule "lib/erc20-helpers"] path = lib/erc20-helpers url = https://github.com/marsfoundation/erc20-helpers -[submodule "lib/xchain-dsr-oracle"] - path = lib/xchain-dsr-oracle - url = https://github.com/marsfoundation/xchain-dsr-oracle [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/openzeppelin/openzeppelin-contracts +[submodule "lib/xchain-ssr-oracle"] + path = lib/xchain-ssr-oracle + url = https://github.com/marsfoundation/xchain-ssr-oracle diff --git a/lib/xchain-dsr-oracle b/lib/xchain-dsr-oracle deleted file mode 160000 index a02e592..0000000 --- a/lib/xchain-dsr-oracle +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a02e59274d20f878f642baec43447b3bc183aca3 diff --git a/lib/xchain-ssr-oracle b/lib/xchain-ssr-oracle new file mode 160000 index 0000000..dc9fc30 --- /dev/null +++ b/lib/xchain-ssr-oracle @@ -0,0 +1 @@ +Subproject commit dc9fc30ea91e8cc562f561faa62d40f615a99abb diff --git a/test/PSMTestBase.sol b/test/PSMTestBase.sol index da8a68f..53f2214 100644 --- a/test/PSMTestBase.sol +++ b/test/PSMTestBase.sol @@ -21,7 +21,7 @@ contract PSMTestBase is Test { MockERC20 public usdc; MockERC20 public susds; - IRateProviderLike public rateProvider; // Can be overridden by dsrOracle using same interface + IRateProviderLike public rateProvider; // Can be overridden by ssrOracle using same interface MockRateProvider public mockRateProvider; // Interface used for mocking diff --git a/test/invariant/Invariants.t.sol b/test/invariant/Invariants.t.sol index 435b8a5..e675f89 100644 --- a/test/invariant/Invariants.t.sol +++ b/test/invariant/Invariants.t.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.13; import "forge-std/Test.sol"; -import { DSRAuthOracle } from "lib/xchain-dsr-oracle/src/DSRAuthOracle.sol"; -import { IDSROracle } from "lib/xchain-dsr-oracle/src/interfaces/IDSROracle.sol"; +import { SSRAuthOracle } from "lib/xchain-ssr-oracle/src/SSRAuthOracle.sol"; +import { ISSROracle } from "lib/xchain-ssr-oracle/src/interfaces/ISSROracle.sol"; import { PSM3 } from "src/PSM3.sol"; @@ -541,36 +541,36 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase { function setUp() public override { super.setUp(); - DSRAuthOracle dsrOracle = new DSRAuthOracle(); + SSRAuthOracle ssrOracle = new SSRAuthOracle(); // Workaround to initialize PSM with an oracle that does not return zero // This gets overwritten by the handler - dsrOracle.grantRole(dsrOracle.DATA_PROVIDER_ROLE(), address(this)); - dsrOracle.setPotData(IDSROracle.PotData({ - dsr: uint96(1e27), + ssrOracle.grantRole(ssrOracle.DATA_PROVIDER_ROLE(), address(this)); + ssrOracle.setSUSDSData(ISSROracle.SUSDSData({ + ssr: uint96(1e27), chi: uint120(1e27), rho: uint40(block.timestamp) })); - dsrOracle.revokeRole(dsrOracle.DATA_PROVIDER_ROLE(), address(this)); + ssrOracle.revokeRole(ssrOracle.DATA_PROVIDER_ROLE(), address(this)); // Redeploy PSM with new rate provider - psm = new PSM3(owner, address(usdc), address(usds), address(susds), address(dsrOracle)); + psm = new PSM3(owner, address(usdc), address(usds), address(susds), address(ssrOracle)); // Seed the new PSM with 1e18 shares (1e18 of value) _deposit(address(usds), BURN_ADDRESS, 1e18); lpHandler = new LpHandler(psm, usdc, usds, susds, 3); swapperHandler = new SwapperHandler(psm, usdc, usds, susds, 3); - timeBasedRateHandler = new TimeBasedRateHandler(psm, dsrOracle); + timeBasedRateHandler = new TimeBasedRateHandler(psm, ssrOracle); // Handler acts in the same way as a receiver on L2, so add as a data provider to the // oracle. - dsrOracle.grantRole(dsrOracle.DATA_PROVIDER_ROLE(), address(timeBasedRateHandler)); + ssrOracle.grantRole(ssrOracle.DATA_PROVIDER_ROLE(), address(timeBasedRateHandler)); - rateProvider = IRateProviderLike(address(dsrOracle)); + rateProvider = IRateProviderLike(address(ssrOracle)); // Manually set initial values for the oracle through the handler to start - timeBasedRateHandler.setPotData(1e27); + timeBasedRateHandler.setSUSDSData(1e27); targetContract(address(lpHandler)); targetContract(address(swapperHandler)); @@ -580,7 +580,7 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase { assertEq(swapperHandler.lp0(), lpHandler.lps(0)); } - function invariant_A_test() public view { + function invariant_A() public view { _checkInvariant_A(); } @@ -620,37 +620,37 @@ contract PSMInvariants_TimeBasedRateSetting_WithTransfers is PSMInvariantTestBas function setUp() public override { super.setUp(); - DSRAuthOracle dsrOracle = new DSRAuthOracle(); + SSRAuthOracle ssrOracle = new SSRAuthOracle(); // Workaround to initialize PSM with an oracle that does not return zero // This gets overwritten by the handler - dsrOracle.grantRole(dsrOracle.DATA_PROVIDER_ROLE(), address(this)); - dsrOracle.setPotData(IDSROracle.PotData({ - dsr: uint96(1e27), + ssrOracle.grantRole(ssrOracle.DATA_PROVIDER_ROLE(), address(this)); + ssrOracle.setSUSDSData(ISSROracle.SUSDSData({ + ssr: uint96(1e27), chi: uint120(1e27), rho: uint40(block.timestamp) })); - dsrOracle.revokeRole(dsrOracle.DATA_PROVIDER_ROLE(), address(this)); + ssrOracle.revokeRole(ssrOracle.DATA_PROVIDER_ROLE(), address(this)); // Redeploy PSM with new rate provider - psm = new PSM3(owner, address(usdc), address(usds), address(susds), address(dsrOracle)); + psm = new PSM3(owner, address(usdc), address(usds), address(susds), address(ssrOracle)); // Seed the new PSM with 1e18 shares (1e18 of value) _deposit(address(usds), BURN_ADDRESS, 1e18); lpHandler = new LpHandler(psm, usdc, usds, susds, 3); swapperHandler = new SwapperHandler(psm, usdc, usds, susds, 3); - timeBasedRateHandler = new TimeBasedRateHandler(psm, dsrOracle); + timeBasedRateHandler = new TimeBasedRateHandler(psm, ssrOracle); transferHandler = new TransferHandler(psm, usdc, usds, susds); // Handler acts in the same way as a receiver on L2, so add as a data provider to the // oracle. - dsrOracle.grantRole(dsrOracle.DATA_PROVIDER_ROLE(), address(timeBasedRateHandler)); + ssrOracle.grantRole(ssrOracle.DATA_PROVIDER_ROLE(), address(timeBasedRateHandler)); - rateProvider = IRateProviderLike(address(dsrOracle)); + rateProvider = IRateProviderLike(address(ssrOracle)); // Manually set initial values for the oracle through the handler to start - timeBasedRateHandler.setPotData(1e27); + timeBasedRateHandler.setSUSDSData(1e27); targetContract(address(lpHandler)); targetContract(address(swapperHandler)); diff --git a/test/invariant/handlers/TimeBasedRateHandler.sol b/test/invariant/handlers/TimeBasedRateHandler.sol index 6d39361..2291b04 100644 --- a/test/invariant/handlers/TimeBasedRateHandler.sol +++ b/test/invariant/handlers/TimeBasedRateHandler.sol @@ -5,40 +5,40 @@ import { HandlerBase, PSM3 } from "test/invariant/handlers/HandlerBase.sol"; import { StdCheats } from "forge-std/StdCheats.sol"; -import { DSRAuthOracle } from "lib/xchain-dsr-oracle/src/DSRAuthOracle.sol"; -import { IDSROracle } from "lib/xchain-dsr-oracle/src/interfaces/IDSROracle.sol"; +import { SSRAuthOracle } from "lib/xchain-ssr-oracle/src/SSRAuthOracle.sol"; +import { ISSROracle } from "lib/xchain-ssr-oracle/src/interfaces/ISSROracle.sol"; contract TimeBasedRateHandler is HandlerBase, StdCheats { - uint256 public dsr; + uint256 public ssr; - uint256 constant TWENTY_PCT_APY_DSR = 1.000000005781378656804591712e27; + uint256 constant TWENTY_PCT_APY_SSR = 1.000000005781378656804591712e27; - DSRAuthOracle public dsrOracle; + SSRAuthOracle public ssrOracle; - uint256 public setPotDataCount; + uint256 public setSUSDSDataCount; uint256 public warpCount; - constructor(PSM3 psm_, DSRAuthOracle dsrOracle_) HandlerBase(psm_) { - dsrOracle = dsrOracle_; + constructor(PSM3 psm_, SSRAuthOracle ssrOracle_) HandlerBase(psm_) { + ssrOracle = ssrOracle_; } // This acts as a receiver on an L2. - function setPotData(uint256 newDsr) external { + function setSUSDSData(uint256 newSsr) external { // 1. Setup and bounds - dsr = _bound(newDsr, 1e27, TWENTY_PCT_APY_DSR); + ssr = _bound(newSsr, 1e27, TWENTY_PCT_APY_SSR); // Update rho to be current, update chi based on current rate uint256 rho = block.timestamp; - uint256 chi = dsrOracle.getConversionRate(rho); + uint256 chi = ssrOracle.getConversionRate(rho); // 2. Cache starting state uint256 startingConversion = psm.convertToAssetValue(1e18); uint256 startingValue = psm.totalAssets(); // 3. Perform action against protocol - dsrOracle.setPotData(IDSROracle.PotData({ - dsr: uint96(dsr), + ssrOracle.setSUSDSData(ISSROracle.SUSDSData({ + ssr: uint96(ssr), chi: uint120(chi), rho: uint40(rho) })); @@ -47,17 +47,17 @@ contract TimeBasedRateHandler is HandlerBase, StdCheats { assertGe( psm.convertToAssetValue(1e18) + 1, startingConversion, - "TimeBasedRateHandler/setPotData/conversion-rate-decrease" + "TimeBasedRateHandler/getSUSDSData/conversion-rate-decrease" ); assertGe( psm.totalAssets() + 1, startingValue, - "TimeBasedRateHandler/setPotData/psm-total-value-decrease" + "TimeBasedRateHandler/getSUSDSData/psm-total-value-decrease" ); // 5. Update metrics tracking state - setPotDataCount++; + setSUSDSDataCount++; } function warp(uint256 skipTime) external {