Maintain Sui's Health and Earn Storage Rebates

Sui Storage Fund rebates, a unique feature of Sui, incentivize the Sui community to maintain a healthy Sui network.

Maintain Sui's Health and Earn Storage Rebates

Unfulfilled orders on DeepBook, Sui's first native liquidity layer, remain on-chain, using up network storage space. These unfulfilled orders also count against DeepBook's dynamic fields limit. Maintaining a healthy network and DeepBook's operability requires cleaning up these old orders.

Fortunately, Sui's storage fee mechanism rewards users for removing objects from the chain. Enterprising users can earn Sui Storage Fund rebates simply by finding and deleting DeepBook's unfulfilled orders. These actions also free up network storage and keep DeepBook available for robust order processing.

The easiest way to find and delete unfulfilled orders involves deploying a bot to do it automatically. Check out the reference code for a maximal extractable value (MEV) bot below. This free-to-use code can be compiled as is or modified to make a custom bot.

Sui storage rebates

Sui charges a storage fee along with gas fees when a transaction creates an object on the network. That storage fee goes into the Sui Storage Fund, which uses a staking mechanism to compensate network operators for maintaining on-chain storage. This design takes into consideration that operators may join and leave the network at any time, maintaining the fund in order to support operators who join after the objects they store were created.

As with all networks, unused files and other artifacts accumulate over time and take up an increasing amount of drive space. When the available storage space becomes fully used, service and performance degrades. On Sui, increased storage demands mean operators need to increase their storage capacity to ensure a performant network.

Deleting an object from Sui, such as an expired DeepBook order, frees up the space the associated objects occupied. Because storage fees are charged up front and for the life of an object, Sui returns 99 percent of the original storage fee as a rebate in SUI tokens. Storage fees on Sui are very low, so the rebate for a single deletion is correspondingly low. Although the transaction involved in deleting an object incurs a gas fee, in many cases the storage fee rebate exceeds the gas fee, resulting in a net positive outcome.

Unfulfilled DeepBook orders

Limit orders on DeepBook, where someone sets an amount they want to spend or receive for tokens, may go unfulfilled because they don’t find a match, similar to how someone might set too high a price for an auction and receive no bids. These unfulfilled orders eventually time out, yet remain on the network. Each order is an object that uses some amount of storage.

In addition, each order uses a dynamic field, a type of field that can be added or removed from an object on the fly. DeepBook has a limit of 1,000 dynamic fields across all of its pools on Sui. If the number of active plus expired orders reaches 1,000, DeepBook reaches the limit of 1,000 dynamic fields and can no longer process any orders until the number drops below 1,000.

The code below shows how to build a reference MEV bot that clears expired orders from DeepBook. When the bot deletes an object, the storage fee rebate associated with that object goes to the address used to execute the bot, helping maintain network health and DeepBook availability while rewarding the bot creator.

Build the MEV bot

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

This article includes only the sections of the code needed to create the bot. See the full code in the Sui repo.

To create a client that connects to the Sui network:

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

The following line retrieves all DeepBook pools using the PoolCreated events:

let allPools = await retrieveAllPools();

This section retrieves all expired orders from 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();

This code shows how to create a transaction to clean up all expired orders, and then get the estimated storage fee rebate using devInspectTransactionBlock:

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 repo shows how to sign and execute the transaction.

The code sample in the repo also demonstrates how to use a Helper function to retrieve all pages of dynamic fields. It then shows how to split the returned array into chunks.

The dry run transaction from the example code returns the 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

Incentivized community

Decentralized, permissionless networks such as Sui require some degree of community maintenance. Because expired orders are not owned by a specific Sui address, anyone can remove them, creating an opportunity to gain storage rebates. Although there are currently not a large number of expired DeepBook orders, this proactive guidance will help ensure a healthy DeepBook system over time as use increases.