This commit is contained in:
0xsatoshi 2024-05-04 14:26:54 +08:00 committed by 0g-wh
parent 19a202669a
commit 3da66a87e6
16 changed files with 151 additions and 182 deletions

View File

@ -10,7 +10,6 @@ import (
sdkmath "cosmossdk.io/math" sdkmath "cosmossdk.io/math"
"github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
abci "github.com/cometbft/cometbft/abci/types" abci "github.com/cometbft/cometbft/abci/types"
tmbytes "github.com/cometbft/cometbft/libs/bytes" tmbytes "github.com/cometbft/cometbft/libs/bytes"
@ -63,11 +62,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
bank.MsgSend{ bank.MsgSend{
FromAddress: fromAddr, FromAddress: fromAddr,
ToAddress: toAddr, ToAddress: toAddr,
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
}, },
Fee: auth.StdFee{ Fee: auth.StdFee{
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(5e4))),
Gas: 1e6, Gas: 1e6,
}, },
Memo: "test memo", Memo: "test memo",

View File

@ -16,7 +16,6 @@ import (
"github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante" "github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
) )
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant { func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
@ -59,7 +58,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend( banktypes.NewMsgSend(
testAddresses[0], testAddresses[0],
testAddresses[1], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
), ),
}, },
checkTx: false, checkTx: false,
@ -129,7 +128,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
[]sdk.Msg{banktypes.NewMsgSend( []sdk.Msg{banktypes.NewMsgSend(
testAddresses[0], testAddresses[0],
testAddresses[3], testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
)}), )}),
}, },
checkTx: false, checkTx: false,
@ -162,7 +161,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend( banktypes.NewMsgSend(
testAddresses[0], testAddresses[0],
testAddresses[3], testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
), ),
&evmtypes.MsgEthereumTx{}, &evmtypes.MsgEthereumTx{},
}, },

View File

@ -34,7 +34,6 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper" evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil" evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types" evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
@ -157,7 +156,7 @@ func (suite *EIP712TestSuite) SetupTest() {
// Genesis states // Genesis states
evmGs := evmtypes.NewGenesisState( evmGs := evmtypes.NewGenesisState(
evmtypes.NewParams( evmtypes.NewParams(
chaincfg.BaseDenom, // evmDenom "neuron", // evmDenom
false, // allowedUnprotectedTxs false, // allowedUnprotectedTxs
true, // enableCreate true, // enableCreate
true, // enableCall true, // enableCall
@ -223,10 +222,10 @@ func (suite *EIP712TestSuite) SetupTest() {
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState), pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
} }
// funds our test accounts with some a0gi // funds our test accounts with some ua0gi
coinsGenState := app.NewFundedGenStateWithSameCoins( coinsGenState := app.NewFundedGenStateWithSameCoins(
tApp.AppCodec(), tApp.AppCodec(),
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e3)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1e9)),
[]sdk.AccAddress{suite.testAddr, suite.testAddr2}, []sdk.AccAddress{suite.testAddr, suite.testAddr2},
) )
@ -376,7 +375,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
suite.tApp.FundModuleAccount( suite.tApp.FundModuleAccount(
suite.ctx, suite.ctx,
evmutiltypes.ModuleName, evmutiltypes.ModuleName,
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))), sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))),
) )
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18)) contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
@ -476,7 +475,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
errMsg: "insufficient funds", errMsg: "insufficient funds",
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder { updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
bk := suite.tApp.GetBankKeeper() bk := suite.tApp.GetBankKeeper()
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.DisplayDenom) gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ua0gi")
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins)) suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
return txBuilder return txBuilder
}, },
@ -488,7 +487,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
failCheckTx: true, failCheckTx: true,
errMsg: "invalid chain-id", errMsg: "invalid chain-id",
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder { updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20))) gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
return suite.createTestEIP712CosmosTxBuilder( return suite.createTestEIP712CosmosTxBuilder(
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs, suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
) )
@ -501,7 +500,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
failCheckTx: true, failCheckTx: true,
errMsg: "invalid pubkey", errMsg: "invalid pubkey",
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder { updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20))) gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
return suite.createTestEIP712CosmosTxBuilder( return suite.createTestEIP712CosmosTxBuilder(
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs, suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
) )
@ -529,7 +528,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
msgs = tc.updateMsgs(msgs) msgs = tc.updateMsgs(msgs)
} }
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20))) gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
txBuilder := suite.createTestEIP712CosmosTxBuilder( txBuilder := suite.createTestEIP712CosmosTxBuilder(
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs, suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
) )
@ -603,7 +602,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
} }
// deliver deposit msg // deliver deposit msg
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20))) gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
txBuilder := suite.createTestEIP712CosmosTxBuilder( txBuilder := suite.createTestEIP712CosmosTxBuilder(
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs, suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
) )

