How Denaria Perpetual DEX Leverages Stylus to Make Trading More Efficient

GM everyone,

I’m Diego from Denaria, a fully onchain perpetual DEX powered by dynAMM, a new AMM design built specifically for onchain perpetuals trading.

I’m here to share with the Arbitrum community the recent work we have done to implement Stylus into our tech stack, and more specifically into our trading engine.

Our main goal is simple: make Denaria’s trading engine more efficient and cheaper to use for our users.

During the Arbitrum Open House Buildathon, we started testing how Stylus could improve the execution efficiency of some of the most calculation-heavy parts of our architecture.

The first implementation focused on CurveMath, one of the math components used inside our PerpPair engine. The first benchmark was not successful: migrating CurveMath alone made execution more expensive than the Solidity baseline because of the cost of moving between the EVM and WASM environments.

This was an important lesson for us: Stylus does not automatically reduce gas costs. It needs to be integrated into the right part of the architecture.

After that, we moved to a broader hybrid implementation, converting the PerpPair smart contract and its dependencies into a Stylus-based PerpEngine, while keeping the Vault, TWAP Oracle Middleware, and their dependencies in Solidity.

The early results are much more promising:

  • 12.2% lower execution costs for long trades
  • 13.4% lower execution costs for short trades

These are still preliminary results, but they confirm the direction we are exploring: the strongest gains come from making the trading engine Stylus-aware, not from moving isolated functions one by one.

I’m sharing the full article below, where we explain the process, the mistakes, the early wins, and what we are planning to work on next.

Would love to hear feedback from the Arbitrum community, especially from teams already experimenting with Stylus in production-like environments.

2 Likes