8000 chore(vesting-precompile): scale balanceChange entry amt by GAtom22 · Pull Request #2928 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(vesting-precompile): scale balanceChange entry amt #2928

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

Merged
merged 11 commits into from
Oct 10, 2024
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (ante) [#2907](https://github.com/evmos/evmos/pull/2907) Add support for custom base denom decimals in the ante for EVM txs.
- (rpc) [#2908](https://github.com/evmos/evmos/pull/2908) Refactor JSON-RPC gas prices to support denom with different precision.
- (app) [#2914](https://github.com/evmos/evmos/pull/2914) Refactor App configurator to abstract `Decimals` type and use validation.
- (precompiles) [#2926](https://github.com/evmos/evmos/pull/2926) Staking: Add amount scaling on `balanceChange` entry to support different evm denom precision.
- (precompiles) [#2928](https://github.com/evmos/evmos/pull/2928) Vesting: Add amount scaling on `balanceChange` entry to support different EVM denom precision.
- (precompiles) [#2926](https://github.com/evmos/evmos/pull/2926) Staking: Add amount scaling on `balanceChange` entry to support different EVM denom precision.

### Bug Fixes

Expand Down
22 changes: 14 additions & 8 deletions precompiles/vesting/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ func (p *Precompile) FundVestingAccount(
vestingCoins = lockedUpCoins
}

// NOTE: This ensures that the changes in the bank keeper are correctly mirrored to the EVM stateDB.
amt := vestingCoins.AmountOf(evmtypes.GetEVMCoinDenom()).BigInt()
p.SetBalanceChangeEntries(
cmn.NewBalanceChangeEntry(funderAddr, amt, cmn.Sub),
cmn.NewBalanceChangeEntry(vestingAddr, amt, cmn.Add),
)
evmDenomAmt := vestingCoins.AmountOf(evmtypes.GetEVMCoinDenom())
if evmDenomAmt.IsPositive() {
// NOTE: This ensures that the changes in the bank keeper are correctly mirrored to the EVM stateDB.
// Need to scale the amount to 18 decimals for the EVM balance change entry
amt := evmtypes.ConvertAmountTo18DecimalsBigInt(evmDenomAmt.BigInt())
p.SetBalanceChangeEntries(
cmn.NewBalanceChangeEntry(funderAddr, amt, cmn.Sub),
cmn.NewBalanceChangeEntry(vestingAddr, amt, cmn.Add),
)
}
}

if err = p.EmitFundVestingAccountEvent(ctx, stateDB, msg, funderAddr, vestingAddr, lockupPeriods, vestingPeriods); err != nil {
Expand Down Expand Up @@ -188,10 +192,12 @@ func (p *Precompile) Clawback(
return nil, err
}

if isContractCaller {
evmDenomAmt := response.Coins.AmountOf(evmtypes.GetEVMCoinDenom())
if isContractCaller && evmDenomAmt.IsPositive() {
// NOTE: This ensures that the changes in the bank keeper are correctly mirrored to the EVM stateDB when calling
// the precompile from another contract.
clawbackAmt := response.Coins.AmountOf(evmtypes.GetEVMCoinDenom()).BigInt()
// Need to scale the amount to 18 decimals for the EVM balance change entry
clawbackAmt := evmtypes.ConvertAmountTo18DecimalsBigInt(evmDenomAmt.BigInt())
p.SetBalanceChangeEntries(
cmn.NewBalanceChangeEntry(accountAddr, clawbackAmt, cmn.Sub),
cmn.NewBalanceChangeEntry(destAddr, clawbackAmt, cmn.Add),
Expand Down
3 changes: 0 additions & 3 deletions precompiles/vesting/vesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
vestingkeeper "github.com/evmos/evmos/v20/x/vesting/keeper"
)

// PrecompileAddress of the vesting EVM extension in hex format.
const PrecompileAddress = "0x0000000000000000000000000000000000000803"

var _ vm.PrecompiledContract = &Precompile{}

// Embed abi json file to the executable binary. Needed when importing as dependency.
Expand Down
Loading
0