OPEN YOUR CRYPTO OPTIONS TRADING ACCOUNT NOW

Lyra Protocol Engineering Update

Lyra Protocol Engineering Update

It’s been a busy time for all the engineers at Lyra, but now that we’ve settled into a rhythm it’s time to update the community with what’s been happening behind the scenes.

We’ve been steadily growing and have now hit 11 core contributors working on the project full time (by the new year). We’re still looking for people to come help so if you like the project and want to contribute in any way, feel free to reach out to us on discord or dm us on twitter @lyrafinance .

When we started this project we committed to launching on L2 Optimism and integrating with Synthetix. We wanted to prove to the world that options could be traded cheaply using the new optimistic rollup technology. We took the stance that centralised side chains could never be the future, as they lack the security that the L1 blockchain provides.

We chose to integrate with Synthetix as we were familiar with the system and it provided certain advantages (no slippage on exchanges, no flash loan attacks, frequently updated Chainlink pricing on L2) over using a system like Uniswap. Synthetix also has an amazing community that we wanted to tap into, and hopefully draw to using our product - and in doing so have a symbiotic relationship with the development of Synthetix. For these advantages, we accepted the limitation of there being only a small selection of tokens at launch. Hopefully in the next few months, we can work with Synthetix to reduce the trading fee and have more tokens added that the community wants to see.

Now let’s look at all the milestones we’ve hit.

  • 05-Jan: Development started
  • 07-Jun: v0.9 audit completed
  • 15-Jun: Announce Lyra
  • 12-Jul: Testnet comp
  • 22-Aug: v1.0 audit completed
  • 25-Aug: Lyra ETH pool launch
  • 13-Sep: Uni pool reward program
  • 17-Sep: Public LPing
  • 29-Sep: Updated mainnet deployment & LINK pool launch

It’s crazy to think just how much we’ve achieved in the 4 months since announcing our project. We now have a community of over 8k discord members and 9k twitter followers. Let’s dig into some key moments in terms of smart contract development.

Development constraints

To begin with, it’s important to state that working in the Optimism environment had constrained what we could do in our contracts - and forced our hand in developing contracts in a style that doesn’t really translate to the ethos of simplicity and modularisation that is touted in the Ethereum white paper. Specifically in regards to the strict gas limit that was enforced on all transactions, including contract deployments. While 11 million gas seems like a lot, operations on L2 used up a lot more gas than traditionally on L1.

With the upcoming regenesis, a lot of these limitations are lifted, and the development process can more easily match exactly how it has been done for L1 contracts. We’ll cover those changes in a bit.

v0.9

At this time, it was not easy to run the Optimism chain locally, and we had to spend a lot of time developing custom scripts to deploy and run integration tests on the local chain, and then running into surprises when deploying to kovan. Eventually we got into a nice flow where we could test and deploy easily - better understanding the constraints.

Given the gas limit constraints, our hand was forced into developing systems that were more monolithic, and communicated between each other as little as possible. If you were to read through the code (LyraGlobals being a good example), you can see a pattern of generating structs that hold onto variables that are passed through permissioned functions to avoid the excess gas calling contracts multiple times and only where necessary.

This was the first set of contracts that were audited.

We were happy with this system, and it was the system we used when running the Testnet Competition (with our own mocked Synthetix contracts). The testnet competition brought in many engineering challenges that we managed to get through, though I think we’ve had many learnings (especially with computing the leaderboard) which we’ve implemented in our latest reward distribution scripts.

v1.0

When we started running full e2e tests for v0.9 on Kovan using the real Synthetix contracts, we quickly found out that the transactions for opening/closing long calls would not work due to the gas limit as exchanges were happening atomically whenever an option was purchased. This change alone would require another audit, so we decided to take the opportunity to add in more functionality to the system.

Given the info from the v0.9 testing, we had to split out atomically exchanging collateral for long calls into a separate transaction. This was a public keeper function `LiquidityPool.exchangeBase()` - this meant logic around round ending and available collateral was also changed to accommodate this change.

This work also introduced the OptionToken ERC1155 tokenised representation of option positions and the TradeType enum.

Once this was successfully audited, we launched the ETH market.

Lyra Rewards

With the introduction of Lyra rewards we’ve created a system of caching and calculating distributions via events emitted from contracts. We’ve made these public in the https://github.com/lyra-finance/reward-distribution repo so anyone can run and verify they get the same results.

