Running Perp-maker for Fun & Profit: Part 2

This is the second article in our two-part series on how to run perp-maker, a market-making template for Perpetual Protocol v2.

In part one, we covered the basics of Perpetual Protocol, the risks and rewards of running the bot, and how to run it locally. It’s recommended to go through part one before reading part two.

In the following, we’ll guide you through how to run the bot on AWS Lambda with npm, preparation to go mainnet, as well as further modification suggestions. If you’re an experienced engineer, you should have no problem setting up the bot via the readme on our repo.

Let’s get started!

Run on AWS Lambda with npm

If you’ve gone through the steps in part one, you should be able to run perp-maker locally. Now, let’s try to deploy it to AWS Lambda.

If you’re not familiar with it, the main selling point of AWS Lambda is that, instead of renting a dedicated server on AWS to run your program 24/7. You only pay the times when your application runs on a shared server, which is more suitable for our use case as the bot only runs from time to time based on your settings. You can watch this video to learn more about AWS Lambda (or serverless in general) in 100 seconds.

As the first step, you need to register an account on AWS and install AWS CLI on your machine. Check the installation instructions for each OS here.

Once AWS CLI is installed, you need to configure your AWS profile by running the following command in your Terminal (macOS) or Command Prompt (Windows):

aws configure

Then you need to type your access key and secret. You can create them from the Identity and Access Management page.

Depending on your settings, sometimes you need to create a new user on AWS to generate a key. To do so, you need to click Users on the Identity and Access Management page and then create a new user with the permission to manage Lambda.

Following this, you need to type the AWS region you use in the .env file in your perp-maker folder. For instance, add AWS_REGION=ap-southest-1 to the file if you choose a server located in Singapore.

For other variables in the .env file, please check part one of this series or perp-maker repo to learn more.

By now we’re all set! Enter the following commands in your terminal to deploy the bot to AWS:

npm run build

npm run sls:deploy

You should be able to see the following responses if everything goes well:

Once your bot is running, you can see the real-time logs by going to the perp-maker-main Lambda function on AWS and clicking the “View logs in CloudWatch” under the Monitor tab.

Another way to validate if the template runs successfully is to check the target markets in the pool section on the UI. For testnet (Optimism Kovan), please visit testnet.perp.exchange. As for mainnet (Optimism), visit app.perp.com.

Prepare for Mainnet

Ready for mainnet? Here’s a checklist:

  • You need to get some USDC on Optimism. You can use TransferTo.xyz to bridge your USDC from another chain to Optimism. If you only have USDC on a centralized exchange like Binance or FTX and you only want to test a small amount out, you can use LayerSwap to transfer directly to Optimism; as for greater amounts like over 5,000 USDC, you can withdraw to BNB Chain or Avalanche’s C-chain and then use TransferTo to go to Optimism (requires a small amount of BNB or AVAX to pay for gas).

  • You need to get ETH on Optimism to pay for the gas fees. Much like USDC, you can use TransferTo or LayerSwap (for CEXes) depending on how much USDC or ETH you want to transfer. In general, each transaction on Perp v2 costs around 0.0001 ETH, so even 0.1 ETH can be used for a long time.

  • You need to change the endpoint in the .env file to the mainnet one.

  • You need to uncomment the two lines in the index.ts file that we’ve added in part one (// process.env["STAGE"] = "production" and // process.env["NETWORK"] = "optimism").

Further Modification Suggestions

As mentioned at the beginning of the article, this bot is just a template to market-make on Perp v2. Given the nature of an open-sourced software, anyone can add functionalities to this bot.

Here are some directions that you can explore:

  • Provide single-sided liquidity:
    Currently, the bot only supports a fixed range above and below the market price. Another way to market-make on Perp v2 is to only provide liquidity for a single side, i.e., only above or below the current market price. One major benefit of providing single-sided liquidity is that when the price moves in the range and then subsequently moves out of the range, the maker can collect fees without any impermanent loss. You can already provide single-sided liquidity on the UI with the simple mode, or “Easy LP" as we call it.

  • Close the newly created position gradually:
    With the current design, the bot will adjust your liquidity when the price is out of the LIQUIDITY_ADJUST_THRESHOLD. When doing that, it’ll realize the impermanent loss by closing 100% of your taker position. This approach should be fine for small positions. However, if your position size is quite large, it’s better to close your position gradually to reduce the slippage incurred in each trade.

  • Utilize the multi-collateral feature:

    One of the selling points of Perp v2 is multi-collateral support, meaning that users can deposit ETH, USDC, FRAX, (and more assets in the future) as the collateral for their positions. The current template only supports USDC as the collateral. One major benefit of using ETH as the collateral is that your collateral value will increase as the price of ETH increases, which is handy if you’re providing liquidity to the ETH market as you’re acting as the short side during the bull market. In other words, in net USD terms, you’re collecting transaction fees without liquidation risk.

That’s the end of our two-part series on how to run perp-maker!

We’ll release another tutorial on how to run perp-curie-arbitrageur very soon! In the meantime, feel free to join our Discord where we have a #coding-chat channel for questions you encounter when building on top of Perp v2.

Helpful Resources

Translations of this article are available in Hindi (हिंदी) and Mandarin (普通话), thanks to the help of our Perpvangelists!

Subscribe to Perpetual Protocol 🥨
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.