Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bep3 evm native conversion logic #1848

Merged
merged 8 commits into from Mar 25, 2024

Conversation

DracoLi
Copy link
Contributor

@DracoLi DracoLi commented Mar 15, 2024

Description

Replaces #1834

Checklist

  • Changelog has been updated as necessary.
  • Keeper unit tests incoming

@DracoLi DracoLi requested a review from galxy25 March 15, 2024 20:24
Copy link
Member

@rhuairahrighairidh rhuairahrighairidh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@DracoLi DracoLi marked this pull request as ready for review March 20, 2024 16:08
Copy link
Member

@nddeluca nddeluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good test cases covering dust, too small of balance, and insuffient balances on both the sdk and erc20 sides.

Let's just add some defensive testing to ensure all four bep3 assets are covered. In addition to using a map for denom lookup, removing unused code, and making extracted helpers private (or adding unit tests for them).

Looks great otherwise. Refactoring implementation is optional -- just added my thoughts there on readability & complexity.

x/evmutil/keeper/conversion_evm_native_bep3.go Outdated Show resolved Hide resolved
x/evmutil/keeper/conversion_evm_native_bep3.go Outdated Show resolved Hide resolved
x/evmutil/keeper/conversion_evm_native_bep3.go Outdated Show resolved Hide resolved
x/evmutil/keeper/conversion_evm_native_bep3.go Outdated Show resolved Hide resolved
x/evmutil/keeper/conversion_evm_native.go Outdated Show resolved Hide resolved
@DracoLi DracoLi requested a review from nddeluca March 21, 2024 20:35
@DracoLi DracoLi force-pushed the dl/evm-native-conversion-bep3 branch from 8ef7925 to a401485 Compare March 22, 2024 17:05
)

var (
bep3Denoms = map[string]bool{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, normally I'd say use a map[string]struct{}, but with 4 items the benefited clarify and simpler logic in isBep3Asset is nice 👍

x/evmutil/keeper/conversion_evm_native_bep3.go Outdated Show resolved Hide resolved
return quotient
}

// bep3ERC20AmountToCoinMintAndERC20LockAmount converts 18 decimals erc20 bep3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appreciate the doc comments 👍

}

func (suite *Bep3ConversionTestSuite) TestConvertCoinToERC20_Bep3() {
for _, denom := range bep3Denoms {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually makes the tests quite a bit easier to read -- easy to see that all denoms are tested and much more resistant to refactorings that could drop a denom, accidentally rename one, break the check some other unique way, etc

amountToLock := amount.BigInt()
amountToMint := amount.BigInt()

if isBep3Asset(pair.Denom) {
Copy link
Member

@nddeluca nddeluca Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean now, and this is a nice approach showing there is are two paths in the logic: One for bep3 assets, and one for not. Also, makes it clear that the amounts are only modified in the bep3 case, but also keeps the dirty details down a level in a function call.

@DracoLi DracoLi merged commit 3afb656 into master Mar 25, 2024
10 checks passed
@DracoLi DracoLi deleted the dl/evm-native-conversion-bep3 branch March 25, 2024 17:43
mergify bot pushed a commit that referenced this pull request Mar 25, 2024
* Implement bep3 evm native conversion logic

* Update changelog

* Fix indentation

* Add bep3 conversion keeper tests

* make DefaultBEP3ConversionDenoms private

* refactor bep3 conversion

* update bep3 tests to cover all bep3 assets

* minor refactor

(cherry picked from commit 3afb656)
DracoLi added a commit that referenced this pull request Mar 25, 2024
* Implement bep3 evm native conversion logic

* Update changelog

* Fix indentation

* Add bep3 conversion keeper tests

* make DefaultBEP3ConversionDenoms private

* refactor bep3 conversion

* update bep3 tests to cover all bep3 assets

* minor refactor

(cherry picked from commit 3afb656)

Co-authored-by: Draco <draco@dracoli.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants