[Contract 11] Replace unchecked bToken addition with checked math#201
Open
sochima2 wants to merge 4 commits into
Open
[Contract 11] Replace unchecked bToken addition with checked math#201sochima2 wants to merge 4 commits into
sochima2 wants to merge 4 commits into
Conversation
…dition-with-checked-math Use checked math for bToken additions
|
@sochima2 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
close #158
Description
Replaced unchecked additions for user bTokens, total bTokens and legacy Blend balance with a helper fn checked_add_i128(env: &Env, lhs: i128, rhs: i128) -> i128 that uses panic_with_error!(env, Error::Overflow) on overflow. (file: contracts/src/lib.rs).
Introduced a typed contract error pub enum Error { Overflow, DeadlineExpired } and imported panic_with_error/contracterror to report failures consistently.
Added the missing remove_liquidity method to the SoroswapRouterTrait and provided a mock implementation used by withdraw tests so the withdrawal path compiles and runs in tests.
Minor formatting and test harness adjustments (use of env.register(..., ()), multiline storage calls) and added a regression test test_blend_supply_btoken_overflow_panics that seeds a b_tokens = i128::MAX position and asserts a subsequent supply panics instead of overflowing.
Testing
Ran cargo test in contracts/ and all tests passed (14 passed, 0 failed).
Ran cargo fmt --all -- --check and it passed.
Ran cargo clippy --all-targets -- -D warnings and no new warnings were introduced (clippy passed).