Utilise marginfi

satswassie
6 min readAug 23, 2022

--

marginfi

(this is not financial advice in the slightest, I’m literally a lego brick wassie on the interwebs)

Let’s delve into what they are at their base. marginfi is a decentralised margin trading protocol built on Solana that places emphasis on capital efficiency, risk management strategies, and being able to make full utilisation of margin. It’s an interface that splices Solana protocols, to allow DeFi users to run “strategies like cross-DEX perp funding rate arbitrage, or cross-DEX atomically hedged market making”. With the sudden and expected continuation of the number of markets, we are presented with a “critical problem: the fragmentation of the trader experience. As protocols specialise in their own product niches, traders must operate across protocols to optimise their financial exposure and access complementary products”.

they allow for users to

  • cross-margin your profits from one protocol to maintain losses in another
  • borrow/lend margin under one context
  • clear up the ability for complex market strategies by arbing exposures on different dApps at once

they’ve hinted at going beyond Solana too in their medium posts… imagine the delta neutral trading strategies you could utilise once this begins.

by unifying your on-chain liquidity in a single account and operating within marginfi’s overlayed risk framework theoretically users should have the ability to maintain better risk management.

Live market testing began back at the tail end of July.

marginfi state they’ve designed a next generation margin lending mechanism that optimises both lending and borrowing experiences. With the implementation of an adaptive interest rate curve called AIR-C in conjunction with the ”topology of the interest rate curve itself, intelligently optimised for borrow/lending dynamics to create safe and attractive yield opportunities”. A lot of fancy words obfuscating your view in that sentence there but if you break it down it’s hopefully rather simple.

They’ve released a sub stack that aims to give their thoughts on current market conditions, opportunities etc which is quite a good read, as it’s in their best interest to serve you with high quality information to utilise within the ecosystem while synchronously adopting people to their platform. Here’s a link to that https://mrgn.substack.com/

If you’re an avid Solana user, or even just frequent crypto twitter, I’m sure you’re aware the importance a liquidation engine is on the overall ecosystem. The recent Solend debacle left many uneasy about the state of DeFi apps and their ability to safely maintain large account liquidations, especially on an omni protocol margin level. They alleviate the stress on the underlying protocol by having the liquidation take place on their side, employing a proxy approach. They’re aware that this problem would be ever growing as ecosystems expand and don’t believe this to be the final approach and aim to be innovative in their future solutions.

They believe their lending, borrowing and rebalancing systems are top tier as they take care of

  • Automating lending on your stables
  • Automated borrowing (within appropriate constraints)
  • Automated liquidity management with an emphasis on protecting capital

marginfi is able to exist and have cross-margin via Underlying Trading Protocols (UTP’s)

The first edition of UTP’s consisted of Mango, 01 exchange, and Drift.

marginfi also aids underlying protocols by being their source of liquidity.

By decreasing the number of steps between transferring from a CEX to different DeFi protocols, they can help onboard/retain a greater amount of crypto users. This is partly because it lowers the number of transactions that a user would need to take to get their positions set up, but also because it allows for a more centralised hub of interactivity between dApps. More of a one stop shop for account management rather than opening multiple tabs at a time and signing an obscene amount of transactions, navigating overarching portfolio management skills between chains.

I’m a bull on creating dashboards that remove the obfuscation of DeFi and facilitate users to have the ability of minimising the steps they have to achieve capital efficiency. Crypto enables users to have freedom over their capital, then dApps help to make this process frictionless.

marginfi aims to lessen the gap in between these rule sets to create a coefficient interface. “marginfi gives traders the speed they need to capture time-bound market opportunities in the most capital efficient way possible”.

How do they do it? Tbh there’s a lot of things going on under the hood that we don’t need to completely understand more than it just works.

They have some nice simple component diagrams though that make you appreciate the steps they’re cutting out

All of the marginfi liquidity exists in one pool, an interconnected UTP allowing for ease of liquidity access. On top of this is the health indicator, calculated by a margin engine, that manages the state of your account to see whether or not your positions are in a healthy state. “The margining process is completely unassuming and always verifies the portfolio health after an action has happened. This enables very flexible use of the margining system, for example, if you have $0 of balance in your margin account and a position with $10k PNL in Mango Markets, the margining engine allows you to directly deposit $10k of collateral into 01 Protocol, without you having to (1) close your

Mango Markets positions, and (2) explicitly borrowing collateral before wanting to use it.” They use a large amount of data surrounding your margin accounts that you are utilising to allow for the ability of bridging liquidity that would otherwise be stuck on other protocols.

The account must satisfy requirements prior to trading or depositing collateral. “More broadly our margin engine ensures that this requirement is satisfied whenever an action happens that either lowers your account equity (opening new positions) or increases your initialisation margin requirement (borrowing liquidity)”. Every UTP is different in the way it calculates equity to maintain. The health of your account is of high priority, which is why they have a verifying margin system that measures actions that have the ability to impose a negative influence, and makes sure to check whether your account is in a healthy state, whether that’s before opening a trade, depositing etc. This machine is unassuming, meaning that it HAS to verify the health, unlike lenders lending money to 3AC… I suggest checking out their docs if you’re interested in the maths behind all these engines, simply because there’s not really a reason for me to spam them here.

Upon the scary event that your account gets liquidated, the engine allies for a liquidator to purchase the entire UTP account for a discount at a rate of 2.5%.

If an account remains with outstanding liabilities and no access to further liquidate the account is bankrupt. The system handles bankruptcies in two ways.

  1. The outstanding liabilities are covered from the insurance fund.
  2. If the liabilities can’t be entirely covered from the insurance fund the losses are socialised between lenders in the liquidity pool.

UTP accounts have to be created through marginfi, meaning that you cannot use your existing DeFi accounts, eg mango

marginfi has bots that they call keepers. These act in real time to protect both users, and the system by intervening as fast as they possibly can. This bot is open source, with plans on making incentives for people to run keeper bots of their own in the future.

The rebalancing of portfolios occurs whenever the system sees that one or more of your UTP accounts is below the level of its intended rebalancing threshold (this is called the UTP init margin requirement), this protects your account from liquidation until otherwise impossible. The mechanics within this system also do not allow for users to withdraw more than their UTP init margin requirements as to not automatically liquidate you for fat-fingering. It’s also designed this way to be able to repay any liabilities that may be required. Bot clusters are highly scalable and easy to replicate if demand requires it. They’re built to effectively retaliate to harsh market conditions/infra mishaps like:

  • Volatility spikes
  • Low/ extreme variations in TPS
  • RPC node failures

marginfi also announced that they will run their own RPC nodes that allow for unrestricted access for these bots with access as fast as possible, this obviously is done to help make sure that UTP accounts get swept by bots as much and as frequently as possible, even amidst RPC failure that the user may be experiencing.

You can clearly see the big problem that this team is solving here and why the existence of this dApp is necessary.

Links to stuffs:

https://docs.marginfi.com/

https://www.marginfi.com/

https://twitter.com/marginfi

https://github.com/mrgnlabs/marginfi-sdk

--

--