Part 1: Building a Financial Advisor dApp on Avalanche

hariseldon
4 min readFeb 26, 2021

--

This series of posts will walk you through how to build an automated dApp on Avalanche that will trawl through Pangolin’s data to find out the best ECR20 pair you should invest your money in to maximise returns.

When we work out how to maximise our returns, we will analyse two key income streams

  1. Fee’s earned by being a Liquidity Provider daily
  2. PNG Token Distributions daily

We’ll then compare that against the impermanent loss compared to if we just HODLed the tokens.

So if we want to look at our formula:

Daily Profit = (Fees + PNG Token Distribution) — Impermanent Loss

This means that if we compare each pair listed on Pangolin we will have a better metric to determine whether that pair is worth investing in.

Let’s now expand upon the income and opportunity cost items to more fully explore how they’re calculated

Fee’s

Fee’s are earned every time a trade occurs on Pangolin. If you are a liquidity provider you get a share of those fee’s earned.

If you look at the above screenshot, you can see the last text states “Liquidity Provider Fee”. The Pangolin litepaper has more details on the Swap fees.

The key takeaway from the Litepaper is As of today swap fees are fixed at .30%, but liquidity providers will only receive at most .25% of these fees.

So we can then go to https://info.pangolin.exchange in order to see what the daily fees are:

We now want to calculate the daily return if we had a $0.50 of PNG and $0.50 AVAX. To do this we can take Fees (24hr) / Liquidity

This then means if I provided Liquidity to the PNG/WAVAX pool I would have earned approximately 0.0015c per day

PNG Token Distribution

We also want to include how much money we make on the PNG Tokens we receive.

If we go to to https://app.pangolin.exchange we can see the current PNG distribution per week

So we can calculate the amount of PNG rewards based on the total AVAX and then convert it to how much in USD we would have made if we had provided $1 of Liquidity to the AVAX-PNG pool.

So in terms of USD we would have made $0.0035

Impermanent Loss

Let’s now get into the murky waters of impermanent loss. I’m not going to go into the details as it’s covered extensively elsewhere. Although this article in particular, proved helpful.

Since we want to calculate the daily rate, we want to see the price change of the AVAX PNG Pair

If we compare the rate as of today $4.1075 vs yesterdays rate of $6.37135 we can now work out our impermanent loss:

As you can see we made a (impermanent) loss of -$0.02361547

Wrapping up

Now that we now what the figures are, let’s return to the calculation and see whether investing $1 in AVAX-PNG pool versus HODLing them is a wise move.

Daily Fees + Daily PNG rewards — Impermanent Loss

$0.0015 + $0.0035 — $0.02361547 = $ (0.018600203)

Wait, what????

Yup, over the last day it was more profitable to HODL your AVAX-PNG pair than to engage in Liquidity mining.

This is just a single example however and doesn’t reflect long term trends. In order for us to accurately determine which is more profitable and which pair maximises this profit, we’ll need to build an indexer to track the historical values.

That’s what we’ll start working on it the next post.

Let me know if you have any questions or if I’ve messed up any calculations.

--

--

hariseldon
hariseldon

Responses (1)