Skip to content

Commit

Permalink
107 distribution quality tiers (#113)
Browse files Browse the repository at this point in the history
Adds quality tier bonus to distribution contract
  • Loading branch information
jim-toth authored Aug 10, 2024
1 parent 5a8d6e3 commit 11b2e1e
Show file tree
Hide file tree
Showing 11 changed files with 6,531 additions and 67 deletions.
2 changes: 0 additions & 2 deletions smartweave/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,3 @@ sw.*

# warp cache
cache/

data/
50 changes: 50 additions & 0 deletions smartweave/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ type DistributionResult = {
networkScore: string
distributedTokens: string
}
quality: {
enabled: boolean
tokensDistributedPerSecond: string
settings: {
uptime: {
[days: number]: number
}
}
uptime: {
[fingerprint: Fingerprint]: number
}
networkScore: string
distributedTokens: string
}
}
multipliers: {
family: {
Expand All @@ -266,6 +280,7 @@ type DistributionResult = {
distributedTokens: string
bonuses: {
hardware: string
quality: string
}
multipliers: {
family: string
Expand All @@ -284,6 +299,18 @@ type DistributionState = {
enabled: boolean
tokensDistributedPerSecond: string
fingerprints: Fingerprint[]
},
quality: {
enabled: boolean
tokensDistributedPerSecond: string
settings: {
uptime: {
[days: number]: number
}
}
uptime: {
[fingerprint: Fingerprint]: number
}
}
}
pendingDistributions: {
Expand Down Expand Up @@ -337,11 +364,29 @@ type DistributionState = {
setHardwareBonusRate(tokensDistributedPerSecond: string) => void
```
- Allows Owner to set quality bonus distribution rate **in atomic units** per
second
```typescript
setQualityTierBonusRate(tokensDistributedPerSecond: string) => void
```
- Allows Owner to toggle hardware bonus on or off
```typescript
toggleHardwareBonus(enabled: boolean) => void
```
- Allows Owner to toggle quality bonus on or off
```typescript
toggleQualityTierBonus(enabled: boolean) => void
```
- Allows Owner to set quality bonus settings
```typescript
setQualityTierBonusSettings(
settings: { uptime: { [days: number]: number } }
) => void
```
- Allows Owner to add fingerprints to a bonus pool. Currently only 'hardware'
```typescript
addFingerprintsToBonus(
Expand All @@ -350,6 +395,11 @@ type DistributionState = {
) => void
```
- Allows Owner to set fingerprint uptimes for quality bonus
```typescript
setQualityTierUptimes(uptimes: { [fingerprint: Fingerprint]: number }) => void
```
- Allows Owner to remove fingerprints from a bonus pool. Currently only
'hardware'
```typescript
Expand Down
114 changes: 114 additions & 0 deletions smartweave/data/test-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"families": [
{
"fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"add": [
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
]
},
{
"fingerprint": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"add": [
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
]
},
{
"fingerprint": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"add": [
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC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EEEEEEEEEEEEEEEEEEE",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
]
}
],
"relays": [
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"nickname": "B109-test-relay-1"
},
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"fingerprint": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"nickname": "B109-test-relay-2"
},
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"fingerprint": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"nickname": "B109-test-relay-3"
},
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"fingerprint": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"nickname": "B109-test-relay-4"
},
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"fingerprint": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
"nickname": "B109-test-relay-5"
},
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"fingerprint": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"nickname": "B109-test-relay-6"
}
],
"scores": [
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"score": "1000",
"fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"address": "0xB109188f495c61659804b054C7Bc9f10435D9095",
"score": "1000",
"fingerprint": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
}
]
}
137 changes: 137 additions & 0 deletions smartweave/scripts/util/quality-results-to-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { readFileSync } from 'fs'

const resultsPath =
`${__dirname}/../../test/e2e/data/results_quality_bonuses.csv`
const resultsCSVBuffer = readFileSync(resultsPath)
const resultsCSV = resultsCSVBuffer.toString()
const results = resultsCSV.split('\r\n')
results.shift() // NB: get rid of header in csv
const rewards = []

let baseNetworkScore = 0
let baseActualDistributedTokens = 0

