-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
src/pool-cl/interfaces/IQuoter.sol
Outdated
/// @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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,got it
src/pool-cl/interfaces/IQuoter.sol
Outdated
error InvalidLockAcquiredSender(); | ||
error InvalidLockCaller(); | ||
error InvalidQuoteBatchParams(); | ||
error InsufficientAmountOut(); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/pool-cl/lens/Quoter.sol
Outdated
if (returnData.length == 0) revert LockFailure(); | ||
// if the call failed, bubble up the reason | ||
/// @solidity memory-safe-assembly | ||
assembly { |
There was a problem hiding this comment.
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") {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
src/pool-cl/lens/Quoter.sol
Outdated
using PathKeyLib for PathKey; | ||
|
||
/// @dev cache used to check a safety condition in exact output swaps. | ||
uint128 private amountOutCached; |
There was a problem hiding this comment.
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
src/pool-cl/lens/Quoter.sol
Outdated
int128[] memory deltaAmounts = new int128[](2); | ||
|
||
deltaAmounts[0] = -deltas.amount0(); | ||
deltaAmounts[1] = -deltas.amount1(); |
There was a problem hiding this comment.
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
src/pool-cl/lens/Quoter.sol
Outdated
} | ||
|
||
/// @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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
src/pool-cl/lens/Quoter.sol
Outdated
// only exactOut case | ||
if (amountOutCached != 0 && amountOutCached != uint128(zeroForOne ? deltas.amount1() : deltas.amount0())) { | ||
revert InsufficientAmountOut(); | ||
} |
There was a problem hiding this comment.
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 ?
I am not quite familiar with quoter, hopefully have more eyes on it @ChefMist @ChefSnoopy @chef-omelette |
src/pool-cl/interfaces/ICLQuoter.sol
Outdated
struct QuoteExactSingleParams { | ||
PoolKey poolKey; | ||
bool zeroForOne; | ||
address recipient; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
lgtm too, lets make sure github issues are created -- so we track the changes |
closing this since pancakeswap/pancake-v4-periphery#43 is merged |
No description provided.