UXDProtocol / uxd-program

Implementation of a program that manages on chain accounts to mint and redeem Redeemables tokens (UXD), hedged by a delta neutral position on underlying DEXes.
https://uxd.fi/
Other
21 stars 5 forks source link

[Alloyx] Use alloyx as emergency liquidity if identity_depository is emptied #319

Closed crypto-vincent closed 9 months ago

crypto-vincent commented 9 months ago

The TLDR of the change is to make the rebalancing flows computed by:

let deposit_redeemable_amount = std::cmp::min(
    identity_depository_overflow_value,
    alloyx_vault_depository_underflow_value,
);
let withdraw_redeemable_amount = std::cmp::max(
    identity_depository_underflow_value,
    alloyx_vault_depository_overflow_value,
);

This is the case so that:

acamill commented 9 months ago

Ok makes sense

On Sat, 9 Dec 2023 at 11:05 AM, uxd-vincent @.***> wrote:

@.**** commented on this pull request.

In programs/uxd/src/instructions/rebalance_alloyx_vault_depository.rs https://github.com/UXDProtocol/uxd-program/pull/319#discussion_r1421231034 :

  • let identity_depository_underflow_value = identity_depository_target_redeemable_amount
  • .saturating_sub(identity_depository_redeemable_amount_under_management);
  • let alloyx_vault_depository_underflow_value = alloyx_vault_depository_target_redeemable_amount
  • .saturating_sub(alloyx_vault_depository_redeemable_amount_under_management);
  • let identity_depository_overflow_value = identity_depository_redeemable_amount_under_management
  • .saturating_sub(identity_depository_target_redeemable_amount);
  • let alloyx_vault_depository_overflow_value =
  • alloyx_vault_depository_redeemable_amount_under_management
  • .saturating_sub(alloyx_vault_depository_target_redeemable_amount);
  • let deposit_redeemable_amount = std::cmp::min(
  • identity_depository_overflow_value,
  • alloyx_vault_depository_underflow_value,
  • );
  • let withdraw_redeemable_amount = std::cmp::max(

If there is somehow a conflict, the deposited value will be used, then the withdraw value will not be used (a single rebalancing will only do a single withdraw/deposit, not both)

In all cases however, one of the two value will always be zero:

  • if the overflow value > 0, then the underflow value == 0
  • So there is always 2 values set to zero in the min/max expressions
  • So there is always one of the two deposit/withdraw value that is zero

— Reply to this email directly, view it on GitHub https://github.com/UXDProtocol/uxd-program/pull/319#discussion_r1421231034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJTOZY2BCQ3WHLFOEZ2LFO3YIPIPRAVCNFSM6AAAAABAHKQPFCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONZTGQ2TQMRSGU . You are receiving this because your review was requested.Message ID: @.***>