MoralisWeb3 / demo-apps

BSD 2-Clause "Simplified" License
394 stars 606 forks source link

Swap Monitor Issue #9

Closed netindicium closed 3 years ago

netindicium commented 3 years ago

Hello there,

I'm following the instructions on the Swap Monitor, and I was able to get it working, but the daily cumulative stats are not working and this is the error on the console, any idea on what would it be ?

Thank you, A2 image

jermay commented 3 years ago

Hrm it works for me when I run it locally. Have you added the event plugin and the Cloud Function trigger in your Moralis Server? These are located in the cloud-functions.js file. If so, is there data in the DaiWethSwapVolume60 collection? If not the stats query might not be returning any data.

This is line 175: https://github.com/MoralisWeb3/demo-apps/blob/74ca6a8c26da0ddd6e6f8e25a1f2b686a4db3741/swap-monitor/index.js#L175

The renderStats() function is called from 2 places:

Hope that helps.

EDIT: It occurrs to me the stats query will probably be empty the very first time it's run with a brand new server if there have been no swaps yet since the event plugin was added. After a couple minutes that would sort itself out though as the DAI/wETH pair is pretty active.

netindicium commented 3 years ago

I have added the Plugin and the Cloud Function as stated on the readme. image image

I can see the data on the dashboard and on index.html, but no the aggregated stats. image image

Any idea what might be ? Thanks.

jermay commented 3 years ago

My bad! Thanks for posting the screenshots. This is the problem:

const pipeline = [ /* code omitted */ ];

Note the /* code omitted */ comment. I forgot to mention the code for Cloud Functions was supposed to be copied from the cloud-functions.js file... not the README. I will update the README to make this clear.

The pipeline object is what defines the things to be aggregated. It's a little long to be copying into the docs directly, but if what it's doing is confusing I can add additional explanations to the README. The complexity comes from converting the string values in the table into numbers, which is rather awkward in the MongoDB syntax the queries use.

jermay commented 3 years ago

Is this better? https://github.com/MoralisWeb3/demo-apps/blob/9-bug-swap-trigger-docs/swap-monitor/README.md

I can clarify further if needed.

netindicium commented 3 years ago

That fixed it, thanks a lot. I did had to start a new instance, for some reason the last one would not respond.

Could you point me in the right direction if I wanted to to tray another token, for example WBTC ?

Thanks again.

jermay commented 3 years ago

Cool. I'll close this issue then.

If you wanted to track another swap pair you'd need to: