The inspiration to build DeFi Puzzle comes from looking at the most popular crypto trading instrument today: perpetual swaps on Bitmex (and Deribit, and Binance).

We were trying to come up with a trust-minimized alternative and came to an understanding we already have most of the elements in place:

  • money market (Compound) for underlying liquidity

  • tokenized deposits (cTokens, or what we call Long tokens)

  • tokenized complex positions (nonfungible tokens)

In addition to those existing elements we need to tokenize the money market liabilities (what we call Short tokens) and provide traders with a straightforward dashboard where they can combine their money market positions to recreate trust-minimized financial products like perpetual swaps.

What it does

Please note the current iteration of the app is a simulation only.

DeFi Puzzle allows users with existing Compound money market positions to combine (“bundle”) their Long and Short positions and thus create their custom financial products such as leveraged long/short positions with custom leverage.

Simple examples:

Assume ETH price of $150.

1) Combining 1 Long ETH + 150 Short DAI results in a bundle with $0 initial value which nets the holder a profit when ETH price moves up and results in a loss when ETH price moves down.

2) Combining 1 Short ETH + 150 Long DAI is an inverse bundle that profits from ETH price moving down.

3) Combining 1 Long ETH + 75 Short DAI results in a bundle with a $75 initial value. A trader can construct or buy 2 such bundles for a price of 1 ETH (ie $150). Such a bundle is effectively an ETH long position with leverage of 2.

Bundle examples

By combining Long and Short tokens of various nominal amounts, traders can construct their custom financial products. You can find more detailed examples of how various bundles can be constructed under this link:

In the linked sheet we have only included assets that are available in the current iteration of the app. In future iterations, more assets will be available, eg. wrapped Bitcoin (WBTC). This way, users will be able to construct advanced leverage trades betting on bitcoin price movements using trust-minimized DeFi building blocks.

Moreover, when we include timelocks, traders have the option to create forwards/futures with fixed maturities.

Nonfungible tokens

Once any bundle is constructed and confirmed, the user receives a nonfungible token (NFT) into his wallet. User can then hold this token for their own speculative needs, or sell it to other traders, for example with some premium on a decentralized exchange. We believe such trading of ready-made custom financial products can arise due to the combination of high capital requirements of some bundles (especially those with high leverage ratios) and much lower net initial value of some bundles (please see the above-linked cheat sheet for illustrative examples).

Unbundling process and custom simulation parameters:

Once user has created a bundle withing the DeFi Puzzle app, he has the ability to “unbundle” (by clicking on the existing bundle in the left-hand ribbon).

The unbundling process in the current iteration of the app allows user to explore various scenarios by changing three parameters: elapsed time (in days), new price of the Long token and new price of the Short token (we are keeping APRs invariable for the sake of simplicity). User is shown the original state of the bundle in comparison with the user-defined scenario. This way, users can play around with various scenarios and devise strategies for various leveraged trades, which could be executed in the future mainnet iteration of the app.

Explanation of individual lines shown in the “This bundle represents” field:

Position: type of the trade (Long/Short ETH or Complex)

Leverage: what implicit leverage is the bundle operating with (ie. how much of the speculative asset could the trader buy for the full price of 1 unit of the asset in the case of leveraged long)

Net value of the bundle: value of long position minus value of short position

Collateralization ratio (this bundle): long positions divided by short positions, bundle only

Collateralization ratio (account total): long positions (bundle + held in account) divided by bundle short positions

Required collateralization ratio: ratio in which the short position needs to be overcollateralized (per Compound money market on Ropsten testnet)

Long position yield: APR yield of the long position (per Compound money market on mainnet)

Short position yield: APR cost of the short position (per Compound money market on mainnet)

Accrued long position yield: total APR yield for the time elapsed

Accrued short position cost: total APR cost for the time elapsed

Total cost to unbundle: original bundle short position component plus accrued short position cost

DeFi Puzzle isn’t just a different UI for Compound; it’s a second layer DeFi solution broadening the options of traders looking for trust-minimized alternatives to today’s big exchanges.

How we built it

After the initial research, we focused on building the app that would show clearly and concisely how our idea will work. Our main goal was to show users that constructing financial products like leveraged longs/shorts can be easy and intuitive. From our experience, we are well aware that trading on leverage without a clear understanding of the nature of the trades and the associated risks is the main cause of unnecessary losses.

The design of the user interface was one of the first undertakings. The name of the project itself - DeFi Puzzle - is a reference to how easy it should be for the users to construct their financial bundles: as easy as fitting various fitting puzzle pieces together (where the proverbial puzzle pieces are their Compound money market positions).

The current iteration of the DeFi Puzzle app is only a simulation of our vision and is currently only built in Javascript and API calls.