View File

@ -13,7 +13,6 @@ import (
"github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante" "github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
) )
func mustParseDecCoins(value string) sdk.DecCoins { func mustParseDecCoins(value string) sdk.DecCoins {
@ -31,7 +30,7 @@ func TestEvmMinGasFilter(t *testing.T) {
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()}) ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{ tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
EvmDenom: chaincfg.BaseDenom, EvmDenom: "neuron",
}) })
testCases := []struct { testCases := []struct {
@ -45,29 +44,29 @@ func TestEvmMinGasFilter(t *testing.T) {
mustParseDecCoins(""), mustParseDecCoins(""),
}, },
{ {
"zero a0gi gas price", "zero ua0gi gas price",
mustParseDecCoins("0a0gi"), mustParseDecCoins("0ua0gi"),
mustParseDecCoins("0a0gi"), mustParseDecCoins("0ua0gi"),
}, },
{ {
"non-zero a0gi gas price", "non-zero ua0gi gas price",
mustParseDecCoins("0.001a0gi"), mustParseDecCoins("0.001ua0gi"),
mustParseDecCoins("0.001a0gi"), mustParseDecCoins("0.001ua0gi"),
}, },
{ {
"zero a0gi gas price, min neuron price", "zero ua0gi gas price, min neuron price",
mustParseDecCoins("0a0gi;100000neuron"), mustParseDecCoins("0ua0gi;100000neuron"),
mustParseDecCoins("0a0gi"), // neuron is removed mustParseDecCoins("0ua0gi"), // neuron is removed
}, },
{ {
"zero a0gi gas price, min neuron price, other token", "zero ua0gi gas price, min neuron price, other token",
mustParseDecCoins("0a0gi;100000neuron;0.001other"), mustParseDecCoins("0ua0gi;100000neuron;0.001other"),
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed mustParseDecCoins("0ua0gi;0.001other"), // neuron is removed
}, },
{ {
"non-zero a0gi gas price, min neuron price", "non-zero ua0gi gas price, min neuron price",
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"), mustParseDecCoins("0.25ua0gi;100000neuron;0.001other"),
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed mustParseDecCoins("0.25ua0gi;0.001other"), // neuron is removed
}, },
} }

View File

@ -14,7 +14,6 @@ import (
"github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante" "github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
) )
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) { func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
@ -34,7 +33,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
"MsgCreateVestingAccount", "MsgCreateVestingAccount",
vesting.NewMsgCreateVestingAccount( vesting.NewMsgCreateVestingAccount(
testAddresses[0], testAddresses[1], testAddresses[0], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
false, false,
), ),
@ -45,7 +44,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
"MsgCreateVestingAccount", "MsgCreateVestingAccount",
vesting.NewMsgCreatePermanentLockedAccount( vesting.NewMsgCreatePermanentLockedAccount(
testAddresses[0], testAddresses[1], testAddresses[0], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
), ),
true, true,
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported", "MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
@ -64,7 +63,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
"other messages not affected", "other messages not affected",
banktypes.NewMsgSend( banktypes.NewMsgSend(
testAddresses[0], testAddresses[1], testAddresses[0], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)), sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
), ),
false, false,
"", "",

View File

@ -288,9 +288,6 @@ type App struct {
} }
func init() { func init() {
// 1stake = 1 ukava = 1_000_000_000_000 akava = 1_000_000_000_000 neuron
conversionMultiplier := sdkmath.NewIntFromUint64(1_000_000_000_000)
sdk.DefaultPowerReduction = sdk.DefaultPowerReduction.Mul(conversionMultiplier)
} }
// NewApp returns a reference to an initialized App. // NewApp returns a reference to an initialized App.

View File

@ -153,7 +153,7 @@ func GenesisStateWithSingleValidator(
balances := []banktypes.Balance{ balances := []banktypes.Balance{
{ {
Address: acc.GetAddress().String(), Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))), Coins: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(100000000000000))),
}, },
} }
@ -216,7 +216,7 @@ func genesisStateWithValSet(
} }
// set validators and delegations // set validators and delegations
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState) currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom currentStakingGenesis.Params.BondDenom = "ua0gi"
stakingGenesis := stakingtypes.NewGenesisState( stakingGenesis := stakingtypes.NewGenesisState(
currentStakingGenesis.Params, currentStakingGenesis.Params,
@ -236,13 +236,13 @@ func genesisStateWithValSet(
for range delegations { for range delegations {
// add delegated tokens to total supply // add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)) totalSupply = totalSupply.Add(sdk.NewCoin("ua0gi", bondAmt))
} }
// add bonded amount to bonded pool module account // add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{ balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(), Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)}, Coins: sdk.Coins{sdk.NewCoin("ua0gi", bondAmt)},
}) })
bankGenesis := banktypes.NewGenesisState( bankGenesis := banktypes.NewGenesisState(

View File

@ -1,27 +0,0 @@
package chaincfg
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// DisplayDenom defines the denomination displayed to users in client applications.
DisplayDenom = "a0gi"
// BaseDenom defines to the default denomination used in 0g-chain
BaseDenom = "neuron"
BaseDenomUnit = 18
ConversionMultiplier = 1e18
)
// RegisterDenoms registers the base and display denominations to the SDK.
func RegisterDenoms() {
if err := sdk.RegisterDenom(DisplayDenom, sdk.OneDec()); err != nil {
panic(err)
}
if err := sdk.RegisterDenom(BaseDenom, sdk.NewDecWithPrec(1, BaseDenomUnit)); err != nil {
panic(err)
}
}

View File

@ -11,7 +11,6 @@ import (
func main() { func main() {
chaincfg.SetSDKConfig().Seal() chaincfg.SetSDKConfig().Seal()
chaincfg.RegisterDenoms()
rootCmd := NewRootCmd() rootCmd := NewRootCmd()

View File

@ -81,7 +81,7 @@ func NewRootCmd() *cobra.Command {
return err return err
} }
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.BaseDenom) customAppTemplate, customAppConfig := servercfg.AppConfig("ua0gi")
return server.InterceptConfigsPreRunHandler( return server.InterceptConfigsPreRunHandler(
cmd, cmd,

View File

@ -5,7 +5,6 @@ import (
"time" "time"
sdkmath "cosmossdk.io/math" sdkmath "cosmossdk.io/math"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@ -42,7 +41,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
} }
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) { func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))) balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{ periods := vestingtypes.Periods{
@ -65,7 +64,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
} }
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) { func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))) balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{ periods := vestingtypes.Periods{
@ -98,7 +97,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
} }
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) { func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))) balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{ periods := vestingtypes.Periods{
@ -126,25 +125,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
} }
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) { func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(4))) balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(4e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{ periods := vestingtypes.Periods{
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // -15 days - vested Length: 15 * 24 * 60 * 60, // -15 days - vested
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +15 days - vesting Length: 15 * 24 * 60 * 60, // +15 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +30 days - vesting Length: 15 * 24 * 60 * 60, // +30 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
} }
@ -160,36 +159,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
expectedPeriods := []vestingtypes.Period{ expectedPeriods := []vestingtypes.Period{
{ {
Length: 15 * 24 * 60 * 60, // 15 days Length: 15 * 24 * 60 * 60, // 15 days
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
{ {
Length: 15 * 24 * 60 * 60, // 15 days Length: 15 * 24 * 60 * 60, // 15 days
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
} }
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2))), vacc.OriginalVesting, "expected original vesting to be updated") assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated") assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period") assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated") assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
} }
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) { func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3))) balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{ periods := vestingtypes.Periods{
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // -15 days - vested Length: 15 * 24 * 60 * 60, // -15 days - vested
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +15 days - vesting Length: 15 * 24 * 60 * 60, // +15 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
} }
@ -199,35 +198,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour) newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
ResetPeriodicVestingAccount(vacc, newVestingStartTime) ResetPeriodicVestingAccount(vacc, newVestingStartTime)
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2))), vacc.DelegatedFree, "expected delegated free to be updated") assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), vacc.DelegatedVesting, "expected delegated vesting to be updated") assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
} }
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) { func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3))) balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{ periods := vestingtypes.Periods{
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // -15 days - vested Length: 15 * 24 * 60 * 60, // -15 days - vested
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
vestingtypes.Period{ vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +15 days - vesting Length: 15 * 24 * 60 * 60, // +15 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
}, },
} }
vacc := createVestingAccount(balance, vestingStartTime, periods) vacc := createVestingAccount(balance, vestingStartTime, periods)
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1)))) vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))))
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour) newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
ResetPeriodicVestingAccount(vacc, newVestingStartTime) ResetPeriodicVestingAccount(vacc, newVestingStartTime)
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified") assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified") assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
} }

View File

@ -9,12 +9,19 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
evmtypes "github.com/evmos/ethermint/x/evm/types" evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/evmutil/types" "github.com/0glabs/0g-chain/x/evmutil/types"
) )
// ConversionMultiplier is the conversion multiplier between neuron and a0gi const (
var ConversionMultiplier = sdkmath.NewInt(chaincfg.ConversionMultiplier) // EvmDenom is the gas denom used by the evm
EvmDenom = "neuron"
// CosmosDenom is the gas denom used by the 0g-chain app
CosmosDenom = "ua0gi"
)
// ConversionMultiplier is the conversion multiplier between neuron and ua0gi
var ConversionMultiplier = sdkmath.NewInt(1_000_000_000_000)
var _ evmtypes.BankKeeper = EvmBankKeeper{} var _ evmtypes.BankKeeper = EvmBankKeeper{}
@ -25,30 +32,30 @@ var _ evmtypes.BankKeeper = EvmBankKeeper{}
// This keeper uses both the a0gi coin and a separate neuron balance to manage the // This keeper uses both the a0gi coin and a separate neuron balance to manage the
// extra percision needed by the evm. // extra percision needed by the evm.
type EvmBankKeeper struct { type EvmBankKeeper struct {
baseKeeper Keeper neuronKeeper Keeper
bk types.BankKeeper bk types.BankKeeper
ak types.AccountKeeper ak types.AccountKeeper
} }
func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper { func NewEvmBankKeeper(neuronKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
return EvmBankKeeper{ return EvmBankKeeper{
baseKeeper: baseKeeper, neuronKeeper: neuronKeeper,
bk: bk, bk: bk,
ak: ak, ak: ak,
} }
} }
// GetBalance returns the total **spendable** balance of neuron for a given account by address. // GetBalance returns the total **spendable** balance of neuron for a given account by address.
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin { func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
if denom != chaincfg.BaseDenom { if denom != EvmDenom {
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom)) panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom))
} }
spendableCoins := k.bk.SpendableCoins(ctx, addr) spendableCoins := k.bk.SpendableCoins(ctx, addr)
a0gi := spendableCoins.AmountOf(chaincfg.DisplayDenom) ua0gi := spendableCoins.AmountOf(CosmosDenom)
neuron := k.baseKeeper.GetBalance(ctx, addr) neuron := k.neuronKeeper.GetBalance(ctx, addr)
total := a0gi.Mul(ConversionMultiplier).Add(neuron) total := ua0gi.Mul(ConversionMultiplier).Add(neuron)
return sdk.NewCoin(chaincfg.BaseDenom, total) return sdk.NewCoin(EvmDenom, total)
} }
// SendCoins transfers neuron coins from a AccAddress to an AccAddress. // SendCoins transfers neuron coins from a AccAddress to an AccAddress.
@ -63,115 +70,115 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
// It will panic if the module account does not exist. An error is returned if the recipient // It will panic if the module account does not exist. An error is returned if the recipient
// address is black-listed or if sending the tokens fails. // address is black-listed or if sending the tokens fails.
func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error { func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
a0gi, neuron, err := SplitNeuronCoins(amt) ua0gi, neuron, err := SplitNeuronCoins(amt)
if err != nil { if err != nil {
return err return err
} }
if a0gi.Amount.IsPositive() { if ua0gi.Amount.IsPositive() {
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(a0gi)); err != nil { if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ua0gi)); err != nil {
return err return err
} }
} }
senderAddr := k.GetModuleAddress(senderModule) senderAddr := k.GetModuleAddress(senderModule)
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil { if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
return err return err
} }
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil { if err := k.neuronKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil {
return err return err
} }
return k.ConvertNeuronToA0gi(ctx, recipientAddr) return k.ConvertNeuronToUa0gi(ctx, recipientAddr)
} }
// SendCoinsFromAccountToModule transfers neuron coins from an AccAddress to a ModuleAccount. // SendCoinsFromAccountToModule transfers neuron coins from an AccAddress to a ModuleAccount.
// It will panic if the module account does not exist. // It will panic if the module account does not exist.
func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error { func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
a0gi, neuronNeeded, err := SplitNeuronCoins(amt) ua0gi, neuronNeeded, err := SplitNeuronCoins(amt)
if err != nil { if err != nil {
return err return err
} }
if a0gi.IsPositive() { if ua0gi.IsPositive() {
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(a0gi)); err != nil { if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ua0gi)); err != nil {
return err return err
} }
} }
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil { if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
return err return err
} }
recipientAddr := k.GetModuleAddress(recipientModule) recipientAddr := k.GetModuleAddress(recipientModule)
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil { if err := k.neuronKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil {
return err return err
} }
return k.ConvertNeuronToA0gi(ctx, recipientAddr) return k.ConvertNeuronToUa0gi(ctx, recipientAddr)
} }
// MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron coins. // MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron coins.
// It will panic if the module account does not exist or is unauthorized. // It will panic if the module account does not exist or is unauthorized.
func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
a0gi, neuron, err := SplitNeuronCoins(amt) ua0gi, neuron, err := SplitNeuronCoins(amt)
if err != nil { if err != nil {
return err return err
} }
if a0gi.IsPositive() { if ua0gi.IsPositive() {
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil { if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ua0gi)); err != nil {
return err return err
} }
} }
recipientAddr := k.GetModuleAddress(moduleName) recipientAddr := k.GetModuleAddress(moduleName)
if err := k.baseKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil { if err := k.neuronKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil {
return err return err
} }
return k.ConvertNeuronToA0gi(ctx, recipientAddr) return k.ConvertNeuronToUa0gi(ctx, recipientAddr)
} }
// BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron coins. // BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron coins.
// It will panic if the module account does not exist or is unauthorized. // It will panic if the module account does not exist or is unauthorized.
func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
a0gi, neuron, err := SplitNeuronCoins(amt) ua0gi, neuron, err := SplitNeuronCoins(amt)
if err != nil { if err != nil {
return err return err
} }
if a0gi.IsPositive() { if ua0gi.IsPositive() {
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil { if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ua0gi)); err != nil {
return err return err
} }
} }
moduleAddr := k.GetModuleAddress(moduleName) moduleAddr := k.GetModuleAddress(moduleName)
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil { if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil {
return err return err
} }
return k.baseKeeper.RemoveBalance(ctx, moduleAddr, neuron) return k.neuronKeeper.RemoveBalance(ctx, moduleAddr, neuron)
} }
// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if // ConvertOneUa0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if
// its neuron balance is smaller than the neuronNeeded amount. // its neuron balance is smaller than the neuronNeeded amount.
func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error { func (k EvmBankKeeper) ConvertOneUa0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
neuronBal := k.baseKeeper.GetBalance(ctx, addr) neuronBal := k.neuronKeeper.GetBalance(ctx, addr)
if neuronBal.GTE(neuronNeeded) { if neuronBal.GTE(neuronNeeded) {
return nil return nil
} }
a0giToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.OneInt())) ua0giToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt()))
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, a0giToStore); err != nil { if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ua0giToStore); err != nil {
return err return err
} }
// add 1a0gi equivalent of neuron to addr // add 1a0gi equivalent of neuron to addr
neuronToReceive := ConversionMultiplier neuronToReceive := ConversionMultiplier
if err := k.baseKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil { if err := k.neuronKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
return err return err
} }
@ -179,28 +186,28 @@ func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.
} }
// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress. // ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress.
func (k EvmBankKeeper) ConvertNeuronToA0gi(ctx sdk.Context, addr sdk.AccAddress) error { func (k EvmBankKeeper) ConvertNeuronToUa0gi(ctx sdk.Context, addr sdk.AccAddress) error {
totalNeuron := k.baseKeeper.GetBalance(ctx, addr) totalNeuron := k.neuronKeeper.GetBalance(ctx, addr)
a0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalNeuron))) ua0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalNeuron)))
if err != nil { if err != nil {
return err return err
} }
// do nothing if account does not have enough neuron for a single a0gi // do nothing if account does not have enough neuron for a single a0gi
a0giToReceive := a0gi.Amount ua0giToReceive := ua0gi.Amount
if !a0giToReceive.IsPositive() { if !ua0giToReceive.IsPositive() {
return nil return nil
} }
// remove neuron used for converting to a0gi // remove neuron used for converting to ua0gi
neuronToBurn := a0giToReceive.Mul(ConversionMultiplier) neuronToBurn := ua0giToReceive.Mul(ConversionMultiplier)
finalBal := totalNeuron.Sub(neuronToBurn) finalBal := totalNeuron.Sub(neuronToBurn)
if err := k.baseKeeper.SetBalance(ctx, addr, finalBal); err != nil { if err := k.neuronKeeper.SetBalance(ctx, addr, finalBal); err != nil {
return err return err
} }
fromAddr := k.GetModuleAddress(types.ModuleName) fromAddr := k.GetModuleAddress(types.ModuleName)
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(a0gi)); err != nil { if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(ua0gi)); err != nil {
return err return err
} }
@ -219,14 +226,14 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
// An error will be returned if the coins are not valid or if the coins are not the neuron denom. // An error will be returned if the coins are not valid or if the coins are not the neuron denom.
func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) { func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
neuron := sdk.ZeroInt() neuron := sdk.ZeroInt()
a0gi := sdk.NewCoin(chaincfg.DisplayDenom, sdk.ZeroInt()) ua0gi := sdk.NewCoin(CosmosDenom, sdk.ZeroInt())
if len(coins) == 0 { if len(coins) == 0 {
return a0gi, neuron, nil return ua0gi, neuron, nil
} }
if err := ValidateEvmCoins(coins); err != nil { if err := ValidateEvmCoins(coins); err != nil {
return a0gi, neuron, err return ua0gi, neuron, err
} }
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate. // note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
@ -235,15 +242,15 @@ func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
if remainingBalance.IsPositive() { if remainingBalance.IsPositive() {
neuron = remainingBalance neuron = remainingBalance
} }
a0giAmount := coin.Amount.Quo(ConversionMultiplier) ua0giAmount := coin.Amount.Quo(ConversionMultiplier)
if a0giAmount.IsPositive() { if ua0giAmount.IsPositive() {
a0gi = sdk.NewCoin(chaincfg.DisplayDenom, a0giAmount) ua0gi = sdk.NewCoin(CosmosDenom, ua0giAmount)
} }
return a0gi, neuron, nil return ua0gi, neuron, nil
} }
// ValidateEvmCoins validates the coins from evm is valid and is the chaincfg.BaseDenom (neuron). // ValidateEvmCoins validates the coins from evm is valid and is the EvmDenom (neuron).
func ValidateEvmCoins(coins sdk.Coins) error { func ValidateEvmCoins(coins sdk.Coins) error {
if len(coins) == 0 { if len(coins) == 0 {
return nil return nil
@ -255,8 +262,8 @@ func ValidateEvmCoins(coins sdk.Coins) error {
} }
// validate that coin denom is neuron // validate that coin denom is neuron
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom { if len(coins) != 1 || coins[0].Denom != EvmDenom {
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom) errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom)
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg) return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
} }

View File

@ -6,7 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/evmutil/types" "github.com/0glabs/0g-chain/x/evmutil/types"
) )
@ -51,7 +50,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
}) })
bankAddr := authtypes.NewModuleAddress(types.ModuleName) bankAddr := authtypes.NewModuleAddress(types.ModuleName)
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.DisplayDenom).Amount.Mul(ConversionMultiplier) bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier)
broken = totalMinorBalances.GT(bankBalance) broken = totalMinorBalances.GT(bankBalance)

View File

@ -50,7 +50,7 @@ func (suite *invariantTestSuite) SetupValidState() {
suite.FundModuleAccountWithZgChain( suite.FundModuleAccountWithZgChain(
types.ModuleName, types.ModuleName,
sdk.NewCoins( sdk.NewCoins(
sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier sdk.NewCoin("ua0gi", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
), ),
) )

View File

@ -82,14 +82,14 @@ func (suite *Suite) SetupTest() {
suite.Addrs = addrs suite.Addrs = addrs
evmGenesis := evmtypes.DefaultGenesisState() evmGenesis := evmtypes.DefaultGenesisState()
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom evmGenesis.Params.EvmDenom = chaincfg.EvmDenom
feemarketGenesis := feemarkettypes.DefaultGenesisState() feemarketGenesis := feemarkettypes.DefaultGenesisState()
feemarketGenesis.Params.EnableHeight = 1 feemarketGenesis.Params.EnableHeight = 1
feemarketGenesis.Params.NoBaseFee = false feemarketGenesis.Params.NoBaseFee = false
cdc := suite.App.AppCodec() cdc := suite.App.AppCodec()
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1000_000_000_000)) coins := sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1000_000_000_000))
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{ authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
sdk.AccAddress(suite.Key1.PubKey().Address()), sdk.AccAddress(suite.Key1.PubKey().Address()),
sdk.AccAddress(suite.Key2.PubKey().Address()), sdk.AccAddress(suite.Key2.PubKey().Address()),
@ -186,12 +186,12 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
} }
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) { func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
a0gi := coins.AmountOf(chaincfg.DisplayDenom) ua0gi := coins.AmountOf("ua0gi")
if a0gi.IsPositive() { if ua0gi.IsPositive() {
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi))) err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi)))
suite.Require().NoError(err) suite.Require().NoError(err)
} }
neuron := coins.AmountOf(chaincfg.BaseDenom) neuron := coins.AmountOf("neuron")
if neuron.IsPositive() { if neuron.IsPositive() {
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron) err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
suite.Require().NoError(err) suite.Require().NoError(err)
@ -199,12 +199,12 @@ func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins)
} }
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) { func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
a0gi := coins.AmountOf(chaincfg.DisplayDenom) ua0gi := coins.AmountOf("ua0gi")
if a0gi.IsPositive() { if ua0gi.IsPositive() {
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi))) err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi)))
suite.Require().NoError(err) suite.Require().NoError(err)
} }
neuron := coins.AmountOf(chaincfg.BaseDenom) neuron := coins.AmountOf("neuron")
if neuron.IsPositive() { if neuron.IsPositive() {
addr := suite.AccountKeeper.GetModuleAddress(moduleName) addr := suite.AccountKeeper.GetModuleAddress(moduleName)
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron) err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
@ -218,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
suite.App.FundModuleAccount( suite.App.FundModuleAccount(
suite.Ctx, suite.Ctx,
types.ModuleName, types.ModuleName,
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))), sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))),
) )
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18)) contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
@ -319,7 +319,7 @@ func (suite *Suite) SendTx(
// Mint the max gas to the FeeCollector to ensure balance in case of refund // Mint the max gas to the FeeCollector to ensure balance in case of refund
suite.MintFeeCollector(sdk.NewCoins( suite.MintFeeCollector(sdk.NewCoins(
sdk.NewCoin( sdk.NewCoin(
chaincfg.DisplayDenom, "ua0gi",
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)), sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
))) )))

