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

Gradual Dutch Auction Module #1

Open
Oighty opened this issue Dec 12, 2023 · 2 comments
Open

Gradual Dutch Auction Module #1

Oighty opened this issue Dec 12, 2023 · 2 comments

Comments

@Oighty
Copy link
Contributor

Oighty commented Dec 12, 2023

Implement a standard Continuous Gradual Dutch Auction with options for Linear and Exponential Price Decay. The concept is based on this article by Paradigm, which covers the Exponential case.

An initial version (where the equations are not updated to these versions) is implemented in src/modules/auctions/GDA.sol.

Auction Pricing Math

Exponential GDA

price in quote tokens for single (infinitesimal) auction at a time t:

$$ q(t) = k e^{- \lambda t} $$

priceFor: number of quote tokens required to purchase $P$ payout tokens

$$ Q(P) = \frac{k (e^{\frac{\lambda P}{r}} - 1)}{\lambda e^{\lambda T}} $$

We cannot add a minimum price directly into the equation in the exponential case because we run into issues with a special function case. However, we can truncate the equation with a minimum price.

$$ Q = max(Q(P), k_{min} P) $$

payoutFor: number of payout tokens to receive for providing $Q$ quote tokens
We derive this by inverting the priceFor equation.

$$ P(Q) = \frac{r}{\lambda} ln \left(\frac{Q \lambda e^{\lambda T}}{k} + 1 \right) $$

We again take a minimum to truncate the equation to enforce a minimum value.

$$ P = min(P(Q), \frac{Q}{k_{min}}) $$

where:

  • $k$ is the starting (equilibrium) price of the auction
  • $k_{min}$ is the minimum price that the auction will reach
  • $\lambda$ is the decay speed constant. This needs to be set with context for the minimum price to avoid sharp bends in the curve as it approaches the minimum.
  • $t$ is the time since an individual auction started.
  • $T$ is amount of time passed since the oldest available auction started.
  • $r$ is the emission speed of the auction in payout tokens per second. It can calculated by the capacity of the auction in payout tokens divided by the duration of the auction in seconds.

Linear GDA

price in quote tokens for single (infinitesimal) auction at a time t:

$$ q(t) = (k - k_{min}) (1 - \lambda t) + k_{min} $$

In the linear case, we can introduce a minimum term into the individual auction equation.

priceFor: number of quote tokens required to purchase $P$ payout tokens

$$ Q(P) = \frac{\lambda (k - k_{min})}{2} \left(\frac{P^2}{r^2} - \frac{2TP}{r} \right) + \frac{k P}{r} $$

payoutFor: number of payout tokens to receive for providing $Q$ quote tokens
We derive this by inverting the priceFor equation.

$$ P(Q) = \frac{2r \left(\sqrt{2 \lambda (k - k_{min}) Q + (k - \lambda T (k - k_{min}))^2} - (k - \lambda T (k - k_{min})) \right)}{\sqrt{2 \lambda (k - k_{min})}} $$

where:

  • $k$ is the starting (equilibrium) price of the auction
  • $k_{min}$ is the minimum price that the auction will reach
  • $\lambda$ is the decay speed constant. This needs to be set with context for the minimum price to avoid sharp bends in the curve as it approaches the minimum.
  • $t$ is the time since an individual auction started.
  • $T$ is amount of time passed since the oldest available auction started.
  • $r$ is the emission speed of the auction in payout tokens per second. It can calculated by the capacity of the auction in payout tokens divided by the duration of the auction in seconds.
@Oighty
Copy link
Contributor Author

Oighty commented Dec 15, 2023

Implementation Considerations

In the previous auction system, a complicated price scaling system was used to cover a broad range of token prices and decimal values while avoiding under/overflows of the math. This was required due to the multiplication of two variables to calculate a price in the original SDA algorithm. This is no longer required. Instead, I believe it makes the most sense to have quote token quantities and auction prices stored in quote token decimals (i.e. quote scale). Base/payout token quantities can be represented in base token decimals (i.e. base scale).

The auction price equations detailed above require various math operations not available in standard Solidity. Additionally, there are some negative values used in the equations so it is not strictly unsigned math. Therefore, a FixedPoint Math library is required. The most robust that I have seen is PRBMath. For this case, we will need the SD59x18 variable type and associated operations, which the stored value as a signed fixed point number with 18 decimal places. Our input and output values will not be in this format since they are token quantities. Therefore, care should be taken to understand the various conversions between token scale and the fixed point math scale.

@Oighty
Copy link
Contributor Author

Oighty commented Apr 30, 2024

After further review and discussion with tex, plan to only implement the exponential decay GDA and include a minimum price term in the equation. The updated math can be found here: https://oighty.eth.limo/gda-w-min-price/

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

Successfully merging a pull request may close this issue.

1 participant