terra-money / classic-core

GO implementation of the Terra Protocol
https://www.terra.money
Other
980 stars 287 forks source link

[FEATURE] Split market spread between oracle voting rewards and block validation rewards #730

Closed yun-yeo closed 2 years ago

yun-yeo commented 2 years ago

Problem definition Currently there is no a strong reason for validators to picking transactions when building blocks because almost all rewards are coming from oracle voting.

To make the strong reason, split the market spread as an oracle voting rewards and a block validation rewards.

Feature specification Pseudocode:

// handleMsgSwap handles the logic of a MsgSwap
// This function does not repeat checks that have already been performed in msg.ValidateBasic()
// Ex) assert(offerCoin.Denom != askDenom)
func (k msgServer) handleSwapRequest(ctx sdk.Context,
    trader sdk.AccAddress, receiver sdk.AccAddress,
    offerCoin sdk.Coin, askDenom string) (*types.MsgSwapResponse, error) {

...

    // Spend swap fee as validator rewards
    if feeCoin.IsPositive() {
        // Split feeCoin 50:50 between oracle voting rewards and block validation rewards
        blockValidationReward := feeCoin.Amount.QuoRaw(2)
        oracleVotesReward := feeCoin.Amount.Sub(blockValidationReward)

        // Send half to fee collector account
        if !blockValidationReward.IsZero() {
            blockValidationRewardCoins := sdk.Coins{{Amount: blockValidationReward, Denom: feeCoin.Denom}}
            err = k.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, authtypes.FeeCollectorName, blockValidationRewardCoins)
            if err != nil {
                return nil, err
            }
        }

        // Send left half to oracle account
        if !oracleVotesReward.IsZero() {
            oracleVotesRewardCoins := sdk.Coins{{Amount: oracleVotesReward, Denom: feeCoin.Denom}}
            err = k.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, oracletypes.ModuleName, oracleVotesRewardCoins)
            if err != nil {
                return nil, err
            }
        }
    }

...

}