View File

@ -63,7 +63,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
}, },
"supplies": [ "supplies": [
{ {
"current_supply": { "denom": "neuron", "amount": "100000000000000" }, "current_supply": { "denom": "ua0gi", "amount": "100" },
"time_elapsed": "3600000000000" "time_elapsed": "3600000000000"
}, },
{ {
@ -96,7 +96,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
}, },
"supplies": [ "supplies": [
{ {
"current_supply": { "denom": "neuron", "amount": "100000000000000" }, "current_supply": { "denom": "ua0gi", "amount": "100" },
"time_elapsed": "3600s" "time_elapsed": "3600s"
}, },
{ {
@ -115,7 +115,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
Assets: v015issuance.Assets{ Assets: v015issuance.Assets{
{ {
Owner: s.addresses[0], Owner: s.addresses[0],
Denom: "neuron", Denom: "ua0gi",
BlockedAddresses: s.addresses[1:2], BlockedAddresses: s.addresses[1:2],
Paused: true, Paused: true,
Blockable: true, Blockable: true,
@ -131,7 +131,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
Assets: []v016issuance.Asset{ Assets: []v016issuance.Asset{
{ {
Owner: s.addresses[0].String(), Owner: s.addresses[0].String(),
Denom: "neuron", Denom: "ua0gi",
BlockedAddresses: []string{s.addresses[1].String()}, BlockedAddresses: []string{s.addresses[1].String()},
Paused: true, Paused: true,
Blockable: true, Blockable: true,
@ -150,7 +150,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
func (s *migrateTestSuite) TestMigrate_Supplies() { func (s *migrateTestSuite) TestMigrate_Supplies() {
s.v15genstate.Supplies = v015issuance.AssetSupplies{ s.v15genstate.Supplies = v015issuance.AssetSupplies{
{ {
CurrentSupply: sdk.NewCoin("neuron", sdkmath.NewInt(100000000000000)), CurrentSupply: sdk.NewCoin("ua0gi", sdkmath.NewInt(100)),
TimeElapsed: time.Duration(1 * time.Hour), TimeElapsed: time.Duration(1 * time.Hour),
}, },
{ {
@ -160,7 +160,7 @@ func (s *migrateTestSuite) TestMigrate_Supplies() {
} }
expected := []v016issuance.AssetSupply{ expected := []v016issuance.AssetSupply{
{ {
CurrentSupply: sdk.NewCoin("neuron", sdkmath.NewInt(100000000000000)), CurrentSupply: sdk.NewCoin("ua0gi", sdkmath.NewInt(100)),
TimeElapsed: time.Duration(1 * time.Hour), TimeElapsed: time.Duration(1 * time.Hour),
}, },
{ {