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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

teogeb
Copy link
Contributor

@teogeb teogeb commented Apr 25, 2025

WIP. Requesting a review for some early feedback about the approach (see e.g. the "open questions" section).

Currently this just stakes 10000 tokens to some random active sponsorship until it runs out of tokens. It should get the list of actions (stakes and unstakes) from a separate module.

Also logging and error handling could be improved.

Open questions

  • We wouldn't like to require that operators provide their private key for this plugin. What other possibilities there are? The nodes can nowadays vote and flag behalf of the operator, so maybe they could also stake/unstake if that kind of permission could be added?
  • How we should query the possible sponsorships, which we could stake to? Now we use projectedInsolvency_gt and spotAPY_gt fllters, but maybe these are not optimall.

SDK features needed

  • Maybe we should add StreamrClient#getTheGraphClient() so that we don't need to use client's private variable?

Development

  • There is temporary autostaker-manual-test.sh script for manual testing. Do not merge that to main, but instead implement some proper tests for this.

Copy link

linear bot commented Apr 25, 2025

@github-actions github-actions bot added the node label Apr 25, 2025
if ((sponsorships.length) > 0 && (availableBalance >= STAKE_AMOUNT)) {
const targetSponsorship = sample(sponsorships)!
logger.info(`Stake ${formatEther(STAKE_AMOUNT)} to ${targetSponsorship.id}`)
await _operatorContractUtils.stake(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "what" to do should be separated from the "when", like it is in the simulator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. put "what to do with the sponsorships from thegraph" into a separate strategies directory

// @ts-expect-error private
const queryResult = streamrClient.theGraphClient.queryEntities((lastId: string, pageSize: number) => {
return {
query: `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How we should query the possible sponsorships, which we could stake to? Now we use projectedInsolvency_gt and spotAPY_gt fllters, but maybe these are not optimall.

remainingWei_gt: "0" is same as the projectedInsolvency, and clearer IMO. It's a good way to select only "active" sponsorships.

There might not need to be hard cutoffs for other this, just order by totalPayoutWeiPerSec desc should be fine, take some reasonable maximum number, e.g. 100.

# Do not merge this manual test to main

NODE_PRIVATE_KEY="1111111111111111111111111111111111111111111111111111111111111111"
OWNER_PRIVATE_KEY="2222222222222222222222222222222222222222222222222222222222222222"
Copy link
Contributor

@jtakalai jtakalai Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't like to require that operators provide their private key for this plugin. What other possibilities there are? The nodes can nowadays vote and flag behalf of the operator, so maybe they could also stake/unstake if that kind of permission could be added?

Nodes do node things; there's another role that can be used for staking/unstaking: CONTROLLER_ROLE. This is added by operator calling operatorContract.grantRole("0x7b765e0e932d348852a6f810bfa1ab891e259123f02db8cdcde614c570223357", controllerAddress) (where that hex mush can be read from operatorContract.CONTROLLER_ROLE())

This is probably preferable as a key management mechanism, so that the autostaker would be run with a private key of this kind of "controller".

There's revokeRole for removing that role.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants