New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Deploying a Stablecoin I Kevin Jones

ETHGlobalSun, Nov 9, 2025, 12:00 AM

Speaker

Kevin Jones

Kevin Jones walks through the Speedrun Ethereum stablecoin challenge, focusing on building an over-collateralized, onchain stablecoin system. He contrasts models: fiat-backed (USDC/USDT), under-collateralized/algorithmic (risky), and the target design: over-collateralized with robust peg mechanisms. The reference implementation includes five parts: a simplified DEX for swaps, a stub oracle for prices, the stablecoin token with restricted mint/burn, an engine contract that manages collateral, minting, and liquidations, and a staking contract plus a rate controller for borrow and savings rates. Using Scaffold-ETH with burner wallets, he deposits ETH as collateral, mints the stablecoin, and demonstrates how collateralization ratios, liquidation thresholds, and incentives keep the system solvent. Kevin then runs a simulation with trading bots to show peg dynamics. When borrow demand overwhelms supply, the stablecoin price drifts below one; raising the borrow rate discourages new borrowing, nudging price back to peg. If price drifts above one, enabling a savings rate incentivizes holders to stake, increasing supply available to sell and pulling price down. He reviews the core code: access-controlled mint/burn in the token, the engine’s health checks and liquidate flow (anyone can repay and collect a reward), and the role of the oracle and DEX. The session closes by encouraging builders to complete the challenge to deeply internalize risk management, incentives, and onchain monetary policy. 00:00 – Intro and why stablecoins matter 01:18 – The Speedrun Ethereum challenge overview 02:28 – Types of stablecoins and tradeoffs 03:42 – Required components: oracle, DEX, token, engine, staking 04:54 – Token design: restricted mint and burn 06:35 – Spinning up the demo with Scaffold-ETH 09:04 – Adding ETH collateral and minting the stablecoin 10:23 – Collateral ratio, liquidation threshold, and rewards 11:54 – Setting up rates and understanding parameters 13:25 – Bot simulation: price falls below peg 14:26 – Raising the borrow rate to restore peg 16:34 – When price goes above peg: savings rate incentives 17:32 – Staking the stablecoin and yield mechanics 18:47 – Pushing toward unsafe health and liquidation discussion 21:11 – Contract tour: oracle, rate controller, token 22:36 – Engine internals: checks, health, and liquidate user 23:20 – Takeaways and next steps _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🇮🇳 *ETHGlobal New Delhi* This workshop is specifically for ETHGlobal New Delhi, a 3-day hackathon held September 19-21 at the India International Convention & Expo Centre, bringing together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! Watch the full ETHGlobal New Delhi 2025 playlist here: https://www.youtube.com/playlist?list=PLXzKMXK2aHh7zCFW3hBqatZ18rQaYeEJL _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ✅ *Follow BuidlGuidl* X: https://x.com/buidlguidl ✅ *Follow ETHGlobal* X: https://x.com/ETHGlobal​ Warpcast: https://warpcast.com/ethglobal Website: https://ethglobal.com YouTube: https://www.youtube.com/c/ETHGlobal _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _Are you interested in Ethereum development and entrepreneurship?_ 👉 Sign up for the next ETHGlobal event: https://ethglobal.com/events 🎁 Get exclusive access and perks with ETHGlobal Plus! https://ethglobal.com/plus 📣 Want us to throw an event in your city? Tell us where! https://ethglobal.com/city

Transcript

[Music] Thank you so much. Uh this has been the first time I've done this with this like silent disco. This is pretty cool. Um uh when we get to questions, I'll throw on my headphones, but um yeah, thank you everyone for coming. Uh my name is Kevin Jones.

