# What's the role of blockTimestampLast in determining price?

I am looking up `getReserves` result of a pair contract.

It produces the following result:

``````Result {
_reserve0: '3219645034999541693795',
_reserve1: '86735629384854886759666',
_blockTimestampLast: '1621295406'
}
``````

This specific pair contract establishes CAKE/BUSD price, i.e. It tells us that 1 CAKE buys USD 26.94 (`86735629384854886759666/3219645034999541693795=26.94`).

As far as I understand, this is the spot price (current price in the marketplace), and it will not (cannot ?) change until the next block.

Assuming that I am right about everything else, what is `_blockTimestampLast` for?

• The price can change. It changes every time a trade was made (even in one block)
– jjj
May 18, 2021 at 22:41
• How does one calculate price change after a trade within a block? May 18, 2021 at 22:42
• The EVM works on transactions. It does not care about what block they are in (slightly simplified). The variables of all smart contracts that are involved are updated in the EVM (the pool, both erc20), when the transaction is executed. So the price is always calculated the same way, just by looking at the reserves. To be honest, I don't exactly know about pancakeswap, but about other pool based exchanges. On others the product of both reserves must stay constant when you exchange, this means that you don't exchange for that exact price, but that the price also depends on how much you exchange.
– jjj
May 18, 2021 at 22:56
• Fixing the price within one block would also allow for massive manipulation of the price, because you can exchange until one reserve is nearly empty without any additional costs. In the next block the price would then be fixed at an absurd level that could be exploited
– jjj
May 18, 2021 at 22:59
• The price you see outside of the block chain is always the price at the end of one block (because those are the valid units). But inside the blockchain it changes for every transaction.
– jjj
May 18, 2021 at 23:04

So for `getReserves()`:
• So just to clarify, the spot price is deducted `token0/token1` and `block.timestamp` does not play any role in this. It is only there to indicate when the last swap happened. May 18, 2021 at 14:18
• `_blockTimestampLast` is used to work out the time elapsed between updates of the cumulative prices (see line 373 in the contract) - basically to check that some time has actually elapsed. (I'm not sure why they've used `block.timestamp` instead of `block.number`.) May 18, 2021 at 14:25