Skip to content

Commit

Permalink
Add consumer distribution handler (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Dec 13, 2024
1 parent 78fed64 commit bc74a3f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions x/zoneconcierge/keeper/ibc_packet_btc_staking_consumer_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package keeper

import (
"context"
"encoding/json"
"fmt"

bbn "github.com/babylonlabs-io/babylon/types"
bsctypes "github.com/babylonlabs-io/babylon/x/btcstkconsumer/types"
finalitytypes "github.com/babylonlabs-io/babylon/x/finality/types"
"github.com/babylonlabs-io/babylon/x/zoneconcierge/types"
sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
)

// BroadcastBTCStakingConsumerEvents retrieves all BTC staking consumer events from the event store,
Expand Down Expand Up @@ -154,3 +156,41 @@ func (k Keeper) HandleConsumerSlashing(

return nil
}

type RewardsDistribution struct {
FpPubkeyHex string `json:"fp_pubkey_hex"`
Reward string `json:"reward"`
}

func (k Keeper) HandleConsumerDistribution(
ctx sdk.Context,
portID string,
channelID string,
consumerDistribution *ibctransfer.FungibleTokenPacketData,
) error {
// clientID, _, err := k.channelKeeper.GetChannelClientState(ctx, portID, channelID)
// if err != nil {
// return fmt.Errorf("failed to get client state: %w", err)
// }

// Deserialize the memo
var rewardsDistribution []RewardsDistribution
if err := json.Unmarshal([]byte(consumerDistribution.Memo), &rewardsDistribution); err != nil {
return fmt.Errorf("failed to unmarshal memo: %w", err)
}

// Process the distribution list
for _, reward := range rewardsDistribution {
fpPubkey, err := bbn.NewBIP340PubKeyFromHex(reward.FpPubkeyHex)
if err != nil {
return fmt.Errorf("failed to create BIP340 public key: %w", err)
}
fmt.Println("FP pubkey:", fpPubkey, ", Reward:", reward.Reward)

// Apply the finality provider commission

// Distribute the rewards to the delegators
}

return nil
}
6 changes: 6 additions & 0 deletions x/zoneconcierge/module_ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ func (im IBCModule) OnRecvPacket(
return channeltypes.NewErrorAcknowledgement(err)
}
return channeltypes.NewResultAcknowledgement([]byte("Consumer slashing handled successfully"))
case *types.ZoneconciergePacketData_ConsumerFpDistribution:
err := im.keeper.HandleConsumerDistribution(ctx, modulePacket.DestinationPort, modulePacket.DestinationChannel, packet.ConsumerFpDistribution)
if err != nil {
return channeltypes.NewErrorAcknowledgement(err)
}
return channeltypes.NewResultAcknowledgement([]byte("Consumer distribution handled successfully"))
// Add other packet types here if needed
default:
errMsg := fmt.Sprintf("unrecognized %s packet type: %T", types.ModuleName, packet)
Expand Down

0 comments on commit bc74a3f

Please sign in to comment.