contributor

package
v1.49.44 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComponentWeightsFromSBOM added in v1.42.38

func ComponentWeightsFromSBOM(entries []SBOMEntry) map[string]int64

ComponentWeightsFromSBOM derives a per-component weight used to distribute revenue that is NOT explicitly tagged to a component. This is the "deployed images → SBOM components → contributors" mapping: each component the platform ships (an SBOM entry) earns a share of untagged revenue.

Preference order for the weight signal:

  1. UsageCount — real billing-period usage of the component (best signal)
  2. TotalLines — code-size proxy when usage hasn't been measured yet
  3. equal (1) — every shipped component shares equally as a last resort

The chosen signal is consistent across all entries: if ANY entry reports usage, usage is used for all; otherwise lines; otherwise equal.

func DistributeRevenue added in v1.42.38

func DistributeRevenue(amount int64, weights map[string]int64) map[string]int64

DistributeRevenue splits amount across components proportional to weights. Integer rounding remainder is assigned to the highest-weight component (ties broken by component name for determinism) so the distributed total exactly equals amount — no cents are created or lost.

func Query

func QuerySBOM

func QuerySBOM(db *datastore.Datastore) datastore.Query

Types

type Attribution

type Attribution struct {
	Component  string  `json:"component"`  // Package name (e.g., "@hanzo/ui")
	Repo       string  `json:"repo"`       // GitHub repo (e.g., "hanzoai/ui")
	Lines      int64   `json:"lines"`      // Lines of code authored
	TotalLines int64   `json:"totalLines"` // Total lines in component
	Percent    float64 `json:"percent"`    // Percentage of component authored
}

Attribution represents a contributor's share in a specific software component.

type Contributor

type Contributor struct {
	mixin.Model[Contributor]

	// Identity
	UserId    string `json:"userId,omitempty"`    // Hanzo user ID (if registered)
	GitLogin  string `json:"gitLogin"`            // GitHub/GitLab login
	GitEmail  string `json:"gitEmail"`            // Git commit email
	Name      string `json:"name"`                // Display name
	AvatarURL string `json:"avatarUrl,omitempty"` // Avatar URL

	// Organization (optional: attribute to org instead of individual)
	OrgId   string `json:"orgId,omitempty"`
	OrgName string `json:"orgName,omitempty"`

	// Payout config
	PayoutMethod string        `json:"payoutMethod"` // "stripe", "crypto", "credits"
	PayoutTarget string        `json:"payoutTarget"` // Stripe account ID, wallet address, or user ID
	Currency     currency.Type `json:"currency" orm:"default:usd"`

	// Stats (computed periodically by cron)
	TotalLinesAuthored int64          `json:"totalLinesAuthored"`
	TotalEarned        currency.Cents `json:"totalEarned"`
	TotalPending       currency.Cents `json:"totalPending"`

	// Status
	Verified bool      `json:"verified"` // Email/identity verified
	Active   bool      `json:"active"`   // Actively receiving payouts
	JoinedAt time.Time `json:"joinedAt"`
	LastPaid time.Time `json:"lastPaid,omitempty"`

	// On-chain payout receipt (PayoutMethod="crypto"): the hash and chain id
	// of the most recent HUSD transfer. Set by the contributor payout cron.
	LastPayoutTx      string `json:"lastPayoutTx,omitempty"`
	LastPayoutChainId int64  `json:"lastPayoutChainId,omitempty"`

	// SBOM attribution: JSON array of component attributions
	// [{"component":"@hanzo/ui","repo":"hanzoai/ui","lines":1234,"percent":5.2}]
	Attributions  []Attribution `json:"attributions,omitempty" datastore:"-"`
	Attributions_ string        `json:"-" datastore:",noindex"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

Contributor tracks an OSS contributor eligible for revenue share payouts. Contributors are identified by their git identity (email/login) and matched to SBOM line attribution for each software component used by bots, agents, and platform services.

func New

func (*Contributor) Load

func (c *Contributor) Load(ps []datastore.Property) (err error)

func (*Contributor) Save

func (c *Contributor) Save() (ps []datastore.Property, err error)

func (*Contributor) Validator

func (c *Contributor) Validator() *val.Validator

type PayoutAllocation

type PayoutAllocation struct {
	ContributorId string  `json:"contributorId"`
	GitLogin      string  `json:"gitLogin"`
	Component     string  `json:"component"`
	Lines         int64   `json:"lines"`
	Percent       float64 `json:"percent"`
	AmountCents   int64   `json:"amountCents"`
}

PayoutAllocation represents a single contributor's share of a revenue pool.

type PayoutConfig

type PayoutConfig struct {
	// PlatformPercent is the platform's share before contributor distribution.
	// Default: 75% platform, 25% to contributors.
	PlatformPercent float64

	// MinPayoutCents is the minimum payout threshold per contributor.
	// Below this, credits accumulate until threshold is reached.
	MinPayoutCents int64

	// ComponentWeights allows weighting certain components higher.
	// Key is component name, value is multiplier (1.0 = normal).
	// Core infrastructure might be weighted 2x, UI components 1x, etc.
	ComponentWeights map[string]float64
}

PayoutConfig controls the revenue sharing algorithm.

func DefaultConfig

func DefaultConfig() PayoutConfig

DefaultConfig returns the default payout configuration. 75/25 split: 75% to platform, 25% to OSS contributors.

type PayoutSummary

type PayoutSummary struct {
	TotalRevenue    int64              `json:"totalRevenue"`    // Total revenue to distribute (cents)
	PlatformShare   int64              `json:"platformShare"`   // Platform's cut (cents)
	ContributorPool int64              `json:"contributorPool"` // Pool for contributors (cents)
	Allocations     []PayoutAllocation `json:"allocations"`
}

PayoutSummary is the result of running the payout algorithm.

func CalculatePayouts

func CalculatePayouts(
	totalRevenueCents int64,
	contributors []Contributor,
	componentRevenue map[string]int64,
	config PayoutConfig,
) PayoutSummary

CalculatePayouts runs the OSS contributor revenue sharing algorithm.

Algorithm:

  1. Take total revenue for the period
  2. Deduct platform share (default 80%)
  3. Remaining 25% is the contributor pool
  4. For each software component used in the billing period: a. Weight the component's revenue contribution b. For each contributor to that component: - Calculate their line attribution percentage - Multiply by component's weighted revenue share
  5. Aggregate per-contributor across all components
  6. Apply minimum payout threshold
  7. Return sorted allocations (highest first)

type SBOMAuthor

type SBOMAuthor struct {
	Login   string  `json:"login"`
	Email   string  `json:"email"`
	Name    string  `json:"name,omitempty"`
	Lines   int64   `json:"lines"`
	Percent float64 `json:"percent"` // Percentage of component authored
}

SBOMAuthor is a contributor entry from git blame analysis.

type SBOMEntry

type SBOMEntry struct {
	mixin.Model[SBOMEntry]

	// Component identity
	Component  string `json:"component"`  // Package name (e.g., "@hanzo/bot")
	Repo       string `json:"repo"`       // GitHub repo (e.g., "hanzoai/bot")
	Version    string `json:"version"`    // Current version
	License    string `json:"license"`    // License type (MIT, Apache-2.0, etc.)
	TotalLines int64  `json:"totalLines"` // Total lines of code

	// Contributor breakdown from git blame
	// [{"login":"user","email":"u@e.com","lines":500,"percent":12.5}]
	Authors  []SBOMAuthor `json:"authors,omitempty" datastore:"-"`
	Authors_ string       `json:"-" datastore:",noindex"`

	// Revenue attribution
	UsageCount     int64   `json:"usageCount"`     // Times used in billing period
	RevenuePercent float64 `json:"revenuePercent"` // % of total platform revenue attributed

	// Scan metadata
	LastScanned time.Time `json:"lastScanned"`
	ScanCommit  string    `json:"scanCommit"` // Git commit hash of last scan

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

SBOMEntry represents a software component in the platform's bill of materials. Each entry tracks the component's identity, its contributors, and the revenue attributed to it based on bot/agent usage.

func NewSBOM

func NewSBOM(db *datastore.Datastore) *SBOMEntry

func (*SBOMEntry) Load

func (s *SBOMEntry) Load(ps []datastore.Property) (err error)

func (*SBOMEntry) Save

func (s *SBOMEntry) Save() (ps []datastore.Property, err error)

func (*SBOMEntry) Validator

func (s *SBOMEntry) Validator() *val.Validator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL