I'm a senior software engineer at Ripple, and let's get started. In this presentation I'll be introducing the world's first AMM-based DEX natively on the XRP Ledger. But first, let's go over a few things. I know Angel covered this in her presentation, but all the transactions for AMM will be referenced from the XLS-30 spec, which is a proposal to add non-custodial AMM as a native feature to the XRP Ledger DEX. It also defines new AMM transactions and requests on the XRP Ledger that will be used in this demo.
So what are these AMM transactions? The transactions that will be used in my demo are AMMCreate, which I'll briefly go over. AMMCreate creates a liquidity pool with two assets, and an asset can be either XRP or an issued currency. Then there's AMMDeposit, which is used to add liquidity to the AMM pool, and as a result an LP token is obtained to represent some share of the AMM pool. There are actually five possible ways of depositing. Conversely, AMMWithdraw is used to remove liquidity from the pool, and as a result the LP token you got from the deposit transaction is returned to the pool. It also has five possible ways of withdrawing. The last transaction is AMMVote, which submits a vote for the trading fee of an AMM instance in which one has liquidity. There's also a new JSON-RPC command introduced called amm_info, which is used for querying an AMM instance. There are two possible ways of doing so: one is by the AMMID, which uniquely identifies an AMM instance, and the other is by providing the asset pair.
I want to be fully transparent: this is still a work in progress, so there are a few transactions that won't be in the demo, such as AMMBid, and also doing AMM swaps using Payment or OfferCreate transactions. As a replacement, I will be doing AMMDeposit followed by AMMWithdraw.
Last but not least, the software architecture of this demo: I'm going to be using a full-stack web app built with the MERN stack, and it's going to be submitting transactions to a private AMM devnet, which runs rippled with AMM support. If you don't already know, rippled is the reference implementation of the XRP Ledger, written in C++, and this is actually using a forked GitHub branch which is open source for you to view. The way I'll be submitting these transactions from my full-stack web app is through the JavaScript client library called xrpl.js, which is using a GitHub branch I created called amm, also open source.
All right, time for the demo. Are you all ready? Okay. This is the first AMM-based DEX I implemented natively on the XRP Ledger. I like to call it XRPL Swap. Right now I've skipped the login process, but you can imagine connecting a browser-based wallet to this app, like an XRPL equivalent of MetaMask. Here we're logged in, with close to 10,000 XRP in our wallet address. But before we do the swapping, let's go to the pool screen. We have our balances here, with XRP, ETH, USD, and BTC, and right now we don't have any active positions, but we do see available pools that have been created, like BTC to USD. Let's go ahead and create our own liquidity pool.
Let's go with XRP and ETH, and let's say I want to deposit 250 XRP and 750 ETH, and here is a trading fee that I'll set to 0.025. Let's create this. The Wi-Fi is kind of slow too. All right, great. We've created our new AMM instance, and as you can see we have a new active position in it. We provided 250 XRP of our own and 750 ETH, and in return we got LP tokens. There's a new entry in the balances: this is the LP token identifier, and this is how much we own, 433K. Now let's look at the raw JSON payload for this transaction. This is the AMMCreate transaction I mentioned in the slides, and this is the raw JSON payload that was sent to rippled. It specifies XRP in drops and the 750 ETH, with the trading fee provided.
Let's do some other things as well. Let's check out other liquidity pools. I want to show some love to BTC. Before I do, there are two ways of changing liquidity: depositing and withdrawing. I want to become a liquidity provider, so I'm going to choose deposit. As I mentioned in the slides, there are five possible ways of depositing or withdrawing, using either LP tokens, asset one, asset two, a combination, or a single-asset price. I'm going to keep things simple and just deposit 2.78 BTC. I'll click submit, and the deposit was placed, and as you can see the BTC amount increased by 2.78. Let's check the transaction, which was AMMDeposit with BTC 2.78.
Now let's check the trading fee of one AMM instance pool. As Angel mentioned in our presentation, there is the ability to vote on the trading fee of an AMM instance in which you have liquidity. The current trading fee is 0.098, with a vote weight of 100,000. Vote weight means how much liquidity you have in the pool, which gives you bigger voting power. Since I don't have that much, let's try a stupendous fee of 25 percent. The vote was placed. Let me show you the transaction quickly, which was an AMMVote. If we go back, this is a vote I submitted with a lesser weight than the one at number one, so the trading fee unfortunately did not change to 25 percent.
Now let's get to swapping. Let's see what I want to swap. I'm getting tired of holding USD, so I want to swap it for ETH. I'll set USD to ETH. Since there's a 50/50 ratio for both currency pairs, this is a spot price, so one USD will give me one ETH. If I click submit, which is not realistic by the way, that would be amazing, right? Like 25 for 25. Great, and it looks like we were able to swap USD for ETH. If we check the transactions, I actually did an AMMDeposit followed by an AMMWithdraw. Ideally, what you would do is a single payment transaction or a single OfferCreate transaction, but since that's still a work in progress, I went with this workaround where you deposit and then withdraw. I deposited 25 USD and withdrew ETH for 23.75, and there were some fees and slippage, so I didn't get the full 25.
I think that pretty much covers it. Let's go back to the slides. This is coming soon. I was writing this on a private AMM devnet, but a public release will be available sometime in the next two weeks for community testing and feedback. AMM support in the XRP Ledger client libraries will have a beta release in the same time frame. I've created GitHub PRs for both xrpl.js and xrpl-py, so it's all open source. Feel free to look at my code and roast me; I encourage it. You can add me on LinkedIn and follow me on Twitter. Thank you, everyone.
