Skip to content

Conversation

@luchobonatti
Copy link
Member

@luchobonatti luchobonatti commented Jun 3, 2025

Refactor getQuote and buildSwapCallData to use Pool instance and add slippage

Overview

This PR refactors getQuote to use a Pool instance directly and adds slippage tolerance handling to buildSwapCallData.

Changes

  • Modified getQuote to accept Pool instance instead of individual parameters
  • Added slippageTolerance parameter to buildSwapCallData with default 0.5% (50 bps)
  • Integrated getQuote with buildSwapCallData for automatic minimum output calculation

Technical Details

  • getQuote now uses pool.poolKey directly instead of constructing it
  • buildSwapCallData calculates amountOutMin using slippage if not provided
  • Added type assertions for addresses to ensure 0x${string} format

Testing

Updated test suite to:

  • Use Pool instance in all test cases
  • Mock getQuote to avoid real contract calls
  • Test slippage tolerance calculation

Usage Example

const params = {
  tokenIn: USDC_ADDRESS,
  amountIn: BigInt(1000000),
  slippageTolerance: 50, // 0.5%
  pool: usdcWethPool
};

const calldata = await buildSwapCallData(params, sdkInstance);

@luchobonatti luchobonatti changed the base branch from main to feat/buildSwapCallData June 3, 2025 18:53
@luchobonatti luchobonatti merged commit 304b2b2 into feat/buildSwapCallData Jun 3, 2025
1 check passed
@luchobonatti luchobonatti deleted the fix/getQuote branch June 3, 2025 18:56
@github-actions
Copy link

github-actions bot commented Jun 3, 2025

🎉 This PR is included in version 1.0.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants