Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autopilot enhancement #771

Closed
wants to merge 8 commits into from
Closed

Autopilot enhancement #771

wants to merge 8 commits into from

Conversation

jstr1121
Copy link
Contributor

@jstr1121 jstr1121 commented May 12, 2023

Context and purpose of the change

The goal of this PR is to support two more features on autopilot module

  • RedeemStake as part of ibc transfer
  • LiquidStake and IBC transfer back liquid staking token as part of ibc transfer

Note: This PR moved from #626

Brief Changelog

  • MsgLiquidStake is returning received liquid staking token amount
  • Add unit test for RedeemStake and LiquidStakeAndIBCTransfer
  • Add integration test for RedeemStake and LiquidStakeAndIBCTransfer

Author's Checklist

I have...

  • Run and PASSED locally all GAIA integration tests
  • If the change is contentful, I either:
    • Added a new unit test OR
    • Added test cases to existing unit tests
  • OR this change is a trivial rework / code cleanup without any test coverage

If skipped any of the tests above, explain.

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • reviewed state machine logic
  • reviewed API design and naming
  • manually tested (if applicable)
  • confirmed the author wrote unit tests for new logic
  • reviewed documentation exists and is accurate

How to test integration test on local

  • Update DefaultStakeibcActive to true at x/autopilot/types/params.go
  • Comment out all skip "DefaultActive set to false, skip test" on dockernet/tests/integration_tests.bats
  • Install docker image for stride make build-docker build=s
  • Start dockernet with make start-docker
  • Run integration test with make test-integration-docker
  • Ensure the result is as following
integration_tests.bats
 ✓ [INTEGRATION-BASIC-GAIA] host zones successfully registered
 ✓ [INTEGRATION-BASIC-GAIA] ibc transfer updates all balances
 ✓ [INTEGRATION-BASIC-GAIA] liquid stake mint and transfer
 ✓ [INTEGRATION-BASIC-GAIA] packet forwarding automatically liquid stakes
 ✓ [INTEGRATION-BASIC-GAIA] transfer stuatom to host chain
 ✓ [INTEGRATION-BASIC-GAIA] packet forwarding automatically liquid stake and ibc transfer stAsset to original network
 ✓ [INTEGRATION-BASIC-GAIA] tokens on GAIA were staked
 ✓ [INTEGRATION-BASIC-GAIA] packet forwarding automatically redeem stake
 ✓ [INTEGRATION-BASIC-GAIA] redemption works
 ✓ [INTEGRATION-BASIC-GAIA] claimed tokens are properly distributed
 ✓ [INTEGRATION-BASIC-GAIA] rewards are being reinvested, exchange rate updating
 ✓ [INTEGRATION-BASIC-GAIA] rewards are being distributed to stakers

12 tests, 0 failures

How to test Hub -> Stride -> Osmosis

  • Update dockernet/config.sh to HOST_CHAINS=(GAIA OSMO)
  • Start dockernet with make start-docker build=sgor
  • Test following script and ensure OSMO_ADDRESS gets stuatom ibc denom
GAIA_ADDRESS=$(./build/gaiad keys show -a gval1 --home=./dockernet/state/gaia1)
STRIDE_ADDRESS=stride1jrmtt5c6z8h5yrrwml488qnm7p3vxrrml2kgvl
OSMO_ADDRESS=osmo1dtq0y9reqst7d99fd3c7x6dflh4eazm4lx5sk9
GAIA_STRIDE_CHAN=channel-0
STRIDE_OSMO_CHAN=channel-1
memo='{ "autopilot": { "receiver": "'$STRIDE_ADDRESS'",  "stakeibc": { "stride_address": "'$STRIDE_ADDRESS'", "action": "LiquidStake", "ibc_receiver": "'$OSMO_ADDRESS'", "transfer_channel": "'$STRIDE_OSMO_CHAN'"  } } }'
./build/gaiad tx ibc-transfer transfer transfer $GAIA_STRIDE_CHAN "$memo" 10000uatom --from gval1 -y --home=./dockernet/state/gaia1
./build/gaiad query tx 31A1480A5F025F900A684F7CFD92F2FE06B4307CA81BD1E01AB31E9C01BFC7DF --home=./dockernet/state/gaia1
./build/gaiad query bank balances $GAIA_ADDRESS --home=./dockernet/state/gaia1
./build/strided query bank balances $STRIDE_ADDRESS --home=./dockernet/state/stride1
./build/osmosisd query bank balances $OSMO_ADDRESS --home=./dockernet/state/osmo1

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md?
  • This pull request updates existing proto field values (and require a backend and frontend migration)?
  • Does this pull request change existing proto field names (and require a frontend migration)?
    How is the feature or change documented?
    • not applicable
    • jira ticket XXX
    • specification (x/<module>/spec/)
    • README.md
    • not documented

