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

Jason Win
7 min readMay 28, 2021

Hello everybody!

The next Covalent hackathon is coming to an end, which means that you are waiting for reviews of new puzzles and their solutions!

If you’re interested, you can check out the reviews for past rounds:

#OneMillionWallets Avalanche Wallet Puzzle Challenge:

Part 1.

Part 2.

Part 3.

This time, Covalent’s partner is the most popular DEX aggregator — 1inch!

I want to note that this stage also consists of three puzzles, but I have managed to solve only one so far.

I started the first one too late and didn’t have enough time to figure it all out. The second I managed to solve, though not without difficulty, and the third I have not yet started, but I will try to do it in the near future.

In general, I can note that this stage of the puzzles looks a little more complicated. In addition to working with the Covalent API, you need to connect logic and some analytics. However, this is of particular interest to me, because it is in the right hands that the Covalent API becomes particularly valuable and necessary.

So, today’s review of the second round of Puzzle Paladin.

Main Task.Calculate the fee percentage (weighted average) using the`DefaultFeeVoteUpdate` events on the 1inch default DAO for the month of April. Important note : We will use data from 1st April to 1st May for this puzzle.Resources:- [Covalent API Docs](https://www.covalenthq.com/docs/api/#overview)- [1Inch Website DAO](https://app.1inch.io/#/1/dao/governance?action=stake)

At first glance, as usual, everything looks confusing and incomprehensible. But the author of the puzzle, left us small hints in the form of steps.

Step 1.Find the 1INCH contract address that has all default DAO methods.

Find a 1inch contract? What could be easier?

I also thought so and first looked for the address of the 1inch token, but it turned out to be the wrong solution. Once again, I was let down by inattentive reading of the task. It is not for nothing that we are told about the DAO methods in this contract and even specify a link.

By clicking on the link https://app.1inch.io/#/1/dao/governance?action=stake I carefully read the description of how it works and realized that in this case I am interested in the 1 INCH liquidity protocol contract.

Go to https://etherscan.io and in the search bar, we look for “1INCH liquidity protocol”. Everything is very fast.

When I got to the right page, I finally managed the first step.

Contract address: 0xbAF9A5d4b0052359326A6CDAb54BABAa3a3A9643

Step 2Get all the DefaultFeeVoteUpdate events using the contract address from step 1. These are events which happen when someone votes for a fee percentage to apply to a swap. Most of the calls are made when a user stakes/unstakes.Note the following:The amount parameter corresponds to the new amount staked by a user. And the `fee` parameter is the fee percentage that the user votes for.So for example, on an `Unstake` transaction where the user completely removes all the previously staked tokens, the `amount` parameter will be 0 because the user doesn’t have any tokens.The fee percentage is a weighted average of the `fee` parameter with `amount` as weight.Using only the `DefaultFeeVoteUpdate` events during April, calculate the weighted average of the fee percentage. To do this, multiply the ‘amount’ * ‘fee percentage’ and sum that across all events. Divide that by the sum of all amounts and you will have your answer.

This is the main step in which we have to do all the basic work. First of all, we need to understand which class of endpoints we will use. Based on the fact that in the second step, we need to make a selection by contract events, it is logical to assume that we will need to use Get Log events by topic hash(es).

If you’ve read my previous reviews, you’ll understand why. In short, each operation has its own class or event, which is denoted by a unique Topic Hash. That’s right, using the Covalent API, we can easily make a selection for specific events.

In the second step, we have the name of the event — Default Fee Vote Update. And then the Covalent API functionality comes to our aid again. Under the Get Log events by topic hast(es) subsection, we see a link to a calculator that will easily show us all the events for any contract.

Go to: https://www.covalenthq.com/docs/tools/topic-calculator
Enter our contract address and click “ Get Events»

We find the Topic Hash we need called “Default Free Vote Update” and copy the address.

Now we have a Topic Hash 0x28eed64d01e23014333abef902958309592b3cf9ce9da390f224467cfcaaf5b2

And we can make a Covalent API call.

In previous reviews, I’ve covered every tab in the Get Log events by topic hast(es) section in detail, so there’s nothing new here. However, we must remember that by the condition we are looking for information in the period from April 1 to May 1, so we need to find the blocks corresponding to these dates.

You can find this information here: https://etherscan.io/blocks

In previous quests, we have already found blocks for these dates, so you can use the old data.

12150245 — April 1
12344944 — May 1

So our query will look like this:

Copy the data to Excel and arrange them in columns. I got a large array of data on 7906 lines, which looks like this:

I admit, after that, I couldn’t figure out what to do next for a while. It would seem that everything is written in the task, but I did not immediately realize that first I need to sort all the data from the “Fee” and “Amount” columns.

Thanks to the alchemist @sergey|Alchemist#4069 I finally found the right path!

First I sorted the “Fee” data and copied it to a separate sheet:

I did the same for “Amount”:

After that, follow the instructions from step 2. Namely, we multiply this data array for all values.

There’s not much left. To find the weighted average value of the commission percentage, the resulting amount of “Fee*Amount” is divided by the amount of “Amount”.

After I found this value, I was completely unsure if I had done everything right.

1,981503272371830000000000000

We have one last step left.

Step 3.
Once you have calculated the fee percentage, copy the first 6 decimal places.Your secret room with the next task will be unlocked at the website: https:// dnd.covalenthq.com/{6decimalplaces} e.g If your answer is 0.654321 the url will be `https://dnd.covalenthq.com/654321`

I tried to use the numbers 981503 as stated in the task, but the page was not found. Thanks to my experience in quests, I know that sometimes it is worth playing with the numbers found, sometimes the answer can be very close. In the end, I tried the numbers 198150 and HOORAY! I did it!

Correct link:
https://dnd.covalenthq.com/198150

It’s probably because of these huge numbers that were converted as a result of copying to Excel.

Well, I’m back in the secret room!

And this time I was waiting for a crossword puzzle on the knowledge of the Covalent and 1inch projects.

The crossword puzzle was very interesting and I had to Google the answers to some questions, but in the end I managed it!

I saw the cherished inscription again!

The link is still available, test your knowledge!

Perhaps, this was the most difficult quest of all the past ones. After all, this time, in addition to collecting data, it was necessary to sort them and perform small calculations.

But it is this ultimate difficulty that makes this quest so interesting!

Learn the Covalent API, it’s very entertaining!

--

--