Get Yer Delegator Rewards!

My oh my, how the days and weeks and months just roll on by! Amigos, it’s been an amazin’ journey thus far, but it ain’t over yet! We here at Bearmint are dedicated to developin’ the very best blockchain solutions fer our end users, so our work is never truly complete! Over the past few weeks we’ve discussed several different aspects related to the world of blockchain and even gone to the trouble of sharin’ some useful guides with you good folks.

Now in blockchains that make use of a consensus mechanism such as Delegated Proof-of-Stake (DPoS), validators provide computational power to produce new blocks while delegators (or voters) back these validators by votin’ fer ‘em. However, delegators need a good reason to vote fer validators other than pure altruism. It’s therefore good practice to reward delegators economically by providin’ ‘em with financial incentives fer backin’ validators that carry out the very important role of securin’ and runnin’ the network! This mechanism doesn’t just come out of nowhere of course, so you’ll need to implement one of yer choosin’!

In today’s very helpful guide, we explain the process of buildin’ and implementin’ a delegator rewardin’ mechanism. However, before we get stuck into all the finer details, we implore you to first review the followin’ definitions so you know exactly what it is we’re talkin’ about when we mention it in the code! Let’s get to it!

I Just Need You to Go Over That One Last Time, Pilgrim

  • @bearmint/bep3 is an NPM package that offers an implementation of BEP-003 which defines a standardized set of assertions that can verify whether certain expectations were fulfilled or not
  • @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

The process of building strategies is relatively straightforward and typically requires little logic in most cases. The following example illustrates how an equity-based strategy will look. However, you’re more than free to implement the logic that is most relevant to your specific use case.

import { assert } from '@bearmint/bep3';
import { makeBigNumber } from '@bearmint/bep12';
import { Account, AccountStakes, BigNumber } from '@bearmint/bep13';
function strategy({
delegator,
delegators,
reward,
validator,
}: {
delegator: Account;
delegators: AccountStakes;
reward: BigNumber;
validator: Account;
}) {
assert.defined<object>(validator.validator?.name);
const validatorStake = makeBigNumber(0).sumBy(Object.values(delegators), 'amount');
const delegatorStake = delegator.stakes[validator.validator.name].amount;
const delegatorStakePercentage = delegatorStake.times(100).dividedBy(validatorStake);
return reward.times(delegatorStakePercentage).dividedBy(100);
}

Registering With the Application

To complete the process, we simply bind our newly-created function to the container as ContainerType.DelegatorRewarderStrategies['@bearmint/bep86']. Now Bearmint will use our rewarder strategy whenever a validator requests it.

import { Cradle, ServiceProvider } from '@bearmint/bep13';
import { makeServiceProviderSkeleton } from '@bearmint/bep16';
import { strategy } from './strategy';
function makeServiceProvider(cradle: Cradle): ServiceProvider {
return {
...makeServiceProviderSkeleton(__dirname),
async register() {
cradle.DelegatorRewarderStrategies['@bearmint/bep86'] = strategy;
},
};
}

Really Couldn’t Be Simpler, Could It Now?

That may just be one of the simplest implementations yet, don’t you reckon, friends? Harnessin’ Bearmint to build and implement yer own delegator rewarder is real simple. Heck, the work’s practically done fer you! Just enter in a few lines of prepared code, and yer rewarder strategy fer delegates’ll be ready in no time at all!

That concludes today’s (very brief) guide, but should you have any needs or queries related to yer own application’s development, please don’t hesitate to get in touch with us on an appropriate channel so we can help you out! Buckley’s got all the solutions you need, and if fer some reason he doesn’t yet, well then, we’ll build 'em!