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

Take command in router #261

Merged
merged 7 commits into from
Aug 4, 2024
Merged

Take command in router #261

merged 7 commits into from
Aug 4, 2024

Conversation

hensha256
Copy link
Contributor

No description provided.

@@ -128,69 +128,75 @@ contract PositionManager is
}

function _handleAction(uint256 action, bytes calldata params) internal virtual override {
if (action == Actions.INCREASE_LIQUIDITY) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this looks bad but i just split the command into a nested if for gas. If you view it in codespace itll make it much easier to see what i did lol.
its like:

if (action > settle) {
   ... all liquidity / mint / burn commands ...
} else {
   ... all payment commands ...
}

@@ -82,16 +82,14 @@ abstract contract DeltaResolver is ImmutableState {
/// @notice Calculates the amount for a take action
function _mapTakeAmount(uint256 amount, Currency currency) internal view returns (uint256) {
if (amount == Constants.OPEN_DELTA) {
return _getFullCredit(currency).toUint128();
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 think this was accidentally copied from the mapInputAmount function which returns a uint128

Comment on lines 91 to 95
function _mapInputAmount(uint128 amount, Currency currency) internal view returns (uint128) {
if (amount == Constants.CONTRACT_BALANCE) {
return currency.balanceOfSelf().toUint128();
} else if (amount == Constants.OPEN_DELTA) {
if (amount == Constants.OPEN_DELTA) {
return _getFullCredit(currency).toUint128();
}
return amount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function is now exactly the same as _mapTakeAmount() (minus casting)

  1. why did we get rid of amount == Constants.CONTRACT_BALANCE

  2. can we natspec why _getFullCredit is used for fetching input amounts? (i'm assuming its for multihop -- the inputs of an intermediate swap is the output (credit) of the previous step)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why did we get rid of amount == Constants.CONTRACT_BALANCE

I just cant see a time it will be used. The entire point in this function is for 1 usecase:

  • USDC traded on v2 for UNI. UNI is left in the router
  • Now we want to trade UNI for PEPE on v4 how do we do that?

Previously i thought we would do swap with input Constants.CONTRACT_BALANCE... and then do settle OPEN_DELTA. But Ive realised we're duplicating logic because you can do settle CONTRACT_BALANCE and then swap OPEN_DELTA.

Maybe its worth having both? idk just feels like a lot of options

@hensha256 hensha256 merged commit 60a983e into main Aug 4, 2024
3 checks passed
@hensha256 hensha256 deleted the take-in-router branch August 4, 2024 17:29
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