Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DracoLi committed Mar 25, 2024
1 parent a401485 commit c039b73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions x/evmutil/keeper/conversion_evm_native_bep3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ func isBep3Asset(denom string) bool {

// convertBep3CoinAmountToERC20Amount converts a bep3 coin amount with 8 decimals
// to the equivalent ERC20 token with 18 decimals.
func convertBep3CoinAmountToERC20Amount(amount *big.Int) *big.Int {
result := new(big.Int).Mul(amount, bep3ConversionFactor)
return result
func convertBep3CoinAmountToERC20Amount(amount *big.Int) (erc20Amount *big.Int) {
return new(big.Int).Mul(amount, bep3ConversionFactor)
}

// convertBep3ERC20AmountToCoinAmount converts a bep3 ERC20 token with 18 decimals
// to the equivalent coin amount with 8 decimals, and dropping the remainder.
func convertBep3ERC20AmountToCoinAmount(amount *big.Int) *big.Int {
quotient := new(big.Int).Div(amount, bep3ConversionFactor)
return quotient
func convertBep3ERC20AmountToCoinAmount(amount *big.Int) (coinAmount *big.Int) {
return new(big.Int).Div(amount, bep3ConversionFactor)
}

// bep3ERC20AmountToCoinMintAndERC20LockAmount converts 18 decimals erc20 bep3
// amount to the equivalent 8 decimals coin amount to mint, and the
// 18 decimals erc20 bep3 amount to lock for the converted coin amount.
func bep3ERC20AmountToCoinMintAndERC20LockAmount(amount *big.Int) (*big.Int, *big.Int, error) {
amountToMint := convertBep3ERC20AmountToCoinAmount(amount)
func bep3ERC20AmountToCoinMintAndERC20LockAmount(amount *big.Int) (
amountToMint *big.Int, amountToLock *big.Int, err error,
) {
amountToMint = convertBep3ERC20AmountToCoinAmount(amount)

// make sure we have at least 1 sdk.Coin to mint
if amountToMint.Cmp(big.NewInt(0)) == 0 {
Expand All @@ -50,6 +50,6 @@ func bep3ERC20AmountToCoinMintAndERC20LockAmount(amount *big.Int) (*big.Int, *bi
)
return nil, nil, err
}
amountToLock := convertBep3CoinAmountToERC20Amount(amountToMint)
amountToLock = convertBep3CoinAmountToERC20Amount(amountToMint)
return amountToMint, amountToLock, nil
}
4 changes: 2 additions & 2 deletions x/evmutil/keeper/conversion_evm_native_bep3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestBep3ConversionTestSuite(t *testing.T) {

func (suite *Bep3ConversionTestSuite) TestConvertCoinToERC20_Bep3() {
for _, denom := range bep3Denoms {
suite.testBep3ConvertCoinToERC20(denom)
suite.testConvertBep3CoinToERC20(denom)
}
}

Expand All @@ -42,7 +42,7 @@ func (suite *Bep3ConversionTestSuite) setEnabledConversionPairDenom(denom string
suite.Keeper.SetParams(suite.Ctx, params)
}

func (suite *Bep3ConversionTestSuite) testBep3ConvertCoinToERC20(denom string) {
func (suite *Bep3ConversionTestSuite) testConvertBep3CoinToERC20(denom string) {
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
suite.Require().NoError(err)
Expand Down

0 comments on commit c039b73

Please sign in to comment.