feat: Add validation for non-zero total deposit in add_liquidity #199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
Added a validation check to ensure the total deposit amount is greater than zero in the
add_liquidityfunction withinswaptemplatebase.vy. This enhancement prevents invalid deposit transactions where all amounts are zero, improving the contract's robustness against potential errors or misuse.How I did it
total_amountvariable to calculate the sum of all_amounts[i]before processing the deposit.assert total_amount > 0check at the beginning of the function to reject transactions with no effective deposit.How to verify it
add_liquidityfunction incontracts/pool-templates/swaptemplatebase.vy(lines wheretotal_amountis calculated and checked).[0, 0, 0]— it should revert with the message "Total deposit amount must be greater than zero".[100, 0, 0]or[50, 50, 0]) — it should proceed as expected without reverting.Related issue
N/A (if no specific issue is linked; if there is one, add e.g., "Fixes #123")
Additional notes
This change was made to enhance the security and usability of the template contract, making it more resilient for new pool deployments. No functional changes to the core algorithm were introduced.