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

feat: Add Quoter for pool-cl #39

Closed

Conversation

ChefCupcake
Copy link
Contributor

No description provided.

/// @notice For each pool also tells you the number of initialized ticks loaded and the sqrt price of the pool after the swap.
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
/// to compute the result. They are also not gas efficient and should not be called on-chain.
interface IQuoter {
Copy link
Collaborator

@chefburger chefburger Jun 18, 2024

Choose a reason for hiding this comment

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

can we do ICLQuoter since bin pool will also have quoter, this helps to avoid confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok,got it

error InvalidLockAcquiredSender();
error InvalidLockCaller();
error InvalidQuoteBatchParams();
error InsufficientAmountOut();
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems error InvalidLockCaller(); and error InvalidQuoteBatchParams(); are unused ?

Copy link
Contributor Author

@ChefCupcake ChefCupcake Jun 18, 2024

Choose a reason for hiding this comment

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

removed unused error

using SafeCast for int24;

function getPoolAndSwapDirection(PathKey memory params, Currency currencyIn)
internal
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider reusing the same one with SwapRouterBased ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems I can't reuse SwapRouterBase because I don't implement _pay function

Copy link
Collaborator

Choose a reason for hiding this comment

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

nvm, will do it in separate PR pancakeswap/pancake-v4-periphery#41

if (returnData.length == 0) revert LockFailure();
// if the call failed, bubble up the reason
/// @solidity memory-safe-assembly
assembly {
Copy link
Collaborator

@chefburger chefburger Jun 18, 2024

Choose a reason for hiding this comment

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

for assembly block pls use if possible

        assembly ("memory-safe") {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it

using PathKeyLib for PathKey;

/// @dev cache used to check a safety condition in exact output swaps.
uint128 private amountOutCached;
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider rewriting with transient storage

int128[] memory deltaAmounts = new int128[](2);

deltaAmounts[0] = -deltas.amount0();
deltaAmounts[1] = -deltas.amount1();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Discuss: should we flip the sign here ? why not just align it the original v4-core return

}

/// @dev Execute a swap and return the amounts delta, as well as relevant pool state
/// @notice if amountSpecified > 0, the swap is exactInput, otherwise exactOutput
Copy link
Collaborator

@chefburger chefburger Jun 18, 2024

Choose a reason for hiding this comment

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

nit: update comment i.e. if amountSpecified < 0, the swap is exactInput, otherwise exactOutput

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

// only exactOut case
if (amountOutCached != 0 && amountOutCached != uint128(zeroForOne ? deltas.amount1() : deltas.amount0())) {
revert InsufficientAmountOut();
}
Copy link
Collaborator

@chefburger chefburger Jun 18, 2024

Choose a reason for hiding this comment

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

Discuss: I guess this only happens when the swap is partially fulfilled. And did a quick glance i found that in v3 we have similar logic. My question is why do we only check partial fulfill for exact out case ?

@chefburger
Copy link
Collaborator

I am not quite familiar with quoter, hopefully have more eyes on it @ChefMist @ChefSnoopy @chef-omelette

@ChefMist ChefMist self-requested a review June 18, 2024 09:28
struct QuoteExactSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like this is unused param

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i will removed recipient in QuoteExactSingleParams

@pancakeswap pancakeswap deleted a comment from ChefCupcake Jun 19, 2024
chefburger
chefburger previously approved these changes Jun 19, 2024
Copy link
Collaborator

@chefburger chefburger left a comment

Choose a reason for hiding this comment

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

lgtm, transient storage optimization can be done in separate PR

@ChefMist
Copy link
Collaborator

lgtm too, lets make sure github issues are created -- so we track the changes

@ChefMist
Copy link
Collaborator

closing this since pancakeswap/pancake-v4-periphery#43 is merged

@ChefMist ChefMist closed this Jun 27, 2024
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.

3 participants