CrocImpact Contract

The CrocImpact contract provides a simple way to calculate the price impact, and resulting token flows associated with a hypothetical swap.

The CrocImpact is deployed at the following address:

Mainnet: 0x3e3EDd3eD7621891E574E5d7f47b1f30A994c0D0

Scroll: 0xc2c301759B5e0C385a38e678014868A33E2F3ae3

Note that calling this contract does not execute a swap. It merely returns the token quantities that would be paid/received if a swap was to be executed at the current chain state. If being calculated off-chain, note that the it's possible that the state of the curve could change between the time the function is called and the time the actual swap transaction arrives on-chain.

The contract has a single public method:

 function calcImpact (
   address base, 
   address quote,
   uint256 poolIdx, 
   bool isBuy, 
   bool inBaseQty, 
   uint128 qty, 
   uint16 tip,
   uint128 limitPrice, 
   public view 
   returns (int128 baseFlow,
            int128 quoteFlow,
            uint128 finalPrice)

The parameter arguments are as follows:

  • base - The address of the base token or virtual token

  • quote - The address of the quote token or virtual token

  • poolIdx - The arbitrary index of the pool type the user is swapping on. The primary pool index on mainnet deployment is 420.

  • isBuy - True if the user wants to pay base token and receive quote token. False if the user wants to receive base token and pay quote token

  • inBaseQty - True if the quantity field is fixed in base token, false in quote token. (Regardless of whether they're being paid or receive)

  • qty - The quantity of the fixed side of the swap.

  • tip - If zero the user accepts the standard swap fee rate in the pool. If non-zero the user agrees to pay up to this swap fee rate to the pool's LPs. In standard cases this should be 0.

  • limitPrice - Represents the worse possible price the user is willing to accept. If buying this represents an upper bound.

The return value is the following:

  • baseFlow - The base side token flows the swap would pay/receive to the caller. Negative quantity indicate a credit received by the user from the pool. Positive quantity indicates a debit paid to the pool by the user.

  • quoteFlow - The quote side token flows the swap would pay/receive to the caller. Same negative/positive convention as baseFlow return value

  • finalPrice - The final price the pool would arrive at after the swap was executed. Note this is the post-swap pool price, not the realized price the swapper pays. The latter can be calculated by dividing base and quote token flows from above.

More information on type conventions for these arguments can be found on Type Conventions page

Last updated