Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Liquid Insurance Funds #210

Closed
wants to merge 19 commits into from
Closed

feat: Liquid Insurance Funds #210

wants to merge 19 commits into from

Conversation

exdx
Copy link
Contributor

@exdx exdx commented May 22, 2024

This PR introduces a new feature to marginfi, an ability to create and interact with a liquid insurance pool that is integrated with a bank's insurance vault. Each liquid insurance pool offers a mint token which represents shares in the pool. Users can deposit and withdraw from the pool.

This feature presents another opportunity for users to earn yield on top of marginfi.

This commit introduces a new feature to marginfi, an ability to create
and interact with a liquid insurance pool that is integrated with a
bank's insurance vault. Each liquid insurance pool offers a mint token
which represents shares in the pool. Users can deposit and withdraw from
the pool.

Signed-off-by: Denton X <[email protected]>
@exdx
Copy link
Contributor Author

exdx commented May 22, 2024

CI is unhappy about unused variables but those should be resolved during the course of review.

Copy link
Member

@jkbpvsc jkbpvsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big missing piece here is bankruptcy handling where shares are devalued because funds are moved out of the insurance fund to cover bad debt.
If bad debt is covered from the insurance fund the value of LIF shares should be discounted by same margin the liquidity that was used in the insurance fund.
We additionally need the same logic when the insurance fund is being withdrawn from manually.

Additionally the accounting for the insurance fund seems broken. It not clear where tokens or shares are being used, or it seems both terms are used interchangeably.

On deposits users are depositing tokens in native amount, and receive shares based on the current value of the shares.
On withdraw users are depositing shares in exchange for bank tokens, priced at the time when the withdraw request is mature.

@jkbpvsc
Copy link
Member

jkbpvsc commented May 22, 2024

Also we need to make sure we can create these insurance funds through the MS -- meaning we need to be able to use a single signature -- all new accounts need to be pdas

Copy link
Contributor

@cavemanloverboy cavemanloverboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any deposit/withdraw tests?

@jkbpvsc
Copy link
Member

jkbpvsc commented May 23, 2024

The basic use cases that should be covered:

  • User deposits, earns interest, user requests withdraw, user withdraws
  • User deposits, user requests withdraw, earns interest, user withdraws
  • User deposits, lif handles bad debt, user requests withdraw, user withdraws
  • User deposits, user requests withdraw, lif handles bad debt, user withdraws
  • User deposits, user requests withdraw, user withdraws

@jkbpvsc
Copy link
Member

jkbpvsc commented May 24, 2024

Also create_withdraw_request_from_liquid_token_fund needs to somehow lock up the shares that the user wants to withdraw. Otherwise users can just create numerous withdraw requests and then claim them at any time.

@exdx
Copy link
Contributor Author

exdx commented May 24, 2024

Thanks for the reviews. I'm mainly going through and deleting code and updating the shares model.

TODOs:

  • Bankruptcy handling (giving the shares a haircut in case money moves out)
  • Locking shares that in the process of being removed
  • Use only PDAs to derive related addresses, instead of storing them in lif state
  • Add seeds to the lif state
  • Support multiple lif withdrawals
  • Calculate interest
  • Switch to account-based accounting model

exdx added 14 commits May 28, 2024 16:14
@jkbpvsc
Copy link
Member

jkbpvsc commented Jul 1, 2024

Closed in favor of #215

@jkbpvsc jkbpvsc closed this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants