-
Notifications
You must be signed in to change notification settings - Fork 838
/
mint.go
82 lines (71 loc) · 2.7 KB
/
mint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2022 Evmos Foundation
// This file is part of the Evmos Network packages.
//
// Evmos is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Evmos packages are distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Evmos packages. If not, see https://github.com/evmos/evmos/blob/main/LICENSE
package keeper
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/evmos/evmos/v12/x/erc20/types"
)
// MintingEnabled checks that:
// - the global parameter for erc20 conversion is enabled
// - minting is enabled for the given (erc20,coin) token pair
// - recipient address is not on the blocked list
// - bank module transfers are enabled for the Cosmos coin
func (k Keeper) MintingEnabled(
ctx sdk.Context,
sender, receiver sdk.AccAddress,
token string,
) (types.TokenPair, error) {
if !k.IsERC20Enabled(ctx) {
return types.TokenPair{}, errorsmod.Wrap(
types.ErrERC20Disabled, "module is currently disabled by governance",
)
}
id := k.GetTokenPairID(ctx, token)
if len(id) == 0 {
return types.TokenPair{}, errorsmod.Wrapf(
types.ErrTokenPairNotFound, "token '%s' not registered by id", token,
)
}
pair, found := k.GetTokenPair(ctx, id)
if !found {
return types.TokenPair{}, errorsmod.Wrapf(
types.ErrTokenPairNotFound, "token '%s' not registered", token,
)
}
if !pair.Enabled {
return types.TokenPair{}, errorsmod.Wrapf(
types.ErrERC20TokenPairDisabled, "minting token '%s' is not enabled by governance", token,
)
}
if k.bankKeeper.BlockedAddr(receiver.Bytes()) {
return types.TokenPair{}, errorsmod.Wrapf(
errortypes.ErrUnauthorized, "%s is not allowed to receive transactions", receiver,
)
}
// NOTE: ignore amount as only denom is checked on IsSendEnabledCoin
coin := sdk.Coin{Denom: pair.Denom}
// check if minting to a recipient address other than the sender is enabled
// for for the given coin denom
if !sender.Equals(receiver) && !k.bankKeeper.IsSendEnabledCoin(ctx, coin) {
return types.TokenPair{}, errorsmod.Wrapf(
banktypes.ErrSendDisabled, "minting '%s' coins to an external address is currently disabled", token,
)
}
return pair, nil
}