token_logic_module

package
v0.1.27-dev1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateGlobalPerClaimMintInflationFromSettlementAmount

func CalculateGlobalPerClaimMintInflationFromSettlementAmount(
	settlementCoin cosmostypes.Coin,
	globalInflationPerClaimRat *big.Rat,
) cosmostypes.Coin

CalculateGlobalPerClaimMintInflationFromSettlementAmount calculates the amount of uPOKT to mint based on the global per claim inflation rate as a function of the settlement amount for a particular claim(s) or session(s).

func GetShareAmountMap

func GetShareAmountMap(
	serviceRevShare []*sharedtypes.ServiceRevenueShare,
	amountToDistribute math.Int,
) (shareAmountMap map[string]math.Int)

GetShareAmountMap calculates the amount of uPOKT to distribute to each revenue shareholder based on the rev share percentage of the service. It returns a map of the shareholder address to the amount of uPOKT to distribute. The first shareholder gets any remainder resulting from the integer division. NB: It is publicly exposed to be used in the tests.

func NewClaimSettlementResult

func NewClaimSettlementResult(
	claim prooftypes.Claim,
	opts ...resultOption,
) *tokenomicstypes.ClaimSettlementResult

NewClaimSettlementResult returns a new ClaimSettlementResult with the given claim and options applied.

func ValidateTLMConfig

func ValidateTLMConfig(tokenLogicModules []TokenLogicModule) error

ValidateTLMConfig ensures that the global mint and global mint reimbursement request TLMs are activated or deactivated together.

func WithBurns

func WithBurns(burns []tokenomicstypes.MintBurnOp) resultOption

WithBurns returns a resultOption which sets the burns field of the ClaimSettlementResult.

func WithMints

func WithMints(mints []tokenomicstypes.MintBurnOp) resultOption

WithMints returns a resultOption which sets the mints field of the ClaimSettlementResult.

func WithModToAcctTransfers

func WithModToAcctTransfers(transfers []tokenomicstypes.ModToAcctTransfer) resultOption

WithModToAcctTransfers returns a resultOption which sets the modToAcctTransfers field of the ClaimSettlementResult.

func WithModToModTransfers

func WithModToModTransfers(transfers []tokenomicstypes.ModToModTransfer) resultOption

WithModToModTransfers returns a resultOption which sets the modToModTransfers field of the ClaimSettlementResult.

Types

type ClaimSettlementResults

type ClaimSettlementResults []*tokenomicstypes.ClaimSettlementResult

ClaimSettlementResults is a slice of ClaimSettlementResult. It implements methods for convenience when working with ClaimSettlementResult objects.

func (*ClaimSettlementResults) Append

Append appends a result to the results.

func (ClaimSettlementResults) GetApplicationAddrs

func (rs ClaimSettlementResults) GetApplicationAddrs() (appAddrs []string)

GetApplicationAddrs returns a slice of application addresses from the combined results' claims.

func (ClaimSettlementResults) GetNumClaims

func (rs ClaimSettlementResults) GetNumClaims() uint64

GetNumClaims returns the number of claims in the combined results.

func (ClaimSettlementResults) GetNumComputeUnits

func (rs ClaimSettlementResults) GetNumComputeUnits() (numComputeUnits uint64, errs error)

GetNumComputeUnits returns the total number of claimed compute units in the results.

func (ClaimSettlementResults) GetNumRelays

func (rs ClaimSettlementResults) GetNumRelays() (numRelays uint64, errs error)

GetNumRelays returns the total number of relays in the combined results.

func (ClaimSettlementResults) GetRelaysPerServiceMap

func (rs ClaimSettlementResults) GetRelaysPerServiceMap() (_ map[string]uint64, errs error)

GetRelaysPerServiceMap returns a map of {service_id -> total_num_relays_claimed_for_service} across all results. IMPORTANT: **DO NOT** directly iterate over returned map in onchain code. Iterating over the returned map can cause non-determinism. Instead, iterate over a sorted slice of the service ID keys.

func (ClaimSettlementResults) GetServiceIds

func (rs ClaimSettlementResults) GetServiceIds() (serviceIds []string)

GetServiceIds returns a slice of service IDs from the combined results' claims. It is intended to be used for deterministic iterating over the map returned from GetRelaysPerServiceMap via the serviceId key.

func (ClaimSettlementResults) GetSupplierOperatorAddrs

func (rs ClaimSettlementResults) GetSupplierOperatorAddrs() (supplierOperatorAddrs []string)

GetSupplierOperatorAddrs returns a slice of supplier addresses from the combined results' claims.

type TLMContext

type TLMContext struct {
	TokenomicsParams      tokenomicstypes.Params
	SettlementCoin        cosmostypes.Coin // This is the "actualSettlementCoin" rather than just the "claimCoin" because of how settlement functions; see ensureClaimAmountLimits for details.
	SessionHeader         *sessiontypes.SessionHeader
	Result                *tokenomicstypes.ClaimSettlementResult
	Service               *sharedtypes.Service
	Application           *apptypes.Application
	Supplier              *sharedtypes.Supplier
	RelayMiningDifficulty *servicetypes.RelayMiningDifficulty
}

TLMContext is responsible for processing & settling tokenomics for a given session. - Holds all inputs and outputs necessary for token logic module processing - Allows TLMs to remain isolated from the tokenomics keeper and each other - Permits shared memory access (prior to an atomic state transition)

type TokenLogicModule

type TokenLogicModule interface {
	GetId() TokenLogicModuleId
	// Process executes the token logic modules business logic given the input/output
	// parameters encapsulated by the TLMContext.
	// IT DOES NOT modify network state directly.
	Process(context.Context, cosmoslog.Logger, TLMContext) error
}

TokenLogicModule interface - All token logic modules must implement this interface

IMPORTANT_SIDE_EFFECTS: - TLMs may update the application and supplier objects (passed as pointers) - TLMs CANNOT persist any state changes - Persistence of updated application and supplier is handled by the tokenomics keeper in `ProcessTokenLogicModules()` - This design and separation of concerns may change in the future

DEV_NOTE: - As of writing, this anticipates potentially unstaking actors if their stake falls below a threshold

func NewDefaultTokenLogicModules

func NewDefaultTokenLogicModules() []TokenLogicModule

NewDefaultTokenLogicModules - Returns the default token logic module processors:

  • TLMRelayBurnEqualsMint
  • TLMGlobalMint
  • TLMGlobalMintReimbursementRequest

func NewGlobalMintReimbursementRequestTLM

func NewGlobalMintReimbursementRequestTLM() TokenLogicModule

NewGlobalMintReimbursementRequestTLM returns a new GlobalMintReimbursementRequest TLM.

func NewGlobalMintTLM

func NewGlobalMintTLM() TokenLogicModule

NewGlobalMintTLM creates a new instance of the GlobalMint TLM.

func NewRelayBurnEqualsMintTLM

func NewRelayBurnEqualsMintTLM() TokenLogicModule

NewRelayBurnEqualsMintTLM returns a new RelayBurnEqualsMint TLM.

type TokenLogicModuleId

type TokenLogicModuleId int
const (
	// UnspecifiedTLM
	// - Default value for TokenLogicModuleId
	// - Used as a field type for objects to distinguish if a TLM has handled it or not
	UnspecifiedTLM TokenLogicModuleId = iota

	// TLMRelayBurnEqualsMint
	// - Burns the application's stake balance based on the amount of work done by the supplier
	// - Mints the same amount of tokens and adds them to the supplier's account balance
	// - When the network matures, this is theoretically the only TLM needed
	TLMRelayBurnEqualsMint

	// TLMGlobalMint
	// - Mints new tokens based on global governance parameters
	// - Rewards participants providing services
	// - Keeps inflation in check
	TLMGlobalMint

	// TLMGlobalMintReimbursementRequest
	// - Complements TLMGlobalMint to enable permissionless demand
	// - Prevents self-dealing attacks:
	//   - Applications are overcharged by an amount equal to global inflation
	//   - Overcharged funds are sent to the DAO/PNF
	//   - Event emitted to track and send reimbursements (managed offchain by PNF)
	// - TODO_POST_MAINNET: Introduce proper tokenomics based on research by @rawthil and @shane
	TLMGlobalMintReimbursementRequest
)

func (TokenLogicModuleId) EnumIndex

func (tlm TokenLogicModuleId) EnumIndex() int

func (TokenLogicModuleId) String

func (tlm TokenLogicModuleId) String() string

Jump to

Keyboard shortcuts

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