I'm trying to write some Javascript code to query Fantom DEXes to find out the price wFTM in various wFTM / USDC
liquidity pools and I'm a bit lost as to what contract method to call.
I'm starting with Spookyswap and I'm thinking what I need to do is first get a reference to the Factory Contract, and then call getPair()
on it with the contract addresses for wFTM (0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83
) and USDC (0x04068DA6C83AFCFA0e13ba15A6696662335D5B75
)
https://ftmscan.com/address/0x152ee697f2e276fa89e96742e9bb9ab1f2e61be3#readContract
When I call that method, I get a reference to this contract
https://ftmscan.com/address/0x2b4C76d0dc16BE1C31D4C1DC53bF9B45987Fc75c#readContract
which has two variables
price0CumulativeLast
price1CumulativeLast
which logically seem like the variables I want, but I'm not really sure that's correct and I have no idea how to translate them into USDC.
There's probably something very obvious I'm not grokking, so any help will be much appreciated. This is my first attempt to learn web3 by creating something on my own.
Thanks!