Uh I do developer relations for the graph, but I also support the build guild. Um and today I'm going to be talking about stable coins. Um, more specifically, there's a challenge on speedrun Ethereum, uh, that really dives into stable coins. Um, it's actually one of my like favorite challenges because, um, stable coins are this really cool product that really came out of like DeFi, um, and really are like a true like kind of example of how we've kind of evolved um, uh, on Ethereum to like create stuff that, you know, no matter what, we need to find a way uh, to build something uh, that's useful. And stable coins, I think, are going to be like one of the next really legups for adoption in crypto.

I mean, they already are. Um, but I'm going to talk a little bit about like the challenge. Uh, I'm going to show off the completed version. We're going to do like a demo of it so that you guys can see um what the solution kind of looks like and talk about some of the uh things that you kind of will learn to um understand when you're building uh the stablecoin challenge. So, uh you guys can get the challenge obviously by just going to speedrun Ethereum and then uh scrolling down to basically right after the onboarding batches there is the overolaterized lending.

I recommend doing that one first. Um I think there might be some new people in the room. Um so, you know, basically that one's going to be give you a primer on like what it really means to have over collateralized uh loans on uh smart contracts. And the reason why that's important is stable coins um are really like one of those uh use cases is over collaterized stable coins. So um I have like a a doc here that you guys can scan if you want.

This is like a the the kind of like the solution. So this actually has the answer and it has a link to the GitHub and the speedrun challenge. Uh and it kind of like goes into very like explanations on like each part of the uh thing. So I recommend you guys check this out. Um and uh I guess first of all I want to talk about like the different kinds of stable coins.

Um there are uh stable coins that are what we would call like um uh what do you call them like onetoone peg stable coins. Uh and these ones are they're they're stable coins in the sense that they're backed by treasuries, right? So like USDC or Tether uh for every single stable coin that is minted there is a dollar that's actually backed on that stable coin. Then there are like undercolateralized stable coins and like algorithmic stable coins which are um you know like Teral Luna I'm sure you guys have heard and some of these other like um um not as efficient when it comes to like using smart contracts to their advantage. Um and like I would say safe stable coins is a good good example.

They're not very safe. Uh and then there's overcolaterized stable coins. And so these are uh really like focusing on the aspects of decentralization u at the same time being able to keep peg stability on the value of the stable coin. Um so that's just good to know. The challenge that uh you're going to be doing is focused on the overcolaterized uh stable coin.

Um for the actual like uh uh system to work properly, there's a few things that you need to understand. One is you actually need uh two things. is you need an oracle, right? Because you always need to know exactly like what the price of uh the asset is that you're providing as collateral uh in the smart contract. And so this could be something like um a chain link price feed or some kind of other like oraclebased system that you're using that basically will let your smart contracts know exactly what the price of the collateral is.

Um and then you also need a DEX. You need some way to do swaps, right? And so, uh, in the challenge, the oracle is kind of like a very like static price, like it's just kind of hardcoded. Um, so it's kind of good to, uh, to understand that. Um, and then for the DEX, um, there's like a very very simple DEX implementation that's already written for you.

So, you don't actually have to write a DEX. At this point, you probably have already done the DEX challenge and you understand that. Um, really the the core of the the thing that you need to like understand and write is really three things. is the actual stable coin itself which is an ERC20 token um that is like modified with some um custom mint and burn functions um and a core uh uh contract that basically handles all of the uh minting. So in this case, we only have like one contract that's in charge of keeping um uh the supply matched to the amount of collateral that's put into the system, and it's the only smart contract that can do that.

Uh and then you have an additional contract that you use for staking, which is we'll get to it later, but it's like a way for you to incentivize people to hold the stable coin uh into a smart contract so that they can earn some kind of uh interest uh on that on that smart contract or on that stable coin, sorry. Uh and so when you first like set up the project again the the decks and the oracle are already going to be written for you and then you'll just need to kind of like focus on those uh other three contracts and go through and fill those out. Um some of the core things that that I'll mention about the u stable coin is it's uh again it has a modified um uh uh burn and a mint function and only the engine is the one that's allowed to mint tokens. And so this is what keeps the uh um the the system whole, right? Like in order to mint a certain amount of tokens, you need to actually like deposit a certain amount of collateral um into the system and then that engine is in charge of like minting the tokens uh to that user.

Um and you can see here where there's like some access control that happens to make sure that that's the case, right? Like the actual uh sender needs to be the actual engine contract here. Um and then on top of that for the mint function uh you have um the ability sorry for the minting only the uh uh engine contract can mint. For the burn function there might be a situation where the owner of the contract also needs to burn tokens uh in like an emergency scenario or something like that. Um and so yeah so I think what it makes sense is actually to show off and get started and show you like a little bit of a demo and then we can actually dive into the smart contracts a little bit more.

So, um, if you if you weren't here on the previous, uh, demo, but I'll just kind of give a really brief overview of what I'm doing. Um, scaffold ETH. So, these challenges are obviously written in scaffold ETH. Uh, you need a few windows open to orchestrate your environment. Uh, the first one that you need is you need a chain up, right?

So, when you do set up this challenge, you basically get to determine whether you want to use hard hat or foundry. Um, I've gone ahead and already chose hard hat. Uh, so when I run yarn chain, it spits up my chain and I'm ready to go. And then in this other window, we can run yarn start, right? Uh, and so that's going to spin up our front end, which is like React with Nex.

js on port 3000. And then we come into this last window and we can do our deploy. So again, this solution that I'm going to show you is like a complete solution. Um, when you first get the contract, again, it won't be working and you'll need to kind of like work through uh the actual speedrun Ethereum challenge and you'll need to go through and do different things. So to get set up, you can come here to this kind of like ch uh checkpoint zero, run this command to actually uh get the repo set up uh start your chain, deploy your contract, and then start your front end.

And then you can go through here and and complete the challenge. Uh so again, uh let me just review this again. So you can see here there's uh five smart contracts that come uh in this kind of setup. One is the DEX, which is basically a very simple DEX that's kind of already written for you. the ERC20 token with the modified uh burn and mint functions.

Then there's the engine which is really in charge of like making sure that users are staking collateral and getting the right amount of stable coin and uh maintaining their PEG. And then you have the staking contract which is uh incentivizing people to be able to stake uh tokens which we we'll show off in a little bit. And then there's the actual oracle uh which tracks the price of ETH, right? So this is again like a dummy. It's like hardcoded.

So in a real world scenario, you probably have like um something like chain link price fees or something like that. Uh oh, and then you also have the rate controller. I forgot there's actually one more contract uh which is in charge of keeping track of the uh the interest rate which we'll we'll show off here in a second. Okay, so it's running. So let's go ahead and spin up scaffold ETH here on port 3000 and we'll kind of show it off.

Okay, I'll make this a little bit bigger. Okay, so if you haven't used Scaffold ETH before, you'll know that you get a burner wallet, right? This is like a burner wallet that comes uh built into the browser session. U and so I can basically come in here immediately and just start getting some ETH. So I'm just going to grab like a bunch of ETH from the faucet because we're going to use 10 ETH for this demo.

Uh we're just going to pretend that I'm a I'm a little mini DeFi trader and I'm interested in doing some um uh basically getting some stable coins, right? Um and I'm going to come in here and I'm going to say, "Okay, well uh right now I have uh 11 ETH, which is worth, you know, $42,000 or $43,000. And I want to basically stake this into uh the contract. I want to add this collateral. So I'm going to add 10 ETH actually so that I have just a little bit of ETH for like gas and stuff like that.

And I'm going to take that and I'm going to I'm going to stake that into the contract. Uh now the the rules of the actual contract if we load it up in uh cursor real quick. We can take a look at the engine contract which is inside the contracts folder here. Or actually is this the right one? Yeah.

Staking oracle. Am I in the right project? Yeah. Oh, it's here at the top. Sorry.

