Synthetix 2023: What We’ve Built

As we enter the holiday season, I wanted to share an overview of the work completed by Synthetix’s Core Contributors so far this year. We built a lot of awesome shit. This is a long post.

The year kicked off with the launch of Perps V2. Despite relatively low volatility in the crypto markets, this has facilitated over $30 billion in trading volume. With no incentives, Synthetix’s liquidity providers have experienced the most profitable days in the protocol’s history over the last month.

This post outlines the work on Synthetix V3, which was accomplished on top of monitoring, configuring, and upgrading the V2 system. The core system and spot markets are on mainnets, with perpetual futures markets and the cross-chain elections system around the corner. Our investment in developer tooling is paying off, keeping up the Core Contributors’ engineering velocity and that of our integrators.

Core

At its core, Synthetix performs two functions: it issues a decentralized stablecoin and it allows liquidity providers to back derivatives markets that exchange that stablecoin into other assets. It’s something like a combination of Uniswap and Liquity. The protocol can be deployed on any blockchain that implements the Ethereum Virtual Machine. It integrates with decentralized oracle networks like Chainlink and Pyth.

Synthetix V3 is modular and permissionless in its design. The protocol’s governance decides what collateral is acceptable and sets risk parameters for each type. Liquidity providers can take out an over-collateralized loan of dollar-denominated stablecoins against this collateral. Pools can be created which consist of vaults for each collateral type. Pool owners can distribute rewards to liquidity providers delegating collateral to these vaults (helping bootstrap initial liquidity) and then configure the pool such that it backs derivatives markets of their choosing.

When traders open and close positions in markets, they deposit and withdraw the stablecoins generated by the protocol. This reduces or increases the debt of liquidity providers that are delegating their collateral to the pools that back these markets. If the market implementations are sound and collect fees, this incentivizes liquidity providers by paying off their loans.

Synthetix V3 allows for a many-to-many relationship between pools and markets. This creates a “marketplace of liquidity,” but could lead to scaling constraints from the added complexity. Because traders are highly active and cost sensitive—while liquidity providers are generally passive and, ideally, profitable—the distribution of changes to debt are executed with lazy evaluation. This means gas costs can stay low for traders, regardless of the core system’s configuration.

Imagine a Plinko machine. Traders move stablecoins in and out of the top of the system with a simple, cheap transaction. Then, anytime someone pokes a relevant part of the core system, the distribution occurs on-chain. A consequence is that functions which might otherwise be read functions are instead write functions. (Apps displaying values to users can always simulate the result of the function call to read the value without spending gas.)

A more crucial aspect of the protocol’s engineering is its integration with decentralized oracle networks. Determining the current price of an asset is already a non-trivial problem in traditional finance. (Is a quote from one minute ago acceptable? One millisecond? How big of an order are you trying to fill? What if exchange venues provide different quotes?) Then add the complexities stemming from latency in block production, miner extractable value, cryptographic verification of price data, and the implementation specifics of decentralized oracle networks.

Synthetix V3 has the logic relevant to this encapsulated in a stand-alone system, the oracle manager. This is a stateless system which allows users to register nodes that can be connected in a tree structure. For example, you might need a price for ETH that is no older than 5 seconds. You might want to use the price from Chainlink if it’s fresh enough, or otherwise use a price from Pyth. Then, you might want to average this price with the price available from Uniswap in the ETH/USDC pool. It could also revert if these prices are more than 20% apart. All of this can be specified with a single node ID, used as a configuration setting in the core system and market implementations.

Another important consideration is price data availability. If a price is needed that’s no older than 5 seconds and it isn’t already available on-chain, we need a way for users to provide it. Rather than relying on decentralized oracle networks to push prices on-chain themselves, Pyth enables price data to be pulled on-demand. We’ve developed ERC-7412, a standard by which clients can recognize the need for off-chain data, like fresh prices, and automatically re-stage the transaction as a multicall that prepends the cryptographic verification of the data to the desired transaction.

The core system has been deployed to Ethereum and Optimism Mainnet, along with the new implementation for spot markets. It has been configured to match the Synthetix V2 system. These deployments are alpha releases; integrators should anticipate the potential for (pre-announced) interface breaking changes if approved by governance. Certain functions, such as the creation of new pools and the registration of new markets, require governance approval on this deployment for now as a risk mitigation measure. Integrators have started building front-ends, markets, and vaults for automated liquidity provisioning strategies around these deployments.

The core system includes functionality for cross-chain stablecoin transfers, powered by Chainlink’s CCIP. Synthetix V3 exceeds feature parity with V2, with the exception of perpetual futures markets (which are imminent, described below) and cross-chain pool synthesis. We’ve built a functional prototype of cross-chain pool synthesis with Wormhole’s forthcoming Cross-Chain Queries. Cross-Chain Queries would also enable the creation of caching functionality, increasing protocol scalability without increasing gas cost for users. (This integration could be transparent for end-users by leveraging ERC-7412.)

The migration plan entails a legacy market, which will allow the V3 protocol to provide liquidity to the V2 protocol, liquidity providers to seamlessly migrate their positions from V2 to V3, and the exchange of stablecoins issued by V2 to that of V3. Given the success of Perps V2 (and to avoid adding unnecessary smart contract risk), the current thinking is that the legacy market can be rolled out after the V3 markets are clearly constrained by a lack of liquidity.

Markets

The most notable improvement of the market implementations in Synthetix V3 is the order settlement logic, which is perhaps the most critical function of this code. Perps V2 introduced the use of pull-based oracles, where a trader makes a commitment to trade on an initial transaction and then a bot can pull in a price to settle the order on a subsequent block. This eliminates the possibility of traders front-running the latest prices made available by the oracle manager.

Both spot and perps markets in V3 now implement this pattern and make a further improvement which leverages Pyth’s Benchmarks. Rather than settling orders with prices available in a window following the commitment, orders can only be settled with a price specific to a timestamp associated with the order. This eliminates the possibility of price optionality.

Though perpetual futures markets are generally preferred by active traders, Synthetix V3’s spot market provides a large amount of utility to the protocol. Fundamentally, the spot markets generate a token (a “synth”) which tracks the value of an asset as an ERC-20 token. This means synths are compatible with virtually every existing wallet application for Ethereum.

In Synthetix V3, governance can allow specific market implementations to deposit collateral into the core system, not only stablecoins. This allows spot markets to also serve the role of “wrappers” in V2, which increase stablecoin scalability. Rather than requiring users to take out an over-collateralized loan to generate stablecoins, they can wrap assets into their synthetic equivalents and sell them for the stablecoin. Better still, a new skew fee incentivizes arbitragers to reduce the protocol’s exposure to price fluctuations of wrapped assets.

The spot market is also integrated with the V3 perpetual futures markets. The new perps implementation can accept synths as collateral, not only stablecoins. Traders can also use the same collateral to margin multiple positions in a single account. This, plus improved logic around liquidations, enables the functionality users would expect from a centralized exchange while also improving risk management for liquidity providers.

Perps V3 can integrate with Optimism’s Gas Price Oracle through the oracle manager to dynamically set incentives for bots to settle trades. Traders just submit an order and receive a notification when their order has been settled. As a fallback, traders can use any ERC-7412 compatible client to settle orders themselves. (The function is completely permissionless.)

The Perps V3 Testnet Competition was conducted last month which generated valuable feedback from traders and integrators. Updates based on this feedback are currently in audit. Synthetix is tracking for a mainnet alpha launch on Base (referred to as the Andromeda Release) before the end of the year.

In parallel, Synthetix Core Contributors have been developing an alternative implementation of perpetual futures markets optimized for the Ethereum Mainnet deployment, codename BFP (Big Fuckin’ Perps). While the main perps implementation aims to enable an end-user experience that rivals that of centralized exchanges, this implementation is designed to facilitate large, gas-optimized wrapped basis trades that consist of a short ETH position margined with wrapped staked ETH. This will allow protocols like Ethena to integrate with Synthetix to generate scalable decentralized stablecoins.

Governance

Synthetix’s current elections system was built with the initial iteration of the new framework and developer tools created by the Core Contributors. The latest iteration of the election system, currently in audit, uses the current version of the architecture employed elsewhere in the codebase and adds greater flexibility to the system.

Similar to how the Synthetix V3 core protocol and markets are effectively a superset of V2 (i.e. V2 could be replicated as one of V3’s many possible configurations), the new elections system allows voting power to be calculated based on participation in the V3 system as well as V2. It also leverages Chainlink’s CCIP to allow voting power to be calculated based on participation in multiple deployments on various chains.

As before, each epoch consists of a nomination, voting, and evaluation period, after which NFTs are distributed to the winners for the following administration period. The NFTs can be integrated into other smart contracts, like Safe Modules, to allow for the signing of transactions related to any aspect of the protocol.

Front-ends

Synthetix V3 has no centralized front-end dependencies. Users generally interact with the protocol using ecosystem projects. There’s an informational page hosted on GitHub Pages and documentation, but the apps developed by Core Contributors are only made available on IPFS via ENS domains.

Anyone can run an IPFS node to access and host these apps (as well as some developed by ecosystem projects). In addition to the web apps, a Python SDK and a data analytics pipeline are under development.

