-
Notifications
You must be signed in to change notification settings - Fork 201
/
msg_server_update_trade_route.go
73 lines (61 loc) · 2.16 KB
/
msg_server_update_trade_route.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
package keeper
import (
"context"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/Stride-Labs/stride/v18/x/stakeibc/types"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Gov tx to update the trade config of a trade route
//
// Example proposal:
//
// {
// "title": "Update a the trade config for host chain X",
// "metadata": "Update a the trade config for host chain X",
// "summary": "Update a the trade config for host chain X",
// "messages":[
// {
// "@type": "/stride.stakeibc.MsgUpdateTradeRoute",
// "authority": "stride10d07y265gmmuvt4z0w9aw880jnsr700jefnezl",
//
// "pool_id": 1,
// "max_allowed_swap_loss_rate": "0.05",
// "min_swap_amount": "10000000",
// "max_swap_amount": "1000000000"
// }
// ],
// "deposit": "2000000000ustrd"
// }
//
// >>> strided tx gov submit-proposal {proposal_file.json} --from wallet
func (ms msgServer) UpdateTradeRoute(goCtx context.Context, msg *types.MsgUpdateTradeRoute) (*types.MsgUpdateTradeRouteResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if ms.authority != msg.Authority {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, msg.Authority)
}
route, found := ms.Keeper.GetTradeRoute(ctx, msg.RewardDenom, msg.HostDenom)
if !found {
return nil, errorsmod.Wrapf(types.ErrTradeRouteNotFound,
"no trade route for rewardDenom %s and hostDenom %s", msg.RewardDenom, msg.HostDenom)
}
maxAllowedSwapLossRate := msg.MaxAllowedSwapLossRate
if maxAllowedSwapLossRate == "" {
maxAllowedSwapLossRate = DefaultMaxAllowedSwapLossRate
}
maxSwapAmount := msg.MaxSwapAmount
if maxSwapAmount.IsZero() {
maxSwapAmount = DefaultMaxSwapAmount
}
updatedConfig := types.TradeConfig{
PoolId: msg.PoolId,
SwapPrice: sdk.ZeroDec(),
PriceUpdateTimestamp: 0,
MaxAllowedSwapLossRate: sdk.MustNewDecFromStr(maxAllowedSwapLossRate),
MinSwapAmount: msg.MinSwapAmount,
MaxSwapAmount: maxSwapAmount,
}
route.TradeConfig = updatedConfig
ms.Keeper.SetTradeRoute(ctx, route)
return &types.MsgUpdateTradeRouteResponse{}, nil
}