Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion contracts/pool-templates/base/SwapTemplateBase.vy
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ def calc_token_amount(_amounts: uint256[N_COINS], _is_deposit: bool) -> uint256:
diff = D0 - D1
return diff * token_amount / D0


# Adds liquidity to the pool by depositing specified amounts of tokens.
# Calculates the new invariant (D) after deposit, applies fees based on the difference
# between ideal and actual balances, and mints LP tokens proportional to the change in D.
# Includes non-reentrant protection to prevent reentrancy attacks and ensures minimum
# mint amount to protect against slippage.
@external
@nonreentrant('lock')
def add_liquidity(_amounts: uint256[N_COINS], _min_mint_amount: uint256) -> uint256:
Expand All @@ -302,6 +306,12 @@ def add_liquidity(_amounts: uint256[N_COINS], _min_mint_amount: uint256) -> uint
"""
assert not self.is_killed # dev: is killed

# Ensure at least one amount is non-zero to prevent invalid deposits
total_amount: uint256 = 0
for i in range(N_COINS):
total_amount += _amounts[i]
assert total_amount > 0, "Total deposit amount must be greater than zero"

amp: uint256 = self._A()
old_balances: uint256[N_COINS] = self.balances

Expand Down