Inspiration

Connecting the lego blocks of DeFi.

What it does

In one transaction, MarginSwap does the following

  • Borrows any quantity of funds from the MarginParent Smart Contract
  • Uses those funds to place a trade on any DeFi exchange (Kyber, Uniswap, 0x, ...)
  • Deposits the output of the trade into Compound.finance
  • Uses the deposit in Compound.finance as collateral to borrow the input to the trade
  • Returns the input to the trade back to the MarginParent contract

Using this technique, MarginSwap allows the trader to get the maximum possible leverage given Compound collateralization factor. So if you're going long on ETH with a collateralization factor of 0.75, you can get upto 1/(1-0.75) = 4x leverage.

How I built it

With experience and deep knowledge of Ethereum's Smart Contract platform.

Challenges I ran into

While developing the Smart Contract, the Ethereum network had very high gas fees. So testing the system on MainNet required me spending quite a bit of $$.

Accomplishments that I'm proud of

I used the new create2 opcode to generate individual wallets for each user. So even before the marginswap contract is setup for a particular user, they can know their contract address. Also added a upgrade mechanism where the user has full control. Because the MarginSwap contract represents their wallet, they can update the code to be anything they'd like. However, if the updated code is not approved by the MarginParent, the MarginSwap contract will not be able to borrow funds from the MarginParent.

What I learned

DeFi is more amazing that I realized going into this project. So much power with an open ecosystem.

What's next for MarginSwap

For merkleX we developed a formal verification system. Looking to further develop that then formally verify the contracts developed for this project. I want unhackable code :).

Built With

Share this project:
×

Updates