So, at the uh the engine contract at the very top, we're we're defining exactly what the the coll collateralization ratio is. And so, this is the amount that the user needs to have in the system before they can be liquidated. So, uh Austin talked earlier about liquidation. The liquidation function is really important because what it does is it allows anyone that is activating and using the system to be able to liquidate anyone that is insolvent who doesn't have enough basically collateral to cover the amount of tokens that they're borrowing against or the that they're trying to get back from their um from the the swap. Um and so this ratio you can kind of adjust but in this case we're just want to set it at 150%.

And then also the liquidation reward is set so that if someone does see a position and wants to pay back the the the actual amount in the liquidation uh threshold that they can earn a reward and get paid for that that liquidation. So this incentivizes keeping the ratio of ETH versus the amount of stable coins in the system equal. Uh and then there's like a precision precision thing which just keeps the rounding uh accurate. Um, and so those are kind of important thing. And then, uh, there's like this kind of like time calculation, which I don't actually know what that's for.

Uh, but we might get to that in a little bit. And so I've gone in here and I've I've staked, uh, I've added 10 ETH of collateral to my to my to the smart contract. So now I should be able to basically get some stable coins out of the contract. So if I come in here and say that I want to mint uh, $10,000 in stable coins, it's going to tell me exactly what my ratio would be. That puts me at about 180%.

So, I could probably go a little bit more. I could do 12,000. Nope, I can't. So, 12,000 is too much. I'm gonna be past that thing.

It's not going to let me mint that. So, maybe we can do it somewhere in the middle. And we'll do like 11,000. So, I've put in 10 ETH. Um, oh, I might need to get some more funds.

Let's see here. 11. One, two, three mints. There we go. So, I had to get some more gas because I didn't have enough for gas.

So, I've I've put in 11 ETH and I've taken out $11,000. That puts me at a ratio here at the bottom of about 163%. So, I'm good. Um, I have this kind of like system where I can put in some collateral. No one can liquidate me right now because I'm in that right ratio.

Um, but I'm kind of like locked up. I could then take more ETH. Uh, I could take that that uh that stuff and I could like stake it and then I could like or I could buy more ETH and then add more collateral and I could do this kind of like looping thing that you you often hear about with like DeFi become overextended. Uh, but for this there's also another cool feature in the in the challenge and it's a simulation script where we can actually simulate a bunch of people uh coming into the system and and trying to utilize this this uh uh stable coin. So, let's do that.

So, we're going to run yarn simulate. What this is going to do is like spin up some bots basically that are going to basically start uh activating into uh the the system. Hopefully it works. Yeah, there we go. And they're going to start kind of like um putting in collateral.

They're kind of like whales. They're going to put in a lot of capital, get a lot of stable coins. And what we see here in this price graph is the the the actual stable price of the of the token of the MyUSD. And you can see what's happening is it's dropping drastically. And so what's going on is that we have this interest rate that was we have set at 0%.

Right? So we're allowing like the bots just to come in, put their ETH into the contract, and pull some uh some stable coins out. And what that's doing is it's creating too much demand for the stable coin and it's causing the price to drop. So like uh what's cool about this challenge is it kind of teaches you a little bit about like economics. In order to like stop that and to like decrease the amount of like um need for dye or I should say like um want for dye, we need to take this borrow rate and actually hike it up and increase it.

So if we take the borrow rate and we take it up to about 10%. Immediately all of the uh bots are going to recognize that hey uh it's actually costing me 10% to put the ETH in. And you can see here that they're actually starting to swap back and it's going to start moving the price back up towards the towards the right dollar. And the reason why that's important is because a stable coin is stable for a reason. Um it's it's it's kind of like a reserve asset, right?

You want to be able to like take your money out of Ethereum and put it into a stable coin because it's stable. like you wouldn't want like the price of a of your stable coin to drop drastically uh because it's going to, you know, it's not a reliable way to like put your equity in something other than like crypto or whatever it is you're using. And so the idea is that you're just adjusting this kind of interest rate to basically control the amount of people. And you can see it's actually still dropping. Uh we could actually raise it a little higher.

Let's raise it up to like 20%. uh which is like a real thing that's happened in the past with some stable coins. they've actually had to like raise it up that much uh to basically keep people from um you can imagine like a scenario where like you know it's DeFi summer and everyone is like very very like into the idea that ETH is going to you know go to the moon and so everyone's just like staking their ETH so they can get stable coins and then uh you know swap for more ETH and then do it do the same thing over and over again and people are very bullish for ETH and so again you have to use this these mechanisms like this borrow rate to like slow that down and you can It's finally coming back up to its peg, right? But at some point, it's actually going to go over it's actually going to go over the peg where that means that at some point people actually don't want die, right? The interest rate is too high for them.

Uh and they're going to start the bots are going to start pulling them out. And you can also see that some of the bots have either been liquidated, right? Or um they yeah have stopped trading because they they don't want to uh I guess they they have too much risk. Um and so you can see that one of the bots is still kind of going strong but now we finally have like reached the peg again, right? We finally recovered.

Then we have this other like mechanism as well which is called the savings rate. So, just like we want to like limit the amount of uh people that are uh borrowing and like swapping for a stable coin, we kind of need to do the reverse. And we need to like incentivize people to actually hold onto the stable coin when it goes too high. And so then you can take and basically create like a savings rate similar to like if you go to your bank account and you want to deposit some money, they give you like a small percentage uh in your thing. Same thing here is we want to incentivize people to actually come into the contract.

And so there's a way to do that in here as well. So we have these these three tabs. The first is like adding collateral or withdrawing collateral. The second is minting USD or repaying your USD or what you borrowed. Or there's the staking operation.

So then I could take my ST staking and I could basically stake it here. But I wouldn't want to do that if I'm not earning something. So we could like make this like I don't know 5% or something like that. Uh and then we could uh stake that. So, we could stake like 11,000 and then stake it here.

So, now I've taken that stable coin, I've put it into the smart contract and I'm staking it and it's getting locked up there and I'm earning 5% but I'm also paying 20% on my loan which is not ideal, right? And so, it's this kind of like balance of like balancing between uh the interest rate that you're that um is going on. And I kind of wanted to show you guys liquidation as well, which is quite interesting. Let's see if I can do it because it's it's tricky. You have to like balance it.

Um but let me see if I can do it. So, first of all, what I'll do is I'll I'll borrow some more ETH. Let me add No, I don't want to add any more collateral. Let me borrow some more stable coins. Sorry.

So, let's add let's let's borrow 600. No, 700 800 900. Sure. 950 70 100 I'm just trying to get a bunch. There we go.

So now I'm like it it kind of warned me. See I'm like trying to mint more and it's telling me well actually you can't do that because it's putting you in an unsafe position. So there's this like fail guard that you have to add. We're saying like oh yeah well like you can only mint like up to your ratio. You've gone over it.

So I'm very much close to like the edge. I'm at 150.37. So, I don't I only need the price of ETH to drop a little bit for me to become insolvent and someone could liquidate me or um yeah, I'm losing track of like everything that you need to understand, but you get what I'm saying. Like, I'm very very close to the threshold and I could be liquidated.

So, what I'd like to do now is like lower this back down to 0% and I'm going to drop the price of the stable coin. Okay. Uh that's a weird error. It shouldn't be giving me that actually. Oh, it's because I don't have enough pay to gas now.

Um, I'm going to start the bots up again. Let me start the bots up one more time. So, I'm going to start five more bots and I'm going to lower this down to 1%. Let me refresh here. I don't know why it's not letting me hit zero.

Maybe it's because the savings rate. Let me try lowering this first. I think it's bugging out on me actually. Okay, let's try it now. Okay, so I'm dropping the savings rate and I'm also going to drop the borrow rate so that the bots are going to start rocking.

And what's going to happen is my stable coin price is going to drop drastically and I think what's going to happen is I'm going to probably be able to get liquidated here in this instance right here. So here it is. I'm dropping again. So, my my you can see here my ratio. Uh, let me borrow a little bit more.

I'm just kind of trying to max out my position here. See, I was able to get it to do it earlier. I don't know exactly what what why it's not working now, but you can see like all the bots are like the interest rate has dropped drastically and whatever. Okay, it's not working me. Maybe if I come back in a little bit, I'll be in an unsafe position and I can try to liquidate it.

So, let's look a little bit closer at the smart contracts here. So, again, uh the decks will already be written for you. You don't need to really touch that at all. The oracle is like this like hardcoded price of ETH. So, in this case, it's a,000 ether uh for um one USD.

And the rate controller is what we're using here to control the rates. And so, again, you won't need to mess with this contract. You'll spend most of your time uh in the myUSD contract which is the stable coin, the engine which is the thing that's controlling the amount of minting and burning and then the last one which is the uh the staking contract which controls how much um uh people will get paid and interest when they stake their tokens. Uh, and so the USD one here, again, you'll you'll learn that you need to create these custom functions that override the standard like ERC20 pattern. And so you can see here we have this like external ones that override and then we just like use that burn function and then use that mint function.

And again, each one has like uh access control. This one will only allow you to do it if you were the owner of the contract or if you are the engine to mint. Only thing that can mint tokens is the engine because we don't want like the infinite money glitch uh to be able to to happen. And then the engine is probably the most complicated contract because that's the one that's going to um have to make sure uh that the person is uh providing enough collateral. Uh there's also the liquidate function in here which there's you'll see here there's a function that checks to see if the user is actually liquidatable.

Um and so that's really important and then there's a function which is a pretty big one actually like you can see how big the liquidate uh user function is. It's quite complicated. Um but this is actually where anybody in the system can come through and like find someone that is liquidatable and get paid that collateral. um that well they have to provide the collateral for the user and then they can earn the 10% on the the payback. Let's see if it's done yet.

No, it's still not. Um okay, cool. So, I think that's a good overview. Uh again, this contract uh this sorry, this GitHub will go into like much more detail about each thing. Um and I think for the sake of yeah, see if there's anything else I want to cover.

I really wanted to show you guys the liquidation, but it doesn't look like it's working. Let me try one more time to get it to do it. Try learn this one% maybe. Yeah. So, I would do it uh here, right?

So what what would I do it like a big swap like how much? Oh, incognito. Yeah. Yeah. Yeah.

Okay, cool. So, new incognito window. That's a good idea. So, let's go here. Let's go to localhost 3000.

So, what I'm doing now is just like spinning up another identity, right? I have this yellow one and this orange one. Well, actually, they're both yellow. Um, and I'm going to get some ETH here. And you're saying like get some like add some collateral?

Yeah. No, just swap. So, just come here and then swap like um six five ETH. Yeah. No, it's not doing it.

It It did earlier. I was able to get it to this like bad state, but it just doesn't seem good. Um it's the the price of uh the stable coin is tanking though, uh because I'm not messing with the rates. Um, yeah. No, sorry.

Well, okay. So, we have like some time for like a couple questions maybe. So, maybe I can do that and then we'll hand it off to Shiv and then Shiv's going to talk about prediction markets. Uh, so yeah. Does anyone have questions?

It's a complicated system. I would say like stable coins is like uh this really like cool evolution of like DeFi and like the need for stable coins is like the story is really cool like how how contracts came to be. Um, but it is very complicated. So hopefully I did an okay job explaining it, but do the mission and uh let me know if you have questions. Any questions in the audience?

No. No. Buler Beller, anyone? Awesome. Cool.

Well, thank you guys for coming to the talk and uh yeah, catch you guys later. [Music]

Automatic transcript — names and jargon may be misspelled.