Overview of Covalent API features: Solving the Puzzle Paladin -the part of Dungeons & Data — 1INCH Network hackaton as a case study — Round 3

Jason Win
6 min readMay 30, 2021

The last round of this series of puzzles was ambiguous for me. I completed one part of the task fairly quickly, but I had to tinker with the second part.

The peculiarity of this series is that we work on the Ethereum network, where a huge amount of data has accumulated. A couple of times my computer froze and gave a critical error when processing a Covalent API request.

But I still did it, and in today’s review I will show my solution.

Main Task 
Find the average swap amount for swaps with ETH as the source token. Find the referrer referenced in the most swaps event.

The task is again divided into steps, with a detailed explanation.

Step 1: Find the average swap amount for swaps with ETH as the source token.1. Find the `1inch Network v2` contract address
2. Find the topic hash for event `Swapped`.
3. Find the average swap amount for swaps with ETH as the source token (data between 24th April and 1st May) (Unit is ETH and precision is 10^-4 ).

First of all, we find the address of 1inch Network v2, all this is easily done in the search bar https://etherscan.io/.

Address found:

0x111111125434b319222CdBf8C261674aDB56F3ae

Now find the Topic Hash for the “Swapped” event. To do this, use one of the Covalent API tools — Topic Calculator.

Go here https://www.covalenthq.com/docs/tools/topic-calculator
in the search bar, enter our address from the previous step and click “Get Events”.

Just below, you will see the Topic Hash we need.

Copy it and save it in your notes.
0x76af224a143865a50b41496e1a73622698692c565c1214bc862f18e22d829c5e

Now we need to collect data using the Covalent API.

Go here: https://www.covalenthq.com/docs/api/#overview

and we find the familiar section Get Log events by topic hast (es).

Please note that we are given a period in which to search for information. From April 24 — May 1. As in previous quests, we search for dates by blocks in the network. In the Ethereum blockchain, you can find it here: https://etherscan.io/blocks

I found the right blocks:

12299579 — April 24
12344944 — May 1

The request in the Covalent API will look like this:

As you can see, I used all the data that was found in the previous steps.

After copying the resulting data to Excel, I ordered it by columns and got 75,373 rows.

Task 3, in step 1, reads:Find the average swap amount for swaps with ETH as the source token (data between 24th April and 1st May) (Unit is ETH and precision is 10^-4 )

And as usual, you had to be very careful to filter out all the conditions correctly. In this case, I had to first filter out all the swap amounts, and then make a selection only for ETH. Source Token is the SrcToken data in my table and it was impossible to ignore this condition. After a while, I finally found the right path.

First, we filter the data by the value “amount” and copy it to a separate sheet.

We get 6852 results. However, this is not all. Now we need to select from this data array the ones that were made with ETH.

To do this, filter the data in the main table by the value “src Token”

And copy this data to a separate sheet, next to the previous ones. It should look something like this.

The last step remains. You need to filter the numeric values by the ETH address. To do this, select filter by 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

Finally, we got the necessary data, I got 3457 lines. Now it remains to find the average value for this data. You can do it in different ways, but the easiest way is to use the AVERAGE formula.

I found this value and according to the conditions, I have to use 4 decimal places. It turned out like this:

We found the first part.

25626

Step 2: Find the referrer referenced in the most swaps. 1inch offers a referral system. The referrer address is a parameter of the `Swap` event.1. Find the `1inch Network v2` contract address
2. Find the topic hash for event `Swapped`.
3. Find the referrer address which appear the most between 24th April and 1st May. Enter the number of transactions which this referrer address appear.

The second part of the code, we need to look in the same data array that we already have. Since we can see that all the data is the same, there is no need to make a new request to the Covalent API, we can work with our data in Excel.

In the second step, we need to find the referrer address that appears most often in the transaction history. To do this, we filter the data again, but this time by the value “referrer”.

If you quickly run your eyes over the first hundred data, it becomes obvious that the address 0x382ffce2287252f930e1c8dc9328dac5bf282ba1 appears most often in transactions.

It remains to make sure of this. To do this, we search for this address throughout the document.

You need to wait a little while until the program finds all the cells with this address. As a result, I see the following:

We found the second part of code
4480

In the last step, we have another instruction:

Your secret room with the next task will be unlocked at the website: https:// dnd.covalenthq.com/{ethValue}{numberOfTransactions}
e.g If your answer is 1.6543 and 4321 the url will be `https://dnd.covalenthq.com/165434321`

And so we check our solution:

https://dnd.covalenthq.com/256264480

I always get excited when I see the secret room page open! Amazing feeling!

At the end, you will find a simple puzzle on the knowledge of people from Covalent and 1inch.

You need to put the portrait and the correct inscription in front of it. If you did it correctly, the picture will turn green.

The page is still available, test your knowledge!

The next series of puzzles has come to an end. As always, it was very interesting and very informative!

I would like to say thank you to Covalent and 1inch for this hackathon, and also thank the author of this quest separately!

I look forward to new activities and interesting events!

Friends, learn the Covalent API, this is the future of blockchain analytics!

--

--