-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Conversation
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]>
CI is unhappy about unused variables but those should be resolved during the course of review. |
There was a problem hiding this 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.
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/deposit.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/deposit.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/deposit.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/withdraw_claim.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/withdraw_request.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/withdraw_request.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/withdraw_request.rs
Outdated
Show resolved
Hide resolved
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 |
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
There was a problem hiding this 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?
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/create_fund.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/deposit.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/deposit.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/withdraw_claim.rs
Outdated
Show resolved
Hide resolved
programs/marginfi/src/instructions/marginfi_group/liquid_insurance_fund/withdraw_request.rs
Outdated
Show resolved
Hide resolved
The basic use cases that should be covered:
|
Signed-off-by: Denton X <[email protected]>
Also |
Thanks for the reviews. I'm mainly going through and deleting code and updating the shares model. TODOs:
|
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
account data Signed-off-by: Denton X <[email protected]>
shares Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
withdraws Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Signed-off-by: Denton X <[email protected]>
Closed in favor of #215 |
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.