v1.1

Since launching, we became aware of an issue in the contracts which allowed LPs to take an action that was not supposed to be allowed (signalling withdrawal after a round has already concluded). If gone unchecked this had the potential of messing up internal accounting in the system, as well as temporarily freezing LP withdrawals until the conclusion of the next round - both of these to the extent of the size of the liquidity certificates that took this illegal action. In the worst case, long options that had a settleable value may have paid out with 0 if all the “reservedQuote” funds were exhausted. We quickly patched this issue (this bug was introduced between v0.9 and v1.0, so we could revert to v0.9 logic).

Alongside this, we fixed two issues with events that we became aware of post launch. The full changes can be seen in the following commit: https://github.com/lyra-finance/lyra-protocol/commit/d8417dfe4e07f3683eb100adbcfcf96d3b312300

At this time we are also aware of an issue with users being unable to close long positions if the collateral in the pool has been exhausted. This is unintentional, however the changes required to fix this would be too major to release promptly without an audit.

Optimism Regenesis - OVM 2.0

Coming at the end of October (14th for Kovan, 28th for mainnet), Optimism is having a regenesis to release a plethora of changes to have all L1 tooling and contracts work as is on L2 (https://medium.com/ethereum-optimism/the-future-of-optimistic-ethereum-7f22d987331). This is huge for the success of Optimism, as any project can now come and deploy contracts that work on L1 directly to L2 (given their protocols/mechanisms can be copied). The change will also bring gas usage to be equal to that as on L1, without changing the gasLimit. This means a lot more will be able to fit in a transaction, so a lot of our changes between v0.9 and v1 were no longer necessary.

Behind the scenes we’ve been working to be able to keep our dApp working smoothly before and after regenesis via an event caching system. However we will be testing all edge cases as the regenesis occurs on Kovan to ensure all funds are safe over the period.

v1.2

So what's next, does the upcoming Optimism regenesis have any impact on our contracts? In short, yes. Are we having a massive makeover? Not yet.

Firstly let’s address delta hedging. Where is it? Since our launch we’ve been working closely with Synthetix to get shorting through the door and launched on optimism, and they are almost there. Unfortunately the gas usage will prevent us from using it until regenesis, and as the Synthetix shorting contracts have changed, we need to do thorough integration testing with the final version before we can commit any user funds into the automated delta hedging system.

As for the changes we’re introducing, we want to fix the issues we have seen with the current system. Most important features to add are:

  • Atomic exchanging for long call collateral
  • The ability for traders to close longs when the pool is full
  • The ability to settle many options after expiry at once
  • Using the Synthetix AddressResolver to keep Synthetix contract addresses up to date automatically
  • Use synthetix.exchangeWithTag() for potential fee rebates for LPs
  • Modifying events to better suit analytics/subgraph needs
  • A switch to enable/disable delta hedging between rounds (allow the extra 1/3rd of the collateral to be used until shorting is available for each of the individual markets - or have the ability to disable it if LPs don’t want it)
  • Slippage prevention (ensure trades have the same price as shown in dApp)

While we would like to include larger pieces of work, we don’t want to slow v2 development, so we will keep the changes to the ones mentioned above. These changes are significant enough that an audit will be necessary. Details for the audit are currently being confirmed. We estimate that this version will be out early Q1 2022.

What’s next?

We think v1.2 will be the final set of contracts we release until v2. Our mechanism team has been working furiously to create a seriously jacked system, which will blow v1 out of the water. Beyond this, we will focus strongly on simplicity and modularisation. The possibilities are endless at this stage. ZK-rollups? Margin system? Capital efficient spreads? Each of these require a huge engineering and RnD effort - so we'll provide more clarity on timelines when we have more confidence.


About Lyra

Lyra is a protocol for trading options on Ethereum. Lyra allows traders to buy and sell options that are accurately priced with the first market-based, skew adjusted pricing model. Lyra also quantifies the risks incurred by liquidity providers and actively hedges them, encouraging more liquidity to enter the protocol.

Stay tuned for more important updates, key date announcements, and exciting opportunities by following us on Twitter.

Join the Lyra community on Discord to get involved; provide early feedback, be the first to learn about new opportunities with Lyra, and be a part of building the future of DeFi.

Marquee Component
OPEN YOUR CRYPTO OPTIONS TRADING ACCOUNT NOW