Developer Tools

It simply would not have been possible for a team this small to build so much without next-gen dev tooling. To overcome the contract size limit, the Synthetix Router was developed to automatically generate code that routes calls to an arbitrary number of contracts. Library contracts like this include getter and setter functions, as would be in model code from an MVC framework. Add a standard UUPS proxy contract and we can build an upgradeable protocol of any size. For Web2 developers, this is like going from individual webpages generated with php—each consisting of a maximum of around a thousand lines of code that can’t be changed—to building with Ruby on Rails (including a package management system, described below).

Even with a solution to the contract size limit, running upgrades and configurations of complex protocols can be painful and unforgiving. Maintaining Synthetix V2 involves significant overhead with just two interconnected mainnet deployments (each with subtly different implementations and configurations). RPC endpoints used to submit the transactions for deployments can fail randomly. Also keep in mind that, unlike Web2 infrastructure, blockchains are immutable. On top of this, deployments entail coordinating transaction verification and signatures from governance.

When we built the prototype of Cannon—our DevOps tool—at the ETHDenver hackathon in 2022, the utility was more ambiguous. Not many teams had faced the same challenges as Synthetix’s Core Contributors. Although “Infrastructure as Code” is generally accepted as a strong pattern in Web2, there wasn’t any mature DevOps tooling in Web3. Since then, alternatives have appeared. I believe there’s absolutely space for multiple flavors of tools, though I’m more confident than ever with our approach. The generous grants we’ve received from Optimism and Safe to accelerate its development have reaffirmed this.

Cannon replaces deploy scripts with cannonfiles, which describe a desired state of a blockchain (rather than a list of transactions to execute). Users can “build” a chain into the desired state using the CLI, resulting in a package of data related to the deployment. If an RPC endpoint fails, the deployment finishes as best it can and then the build can be re-run to automatically pick up where it left off (based on the ‘partial build’ package). If signatures are required to complete a deployment, a ‘partial build’ package can be used to stage the remaining transactions to a Safe using the web deployer. Packages can be published to the registry on Ethereum.

Packages can be used by developers building integrations (like front-ends and bots) for local development and continuous integration scripts for testing. Packages include addresses and ABIs, which are leveraged by the interact tools in Cannon’s web app and CLI so users can execute transactions on deployed protocols. (This is especially useful for Synthetix, as Etherscan doesn’t have support for interacting with protocols using a router yet.)

Perhaps the most powerful feature of Cannon is its ability to use packages in cannonfiles, allowing for composability. A cannonfile can automatically import deployment data related to the protocols it integrates with. They can even provision entirely new instances of smart contracts and protocols.

This enables a GitOps workflow, where an unlimited number of deployments can be maintained without accruing additional overhead. Developers ship an upgraded version of code as a package. Then, a cannonfile for a deployment is updated to specify the new version, along with any configuration updates. Partial deployment data is generated after putting the new code on-chain. Then, signatures are collected to have the protocol use the new code (by having the proxy point at the new router) and enact any configuration changes. Finally, the completed package is published to the registry.

This creates a new paradigm for builders. Rather than just writing simple, immutable smart contracts that require a single transaction to deploy and no maintenance, we can build at a level of abstraction that involves an orchestration of many complex protocols across multiple chains. In my view, the industry has already built all of the “primitives”. Now, we need tooling on par with Web2 to create more sophisticated systems. Once proven out, these protocols can be made immutable. This will provide more protection for users than the traditional financial system ever could.

Zooming Out

It’s been a weird year for crypto. “The bear is for builders,” they say.

Layer 2 blockchains and decentralized oracle networks made huge progress increasing their performance and technical decentralization. Web3 user experience has made huge strides as well. Kwenta and Polynomial feel smoother than the user interfaces offered by my bank. During the testnet competition, they seemed on par with centralized crypto exchanges to me.

But most people wouldn’t know. The media remained fixated on Sam Bankman-Fried. His indictment was—paradoxically—painted as an indictment of crypto.

It’s as if reporters don’t understand that FTX was a centralized exchange. The code behind its fraudulent liquidations mechanism was only made public long after users’ funds were lost. If there are concerns with how Synthetix processes liquidations, you can make a pull request and present a SIP.

Plus, there’s no need to have a government make sure Synthetix didn’t send users’ funds to its ex-girlfriend’s venture capital fund. Anyone can just check what tokens are held by a deployment’s core proxy contract.

In a better world, regulators would shift more resources towards education as a tool to protect consumers. Whether or not we’re “out of the bear market,” it’s clear that decentralized finance isn’t going away. I hope more people learn about it.

Subscribe to Noah
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.