@@ -27,8 +27,10 @@ type ModuleRoutingInfo interface {

// Packet metadata info specific to Stakeibc (e.g. 1-click liquid staking)
type StakeibcPacketMetadata struct {
Action string `json:"action"`
StrideAddress string `json:"stride_address"`
Action string `json:"action"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use an enum here?

Comment on lines +32 to +33
IbcReceiver string `json:"ibc_receiver,omitempty"`
TransferChannel string `json:"transfer_channel,omitempty"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these are empty it's assumed that the token is returned to the original sender over the same source channel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. These are omitted only when the receiver is original sender through original transfer channel.

Comment on lines +49 to +50
case "LiquidStake":
case "RedeemStake":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these seem that are not set up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's validation if the action is one of LiquidStake or RedeemStake, more could be added later and just used this format for validation

@@ -27,8 +27,10 @@ type ModuleRoutingInfo interface {

// Packet metadata info specific to Stakeibc (e.g. 1-click liquid staking)
type StakeibcPacketMetadata struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
type StakeibcPacketMetadata struct {
type StakeIBCPacketMetadata struct {

case "RedeemStake":
// Try to redeem stake - return an ack error if it fails, otherwise return the ack generated from the earlier packet propogation
if err := im.keeper.TryRedeemStake(ctx, packet, newData, routingInfo); err != nil {
im.keeper.Logger(ctx).Error(fmt.Sprintf("Error redeem staking packet from autopilot for %s: %s", newData.Sender, err.Error()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
im.keeper.Logger(ctx).Error(fmt.Sprintf("Error redeem staking packet from autopilot for %s: %s", newData.Sender, err.Error()))
im.keeper.Logger(ctx).Debug("failed redeem staking packet from autopilot", "sender" newData.Sender.String(), "error", err.Error())

x/autopilot/module_ibc.go Show resolved Hide resolved
Comment on lines +34 to +35
voucherPrefix := transfertypes.GetDenomPrefix(packet.GetSourcePort(), packet.GetSourceChannel())
stAssetDenom := newData.Denom[len(voucherPrefix):]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure there is a util for this

Comment on lines +30 to +32
if !transfertypes.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), newData.Denom) {
return fmt.Errorf("the ibc tokens are not supported for redeem stake")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the redeem stake flow? isn't the receiver chain in this case Stride?

}

// Note: newData.denom is ibc denom for st assets - e.g. ibc/xxx
var token = sdk.NewCoin(newData.Denom, amount)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double-check if the packet data is validated, otherwise this line panics if the denom or amount are invalid

return k.RunRedeemStake(ctx, strideAddress, packetMetadata.IbcReceiver, hostZoneDenom, token, []metrics.Label{})
}

func (k Keeper) RunRedeemStake(ctx sdk.Context, addr sdk.AccAddress, receiver string, hostZoneDenom string, token sdk.Coin, labels []metrics.Label) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highly recommend using the spread operator for optional slices

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Jun 9, 2023
@github-actions github-actions bot closed this Jun 15, 2023
@jstr1121 jstr1121 reopened this Jun 26, 2023
@github-actions github-actions bot removed the Stale label Jun 27, 2023
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Jul 12, 2023
@github-actions github-actions bot closed this Jul 18, 2023
@riley-stride riley-stride reopened this Jul 31, 2023
@github-actions github-actions bot removed the Stale label Aug 1, 2023
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Aug 16, 2023
@github-actions github-actions bot closed this Aug 23, 2023
@riley-stride riley-stride reopened this Aug 23, 2023
Copy link
Contributor

@riley-stride riley-stride left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed "remove stride_address field on functional info" commit 088fb2d. Looks good.

IbcReceiver string `json:"ibc_receiver,omitempty"`
TransferChannel string `json:"transfer_channel,omitempty"`
}

// Packet metadata info specific to Claim (e.g. airdrops for non-118 coins)
type ClaimPacketMetadata struct {
StrideAddress string
}

// Validate stakeibc packet metadata fields
// including the stride address and action type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rm "stride address and"

@@ -57,10 +51,6 @@ func (m StakeibcPacketMetadata) Validate() error {

// Validate claim packet metadata includes the stride address
func (m ClaimPacketMetadata) Validate() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this fn be removed now that it validates nothing?

@github-actions github-actions bot removed the Stale label Aug 24, 2023
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Sep 8, 2023
@github-actions github-actions bot closed this Sep 15, 2023
@@ -38,9 +38,16 @@ func (k Keeper) TryLiquidStaking(
}

// Note: newData.denom is base denom e.g. uatom - not ibc/xxx
var token = sdk.NewCoin(newData.Denom, amount)
var token = sdk.Coin{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed afaict

mergify bot pushed a commit that referenced this pull request Jan 8, 2024
Closes: #771

## Context and purpose of the change

Add `RedeemStake` to autopilot.


## Brief Changelog

* Add integration test for `RedeemStake`
* Add unittest for `RedeemStake`
* Integrate with autopilot module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants