/
msg_server.go
520 lines (448 loc) · 21.3 KB
/
msg_server.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
package keeper
import (
"context"
"fmt"
sdktypes "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
ibcporttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v4/modules/core/24-host"
"github.com/persistenceOne/pstake-native/v2/x/lscosmos/types"
)
type msgServer struct {
Keeper
}
// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}
var _ types.MsgServer = msgServer{}
// LiquidStake defines a method for liquid staking tokens
func (m msgServer) LiquidStake(goCtx context.Context, msg *types.MsgLiquidStake) (*types.MsgLiquidStakeResponse, error) {
ctx := sdktypes.UnwrapSDKContext(goCtx)
// check if module is inactive or active
if !m.GetModuleState(ctx) {
return nil, types.ErrModuleDisabled
}
//GetParams
hostChainParams := m.GetHostChainParams(ctx)
//check for minimum deposit amount
if msg.Amount.Amount.LT(hostChainParams.MinDeposit) {
return nil, sdkerrors.Wrapf(
types.ErrMinDeposit, "expected amount more than %s, got %s", hostChainParams.MinDeposit, msg.Amount.Amount,
)
}
expectedIBCPrefix := ibctransfertypes.GetDenomPrefix(hostChainParams.TransferPort, hostChainParams.TransferChannel)
denomTraceStr, err := m.ibcTransferKeeper.DenomPathFromHash(ctx, msg.Amount.Denom)
if err != nil {
return nil, sdkerrors.Wrapf(types.ErrInvalidDenom, "got error : %s", err)
}
denomTrace := ibctransfertypes.ParseDenomTrace(denomTraceStr)
// Check if ibc path matches allowlisted path.
if expectedIBCPrefix != denomTrace.GetPrefix() {
return nil, sdkerrors.Wrapf(
types.ErrInvalidDenomPath, "expected %s, got %s", expectedIBCPrefix, denomTrace.GetPrefix(),
)
}
//Check if base denom is valid (uatom) , this can be programmed further to accommodate for liquid staked vouchers.
if denomTrace.BaseDenom != hostChainParams.BaseDenom {
return nil, sdkerrors.Wrapf(
types.ErrInvalidDenom, "expected %s, got %s", hostChainParams.BaseDenom, denomTrace.BaseDenom,
)
}
// get the delegator address from bech32 string
delegatorAddress, err := sdktypes.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "got error : %s", err)
}
// amount of stk tokens to be minted. We calculate this before depositing any amount so as to not affect minting c-value.
// We do not care about residue here because it won't be minted and bank.TotalSupply invariant should not be affected
cValue := m.GetCValue(ctx)
mintToken, _ := m.ConvertTokenToStk(ctx, sdktypes.NewDecCoinFromCoin(msg.Amount), cValue)
//send the deposit to the deposit-module account
depositAmount := sdktypes.NewCoins(msg.Amount)
err = m.SendTokensToDepositModule(ctx, depositAmount, delegatorAddress)
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrFailedDeposit, "failed to deposit tokens to module account %s, got error : %s", types.DepositModuleAccount, err,
)
}
//Mint staked representative tokens in lscosmos module account
err = m.bankKeeper.MintCoins(ctx, types.ModuleName, sdktypes.NewCoins(mintToken))
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrMintFailed, "failed to mint coins in module %s, got error %s", types.ModuleName, err,
)
}
//Calculate protocol fee
protocolFee := hostChainParams.PstakeParams.PstakeDepositFee
protocolFeeAmount := protocolFee.MulInt(mintToken.Amount)
// We do not care about residue, as to not break Total calculation invariant.
protocolCoin, _ := sdktypes.NewDecCoinFromDec(hostChainParams.MintDenom, protocolFeeAmount).TruncateDecimal()
//Send (mintedTokens - protocolTokens) to delegator address
err = m.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, delegatorAddress,
sdktypes.NewCoins(mintToken.Sub(protocolCoin)))
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrMintFailed, "failed to send coins from module %s to account %s, got error : %s",
types.ModuleName, delegatorAddress.String(), err,
)
}
//Send protocol fee to protocol pool
if protocolCoin.IsPositive() {
err = m.SendProtocolFee(ctx, sdktypes.NewCoins(protocolCoin), types.ModuleName, hostChainParams.PstakeParams.PstakeFeeAddress)
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrFailedDeposit, "failed to send protocol fee to pstake fee address %s, got error : %s",
hostChainParams.PstakeParams.PstakeFeeAddress, err,
)
}
}
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
types.EventTypeLiquidStake,
sdktypes.NewAttribute(types.AttributeDelegatorAddress, delegatorAddress.String()),
sdktypes.NewAttribute(types.AttributeAmount, mintToken.String()),
sdktypes.NewAttribute(types.AttributeAmountReceived, mintToken.Sub(protocolCoin).String()),
sdktypes.NewAttribute(types.AttributePstakeDepositFee, protocolCoin.String()),
),
sdktypes.NewEvent(
sdktypes.EventTypeMessage,
sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory),
sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.DelegatorAddress),
)},
)
return &types.MsgLiquidStakeResponse{}, nil
}
// LiquidUnstake defines a method for unstaking the liquid staked tokens
func (m msgServer) LiquidUnstake(goCtx context.Context, msg *types.MsgLiquidUnstake) (*types.MsgLiquidUnstakeResponse, error) {
ctx := sdktypes.UnwrapSDKContext(goCtx)
// check if module is inactive or active
if !m.GetModuleState(ctx) {
return nil, types.ErrModuleDisabled
}
hostChainParams := m.GetHostChainParams(ctx)
if msg.Amount.Denom != hostChainParams.MintDenom {
return nil, sdkerrors.Wrapf(types.ErrInvalidDenom, "Expected %s, got %s", hostChainParams.MintDenom, msg.Amount.Denom)
}
delegatorAddress, err := sdktypes.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
return nil, err
}
// take deposit into module acc
err = m.bankKeeper.SendCoinsFromAccountToModule(ctx, delegatorAddress, types.UndelegationModuleAccount, sdktypes.NewCoins(msg.Amount))
if err != nil {
return nil, err
}
// take pstake fees
unstakeCoin := msg.Amount
pstakeFeeAmt := hostChainParams.PstakeParams.PstakeUnstakeFee.MulInt(msg.Amount.Amount).TruncateInt()
pstakeFee := sdktypes.NewCoin(msg.Amount.Denom, pstakeFeeAmt)
if pstakeFeeAmt.IsPositive() {
err = m.SendProtocolFee(ctx, sdktypes.NewCoins(pstakeFee), types.UndelegationModuleAccount, hostChainParams.PstakeParams.PstakeFeeAddress)
if err != nil {
return nil, err
}
unstakeCoin = msg.Amount.Sub(pstakeFee)
}
// Add entry to unbonding db
epoch := m.epochKeeper.GetEpochInfo(ctx, types.UndelegationEpochIdentifier)
unbondingEpochNumber := types.CurrentUnbondingEpoch(epoch.CurrentEpoch)
m.AddDelegatorUnbondingEpochEntry(ctx, delegatorAddress, unbondingEpochNumber, unstakeCoin)
m.AddTotalUndelegationForEpoch(ctx, unbondingEpochNumber, unstakeCoin)
// check is there are delegations worth the amount to be undelegated.
// there are chances where the delegation epoch is not yet done so stkAtom are more than delegated amount
// in this case users should just redeem tokens. (as tokens should be present as part of deposit tokens)
delegationState := m.GetDelegationState(ctx)
undelegations, err := m.GetHostAccountUndelegationForEpoch(ctx, unbondingEpochNumber)
if err != nil {
return nil, err
}
totalDelegations := delegationState.TotalDelegations(hostChainParams.BaseDenom)
baseDenomUndelegations, _ := m.ConvertStkToToken(ctx, sdktypes.NewDecCoinFromCoin(undelegations.TotalUndelegationAmount), m.GetCValue(ctx))
if totalDelegations.IsLT(sdktypes.NewCoin(hostChainParams.BaseDenom, baseDenomUndelegations.Amount)) {
return nil, sdkerrors.Wrapf(types.ErrHostChainDelegationsLTUndelegations, "Delegated amount: %s is less than total undelegations for the epoch: %s", totalDelegations, undelegations.TotalUndelegationAmount)
}
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
types.EventTypeLiquidUnstake,
sdktypes.NewAttribute(types.AttributeDelegatorAddress, msg.GetDelegatorAddress()),
sdktypes.NewAttribute(types.AttributeAmountReceived, msg.Amount.String()),
sdktypes.NewAttribute(types.AttributePstakeUnstakeFee, pstakeFee.String()),
sdktypes.NewAttribute(types.AttributeUnstakeAmount, unstakeCoin.String()),
),
sdktypes.NewEvent(
sdktypes.EventTypeMessage,
sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory),
sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.GetDelegatorAddress()),
)},
)
return &types.MsgLiquidUnstakeResponse{}, nil
}
// Redeem defines a method for redeeming liquid staked tokens instantly
func (m msgServer) Redeem(goCtx context.Context, msg *types.MsgRedeem) (*types.MsgRedeemResponse, error) {
ctx := sdktypes.UnwrapSDKContext(goCtx)
// check if module is inactive or active
if !m.GetModuleState(ctx) {
return nil, types.ErrModuleDisabled
}
// take redeem address from msg address string
redeemAddress, err := sdktypes.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "got error : %s", err)
}
// get the ibc denom and host chain params
ibcDenom := m.GetIBCDenom(ctx)
hostChainParams := m.GetHostChainParams(ctx)
// check msg amount denom
if msg.Amount.Denom != hostChainParams.MintDenom {
return nil, sdkerrors.Wrapf(types.ErrInvalidDenom, "expected %s, got %s", hostChainParams.BaseDenom, msg.Amount.Denom)
}
// We do not care about residue, as to not break Total calculation invariant.
// protocolCoin is the redemption fee
protocolCoin, _ := sdktypes.NewDecCoinFromDec(
hostChainParams.MintDenom,
hostChainParams.PstakeParams.PstakeRedemptionFee.MulInt(msg.Amount.Amount),
).TruncateDecimal()
// send redeem tokens to module account from redeem account
err = m.bankKeeper.SendCoinsFromAccountToModule(ctx, redeemAddress, types.ModuleName, sdktypes.NewCoins(msg.Amount))
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrMintFailed, "failed to send coins from account %s to module %s, got error : %s",
redeemAddress.String(), types.ModuleName, err,
)
}
// send protocol fee to protocol pool
if protocolCoin.IsPositive() {
err = m.SendProtocolFee(ctx, sdktypes.NewCoins(protocolCoin), types.ModuleName, hostChainParams.PstakeParams.PstakeFeeAddress)
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrFailedDeposit, "failed to send protocol fee to pstake fee address %s, got error : %s",
hostChainParams.PstakeParams.PstakeFeeAddress, err,
)
}
}
// convert redeem amount to ibc/allow-listed-denom amount (sub protocolCoin) based on the current c-value
redeemStk := msg.Amount.Sub(protocolCoin)
redeemToken, _ := m.ConvertStkToToken(ctx, sdktypes.NewDecCoinFromCoin(redeemStk), m.GetCValue(ctx))
// get all deposit account balances
allDepositBalances := m.bankKeeper.GetAllBalances(ctx, authtypes.NewModuleAddress(types.DepositModuleAccount))
delegationBalance := sdktypes.NewCoin(ibcDenom, allDepositBalances.AmountOf(ibcDenom))
// check deposit account has sufficient funds
if redeemToken.IsGTE(delegationBalance) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "expected tokens under %s, got %s for redeem", delegationBalance.String(), redeemToken.String())
}
// send the ibc/Denom token from module to the account
err = m.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.DepositModuleAccount, redeemAddress, sdktypes.NewCoins(redeemToken))
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrMintFailed, "failed to send coins from module %s to account %s, got error : %s",
types.DepositModuleAccount, redeemAddress.String(), err,
)
}
// burn the redeemStk token
err = m.bankKeeper.BurnCoins(ctx, types.ModuleName, sdktypes.NewCoins(redeemStk))
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrBurnFailed, "failed to burn coins from module %s, got error %s", types.ModuleName, err,
)
}
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
types.EventTypeRedeem,
sdktypes.NewAttribute(types.AttributeDelegatorAddress, redeemAddress.String()),
sdktypes.NewAttribute(types.AttributeAmount, msg.Amount.String()),
sdktypes.NewAttribute(types.AttributeAmountReceived, redeemToken.String()),
sdktypes.NewAttribute(types.AttributePstakeRedeemFee, protocolCoin.String()),
),
sdktypes.NewEvent(
sdktypes.EventTypeMessage,
sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory),
sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.DelegatorAddress),
)},
)
return &types.MsgRedeemResponse{}, nil
}
// Claim defines a method for claiming unstaked mature tokens or failed unbondings
func (m msgServer) Claim(goCtx context.Context, msg *types.MsgClaim) (*types.MsgClaimResponse, error) {
ctx := sdktypes.UnwrapSDKContext(goCtx)
// check if module is inactive or active
if !m.GetModuleState(ctx) {
return nil, types.ErrModuleDisabled
}
// get AccAddress from bech32 string
delegatorAddress, err := sdktypes.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
return nil, err
}
// get all the entries corresponding to the delegator address
delegatorUnbondingEntries := m.IterateDelegatorUnbondingEpochEntry(ctx, delegatorAddress)
// loop through all the epoch and send tokens if an entry has matured.
for _, unbondingEntry := range delegatorUnbondingEntries {
unbondingEpochCValue := m.GetUnbondingEpochCValue(ctx, unbondingEntry.EpochNumber)
if unbondingEpochCValue.IsMatured {
// get c value from the UnbondingEpochCValue struct
// calculate claimable amount from un inverse c value
claimableAmount := unbondingEntry.Amount.Amount.ToDec().Quo(unbondingEpochCValue.GetUnbondingEpochCValue())
// calculate claimable coin and community coin to be sent to delegator account and community pool respectively
claimableCoin, _ := sdktypes.NewDecCoinFromDec(m.GetIBCDenom(ctx), claimableAmount).TruncateDecimal()
// send coin to delegator address from undelegation module account
err = m.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.UndelegationModuleAccount, delegatorAddress, sdktypes.NewCoins(claimableCoin))
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
types.EventTypeClaim,
sdktypes.NewAttribute(types.AttributeDelegatorAddress, delegatorAddress.String()),
sdktypes.NewAttribute(types.AttributeAmount, unbondingEntry.Amount.String()),
sdktypes.NewAttribute(types.AttributeClaimedAmount, claimableAmount.String()),
)},
)
// remove entry from unbonding epoch entry
m.RemoveDelegatorUnbondingEpochEntry(ctx, delegatorAddress, unbondingEntry.EpochNumber)
}
if unbondingEpochCValue.IsFailed {
err = m.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.UndelegationModuleAccount, delegatorAddress, sdktypes.NewCoins(unbondingEntry.Amount))
if err != nil {
return nil, err
}
// remove entry from unbonding epoch entry
m.RemoveDelegatorUnbondingEpochEntry(ctx, delegatorAddress, unbondingEntry.EpochNumber)
}
}
// emit event
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
sdktypes.EventTypeMessage,
sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory),
sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.DelegatorAddress),
)},
)
return &types.MsgClaimResponse{}, nil
}
// JumpStart defines a method for jump-starting the module through fee address account.
func (m msgServer) JumpStart(goCtx context.Context, msg *types.MsgJumpStart) (*types.MsgJumpStartResponse, error) {
ctx := sdktypes.UnwrapSDKContext(goCtx)
// check pstake fee address == from addr
hostChainParams := m.GetHostChainParams(ctx)
if msg.PstakeAddress != hostChainParams.PstakeParams.PstakeFeeAddress {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("msg.pstakeAddress should be equal to msg.PstakeParams.PstakeFeeAddress, got %s expected %s", msg.PstakeAddress, hostChainParams.PstakeParams.PstakeFeeAddress))
}
// check module disabled
if m.GetModuleState(ctx) {
return nil, types.ErrModuleAlreadyEnabled
}
// ensure if params were set before never allow the denoms to be reset/changed, so tvu can always be checked
if !hostChainParams.IsEmpty() && hostChainParams.BaseDenom != msg.BaseDenom {
return nil, types.ErrInvalidDenom
}
if types.ConvertBaseDenomToMintDenom(msg.BaseDenom) != msg.MintDenom {
return nil, types.ErrInvalidMintDenom
}
// check if there is any mints.
stkSupply := m.bankKeeper.GetSupply(ctx, msg.MintDenom)
if stkSupply.Amount.GT(sdktypes.ZeroInt()) {
return nil, sdkerrors.Wrap(types.ErrModuleAlreadyEnabled, "Module cannot be reset once via admin once it has positive delegations.")
}
// reset db, no need to release capability
m.SetDelegationState(ctx, types.DelegationState{})
m.SetHostChainRewardAddress(ctx, types.HostChainRewardAddress{})
if err := msg.HostAccounts.Validate(); err != nil {
return nil, err
}
m.SetHostAccounts(ctx, msg.HostAccounts)
// check fees limits
if err := msg.PstakeParams.Validate(); err != nil {
return nil, err
}
if msg.MinDeposit.LTE(sdktypes.ZeroInt()) {
return nil, sdkerrors.Wrap(types.ErrInvalidDeposit, "MinDeposit should be GT 0")
}
// do proposal things
if msg.TransferPort != ibctransfertypes.PortID {
return nil, sdkerrors.Wrap(ibcporttypes.ErrInvalidPort, "Only acceptable TransferPort is \"transfer\"")
}
// checks for valid and active channel
channel, found := m.channelKeeper.GetChannel(ctx, msg.TransferPort, msg.TransferChannel)
if !found {
return nil, sdkerrors.Wrap(ibcchanneltypes.ErrChannelNotFound, fmt.Sprintf("channel for ibc transfer: %s not found", msg.TransferChannel))
}
if channel.State != ibcchanneltypes.OPEN {
return nil, sdkerrors.Wrapf(
ibcchanneltypes.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
)
}
// TODO Understand capabilities and see if it has to be/ should be claimed in lsscopedkeeper. If it even matters.
_, err := m.lscosmosScopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(msg.TransferPort, msg.TransferChannel))
if err != nil {
ctx.Logger().Info(fmt.Sprintf("err: %s, Capability already exists", err.Error()))
}
hostAccounts := m.GetHostAccounts(ctx)
// This checks for channel being active
err = m.icaControllerKeeper.RegisterInterchainAccount(ctx, msg.ConnectionID, hostAccounts.DelegatorAccountOwnerID, "")
if err != nil {
return nil, sdkerrors.Wrap(err, "Could not register ica delegation Address")
}
newHostChainParams := types.NewHostChainParams(msg.ChainID, msg.ConnectionID, msg.TransferChannel,
msg.TransferPort, msg.BaseDenom, msg.MintDenom, msg.PstakeParams.PstakeFeeAddress,
msg.MinDeposit, msg.PstakeParams.PstakeDepositFee, msg.PstakeParams.PstakeRestakeFee,
msg.PstakeParams.PstakeUnstakeFee, msg.PstakeParams.PstakeRedemptionFee)
m.SetHostChainParams(ctx, newHostChainParams)
m.SetAllowListedValidators(ctx, msg.AllowListedValidators)
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
types.EventTypeJumpStart,
sdktypes.NewAttribute(types.AttributePstakeAddress, msg.PstakeAddress),
),
sdktypes.NewEvent(
sdktypes.EventTypeMessage,
sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory),
sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.PstakeAddress),
)},
)
return &types.MsgJumpStartResponse{}, nil
}
// RecreateICA defines a method for recreating closed ica channels
func (m msgServer) RecreateICA(goCtx context.Context, msg *types.MsgRecreateICA) (*types.MsgRecreateICAResponse, error) {
ctx := sdktypes.UnwrapSDKContext(goCtx)
// check if module is inactive or active
if !m.GetModuleState(ctx) {
return nil, types.ErrModuleDisabled
}
hostAccounts := m.Keeper.GetHostAccounts(ctx)
hostChainParams := m.Keeper.GetHostChainParams(ctx)
msgAttributes := []sdktypes.Attribute{sdktypes.NewAttribute(types.AttributeFromAddress, msg.FromAddress)}
_, ok := m.icaControllerKeeper.GetOpenActiveChannel(ctx, hostChainParams.ConnectionID, hostAccounts.DelegatorAccountPortID())
if !ok {
err := m.icaControllerKeeper.RegisterInterchainAccount(ctx, hostChainParams.ConnectionID, hostAccounts.DelegatorAccountOwnerID, "")
if err != nil {
return nil, sdkerrors.Wrap(err, "Could not register ica delegation Address")
}
msgAttributes = append(msgAttributes, sdktypes.NewAttribute(types.AttributeRecreateDelegationICA, hostAccounts.DelegatorAccountPortID()))
}
_, ok = m.icaControllerKeeper.GetOpenActiveChannel(ctx, hostChainParams.ConnectionID, hostAccounts.RewardsAccountPortID())
if !ok {
err := m.icaControllerKeeper.RegisterInterchainAccount(ctx, hostChainParams.ConnectionID, hostAccounts.RewardsAccountOwnerID, "")
if err != nil {
return nil, sdkerrors.Wrap(err, "Could not register ica reward Address")
}
msgAttributes = append(msgAttributes, sdktypes.NewAttribute(types.AttributeRecreateRewardsICA, hostAccounts.RewardsAccountPortID()))
}
ctx.EventManager().EmitEvents(sdktypes.Events{
sdktypes.NewEvent(
types.EventTypeRecreateICA,
msgAttributes...,
),
sdktypes.NewEvent(
sdktypes.EventTypeMessage,
sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory),
sdktypes.NewAttribute(sdktypes.AttributeKeySender, msg.FromAddress),
)},
)
return &types.MsgRecreateICAResponse{}, nil
}