let familyMultiplierNetworkScore = 0
let familyMultiplierActualDistributedTokens = 0

let qualityBonusNetworkScore = 0
let qualityBonusActualDistributedTokens = 0

let hwBonusNetworkScore = 0
let hwBonusActualDistributedTokens = 0

let hwBonusNetworkScoreWithFamilyMultiplier = 0
let hwBonusActualDistributedTokensWithFamilyMultiplier = 0

let totalNetworkScore = 0
let totalActualDistributedTokens = 0

for (const result of results) {
const [
r1,
r2,
address,

baseScore,
basePercentShare,
baseReward,

familyMultiplierScore,
familyMultiplierPercentShare,
familyMultiplierReward,

qualityBonusScore,
qualityBonusPercentShare,
qualityBonusReward,

qualityBonusScoreWithFamilyMultiplier,
qualityBonusPercentShareWithFamilyMultiplier,
qualityBonusRewardWithFamilyMultiplier,

hwBonusScore,
hwBonusPercentShare,
hwBonusReward,

hwBonusScoreWithFamilyMultiplier,
hwBonusPercentShareWithFamilyMultiplier,
hwBonusRewardWithFamilyMultiplier,

totalReward,
totalRewardWithFamilyMultiplier
] = result.split(',')

baseNetworkScore += Number.parseInt(baseScore)
baseActualDistributedTokens += Number.parseInt(baseReward)

familyMultiplierNetworkScore += Number.parseInt(familyMultiplierScore)
familyMultiplierActualDistributedTokens += Number.parseInt(familyMultiplierReward)

qualityBonusNetworkScore += Number.parseInt(qualityBonusScore)
qualityBonusActualDistributedTokens += Number.parseInt(qualityBonusReward)

hwBonusNetworkScore += Number.parseInt(hwBonusScore)
hwBonusActualDistributedTokens += Number.parseInt(hwBonusReward)

hwBonusNetworkScoreWithFamilyMultiplier += Number.parseInt(hwBonusScoreWithFamilyMultiplier)
hwBonusActualDistributedTokensWithFamilyMultiplier += Number.parseInt(hwBonusRewardWithFamilyMultiplier)

totalNetworkScore +=
Number.parseInt(baseScore)
+ Number.parseInt(hwBonusScoreWithFamilyMultiplier)
+ Number.parseInt(qualityBonusScore)
totalActualDistributedTokens += Number.parseInt(totalReward)

rewards.push({
address,

baseScore,
basePercentShare,
baseReward,

familyMultiplierScore,
familyMultiplierPercentShare,
familyMultiplierReward,

qualityBonusScore,
qualityBonusPercentShare,
qualityBonusReward,

hwBonusScore,
hwBonusPercentShare,
hwBonusReward,

hwBonusScoreWithFamilyMultiplier,
hwBonusPercentShareWithFamilyMultiplier,
hwBonusRewardWithFamilyMultiplier,

totalReward
})
}

const output = {
baseNetworkScore: baseNetworkScore.toString(),
baseActualDistributedTokens: baseActualDistributedTokens.toString(),

familyMultiplierNetworkScore: familyMultiplierNetworkScore.toString(),
familyMultiplierActualDistributedTokens:
familyMultiplierActualDistributedTokens.toString(),

qualityBonusNetworkScore: qualityBonusNetworkScore.toString(),
qualityBonusActualDistributedTokens:
qualityBonusActualDistributedTokens.toString(),

hwBonusNetworkScore: hwBonusNetworkScore.toString(),
hwBonusActualDistributedTokens: hwBonusActualDistributedTokens.toString(),

hwBonusNetworkScoreWithFamilyMultiplier:
hwBonusNetworkScoreWithFamilyMultiplier.toString(),
hwBonusActualDistributedTokensWithFamilyMultiplier:
hwBonusActualDistributedTokensWithFamilyMultiplier.toString(),

totalNetworkScore: totalNetworkScore.toString(),
totalActualDistributedTokens: totalActualDistributedTokens.toString(),

rewards
}

console.log(JSON.stringify(output, undefined, 2))
Loading

0 comments on commit 11b2e1e

Please sign in to comment.