This transaction transaction describes Swap event:
This means that the effective trade rate is:
Meanwhile, this is the last Sync event before Swap and Sync event after Swap.
The first one describes rate
32,118 and the second one
24,414. Neither are equal or close to
What's the relationship between Swap events and reserve values and how was the Swap rate determined?
For what it is worth, I was able to calculate similar output using formula from this answer:
reserve0=95594454080845 reserve1=3070347989941780637 amount0_in=14067900000000 round((reserve1 * amount0_in)/(reserve0 + amount0_in))
393875809522191052, which is close to the expected
393017164305296368, though not exactly the same.
The difference appears to be 0.21%:
a=393,875,809,522,191,052 b=393,017,164,305,296,368 ((a-b)/((a+b)/2))*100=0.21
That 0.21% resembles pancakeswap fee. However, I cannot figure out how to incorporate that into the original formula to get the exact same figure.
I even tried to apply the logic from
getAmountOut, but that still gives a different number:
amount_in_with_fee=amount_in*998 = 14,039,764,200,000,000 numerator=amount_in_with_fee*reserve1 = 43,106,961,790,726,571,871,605,795,400,000,000 denominator=reserve0*1000+amount_in_with_fee = 109,634,218,280,845,000 amount_out=round(numerator/denominator) = 393,188,937,420,080,150