token_logic_module

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MintDistributionAllowableTolerancePercent is the percent difference that is allowable
	// between the number of minted/ tokens in the tokenomics module and what is distributed
	// to pocket network participants.
	// This internal constant SHOULD ONLY be used in TokenLogicModuleGlobalMint.
	// Due to floating point arithmetic, the total amount of minted coins may be slightly
	// larger than what is distributed to pocket network participants
	// TODO_MAINNET: Figure out if we can avoid this tolerance and use fixed point arithmetic.
	MintDistributionAllowableTolerancePercent = 0.02 // 2%
	// MintDistributionAllowableToleranceAbsolution is similar to MintDistributionAllowableTolerancePercent
	// but provides an absolute number where the % difference might no be
	// meaningful for small absolute numbers.
	// TODO_MAINNET: Figure out if we can avoid this tolerance and use fixed point arithmetic.
	MintDistributionAllowableToleranceAbs = 5.0 // 5 uPOKT
)

Variables

View Source
var (
	// TODO_BETA(@red-0ne, #732): Make this a governance parameter and give it a non-zero value + tests.
	// GlobalInflationPerClaim is the percentage of the claim amount that is minted
	// by TLMGlobalMint to reward the actors in the network.
	GlobalInflationPerClaim = 0.1
)

Functions

func CalculateGlobalPerClaimMintInflationFromSettlementAmount

func CalculateGlobalPerClaimMintInflationFromSettlementAmount(
	settlementCoin cosmostypes.Coin,
) (cosmostypes.Coin, big.Float)

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 uint64,
) (shareAmountMap map[string]uint64)

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 due to floating point arithmetic. NB: It is publically 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 IDs to the total number of relays claimed for that service in the combined results. IMPORTANT: **DO NOT** directly iterate over returned map in on-chain code to avoid the possibility of introducing non-determinism. Instead, iterate over the service ID slice returned by OR 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 holds all inputs and outputs necessary for token logic module processing, allowing TLMs to remain isolated from the tokenomics keeper and each other while still permitting 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 is an interface that all token logic modules are expected to implement. IMPORTANT_SIDE_EFFECTS: Please note that TLMs may update the application and supplier objects, which is why they are passed in as pointers. NOTE: TLMs CANNOT persist any state changes. Persistence of updated application and supplier to the keeper is currently done by the tokenomics keeper in `ProcessTokenLogicModules()`. This design and separation of concerns may change in the future. DEV_NOTE: As of writing this, this is only in anticipation of potentially unstaking actors if their stake falls below a certain threshold.

func NewDefaultTokenLogicModules

func NewDefaultTokenLogicModules() []TokenLogicModule

NewDefaultTokenLogicModules returns the default token logic module processors: - TLMRelayBurnEqualsMint - TLMGlobalMint

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 is the default value for TokenLogicModuleId, it is used as a field
	// type for objects which need to distinguish whether a TLM has handled it or not.
	UnspecifiedTLM TokenLogicModuleId = iota

	// TLMRelayBurnEqualsMint is the token logic module that burns the application's
	// stake balance based on the amount of work done by the supplier.
	// The same amount of tokens is minted and added to the supplier account balance.
	// When the network achieves maturity in the far future, this is theoretically
	// the only TLM that will be necessary.
	TLMRelayBurnEqualsMint

	// TLMGlobalMint is the token logic module that mints new tokens based on the
	// global governance parameters in order to reward the participants providing
	// services while keeping inflation in check.
	TLMGlobalMint

	// TLMGlobalMintReimbursementRequest is the token logic module that complements
	// TLMGlobalMint to enable permissionless demand.
	// In order to prevent self-dealing attacks, applications will be overcharged by
	// the amount equal to global inflation, those funds will be sent to the DAO/PNF,
	// and an event will be emitted to track and send reimbursements; managed offchain by PNF.
	// TODO_POST_MAINNET: Introduce proper tokenomics based on the research done 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