Skip to content

Commit

Permalink
add RAY constant
Browse files Browse the repository at this point in the history
  • Loading branch information
kyzia551 committed Aug 14, 2024
1 parent 7c0e5b6 commit 721b437
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/periphery/contracts/static-a-token/Stata4626Upgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
}
}

uint256 public constant RAY = 1e27;

IPool public immutable POOL;
IPoolAddressesProvider public immutable POOL_ADDRESSES_PROVIDER;

Expand Down Expand Up @@ -134,20 +136,17 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
// if no supply cap deposit is unlimited
if (supplyCap == 0) return type(uint256).max;

// TODO: revalidate
// return remaining supply cap margin
// uint256 currentSupply = (IAToken(reserveData.aTokenAddress).scaledTotalSupply() +
// reserveData.accruedToTreasury).rayMulRoundUp(_rate());
uint256 currentSupply = (IAToken(reserveData.aTokenAddress).scaledTotalSupply() +
reserveData.accruedToTreasury).mulDiv(_rate(), 1e27, Math.Rounding.Ceil);
reserveData.accruedToTreasury).mulDiv(_rate(), RAY, Math.Rounding.Ceil);
return currentSupply > supplyCap ? 0 : supplyCap - currentSupply;
}

///@inheritdoc IStata4626
function latestAnswer() external view returns (int256) {
uint256 aTokenUnderlyingAssetPrice = IAaveOracle(POOL_ADDRESSES_PROVIDER.getPriceOracle())
.getAssetPrice(asset());
return int256(aTokenUnderlyingAssetPrice.mulDiv(_rate(), 1e27, Math.Rounding.Floor)); // TODO: fix others
return int256(aTokenUnderlyingAssetPrice.mulDiv(_rate(), RAY, Math.Rounding.Floor)); // TODO: fix others
}

function _deposit(
Expand Down Expand Up @@ -234,15 +233,15 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
Math.Rounding rounding
) internal view virtual override returns (uint256) {
// * @notice assets * RAY / exchangeRate
return assets.mulDiv(1e27, _rate(), rounding); // TODO: fix others
return assets.mulDiv(RAY, _rate(), rounding);
}

function _convertToAssets(
uint256 shares,
Math.Rounding rounding
) internal view virtual override returns (uint256) {
// * @notice share * exchangeRate / RAY
return shares.mulDiv(_rate(), 1e27, rounding); // TODO: fix others
return shares.mulDiv(_rate(), RAY, rounding);
}

function _rate() internal view returns (uint256) {
Expand Down

0 comments on commit 721b437

Please sign in to comment.