Skip to content

Instantly share code, notes, and snippets.

@JohnPlummer
Created March 6, 2024 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnPlummer/255df66376767be4111a5733ba399c1f to your computer and use it in GitHub Desktop.
Save JohnPlummer/255df66376767be4111a5733ba399c1f to your computer and use it in GitHub Desktop.
# Constants for the initial state of the liquidity pool
x_initial = 1000 # Initial amount of Token A
y_initial = 1000 # Initial amount of Token B
k = x_initial * y_initial # Constant product k
delta_x = 100 # Amount of Token A being swapped
# New amount of Token A in the pool
x_final = x_initial + delta_x
# Calculate the new amount of Token B using the constant product formula
y_final = k / x_final
# Amount of Token B received
delta_y = y_initial - y_final
delta_y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment