Easily build MEV robots to maintain Sui network health and earn profits

DeepBook is Sui's first native liquidity layer. Uncompleted expired orders still exist on the chain, which takes up network storage space. These expired orders also count towards DeepBook's dynamic field limits, and maintaining a healthy network and DeepBook operability requires cleaning up these old orders.

Fortunately, Sui’s storage fee mechanism rewards users for deleting objects from the chain, and far-sighted users can earn returns on Sui’s storage funds by finding and deleting DeepBook’s outstanding orders. These operations also free up network storage space, keeping DeepBook available and using it for robust order processing.

The easiest way to find and delete expired orders is to deploy a bot that does this automatically. Check out the reference code for the maximum extractable value (MEV) robot below. This free-to-use code can be compiled as-is, or modified to create custom bots.

Sui Storage Return

Sui charges storage fees when transactions create objects on the network, as well as gas fees. This storage fee will go toward the Sui Storage Fund , which uses a proof-of-stake mechanism to compensate network operators for the cost of maintaining on-chain storage. This design takes into account that operators may join and leave the network at any time, so a fund is maintained to support those operators who join after the objects they store are created.

As with all networks, unused files and other items accumulate over time and take up more and more storage space. When available storage space is fully used, service and performance degrade. On Sui, increased storage requirements mean operators need to increase their storage capacity to ensure good network performance.

Deleting an object from Sui, such as an expired DeepBook order, will free up the space occupied by the related object. Since storage fees are charged in advance and objects are charged storage fees during their lifetime, Sui returns 99% of the original storage fees in the form of $SUI. Storage fees on Sui are very low, so the refund for a single deletion is correspondingly low. Although deleting an object involves a gas fee, in many cases the storage fee rebate exceeds the gas fee, resulting in a net benefit.

DeepBook expired orders

In limit orders on DeepBook, someone sets the amount they wish to spend or receive for a token, but these orders may not be filled because a matching order cannot be found, similar to how someone might set a price that is too high for an auction. Unsuccessful shooting. These unfilled orders will eventually expire but still exist in the network. Each order is an object and takes up a certain amount of storage space.

Additionally, each order uses dynamic fields, which is a type of field that can be added or removed on an object at any time. DeepBook has a limit of 1000 dynamic fields across all pools on Sui. If the number of active orders plus expired orders reaches 1,000, DeepBook will reach the limit of 1,000 dynamic fields, and DeepBook cannot process the order again until the number drops below 1,000.

The code below shows how to build a reference MEV robot for clearing expired orders in DeepBook. When a bot deletes an object, storage fee rebates associated with that object are sent to the address used to execute the bot, helping to maintain the health of the network and DeepBook's availability while rewarding the bot's creator.

Building an MEV robot

The following reference code, also available in the Sui GitHub repository , demonstrates how to create a simple MEV bot to remove DeepBook expired orders from the network.

This article only includes the portion of the code required to create the bot, see the full code in the Sui repository.

(1) Create a client connected to the Sui network:

const client = new SuiClient({url: 
"https://explorer-rpc.mainnet.sui.io:443"});

(2) The following line retrieves all DeepBook pools using the PoolCreated event:

let allPools = await retrieveAllPools();

(3) This part retrieves all expired orders in each pool:

let allExpiredOrdersPromises = [];
for (let pool of allPools) {

allExpiredOrdersPromises.push(retrieveExpiredOrders(pool.pool_id).then((expiredOrders) => {
  return {pool, expiredOrders}
 }));
    
}
let allExpiredOrders = (await Promise.all(allExpiredOrdersPromises)).flat();

(4) This code shows how to create a transaction to clean up all expired orders, and then use devInspectTransactionBlock to get the estimated storage fee return:

let {rebate, tx} = await createCleanUpTransaction(allExpiredOrders);

console.log(`Total estimated storage fee rebate: ${rebate / 1e9} SUI`);

In addition to the code above, the code in the repository shows how to sign and execute transactions.

The code example in the repository also demonstrates how to use the Helper function to retrieve dynamic fields for all pages, and it shows how to split the returned array into chunks.

The interfering running transaction in the sample code returns expired orders on the network, similar to the following:

Pool d9e45ab5440d61cc52e3b2bd915cdd643146f7593d587c715bc7bfa48311d826 has 6 expired orders out of 28 orders
Pool f0f663cf87f1eb124da2fc9be813e0ce262146f3df60bc2052d738eb41a25899 has 6 expired orders out of 21 orders
Pool 18d871e3c3da99046dfc0d3de612c5d88859bc03b8f0568bd127d0e70dbc58be has 1 expired orders out of 1 orders
Pool 5deafda22b6b86127ea4299503362638bea0ca33bb212ea3a67b029356b8b955 has 5 expired orders out of 57 orders
Pool 7f526b1263c4b91b43c9e646419b5696f424de28dda3c1e6658cc0a54558baa7 has 72 expired orders out of 2925 orders

Inspire the community

A decentralized, permissionless network like Sui requires a certain level of community maintenance. Since expired orders do not belong to a specific Sui address, anyone can delete them for a chance to get storage fees refunded. Although the current number of expiring DeepBook orders is small, this proactive guidance will help ensure the long-term health of the DeepBook system as usage increases.


About Sui Network

Sui is an L1 public chain redesigned and built based on first principles, aiming to provide creators and developers with a development platform capable of hosting the next billion users in Web3. Applications on Sui are based on the Move smart contract language and are horizontally scalable, allowing developers to support a wide range of application development quickly and at low cost. Get more information: https://linktr.ee/sui_apac

Official website | English Twitter | Chinese Twitter | Discord | English Telegram group | Chinese Telegram group

Guess you like

Origin blog.csdn.net/Sui_Network/article/details/133273873