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

minor optimisations #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ contract LendingPool is OwnableUpgradeable, ERC721Upgradeable, Clone {
}

function calculateInterest(uint priceOfNextItems) internal view returns (uint interest) {
uint borrowed = priceOfNextItems/2 + totalBorrowed;
uint borrowed = (priceOfNextItems >> 1) + totalBorrowed;
Copy link
Member

Choose a reason for hiding this comment

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

good point, does this have any side effects?

Copy link
Author

Choose a reason for hiding this comment

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

DIV operator costs 5 gas while SHR costs 3 gas, so that saves 2 gas. And if that's called multiple times it'd sure amount to much.

uint variableRate = (borrowed * maxVariableInterestPerEthPerSecond) / (address(this).balance + totalBorrowed);
return minimumInterest + variableRate;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/ListNfts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract ListNfts {
owner,
balance
);
if (tokenId >= start && tokenId < end) {
if (tokenId < end && tokenId >= start) {
Copy link
Member

Choose a reason for hiding this comment

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

this contract is never called on-chain

nfts[length] = tokenId;
unchecked {
// unchecked: always less than end minus start
Expand Down
11 changes: 8 additions & 3 deletions contracts/LlamaLendFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ contract LlamaLendFactory is Ownable {
}

function emergencyShutdown(address[] calldata pools) external onlyOwner {
for(uint i = 0; i < pools.length; i++){
LendingPool(pools[i]).emergencyShutdown();
uint length = pools.length;
Copy link
Member

Choose a reason for hiding this comment

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

i expect to never call this method, and if i call it will be one-off so gas doesnt matter much

uint i = 0;
while(i < length){
LendingPool(pools[i]).emergencyShutdown();
unchecked {
i++;
}
}
}

Expand All @@ -51,4 +56,4 @@ contract LlamaLendFactory is Ownable {
}

receive() external payable {}
}
}