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

IRS Query for frontend #724

Open
3 of 4 tasks
Senna46 opened this issue Jan 15, 2024 · 4 comments
Open
3 of 4 tasks

IRS Query for frontend #724

Senna46 opened this issue Jan 15, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@Senna46
Copy link
Contributor

Senna46 commented Jan 15, 2024

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)

  • Swap UT to YT
  • Swap YT to UT (not matured)
  • Redeem PT & YT to UT
  • Add Liquidity (UT & PT) to LP token

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 Senna46 added the enhancement New feature or request label Jan 15, 2024
@Senna46
Copy link
Contributor Author

Senna46 commented Jan 15, 2024

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
Copy link
Contributor Author

Senna46 commented Jan 15, 2024

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
Copy link
Contributor Author

Senna46 commented Jan 15, 2024

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
Copy link
Contributor Author

Senna46 commented Jan 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant