diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index 971afb726..a0e31b48a 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -25,7 +25,7 @@ func (suite *KeeperTestSuite) TestABCIEndBlockDepositClaim() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) @@ -93,7 +93,7 @@ func (suite *KeeperTestSuite) TestOracleUpdate() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) @@ -209,7 +209,7 @@ func (suite *KeeperTestSuite) TestAttestationAfterOracleUpdate() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), msgBondedOracle) @@ -407,7 +407,7 @@ func (suite *KeeperTestSuite) TestOracleDelete() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) @@ -474,7 +474,7 @@ func (suite *KeeperTestSuite) TestOracleSetSlash() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) @@ -532,7 +532,7 @@ func (suite *KeeperTestSuite) TestSlashOracle() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) diff --git a/x/crosschain/keeper/attestation_handler.go b/x/crosschain/keeper/attestation_handler.go index c16da5abc..dbf95a55b 100644 --- a/x/crosschain/keeper/attestation_handler.go +++ b/x/crosschain/keeper/attestation_handler.go @@ -62,7 +62,7 @@ func (k Keeper) AttestationHandler(ctx sdk.Context, externalClaim types.External return errorsmod.Wrap(types.ErrInvalid, "bridge token is exist") } k.Logger(ctx).Info("add bridge token claim", "symbol", claim.Symbol, "token", claim.TokenContract, "channelIbc", claim.ChannelIbc) - if claim.Symbol == fxtypes.DefaultDenom { + if claim.Symbol == types.NativeDenom { // Check if denom exists metadata, found := k.bankKeeper.GetDenomMetaData(ctx, claim.Symbol) if !found { diff --git a/x/crosschain/keeper/grpc_query_test.go b/x/crosschain/keeper/grpc_query_test.go index 2242a6f24..c10ef5147 100644 --- a/x/crosschain/keeper/grpc_query_test.go +++ b/x/crosschain/keeper/grpc_query_test.go @@ -24,7 +24,6 @@ import ( "github.com/functionx/fx-core/v6/app" "github.com/functionx/fx-core/v6/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v6/types" arbitrumtypes "github.com/functionx/fx-core/v6/x/arbitrum/types" avalanchetypes "github.com/functionx/fx-core/v6/x/avalanche/types" bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" @@ -67,8 +66,8 @@ func (suite *CrossChainGrpcTestSuite) SetupTest() { types.RegisterQueryServer(queryHelper, suite.app.CrosschainKeeper) suite.queryClient = types.NewQueryClient(queryHelper) - suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) - suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(types.NewDelegateAmount(sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(sdk.NewCoin(types.NativeDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) suite.msgServer = keeper.NewMsgServerImpl(suite.Keeper()) } diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index 3bf57c1cc..9ee0fb744 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -11,7 +11,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/tendermint/tendermint/libs/log" - fxtypes "github.com/functionx/fx-core/v6/types" "github.com/functionx/fx-core/v6/x/crosschain/types" ) @@ -162,7 +161,7 @@ func (k Keeper) UnbondedOracleFromProposal(ctx sdk.Context, oracle types.Oracle) if err != nil { return err } - msgUndelegate := stakingtypes.NewMsgUndelegate(delegateAddr, valAddr, sdk.NewCoin(fxtypes.DefaultDenom, getOracleDelegateToken)) + msgUndelegate := stakingtypes.NewMsgUndelegate(delegateAddr, valAddr, types.NewDelegateAmount(getOracleDelegateToken)) if _, err = k.stakingMsgServer.Undelegate(sdk.WrapSDKContext(ctx), msgUndelegate); err != nil { return err } diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index 760b2aaf3..f7a0d7476 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -110,8 +110,8 @@ func (suite *KeeperTestSuite) SetupTest() { ProposerAddress: valSet.Proposer.Address.Bytes(), }) - suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) - suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(types.NewDelegateAmount(sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(sdk.NewCoin(types.NativeDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) suite.externalPris = helpers.CreateMultiECDSA(valNumber) suite.valAddrs = make([]sdk.ValAddress, valNumber) diff --git a/x/crosschain/keeper/msg_server.go b/x/crosschain/keeper/msg_server.go index 1c5c91a8a..3488bba65 100644 --- a/x/crosschain/keeper/msg_server.go +++ b/x/crosschain/keeper/msg_server.go @@ -122,12 +122,12 @@ func (s MsgServer) AddDelegate(c context.Context, msg *types.MsgAddDelegate) (*t return nil, errorsmod.Wrapf(types.ErrInvalid, "delegate denom got %s, expected %s", msg.Amount.Denom, threshold.Denom) } - slashAmount := sdk.NewCoin(fxtypes.DefaultDenom, oracle.GetSlashAmount(s.GetSlashFraction(ctx))) + slashAmount := types.NewDelegateAmount(oracle.GetSlashAmount(s.GetSlashFraction(ctx))) if slashAmount.IsPositive() && msg.Amount.Amount.LT(slashAmount.Amount) { return nil, errorsmod.Wrap(types.ErrInvalid, "not sufficient slash amount") } - delegateCoin := sdk.NewCoin(fxtypes.DefaultDenom, msg.Amount.Amount.Sub(slashAmount.Amount)) + delegateCoin := types.NewDelegateAmount(msg.Amount.Amount.Sub(slashAmount.Amount)) oracle.DelegateAmount = oracle.DelegateAmount.Add(delegateCoin.Amount) if oracle.DelegateAmount.Sub(threshold.Amount).IsNegative() { @@ -203,7 +203,7 @@ func (s MsgServer) ReDelegate(c context.Context, msg *types.MsgReDelegate) (*typ if err != nil { return nil, err } - msgBeginRedelegate := stakingtypes.NewMsgBeginRedelegate(delegateAddr, valSrcAddress, valDstAddress, sdk.NewCoin(fxtypes.DefaultDenom, delegateToken)) + msgBeginRedelegate := stakingtypes.NewMsgBeginRedelegate(delegateAddr, valSrcAddress, valDstAddress, types.NewDelegateAmount(delegateToken)) if _, err = s.stakingMsgServer.BeginRedelegate(c, msgBeginRedelegate); err != nil { return nil, err } @@ -302,9 +302,9 @@ func (s MsgServer) UnbondedOracle(c context.Context, msg *types.MsgUnbondedOracl return nil, errorsmod.Wrap(types.ErrInvalid, "exist unbonding delegation") } balances := s.bankKeeper.GetAllBalances(ctx, delegateAddr) - slashAmount := sdk.NewCoin(fxtypes.DefaultDenom, oracle.GetSlashAmount(s.GetSlashFraction(ctx))) + slashAmount := types.NewDelegateAmount(oracle.GetSlashAmount(s.GetSlashFraction(ctx))) if slashAmount.IsPositive() { - if balances.AmountOf(fxtypes.DefaultDenom).LT(slashAmount.Amount) { + if balances.AmountOf(slashAmount.Denom).LT(slashAmount.Amount) { return nil, errorsmod.Wrap(types.ErrInvalid, "not sufficient slash amount") } if err = s.bankKeeper.SendCoinsFromAccountToModule(ctx, delegateAddr, s.moduleName, sdk.NewCoins(slashAmount)); err != nil { diff --git a/x/crosschain/keeper/msg_server_test.go b/x/crosschain/keeper/msg_server_test.go index 37ea9af1b..50a28fc5b 100644 --- a/x/crosschain/keeper/msg_server_test.go +++ b/x/crosschain/keeper/msg_server_test.go @@ -19,7 +19,6 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/functionx/fx-core/v6/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v6/types" "github.com/functionx/fx-core/v6/x/crosschain/types" ethtypes "github.com/functionx/fx-core/v6/x/eth/types" trontypes "github.com/functionx/fx-core/v6/x/tron/types" @@ -108,11 +107,8 @@ func (suite *KeeperTestSuite) TestMsgBondedOracle() { BridgerAddress: suite.bridgerAddrs[oracleIndex].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[oracleIndex].PublicKey), ValidatorAddress: suite.valAddrs[oracleIndex].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: sdkmath.NewInt((tmrand.Int63n(3) + 1) * 10_000).MulRaw(1e18), - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(3) + 1) * 10_000).MulRaw(1e18)), + ChainName: suite.chainName, } testCase.preRun(msg) @@ -286,11 +282,8 @@ func (suite *KeeperTestSuite) TestMsgAddDelegate() { BridgerAddress: suite.bridgerAddrs[oracleIndex].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[oracleIndex].PublicKey), ValidatorAddress: suite.valAddrs[oracleIndex].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: initDelegateAmount, - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(initDelegateAmount), + ChainName: suite.chainName, }) require.NoError(t, err) @@ -300,8 +293,8 @@ func (suite *KeeperTestSuite) TestMsgAddDelegate() { msg := &types.MsgAddDelegate{ ChainName: suite.chainName, OracleAddress: suite.oracleAddrs[oracleIndex].String(), - Amount: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt( - tmrand.Int63n(maxDelegateAmount.QuoRaw(1e18).Int64())+1, + Amount: types.NewDelegateAmount(sdkmath.NewInt( + tmrand.Int63n(maxDelegateAmount.QuoRaw(1e18).Int64()) + 1, ). MulRaw(1e18). Sub(sdkmath.NewInt(1))), @@ -355,11 +348,8 @@ func (suite *KeeperTestSuite) TestMsgEditBridger() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: delegateAmount, - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(delegateAmount), + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), bondedMsg) suite.NoError(err) @@ -436,11 +426,8 @@ func (suite *KeeperTestSuite) TestMsgSetOracleSetConfirm() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) require.NoError(suite.T(), err) @@ -562,11 +549,8 @@ func (suite *KeeperTestSuite) TestClaimWithOracleOnline() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) require.NoError(suite.T(), err) @@ -763,11 +747,8 @@ func (suite *KeeperTestSuite) TestClaimMsgGasConsumed() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), msg) require.NoError(suite.T(), err) @@ -788,11 +769,8 @@ func (suite *KeeperTestSuite) TestClaimTest() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) require.NoError(suite.T(), err) @@ -912,11 +890,8 @@ func (suite *KeeperTestSuite) TestRequestBatchBaseFee() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: sdk.Coin{ - Denom: fxtypes.DefaultDenom, - Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), - }, - ChainName: suite.chainName, + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), + ChainName: suite.chainName, } if len(suite.valAddrs) > i { normalMsg.ValidatorAddress = suite.valAddrs[i].String() diff --git a/x/crosschain/keeper/params_test.go b/x/crosschain/keeper/params_test.go index bb032b0cf..a8cfd9e78 100644 --- a/x/crosschain/keeper/params_test.go +++ b/x/crosschain/keeper/params_test.go @@ -4,7 +4,6 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v6/types" "github.com/functionx/fx-core/v6/x/crosschain/types" ) @@ -26,7 +25,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -44,7 +43,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -62,7 +61,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -80,7 +79,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -116,7 +115,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 1, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -134,7 +133,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDec(2), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -152,7 +151,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDec(2), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, diff --git a/x/crosschain/keeper/pool.go b/x/crosschain/keeper/pool.go index bc2b04cd7..7a71a87e4 100644 --- a/x/crosschain/keeper/pool.go +++ b/x/crosschain/keeper/pool.go @@ -122,7 +122,7 @@ func (k Keeper) RemoveFromOutgoingPoolAndRefund(ctx sdk.Context, txId uint64, se totalToRefund.Amount = totalToRefund.Amount.Add(tx.Fee.Amount) totalToRefundCoins := sdk.NewCoins(totalToRefund) - if bridgeToken.Denom == fxtypes.DefaultDenom { + if bridgeToken.Denom == types.NativeDenom { if err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, k.moduleName, sender, totalToRefundCoins); err != nil { return sdk.Coin{}, err } @@ -175,7 +175,7 @@ func (k Keeper) AddUnbatchedTxBridgeFee(ctx sdk.Context, txId uint64, sender sdk // If the coin is a gravity voucher, burn the coins. If not, check if there is a deployed ERC20 contract representing it. // If there is, lock the coins. - if addBridgeFee.Denom == fxtypes.DefaultDenom { + if addBridgeFee.Denom == types.NativeDenom { // lock coins in module if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, k.moduleName, sdk.NewCoins(addBridgeFee)); err != nil { return err diff --git a/x/crosschain/keeper/pool_test.go b/x/crosschain/keeper/pool_test.go index 9591194f0..ea6c40380 100644 --- a/x/crosschain/keeper/pool_test.go +++ b/x/crosschain/keeper/pool_test.go @@ -8,7 +8,7 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/functionx/fx-core/v6/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v6/types" + "github.com/functionx/fx-core/v6/x/crosschain/types" ethtypes "github.com/functionx/fx-core/v6/x/eth/types" ) @@ -46,7 +46,7 @@ func (suite *KeeperTestSuite) TestKeeper_Outgoing() { func (suite *KeeperTestSuite) TestKeeper_Outgoing2() { sender := helpers.GenerateAddress().Bytes() bridgeToken := helpers.GenerateAddress().Hex() - denom := fxtypes.DefaultDenom + denom := types.NativeDenom supply := suite.app.BankKeeper.GetSupply(suite.ctx, denom) sendAmount := sdk.NewCoin(denom, sdkmath.NewInt(int64(tmrand.Uint32()*2))) diff --git a/x/crosschain/types/msg_validator_test.go b/x/crosschain/types/msg_validator_test.go index 935bcd2f8..a2a02deac 100644 --- a/x/crosschain/types/msg_validator_test.go +++ b/x/crosschain/types/msg_validator_test.go @@ -16,7 +16,6 @@ import ( _ "github.com/functionx/fx-core/v6/app" "github.com/functionx/fx-core/v6/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v6/types" avalanchetypes "github.com/functionx/fx-core/v6/x/avalanche/types" bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" "github.com/functionx/fx-core/v6/x/crosschain/types" @@ -163,7 +162,7 @@ func TestMsgBondedOracle_ValidateBasic(t *testing.T) { OracleAddress: normalOracleAddress, BridgerAddress: normalBridgeAddress, ExternalAddress: normalExternalAddress, - DelegateAmount: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1)), + DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(1)), }, expectPass: true, err: nil, @@ -225,7 +224,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: "", - Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(1)}, + Amount: types.NewDelegateAmount(sdkmath.NewInt(1)), }, expectPass: false, err: errortypes.ErrInvalidAddress, @@ -236,7 +235,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: errPrefixAddress, - Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(1)}, + Amount: types.NewDelegateAmount(sdkmath.NewInt(1)), }, expectPass: false, err: errortypes.ErrInvalidAddress, @@ -247,18 +246,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: normalOracleAddress, - Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(0)}, - }, - expectPass: false, - err: errortypes.ErrInvalidRequest, - errReason: "invalid amount: invalid request", - }, - { - testName: "err - negative delegate amount", - msg: &types.MsgAddDelegate{ - ChainName: moduleName, - OracleAddress: normalOracleAddress, - Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(-1)}, + Amount: types.NewDelegateAmount(sdkmath.NewInt(0)), }, expectPass: false, err: errortypes.ErrInvalidRequest, @@ -269,7 +257,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: normalOracleAddress, - Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(1)}, + Amount: types.NewDelegateAmount(sdkmath.NewInt(1)), }, expectPass: true, err: nil, @@ -1298,7 +1286,7 @@ func TestMsgIncreaseBridgeFee_ValidateBasic(t *testing.T) { ChainName: moduleName, Sender: normalFxAddress, TransactionId: 1, - AddBridgeFee: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1)), + AddBridgeFee: sdk.NewCoin(tmrand.Str(2), sdkmath.NewInt(1)), }, expectPass: true, }, diff --git a/x/crosschain/types/params.go b/x/crosschain/types/params.go index 3f54bce1e..20a690970 100644 --- a/x/crosschain/types/params.go +++ b/x/crosschain/types/params.go @@ -20,6 +20,11 @@ const ( MaxKeepEventSize = 100 ) +var ( + OracleDelegateDenom = fxtypes.DefaultDenom + NativeDenom = fxtypes.DefaultDenom +) + var ( // AttestationVotesPowerThreshold threshold of votes power to succeed AttestationVotesPowerThreshold = sdkmath.NewInt(66) @@ -70,7 +75,7 @@ func DefaultParams() Params { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: DefaultOracleDelegateThreshold, Oracles: nil, } @@ -199,7 +204,7 @@ func validateOracleDelegateThreshold(i interface{}) error { if !c.IsValid() || !c.IsPositive() { return fmt.Errorf("invalid delegate threshold") } - if c.Denom != fxtypes.DefaultDenom { + if c.Denom != OracleDelegateDenom { return fmt.Errorf("oracle delegate denom must FX") } return nil diff --git a/x/crosschain/types/types.go b/x/crosschain/types/types.go index 1e9cffe25..b0fec1c64 100644 --- a/x/crosschain/types/types.go +++ b/x/crosschain/types/types.go @@ -15,6 +15,10 @@ import ( fxtypes "github.com/functionx/fx-core/v6/types" ) +func NewDelegateAmount(amount sdkmath.Int) sdk.Coin { + return sdk.NewCoin(OracleDelegateDenom, amount) +} + // --- ERC20Token --- // func NewERC20Token(amount sdkmath.Int, contract string) ERC20Token {