Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Market Reserve Automation #456

Open
wants to merge 46 commits into
base: main
Choose a base branch
from

Conversation

ElliotFriedman
Copy link
Collaborator

No description provided.

Copy link

openzeppelin-code bot commented Jan 9, 2025

Market Reserve Automation

Generated at commit: 40f3d9402eb9afad194666b6143422c905b352de

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
3
5
0
12
45
65
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

src/market/ReserveAutomation.sol Outdated Show resolved Hide resolved
src/market/ReserveAutomation.sol Outdated Show resolved Hide resolved
src/market/ReserveAutomation.sol Outdated Show resolved Hide resolved
src/market/ReserveAutomation.sol Outdated Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
@ElliotFriedman ElliotFriedman marked this pull request as ready for review January 11, 2025 03:17
Signed-off-by: Elliot <[email protected]>
… cycles and making purchases in each

Signed-off-by: Elliot <[email protected]>
.InitParams({
recipientAddress: holdingDeposit,
wellToken: xWellProxy,
reserveAsset: _addresses.getAddress(underlyingName),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced with mToken.getUnderlying(), making the file more generic so we can reuse it for future deployments to other chains

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure those changes can be made, but Halborn won't be auditing the deployment script anyway so it's fine to leave as is for the Base deployment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the current repo folder structure I believe it's makes more sense to keep this file inside /script and rename to DeployReserveAutomation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chainink oracle, market and underlying address names could be placed in a json config file so we could easily deploy the reserve automation to any chain


/// @notice array of mToken names to deploy automation for
function _getMTokens() internal pure returns (string[] memory) {
string[] memory tokens = new string[](12);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to make the token list an argument for the deploy and validate functions, so we can reuse it to deploy on other chains

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should differentiate between what is a nice to have vs what is a must have for this audit. since they won't be reviewing deployment scripts this should be non blocking.

src/market/AutomationDeploy.sol Show resolved Hide resolved
src/market/ERC20Mover.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Outdated Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved
}

/// normalize decimals up to 18 if reserve asset has less than 18 decimals
if (reserveAssetDecimals != 18) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we have checks to make sure this is never > 18 we could do < instead

Suggested change
if (reserveAssetDecimals != 18) {
if (reserveAssetDecimals < 18) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you going to remediate this?

src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Show resolved Hide resolved

/// if the reserve asset has non 18 decimals, shrink down the amount of
/// reserve asset received to the actual amount
if (reserveAssetDecimals != 18) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we have checks to make sure this is never > 18 we could do < instead

Suggested change
if (reserveAssetDecimals != 18) {
if (reserveAssetDecimals < 18) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you going to remediate this?

src/market/ReserveAutomation.sol Show resolved Hide resolved
,
uint80 answeredInRound
) = AggregatorV3Interface(oracleAddress).latestRoundData();
bool valid = price > 0 && answeredInRound >= roundId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also checks that updatedAt != 0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Gautlet is going to report this if we don't add the check

src/market/ReserveAutomation.sol Show resolved Hide resolved
src/market/ReserveAutomation.sol Outdated Show resolved Hide resolved
Comment on lines 557 to 568
if (
startPeriodTimestampCachedChainlinkPrice[startTime].wellPrice == 0
) {
(int256 wellPrice, ) = getPriceAndDecimals(wellChainlinkFeed);
startPeriodTimestampCachedChainlinkPrice[startTime]
.wellPrice = wellPrice;

(int256 reservePrice, ) = getPriceAndDecimals(reserveChainlinkFeed);
startPeriodTimestampCachedChainlinkPrice[startTime]
.reservePrice = reservePrice;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we move this above line 534 amountOut = getAmountReservesOut(amountWellIn); we don't need to call (int256 price, uint8 decimals) = getPriceAndDecimals(oracleAddress); in the getNormalizedFunction as we will be sure there is a cached price

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice optimization

Copy link

Compiling 4 files with Solc 0.8.19
Solc 0.8.19 finished in 8.49ms
Compiler run successful!
Script ran successfully.
Gas used: 35208166

If you wish to simulate on-chain transactions pass a RPC URL.

address oracleAddress,
int256 cachedPrice
) internal view returns (uint256 normalizedPrice) {
(int256 price, uint8 decimals) = getPriceAndDecimals(oracleAddress);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(int256 price, uint8 decimals) = getPriceAndDecimals(oracleAddress);

}

/// normalize decimals up to 18 if reserve asset has less than 18 decimals
if (reserveAssetDecimals != 18) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you going to remediate this?


/// if the reserve asset has non 18 decimals, shrink down the amount of
/// reserve asset received to the actual amount
if (reserveAssetDecimals != 18) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you going to remediate this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants