Search code examples
ethereumsolidity

What Mapping dot update is?


Trying to get the meaning of Uniswap v3-core, I rammed into an unexpected Solidity syntax which I cannot comprehend, so I need someone who could explain it.

the thing is about UniswapV3Pool.sol contract which can be found at both etherscan.io and github of the project.

More to the point, there are the following lines:

406             flippedLower = ticks.update( 
407                 tickLower, 
408                 tick, 
409                 liquidityDelta, 
410                 _feeGrowthGlobal0X128, 
411                 _feeGrowthGlobal1X128, 
412                 secondsPerLiquidityCumulativeX128, 
413                 tickCumulative, 
414                 time, 
415                 false, 
416                 maxLiquidityPerTick 
417             );

but the ticks variable is just a mapping:

 93     mapping(int24 => Tick.Info) public override ticks;
  1. So I do not get it. What update is called there?
  2. There are some similar puzzling things, such as
386         position = positions.get(owner, tickLower, tickUpper);

where

 97     mapping(bytes32 => Position.Info) public override positions;

There is no get on a mapping as well. What is going on?


Solution

  • UniswapV3Pool.sol extends a specific mapping type by functions defined in the Tick library:

    using Tick for mapping(int24 => Tick.Info);
    

    The Tick library then defines the update() function (GitHub source).


    Same goes with the positions mapping extended by the Position library (GitHub source), as well as few others.

    using Position for mapping(bytes32 => Position.Info);
    

    Here's the Solidity docs for using ... for: https://docs.soliditylang.org/en/v0.8.11/contracts.html#using-for