Arbitrage Adventures in DeFi
date
Oct 17, 2024
slug
arbitrage
status
Published
tags
Blockchain
summary
type
Post
I discovered a potential arbitrage opportunity involving the pufETH token contract. This post details the opportunity, my analysis, and why it ultimately didn't materialize as expected.
Discovery
The opportunity arose when I noticed discrepancies between the contract rate of pufETH and its market rate while adding a price feed for eOracle. Typically, such differences shouldn't exist for redeemable assets.
Upon investigation, I found that the asset was only redeemable when not reaching the daily limit. Checking the contract revealed that the limit was set to 0.
The puffer Contract indicated that this value would reset at 00:00 UTC:
Potential Profit
Initial calculations suggested a potential profit of almost 16 ETH (= $40,000) from this arbitrage:
Starting with 2000 ETH, swapping on 1inch and then redeeming, the
redeem(shares, receiver, owner)
function would yield 2'015'993'375'942'433'269'820
wei - approximately 2016 ETH. After returning the borrowed 2000 ETH, we'd net a 16 ETH profit.Even accounting for the "minimum receive" shown on 1inch, a profit of at least 5 ETH seemed feasible.
Preparation
To capitalize on this opportunity, I planned the following steps:
- Start flash loan for WETH.
- Swap all WETH with pufETH on 1inch
- Withdraw pufETH and get WETH using token contract
- Return flash loan
I created a smart contract to execute this plan and waited for 00:00 UTC to verify and trigger it.
Outcome
At 00:00 UTC, contrary to expectations, the limit didn't change and stayed 0.
The situation remained unchanged even after several minutes and into the next morning. It appeared that the internal storage
$.dailyAssetsWithdrawalLimit
was also set to 0.However, on October 14, 2024, at 14:30, I noticed the limit had finally changed:
At that time, with a volume of 2000 WETH, the potential profit was approximately 2 ETH. However, within minutes, even volumes of 10-50 WETH were no longer profitable.
A brief window of low activity appeared to follow the dailyLimit reset. This emphasizes that had I been monitoring for this
dailyAssetsWithdrawalLimit
change, I could have captured this arbitrage opportunity.There's no clear explanation for why the limit changed on that specific block. Examining all blocks prior to 20963354 revealed that the DailyLimit wasn't functioning as a true daily limit, but instead remained at 0 for an extended period. This prolonged zero-limit state created the arbitrage opportunity. Surprisingly, the Puffer team's reopening of the redeem function coincided with my research into it just one day prior - a remarkable coincidence.
Conclusion
This experience marked my first venture into arbitrage opportunities, and I came surprisingly close to capitalizing on one. My initial gut feeling that something was amiss with the pufETH contract proved correct, reinforcing the importance of trusting instincts in DeFi.
The process highlighted how crucial meticulous investigation and attention to detail are in decentralized finance. This level of scrutiny provides an edge not only in my professional work but also in identifying unique opportunities like this one.
While the arbitrage didn't materialize as hoped, the experience was undeniably thrilling. It demonstrated the potential rewards of combining technical knowledge, intuition, and persistence in the rapidly evolving DeFi landscape.