Playground
counter.gno
package launchpad
// Counter manages unique incrementing IDs.
type Counter struct {
id int64
}
// NewCounter creates a new Counter starting at zero.
//
// Returns:
// - counter: counter initialized with current ID zero.
func NewCounter() *Counter {
return &Counter{
id: 0,
}
}
// Next increments the counter and returns the next unique ID.
//
// Returns:
// - id: incremented counter value.
func (c *Counter) Next() int64 {
c.id++
return c.id
}
// Get returns the current counter ID without incrementing it.
//
// Returns:
// - id: current counter value.
func (c *Counter) Get() int64 {
return c.id
}
deposit.gno
package launchpad
// Deposit represents a deposit made by a user in a launchpad project.
//
// This struct contains the necessary data and methods to manage and distribute
// rewards for a specific deposit.
//
// Fields:
// - depositor (std.Address): The address of the depositor.
// - id (string): The unique identifier for the deposit.
// - projectID (string): The ID of the project associated with the deposit.
// - tier (int64): The tier duration of the deposit (30, 90, or 180 days).
// - depositAmount (int64): The amount of the deposit.
// - withdrawnHeight (int64): The height at which the deposit was withdrawn.
// - withdrawnTime (int64): The Unix timestamp when the deposit was withdrawn.
// - createdHeight (int64): The block height at which the deposit was created.
// - createdAt (int64): The Unix timestamp when the deposit was created.
// - endTime (int64): The Unix timestamp when the deposit ends.
type Deposit struct {
depositor address
id string
projectID string
tier int64 // 30, 90, 180 // instead of tierId
depositAmount int64
withdrawnHeight int64
withdrawnTime int64
createdHeight int64
createdAt int64
endTime int64
}
// ID returns the unique identifier stored for the deposit.
//
// Returns:
// - id: deposit identifier used to retrieve this deposit from launchpad state.
func (d Deposit) ID() string {
return d.id
}
// SetID updates the unique identifier stored for the deposit.
//
// Parameters:
// - id: new identifier to associate with the deposit.
func (d *Deposit) SetID(id string) {
d.id = id
}
// ProjectID returns the identifier of the launchpad project associated with the deposit.
//
// Returns:
// - projectID: associated launchpad project identifier.
func (d Deposit) ProjectID() string {
return d.projectID
}
// SetProjectID updates the launchpad project identifier associated with the deposit.
//
// Parameters:
// - projectID: identifier of the launchpad project to associate with the deposit.
func (d *Deposit) SetProjectID(projectID string) {
d.projectID = projectID
}
// Tier returns the deposit's tier duration.
//
// Returns:
// - tier: tier duration in days; launchpad tiers use 30, 90, or 180.
func (d Deposit) Tier() int64 {
return d.tier
}
// SetTier updates the tier duration recorded for the deposit.
//
// Parameters:
// - tier: tier duration in days; valid launchpad tiers are 30, 90, or 180.
func (d *Deposit) SetTier(tier int64) {
d.tier = tier
}
// Depositor returns the address that made the deposit.
//
// Returns:
// - depositor: account address recorded as the deposit owner.
func (d Deposit) Depositor() address {
return d.depositor
}
// SetDepositor updates the account address recorded as the deposit owner.
//
// Parameters:
// - depositor: account address to record as the deposit owner.
func (d *Deposit) SetDepositor(depositor address) {
d.depositor = depositor
}
// DepositAmount returns the amount recorded for the deposit.
//
// Returns:
// - depositAmount: amount of GNS deposited for the associated project.
func (d Deposit) DepositAmount() int64 {
return d.depositAmount
}
// SetDepositAmount updates the amount recorded for the deposit.
//
// Parameters:
// - depositAmount: amount of GNS to record as deposited for the associated project.
func (d *Deposit) SetDepositAmount(depositAmount int64) {
d.depositAmount = depositAmount
}
// CreatedHeight returns the block height at which the deposit was created.
//
// Returns:
// - createdHeight: creation block height stored on the deposit.
func (d Deposit) CreatedHeight() int64 {
return d.createdHeight
}
// SetCreatedHeight updates the block height recorded for deposit creation.
//
// Parameters:
// - createdHeight: block height at which the deposit was created.
func (d *Deposit) SetCreatedHeight(createdHeight int64) {
d.createdHeight = createdHeight
}
// CreatedAt returns the Unix timestamp at which the deposit was created.
//
// Returns:
// - createdAt: creation timestamp in Unix seconds.
func (d Deposit) CreatedAt() int64 {
return d.createdAt
}
// SetCreatedAt updates the Unix timestamp recorded for deposit creation.
//
// Parameters:
// - createdAt: creation timestamp in Unix seconds.
func (d *Deposit) SetCreatedAt(createdAt int64) {
d.createdAt = createdAt
}
// WithdrawnTime returns the Unix timestamp recorded for withdrawal.
//
// Returns:
// - withdrawnTime: withdrawal timestamp in Unix seconds; zero before withdrawal is recorded.
func (d Deposit) WithdrawnTime() int64 {
return d.withdrawnTime
}
// SetWithdrawnTime updates the Unix timestamp recorded for withdrawal.
//
// Parameters:
// - withdrawnTime: withdrawal timestamp in Unix seconds.
func (d *Deposit) SetWithdrawnTime(withdrawnTime int64) {
d.withdrawnTime = withdrawnTime
}
// WithdrawnHeight returns the block height recorded for withdrawal.
//
// Returns:
// - withdrawnHeight: withdrawal block height; zero before withdrawal is recorded.
func (d Deposit) WithdrawnHeight() int64 {
return d.withdrawnHeight
}
// SetWithdrawnHeight updates the block height recorded for withdrawal.
//
// Parameters:
// - withdrawnHeight: block height at which the deposit was withdrawn.
func (d *Deposit) SetWithdrawnHeight(withdrawnHeight int64) {
d.withdrawnHeight = withdrawnHeight
}
// EndTime returns the Unix timestamp at which the deposit's tier ends.
//
// Returns:
// - endTime: tier end timestamp in Unix seconds.
func (d Deposit) EndTime() int64 {
return d.endTime
}
// SetEndTime updates the Unix timestamp at which the deposit's tier ends.
//
// Parameters:
// - endTime: tier end timestamp in Unix seconds.
func (d *Deposit) SetEndTime(endTime int64) {
d.endTime = endTime
}
// ProjectTierID returns the composite identifier for the deposit's project tier.
//
// Returns:
// - projectTierID: identifier formed from the project ID and tier duration.
func (d Deposit) ProjectTierID() string {
return MakeProjectTierID(d.projectID, d.tier)
}
// IsDepositor reports whether an address matches the deposit owner.
//
// Parameters:
// - address: account address to compare with the recorded depositor.
//
// Returns:
// - matches: true when the supplied address has the same string representation as the depositor; false otherwise.
func (d Deposit) IsDepositor(address address) bool {
return d.depositor.String() == address.String()
}
// IsEnded reports whether the deposit's tier end time is before the supplied time.
//
// Parameters:
// - currentTime: current Unix timestamp in seconds used for the end-time comparison.
//
// Returns:
// - ended: true when endTime is strictly less than currentTime; false at or before the end time.
func (d Deposit) IsEnded(currentTime int64) bool {
return d.endTime < currentTime
}
// IsWithdrawn reports whether both withdrawal markers have been recorded.
//
// Returns:
// - withdrawn: true when both withdrawnHeight and withdrawnTime are greater than zero; false when either marker is zero.
func (d Deposit) IsWithdrawn() bool {
return d.withdrawnTime > 0 && d.withdrawnHeight > 0
}
// SetWithdrawn records the block height and Unix timestamp of withdrawal.
//
// Parameters:
// - withdrawnHeight: block height at which the deposit was withdrawn.
// - withdrawnTime: withdrawal timestamp in Unix seconds.
func (d *Deposit) SetWithdrawn(withdrawnHeight int64, withdrawnTime int64) {
d.withdrawnHeight = withdrawnHeight
d.withdrawnTime = withdrawnTime
}
// MakeDeposit returns a new Deposit value with the given values.
//
// Parameters:
// - depositID: unique identifier to assign to the new deposit.
// - projectID: launchpad project identifier associated with the deposit.
// - tier: tier duration in days; launchpad tiers use 30, 90, or 180.
// - depositor: account address making the deposit.
// - depositAmount: amount of GNS deposited for the project.
// - createdHeight: block height at which the deposit was created.
// - createdTime: creation timestamp in Unix seconds.
// - endTime: tier end timestamp in Unix seconds.
//
// Returns:
// - deposit: new Deposit populated with the supplied fields and zero withdrawal markers.
func MakeDeposit(
depositID string,
projectID string,
tier int64,
depositor address,
depositAmount int64,
createdHeight int64,
createdTime int64,
endTime int64,
) Deposit {
return Deposit{
id: depositID,
projectID: projectID,
tier: tier,
depositor: depositor,
depositAmount: depositAmount,
withdrawnHeight: 0,
createdHeight: createdHeight,
createdAt: createdTime,
endTime: endTime,
}
}
// DefaultDeposit returns the zero Deposit value.
//
// Returns:
// - deposit: zero-valued Deposit with no identifier, amounts, timestamps, or withdrawal markers.
func DefaultDeposit() Deposit {
return Deposit{}
}
doc.gno
package launchpad
errors.gno
package launchpad const ErrSpoofedRealm = "rlm does not match the current crossing frame"
getter.gno
package launchpad
import (
u256 "gno.land/p/gnoswap/uint256/v1"
rotree "gno.land/p/nt/bptree/rotree/v0"
)
// GetProjects returns a read-only view of every project, keyed by project ID.
// Callers paginate it themselves through IterateByOffset. Reading an entry
// yields a clone, so the view cannot mutate realm state.
//
// Returns:
// - projects: read-only tree keyed by project ID; reading an entry yields a clone.
func GetProjects() *rotree.ReadOnlyTree {
return getImplementation().GetProjects()
}
// GetProjectName returns the name of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - name: stored project name.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectName(projectId string) (string, error) {
return getImplementation().GetProjectName(projectId)
}
// GetProjectTokenPath returns the token path of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - tokenPath: reward-token contract path configured for the project.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectTokenPath(projectId string) (string, error) {
return getImplementation().GetProjectTokenPath(projectId)
}
// GetProjectDepositAmount returns the deposit amount of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - amount: project-token amount initially allocated to the project, in token base units.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectDepositAmount(projectId string) (int64, error) {
return getImplementation().GetProjectDepositAmount(projectId)
}
// GetProjectRecipient returns the recipient address of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - recipient: address configured to receive the project's launchpad proceeds.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectRecipient(projectId string) (address, error) {
return getImplementation().GetProjectRecipient(projectId)
}
// GetProjectCondition retrieves a specific condition of a project.
// Returns a cloned condition to prevent external modification.
//
// Parameters:
// - projectId: unique identifier of the project containing the condition.
// - tokenPath: token contract path used as the condition key.
//
// Returns:
// - condition: cloned condition for the requested token; nil when the implementation returns no condition without an error.
// - err: non-nil when the project or condition cannot be found.
func GetProjectCondition(projectId string, tokenPath string) (*ProjectCondition, error) {
condition, err := getImplementation().GetProjectCondition(projectId, tokenPath)
if err != nil {
return nil, err
}
if condition == nil {
return nil, nil
}
return condition.Clone(), nil
}
// GetProjectTiersRatios returns the tiers ratios map of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - tiersRatios: cloned map from tier duration to its allocation ratio.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectTiersRatios(projectId string) (map[int64]int64, error) {
tiersRatios, err := getImplementation().GetProjectTiersRatios(projectId)
if err != nil {
return nil, err
}
return cloneInt64Map(tiersRatios), nil
}
// GetProjectCreatedHeight returns the created height of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - height: block height at which the project was created.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectCreatedHeight(projectId string) (int64, error) {
return getImplementation().GetProjectCreatedHeight(projectId)
}
// GetProjectCreatedAt returns the created time of a project by its ID.
//
// Parameters:
// - projectId: unique identifier of the launchpad project to inspect.
//
// Returns:
// - createdAt: Unix timestamp in seconds at which the project was created.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectCreatedAt(projectId string) (int64, error) {
return getImplementation().GetProjectCreatedAt(projectId)
}
// GetProjectTier retrieves a specific tier of a project.
// Returns a cloned tier to prevent external modification.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - projectTier: cloned project tier; nil when the implementation supplies no tier without an error.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTier(projectId string, tier int64) (*ProjectTier, error) {
projectTier, err := getImplementation().GetProjectTier(projectId, tier)
if err != nil {
return nil, err
}
if projectTier == nil {
return nil, nil
}
return projectTier.Clone(), nil
}
// GetProjectTierDistributeAmountPerSecondX128 returns the distribute amount per second (Q128) of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - amountPerSecondX128: project-token distribution rate per second in Q128 fixed-point units; nil when no value is available.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierDistributeAmountPerSecondX128(projectId string, tier int64) (*u256.Uint, error) {
amount, err := getImplementation().GetProjectTierDistributeAmountPerSecondX128(projectId, tier)
if err != nil {
return nil, err
}
if amount == nil {
return nil, nil
}
return amount.Clone(), nil
}
// GetProjectTierTotalDistributeAmount returns the total distribute amount of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - amount: total project-token allocation for the tier, in token base units.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierTotalDistributeAmount(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierTotalDistributeAmount(projectId, tier)
}
// GetProjectTierTotalDepositAmount returns the total deposit amount of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - amount: cumulative GNS principal deposited into the tier, in base units.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierTotalDepositAmount(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierTotalDepositAmount(projectId, tier)
}
// GetProjectTierTotalWithdrawAmount returns the total withdraw amount of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - amount: cumulative GNS principal withdrawn from the tier, in base units.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierTotalWithdrawAmount(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierTotalWithdrawAmount(projectId, tier)
}
// GetProjectTierTotalDepositCount returns the total deposit count of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - count: cumulative number of deposits created in the tier.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierTotalDepositCount(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierTotalDepositCount(projectId, tier)
}
// GetProjectTierTotalWithdrawCount returns the total withdraw count of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - count: cumulative number of withdrawals completed in the tier.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierTotalWithdrawCount(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierTotalWithdrawCount(projectId, tier)
}
// GetProjectTierTotalCollectedAmount returns the total collected amount of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - amount: cumulative project-token reward collected from the tier, in token base units.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierTotalCollectedAmount(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierTotalCollectedAmount(projectId, tier)
}
// GetProjectTierStartTime returns the start time of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - startTime: tier start timestamp in Unix seconds.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierStartTime(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierStartTime(projectId, tier)
}
// GetProjectTierEndTime returns the end time of a project tier.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - endTime: tier end timestamp in Unix seconds.
// - err: non-nil when the project or tier cannot be found.
func GetProjectTierEndTime(projectId string, tier int64) (int64, error) {
return getImplementation().GetProjectTierEndTime(projectId, tier)
}
// GetDepositCount returns the total number of deposits.
//
// Returns:
// - count: number of deposit records currently stored.
func GetDepositCount() int {
return getImplementation().GetDepositCount()
}
// GetCurrentDepositId returns the current deposit counter value.
//
// Returns:
// - depositId: current deposit counter value; it is not incremented by this read.
func GetCurrentDepositId() int64 {
return getImplementation().GetCurrentDepositId()
}
// GetProjectTierRewards returns a read-only view of a project tier's reward
// states, keyed by deposit ID. Reading an entry yields a clone, so the view
// cannot mutate realm state. nil is returned when the project tier does not
// exist.
//
// Parameters:
// - projectId: unique identifier of the project containing the tier.
// - tier: tier duration key, such as 30, 90, or 180.
//
// Returns:
// - rewards: read-only tree of reward states keyed by deposit ID; nil when the tier's reward manager is unavailable.
func GetProjectTierRewards(projectId string, tier int64) *rotree.ReadOnlyTree {
return getImplementation().GetProjectTierRewards(projectId, tier)
}
// GetDeposit retrieves a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - deposit: stored deposit value.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDeposit(depositId string) (Deposit, error) {
return getImplementation().GetDeposit(depositId)
}
// GetDepositProjectID returns the project ID of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - projectId: project identifier associated with the deposit.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositProjectID(depositId string) (string, error) {
return getImplementation().GetDepositProjectID(depositId)
}
// GetDepositTier returns the tier of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - tier: tier duration key selected by the deposit.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositTier(depositId string) (int64, error) {
return getImplementation().GetDepositTier(depositId)
}
// GetDepositProjectTierID returns the project tier ID of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - projectTierId: composite project-tier identifier derived from the deposit's project and tier.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositProjectTierID(depositId string) (string, error) {
return getImplementation().GetDepositProjectTierID(depositId)
}
// GetDepositAmount returns the deposit amount of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - amount: GNS principal deposited, in base units.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositAmount(depositId string) (int64, error) {
return getImplementation().GetDepositAmount(depositId)
}
// GetDepositWithdrawnHeight returns the withdrawn height of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - height: withdrawal block height; zero when the deposit has not been withdrawn.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositWithdrawnHeight(depositId string) (int64, error) {
return getImplementation().GetDepositWithdrawnHeight(depositId)
}
// GetDepositWithdrawnTime returns the withdrawn time of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - withdrawnAt: withdrawal Unix timestamp in seconds; zero when the deposit has not been withdrawn.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositWithdrawnTime(depositId string) (int64, error) {
return getImplementation().GetDepositWithdrawnTime(depositId)
}
// GetDepositCreatedHeight returns the created height of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - height: creation block height of the deposit.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositCreatedHeight(depositId string) (int64, error) {
return getImplementation().GetDepositCreatedHeight(depositId)
}
// GetDepositCreatedAt returns the created time of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - createdAt: deposit creation Unix timestamp in seconds.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositCreatedAt(depositId string) (int64, error) {
return getImplementation().GetDepositCreatedAt(depositId)
}
// GetDepositEndTime returns the end time of a deposit by its ID.
//
// Parameters:
// - depositId: unique identifier of the deposit to inspect.
//
// Returns:
// - endTime: deposit lock/end Unix timestamp in seconds.
// - err: non-nil when depositId does not identify a stored deposit.
func GetDepositEndTime(depositId string) (int64, error) {
return getImplementation().GetDepositEndTime(depositId)
}
// GetTotalGNSStakedAmount returns the total amount of GNS currently staked across all launchpad deposits.
//
// Returns:
// - amount: total GNS principal currently staked across launchpad deposits, in base units.
func GetTotalGNSStakedAmount() int64 {
return getImplementation().GetTotalGNSStakedAmount()
}
// GetProjectTierRewardManagerCount returns the total number of reward managers.
//
// Returns:
// - count: number of project-tier reward managers currently stored.
func GetProjectTierRewardManagerCount() int {
return getImplementation().GetProjectTierRewardManagerCount()
}
// GetProjectTierRewardManager retrieves a reward manager by project tier ID.
// Returns a cloned reward manager to prevent external modification.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - rewardManager: cloned reward manager; nil when the implementation supplies no manager without an error.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardManager(projectTierId string) (*RewardManager, error) {
rewardManager, err := getImplementation().GetProjectTierRewardManager(projectTierId)
if err != nil {
return nil, err
}
if rewardManager == nil {
return nil, nil
}
return rewardManager.Clone(), nil
}
// GetProjectTierRewardDistributeAmountPerSecondX128 returns the distribute amount per second (Q128) of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - amountPerSecondX128: reward distribution rate per second in Q128 fixed-point token units; nil when no value is available.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardDistributeAmountPerSecondX128(projectTierId string) (*u256.Uint, error) {
amount, err := getImplementation().GetProjectTierRewardDistributeAmountPerSecondX128(projectTierId)
if err != nil {
return nil, err
}
if amount == nil {
return nil, nil
}
return amount.Clone(), nil
}
// GetProjectTierRewardAccumulatedRewardPerDepositX128 returns the accumulated reward per deposit (Q128) of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - accumulatedRewardPerDepositX128: accumulated reward index per deposited GNS unit in Q128 fixed-point units; nil when no value is available.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardAccumulatedRewardPerDepositX128(projectTierId string) (*u256.Uint, error) {
amount, err := getImplementation().GetProjectTierRewardAccumulatedRewardPerDepositX128(projectTierId)
if err != nil {
return nil, err
}
if amount == nil {
return nil, nil
}
return amount.Clone(), nil
}
// GetProjectTierRewardTotalDistributeAmount returns the total distribute amount of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - amount: total reward allocation managed for the project tier, in token base units.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardTotalDistributeAmount(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardTotalDistributeAmount(projectTierId)
}
// GetProjectTierRewardTotalClaimedAmount returns the total claimed amount of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - amount: total reward amount claimed from the manager, in token base units.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardTotalClaimedAmount(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardTotalClaimedAmount(projectTierId)
}
// GetProjectTierRewardDistributeStartTime returns the distribute start time of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - startTime: reward distribution start timestamp in Unix seconds.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardDistributeStartTime(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardDistributeStartTime(projectTierId)
}
// GetProjectTierRewardDistributeEndTime returns the distribute end time of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - endTime: reward distribution end timestamp in Unix seconds.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardDistributeEndTime(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardDistributeEndTime(projectTierId)
}
// GetProjectTierRewardAccumulatedDistributeAmount returns a legacy reward-manager field.
// The v1 reward paths do not maintain it, so normal reads return zero unless it
// was explicitly set.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - amount: legacy accumulated distribution amount in token base units; v1 accounting normally leaves it at zero unless explicitly set.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardAccumulatedDistributeAmount(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardAccumulatedDistributeAmount(projectTierId)
}
// GetProjectTierRewardAccumulatedTime returns the accumulated time of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - time: last reward-accumulation timestamp in Unix seconds, or zero before accumulation.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardAccumulatedTime(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardAccumulatedTime(projectTierId)
}
// GetProjectTierRewardClaimableDuration returns the reward claimable duration of a reward manager.
//
// Parameters:
// - projectTierId: composite project-tier identifier whose manager is requested.
//
// Returns:
// - duration: reward claimable window in seconds.
// - err: non-nil when projectTierId does not identify a stored reward manager.
func GetProjectTierRewardClaimableDuration(projectTierId string) (int64, error) {
return getImplementation().GetProjectTierRewardClaimableDuration(projectTierId)
}
// GetRewardState retrieves a reward state by project tier ID and deposit ID.
// Returns a cloned reward state to prevent external modification.
//
// Parameters:
// - projectTierId: composite project-tier identifier containing the reward state.
// - depositId: deposit identifier whose reward state is requested.
//
// Returns:
// - rewardState: cloned reward state; nil when the implementation supplies no state without an error.
// - err: non-nil when the reward manager or reward state cannot be found.
func GetRewardState(projectTierId string, depositId string) (*RewardState, error) {
rewardState, err := getImplementation().GetRewardState(projectTierId, depositId)
if err != nil {
return nil, err
}
if rewardState == nil {
return nil, nil
}
return rewardState.Clone(), nil
}
// GetProjectActiveStatus returns whether a project is currently active.
//
// Parameters:
// - projectId: unique identifier of the project to inspect.
//
// Returns:
// - active: true when the project is active at the current Unix time; false when it is inactive.
// - err: non-nil when projectId does not identify a stored project.
func GetProjectActiveStatus(projectId string) (bool, error) {
return getImplementation().GetProjectActiveStatus(projectId)
}
getter_utils.gno
package launchpad
func cloneInt64Map(src map[int64]int64) map[int64]int64 {
if src == nil {
return nil
}
dst := make(map[int64]int64, len(src))
for key, value := range src {
dst[key] = value
}
return dst
}
gnomod.toml
module = "gno.land/r/gnoswap/launchpad" gno = "0.9" [addpkg] creator = "g1q5tjjv3kkslzwf2na9y9wk7e5a8ugph8xfsk04" height = 557776 max_deposit = "100000000ugnot"
project.gno
package launchpad
import (
ufmt "gno.land/p/nt/ufmt/v0"
)
// Project represents a launchpad project.
//
// This struct contains the necessary data and methods to manage and distribute
// rewards for a specific project.
//
// Fields:
// - id (string): The unique identifier for the project, formatted as "{tokenPath}:{createdHeight}".
// - name (string): The name of the project.
// - tokenPath (string): The path of the token associated with the project.
// - depositAmount (int64): The total amount of tokens deposited for the project.
// - recipient (address): The address to receive the project's rewards.
// - conditions (map[string]*ProjectCondition): A map of token paths to their associated conditions.
// - tiers (map[int64]*ProjectTier): A map of tier durations to their associated tiers.
// - tiersRatios (map[int64]int64): A map of tier durations to their associated ratios.
// - createdHeight (int64): The block height at which the project was created.
// - createdAt (int64): The Unix timestamp at which the project was created.
type Project struct {
id string // 'tokenPath:createdHeight'
name string
tokenPath string
depositAmount int64
recipient address // string
conditions map[string]*ProjectCondition // tokenPath -> Condition
tiers map[int64]*ProjectTier
tiersRatios map[int64]int64
createdHeight int64
createdAt int64
}
// ID returns the project identifier in "{tokenPath}:{createdHeight}" form.
//
// Returns:
// - id: unique identifier assigned to this project.
func (p *Project) ID() string {
return p.id
}
// SetID replaces the project's identifier.
//
// Parameters:
// - id: project identifier to store, normally in "{tokenPath}:{createdHeight}" form.
func (p *Project) SetID(id string) {
p.id = id
}
// Name returns the project's human-readable name.
//
// Returns:
// - name: stored project name.
func (p *Project) Name() string {
return p.name
}
// SetName replaces the project's human-readable name.
//
// Parameters:
// - name: project name to store.
func (p *Project) SetName(name string) {
p.name = name
}
// TokenPath returns the token path whose tokens are distributed as project rewards.
//
// Returns:
// - tokenPath: configured project reward-token path.
func (p *Project) TokenPath() string {
return p.tokenPath
}
// SetTokenPath replaces the project's reward-token path.
//
// Parameters:
// - tokenPath: token path to store as the project's reward token.
func (p *Project) SetTokenPath(tokenPath string) {
p.tokenPath = tokenPath
}
// DepositAmount returns the total reward-token allocation configured for the project.
//
// Returns:
// - amount: project reward-token allocation.
func (p *Project) DepositAmount() int64 {
return p.depositAmount
}
// SetDepositAmount replaces the project's total reward-token allocation.
//
// Parameters:
// - amount: total reward-token amount allocated to the project.
func (p *Project) SetDepositAmount(amount int64) {
p.depositAmount = amount
}
// Recipient returns the address authorized to receive the project's rewards.
//
// Returns:
// - recipient: configured project recipient address.
func (p *Project) Recipient() address {
return p.recipient
}
// SetRecipient replaces the address authorized to receive project rewards.
//
// Parameters:
// - recipient: address to store as the project recipient.
func (p *Project) SetRecipient(recipient address) {
p.recipient = recipient
}
// Conditions returns a copy of the project's token deposit conditions.
//
// Returns:
// - conditions: map from token path to cloned condition values; mutations do not alter project state.
func (p *Project) Conditions() map[string]*ProjectCondition {
conditions := make(map[string]*ProjectCondition)
for tokenPath, condition := range p.conditions {
conditions[tokenPath] = condition.Clone()
}
return conditions
}
// SetConditions replaces the project's token deposit conditions.
// The map and its entries are retained in the project realm for later mutation.
//
// Parameters:
// - conditions: map from required token path to its deposit condition.
func (p *Project) SetConditions(conditions map[string]*ProjectCondition) {
owned := make(map[string]*ProjectCondition, len(conditions))
for tokenPath, condition := range conditions {
owned[tokenPath] = condition
}
p.conditions = owned
}
// SetCondition replaces one token-path deposit condition in the project-owned map.
//
// Parameters:
// - tokenPath: token path whose condition is replaced.
// - condition: required balance condition for that token path.
func (p *Project) SetCondition(tokenPath string, condition *ProjectCondition) {
p.conditions[tokenPath] = condition
}
// Tiers returns a copy of the project's configured duration-to-tier map.
//
// Returns:
// - tiers: map from tier duration in seconds to cloned tier values.
func (p *Project) Tiers() map[int64]*ProjectTier {
tiers := make(map[int64]*ProjectTier)
for duration, tier := range p.tiers {
tiers[duration] = tier.Clone()
}
return tiers
}
// SetTiers replaces the project's tier map with a project-owned map.
//
// Parameters:
// - tiers: map from tier duration in seconds to its tier configuration.
func (p *Project) SetTiers(tiers map[int64]*ProjectTier) {
owned := make(map[int64]*ProjectTier, len(tiers))
for duration, tier := range tiers {
owned[duration] = tier
}
p.tiers = owned
}
// TiersRatios returns reward allocation ratios keyed by tier duration.
//
// Returns:
// - ratios: map from tier duration in seconds to its allocation ratio.
func (p *Project) TiersRatios() map[int64]int64 {
return p.tiersRatios
}
// SetTiersRatios replaces the project's tier allocation ratios.
//
// Parameters:
// - tiersRatios: map from tier duration in seconds to its reward allocation ratio.
func (p *Project) SetTiersRatios(tiersRatios map[int64]int64) {
p.tiersRatios = tiersRatios
}
// CreatedHeight returns the block height at which the project was created.
//
// Returns:
// - height: project creation block height.
func (p *Project) CreatedHeight() int64 {
return p.createdHeight
}
// SetCreatedHeight replaces the project's creation block height.
//
// Parameters:
// - height: block height to store as the project creation height.
func (p *Project) SetCreatedHeight(height int64) {
p.createdHeight = height
}
// CreatedAt returns the Unix timestamp at which the project was created.
//
// Returns:
// - time: project creation Unix timestamp.
func (p *Project) CreatedAt() int64 {
return p.createdAt
}
// SetCreatedAt replaces the project's creation timestamp.
//
// Parameters:
// - time: Unix timestamp to store as the project creation time.
func (p *Project) SetCreatedAt(time int64) {
p.createdAt = time
}
// GetTier returns a copy of the project's tier for one duration.
//
// Parameters:
// - duration: tier duration in seconds.
//
// Returns:
// - tier: cloned tier configuration for the duration, or nil when absent.
// - err: non-nil when no tier is configured for duration.
func (p *Project) GetTier(duration int64) (*ProjectTier, error) {
tier, exists := p.tiers[duration]
if !exists {
return nil, ufmt.Errorf("tier(%d) not found", duration)
}
return tier.Clone(), nil
}
// SetTier replaces one duration entry in the project-owned tier map.
//
// Parameters:
// - duration: tier duration in seconds used as the map key.
// - tier: tier configuration to store for duration.
func (p *Project) SetTier(duration int64, tier *ProjectTier) {
p.tiers[duration] = tier
}
// IsRecipient reports whether recipient matches the project's configured recipient address.
//
// Parameters:
// - recipient: address to compare with the configured project recipient.
//
// Returns:
// - matches: true when recipient is the configured project recipient.
func (p *Project) IsRecipient(recipient address) bool {
return p.recipient == recipient
}
// NewProject creates a project with empty conditions, tiers, and tier-ratio maps.
//
// Parameters:
// - name: human-readable project name.
// - tokenPath: token path whose tokens are distributed as project rewards.
// - depositAmount: total reward-token amount allocated to the project.
// - recipient: address authorized to receive project rewards.
// - createdHeight: block height at which the project is created.
// - createdAt: Unix timestamp at which the project is created.
//
// Returns:
// - project: initialized project with an ID derived from tokenPath and createdHeight.
func NewProject(
name string,
tokenPath string,
depositAmount int64,
recipient address,
createdHeight int64,
createdAt int64,
) *Project {
return &Project{
id: MakeProjectID(tokenPath, createdHeight),
name: name,
tokenPath: tokenPath,
depositAmount: depositAmount,
recipient: recipient,
conditions: make(map[string]*ProjectCondition),
tiers: make(map[int64]*ProjectTier),
tiersRatios: make(map[int64]int64),
createdHeight: createdHeight,
createdAt: createdAt,
}
}
// Clone returns a deep-enough copy of the project for independent map and nested
// condition/tier mutation; scalar fields are copied directly.
//
// Returns:
// - clone: project copy with independently allocated condition, tier, and ratio maps.
func (p Project) Clone() *Project {
conditions := make(map[string]*ProjectCondition)
for k, v := range p.conditions {
conditions[k] = v.Clone()
}
tiers := make(map[int64]*ProjectTier)
for k, v := range p.tiers {
tiers[k] = v.Clone()
}
tiersRatios := make(map[int64]int64)
for k, v := range p.tiersRatios {
tiersRatios[k] = v
}
return &Project{
id: p.id,
name: p.name,
tokenPath: p.tokenPath,
depositAmount: p.depositAmount,
recipient: p.recipient,
conditions: conditions,
tiers: tiers,
tiersRatios: tiersRatios,
createdHeight: p.createdHeight,
createdAt: p.createdAt,
}
}
// MakeProjectID combines a token path and creation height into a project identifier.
//
// Parameters:
// - tokenPath: token path associated with the project.
// - createdHeight: block height at which the project was created.
//
// Returns:
// - projectID: identifier in "{tokenPath}:{createdHeight}" form.
func MakeProjectID(tokenPath string, createdHeight int64) string {
return ufmt.Sprintf("%s:%d", tokenPath, createdHeight)
}
project_condition.gno
package launchpad
import (
"strconv"
"strings"
ufmt "gno.land/p/nt/ufmt/v0"
)
const stringSplitterPad = "*PAD*"
// ProjectCondition represents a condition for a project.
//
// This struct contains the necessary data and methods to manage and distribute
// rewards for a specific project.
//
// Fields:
// - tokenPath (string): The path of the token associated with the project.
// - minimumAmount (int64): The minimum amount of the token required for the project.
type ProjectCondition struct {
tokenPath string
minimumAmount int64
}
// TokenPath returns the token contract path required by this condition.
//
// Returns:
// - tokenPath: configured condition token path; an empty string means no token is configured.
func (p *ProjectCondition) TokenPath() string {
return p.tokenPath
}
// MinimumAmount returns the minimum balance amount required by this condition.
//
// Returns:
// - minimumAmount: minimum amount in the token's base units; values at or below zero make the condition unavailable.
func (p *ProjectCondition) MinimumAmount() int64 {
return p.minimumAmount
}
// IsAvailable reports whether this condition has a non-empty token path and a positive minimum amount.
//
// Returns:
// - available: true when both the token path and minimum amount are valid; false otherwise.
func (p *ProjectCondition) IsAvailable() bool {
return p.tokenPath != "" && p.minimumAmount > 0
}
// CheckBalanceCondition validates an input token balance against this condition.
//
// Parameters:
// - inputTokenPath: token path whose balance is being checked; it must equal the condition token path.
// - inputAmount: input token balance in base units; it must be at least the configured minimum.
//
// Returns:
// - err: nil when the token path and amount satisfy the condition; non-nil describing a mismatch otherwise.
func (p *ProjectCondition) CheckBalanceCondition(inputTokenPath string, inputAmount int64) error {
if p.tokenPath != inputTokenPath {
return ufmt.Errorf("token path(%s) is not matched", inputTokenPath)
}
if inputAmount < p.minimumAmount {
return ufmt.Errorf("input amount(%d) is less than minimum amount(%d)", inputAmount, p.minimumAmount)
}
return nil
}
// Clone returns an independent copy of this project condition.
//
// Returns:
// - condition: copied token path and minimum amount in a new ProjectCondition value.
func (p ProjectCondition) Clone() *ProjectCondition {
return &ProjectCondition{
tokenPath: p.tokenPath,
minimumAmount: p.minimumAmount,
}
}
// NewProjectCondition creates a project condition for a token path and minimum amount.
//
// Parameters:
// - tokenPath: token contract path whose balance is required.
// - minimumAmount: minimum balance in the token's base units.
//
// Returns:
// - condition: newly allocated project condition containing the supplied values.
func NewProjectCondition(tokenPath string, minimumAmount int64) *ProjectCondition {
return &ProjectCondition{
tokenPath: tokenPath,
minimumAmount: minimumAmount,
}
}
// NewProjectConditionsWithError parses parallel *PAD*-separated token paths and minimum amounts.
//
// Parameters:
// - conditionTokens: *PAD*-separated token contract paths, in condition order.
// - conditionAmounts: *PAD*-separated decimal int64 minimum amounts paired by index with conditionTokens; entries beyond the token list are not consumed.
//
// Returns:
// - conditions: parsed available conditions in the same order as their token paths; empty when both inputs are empty.
// - err: nil on successful parsing; non-nil when a token lacks a matching amount, an amount is not a valid int64, or a condition is unavailable.
func NewProjectConditionsWithError(conditionTokens string, conditionAmounts string) ([]*ProjectCondition, error) {
if conditionTokens == "" && conditionAmounts == "" {
return []*ProjectCondition{}, nil
}
conditions := []*ProjectCondition{}
tokenPaths := strings.Split(conditionTokens, stringSplitterPad)
minimumAmounts := strings.Split(conditionAmounts, stringSplitterPad)
for index, tokenPath := range tokenPaths {
if index >= len(minimumAmounts) {
return nil, ufmt.Errorf("condition amount(%s) is not matched with condition token(%s)", conditionAmounts, conditionTokens)
}
minimumAmount, err := strconv.ParseInt(minimumAmounts[index], 10, 64)
if err != nil {
return nil, ufmt.Errorf("condition amount(%s) is not a valid integer", minimumAmounts[index])
}
condition := NewProjectCondition(tokenPath, minimumAmount)
if !condition.IsAvailable() {
return nil, ufmt.Errorf("condition(%s) is not available", condition.TokenPath())
}
conditions = append(conditions, condition)
}
return conditions, nil
}
project_tier.gno
package launchpad
import (
ufmt "gno.land/p/nt/ufmt/v0"
u256 "gno.land/p/gnoswap/uint256/v1"
)
// ProjectTier represents a tier within a project.
//
// This struct contains the necessary data and methods to manage and distribute
// rewards for a specific tier of a project.
//
// Fields:
// - distributeAmountPerSecondX128 (u256.Uint): The amount of tokens to be distributed per second, represented as a Q128 fixed-point number.
// - startTime (int64): The time for the start of the tier.
// - endTime (int64): The time for the end of the tier.
// - id (string): The unique identifier for the tier, formatted as "{projectID}:duration".
// - totalDistributeAmount (int64): The total amount of tokens to be distributed for the tier.
// - totalDepositAmount (int64): The total amount of tokens deposited for the tier.
// - totalWithdrawAmount (int64): The total amount of tokens withdrawn from the tier.
// - totalDepositCount (int64): The total number of deposits made to the tier.
// - totalWithdrawCount (int64): The total number of withdrawals from the tier.
// - totalCollectedAmount (int64): The total amount of tokens collected as rewards for the tier.
type ProjectTier struct {
distributeAmountPerSecondX128 *u256.Uint // distribute amount per second, Q128
id string // '{projectId}:duration' // duration == 30, 90, 180
totalDistributeAmount int64
totalDepositAmount int64 // accumulated deposit amount
totalWithdrawAmount int64 // accumulated withdraw amount
totalDepositCount int64 // accumulated deposit count
totalWithdrawCount int64 // accumulated withdraw count
totalCollectedAmount int64 // total collected amount by user (reward)
startTime int64
endTime int64
}
// DistributeAmountPerSecondX128 returns the distribute amount per second (Q128) of the project tier.
//
// Returns:
// - amount: per-second distribution rate encoded as a Q128 fixed-point value.
func (pt *ProjectTier) DistributeAmountPerSecondX128() *u256.Uint {
return pt.distributeAmountPerSecondX128
}
// SetDistributeAmountPerSecondX128 sets the distribute amount per second (Q128) of the project tier.
//
// Parameters:
// - amount: per-second distribution rate to store, encoded as a Q128 fixed-point value.
func (pt *ProjectTier) SetDistributeAmountPerSecondX128(amount *u256.Uint) {
pt.distributeAmountPerSecondX128 = u256.Zero().Set(amount)
}
// ID returns the ID of the project tier.
//
// Returns:
// - id: tier identifier in the "{projectID}:{duration}" form.
func (pt *ProjectTier) ID() string {
return pt.id
}
// SetID sets the ID of the project tier.
//
// Parameters:
// - id: tier identifier to store, normally "{projectID}:{duration}".
func (pt *ProjectTier) SetID(id string) {
pt.id = id
}
// TotalDistributeAmount returns the total distribute amount of the project tier.
//
// Returns:
// - amount: total token amount allocated for distribution by this tier.
func (pt *ProjectTier) TotalDistributeAmount() int64 {
return pt.totalDistributeAmount
}
// SetTotalDistributeAmount sets the total distribute amount of the project tier.
//
// Parameters:
// - amount: total token amount allocated for distribution by this tier.
func (pt *ProjectTier) SetTotalDistributeAmount(amount int64) {
pt.totalDistributeAmount = amount
}
// TotalDepositAmount returns the total deposit amount of the project tier.
//
// Returns:
// - amount: aggregate token amount deposited into this tier.
func (pt *ProjectTier) TotalDepositAmount() int64 {
return pt.totalDepositAmount
}
// SetTotalDepositAmount sets the total deposit amount of the project tier.
//
// Parameters:
// - amount: aggregate token amount to record as deposited into this tier.
func (pt *ProjectTier) SetTotalDepositAmount(amount int64) {
pt.totalDepositAmount = amount
}
// TotalWithdrawAmount returns the total withdraw amount of the project tier.
//
// Returns:
// - amount: aggregate token amount withdrawn from this tier.
func (pt *ProjectTier) TotalWithdrawAmount() int64 {
return pt.totalWithdrawAmount
}
// SetTotalWithdrawAmount sets the total withdraw amount of the project tier.
//
// Parameters:
// - amount: aggregate token amount to record as withdrawn from this tier.
func (pt *ProjectTier) SetTotalWithdrawAmount(amount int64) {
pt.totalWithdrawAmount = amount
}
// TotalDepositCount returns the total deposit count of the project tier.
//
// Returns:
// - count: number of deposits recorded for this tier.
func (pt *ProjectTier) TotalDepositCount() int64 {
return pt.totalDepositCount
}
// SetTotalDepositCount sets the total deposit count of the project tier.
//
// Parameters:
// - count: number of deposits to record for this tier.
func (pt *ProjectTier) SetTotalDepositCount(count int64) {
pt.totalDepositCount = count
}
// TotalWithdrawCount returns the total withdraw count of the project tier.
//
// Returns:
// - count: number of withdrawals recorded for this tier.
func (pt *ProjectTier) TotalWithdrawCount() int64 {
return pt.totalWithdrawCount
}
// SetTotalWithdrawCount sets the total withdraw count of the project tier.
//
// Parameters:
// - count: number of withdrawals to record for this tier.
func (pt *ProjectTier) SetTotalWithdrawCount(count int64) {
pt.totalWithdrawCount = count
}
// TotalCollectedAmount returns the total collected amount of the project tier.
//
// Returns:
// - amount: aggregate reward amount collected from this tier.
func (pt *ProjectTier) TotalCollectedAmount() int64 {
return pt.totalCollectedAmount
}
// SetTotalCollectedAmount sets the total collected amount of the project tier.
//
// Parameters:
// - amount: aggregate reward amount to record as collected from this tier.
func (pt *ProjectTier) SetTotalCollectedAmount(amount int64) {
pt.totalCollectedAmount = amount
}
// StartTime returns the start time of the project tier.
//
// Returns:
// - time: tier start timestamp in Unix seconds.
func (pt *ProjectTier) StartTime() int64 {
return pt.startTime
}
// SetStartTime sets the start time of the project tier.
//
// Parameters:
// - time: tier start timestamp in Unix seconds.
func (pt *ProjectTier) SetStartTime(time int64) {
pt.startTime = time
}
// EndTime returns the end time of the project tier.
//
// Returns:
// - time: tier end timestamp in Unix seconds.
func (pt *ProjectTier) EndTime() int64 {
return pt.endTime
}
// SetEndTime sets the end time of the project tier.
//
// Parameters:
// - time: tier end timestamp in Unix seconds.
func (pt *ProjectTier) SetEndTime(time int64) {
pt.endTime = time
}
// IsActivated reports whether the tier is active at the supplied timestamp.
//
// Parameters:
// - currentTime: timestamp in Unix seconds to compare with the tier window.
//
// Returns:
// - activated: true when startTime <= currentTime and currentTime < endTime; false otherwise.
func (pt *ProjectTier) IsActivated(currentTime int64) bool {
return pt.startTime <= currentTime && currentTime < pt.endTime
}
// IsEnded returns true if the project tier has ended.
//
// Parameters:
// - currentTime: timestamp in Unix seconds to compare with the tier end time.
//
// Returns:
// - ended: true when endTime is strictly less than currentTime; false at or before the end time.
func (pt *ProjectTier) IsEnded(currentTime int64) bool {
return pt.endTime < currentTime
}
// Clone returns an independent copy of the project tier, including a cloned
// Q128 distribution-rate value and all aggregate counters.
//
// Returns:
// - clone: copy whose mutable fixed-point value is independent of the receiver.
func (pt ProjectTier) Clone() *ProjectTier {
return &ProjectTier{
id: pt.id,
totalDistributeAmount: pt.totalDistributeAmount,
distributeAmountPerSecondX128: pt.distributeAmountPerSecondX128.Clone(),
startTime: pt.startTime,
endTime: pt.endTime,
totalDepositAmount: pt.totalDepositAmount,
totalWithdrawAmount: pt.totalWithdrawAmount,
totalDepositCount: pt.totalDepositCount,
totalWithdrawCount: pt.totalWithdrawCount,
totalCollectedAmount: pt.totalCollectedAmount,
}
}
// NewProjectTier returns a pointer to a new ProjectTier with the given values.
//
// Parameters:
// - projectID: launchpad project identifier associated with the tier.
// - tierDuration: tier duration in days; launchpad tiers use 30, 90, or 180.
// - totalDistributeAmount: total token amount allocated for this tier.
// - startTime: tier start timestamp in Unix seconds.
// - endTime: tier end timestamp in Unix seconds.
//
// Returns:
// - tier: new ProjectTier with the supplied identity, allocation, and time window; counters and rates start at zero.
func NewProjectTier(
projectID string,
tierDuration int64,
totalDistributeAmount int64,
startTime int64,
endTime int64,
) *ProjectTier {
return &ProjectTier{
id: MakeProjectTierID(projectID, tierDuration),
totalDistributeAmount: totalDistributeAmount,
distributeAmountPerSecondX128: u256.Zero(),
startTime: startTime,
endTime: endTime,
totalDepositAmount: 0,
totalWithdrawAmount: 0,
totalDepositCount: 0,
totalWithdrawCount: 0,
totalCollectedAmount: 0,
}
}
// MakeProjectTierID constructs the tier identifier from a project ID and duration.
// The resulting identifier uses the "{projectID}:{duration}" format.
//
// Parameters:
// - projectID: unique launchpad project identifier associated with the tier.
// - duration: tier duration in days, such as 30, 90, or 180.
//
// Returns:
// - projectTierID: identifier combining projectID and duration with a colon.
func MakeProjectTierID(projectID string, duration int64) string {
return ufmt.Sprintf("%s:%d", projectID, duration)
}
proxy.gno
package launchpad
// CreateProject creates a new launchpad project callable by the administrator or governance.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - name: human-readable project name.
// - tokenPath: token path whose tokens are distributed as project rewards.
// - recipient: address authorized to receive project rewards and project proceeds.
// - depositAmount: total reward-token amount allocated to the project.
// - conditionTokens: optional `*PAD*`-separated token paths required for deposits.
// - conditionAmounts: optional `*PAD*`-separated required amounts matching conditionTokens.
// - tier30Ratio: reward allocation ratio for the 30-day tier.
// - tier90Ratio: reward allocation ratio for the 90-day tier.
// - tier180Ratio: reward allocation ratio for the 180-day tier.
// - startTime: Unix timestamp at which project reward distribution starts.
//
// Returns:
// - projectId: identifier assigned to the newly created project.
//
// Halt check: reverts while the Launchpad halt scope is active.
func CreateProject(
cur realm,
name string,
tokenPath string,
recipient address,
depositAmount int64,
conditionTokens string,
conditionAmounts string,
tier30Ratio int64,
tier90Ratio int64,
tier180Ratio int64,
startTime int64,
) string {
return getImplementation().CreateProject(
0,
cur,
name,
tokenPath,
recipient,
depositAmount,
conditionTokens,
conditionAmounts,
tier30Ratio,
tier90Ratio,
tier180Ratio,
startTime,
)
}
// CollectProtocolFee collects protocol-fee rewards allocated to project recipients.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
//
// Halt check: reverts while the Withdraw halt scope is active.
func CollectProtocolFee(cur realm) {
getImplementation().CollectProtocolFee(0, cur)
}
// CollectEmissionReward collects accumulated launchpad emission rewards.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
//
// Halt check: reverts while the Withdraw halt scope is active.
func CollectEmissionReward(cur realm) {
getImplementation().CollectEmissionReward(0, cur)
}
// CollectProtocolFeeReward collects accumulated launchpad protocol-fee rewards for a token path.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - tokenPath: token path whose accumulated protocol-fee reward is collected.
//
// Halt check: reverts while the Withdraw halt scope is active.
func CollectProtocolFeeReward(cur realm, tokenPath string) {
getImplementation().CollectProtocolFeeReward(0, cur, tokenPath)
}
// TransferLeftFromProjectByAdmin transfers unreserved reward tokens from an ended project.
// Active depositor claims remain reserved and are excluded; only the administrator may call it.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - projectID: identifier of the ended project whose remaining balance is transferred.
// - recipient: destination address for the transferable balance.
//
// Returns:
// - amount: number of reward tokens transferred after active claims are reserved.
//
// Halt check: reverts while the Launchpad halt scope is active.
func TransferLeftFromProjectByAdmin(cur realm, projectID string, recipient address) int64 {
return getImplementation().TransferLeftFromProjectByAdmin(0, cur, projectID, recipient)
}
// DepositGns deposits GNS into a selected launchpad project tier.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - targetProjectTierID: project-tier identifier in `{projectID}:{tierDuration}` form.
// - depositAmount: amount of GNS to stake in the selected tier.
// - referrer: optional referral address associated with the deposit.
//
// Returns:
// - depositId: identifier assigned to the newly created deposit.
//
// Halt check: reverts while the Launchpad halt scope is active.
func DepositGns(cur realm, targetProjectTierID string, depositAmount int64, referrer string) string {
return getImplementation().DepositGns(0, cur, targetProjectTierID, depositAmount, referrer)
}
// CollectDepositGns withdraws the GNS amount recorded by a deposit.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - depositID: identifier of the deposit whose GNS is collected.
//
// Returns:
// - amount: GNS amount withdrawn from the deposit.
// - err: non-nil when the deposit cannot be collected.
//
// Halt check: reverts while the Withdraw halt scope is active.
func CollectDepositGns(cur realm, depositID string) (int64, error) {
return getImplementation().CollectDepositGns(0, cur, depositID)
}
// CollectRewardByDepositId collects the project-token reward earned by a deposit.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - depositID: identifier of the deposit whose reward is collected.
//
// Returns:
// - amount: project-token reward amount transferred to the depositor.
//
// Halt check: reverts while the Withdraw halt scope is active.
func CollectRewardByDepositId(cur realm, depositID string) int64 {
return getImplementation().CollectRewardByDepositId(0, cur, depositID)
}
render.gno
package launchpad
// Render delegates web rendering to the active implementation.
func Render(path string) string {
return getImplementation().Render(path)
}
reward_manager.gno
package launchpad
import (
bptree "gno.land/p/nt/bptree/v0"
u256 "gno.land/p/gnoswap/uint256/v1"
)
// RewardManager manages the distribution of rewards for a project tier.
//
// This struct contains the necessary data and methods to calculate and track
// rewards for deposits associated with a project tier.
//
// Fields:
// - rewards (bptree.BPTree): A map of deposit IDs to their associated reward states.
// - distributeAmountPerSecondX128 (u256.Uint): The amount of tokens to be distributed per second, represented as a Q128 fixed-point number.
// - accumulatedRewardPerDepositX128 (u256.Uint): The accumulated reward per GNS stake, represented as a Q128 fixed-point number.
// - totalDistributeAmount (int64): The total token allocation for this tier.
// - totalClaimedAmount (int64): The total amount of tokens claimed.
// - distributeStartTime (int64): The start time of the reward calculation.
// - distributeEndTime (int64): The end time of the reward calculation.
// - accumulatedDistributeAmount (int64): A legacy field not maintained by v1 reward accounting; normally zero unless explicitly set.
// - rewardClaimableDuration (int64): The duration of reward claimable.
type RewardManager struct {
rewards *bptree.BPTree // depositId -> RewardState
distributeAmountPerSecondX128 *u256.Uint // distribute amount per second, Q128
accumulatedRewardPerDepositX128 *u256.Uint // accumulated reward per GNS stake, Q128
totalDistributeAmount int64 // total token allocation for this tier
totalClaimedAmount int64 // total claimed amount
activeDepositAmount int64 // principal represented by active reward states
activeClaimedAmount int64 // claims paid to active reward states
distributeStartTime int64 // start time of reward calculation
distributeEndTime int64 // end time of reward calculation
accumulatedDistributeAmount int64 // legacy field; v1 reward paths do not update it
accumulatedTime int64 // last time when reward was calculated
rewardClaimableDuration int64 // duration of reward claimable
activePriceDebtX128 *u256.Uint // sum of active deposit amount × initial reward index
}
// Rewards returns the rewards tree of the reward manager.
//
// Returns:
// - rewards: reward-state tree keyed by deposit ID.
func (rm *RewardManager) Rewards() *bptree.BPTree {
return rm.rewards
}
// SetRewards sets the rewards tree of the reward manager.
//
// Parameters:
// - rewards: reward-state tree to use for this manager.
func (rm *RewardManager) SetRewards(rewards *bptree.BPTree) {
rm.rewards = rewards
}
// SetReward associates a reward state with a deposit ID in the manager's reward tree.
//
// Parameters:
// - depositID: deposit identifier used as the reward-tree key.
// - rewardState: reward state to store for that deposit.
func (rm *RewardManager) SetReward(depositID string, rewardState *RewardState) {
rm.rewards.Set(depositID, rewardState)
}
// RemoveReward removes the reward state associated with a deposit ID.
//
// Parameters:
// - depositID: deposit identifier whose reward state is removed.
func (rm *RewardManager) RemoveReward(depositID string) {
rm.rewards.Remove(depositID)
}
// DistributeAmountPerSecondX128 returns the distribute amount per second (Q128) of the reward manager.
//
// Returns:
// - amountPerSecondX128: reward distribution rate in Q128 fixed-point token units per second.
func (rm *RewardManager) DistributeAmountPerSecondX128() *u256.Uint {
return rm.distributeAmountPerSecondX128
}
// SetDistributeAmountPerSecondX128 sets the distribute amount per second (Q128) of the reward manager.
//
// Parameters:
// - amount: replacement reward distribution rate in Q128 fixed-point token units per second; the value is copied.
func (rm *RewardManager) SetDistributeAmountPerSecondX128(amount *u256.Uint) {
rm.distributeAmountPerSecondX128 = u256.Zero().Set(amount)
}
// AccumulatedRewardPerDepositX128 returns the accumulated reward per deposit (Q128) of the reward manager.
//
// Returns:
// - accumulatedRewardPerDepositX128: accumulated reward index per deposited GNS unit in Q128 fixed-point units.
func (rm *RewardManager) AccumulatedRewardPerDepositX128() *u256.Uint {
return rm.accumulatedRewardPerDepositX128
}
// SetAccumulatedRewardPerDepositX128 sets the accumulated reward per deposit (Q128) of the reward manager.
//
// Parameters:
// - amount: replacement accumulated reward-per-deposit index in Q128 fixed-point units; the value is copied.
func (rm *RewardManager) SetAccumulatedRewardPerDepositX128(amount *u256.Uint) {
rm.accumulatedRewardPerDepositX128 = u256.Zero().Set(amount)
}
// TotalDistributeAmount returns the total distribute amount of the reward manager.
//
// Returns:
// - amount: total reward allocation for the tier in token base units.
func (rm *RewardManager) TotalDistributeAmount() int64 {
return rm.totalDistributeAmount
}
// SetTotalDistributeAmount sets the total distribute amount of the reward manager.
//
// Parameters:
// - amount: total reward allocation for the tier in token base units.
func (rm *RewardManager) SetTotalDistributeAmount(amount int64) {
rm.totalDistributeAmount = amount
}
// TotalClaimedAmount returns the total claimed amount of the reward manager.
//
// Returns:
// - amount: total reward amount claimed from the tier in token base units.
func (rm *RewardManager) TotalClaimedAmount() int64 {
return rm.totalClaimedAmount
}
// SetTotalClaimedAmount sets the total claimed amount of the reward manager.
//
// Parameters:
// - amount: total claimed reward amount in token base units.
func (rm *RewardManager) SetTotalClaimedAmount(amount int64) {
rm.totalClaimedAmount = amount
}
// ActiveDepositAmount returns the principal represented by currently active reward states.
//
// Returns:
// - amount: active deposited GNS principal in base units.
func (rm *RewardManager) ActiveDepositAmount() int64 {
return rm.activeDepositAmount
}
// SetActiveDepositAmount replaces the principal represented by currently active reward states.
//
// Parameters:
// - amount: active deposited GNS principal in base units.
func (rm *RewardManager) SetActiveDepositAmount(amount int64) {
rm.activeDepositAmount = amount
}
// ActiveClaimedAmount returns the reward amount claimed by currently active reward states.
//
// Returns:
// - amount: active claimed reward amount in token base units.
func (rm *RewardManager) ActiveClaimedAmount() int64 {
return rm.activeClaimedAmount
}
// SetActiveClaimedAmount replaces the reward amount claimed by currently active reward states.
//
// Parameters:
// - amount: active claimed reward amount in token base units.
func (rm *RewardManager) SetActiveClaimedAmount(amount int64) {
rm.activeClaimedAmount = amount
}
// ActivePriceDebtX128 returns the sum of active deposits' initial reward-index debts.
//
// Returns:
// - debt: aggregate active price debt in Q128 fixed-point units.
func (rm *RewardManager) ActivePriceDebtX128() *u256.Uint {
return rm.activePriceDebtX128
}
// SetActivePriceDebtX128 replaces the aggregate active price-index debt.
//
// Parameters:
// - debt: aggregate active price debt in Q128 fixed-point units; the value is copied.
func (rm *RewardManager) SetActivePriceDebtX128(debt *u256.Uint) {
rm.activePriceDebtX128 = u256.Zero().Set(debt)
}
// DistributeStartTime returns the distribute start time of the reward manager.
//
// Returns:
// - startTime: reward distribution start timestamp in Unix seconds.
func (rm *RewardManager) DistributeStartTime() int64 {
return rm.distributeStartTime
}
// SetDistributeStartTime sets the distribute start time of the reward manager.
//
// Parameters:
// - time: reward distribution start timestamp in Unix seconds.
func (rm *RewardManager) SetDistributeStartTime(time int64) {
rm.distributeStartTime = time
}
// DistributeEndTime returns the distribute end time of the reward manager.
//
// Returns:
// - endTime: reward distribution end timestamp in Unix seconds.
func (rm *RewardManager) DistributeEndTime() int64 {
return rm.distributeEndTime
}
// SetDistributeEndTime sets the distribute end time of the reward manager.
//
// Parameters:
// - time: reward distribution end timestamp in Unix seconds.
func (rm *RewardManager) SetDistributeEndTime(time int64) {
rm.distributeEndTime = time
}
// AccumulatedDistributeAmount returns the legacy reward-manager field.
// v1 reward paths do not maintain it, so normal reads return zero unless it was
// explicitly set.
//
// Returns:
// - amount: legacy accumulated distribution amount in token base units; v1 accounting normally leaves it at zero unless explicitly set.
func (rm *RewardManager) AccumulatedDistributeAmount() int64 {
return rm.accumulatedDistributeAmount
}
// SetAccumulatedDistributeAmount sets the legacy reward-manager field. It is not
// used by v1 reward accounting.
//
// Parameters:
// - amount: legacy accumulated distribution amount in token base units; v1 accounting does not update this field.
func (rm *RewardManager) SetAccumulatedDistributeAmount(amount int64) {
rm.accumulatedDistributeAmount = amount
}
// AccumulatedTime returns the accumulated time of the reward manager.
//
// Returns:
// - time: last reward-accumulation timestamp in Unix seconds, or zero before accumulation.
func (rm *RewardManager) AccumulatedTime() int64 {
return rm.accumulatedTime
}
// SetAccumulatedTime sets the accumulated time of the reward manager.
//
// Parameters:
// - time: last reward-accumulation timestamp in Unix seconds.
func (rm *RewardManager) SetAccumulatedTime(time int64) {
rm.accumulatedTime = time
}
// RewardClaimableDuration returns the reward claimable duration of the reward manager.
//
// Returns:
// - duration: time after a reward becomes claimable during which it remains collectible, in seconds.
func (rm *RewardManager) RewardClaimableDuration() int64 {
return rm.rewardClaimableDuration
}
// SetRewardClaimableDuration sets the reward claimable duration of the reward manager.
//
// Parameters:
// - duration: claimable reward window in seconds.
func (rm *RewardManager) SetRewardClaimableDuration(duration int64) {
rm.rewardClaimableDuration = duration
}
// Clone returns an independent copy of the reward manager, including its reward states and Q128 values.
//
// Returns:
// - rewardManager: deep copy with a separate reward tree and mutable numeric values.
func (rm RewardManager) Clone() *RewardManager {
rewardsTree := bptree.NewBPTreeN(16)
rm.rewards.Iterate("", "", func(key string, value interface{}) bool {
rewardState, ok := value.(*RewardState)
if !ok {
return true
}
rewardsTree.Set(key, rewardState.Clone())
return false
})
return &RewardManager{
rewards: rewardsTree,
distributeAmountPerSecondX128: rm.distributeAmountPerSecondX128.Clone(),
accumulatedRewardPerDepositX128: rm.accumulatedRewardPerDepositX128.Clone(),
totalDistributeAmount: rm.totalDistributeAmount,
totalClaimedAmount: rm.totalClaimedAmount,
activeDepositAmount: rm.activeDepositAmount,
activeClaimedAmount: rm.activeClaimedAmount,
distributeStartTime: rm.distributeStartTime,
distributeEndTime: rm.distributeEndTime,
accumulatedDistributeAmount: rm.accumulatedDistributeAmount,
accumulatedTime: rm.accumulatedTime,
rewardClaimableDuration: rm.rewardClaimableDuration,
activePriceDebtX128: rm.activePriceDebtX128.Clone(),
}
}
// NewRewardManager returns a pointer to a new RewardManager with the given values.
//
// Parameters:
// - totalDistributeAmount: total reward allocation for the tier in token base units.
// - distributeStartTime: reward distribution start timestamp in Unix seconds.
// - distributeEndTime: reward distribution end timestamp in Unix seconds.
// - rewardCollectableDuration: duration in seconds for which each accrued reward remains claimable.
//
// Returns:
// - rewardManager: initialized manager with zeroed accounting counters and an empty reward tree.
func NewRewardManager(
totalDistributeAmount int64,
distributeStartTime int64,
distributeEndTime int64,
rewardCollectableDuration int64,
) *RewardManager {
return &RewardManager{
totalDistributeAmount: totalDistributeAmount,
distributeStartTime: distributeStartTime,
distributeEndTime: distributeEndTime,
totalClaimedAmount: 0,
activeDepositAmount: 0,
activeClaimedAmount: 0,
accumulatedDistributeAmount: 0,
accumulatedTime: 0,
accumulatedRewardPerDepositX128: u256.Zero(),
distributeAmountPerSecondX128: u256.Zero(),
rewardClaimableDuration: rewardCollectableDuration,
activePriceDebtX128: u256.Zero(),
rewards: bptree.NewBPTreeN(16),
}
}
reward_state.gno
package launchpad
import (
u256 "gno.land/p/gnoswap/uint256/v1"
)
// RewardState represents the state of a reward for a deposit.
// It contains the necessary data to manage and distribute rewards for a specific deposit.
type RewardState struct {
priceDebtX128 *u256.Uint // price debt per GNS stake, Q128
claimableTime int64 // time when reward can be claimed
depositAmount int64 // amount of GNS staked
distributeStartTime int64 // time when launchpad started staking
distributeEndTime int64 // end time of reward calculation
accumulatedRewardAmount int64 // legacy field; v1 reward accounting does not populate it
accumulatedTime int64 // last time when reward was calculated
claimedAmount int64 // amount of reward claimed so far
}
// NewRewardState creates a reward state initialized from a reward-per-deposit index.
//
// Parameters:
// - accumulatedRewardPerDepositX128: current accumulated reward-per-deposit index in Q128 fixed-point units; it becomes this deposit's initial price debt.
// - depositAmount: GNS amount staked by the deposit, in base units.
// - distributeStartTime: Unix timestamp in seconds when this deposit begins accruing rewards.
// - distributeEndTime: Unix timestamp in seconds when this deposit stops accruing rewards.
// - claimableTime: Unix timestamp in seconds after which the accrued reward can be claimed.
//
// Returns:
// - rewardState: newly allocated state with claimed and legacy accumulation fields initialized to zero.
func NewRewardState(
accumulatedRewardPerDepositX128 *u256.Uint,
depositAmount,
distributeStartTime,
distributeEndTime int64,
claimableTime int64,
) *RewardState {
return &RewardState{
priceDebtX128: accumulatedRewardPerDepositX128,
depositAmount: depositAmount,
distributeStartTime: distributeStartTime,
distributeEndTime: distributeEndTime,
claimableTime: claimableTime,
accumulatedRewardAmount: 0,
claimedAmount: 0,
}
}
// PriceDebtX128 returns the deposit's initial reward index debt in Q128 fixed-point units.
//
// Returns:
// - debt: stored price debt used to subtract rewards accrued before this deposit joined.
func (rs *RewardState) PriceDebtX128() *u256.Uint {
return rs.priceDebtX128
}
// SetPriceDebtX128 replaces the deposit's initial reward index debt.
//
// Parameters:
// - debt: new price debt in Q128 fixed-point units; the value is copied into the state.
func (rs *RewardState) SetPriceDebtX128(debt *u256.Uint) {
rs.priceDebtX128 = u256.Zero().Set(debt)
}
// ClaimableTime returns the earliest Unix timestamp at which this reward may be claimed.
//
// Returns:
// - claimableTime: claimability timestamp in Unix seconds.
func (rs *RewardState) ClaimableTime() int64 {
return rs.claimableTime
}
// SetClaimableTime sets the earliest Unix timestamp at which this reward may be claimed.
//
// Parameters:
// - time: claimability timestamp in Unix seconds.
func (rs *RewardState) SetClaimableTime(time int64) {
rs.claimableTime = time
}
// DepositAmount returns the GNS principal represented by this reward state.
//
// Returns:
// - amount: staked GNS amount in base units used for reward allocation.
func (rs *RewardState) DepositAmount() int64 {
return rs.depositAmount
}
// SetDepositAmount replaces the GNS principal represented by this reward state.
//
// Parameters:
// - amount: staked GNS amount in base units used for reward allocation.
func (rs *RewardState) SetDepositAmount(amount int64) {
rs.depositAmount = amount
}
// DistributeStartTime returns the Unix timestamp when this deposit starts accruing rewards.
//
// Returns:
// - startTime: reward accrual start timestamp in Unix seconds.
func (rs *RewardState) DistributeStartTime() int64 {
return rs.distributeStartTime
}
// SetDistributeStartTime sets the Unix timestamp when this deposit starts accruing rewards.
//
// Parameters:
// - time: reward accrual start timestamp in Unix seconds.
func (rs *RewardState) SetDistributeStartTime(time int64) {
rs.distributeStartTime = time
}
// DistributeEndTime returns the Unix timestamp when this deposit stops accruing rewards.
//
// Returns:
// - endTime: reward accrual end timestamp in Unix seconds.
func (rs *RewardState) DistributeEndTime() int64 {
return rs.distributeEndTime
}
// SetDistributeEndTime sets the Unix timestamp when this deposit stops accruing rewards.
//
// Parameters:
// - time: reward accrual end timestamp in Unix seconds.
func (rs *RewardState) SetDistributeEndTime(time int64) {
rs.distributeEndTime = time
}
// AccumulatedRewardAmount returns the legacy accumulated reward field.
//
// Returns:
// - amount: legacy reward amount in token base units; v1 accounting normally leaves it at zero unless explicitly set.
func (rs *RewardState) AccumulatedRewardAmount() int64 {
return rs.accumulatedRewardAmount
}
// SetAccumulatedRewardAmount sets the legacy accumulated reward field.
//
// Parameters:
// - amount: legacy reward amount in token base units; v1 accounting does not update this field.
func (rs *RewardState) SetAccumulatedRewardAmount(amount int64) {
rs.accumulatedRewardAmount = amount
}
// AccumulatedTime returns the last timestamp recorded for reward accumulation.
//
// Returns:
// - time: last accumulated timestamp in Unix seconds, or zero before one is recorded.
func (rs *RewardState) AccumulatedTime() int64 {
return rs.accumulatedTime
}
// SetAccumulatedTime sets the last timestamp recorded for reward accumulation.
//
// Parameters:
// - time: last accumulated timestamp in Unix seconds.
func (rs *RewardState) SetAccumulatedTime(time int64) {
rs.accumulatedTime = time
}
// ClaimedAmount returns the reward amount already claimed for this deposit.
//
// Returns:
// - amount: claimed reward amount in token base units.
func (rs *RewardState) ClaimedAmount() int64 {
return rs.claimedAmount
}
// SetClaimedAmount replaces the reward amount already claimed for this deposit.
//
// Parameters:
// - amount: claimed reward amount in token base units.
func (rs *RewardState) SetClaimedAmount(amount int64) {
rs.claimedAmount = amount
}
// Clone returns an independent copy of this reward state, including a cloned Q128 price debt value.
//
// Returns:
// - rewardState: deep copy of the reward state that can be modified without changing the source.
func (rs RewardState) Clone() *RewardState {
return &RewardState{
priceDebtX128: rs.priceDebtX128.Clone(),
claimableTime: rs.claimableTime,
depositAmount: rs.depositAmount,
distributeStartTime: rs.distributeStartTime,
distributeEndTime: rs.distributeEndTime,
accumulatedRewardAmount: rs.accumulatedRewardAmount,
accumulatedTime: rs.accumulatedTime,
claimedAmount: rs.claimedAmount,
}
}
state.gno
package launchpad
import (
"errors"
_ "gno.land/r/gnoswap/rbac/v1" // initialize readable contract role(s)
"gno.land/p/gnoswap/store/v1"
"gno.land/p/gnoswap/version_manager/v1"
)
var (
kvStore store.KVStore
versionManager version_manager.VersionManager
implementation ILaunchpad
)
func init(cur realm) {
// Create a new KV store instance for this domain
kvStore = store.NewKVStore(cur.Address())
// Initialize the initializers map to store implementation registration functions
versionManager = version_manager.NewVersionManager(
cur.PkgPath(),
kvStore,
initializeDomainStore,
)
implementation = nil
}
func initializeDomainStore(_ int, rlm realm, kvStore store.KVStore) any {
return NewLaunchpadStore(kvStore)
}
func getImplementation() ILaunchpad {
if implementation == nil {
panic("implementation is not initialized")
}
return implementation
}
func updateImplementation() error {
result := versionManager.GetCurrentImplementation()
if result == nil {
return errors.New("implementation is not initialized")
}
impl, ok := result.(ILaunchpad)
if !ok {
return errors.New("impl is not an ILaunchpad")
}
implementation = impl
return nil
}
store.gno
package launchpad
import (
"errors"
"strconv"
"gno.land/p/gnoswap/store/v1"
bptree "gno.land/p/nt/bptree/v0"
ufmt "gno.land/p/nt/ufmt/v0"
)
// NewBPTreeN allocates a BP-tree under /r/gnoswap/launchpad's realm context
// (the realm that declares Project/Deposit/RewardManager). The tree's PkgID is
// therefore /r/gnoswap/launchpad, matching the domain values it stores, so
// tree.Set leaf-slot writes clear the readonly-taint gate regardless of which
// realm (launchpad/v1, mock, tests) calls Set. Implementations, mocks, and
// tests must allocate launchpad trees through here rather than calling
// bptree.NewBPTreeN directly in their own realm.
//
// Parameters:
// - fanout: branching factor passed to the BP-tree constructor.
//
// Returns:
// - tree: new BP-tree allocated under the launchpad realm's package context.
func NewBPTreeN(fanout int) *bptree.BPTree {
return bptree.NewBPTreeN(fanout)
}
type StoreKey string
// String returns the textual key represented by this StoreKey.
//
// Returns:
// - key: store key string used by the KV store.
func (s StoreKey) String() string {
return string(s)
}
const (
StoreKeyProjects StoreKey = "projects" // Projects tree
StoreKeyProjectRecipients StoreKey = "projectRecipients" // Recipient membership tree
StoreKeyProjectTierRewardManagers StoreKey = "projectTierRewardManagers" // Project tier reward managers tree
StoreKeyDepositCounter StoreKey = "depositCounter" // Deposit counter
StoreKeyDeposits StoreKey = "deposits" // Deposits tree
StoreKeyTotalGNSStakedAmount StoreKey = "totalGNSStakedAmount" // Total active launchpad GNS stake
)
type launchpadStore struct {
kvStore store.KVStore
}
// HasProjectsKey checks if the projects key exists in the store.
//
// Returns:
// - exists: true when the projects tree key is present in the KV store.
func (s *launchpadStore) HasProjectsKey() bool {
return s.kvStore.Has(StoreKeyProjects.String())
}
// GetProjects retrieves the projects tree.
//
// Returns:
// - projects: stored projects BP-tree keyed by project ID; the method panics if the key is missing or has the wrong type.
func (s *launchpadStore) GetProjects() *bptree.BPTree {
result, err := s.kvStore.Get(StoreKeyProjects.String())
if err != nil {
panic(err)
}
projects, ok := result.(*bptree.BPTree)
if !ok {
panic(ufmt.Sprintf("failed to cast result to *bptree.BPTree: %T", result))
}
return projects
}
// SetProjects stores the projects tree.
//
// Parameters:
// - _: cross-call discriminator; callers pass 0.
// - rlm: propagated realm context; it must be current (`rlm.IsCurrent()`), otherwise the write returns ErrSpoofedRealm.
// - projects: projects BP-tree to persist under the projects store key.
//
// Returns:
// - err: nil when the tree is stored; non-nil for a spoofed realm or an underlying KV-store write failure.
func (s *launchpadStore) SetProjects(_ int, rlm realm, projects *bptree.BPTree) error {
if !rlm.IsCurrent() {
return errors.New(ErrSpoofedRealm)
}
return s.kvStore.Set(0, rlm, StoreKeyProjects.String(), projects)
}
// HasProjectRecipientsKey checks if the recipient membership tree exists.
//
// Returns:
// - exists: true when the project-recipient membership key is present in the KV store.
func (s *launchpadStore) HasProjectRecipientsKey() bool {
return s.kvStore.Has(StoreKeyProjectRecipients.String())
}
// GetProjectRecipients retrieves the recipient address membership tree.
//
// Returns:
// - recipients: stored recipient-membership BP-tree keyed by address string; the method panics if the key is missing or has the wrong type.
func (s *launchpadStore) GetProjectRecipients() *bptree.BPTree {
result, err := s.kvStore.Get(StoreKeyProjectRecipients.String())
if err != nil {
panic(err)
}
recipients, ok := result.(*bptree.BPTree)
if !ok {
panic(ufmt.Sprintf("failed to cast result to *bptree.BPTree: %T", result))
}
return recipients
}
// SetProjectRecipients stores the recipient membership tree.
//
// Parameters:
// - _: cross-call discriminator; callers pass 0.
// - rlm: propagated realm context; it must be current (`rlm.IsCurrent()`), otherwise the write returns ErrSpoofedRealm.
// - recipients: recipient-membership BP-tree to persist.
//
// Returns:
// - err: nil when the tree is stored; non-nil for a spoofed realm or an underlying KV-store write failure.
func (s *launchpadStore) SetProjectRecipients(_ int, rlm realm, recipients *bptree.BPTree) error {
if !rlm.IsCurrent() {
return errors.New(ErrSpoofedRealm)
}
return s.kvStore.Set(0, rlm, StoreKeyProjectRecipients.String(), recipients)
}
// HasProjectTierRewardManagersKey checks if the project tier reward managers key exists in the store.
//
// Returns:
// - exists: true when the project-tier reward-manager key is present in the KV store.
func (s *launchpadStore) HasProjectTierRewardManagersKey() bool {
return s.kvStore.Has(StoreKeyProjectTierRewardManagers.String())
}
// GetProjectTierRewardManagers retrieves the project tier reward managers tree.
//
// Returns:
// - managers: stored reward-manager BP-tree keyed by project-tier ID; the method panics if the key is missing or has the wrong type.
func (s *launchpadStore) GetProjectTierRewardManagers() *bptree.BPTree {
result, err := s.kvStore.Get(StoreKeyProjectTierRewardManagers.String())
if err != nil {
panic(err)
}
managers, ok := result.(*bptree.BPTree)
if !ok {
panic(ufmt.Sprintf("failed to cast result to *bptree.BPTree: %T", result))
}
return managers
}
// SetProjectTierRewardManagers stores the project tier reward managers tree.
//
// Parameters:
// - _: cross-call discriminator; callers pass 0.
// - rlm: propagated realm context; it must be current (`rlm.IsCurrent()`), otherwise the write returns ErrSpoofedRealm.
// - managers: project-tier reward-manager BP-tree to persist.
//
// Returns:
// - err: nil when the tree is stored; non-nil for a spoofed realm or an underlying KV-store write failure.
func (s *launchpadStore) SetProjectTierRewardManagers(_ int, rlm realm, managers *bptree.BPTree) error {
if !rlm.IsCurrent() {
return errors.New(ErrSpoofedRealm)
}
return s.kvStore.Set(0, rlm, StoreKeyProjectTierRewardManagers.String(), managers)
}
// HasDepositCounterStoreKey checks if the deposit counter key exists in the store.
//
// Returns:
// - exists: true when the deposit-counter key is present in the KV store.
func (s *launchpadStore) HasDepositCounterStoreKey() bool {
return s.kvStore.Has(StoreKeyDepositCounter.String())
}
// GetDepositCounter retrieves the deposit counter.
//
// Returns:
// - counter: stored deposit counter; the method panics if the key is missing or has the wrong type.
func (s *launchpadStore) GetDepositCounter() *Counter {
result, err := s.kvStore.Get(StoreKeyDepositCounter.String())
if err != nil {
panic(err)
}
counter, ok := result.(*Counter)
if !ok {
panic(ufmt.Sprintf("failed to cast result to Counter: %T", result))
}
return counter
}
// SetDepositCounter stores the deposit counter under its dedicated key.
//
// Parameters:
// - _: cross-call discriminator; callers pass 0.
// - rlm: propagated realm context; it must be current (`rlm.IsCurrent()`), otherwise the write returns ErrSpoofedRealm.
// - counter: deposit counter to persist.
//
// Returns:
// - err: nil when the counter is stored; non-nil for a spoofed realm or an underlying KV-store write failure.
func (s *launchpadStore) SetDepositCounter(_ int, rlm realm, counter *Counter) error {
if !rlm.IsCurrent() {
return errors.New(ErrSpoofedRealm)
}
return s.kvStore.Set(0, rlm, StoreKeyDepositCounter.String(), counter)
}
// NextDepositID increments the stored deposit counter and formats the new value as a decimal ID.
//
// Returns:
// - depositID: next monotonically increasing deposit ID as a decimal string; the counter is incremented before formatting.
func (s *launchpadStore) NextDepositID() string {
counter := s.GetDepositCounter()
return strconv.FormatInt(counter.Next(), 10)
}
// HasDepositsKey checks if the deposits key exists in the store.
//
// Returns:
// - exists: true when the deposits tree key is present in the KV store.
func (s *launchpadStore) HasDepositsKey() bool {
return s.kvStore.Has(StoreKeyDeposits.String())
}
// GetDeposits retrieves the deposits tree.
//
// Returns:
// - deposits: stored deposits BP-tree keyed by deposit ID; the method panics if the key is missing or has the wrong type.
func (s *launchpadStore) GetDeposits() *bptree.BPTree {
result, err := s.kvStore.Get(StoreKeyDeposits.String())
if err != nil {
panic(err)
}
deposits, ok := result.(*bptree.BPTree)
if !ok {
panic(ufmt.Sprintf("failed to cast result to *bptree.BPTree: %T", result))
}
return deposits
}
// SetDeposits stores the deposits tree.
//
// Parameters:
// - _: cross-call discriminator; callers pass 0.
// - rlm: propagated realm context; it must be current (`rlm.IsCurrent()`), otherwise the write returns ErrSpoofedRealm.
// - deposits: deposits BP-tree to persist.
//
// Returns:
// - err: nil when the tree is stored; non-nil for a spoofed realm or an underlying KV-store write failure.
func (s *launchpadStore) SetDeposits(_ int, rlm realm, deposits *bptree.BPTree) error {
if !rlm.IsCurrent() {
return errors.New(ErrSpoofedRealm)
}
return s.kvStore.Set(0, rlm, StoreKeyDeposits.String(), deposits)
}
// HasTotalGNSStakedAmountKey checks if the total active GNS stake key exists in the store.
//
// Returns:
// - exists: true when the total-GNS-staked amount key is present in the KV store.
func (s *launchpadStore) HasTotalGNSStakedAmountKey() bool {
return s.kvStore.Has(StoreKeyTotalGNSStakedAmount.String())
}
// GetTotalGNSStakedAmount retrieves the total active GNS amount tracked by the store.
//
// Returns:
// - amount: total currently staked GNS in base units; the method panics if the key is missing or has the wrong type.
func (s *launchpadStore) GetTotalGNSStakedAmount() int64 {
result, err := s.kvStore.Get(StoreKeyTotalGNSStakedAmount.String())
if err != nil {
panic(err)
}
amount, ok := result.(int64)
if !ok {
panic(ufmt.Sprintf("failed to cast result to int64: %T", result))
}
return amount
}
// SetTotalGNSStakedAmount stores the total active GNS amount.
//
// Parameters:
// - _: cross-call discriminator; callers pass 0.
// - rlm: propagated realm context; it must be current (`rlm.IsCurrent()`), otherwise the write returns ErrSpoofedRealm.
// - amount: total currently staked GNS in base units.
//
// Returns:
// - err: nil when the amount is stored; non-nil for a spoofed realm or an underlying KV-store write failure.
func (s *launchpadStore) SetTotalGNSStakedAmount(_ int, rlm realm, amount int64) error {
if !rlm.IsCurrent() {
return errors.New(ErrSpoofedRealm)
}
return s.kvStore.Set(0, rlm, StoreKeyTotalGNSStakedAmount.String(), amount)
}
// NewLaunchpadStore creates a new launchpad store instance with the provided KV store.
// This function is used by the upgrade system to create storage instances for each implementation.
//
// Parameters:
// - kvStore: key-value store used to persist launchpad state.
//
// Returns:
// - launchpadStore: storage implementation backed by kvStore.
func NewLaunchpadStore(kvStore store.KVStore) ILaunchpadStore {
return &launchpadStore{
kvStore: kvStore,
}
}
types.gno
package launchpad
import (
"gno.land/p/gnoswap/uint256/v1"
rotree "gno.land/p/nt/bptree/rotree/v0"
bptree "gno.land/p/nt/bptree/v0"
)
type ILaunchpad interface {
ILaunchpadProject
ILaunchpadDeposit
ILaunchpadGetter
Render(path string) string
}
type ILaunchpadProject interface {
// CreateProject creates a project and its reward tiers in the current launchpad realm.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
// - name: human-readable project name.
// - tokenPath: token path whose tokens are distributed as project rewards.
// - recipient: address authorized to receive project rewards and project proceeds.
// - depositAmount: total reward-token amount allocated to the project.
// - conditionTokens: optional `*PAD*`-separated token paths required for deposits.
// - conditionAmounts: optional `*PAD*`-separated required amounts matching conditionTokens.
// - tier30Ratio: reward allocation ratio for the 30-day tier.
// - tier90Ratio: reward allocation ratio for the 90-day tier.
// - tier180Ratio: reward allocation ratio for the 180-day tier.
// - startTime: Unix timestamp at which project reward distribution starts.
//
// Returns:
// - projectID: identifier assigned to the newly created project.
CreateProject(
_ int,
rlm realm,
name string,
tokenPath string,
recipient address,
depositAmount int64,
conditionTokens string,
conditionAmounts string,
tier30Ratio int64,
tier90Ratio int64,
tier180Ratio int64,
startTime int64,
) string
// TransferLeftFromProjectByAdmin transfers unreserved reward tokens from an ended project.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
// - projectID: identifier of the ended project whose remaining balance is transferred.
// - recipient: destination address for the transferable balance.
//
// Returns:
// - amount: number of reward tokens transferred after active claims are reserved.
TransferLeftFromProjectByAdmin(_ int, rlm realm, projectID string, recipient address) int64
// CollectProtocolFee collects protocol-fee rewards allocated to the project recipient.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
CollectProtocolFee(_ int, rlm realm)
// CollectEmissionReward collects accumulated launchpad emission rewards.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
CollectEmissionReward(_ int, rlm realm)
// CollectProtocolFeeReward collects accumulated protocol-fee rewards for one token path.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
// - tokenPath: token path whose accumulated protocol-fee reward is collected.
CollectProtocolFeeReward(_ int, rlm realm, tokenPath string)
}
type ILaunchpadDeposit interface {
// DepositGns creates a GNS deposit in the selected project tier.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
// - targetProjectTierID: project-tier identifier in `{projectID}:{tierDuration}` form.
// - depositAmount: amount of GNS to stake in the selected tier.
// - referrer: optional referral address associated with the deposit.
//
// Returns:
// - depositID: identifier assigned to the newly created deposit.
DepositGns(_ int, rlm realm, targetProjectTierID string, depositAmount int64, referrer string) string
// CollectDepositGns withdraws a deposit's staked GNS after its tier permits withdrawal.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
// - depositID: identifier of the deposit whose GNS is collected.
//
// Returns:
// - amount: GNS amount withdrawn from the deposit.
// - err: non-nil when the deposit cannot be collected.
CollectDepositGns(_ int, rlm realm, depositID string) (int64, error)
// CollectRewardByDepositId collects the project-token reward earned by a deposit.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: Current realm context forwarded unchanged by the launchpad proxy.
// - depositID: identifier of the deposit whose reward is collected.
//
// Returns:
// - amount: project-token reward amount transferred to the depositor.
CollectRewardByDepositId(_ int, rlm realm, depositID string) int64
}
type ILaunchpadGetter interface {
// GetProjects returns a read-only tree containing projects keyed by project ID.
//
// Returns:
// - projects: read-only project tree for iteration without mutating stored state.
GetProjects() *rotree.ReadOnlyTree
// GetProjectName returns the human-readable name of a project.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - name: stored project name, or an empty string when lookup fails.
// - err: non-nil when projectId does not identify a stored project.
GetProjectName(projectId string) (string, error)
// GetProjectTokenPath returns the reward-token path configured for a project.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - tokenPath: configured project reward-token path, or an empty string on lookup failure.
// - err: non-nil when projectId does not identify a stored project.
GetProjectTokenPath(projectId string) (string, error)
// GetProjectDepositAmount returns the total reward-token allocation configured for a project.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - amount: configured project reward-token amount, or zero on lookup failure.
// - err: non-nil when projectId does not identify a stored project.
GetProjectDepositAmount(projectId string) (int64, error)
// GetProjectRecipient returns the address configured to receive a project's rewards.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - recipient: configured project recipient address, or the zero address on lookup failure.
// - err: non-nil when projectId does not identify a stored project.
GetProjectRecipient(projectId string) (address, error)
// GetProjectCondition returns the deposit condition for one token path in a project.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tokenPath: token path whose required balance condition is requested.
//
// Returns:
// - condition: configured token condition, or nil when lookup fails.
// - err: non-nil when the project or token condition is not found.
GetProjectCondition(projectId string, tokenPath string) (*ProjectCondition, error)
// GetProjectTiersRatios returns reward allocation ratios keyed by tier duration.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - ratios: map from tier duration to its reward allocation ratio.
// - err: non-nil when projectId does not identify a stored project.
GetProjectTiersRatios(projectId string) (map[int64]int64, error)
// GetProjectCreatedHeight returns the block height at which a project was created.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - height: creation block height, or zero on lookup failure.
// - err: non-nil when projectId does not identify a stored project.
GetProjectCreatedHeight(projectId string) (int64, error)
// GetProjectCreatedAt returns the Unix timestamp at which a project was created.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - time: creation Unix timestamp, or zero on lookup failure.
// - err: non-nil when projectId does not identify a stored project.
GetProjectCreatedAt(projectId string) (int64, error)
// GetProjectTier returns one tier of a project by its duration.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - projectTier: requested tier, or nil when lookup fails.
// - err: non-nil when the project or requested tier is not found.
GetProjectTier(projectId string, tier int64) (*ProjectTier, error)
// GetProjectTierDistributeAmountPerSecondX128 returns a tier's Q128-scaled reward rate.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - amountPerSecondX128: reward tokens per second scaled by 2^128.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierDistributeAmountPerSecondX128(projectId string, tier int64) (*uint256.Uint, error)
// GetProjectTierTotalDistributeAmount returns the total reward allocation for a tier.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - amount: total reward-token amount allocated to the tier.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierTotalDistributeAmount(projectId string, tier int64) (int64, error)
// GetProjectTierTotalDepositAmount returns the cumulative GNS deposited into a tier.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - amount: cumulative GNS amount deposited into the tier.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierTotalDepositAmount(projectId string, tier int64) (int64, error)
// GetProjectTierTotalWithdrawAmount returns the cumulative GNS withdrawn from a tier.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - amount: cumulative GNS amount withdrawn from the tier.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierTotalWithdrawAmount(projectId string, tier int64) (int64, error)
// GetProjectTierTotalDepositCount returns the cumulative number of tier deposits.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - count: cumulative number of deposits recorded for the tier.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierTotalDepositCount(projectId string, tier int64) (int64, error)
// GetProjectTierTotalWithdrawCount returns the cumulative number of tier withdrawals.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - count: cumulative number of withdrawals recorded for the tier.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierTotalWithdrawCount(projectId string, tier int64) (int64, error)
// GetProjectTierTotalCollectedAmount returns the cumulative reward amount collected from a tier.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - amount: cumulative project-token reward amount collected from the tier.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierTotalCollectedAmount(projectId string, tier int64) (int64, error)
// GetProjectTierStartTime returns the Unix timestamp when a tier starts distributing rewards.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - time: tier distribution start Unix timestamp.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierStartTime(projectId string, tier int64) (int64, error)
// GetProjectTierEndTime returns the Unix timestamp when a tier stops distributing rewards.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - time: tier distribution end Unix timestamp.
// - err: non-nil when the project or requested tier is not found.
GetProjectTierEndTime(projectId string, tier int64) (int64, error)
// GetDepositCount returns the number of deposits currently stored.
//
// Returns:
// - count: number of stored deposits.
GetDepositCount() int
// GetCurrentDepositId returns the latest allocated deposit identifier.
//
// Returns:
// - depositID: latest numeric deposit identifier.
GetCurrentDepositId() int64
// GetProjectTierRewards returns a read-only reward-state tree for a project tier.
//
// Parameters:
// - projectId: identifier of the project to inspect.
// - tier: tier duration in seconds.
//
// Returns:
// - rewards: read-only tree of reward states keyed by deposit ID.
GetProjectTierRewards(projectId string, tier int64) *rotree.ReadOnlyTree
// GetDeposit returns the stored deposit identified by depositId.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - deposit: stored deposit, or its zero value when lookup fails.
// - err: non-nil when depositId does not identify a stored deposit.
GetDeposit(depositId string) (Deposit, error)
// GetDepositProjectID returns the project identifier associated with a deposit.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - projectID: project identifier recorded in the deposit.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositProjectID(depositId string) (string, error)
// GetDepositTier returns the tier duration recorded in a deposit.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - tier: deposit tier duration in seconds.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositTier(depositId string) (int64, error)
// GetDepositProjectTierID returns the combined project-tier identifier for a deposit.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - projectTierID: identifier in `{projectID}:{tierDuration}` form.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositProjectTierID(depositId string) (string, error)
// GetDepositAmount returns the currently staked GNS amount in a deposit.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - amount: current GNS amount held by the deposit.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositAmount(depositId string) (int64, error)
// GetDepositWithdrawnHeight returns the block height at which a deposit was withdrawn.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - height: withdrawal block height, or the stored zero value if not withdrawn.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositWithdrawnHeight(depositId string) (int64, error)
// GetDepositWithdrawnTime returns the Unix timestamp at which a deposit was withdrawn.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - time: withdrawal Unix timestamp, or the stored zero value if not withdrawn.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositWithdrawnTime(depositId string) (int64, error)
// GetDepositCreatedHeight returns the block height at which a deposit was created.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - height: deposit creation block height.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositCreatedHeight(depositId string) (int64, error)
// GetDepositCreatedAt returns the Unix timestamp at which a deposit was created.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - time: deposit creation Unix timestamp.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositCreatedAt(depositId string) (int64, error)
// GetDepositEndTime returns the Unix timestamp when a deposit's tier ends.
//
// Parameters:
// - depositId: identifier of the deposit to inspect.
//
// Returns:
// - time: deposit tier end Unix timestamp.
// - err: non-nil when depositId does not identify a stored deposit.
GetDepositEndTime(depositId string) (int64, error)
// GetTotalGNSStakedAmount returns the current GNS amount staked across all deposits.
//
// Returns:
// - amount: aggregate currently staked GNS amount.
GetTotalGNSStakedAmount() int64
// GetProjectTierRewardManagerCount returns the number of stored tier reward managers.
//
// Returns:
// - count: number of project-tier reward managers.
GetProjectTierRewardManagerCount() int
// GetProjectTierRewardManager returns the reward manager for a project tier.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - manager: reward manager for the project tier, or nil on lookup failure.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardManager(projectTierId string) (*RewardManager, error)
// GetProjectTierRewardDistributeAmountPerSecondX128 returns a tier manager's Q128 reward rate.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - amountPerSecondX128: reward tokens per second scaled by 2^128.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardDistributeAmountPerSecondX128(projectTierId string) (*uint256.Uint, error)
// GetProjectTierRewardAccumulatedRewardPerDepositX128 returns accumulated Q128 reward per deposit.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - accumulatedX128: accumulated reward-per-deposit value scaled by 2^128.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardAccumulatedRewardPerDepositX128(projectTierId string) (*uint256.Uint, error)
// GetProjectTierRewardTotalDistributeAmount returns total reward tokens allocated to a tier.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - amount: total reward-token allocation.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardTotalDistributeAmount(projectTierId string) (int64, error)
// GetProjectTierRewardTotalClaimedAmount returns total reward tokens claimed from a tier.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - amount: cumulative claimed reward-token amount.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardTotalClaimedAmount(projectTierId string) (int64, error)
// GetProjectTierRewardDistributeStartTime returns a tier manager's distribution start time.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - time: distribution start Unix timestamp.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardDistributeStartTime(projectTierId string) (int64, error)
// GetProjectTierRewardDistributeEndTime returns a tier manager's distribution end time.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - time: distribution end Unix timestamp.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardDistributeEndTime(projectTierId string) (int64, error)
// GetProjectTierRewardAccumulatedDistributeAmount returns the accumulated distributed reward amount.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - amount: accumulated reward-token amount accounted for distribution.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardAccumulatedDistributeAmount(projectTierId string) (int64, error)
// GetProjectTierRewardAccumulatedTime returns the timestamp through which rewards are accumulated.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - time: accumulated Unix timestamp.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardAccumulatedTime(projectTierId string) (int64, error)
// GetProjectTierRewardClaimableDuration returns the delay before rewards become claimable.
//
// Parameters:
// - projectTierId: identifier of the project tier.
//
// Returns:
// - duration: claimable delay in seconds.
// - err: non-nil when projectTierId does not identify a stored manager.
GetProjectTierRewardClaimableDuration(projectTierId string) (int64, error)
// GetRewardState returns the reward state for one deposit in a project tier.
//
// Parameters:
// - projectTierId: identifier of the project tier.
// - depositId: identifier of the deposit whose reward state is requested.
//
// Returns:
// - rewardState: stored reward state, or nil on lookup failure.
// - err: non-nil when the project tier or deposit reward state is missing.
GetRewardState(projectTierId string, depositId string) (*RewardState, error)
// GetProjectActiveStatus reports whether a project is active at the current time.
//
// Parameters:
// - projectId: identifier of the project to inspect.
//
// Returns:
// - active: true when the project is currently active; false otherwise.
// - err: non-nil when projectId does not identify a stored project.
GetProjectActiveStatus(projectId string) (bool, error)
}
type ILaunchpadStore interface {
// HasProjectsKey reports whether the projects tree has a persisted store key.
//
// Returns:
// - exists: true when the projects store key is present.
HasProjectsKey() bool
// GetProjects returns the persisted project tree.
//
// Returns:
// - projects: tree containing projects keyed by project ID.
GetProjects() *bptree.BPTree
// SetProjects persists the project tree in the current store realm.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: current realm context forwarded for current-realm validation.
// - projects: project tree to persist.
//
// Returns:
// - err: non-nil when the realm context fails store validation or persistence fails.
SetProjects(_ int, rlm realm, projects *bptree.BPTree) error
// HasProjectRecipientsKey reports whether the project-recipient tree has a persisted key.
//
// Returns:
// - exists: true when the project-recipient store key is present.
HasProjectRecipientsKey() bool
// GetProjectRecipients returns the persisted project-recipient membership tree.
//
// Returns:
// - recipients: tree mapping project identifiers to recipient membership data.
GetProjectRecipients() *bptree.BPTree
// SetProjectRecipients persists the project-recipient membership tree.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: current realm context forwarded for current-realm validation.
// - recipients: project-recipient membership tree to persist.
//
// Returns:
// - err: non-nil when the realm context fails store validation or persistence fails.
SetProjectRecipients(_ int, rlm realm, recipients *bptree.BPTree) error
// HasProjectTierRewardManagersKey reports whether tier reward managers have a persisted key.
//
// Returns:
// - exists: true when the reward-manager store key is present.
HasProjectTierRewardManagersKey() bool
// GetProjectTierRewardManagers returns the persisted tier reward-manager tree.
//
// Returns:
// - managers: tree keyed by project-tier identifier.
GetProjectTierRewardManagers() *bptree.BPTree
// SetProjectTierRewardManagers persists the tier reward-manager tree.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: current realm context forwarded for current-realm validation.
// - managers: tier reward-manager tree to persist.
//
// Returns:
// - err: non-nil when the realm context fails store validation or persistence fails.
SetProjectTierRewardManagers(_ int, rlm realm, managers *bptree.BPTree) error
// DepositCounter
// HasDepositCounterStoreKey reports whether the deposit counter has a persisted key.
//
// Returns:
// - exists: true when the deposit-counter store key is present.
HasDepositCounterStoreKey() bool
// GetDepositCounter returns the persisted counter used to allocate deposit IDs.
//
// Returns:
// - counter: deposit ID counter.
GetDepositCounter() *Counter
// SetDepositCounter persists the counter used to allocate deposit IDs.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: current realm context forwarded for current-realm validation.
// - counter: counter state to persist.
//
// Returns:
// - err: non-nil when the realm context fails store validation or persistence fails.
SetDepositCounter(_ int, rlm realm, counter *Counter) error
// NextDepositID advances the deposit counter and returns its new identifier.
//
// Returns:
// - depositID: newly allocated deposit identifier.
NextDepositID() string
// HasDepositsKey reports whether the deposits tree has a persisted store key.
//
// Returns:
// - exists: true when the deposits store key is present.
HasDepositsKey() bool
// GetDeposits returns the persisted deposit tree.
//
// Returns:
// - deposits: tree containing deposits keyed by deposit ID.
GetDeposits() *bptree.BPTree
// SetDeposits persists the deposit tree in the current store realm.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: current realm context forwarded for current-realm validation.
// - deposits: deposit tree to persist.
//
// Returns:
// - err: non-nil when the realm context fails store validation or persistence fails.
SetDeposits(_ int, rlm realm, deposits *bptree.BPTree) error
// HasTotalGNSStakedAmountKey reports whether the aggregate GNS stake has a persisted key.
//
// Returns:
// - exists: true when the total-stake store key is present.
HasTotalGNSStakedAmountKey() bool
// GetTotalGNSStakedAmount returns the aggregate GNS amount currently staked.
//
// Returns:
// - amount: total GNS amount currently held in deposits.
GetTotalGNSStakedAmount() int64
// SetTotalGNSStakedAmount persists the aggregate current GNS stake.
//
// Parameters:
// - _: Noncrossing implementation-call discriminator; pass 0.
// - rlm: current realm context forwarded for current-realm validation.
// - amount: aggregate GNS amount currently staked.
//
// Returns:
// - err: non-nil when the realm context fails store validation or persistence fails.
SetTotalGNSStakedAmount(_ int, rlm realm, amount int64) error
}
upgrade.gno
package launchpad
import (
"gno.land/r/gnoswap/access/v1"
)
// RegisterInitializer registers a new launchpad implementation version.
// This function is called by each version (v1, v2, etc.) during initialization
// to register their implementation with the proxy system.
//
// The initializer function creates a new instance of the implementation
// using the provided launchpadStore interface.
//
// Security: Only contracts within the domain path can register initializers.
// Each package path can only register once to prevent duplicate registrations.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - initializer: callback that receives the implementation realm context and launchpad store, then returns the version's ILaunchpad implementation; its leading integer discriminator is invoked as 0.
func RegisterInitializer(cur realm, initializer func(_ int, rlm realm, launchpadStore ILaunchpadStore) ILaunchpad) {
initializerFunc := func(_ int, rlm realm, domainStore any) any {
access.AssertIsRlmCurrent(0, rlm)
currentLaunchpadStore, ok := domainStore.(ILaunchpadStore)
if !ok {
panic("domainStore is not an ILaunchpadStore")
}
return initializer(0, rlm, currentLaunchpadStore)
}
err := versionManager.RegisterInitializer(0, cur, initializerFunc)
if err != nil {
panic(err)
}
err = updateImplementation()
if err != nil {
panic(err)
}
}
// UpgradeImpl switches the active launchpad implementation to a different version.
// This function allows seamless upgrades from one version to another without
// data migration or downtime.
//
// Security: Only admin or governance can perform upgrades.
// The new implementation must have been previously registered via RegisterInitializer.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this realm.
// - packagePath: registered package path of the launchpad implementation to activate.
func UpgradeImpl(cur realm, packagePath string) {
// Ensure only admin or governance can perform upgrades
caller := cur.Previous().Address()
access.AssertIsAdminOrGovernance(caller)
err := versionManager.ChangeImplementation(0, cur, packagePath)
if err != nil {
panic(err)
}
err = updateImplementation()
if err != nil {
panic(err)
}
}
// GetImplementationPackagePath returns the package path of the currently active implementation.
//
// Returns:
// - packagePath: package path of the active implementation
func GetImplementationPackagePath() string {
return versionManager.GetCurrentPackagePath()
}