How Spectrum provides best rate deposit to Liquid Pylon Vault

One feature that come together with Liquid Pylon Vault is that we also provide best rate deposit to the vault using only UST.

When deposit, app shows how much to swap at Terraswap and how much to deposit via Pylon Gateway

Most of the time, we can get bPsiDP-24m from Terraswap at a discount rate, however, if we swap too many tokens in one transaction, the price of bPsiDP-24m might go above $1.

To ensure that you will always get the best rate for their deposit, we need best rate deposit mechanism for this vault.

Solution overview is simple:

Calculate swap and direct deposit amounts to ensure best rate deposit (Illustration)

Here are the implementation details (Warning: math ahead!):

In Terraswap, we cannot swap directly from UST to bPsiDP-24m. We need to swap in 2 steps:

For Psi-UST pool: finding UST for a Psi amount

Terraswap swap rate is using this formula

From (1), this is the formula for swapping UST to Psi

From (2), we can shuffle variable to find UST amount

From (3), we can simplify to

For bPsiDP-Psi pool: finding bPsiDP for a Psi amount

This step is easy, from (1), we can get to this formula

And from (5), we can simplify to

Mix 2 pools together

Given that UST amount equal to bPsiDP amount, from (4) and (6), we can come to this formula

Let’s replace Psi amount with X

Now let’s move everything to one side

And simplify to

From here, we can apply quadratic formula

After apply, it will transform into

And simplify into

Now we can find optimal Psi amount. After we get X, use equation (4), we can find optimal UST amount

Here is pseudo code to find optimal UST amount


With best rate deposit to Liquid Pylon Vault, you can simply deposit UST to the vault and we will make sure that you will get the best rate without a hassle of going too many different apps or comparing different exchange rates.

Learn more about Liquid Pylon Vault or explore Spectrum Protocol at



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store