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

CurrencySettler -> DeltaResolver #186

Merged
merged 12 commits into from
Jul 25, 2024
Merged

CurrencySettler -> DeltaResolver #186

merged 12 commits into from
Jul 25, 2024

Conversation

hensha256
Copy link
Contributor

@hensha256 hensha256 commented Jul 23, 2024

  • Currently the currency settler is very generic which is adding gas. We often just pass false or true as the final parameter in meaning that really we should just be writing more efficient functions.
  • For the rare cases when we truly want to pass in a boolean, the calling contract can handle that
  • Adds safe transfer to make the library secure

src/PositionManager.sol Outdated Show resolved Hide resolved
src/libraries/CurrencySettler.sol Outdated Show resolved Hide resolved
Copy link
Member

@snreynolds snreynolds left a comment

Choose a reason for hiding this comment

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

We should add tests! Bit odd this has no testing updates needed & since we're modifying it quite a bit from core it should have its own test file imo in periphery

@hensha256 hensha256 changed the title Simplify currency settler CurrencySettler -> DeltaResolver Jul 24, 2024
src/PositionManager.sol Outdated Show resolved Hide resolved
/// @param token The token to settle. This is known not to be the native currency
/// @param payer The address who should pay tokens
/// @param amount The number of tokens to send
function _pay(Currency token, address payer, uint256 amount) internal virtual;
Copy link
Member

Choose a reason for hiding this comment

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

lol i wish we could call this send ...

Copy link
Member

Choose a reason for hiding this comment

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

note that this contract must be approved/permitted to pay on behalf of the payer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that this contract must be approved/permitted to pay on behalf of the payer?

not necessarily true though... it could be that this function chooses to pull tokens out of compound to pay the debt, or any other random way they want to pay.

src/base/DeltaResolver.sol Outdated Show resolved Hide resolved

/// @notice Abstract contract used to sync, send, and settle funds to the pool manager
/// @dev Note that sync() is called before any erc-20 transfer in `settle`.
abstract contract DeltaResolver is ImmutableState {
Copy link
Member

Choose a reason for hiding this comment

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

hm the inheriting structure in the base PositionManager contract now inherits two contracts(SafeCallback and this one) that both also inherit ImmutableState? Any way we can avoid that?

Copy link
Member

Choose a reason for hiding this comment

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

maybe we need to expose a virtual function poolManager() that is overridden in the main base contract ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally think its fine that they both inherit it. The way inheritance works in solidity means it only actually gets inherited once, and it allows us to keep all the contracts super modular and not worry about each other

// implementation of abstract function DeltaResolver._pay
function _pay(Currency token, address payer, uint256 amount) internal override {
// TODO this should use Permit2
ERC20(Currency.unwrap(token)).safeTransferFrom(payer, address(poolManager), amount);
Copy link
Member

Choose a reason for hiding this comment

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

wondering if we should also support transfer not just transferFrom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh this was just a draft function to get posm to functional-parity with where it was before this PR. I'm assuming youll redo the _pay implementation to use Permit2.
As for whether posm needs transfer (universal router does). That depends if posm will ever custody funds that need to go into another position? I dont think so because you just leave them in pool manager and the deltas handle it all. So I would imagine posm only needs transferFrom unless you have a counter example?

Copy link
Member

Choose a reason for hiding this comment

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

we may want to consider supporting transfer? but youre right we dont need it in this PR

Copy link
Member

@snreynolds snreynolds left a comment

Choose a reason for hiding this comment

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

Nice! Looks great

My only final comment is whether we should update core at all with these patterns? IK we have CurrencySettler in core which is mostly just used for testing purposes but I think it was nice that core/periphery had the same "infra" - I believe its why merging core into periphery became easier

@hensha256
Copy link
Contributor Author

yeah thats fair. I could make an update PR to core's currency settler to look like this too

@snreynolds snreynolds self-requested a review July 25, 2024 18:15
@snreynolds snreynolds merged commit 1c1d153 into main Jul 25, 2024
3 checks passed
@snreynolds snreynolds deleted the redo-currency-settler branch July 25, 2024 18:16
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