Skip to content

Commit

Permalink
refactor: SupplierStakingFee var usages with supplier_staking_fee par…
Browse files Browse the repository at this point in the history
…am usages
  • Loading branch information
bryanchriswhite committed Nov 21, 2024
1 parent f206a28 commit 643f058
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
11 changes: 3 additions & 8 deletions x/supplier/keeper/msg_server_stake_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/app/volatile"
"github.com/pokt-network/poktroll/telemetry"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

var (
// TODO_BETA(@bryanchriswhite): Make supplier staking fee a governance parameter
// TODO_BETA(@red-0ne): Update supplier staking documentation to remove the upstaking requirement and introduce the staking fee.
SupplierStakingFee = sdk.NewInt64Coin(volatile.DenomuPOKT, 1)
)

// TODO_BETA(@red-0ne): Update supplier staking documentation to remove the upstaking requirement and introduce the staking fee.
func (k msgServer) StakeSupplier(ctx context.Context, msg *suppliertypes.MsgStakeSupplier) (*suppliertypes.MsgStakeSupplierResponse, error) {
isSuccessful := false
defer telemetry.EventSuccessCounter(
Expand Down Expand Up @@ -147,7 +141,8 @@ func (k msgServer) StakeSupplier(ctx context.Context, msg *suppliertypes.MsgStak
}

// Send the coins from the message signer account to the staked supplier pool
stakeWithFee := sdk.NewCoins(coinsToEscrow.Add(SupplierStakingFee))
supplierStakingFee := k.GetParams(ctx).StakingFee
stakeWithFee := sdk.NewCoins(coinsToEscrow.Add(*supplierStakingFee))
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, msgSignerAddress, suppliertypes.ModuleName, stakeWithFee)
if err != nil {
logger.Info(fmt.Sprintf("ERROR: could not send %v coins from %q to %q module account due to %v", coinsToEscrow, msgSignerAddress, suppliertypes.ModuleName, err))
Expand Down
3 changes: 2 additions & 1 deletion x/supplier/keeper/msg_server_stake_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestMsgServer_StakeSupplier_SuccessfulCreateAndUpdate(t *testing.T) {
require.Len(t, foundSupplier.Services[0].Endpoints, 1)
require.Equal(t, "http://localhost:8080", foundSupplier.Services[0].Endpoints[0].Url)
// Assert that the supplier's account balance was reduced by the staking fee
balanceDecrease := keeper.SupplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
supplierStakingFee := supplierModuleKeepers.Keeper.GetParams(ctx).StakingFee
balanceDecrease := supplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
// SupplierBalanceMap reflects the relative changes to the supplier's balance
// (i.e. it starts from 0 and can go below it).
// It is not using coins that enforce non-negativity of the balance nor account
Expand Down
5 changes: 3 additions & 2 deletions x/supplier/keeper/msg_server_unstake_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ func TestMsgServer_UnstakeSupplier_OperatorCanUnstake(t *testing.T) {

// Balance decrease is the total amount deducted from the supplier's balance, including
// the initial stake and the staking fee.
balanceDecrease := keeper.SupplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
supplierStakingFee := supplierModuleKeepers.Keeper.GetParams(ctx).StakingFee
balanceDecrease := supplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
// Ensure that the initial stake is not returned to the owner yet
require.Equal(t, -balanceDecrease, supplierModuleKeepers.SupplierBalanceMap[ownerAddr])

Expand All @@ -415,5 +416,5 @@ func TestMsgServer_UnstakeSupplier_OperatorCanUnstake(t *testing.T) {

// Ensure that the initial stake is returned to the owner while the staking fee
// remains deducted from the supplier's balance.
require.Equal(t, -keeper.SupplierStakingFee.Amount.Int64(), supplierModuleKeepers.SupplierBalanceMap[ownerAddr])
require.Equal(t, -supplierStakingFee.Amount.Int64(), supplierModuleKeepers.SupplierBalanceMap[ownerAddr])
}

0 comments on commit 643f058

Please sign in to comment.