Originally posted on elenithinks.com.
In my first article how not to get started in DeFi I reveal a very personal preference: I, too, like money. One thing I like almost as much as making money, is not losing it. My recent attempts in DeFi to make money have become exercises in minimizing money lost.
The largest source of my money losing endeavors was not poor investment picking, but high, unexpected costs that appeared when I was already in too deep (and my inability to internalize the sunk loss fallacy). Often there are a series of initiation fees such as approving withdrawal of a certain currency to authorizing functionality on the platform. After all these one-time setup fees, I would finally get to the transaction fee portion. However, I wouldn’t know what this would cost me until I actually tee-up the transaction. This would end up being a lot of initiating a transaction and then rejecting it just to learn the fee. This is all to say fees suck, but unexpected high fees are even worse.
And this is just to fund! The cost to withdraw the money is its own mystery.
What would end up happening is my $100 investment quickly became a $80 investment and eventually only $70 after I withdrew it - losing any profits (plus more) I may have made. I told myself I was learning, so fine, but I didn’t want to keep needlessly losing money because I didn’t have all the information I required to choose my learning wisely.
What I needed was a dashboard that showed me these costs. I initially tried to make this in excel, my first true love, but quickly realized updating the inputs was an equally painful process. I’d written python code all of once about 7 years ago, but everything is google-able, so how hard could it be? (This is where I thank Sergey who saved me from python error hell - thank you!)
This is a long leadup to say, I built a thing: Gas Estimator Dashboard (Thank you again to Sergey who deployed this thing for me on the interwebs).
Caption: Enticing snapshot so you visit my site
I’ve already found the dashboard to be useful. I saw that the gas price was only $3 to finally withdraw my $88 dollars that was ‘trapped’ in Uniswap (it originally cost me $20 to fund!).
To help me figure out how long it would take to recoup my costs, I also built a calculator where you can input the investment amount (before fees) and expected APY and it outputs the time to make the fees back after taking into account the fees you paid.
Here’s how it works:
The gas cost is a function of (1) gas price and (2) gas used.
Gas price is denominated in gwei, which is just a denomination of ETH (0.000000001 ether to be exact). This is how much you’re willing to pay the miner to include your transaction.
When blocks are at capacity, this price is essentially a bribe to move higher up in the line. Several websites provide estimations of the gas price based on the other transactions in the pending line (called the mempool). Here I used DeFi Pulse’s API (which is actually just ETH Gas Station) to get the current price for sending a transaction “fast”, which they define as being mined in less than 2 minutes. (Note: bloXroute is coming out with our own estimator which I’ll switch to in a few weeks).
Next, I needed to know the amount of gas that would be used to process my transactions.
This is related to how much computational power it takes to execute the transaction. When your transaction calls a contract, some code gets run and the cost is related to the effort it takes to run that code.
This is why Ethereum is often called the “World Computer.” You are essentially running a program, and larger programs take more computational power and thus cost more. Since the contracts are pretty static except for a few inputs (e.g. amount investing, wallet from address, etc.), the amount of gas required to run a program should be about the same each time.*
To get the estimated contract gas requirement, I teed-up transactions in MetaMask and took their estimated gas limit (the maximum you’re allowing the transaction to pay). This eventually got annoying since sometimes there are authorization fees before you can actually execute, so I needed another way. I recently realized I could go look at executed transactions on Etherscan and see what was paid. Going forward this is how I will estimate the amount of gas.
Lastly, I think in dollars, so I needed to get the current price of Ethereum in USD. The final equation used become:
gwei to send a fast transaction * 0.000000001 * ETH Price in USD * Gas Used
For the break even calculation, to get the expected return I used the following equation:
Estimated yearly return = (investment amount - fees) * APY
Then to calculate the time to make the fee back, I:
Fee / (Estimated yearly return * (investment amount - fees))
I then put this result in months to see just how long it would take.
Version 1000.1
This is my first iteration and I plan on working on it over time, taking a page from Jake McCrary’s article “Go create silly, small programs”. I’ve already added in withdrawal fees (hat tip to Sean Schulte for the idea) and maybe I’ll add something related to yield farming.
—-
*It low-key frustrates me that projects don’t publish this information and make it easier to calculate. Ethereum’s yellow paper even provides a Fee Schedule with scalar values corresponding to the relative gas costs of a number of abstract operations that a transaction may affect. But I digress…