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

SwapRouterBase _pay method is confusing #67

Open
ChefMist opened this issue Jul 24, 2024 · 0 comments
Open

SwapRouterBase _pay method is confusing #67

ChefMist opened this issue Jul 24, 2024 · 0 comments

Comments

@ChefMist
Copy link
Collaborator

ref: https://github.com/pancakeswap/pancake-v4-periphery/blob/main/src/SwapRouterBase.sol

Originally the implementation is as follows:

function _payAndSettle(Currency currency, address msgSender, int128 settleAmount) internal virtual {
  _pay(currency, msgSender, address(vault), uint256(uint128(settleAmount)));
  vault.settleAndMintRefund(currency, msgSender);
}

function _pay(Currency currency, address payer, address recipient, uint256 amount) internal virtual;

Then we made some changes in v4-core and the new implementation is as follows:

function _payAndSettle(Currency currency, address msgSender, int128 settleAmount) internal virtual {
  if (currency.isNative()) {
    vault.settle{value: uint256(uint128(settleAmount))}(currency);
  } else {
    vault.sync(currency);
    _pay(currency, msgSender, address(vault), uint256(uint128(settleAmount)));
    vault.settle(currency);
  }
}

function _pay(Currency currency, address payer, address recipient, uint256 amount) internal virtual;

Problem

Problem 1: its not clear for implementation to know how to implement _pay for example:

  1. _pay is only called when we sync non native currency
  2. address recipient is always vault

Suggestion to get feedback

rename the _pay

// from
_pay(Currency currency, address payer, address recipient, uint256 amount)

// to
_payNonNativeToVault(Currency currency, address payer, address vault, uint256 amount);
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

No branches or pull requests

1 participant