Skip to content

Commit

Permalink
Fix: Mint rewards to the finality contract (#69)
Browse files Browse the repository at this point in the history
Fixes the minted rewards recipient address as discussed in / required by babylon-contract #97
  • Loading branch information
maurolacy authored Dec 16, 2024
1 parent 940af19 commit 82fc98b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/bcd_consumer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (s *BCDConsumerIntegrationTestSuite) Test6ConsumerFPRewardsGeneration() {
s.NotNil(czActivatedBlock)

// Ensure the staking contract balance is initially empty
rewards, err := s.cosmwasmController.QueryStakingContractBalances()
rewards, err := s.cosmwasmController.QueryFinalityContractBalances()
s.NoError(err)
s.Empty(rewards)

Expand Down Expand Up @@ -344,7 +344,7 @@ func (s *BCDConsumerIntegrationTestSuite) Test6ConsumerFPRewardsGeneration() {

// Ensure consumer rewards are generated and sent to the staking contract
s.Eventually(func() bool {
rewards, err := s.cosmwasmController.QueryStakingContractBalances()
rewards, err := s.cosmwasmController.QueryFinalityContractBalances()
if err != nil {
s.T().Logf("failed to query rewards: %s", err.Error())
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ func (cc *CosmwasmConsumerController) QueryDelegations() (*ConsumerDelegationsRe
return &resp, nil
}

func (cc *CosmwasmConsumerController) QueryFinalityContractBalances() (sdk.Coins, error) {
return cc.QueryBalances(cc.cfg.BtcFinalityContractAddress)
}

func (cc *CosmwasmConsumerController) QueryStakingContractBalances() (sdk.Coins, error) {
return cc.QueryBalances(cc.cfg.BtcStakingContractAddress)
}
Expand Down
Binary file modified tests/testdata/btc_finality.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testdata/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4e0214702fc01ebbbf0e966a88ac115726180a5b
84130eb706e1fb60e16cecf9ce8ade94b66ffa62
8 changes: 4 additions & 4 deletions x/babylon/keeper/mint_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/errors"
)

// MintBlockRewards mints new tokens and sends them to the staking contract for distribution.
// MintBlockRewards mints new tokens and sends them to the finality contract for distribution.
// Authorization of the actor should be handled before entering this method.
// Authorization of the recipient is being handled within the method for safety, but can
// be removed for flexibility
Expand All @@ -26,9 +26,9 @@ func (k Keeper) MintBlockRewards(pCtx sdk.Context, recipient sdk.AccAddress, amt
}
// FIXME? Remove this constraint for flexibility
params := k.GetParams(pCtx)
if recipient.String() != params.BtcStakingContractAddress {
return sdkmath.ZeroInt(), errors.ErrUnauthorized.Wrapf("invalid recipient: got %s, expected staking contract (%s)",
recipient, params.BtcStakingContractAddress)
if recipient.String() != params.BtcFinalityContractAddress {
return sdkmath.ZeroInt(), errors.ErrUnauthorized.Wrapf("invalid recipient: got %s, expected finality contract (%s)",
recipient, params.BtcFinalityContractAddress)
}

// TODO?: Ensure Babylon constraints
Expand Down

0 comments on commit 82fc98b

Please sign in to comment.