UnUniFi / chain

GNU General Public License v3.0
35 stars 14 forks source link

IRS Query for frontend #724

Open Senna46 opened 5 months ago

Senna46 commented 5 months ago

There are several Msg that require specifying the amount requested in the IRS, which hinders UX. The following query is needed to resolve this. (not sure if this can be achieved)

Need queries that return a right estimate for the left input.

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Senna46 commented 5 months ago

Swap UT to YT

internally

  1. loan UT
  2. Mint PT & YT
  3. Swap PT => UT
  4. Payback loan

UT required (x) = YT desired - PT swapped to UT

let YT desired = y x = y - y (1 -moduleBonded/YT supply) swapRate(PT/UT) y = x * YT supply / moduleBonded / swapRate(PT/UT)

~It can be implemented if SwapRate can be calculated.~ This is quite difficult because y is used to calculate SwapRate. As an alternative, I'll use the rate for 1 Token for now.

The same method uses on chain/x/irs/keeper/grpc_query_tranche_apys.go

Senna46 commented 5 months ago

Swap YT to UT (not matured)

chain/x/irs/keeper/swap_advanced.go

// // TODO: This implementation is better if there is no Redeem time lag
// func (k Keeper) SwapYtToUt(ctx sdk.Context, sender sdk.AccAddress, pool types.TranchePool, requiredUtAmount sdk.Int, token sdk.Coin) error {

Because redeem has a time lag, this is too difficult to achieve. For now, it should be limited to maturities.

Senna46 commented 5 months ago

Redeem PT & YT to UT

PT Required = UT desired PT Supply / moduleBonded YT Required = UT desired YT Supply / moduleBonded

So,

UT desired (output) = PT Required (input) moduleBonded / PT Supply YT Required (output) = PT Required (input) YT Supply / PT Supply

The same method can be for the reverse.

Senna46 commented 5 months ago

Add Liquidity (UT & PT) to LP token

UT required = UT Pool Liquidity LP desired / Pool Total Share (Ceil) PT required = PT Pool Liquidity LP desired / Pool Total Share (Ceil)

So,

LP desired (output) = UT required (input) Pool Total Share / UT Pool Liquidity PT required (output) = UT required (input) PT Pool Liquidity / UT Pool Liquidity

The same method can be for the reverse.