Deploy a Serverless Maker Bot on AirSwap (Part 2) – Fluidity

0 2


Deploying with ZEIT Now

This is probably the easiest part of the tutorial, because ZEIT makes deployment so easy. Simply run the following command inside of airswap-maker-kit-examples/zeit/

$ now

When the deployment finishes, you’ll see your maker address printed out. Keep this handy, we’ll be using it shortly. It should be formatted as https://maker.<your zeit username>.now.sh

This address shouldn’t be longer than 32 characters including the https:// prefix. If it’s longer, consider changing the “name” of your maker in now.json to something shorter, or using a shorter ZEIT username.

Approve tokens for trading

We need to approve the Swap contract to move tokens on our behalf in order for it to work properly. This is a fundamental necessity of almost every kind of decentralized exchange system on Ethereum. You’ll need to complete this step for any token that you want your maker to trade, but you should only ever have to perform it once per token. The AirSwap Maker Kit includes a script to automate token approvals, so let’s take care of that now.

On the command line, navigate to the airswap-maker-kit repo that you cloned down in Part 1. Then, copy the .env file that you created in the airswap-maker-kit-examples directory and duplicate it inairswap-maker-kit

It should look like this:

ETHEREUM_ACCOUNT=64_CHAR_PRIVATE_KEY_HERE

Now we’re ready to run the token approval script.

$ yarn token:approve

When prompted for the address of the token you want to approve, paste in the Rinkeby DAI address. In Part 1, we got some test DAI from the Compound Faucet. Paste the address into the prompt and hit enter/return on your keyboard.

0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea

Finally, double-check that everything is correct and type “yes”. Your transaction will now be submitted to the Ethereum network, and you just have to wait a minute or two for the miners to finalize it.

Setting a trade intent

At the end of Part 1, we queried our maker locally by pasting our localhost:3000 address into the prompt. We could query any maker directly peer-to-peer in this fashion, but what if we don’t already know a maker’s location in advance? How can we discover other traders on the network? That’s where the Indexer smart contract comes in. An Indexer is a smart contract that aggregates trade intents. In our example we are trading DAI/WETH, so we will publish an intent to the indexer that signals this to the network. Then, other traders who are interested in trading DAI/WETH can discover our address on the indexer and ask for a quote or order. In fact, this is exactly the method that AirSwap Instant employs to help traders discover each other. AirSwap Maker Kit also has a script for setting Indexer intents, which we’ll use below.

Again, navigate to the airswap-maker-kit directory if you’re not already there.

First, approve the indexer to stake AST

yarn indexer:enable

Now, we can decide how much we want to stake. The more we stake, the higher up on the list we’ll appear when traders query the indexer. You should have received ~5000 test AST from the Rinkeby faucet in Part I, so stake however much of that you want. You can also run the yarn indexer:get command to view the current state of the list.

yarn indexer:set

Querying your maker on AirSwap Instant

Now that we’ve completed all the necessary steps, we should be able to communicate with our maker on the web. To verify this, let’s head over to the development version of AirSwap Instant running on the Rinkeby test net: https://instant.development.airswap.io

Using MetaMask, switch to a different address than the one you’re using for your maker. Change the base asset in the top right to “WETH” (we set our maker to trade DAI for WETH).

Now, open the Chrome Network debugger and request an order for some DAI. You should see your maker appear in the network activity, and one of the quotes in the “All Quotes” results should be from your maker. Congratulations, your maker is now online 🎉

Now that you have a working end-to-end example, you can start to customize the code and add your own logic. You should also check out your ZEIT Dashboard. It provides many helpful tools such as log monitoring that will help you debug your deployed maker.

You might also like

Pin It on Pinterest

Share This

Share this post with your friends!

WhatsApp chat