Skip to content
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
1 change: 1 addition & 0 deletions .cursor/commands/code-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Before I push this PR, please review all of your changes and identify any unused code, opportunities for refactoring, or areas where you could make the code cleaner and more maintable.
26 changes: 26 additions & 0 deletions .cursor/commands/optimize-performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Optimize Performance

Analyze the current code for performance bottlenecks and provide optimization recommendations. Focus on:

## Performance Analysis

- Identify slow algorithms and inefficient data structures
- Find memory leaks and excessive allocations
- Detect unnecessary computations and redundant operations
- Analyze database queries and API calls

## Optimization Strategies

- Suggest algorithm improvements and better data structures
- Recommend caching strategies where appropriate
- Propose lazy loading and pagination solutions
- Identify opportunities for parallel processing

## Implementation

- Provide optimized code with explanations
- Include performance impact estimates
- Suggest profiling and monitoring approaches
- Consider trade-offs between performance and maintainability

Focus on measurable improvements while maintaining code quality and readability.
26 changes: 26 additions & 0 deletions .cursor/commands/refactor-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Refactor Code

Please refactor the selected code to improve its quality while maintaining the same functionality. Focus on:

## Code Quality Improvements

- Extract reusable functions or components
- Eliminate code duplication
- Improve variable and function naming
- Simplify complex logic and reduce nesting

## Performance Optimizations

- Identify and fix performance bottlenecks
- Optimize algorithms and data structures
- Reduce unnecessary computations
- Improve memory usage

## Maintainability

- Make the code more readable and self-documenting
- Add appropriate comments where needed
- Follow SOLID principles and design patterns
- Improve error handling and edge case coverage

Provide the refactored code with explanations of the improvements made.
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,3 @@ jobs:
run: |
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
26 changes: 11 additions & 15 deletions contracts/Aavegotchi/facets/EscrowFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,45 +133,41 @@ contract EscrowFacet is Modifiers {
}

//old lendings
function fixOldLendingsAndSettleAlchemica(
uint256[] calldata _lendingIds,
address[] calldata _oldEscrows,
address[] calldata _alchemicaAddresses
) external onlyBaseRelayer {
require(_lendingIds.length == _oldEscrows.length, "EscrowFacet: LendingIds and OldEscrows length must match");
function fixOldLendingsAndSettleAlchemica(uint256[] calldata _lendingIds, address[] calldata _alchemicaAddresses) external onlyBaseRelayer {
for (uint256 i = 0; i < _lendingIds.length; i++) {
GotchiLending storage lending = s.gotchiLendings[uint32(_lendingIds[i])];
address escrow = s.aavegotchis[lending.erc721TokenId].escrow;

if (lending.completed == true && !lending.canceled) {
if (lending.completed == true) {
//claim directly from old escrow so far there is a balance

for (uint256 j = 0; j < _alchemicaAddresses.length; j++) {
address alchemicaAddress = _alchemicaAddresses[j];
uint256 balance = IERC20(alchemicaAddress).balanceOf(_oldEscrows[i]);
uint256 balance = IERC20(alchemicaAddress).balanceOf(escrow);

//check allowance
if (IERC20(alchemicaAddress).allowance(_oldEscrows[i], address(this)) < balance) {
CollateralEscrow(payable(_oldEscrows[i])).approveAavegotchiDiamond(alchemicaAddress);
if (IERC20(alchemicaAddress).allowance(escrow, address(this)) < balance) {
CollateralEscrow(payable(escrow)).approveAavegotchiDiamond(alchemicaAddress);
}
//split
uint256 ownerAmount = (balance * lending.revenueSplit[0]) / 100;
uint256 borrowerAmount = (balance * lending.revenueSplit[1]) / 100;
address owner = lending.originalOwner == address(0) ? lending.lender : lending.originalOwner;
if (ownerAmount > 0) {
LibERC20.transferFrom(alchemicaAddress, _oldEscrows[i], owner, ownerAmount);
LibERC20.transferFrom(alchemicaAddress, escrow, owner, ownerAmount);
}
if (borrowerAmount > 0) {
LibERC20.transferFrom(alchemicaAddress, _oldEscrows[i], lending.borrower, borrowerAmount);
LibERC20.transferFrom(alchemicaAddress, escrow, lending.borrower, borrowerAmount);
}
if (lending.thirdParty != address(0)) {
uint256 thirdPartyAmount = (balance * lending.revenueSplit[2]) / 100;
LibERC20.transferFrom(alchemicaAddress, _oldEscrows[i], lending.thirdParty, thirdPartyAmount);
LibERC20.transferFrom(alchemicaAddress, escrow, lending.thirdParty, thirdPartyAmount);
}
}
}
//ongoing lendings that do not have revenue tokens
else if (!lending.completed && !lending.canceled && lending.timeCreated > 0) {
//set the revenue tokens from storage
else if (!lending.completed) {
//set the revenue tokens to storage
if (lending.revenueTokens.length == 0) {
lending.revenueTokens = _alchemicaAddresses;
}
Expand Down
Loading
Loading