CronCats / croncat-rs

A Rust version of the CronCat agent.
GNU Affero General Public License v3.0
19 stars 5 forks source link

Allow agent to auto-withdraw rewards/balance from CronCat Manager #100

Closed mikedotexe closed 1 year ago

mikedotexe commented 1 year ago

This is similar to and older draft pull request here: https://github.com/CronCats/croncat-rs/pull/87

This is related to issues #84 and #85

I'll describe what's left to do here, instead of creating a new issue))

So, as @NinoLipartiia pointed out via DMs, an agent might have a payable account different than their agent address. In this case, the objective changes a bit. Let's talk this through…

If an agent…

is also the payable address

It is very helpful, and arguably necessary, for the agent to automatically withdraw, which is the original intention of the issues and this pull request. We want to give the agent the ability to set a variable in the YAML files that specifies an amount of native tokens. If the agent's balance falls below that, it should automatically call withdraw_reward on the CronCat Manager, effectively "refilling" its native tokens and ensuring that it can continue running as an agent normally and calling proxy_call without the risk of running out of funds needed for the gas.

So in this case, the agent will likely choose to use some new variable (not introduced in this PR, please introduce into the YAML config(s) ) If the agent decides to not add the new YAML entry, they are essentially saying, "I have another mechanism to keep my agent's balance full, don't worry about it.

has a different payable address

In this case, the agent might desire to automatically withdraw. Or they might decide to not add the YAML variable, in which case it would never withdraw automatically.

Summary

In both cases, we want to add a YAML variable to the config(s) that specifies a threshold (in native tokens) that, when the agent balance falls below, will trigger an automatic call to withdraw_reward.

If there is no YAML entry for that variable, the agent never automatically withdraws.


Here's the withdraw function in the CronCat Manager: https://github.com/CronCats/cw-croncat/blob/main/contracts/cw-croncat/src/contract.rs#L157

Given the code as it is now in this draft pull request, you should be able to run this and see that the agent balance is being fetched. Look for my patented "aloha" logs here:

Screen Shot 2022-12-12 at 9 28 52 AM