Description
To absolutely guarantee that our swap math doesn't result in missing funds due to rounding errors, we need invariant assertions.
Before a swap executes, we should record the pool's balance. After the swap and token transfers, we check the balance again.
The new balance must be exactly equal to or greater than the expected constant product math output.
If this invariant is violated, the contract must panic and revert the entire transaction immediately.
Requirements
Description
To absolutely guarantee that our swap math doesn't result in missing funds due to rounding errors, we need invariant assertions.
Before a swap executes, we should record the pool's balance. After the swap and token transfers, we check the balance again.
The new balance must be exactly equal to or greater than the expected constant product math output.
If this invariant is violated, the contract must panic and revert the entire transaction immediately.
Requirements
swapfunction, capturetoken_a.balance()andtoken_b.balance()before any transfers occur.Error::InvariantViolatedif it fails.