Time to Reward Them Validators!

How’s everyone doin’ now that the Ethereum Merge is complete? The shift from Proof-of-Work (PoW) to Proof-of-Stake (PoS) fer them developers over at Ethereum was nothin’ short of real hard work and many sleepless nights. While PoS may not be perfect as far as consensus mechanisms go, it sure is a whole lot more resource efficient than PoW! We here at Bearmint would like to congratulate everyone who made The Merge possible and can assure you that we will continue to watch Ethereum’s development with great interest.

Truth is, there’s a whole lot more to blockchains than just consensus mechanisms. We’ve covered a whole bunch of different topics related to buildin’ blockchains over the past few weeks, and as we continue along the path towards our official launch, we’ll keep bringin’ you content on the regular! If you really want to learn about blockchain development, then all you need to do is keep readin’ our blogs, and we guarantee that within a few weeks, you’ll be infinitely more knowledgeable than when you started out!

Now with the topic of consensus mechanisms and PoS in mind, validators stake a certain number of tokens so they can participate in consensus and validate new blocks. They also provide computational power to the network in order to keep it secure and runnin’ nice and smoothly. Of course we can’t expect these validators to spend all this time and money to help sustain the network without givin’ them some kind of incentive. So fer this reason, we reward validators fer takin’ these risks and puttin’ themselves on the line so that everyone’s digital assets are kept safe and can be exchanged at any time.

Last time we covered how to build and implement a delegator rewarder, so today we’ll focus on buildin’ and implementin’ somethin’ similar: a validator rewarder. As always, before we get stuck into the guide, we ask that you review the followin’ list of definitions so that you aren’t left clueless and slack-jawed when you see these items crop up in the code!

Give Me a Second to Let It All Sink in, Hombre…

  • @bearmint/bep12 is an NPM package that offers an implementation of BEP-012 which proposes a standardized interface around BigInt as well as the addition of a few convenient functions to keep common operations as dry as possible
  • @bearmint/bep13 is an NPM package that offers an implementation of BEP-013 which allows for the sharing of a set of types between all the modules that exist within Bearmint
  • @bearmint/bep16 is an NPM package that offers an implementation of BEP-016 which contains a standardized method of bootstrapping the plugins and application via service providers

Building the Strategy

This process is relatively straightforward and basically requires fundamental logic in most cases. The following example illustrates a mechanism that implements a fixed reward, but you’re free to implement whatever logic best suits your unique use case.

import type { Cradle, ValidatorRewarderStrategy } from '@bearmint/bep13';
import { makeBigNumber } from '@bearmint/bep12';
import { increaseBalance } from '@bearmint/bep22';
export function makeStrategy(cradle: Cradle): ValidatorRewarderStrategy {
return {
async execute({ account, denomination }) {
const amount = makeBigNumber(0);
increaseBalance({
account,
amount,
denomination,
});
return amount;
},
};
}

Registering With the Application

To finish up, we simply bind our newly-created function to the container as ContainerType.ValidatorRewarderStrategies['@bearmint/bep78'] - Bearmint will now use our chosen rewarder strategy whenever it’s requested.

import type { Cradle, ServiceProvider } from '@bearmint/bep13';
import { makeServiceProviderSkeleton } from '@bearmint/bep16';
import { strategy } from './strategy';
function makeServiceProvider(cradle: Cradle): ServiceProvider {
return {
...makeServiceProviderSkeleton(import.meta.url ?? __dirname),
async register() {
cradle.ValidatorRewarderStrategies['@bearmint/bep79'] = strategy;
},
};
}

It’s All Over? Already?

Yep, that’s all there is to it, friends! There are different validator rewards strategies available, so if you don’t fancy fixed rewards, yer more than free to choose one that suits you. Thank you fer yer time and attention. Should you have any queries or if you need to find out somethin’ specific fer yer particular use case, we kindly ask that you get in touch with us so that we can provide you with the assistance you need and help you get to where you want to be sooner than later!