Skip to content

[Contract 11] Replace unchecked bToken addition with checked math#201

Open
sochima2 wants to merge 4 commits into
DXmakers:mainfrom
sochima2:main
Open

[Contract 11] Replace unchecked bToken addition with checked math#201
sochima2 wants to merge 4 commits into
DXmakers:mainfrom
sochima2:main

Conversation

@sochima2
Copy link
Copy Markdown

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).

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract 11] Replace unchecked bToken addition with checked math

1 participant