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

WIP: unlendable deposits #907

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open

WIP: unlendable deposits #907

wants to merge 24 commits into from

Conversation

ckamm
Copy link
Contributor

@ckamm ckamm commented Mar 6, 2024

TODO:

  • changes to max swap/order/perp etc functions to account for disableLending

- for sanity, the liquidator likely must have lendable positions too
- instruction for creating and closing an unlendable position
- heaps of tests, rs client changes, ts client changes :/

Done:
- when dealing with the vault, always keep unlendable_deposits in the
  vault (unless withdrawing a no-lending position)
- no-lending positions can't work as settle token positions for perps
@github-actions github-actions bot added the program On-chain program changes label Mar 6, 2024
@ckamm ckamm changed the title wip: unlendable deposits? wip: unlendable deposits Mar 14, 2024
@github-actions github-actions bot added the client TS client changes label Mar 14, 2024
programs/mango-v4/src/instructions/flash_loan.rs Outdated Show resolved Hide resolved
@@ -331,6 +332,14 @@ pub fn serum3_place_order(
)?
};

// Verify that the no-lending amount on the vault remains. If the acting account
// itself had a no-lending position, the unlendable_deposits has already been reduced.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a new constraint that needs to be factored into max-obv1-size

// itself had a no-lending position, the unlendable_deposits has already been reduced.
require_gte!(
change.vault_balance,
bank.unlendable_deposits,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a constraint that needs to appear in max-swap?

programs/mango-v4/src/instructions/token_liq_with_token.rs Outdated Show resolved Hide resolved
programs/mango-v4/src/logs.rs Outdated Show resolved Hide resolved
programs/mango-v4/src/state/bank.rs Outdated Show resolved Hide resolved
programs/mango-v4/src/state/mango_account_components.rs Outdated Show resolved Hide resolved
ctx.accounts
.vault
.amount
.saturating_sub(bank.unlendable_deposits),
Copy link
Contributor

Choose a reason for hiding this comment

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

ah this is scary, how can we avoid using vault amounts just as is in future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed more changes to the ts side where it was using vaults

@ckamm
Copy link
Contributor Author

ckamm commented Mar 18, 2024

Should flash loaners be allowed to borrow unlendable deposits?

@ckamm ckamm changed the title wip: unlendable deposits unlendable deposits Mar 19, 2024
@microwavedcola1
Copy link
Contributor

Should flash loaners be allowed to borrow unlendable deposits?

technically yes, but we should just be conservative imo, or?

if position.allow_lending() {
assert!(position.unlendable_deposits == 0);
let opening_indexed_position = position.indexed_position;
let result = self.deposit_internal(position, native_amount, allow_dusting, now_ts)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename the deposit_internal method to make it explicit that it's only for "lendable position"

if position.allow_lending() {
assert!(position.unlendable_deposits == 0);
let opening_indexed_position = position.indexed_position;
let res = self.withdraw_internal(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, would rename withdraw_internal to a more explicit withdraw_indexed_pos_internal or withdraw_lendable_pos_internal

MangoError::UnlendableTokenPositionCannotBeNegative
);
position.unlendable_deposits -= withdraw_amount_u64;
self.unlendable_deposits -= withdraw_amount_u64;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should/could we also add a require_gte on the bank unlendable deposit vs withdrawn amount ?

@microwavedcola1 microwavedcola1 changed the title unlendable deposits WIP: unlendable deposits Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client TS client changes program On-chain program changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants