Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Provider Rewards and Promotions #867

Merged
merged 31 commits into from
Oct 3, 2024
Merged

Conversation

michaeldjeffrey
Copy link
Contributor

@michaeldjeffrey michaeldjeffrey commented Sep 21, 2024

Service Provider Promotion Rewards

HIP-114, Pre-req PR, Proto PR

Where do Funds come from?

Service Providers update their incentive_escrow_fund_bps on Solana. The promotion_fund workspace is configured to check Solana for updates to Service Provider Accounts, and output new reports to S3 when values change.

bps stands for Basis Points. They represent a percentage to 2 decimal places 00.00%. A bps of 500 is equal to 5%. 10,000 equals 100%.

mobile-verifier watches that file and saves it's values to it's db. This means rewards can be run without needing to talk to Solana. S3 acts as the history of values for Service Providers, and mobile-verifier hangs on to the latest value.

A promotions subcommand has been added to mobile-verifier.

Calculating with percentages

Now that Service Providers can set aside a percentage of their rewards for promotions, it becomes easier to think of calculating rewards in only percentages. There are 5 percentages we track.

1. dc_perc :: Service Provider DC percentage of total rewards pool

This percentage is derived from the amount of DC transfer a Service Provider facilitated during the reward period.

2. allocated_promo_perc :: Percentage the Service Provider has set aside for promotions

This is the percentage representation of incentive_escrow_fund_bps.

3. realized_promo_perc :: Promotions as a percentage of total rewards pool

To get this percentage we take the allocated_promo_perc of dc_perc. If a Service Provider has 60% of the total rewards pool and has set aside 20% of their rewards for promotions 60% x 20% = 12%, that Service Provider's promotion rewards represent 12% of the total rewards pool.

In he case where a Service Provider has no promotions to give out, this percentage will be 0%.

4. realized_dc_perc :: Service Provider rewards as a percentage of total rewards pool

This percentage is dc_perc - realized_promo_perc. It is the subset of the total rewards pool that is going to the Service Provider. Continuing the example from above, 60% - 12% = 48%, that Service Provider's rewards represent 48% of the total rewards pool.

In the case where a Service Provider has no rewards this percentage will be equal to dc_perc.

5. matched_promo_perc :: Matched promotion from Unallocated as a percentage of total rewards pool

This percentage is the amount of the total rewards pool going towards matching a Service Provider's promotions. This value is extrapolated in the next section.

How does matching work?

Thus far, the unallocated service provider rewards can be found by removing all service provider's dc_perc from 100%. Continuing the above example with a single service provider, there is 40% of the rewards pool unallocated and available for matching promotion rewards.

Matched rewards can never exceed the amount a service provider has allocated for promotions. And matched rewards can never go towards anything other than promotions.

If a Service Provider has no promotions for the reward period, they are not considered in any of the matching situations.

Unallocated % is greater than all promotions

If you take take the sum of all Service Provider's realized_promo_perc, and it is less than the remaining unallocated rewards, each service provider receives an equal amount of matched rewards. realized_promo_perc == matched_promo_perc.

With the ongoing example, 12% would be used to match the 12% promotion rewards from the Service Provider, and the remaining unallocated amount would be 28%. Remember all these percentages are relative to the total rewards pool.

Unallocated % is less than all promotions

In this situation, the unallocated rewards are distributed amongst the service providers in portions relative to their dc_perc.

Let's have an example where Total Rewards Allocation: 100,000

DC Tranfser Promotion Allocation % of total rewards % of DC transfer
Service Provider 1 80,000 50% 80% 88%
Service Provider 2 10,000 50% 10% 12%

The realized promotion percentage for both Service Providers is 45%. (50% of 80%) + (50% of 10%).

To dive up the remaining 10% of rewards, we split on the % of DC Transfer.

Service Provider 1: 88% of 10% = 8.8%
Service Provider 2: 12% of 10% = 1.2%

Now, 100% of the total service provider rewards should be accounted for.

dc_perc allocated_promo_perc realized_promo_perc realized_dc_perc matched_promo_perc
Service Provider 1 80% 50% 40% 40% 8.8%
Service Provider 2 10% 50% 5% 5% 1.2%

40% + 40% + 8.8% + 5% + 5% + 1.2% = 100%

Distributing Promotions

Service Providers submit promotion rewards by assigning a number of shares to the recipient (Entity in code). To distribute the rewards, we do a familiar calculation where we find the rewards_per_share by doing total_shares / total_rewards, then each recipient is given their shares * rewards_per_share.

total_rewards in this case is a Service Proviers (realized_promo_perc + matched_promo_perc) * total_rewards_pool.

Rounding

Generally, when dealing with reward calculations that result in fractional values, oralces always down. This is to prevent any chance of over allocation. In dealing with very large numbers and the way computers do math, we may not always end up with nice round numbers.

There are a couple tests where the math in any online calculator will come out to an even 60,000. The DC Transfer in the test represent some 0.00000073% of rewards above 8 trillion. The resulting multiplication when using percentages comes out to 5,999.9999999976 (estimation). This gets rounded down, and the missing reward is moved to the unallocated pool.

Errors like this are reduced when dealing with larger allocations of the total rewards pool.

Something like Bankers rounding wouldn't necessarily alleviate this problem, because we have no reason to think that promotion values will be randomly distributed. Assuming promotion shares could all be the same for a reward period, they would all round in the same direction, and if that direction is up, we could end up allocating more rewards than what exists.

So we remain safe and round down.

This workspace is all about dealing with Service Provider Promotion Fund
allocation.

HIP-114
https://github.com/helium/HIP/blob/main/0114-incentive-escrow-fund-for-subscriber-referrals.md

Service Provider Promotions are stored in CarrierV0 on Solana.
To keep the mobile-verifier from talking to a chain, this service will
periodically check Solana and compare Service Providers allocations to
what is stored in S3.

If the values have changed, a new file will be output to a bucket for
the mobile-verifier rewarder to read from.

NOTE: Allocation Values are stored in Bps (Basis Points)
https://www.investopedia.com/terms/b/basispoint.asp

** Commands

*** ./promotion_fund write-solana

Fetch Allocation values from Solana and write them to S3.
This command _always_ writes an S3 file.

*** ./promotion_fund print-s3

Using the lookback time in the provided settings file, show the
Allocation values this service would start up with.

*** ./promotion_fund server

Start a server that reads from S3, then checks with Solana periodically
for updated Allocatino values. Writing new files when needed.
- ingest promotion rewards, nothing will be done with them until the
  processor is added into mobile-verifier.
- dump reward files
- add sp_allocations dummy field to rewarder output
- reward indexer mobile promotion type added
Otherwise inserting a new reward would match on the address and
continually change the reward_type column for no reason.
Default trait impls cannot be added to functions, but they can be added
to structs. This struct keeps us from needing to do the gross blank
generic filling in when we want a continuous file source with a decode
other than MsgDecodeFileInfoPollerParser.
Rather than always dealing with conrete numbers, now that Service
Providers can allocate a percentage of their rewards to promotions for
subscribers or gateways, it becomes easier to speak of everything in
percentages.

This is a quick overview of what a more detailed overview you will find
in the PR.

For every Service Provider (SP) we figure out how much of the total
rewards allocation they are being awarded for data transfer. We get the
percent they have allocated for promotions (essentially from solana, but
really s3), and we determine which percentage of the _total rewards
allocation_ that is.

If a SP is getting 50% of the total rewards, and they allocate 20% of
those rewards to promotions, then the SP will receive 40% of the total,
and promotions from them will represent 10% of the total.

We do that for all SPs. The unallocated percentage is then distributed
to the promotions of each SP. If there is more than enough unallocated
left over, each SP get's a matched percentage of the whole to what they
set aside. When there is not enough, they get a percentage equal to
their initial rewards percentage.

This is to keep a service provider from getting the bulk of extra
rewards by settings aside a large amount for promotions, and receiving
little in rewards for data transfer, but getting more for matching.

A SP may never receive more in matched rewards than they have allocated
themselves.
This makes invocations of rewarding look very consistent
because we're dealing with percentages, and not doing bankers rounding
or nearest even, the likelihood that a calculation comes out extremely
close to a hole number then gets rounded down is increased. Especially
when dealing with percentages to the 7th decimal point and a base number
in the trillions.
I'm hoping there's an easy way to do this someone can point me to
it get a bit verbose with all the service_provider flying around, but I
think it will be rather helpful when you only have the type and it
hasn't been aliased.
truncating to 5 decimal places for a % can result in the summed
allocation exceeding 100%.

Thanks proptest
It has been noted that in tests a single bone is okay, as long as we're
not going over the allocated bones
let's not have the worst of both worlds where we comment out unused
code.
Remove the printlns, they're not hard to add back in if you need them.
For accounting reasons, Service Providers can have multiple payer keys
listed. We need to ensuure all their dc transfer are accumulated into
their service provider entry when we are generating rewards.
@michaeldjeffrey michaeldjeffrey merged commit 2e3a438 into main Oct 3, 2024
17 checks passed
@michaeldjeffrey michaeldjeffrey deleted the mj/sp-rewards-in-perc branch October 3, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants