Hello there and gm frens!! We’re here today to talk about one of our most popular and simple, yet useful tests that one can write, a price peg test. If you missed our last writeup about Olympus, feel free to find it here!
One of our community members, waynebruce, wrote a peg test for the Dai stablecoin, Dai Peg Test, a while back, and we’ll go over it today!
Dai by MakerDao, was designed to counter one of the problems other cryptocurrencies were having, which was unstable prices. Dai aims to change that by being a decentralized, unbiased cryptocurrency that is pegged to the US dollar. This brought along the term stablecoin, and as long as the Keepers maintain the 1 US Dollar target price, then the goal has been achieved.
Now to the Ante Test in question. This turns out to revolve around 1 crucial point, is the price of Dai within reasonable bounds as described by the Maker Protocol and understood by its users.
To get to that point, let’s start with the checkTestPasses()
function:
function checkTestPasses() public view override returns (bool) {
(, int256 price, , , ) = priceFeed.latestRoundData();
return (95000000 < price && price < 105000000);
}
We can see that we’ll return true if the price is between 0.95 and 1.05 US Dollars.
This price we get by using latestRoundData()
from Chainlink’s aggregator interface.
Moving on up, we see that the constructor for the Ante Test initializes the protocol, Dai, the contract in question, Dai’s address, and the Dai/USD aggregator deployed by Chainlink.
constructor() {
protocolName = "DAI";
testedContracts = [DaiAddr];
priceFeed = AggregatorV3Interface(0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9); }
And that’s it to this Dai Peg Ante Test! At it’s core, there’s just 2 important parts to a peg test, the value that the peg needs to be held at, and getting that value.
What’s interesting here will be analyzing what could cause a failure in this test.
The first way this test could fail is if DAI’s price fluctuates outside its range of 0.95 and 1.05. If the test is checked at that time, then it can fail. And this has happened before, looking at CoinGecko’s historical chart for Dai, back in November of 2019 and March of 2020.
Value of Dai from Nov 2019 to Feb 2022
As the price is what determines whether or not the test fails, the second critical piece then is how we fetch the price, in this case, the Chainlink Aggregator. If an attacker were able to manipulate or trick the aggregator to return a value that doesn’t actually represent the true Dai price, than the test could also fail.
Food for thought anyway, it’s always good to consider what different ways a test can fail and see if we can make sure that these points are carefully considered when writing an Ante Test!
As the skeleton for this test is relatively basic, it can be expanded to incorporate different types of pegs depending on what is being called for.
For example, regarding Tether, this Ante Test written by raddy outlines the fact we care more about the dropping of Tether value, so the test is written to only check if its value drops below 0.90 US dollar.
And then moving even further! This Iron Peg Holds Test written by a-deva highlights how we can take a simple peg test and take it even further! This one is a bit more complicated to go through in this post, so we’ll revisit it another time to go deeper into it.
And that’s it for this week! Please feel free to come and check out the various tests that have already been written in the Ante Community Github. Join us at our Discord to talk web3, interesting protocols, Ante Tests, or just hang out! And follow us on Twitter to see the latest news and updates we have! Till next time everybody!