Skip to content

Commit a0669c4

Browse files
committed
refactor: generalize implementation
1 parent b9ad379 commit a0669c4

27 files changed

Lines changed: 1330 additions & 853 deletions

api/v2/dollar.pulsar.go

Lines changed: 128 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/events.pulsar.go

Lines changed: 143 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/genesis.pulsar.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/query.pulsar.go

Lines changed: 355 additions & 290 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/tx.pulsar.go

Lines changed: 162 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ deps:
1010
- buf.build/googleapis/googleapis:cc916c31859748a68fd229a3c8d7a2e8
1111
lint:
1212
except:
13+
- ENUM_VALUE_PREFIX
14+
- ENUM_ZERO_VALUE_SUFFIX
1315
- SERVICE_SUFFIX
1416
- RPC_REQUEST_STANDARD_NAME
1517
- RPC_RESPONSE_STANDARD_NAME

client/cli/query.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func QueryStats() *cobra.Command {
7474
func QueryYieldRecipients() *cobra.Command {
7575
cmd := &cobra.Command{
7676
Use: "yield-recipients",
77-
Short: "Query all yield recipients for IBC channels",
77+
Short: "Query all yield recipients for external chains",
7878
Args: cobra.NoArgs,
7979
RunE: func(cmd *cobra.Command, args []string) error {
8080
clientCtx := client.GetClientContextFromCmd(cmd)
@@ -96,14 +96,19 @@ func QueryYieldRecipients() *cobra.Command {
9696

9797
func QueryYieldRecipient() *cobra.Command {
9898
cmd := &cobra.Command{
99-
Use: "yield-recipient [channel-id]",
100-
Short: "Query the yield recipient for an IBC channel",
101-
Args: cobra.ExactArgs(1),
99+
Use: "yield-recipient [provider] [identifier]",
100+
Short: "Query the yield recipient for an external chain",
101+
Args: cobra.ExactArgs(2),
102102
RunE: func(cmd *cobra.Command, args []string) error {
103103
clientCtx := client.GetClientContextFromCmd(cmd)
104104
queryClient := v2.NewQueryClient(clientCtx)
105105

106-
res, err := queryClient.YieldRecipient(context.Background(), &v2.QueryYieldRecipient{ChannelId: args[0]})
106+
provider := v2.Provider(v2.Provider_value[args[0]])
107+
108+
res, err := queryClient.YieldRecipient(context.Background(), &v2.QueryYieldRecipient{
109+
Provider: provider,
110+
Identifier: args[1],
111+
})
107112
if err != nil {
108113
return err
109114
}

client/cli/tx.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,22 @@ func GetTxCmd() *cobra.Command {
4848

4949
func TxSetYieldRecipient() *cobra.Command {
5050
cmd := &cobra.Command{
51-
Use: "set-yield-recipient [channel-id] [yield-recipient]",
52-
Short: "Set the yield recipient for an IBC channel",
53-
Args: cobra.ExactArgs(2),
51+
Use: "set-yield-recipient [provider] [identifier] [recipient]",
52+
Short: "Set the yield recipient for an external chain",
53+
Args: cobra.ExactArgs(3),
5454
RunE: func(cmd *cobra.Command, args []string) error {
5555
clientCtx, err := client.GetClientTxContext(cmd)
5656
if err != nil {
5757
return err
5858
}
5959

60+
provider := v2.Provider(v2.Provider_value[args[0]])
61+
6062
msg := &v2.MsgSetYieldRecipient{
61-
Signer: clientCtx.GetFromAddress().String(),
62-
ChannelId: args[0],
63-
YieldRecipient: args[1],
63+
Signer: clientCtx.GetFromAddress().String(),
64+
Provider: provider,
65+
Identifier: args[1],
66+
Recipient: args[2],
6467
}
6568

6669
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)

e2e/ibc_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"context"
2525
"encoding/base64"
2626
"encoding/json"
27+
"fmt"
2728
"testing"
2829

2930
"cosmossdk.io/math"
@@ -117,12 +118,13 @@ func TestIBCYieldDistribution(t *testing.T) {
117118
// TODO: Once NobleICS4Wrapper has been migrated, ensure that transfers are blocked at first!
118119

119120
// ACT: Set the yield recipient for the external chain.
120-
_, err = validator.ExecTx(ctx, authority.KeyName(), "dollar", "set-yield-recipient", channelID, yieldRecipient)
121+
_, err = validator.ExecTx(ctx, authority.KeyName(), "dollar", "set-yield-recipient", "IBC", channelID, yieldRecipient)
121122
require.NoError(t, err)
122123

123124
// ASSERT: There is one yield recipient.
124125
yieldRecipients = getYieldRecipients(t, ctx, validator)
125-
require.Equal(t, yieldRecipient, yieldRecipients[channelID])
126+
key := fmt.Sprintf("%s/%s", dollartypes.Provider_IBC, channelID)
127+
require.Equal(t, yieldRecipient, yieldRecipients[key])
126128

127129
// ACT: Send 500,000 $USDN from the user on Noble to the external chain.
128130
_, err = chain.SendIBCTransfer(ctx, channelID, user.KeyName(), ibc.WalletAmount{

genesis.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package dollar
2323
import (
2424
"context"
2525
"fmt"
26+
"strings"
2627

2728
"cosmossdk.io/collections"
2829
"cosmossdk.io/core/address"
@@ -70,10 +71,15 @@ func InitGenesis(ctx context.Context, k *keeper.Keeper, address address.Codec, g
7071
panic(errors.Wrap(err, "unable to set genesis stats"))
7172
}
7273

73-
for channelId, yieldRecipient := range genesis.YieldRecipients {
74-
err = k.YieldRecipients.Set(ctx, channelId, yieldRecipient)
74+
for key, recipient := range genesis.YieldRecipients {
75+
splitKey := strings.Split(key, "/")
76+
provider := types.Provider(types.Provider_value[splitKey[0]])
77+
identifier := splitKey[1]
78+
79+
key := collections.Join(int32(provider), identifier)
80+
err = k.YieldRecipients.Set(ctx, key, recipient)
7581
if err != nil {
76-
panic(errors.Wrapf(err, "unable to set genesis yield recipient (%s:%s)", channelId, yieldRecipient))
82+
panic(errors.Wrapf(err, "unable to set genesis yield recipient (%s/%s:%s)", provider, identifier, recipient))
7783
}
7884
}
7985

0 commit comments

Comments
 (0)