patrickogrady.xyz Profile picture
building something new || previously @avalabs @coinbase @stanford || opinions are my own and will probably change

Feb 22, 2023, 13 tweets

[HyperSDK Build Journal]

Next up: Swaps on the TokenVM

To start, I'm just going to allow people to:
1) Create resting orders (with a fixed quantity and price)
2) Interact with resting orders (purchase some/all of the fixed quantity at a set price)
3) Cancel resting orders… twitter.com/i/web/status/1…

Context on "[HyperSDK Build Journal]":

At @luigidemeo's suggestion, going to start tagging these with #HyperSDKJournal to make them more searchable. 🙏

Finding that I'm frequently in need of a unique ID to name things that my Actions create (like an OrderID).

There isn't a great way to do this with the current interface because Actions need to provide all StateKeys they'll touch before execution. This means we can't just use… twitter.com/i/web/status/1…

This change looks like:

Create Order is done...now working on Close Order.

Then, I'll add support for actually filling one of these resting orders.

After all that, I'll add a number of fun integration tests that should make it clear how to interact with the TokenVM.

#HyperSDKJournal

Close Order is now complete 👀: github.com/ava-labs/hyper…

You can see that most of the work of adding an Action to an existing HyperVM is to:
1) Define the on-chain representation
2) Add any missing "Storage" functions (in this case, I needed to add the ability to read orders from… twitter.com/i/web/status/1…

Added Fill Order (untested): github.com/ava-labs/hyper…

To make the output of a fill more useful, I also added a custom result marshaller that contains the result (how much you got vs how much you expected to get).

This is the first Action that uses the conditional fee logic as… twitter.com/i/web/status/1…

Added a cool in-memory order book using the Uint64Heap I wrote for the mempool: github.com/ava-labs/hyper…

This will allow the TokenVM RPC to serve an "Open Orders" endpoint (that we will test in the integration tests).

#HyperSDKJournal

We now update the in-memory order book whenever a block is accepted 🚀

Next up: testing + RPC support

Went down the numerical precision rabbit hole for WAY too long working on overfill refunds (if you attempt to purchase more than the remaining units left on a order).

It is critical to support this flow as someone else may trade at the same time as you (so the order you thought… twitter.com/i/web/status/1…

After making this change, I was able to finish all the code and tests for the "TokenVM"!

Now, I just need to add a README and it will be good to merge: github.com/ava-labs/hyper…

Implementing all Actions took 600 lines and implementing Auth only took 108 lines! You can view the… twitter.com/i/web/status/1…

If you want to check out how to mint assets and fill orders, check out the integration tests: github.com/ava-labs/hyper…

(make sure to take a look at how the integration tests make use of the in-memory order book)

#HyperSDKJournal

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling