Skip to content

Commit

Permalink
Donation method
Browse files Browse the repository at this point in the history
  • Loading branch information
michwill committed Dec 16, 2024
1 parent c2a8f09 commit a4c24cb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions contracts/main/CurveTwocryptoOptimized.vy
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,41 @@ def add_liquidity(
return d_token


@external
@nonreentrant("lock")
def donate(amounts: uint256[N_COINS]):
A_gamma: uint256[2] = self._A_gamma()
xp: uint256[N_COINS] = self.balances
assert amounts[0] + amounts[1] > 0 # dev: no coins to add
price_scale: uint256 = self.cached_price_scale

########################## TRANSFER IN <-------
for i in range(N_COINS):
if amounts[i] > 0:
# Updates self.balances here:
xp[i] += self._transfer_in(
i,
amounts[i],
msg.sender,
False, # <--------------------- Disable optimistic transfers.
)
self.balances = xp

# Calculate D for new balances
xp = [xp[0] * PRECISIONS[0], xp[1] * price_scale * PRECISIONS[1] / PRECISION]
D: uint256 = MATH.newton_D(A_gamma[0], A_gamma[1], xp, 0)

# Update D and virtual_price
self.D = D # D = D/D_old * D_old
xp = [
unsafe_div(D, N_COINS),
D * PRECISION / (N_COINS * price_scale) # <------ safediv.
] # with price_scale.
# virtual_price = virtual_price * D / D_old (as per simulator),
# but recalc here gives the same result
self.virtual_price = 10**18 * isqrt(xp[0] * xp[1]) / self.totalSupply


@external
@nonreentrant("lock")
def remove_liquidity(
Expand Down

0 comments on commit a4c24cb

Please sign in to comment.