-
Notifications
You must be signed in to change notification settings - Fork 47
/
msg_server_update_pool_params.go
56 lines (45 loc) · 1.66 KB
/
msg_server_update_pool_params.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
package keeper
import (
"context"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/elys-network/elys/x/amm/types"
assetprofiletypes "github.com/elys-network/elys/x/assetprofile/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)
// UpdatePoolParams updates the pool params
func (k Keeper) UpdatePoolParams(ctx sdk.Context, poolId uint64, poolParams types.PoolParams) (uint64, types.PoolParams, error) {
pool, found := k.GetPool(ctx, poolId)
if !found {
return 0, types.PoolParams{}, types.ErrPoolNotFound
}
baseCurrency, found := k.assetProfileKeeper.GetUsdcDenom(ctx)
if !found {
return 0, types.PoolParams{}, errorsmod.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", ptypes.BaseCurrency)
}
// If the fee denom is empty, set it to the base currency
if poolParams.FeeDenom == "" {
poolParams.FeeDenom = baseCurrency
}
pool.PoolParams = poolParams
err := k.SetPool(ctx, pool)
if err != nil {
return 0, types.PoolParams{}, err
}
return pool.PoolId, pool.PoolParams, nil
}
func (k msgServer) UpdatePoolParams(goCtx context.Context, msg *types.MsgUpdatePoolParams) (*types.MsgUpdatePoolParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if k.authority != msg.Authority {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}
poolId, poolParams, err := k.Keeper.UpdatePoolParams(ctx, msg.PoolId, *msg.PoolParams)
if err != nil {
return nil, err
}
return &types.MsgUpdatePoolParamsResponse{
PoolId: poolId,
PoolParams: &poolParams,
}, nil
}