From ffbb2a8279b56bf596290d0e7f1b26481e3476af Mon Sep 17 00:00:00 2001 From: Julian R Date: Mon, 4 Nov 2024 09:21:44 -0300 Subject: [PATCH] use erc4626 --- contracts/plugins/assets/sky/README.md | 5 ++--- contracts/plugins/assets/sky/SUSDSCollateral.sol | 16 +++------------- .../sky/SUSDSCollateralTestSuite.test.ts | 1 + 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/contracts/plugins/assets/sky/README.md b/contracts/plugins/assets/sky/README.md index c9afb1aa1..39701370c 100644 --- a/contracts/plugins/assets/sky/README.md +++ b/contracts/plugins/assets/sky/README.md @@ -8,8 +8,7 @@ This plugin allows `sUSDS` (Sky) holders to use their tokens as collateral in th These `sUSDS` tokens serve as a digital record of any value accrued to a specific position. The Sky Protocol dynamically and automatically adds USDS tokens to the entire pool of USDS supplied to the module every few seconds, in accordance with the Sky Savings Rate. As a result of the tokens auto-accumulating in the pool over time, the value tends to accrue within the sUSDS being held. -Since it is ERC4626, the redeemable USDS amount can be gotten by dividing `sUSDS.totalAssets()` by `sUSDS.totalSupply()`. However, the same rate can be read out more directly by calling `sUSDS.chi()`. - +Since it is ERC4626, the redeemable USDS amount can be gotten by dividing `sUSDS.totalAssets()` by `sUSDS.totalSupply()`. `sUSDS` contract: Sky Money: https://sky.money/ @@ -26,4 +25,4 @@ Sky Money: https://sky.money/ #### refPerTok {ref/tok} -`return shiftl_toFix(susds.chi(), -27);` +`return shiftl_toFix(IERC4626(address(erc20)).convertToAssets(oneShare), -refDecimals, FLOOR);` diff --git a/contracts/plugins/assets/sky/SUSDSCollateral.sol b/contracts/plugins/assets/sky/SUSDSCollateral.sol index 837dd68fd..926af4bfd 100644 --- a/contracts/plugins/assets/sky/SUSDSCollateral.sol +++ b/contracts/plugins/assets/sky/SUSDSCollateral.sol @@ -1,9 +1,7 @@ // SPDX-License-Identifier: BlueOak-1.0.0 pragma solidity 0.8.19; -import "../../../libraries/Fixed.sol"; -import "../AppreciatingFiatCollateral.sol"; -import "./vendor/ISUsds.sol"; +import "../ERC4626FiatCollateral.sol"; /** * @title SUSDS Collateral @@ -13,19 +11,11 @@ import "./vendor/ISUsds.sol"; * tar = USD * UoA = USD */ -contract SUSDSCollateral is AppreciatingFiatCollateral { - using OracleLib for AggregatorV3Interface; - using FixLib for uint192; - +contract SUSDSCollateral is ERC4626FiatCollateral { /// @param config.chainlinkFeed {UoA/ref} price of USDS in USD terms constructor(CollateralConfig memory config, uint192 revenueHiding) - AppreciatingFiatCollateral(config, revenueHiding) + ERC4626FiatCollateral(config, revenueHiding) { require(config.defaultThreshold != 0, "defaultThreshold zero"); } - - /// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens - function underlyingRefPerTok() public view override returns (uint192) { - return shiftl_toFix(ISUsds(address(erc20)).chi(), -27, FLOOR); - } } diff --git a/test/plugins/individual-collateral/sky/SUSDSCollateralTestSuite.test.ts b/test/plugins/individual-collateral/sky/SUSDSCollateralTestSuite.test.ts index 271beb989..538e19fa6 100644 --- a/test/plugins/individual-collateral/sky/SUSDSCollateralTestSuite.test.ts +++ b/test/plugins/individual-collateral/sky/SUSDSCollateralTestSuite.test.ts @@ -220,6 +220,7 @@ const opts = { collateralName: 'SUSDSCollateral', chainlinkDefaultAnswer, itIsPricedByPeg: true, + toleranceDivisor: bn('1e8'), } collateralTests(opts)