Skip to content

Commit

Permalink
fix: instantiate ratesync ibc contracts with counterparty transfer ra…
Browse files Browse the repository at this point in the history
…ther … (#761)

* instantiate ratesync ibc contracts with counterparty transfer rather than self chain transfer

* update CHANGELOG.md
  • Loading branch information
puneet2019 authored Feb 9, 2024
1 parent 417d692 commit 5064db4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [721](https://github.com/persistenceOne/pstake-native/pull/721) Add Query host chain user unbondings.

### Bug Fixes

- [761](https://github.com/persistenceOne/pstake-native/pull/761) Use counterparty channels instead of self chain for ratesync-instantiate
- [752](https://github.com/persistenceOne/pstake-native/pull/752) Use correct existing delegation amount.
- [751](https://github.com/persistenceOne/pstake-native/pull/751) Set LSM bond factor as -1 by default.
- [750](https://github.com/persistenceOne/pstake-native/pull/750) Shares to tokens.
Expand Down
27 changes: 16 additions & 11 deletions x/ratesync/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ func (k msgServer) CreateHostChain(goCtx context.Context, msg *types.MsgCreateHo

channel, found := k.ibcKeeper.ChannelKeeper.GetChannel(ctx, msg.HostChain.TransferPortID, msg.HostChain.TransferChannelID)
if !found || channel.State != channeltypes.OPEN {
if err != nil {
return nil, errorsmod.Wrapf(
sdkerrors.ErrNotFound,
"error creating %s ratesync with channel: %s, port: %s, err:%s",
chainID, msg.HostChain.TransferChannelID, msg.HostChain.TransferPortID,
err.Error(),
)
}
return nil, errorsmod.Wrapf(
sdkerrors.ErrNotFound,
"error creating %s ratesync with channel: %s, port: %s",
chainID, msg.HostChain.TransferChannelID, msg.HostChain.TransferPortID,
)
}

k.SetHostChain(
Expand Down Expand Up @@ -121,11 +118,19 @@ func (k msgServer) UpdateHostChain(goCtx context.Context, msg *types.MsgUpdateHo
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid channelID, channelID cannot be updated, "+
"channelID mismatch got %s, found %s", msg.HostChain.TransferChannelID, oldHC.TransferChannelID)
}

if msg.HostChain.TransferPortID != oldHC.TransferPortID {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid portID, portID cannot be updated, "+
"portID mismatch got %s, found %s", msg.HostChain.TransferPortID, oldHC.TransferPortID)
}

channel, found := k.ibcKeeper.ChannelKeeper.GetChannel(ctx, oldHC.TransferPortID, oldHC.TransferChannelID)
if !found || channel.State != channeltypes.OPEN {
return nil, errorsmod.Wrapf(
sdkerrors.ErrNotFound,
"error creating %s ratesync with channel: %s, port: %s",
oldHC.ChainID, msg.HostChain.TransferChannelID, msg.HostChain.TransferPortID,
)
}
if oldHC.ICAAccount.ChannelState != liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid ICAAccount state, should already be active")
}
Expand Down Expand Up @@ -167,7 +172,7 @@ func (k msgServer) UpdateHostChain(goCtx context.Context, msg *types.MsgUpdateHo
// update oldhc, generate and execute wasm instantiate
oldHC.Features.LiquidStakeIBC = msg.HostChain.Features.LiquidStakeIBC

err := k.InstantiateLiquidStakeContract(ctx, oldHC.ICAAccount, oldHC.Features.LiquidStakeIBC, oldHC.ID, oldHC.ConnectionID, oldHC.TransferChannelID, oldHC.TransferPortID)
err := k.InstantiateLiquidStakeContract(ctx, oldHC.ICAAccount, oldHC.Features.LiquidStakeIBC, oldHC.ID, oldHC.ConnectionID, channel.Counterparty.ChannelId, channel.Counterparty.PortId)
if err != nil {
return nil, err
}
Expand All @@ -192,7 +197,7 @@ func (k msgServer) UpdateHostChain(goCtx context.Context, msg *types.MsgUpdateHo
// update oldhc, generate and execute wasm instantiate
oldHC.Features.LiquidStake = msg.HostChain.Features.LiquidStake

err := k.InstantiateLiquidStakeContract(ctx, oldHC.ICAAccount, oldHC.Features.LiquidStake, oldHC.ID, oldHC.ConnectionID, oldHC.TransferChannelID, oldHC.TransferPortID)
err := k.InstantiateLiquidStakeContract(ctx, oldHC.ICAAccount, oldHC.Features.LiquidStake, oldHC.ID, oldHC.ConnectionID, channel.Counterparty.ChannelId, channel.Counterparty.PortId)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5064db4

Please sign in to comment.