Skip to content

Commit

Permalink
Merge pull request #119 from algorandfoundation/feat/enable-incentive…
Browse files Browse the repository at this point in the history
…-eligibility-fees

feat: enable incentive eligibility fees
  • Loading branch information
tasosbit authored Jan 21, 2025
2 parents 8e65d2d + cf78f2b commit fd04288
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ var bootstrapCmd = &cobra.Command{

t := new(system.Clock)
// Fetch the state and handle any creation errors
state, stateResponse, err := algod.NewStateModel(ctx, client, httpPkg)
state, stateResponse, err := algod.NewStateModel(ctx, client, httpPkg, false)
cmdutils.WithInvalidResponsesExplanations(err, stateResponse, cmd.UsageString())
cobra.CheckErr(err)

Expand Down
6 changes: 5 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var (

NeedsUpgrade = false

// whether the user forbids incentive eligibility fees to be set
IncentivesDisabled = false

// algodEndpoint defines the URI address of the Algorand node, including the protocol (http/https), for client communication.
algodData string

Expand Down Expand Up @@ -60,7 +63,7 @@ var (
httpPkg := new(api.HttpPkg)
t := new(system.Clock)
// Fetch the state and handle any creation errors
state, stateResponse, err := algod.NewStateModel(ctx, client, httpPkg)
state, stateResponse, err := algod.NewStateModel(ctx, client, httpPkg, IncentivesDisabled)
utils.WithInvalidResponsesExplanations(err, stateResponse, cmd.UsageString())
cobra.CheckErr(err)

Expand Down Expand Up @@ -127,6 +130,7 @@ func NeedsToBeStopped(cmd *cobra.Command, args []string) {
// init initializes the application, setting up logging, commands, and version information.
func init() {
log.SetReportTimestamp(false)
RootCmd.Flags().BoolVarP(&IncentivesDisabled, "no-incentives", "n", false, style.LightBlue("Disable setting incentive eligibility fees"))
RootCmd.SetVersionTemplate(fmt.Sprintf("nodekit-%s-%s@{{.Version}}\n", runtime.GOARCH, runtime.GOOS))
// Add Commands
if runtime.GOOS != "windows" {
Expand Down
10 changes: 7 additions & 3 deletions internal/algod/participation/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func GetOnlineShortLink(http api.HttpPkgInterface, part OnlineShortLinkBody) (Sh
if err != nil {
return response, err
}
res, err := http.Post("http://b.nodekit.run/online", "applicaiton/json", bytes.NewReader(data))
res, err := http.Post("http://b.nodekit.run/online", "application/json", bytes.NewReader(data))
if err != nil {
return response, err
}
Expand Down Expand Up @@ -219,6 +219,10 @@ func GetOfflineShortLink(http api.HttpPkgInterface, offline OfflineShortLinkBody

// ToShortLink generates a shortened URL string using the unique
// identifier from the provided ShortLinkResponse.
func ToShortLink(link ShortLinkResponse) string {
return fmt.Sprintf("https://b.nodekit.run/%s", link.Id)
func ToShortLink(link ShortLinkResponse, incentiveEligibleFee bool) string {
suffix := ""
if incentiveEligibleFee {
suffix = "i"
}
return fmt.Sprintf("https://b.nodekit.run/%s%s", link.Id, suffix)
}
7 changes: 6 additions & 1 deletion internal/algod/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type StateModel struct {
// TODO: handle contexts instead of adding it to state (skill-issue zero)
Watching bool

// Whether user has disabled automatically applying incentive eligibility fees
IncentivesDisabled bool

// Client provides an interface for interacting with API endpoints,
// enabling various node operations and data retrieval.
Client api.ClientWithResponsesInterface
Expand All @@ -53,7 +56,7 @@ type StateModel struct {

// NewStateModel initializes and returns a new StateModel instance
// along with an API response and potential error.
func NewStateModel(ctx context.Context, client api.ClientWithResponsesInterface, httpPkg api.HttpPkgInterface) (*StateModel, api.ResponseInterface, error) {
func NewStateModel(ctx context.Context, client api.ClientWithResponsesInterface, httpPkg api.HttpPkgInterface, incentivesDisabled bool) (*StateModel, api.ResponseInterface, error) {
// Preload the node status
status, response, err := NewStatus(ctx, client, httpPkg)
if err != nil {
Expand All @@ -79,6 +82,8 @@ func NewStateModel(ctx context.Context, client api.ClientWithResponsesInterface,
Client: client,
HttpPkg: httpPkg,
Context: ctx,

IncentivesDisabled: incentivesDisabled,
}, partkeysResponse, nil
}

Expand Down
7 changes: 7 additions & 0 deletions internal/algod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type Status struct {
// NeedsUpdate indicates whether the system requires an update based on the current version and available release data.
NeedsUpdate bool `json:"needsUpdate"`

// LastProtocolVersion represents the most recent round protocol version.
LastProtocolVersion string `json:"lastProtocolVersion"`

// LastRound represents the most recent round number recorded by the system or client.
LastRound uint64 `json:"lastRound"`

Expand Down Expand Up @@ -106,6 +109,9 @@ func (s Status) Update(status Status) Status {
if s.LastRound != status.LastRound {
s.LastRound = status.LastRound
}
if s.LastProtocolVersion != status.LastProtocolVersion {
s.LastProtocolVersion = status.LastProtocolVersion
}
return s
}

Expand All @@ -127,6 +133,7 @@ func (s Status) Wait(ctx context.Context) (Status, api.ResponseInterface, error)
// Merge updates the current Status with data from a given StatusLike instance and adjusts fields based on defined conditions.
func (s Status) Merge(res api.StatusLike) Status {
s.LastRound = uint64(res.LastRound)
s.LastProtocolVersion = res.LastVersion
catchpoint := res.Catchpoint
if catchpoint != nil && *catchpoint != "" {
s.State = FastCatchupState
Expand Down
24 changes: 19 additions & 5 deletions ui/modals/transaction/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ func (m *ViewModel) Account() *algod.Account {

return nil
}

func (m *ViewModel) IsIncentiveProtocol() bool {
return m.State.Status.LastProtocolVersion == "https://github.com/algorandfoundation/specs/tree/236dcc18c9c507d794813ab768e467ea42d1b4d9"
}

// Whether the 2A incentive fee should be added
func (m *ViewModel) ShouldAddIncentivesFee() bool {
// conditions for 2A fee:
// 1) incentives allowed by user: command line flag to disable incentives has not been passed
// 2) online keyreg
// 3) protocol supports incentives
// 4) account is not already incentives eligible
return m.State != nil && !m.State.IncentivesDisabled && !m.Active && m.IsIncentiveProtocol() && !m.Account().IncentiveEligible
}

func (m *ViewModel) UpdateState() {
if m.Participation == nil {
return
Expand All @@ -64,11 +79,10 @@ func (m *ViewModel) UpdateState() {
}

var fee *uint64
// TODO: enable fee with either feature flag or config flag
//if m.Account().IncentiveEligible && !m.Active {
//feeInst := uint64(2000000)
//fee = &feeInst
//}
if m.ShouldAddIncentivesFee() {
feeInst := uint64(2000000)
fee = &feeInst
}

m.ATxn.AUrlTxnKeyCommon.Sender = m.Participation.Address
m.ATxn.AUrlTxnKeyCommon.Type = string(types.KeyRegistrationTx)
Expand Down
13 changes: 12 additions & 1 deletion ui/modals/transaction/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ func (m ViewModel) View() string {
adj = "online"
}
intro := fmt.Sprintf("Sign this transaction to register your account as %s", adj)
link := participation.ToShortLink(*m.Link)
link := participation.ToShortLink(*m.Link, m.ShouldAddIncentivesFee())
loraText := lipgloss.JoinVertical(
lipgloss.Center,
"Open this URL in your browser:\n",
style.WithHyperlink(link, link),
)

if m.ShouldAddIncentivesFee() {
loraText = lipgloss.JoinVertical(
lipgloss.Center,
loraText,
"",
"Note: Transction fee set to 2 ALGO",
"for staking rewards eligibility",
)
}

if isOffline {
loraText = lipgloss.JoinVertical(
lipgloss.Center,
Expand Down

0 comments on commit fd04288

Please sign in to comment.