Challenges we ran into

Throughout this hackathon, we greatly improved our understanding of what can be done once we have the basic DeFi building blocks in place (liquid money market with tokenized deposits & liabilities, possibility to combine them in NFT bundles). On the other hand, we discover potential obstacles to the realization of our idea that we weren’t fully aware of in the beginning.

We found out there are several areas of further development we need to undertake before the utility showcased in our simulation app is ready to be deployed on the Ethereum mainnet:

Short tokens development: currently, only deposits on Compound are tokenized (through cTokens). We need to provide the users with the ability to also have their liabilities represented in a token form (Short tokens). These Short tokens need to have restrictions in place that restrain under which conditions such tokens can be created, transferred and held. Since Short tokens always have negative value, they need to be held in an account with tokens of positive value that can be liquidated in case of need (fall under a certain collateralization ratio threshold). This means that Short tokens should be either bundled with Long tokens of sufficient extra value (so that the bundle itself never becomes undercollateralized), or the bundle has to be held in an account with further Long tokens (as is the case with Pure Upside/Downside bundles). Transfer of Short tokens in their unbundled form has to always be confirmed by the recipient and the recipient’s account needs to be sufficiently collateralized before the transfer is executed.

Long tokens development: although we already have cTokens in place, our concept of Long tokens requires several changes. First, Long tokens need to have transfer restrictions in place to prevent abandonment of liabilities in the form of Short tokens. Short tokens need to bind Long tokens of sufficient value to a certain address. Second, to provide for good user experience, Long tokens need to have a nominal amount equal to the underlying asset: 1 ETH deposited in Compound needs to result in 1 L-ETH in Long tokens. cTokens currently don’t reflect the underlying nominal amounts, as they accrue interest through changes in exchange rate versus the underlying asset. Third, when users borrow from Compound money market, they should have the ability to receive the Long tokens instead of the underlying asset. This would greatly increase the user experience when they borrow from the Compound to later bundle their positions - only liquidatable Long tokens are allowed in bundles, not the underlying assets.

Liquidation procedure: since custom bundles with possibly a very high leverage are allowed to be constructed, we need a streamlined liquidation procedure in place. Current liquidation procedure on Compound relies on triggers from human liquidators (or their bots), but this may prove insufficient in case of need of fast liquidations of high value. Therefore we need to explore the possibility to liquidate bundles by utilizing automated swap protocols such as Kyber.

Unbundling: we need to design a straightforward and safe process of paying down the liability (Short tokens) and thus unlocking the asset part of the bundle (Long tokens). This can be done in two ways. First, the user simply pays off the liability with the same asset as the liability (e.g. L-DAI pays for S-DAI liability). This, of course, requires the user to have the exact amount (or slightly more as the interest accrues every block) of the asset. Second, we could provide the user with the ability to pay down the liability in a different asset - for example, to pay down S-DAI with L-ETH. For this, automated swap protocols like Kyber are the natural fit. The ability to easily pay down the liability in a different asset would be good for simple unbundling: within a bundle of 1 L-ETH and 150 S-DAI, the S-DAI liability would be paid off with the L-ETH. Therefore, if the ETH price was $200 at the time of unbundling, the user would end up with a net 0.25 L-ETH.

The way we tackle these developments depends on how integrated we can get with the Compound protocol itself. Ideally, we would like to see Long & Short tokens as an integral part of the Compound as that would make further developments much easier. If that’s not possible, we can build the elements necessary for DeFi Puzzle by wrapping cTokens and Compound liabilities and introducing Long & Short tokens this way.

Accomplishments that we're proud of

We’re happy we came up with a way of communicating our idea straightforwardly. Leveraged trades aren’t very intuitive and we believe our app can improve the understanding of how such trades work and hopefully decrease the ratio of losing trades. We also hope efforts like our app can bring in more traders from the big exchanges to DeFi and reduce the systemic risk of centralized custodians.

What we learned

Mostly we learned a different way of looking at leveraged trading. Working on DeFi Puzzle drove us to adopt a user-centric viewpoint and got us thinking deeply about the individual building blocks of a leveraged trade and how these can be combined while not letting the users drown in complexity.

What's next for DeFi Puzzle

We need to undertake further research & development in the areas described in “Challenges we ran into”.

Our focus for future iterations is to build a mobile-first version of the app, in order to achieve stronger user adoption.

From the technical standpoint, we would like to develop following areas:

  • Timelocked contracts for fixed-term futures/forwards
  • Margin calls to alert users their bundles are nearing liquidation
  • Stop loss functionality to prevent forced bundle liquidation

We are looking for grants, investments & development partners.

Follow our progress at

Built With

+ 2 more
Share this project: