Skip to content

feat(node): [NET-1455] Autostaker plugin #3086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 64 commits into from
Jun 10, 2025
Merged

feat(node): [NET-1455] Autostaker plugin #3086

merged 64 commits into from
Jun 10, 2025

Conversation

teogeb
Copy link
Contributor

@teogeb teogeb commented Apr 25, 2025

Summary

An experimental plugin that automatically manages sponsorship stakings. It periodically checks which sponsorships offer good payouts and stakes tokens to those sponsorships when possible (i.e. if there are unstaked tokens available or tokens can be unstaked from another sponsorship with a worse payout).

Features

  • Uses a payout-proportional strategy, see details in the comment of payoutProportionalStrategy.ts
  • Simple error handling: if an error occurs during staking or unstaking, all subsequent actions in that run are skipped (this is acceptable because the actions will be retried in the next scheduled run)
  • Uses an approximate scheduler
  • Operators select different sponsorships if multiple sponsorships have the same payoutPerSec
  • Filters out:
    • small transactions (the minimum transaction size is configurable via minTransactionDataTokenAmount)
    • sponsorships with too small payouts
    • sponsorships with a non-zero minimumStakingPeriodSeconds
    • sponsorships that require too many operators to join before payouts start (configurable via maxAcceptableMinOperatorCount)
    • sponsorships that have already reached the maximum number of operator stakes

Authentication

As the plugin does transaction on behalf of the operator, it needs either operator's private key or a CONTROLLER role assigned to it so that it can act as a staking agent. Granting the role is the preferred approach since controllers don't have permission to withdraw funds from the Operator contract

Future Improvements

  • Support sponsorships with minimumStakingPeriodSeconds by implementing logic to prevent premature unstaking, instead of filtering them out.
  • Convert the smoke test to an integration test and run it in CI. The test is currently quite slow.
  • Consider combining the rounding logic and the filtering of small transactions. A possible approach: 1) skip rounding, 2) filter out transactions that are too small, 3) balance the net change by removing or reducing the smallest stakes. This would stake all available tokens but might do too many transactions overall.

Copy link

linear bot commented Apr 25, 2025

@github-actions github-actions bot added the node label Apr 25, 2025
teogeb added a commit that referenced this pull request Apr 28, 2025
…3087)

Added a method which provides a client for querying The Graph. All
entities of the Streamr graph can be queried using this client, e.g.:
- `Stream`
- `StreamPermission`
- `Operator` 
- `Sponsorship`
- `Stake`
- `Vote`
- ...

This method is currently internal, but it can be made public if needed.

Needed in #3086.
@github-actions github-actions bot added the utils label May 19, 2025
jtakalai pushed a commit that referenced this pull request May 20, 2025
…3087)

Added a method which provides a client for querying The Graph. All
entities of the Streamr graph can be queried using this client, e.g.:
- `Stream`
- `StreamPermission`
- `Operator` 
- `Sponsorship`
- `Stake`
- `Vote`
- ...

This method is currently internal, but it can be made public if needed.

Needed in #3086.
@github-actions github-actions bot added the cli-tools Related to CLI Tools Package label May 28, 2025
@harbu
Copy link
Contributor

harbu commented Jun 3, 2025

Two things that need solving still

  • Handling of minimumStakingPeriodSeconds. I suggest we just ignore / skip sponsorships that have this set (in the spirit of MVP). Future improvement here is to add support for such sponsorships.
  • Handling of minOperatorCount (or whatever the variable is named). I suggest there is a config setting (e.g. maxAcceptableMinOperatorCount) that controls what is the maximum acceptable number for this config for a sponsorship. Any sponsorship requiring a higher amount of operators is simply ignored / skipped.

@github-actions github-actions bot added the docs label Jun 5, 2025
@teogeb teogeb requested a review from harbu June 6, 2025 08:53
@teogeb teogeb merged commit 2e55453 into main Jun 10, 2025
24 checks passed
@teogeb teogeb deleted the autostaker-plugin branch June 10, 2025 13:37
teogeb added a commit that referenced this pull request Jun 27, 2025
## Summary

Entries in the undelegation queue now affect the Autostaker
calculations.

## Background
 
When a delegator undelegates some amount from an operator, the tokens
aren't immediately transferred back to the delegator. Instead the amount
is added to the undelegation queue. The transfer happens as soon as
there are enough unstaked tokens in the operator contract.

## Changes

Modified the target stake calculation `payoutProportionalStrategy`. The
rounding logic and skipping of small transactions are also affected
slightly. The autostaker plugin reads the sum of undelegation queue
entries from The Graph and passes the amount to the strategy function.

Also added more assertions to the `autostaker.test.ts` smoke tests.

## Other changes

- The `myStakedAmount` in calculated from the stakes instead of querying
it from the contract
- Simplified logging in the plugin

## Chores

- Removed `sum.ts` from the `@streamr/utils` package
  - it was not exported
- the file was added during the development of
#3086 (we should have removed
the file in that PR)
- Fixed field type in `StakeQueryResultItem`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants