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

Add flash lending functionality #10

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

heytdep
Copy link

@heytdep heytdep commented Dec 9, 2024

tackles #7

This is not yet tested but should work. Will be adding more context on the issue.

Copy link
Contributor

@mootz12 mootz12 left a comment

Choose a reason for hiding this comment

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

Minor feedback to keep action switch statement more consistent between actions.

Testing this will be tricky, we will need to add a MockErc3156 contract into test-utils

Comment on lines +372 to +377
// the actual difference between the flash borrow and standard borrow.
if !flash {
actions.add_for_pool_transfer(token_address, transfer_amount);
} else {
actions.add_flash_borrow(token_address, transfer_amount);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be clearer to have the individualized code within the switch statement instead of in this function

} else {
actions.add_flash_borrow(token_address, transfer_amount);
}
*check_health = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

we should leave this line in the switch statement as well, to follow suit with how other external functions are called, like auction::fill

@@ -48,6 +49,25 @@ pub fn execute_submit(
panic_with_error!(e, PoolError::InvalidHf);
}

// deal with potential flash lending before dealing with the other transfers.
// tbd: do we want to allow for multiple flash loans? There doesn't seem to be a risk in it so currently enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

The only real use case I can imagine for this would probably not benefit from multiple contracts being invoked, however.

It seems more likely that a user would flash borrow multiple tokens to 1 contract to then invoke. However, this is would break moderc3156 interface.

IMO we can leave for now, but it's worth some additional thought.

cc: @markuspluna

@heytdep
Copy link
Author

heytdep commented Dec 13, 2024

@mootz12 thanks for reviewing.

  1. will put everything in the switch statement. Still don't think it's the best solution since it's really verbose but I agree it makes the code more straightforward and similar to the existing one.
  2. about the flash loan interface, I'm open to changing it or adding a new functions. Might be good to brainstorm on that end. Probably worth it to explore multi-token flash loans. Due to the way requests are built though this seems tricky if we don't want to accept an array for all requests' asset field (I wouldn't do this tbh) but I haven't thought too much about it.

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