diff --git a/index.html b/index.html index 4c073135..80ffdd14 100644 --- a/index.html +++ b/index.html @@ -2,4 +2,4 @@
If you are using a private container registry to store your images, you will need to provide your bot with the necessary credentials to access it.
+First you will need to add your credentials to the cluster with the silverback cluster registry auth new
command.
Then you can provide the name of these credentials when creating your bot with the silverback cluster bots new
or silverback cluster bots update
commands.
You are finally ready to deploy your bot on the Cluster and get it running!
diff --git a/v0.5.11/.buildinfo b/v0.5.11/.buildinfo new file mode 100644 index 00000000..4560421e --- /dev/null +++ b/v0.5.11/.buildinfo @@ -0,0 +1,4 @@ +# Sphinx build info version 1 +# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. +config: b46fa637138fb600b9e344a8377fd2af +tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/v0.5.11/.doctrees/commands/cluster.doctree b/v0.5.11/.doctrees/commands/cluster.doctree new file mode 100644 index 00000000..3886e3e1 Binary files /dev/null and b/v0.5.11/.doctrees/commands/cluster.doctree differ diff --git a/v0.5.11/.doctrees/commands/run.doctree b/v0.5.11/.doctrees/commands/run.doctree new file mode 100644 index 00000000..ca3c70f9 Binary files /dev/null and b/v0.5.11/.doctrees/commands/run.doctree differ diff --git a/v0.5.11/.doctrees/environment.pickle b/v0.5.11/.doctrees/environment.pickle new file mode 100644 index 00000000..d184d608 Binary files /dev/null and b/v0.5.11/.doctrees/environment.pickle differ diff --git a/v0.5.11/.doctrees/index.doctree b/v0.5.11/.doctrees/index.doctree new file mode 100644 index 00000000..ec2444df Binary files /dev/null and b/v0.5.11/.doctrees/index.doctree differ diff --git a/v0.5.11/.doctrees/methoddocs/application.doctree b/v0.5.11/.doctrees/methoddocs/application.doctree new file mode 100644 index 00000000..13cc41ca Binary files /dev/null and b/v0.5.11/.doctrees/methoddocs/application.doctree differ diff --git a/v0.5.11/.doctrees/methoddocs/exceptions.doctree b/v0.5.11/.doctrees/methoddocs/exceptions.doctree new file mode 100644 index 00000000..57c9cee6 Binary files /dev/null and b/v0.5.11/.doctrees/methoddocs/exceptions.doctree differ diff --git a/v0.5.11/.doctrees/methoddocs/middlewares.doctree b/v0.5.11/.doctrees/methoddocs/middlewares.doctree new file mode 100644 index 00000000..d6b3b9a0 Binary files /dev/null and b/v0.5.11/.doctrees/methoddocs/middlewares.doctree differ diff --git a/v0.5.11/.doctrees/methoddocs/runner.doctree b/v0.5.11/.doctrees/methoddocs/runner.doctree new file mode 100644 index 00000000..1105f7f4 Binary files /dev/null and b/v0.5.11/.doctrees/methoddocs/runner.doctree differ diff --git a/v0.5.11/.doctrees/methoddocs/subscriptions.doctree b/v0.5.11/.doctrees/methoddocs/subscriptions.doctree new file mode 100644 index 00000000..d288ab08 Binary files /dev/null and b/v0.5.11/.doctrees/methoddocs/subscriptions.doctree differ diff --git a/v0.5.11/.doctrees/methoddocs/utils.doctree b/v0.5.11/.doctrees/methoddocs/utils.doctree new file mode 100644 index 00000000..57a105ce Binary files /dev/null and b/v0.5.11/.doctrees/methoddocs/utils.doctree differ diff --git a/v0.5.11/.doctrees/userguides/development.doctree b/v0.5.11/.doctrees/userguides/development.doctree new file mode 100644 index 00000000..bd66ebd4 Binary files /dev/null and b/v0.5.11/.doctrees/userguides/development.doctree differ diff --git a/v0.5.11/.doctrees/userguides/platform.doctree b/v0.5.11/.doctrees/userguides/platform.doctree new file mode 100644 index 00000000..190aeb39 Binary files /dev/null and b/v0.5.11/.doctrees/userguides/platform.doctree differ diff --git a/v0.5.11/.doctrees/userguides/quickstart.doctree b/v0.5.11/.doctrees/userguides/quickstart.doctree new file mode 100644 index 00000000..1e7c165d Binary files /dev/null and b/v0.5.11/.doctrees/userguides/quickstart.doctree differ diff --git a/v0.5.11/_sources/commands/cluster.rst.txt b/v0.5.11/_sources/commands/cluster.rst.txt new file mode 100644 index 00000000..0599bdf2 --- /dev/null +++ b/v0.5.11/_sources/commands/cluster.rst.txt @@ -0,0 +1,26 @@ +Cloud Platform +************** + +.. click:: silverback._cli:login + :prog: silverback login + :nested: none + +.. click:: silverback._cli:cluster + :prog: silverback cluster + :nested: full + :commands: workspaces, new, list, info, health + +.. click:: silverback._cli:vars + :prog: silverback cluster vars + :nested: full + :commands: new, list, info, update, remove + +.. click:: silverback._cli:docker_auth + :prog: silverback cluster docker auth + :nested: full + :commands: new, list, info, update, remove + +.. click:: silverback._cli:bots + :prog: silverback cluster bots + :nested: full + :commands: new, list, info, update, remove, health, start, stop, logs, errors diff --git a/v0.5.11/_sources/commands/run.rst.txt b/v0.5.11/_sources/commands/run.rst.txt new file mode 100644 index 00000000..fbceda35 --- /dev/null +++ b/v0.5.11/_sources/commands/run.rst.txt @@ -0,0 +1,10 @@ +Local Development +***************** + +.. click:: silverback._cli:run + :prog: silverback run + :nested: none + +.. click:: silverback._cli:worker + :prog: silverback worker + :nested: none diff --git a/v0.5.11/_sources/index.rst.txt b/v0.5.11/_sources/index.rst.txt new file mode 100644 index 00000000..b5590661 --- /dev/null +++ b/v0.5.11/_sources/index.rst.txt @@ -0,0 +1 @@ +.. dynamic-toc-tree:: diff --git a/v0.5.11/_sources/methoddocs/application.md.txt b/v0.5.11/_sources/methoddocs/application.md.txt new file mode 100644 index 00000000..7d7d70e5 --- /dev/null +++ b/v0.5.11/_sources/methoddocs/application.md.txt @@ -0,0 +1,10 @@ +# silverback.application + +The `silverback.application` module contains the high-level implementation of the the user's +Silverback application, meant to be used to expose method handlers and other functionality. + +```{eval-rst} +.. automodule:: silverback.application + :members: + :show-inheritance: +``` diff --git a/v0.5.11/_sources/methoddocs/exceptions.md.txt b/v0.5.11/_sources/methoddocs/exceptions.md.txt new file mode 100644 index 00000000..efdf9222 --- /dev/null +++ b/v0.5.11/_sources/methoddocs/exceptions.md.txt @@ -0,0 +1,7 @@ +# silverback.exceptions + +```{eval-rst} +.. automodule:: silverback.exceptions + :members: + :show-inheritance: +``` diff --git a/v0.5.11/_sources/methoddocs/middlewares.md.txt b/v0.5.11/_sources/methoddocs/middlewares.md.txt new file mode 100644 index 00000000..4f76353f --- /dev/null +++ b/v0.5.11/_sources/methoddocs/middlewares.md.txt @@ -0,0 +1,10 @@ +# silverback.middlewares + +The `silverback.middlewares` module contains middleware intended to improve the usability of +silverback as a whole, and add integrations for the silverback platform as well. + +```{eval-rst} +.. automodule:: silverback.middlewares + :members: + :show-inheritance: +``` diff --git a/v0.5.11/_sources/methoddocs/runner.md.txt b/v0.5.11/_sources/methoddocs/runner.md.txt new file mode 100644 index 00000000..b977d057 --- /dev/null +++ b/v0.5.11/_sources/methoddocs/runner.md.txt @@ -0,0 +1,10 @@ +# silverback.runner + +The `silverback.runner` module contains implementations for running Silverback apps in a variety +of different scenarios and trigger methods. + +```{eval-rst} +.. automodule:: silverback.runner + :members: + :show-inheritance: +``` diff --git a/v0.5.11/_sources/methoddocs/subscriptions.md.txt b/v0.5.11/_sources/methoddocs/subscriptions.md.txt new file mode 100644 index 00000000..fdf71f2e --- /dev/null +++ b/v0.5.11/_sources/methoddocs/subscriptions.md.txt @@ -0,0 +1,10 @@ +# silverback.subscriptions + +The `silverback.subscriptions` module contains an implementation of a Websocket subscription queue, +used for connected to an RPC node via websockets that implements the `eth_subscribe` RPC method. + +```{eval-rst} +.. automodule:: silverback.subscriptions + :members: + :show-inheritance: +``` diff --git a/v0.5.11/_sources/methoddocs/utils.md.txt b/v0.5.11/_sources/methoddocs/utils.md.txt new file mode 100644 index 00000000..e04fcf74 --- /dev/null +++ b/v0.5.11/_sources/methoddocs/utils.md.txt @@ -0,0 +1,7 @@ +# silverback.utils + +```{eval-rst} +.. automodule:: silverback.utils + :members: + :show-inheritance: +``` diff --git a/v0.5.11/_sources/userguides/development.md.txt b/v0.5.11/_sources/userguides/development.md.txt new file mode 100644 index 00000000..fe5884ed --- /dev/null +++ b/v0.5.11/_sources/userguides/development.md.txt @@ -0,0 +1,208 @@ +# Developing Applications + +In this guide, we are going to show you more details on how to build an application with Silverback. + +## Prerequisites + +You should have a python project with Silverback installed. +You can install Silverback via `pip install silverback` + +## Creating an Application + +Creating a Silverback Application is easy, to do so initialize the `silverback.SilverbackApp` class: + +```py +from silverback import SilverbackApp + +app = SilverbackApp() +``` + +The SilverbackApp class handles state and configuration. +Through this class, we can hook up event handlers to be executed each time we encounter a new block or each time a specific event is emitted. +Initializing the app creates a network connection using the Ape configuration of your local project, making it easy to add a Silverback bot to your project in order to perform automation of necessary on-chain interactions required. + +However, by default an app has no configured event handlers, so it won't be very useful. +This is where adding event handlers is useful via the `app.on_` method. +This method lets us specify which event will trigger the execution of our handler as well as which handler to execute. + +## New Block Events + +To add a block handler, you will do the following: + +```py +from ape import chain + +@app.on_(chain.blocks) +def handle_new_block(block): + ... +``` + +Inside of `handle_new_block` you can define any logic that you want to handle each new `block` detected by the silverback client. +You can return any serializable data structure from this function and that will be stored in the results database as a trackable metric for the execution of this handler. +Any errors you raise during this function will get captured by the client, and recorded as a failure to handle this `block`. + +## New Event Logs + +Similarly to blocks, you can handle events emitted by a contract by adding an event handler: + +``` +from ape import Contract + +TOKEN = Contract(' + + '' + + _("Hide Search Matches") + + "
" + ) + ); + }, + + /** + * helper function to hide the search marks again + */ + hideSearchWords: () => { + document + .querySelectorAll("#searchbox .highlight-link") + .forEach((el) => el.remove()); + document + .querySelectorAll("span.highlighted") + .forEach((el) => el.classList.remove("highlighted")); + localStorage.removeItem("sphinx_highlight_terms") + }, + + initEscapeListener: () => { + // only install a listener if it is really needed + if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) return; + + document.addEventListener("keydown", (event) => { + // bail for input elements + if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; + // bail with special keys + if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return; + if (DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS && (event.key === "Escape")) { + SphinxHighlight.hideSearchWords(); + event.preventDefault(); + } + }); + }, +}; + +_ready(() => { + /* Do not call highlightSearchWords() when we are on the search page. + * It will highlight words from the *previous* search query. + */ + if (typeof Search === "undefined") SphinxHighlight.highlightSearchWords(); + SphinxHighlight.initEscapeListener(); +}); diff --git a/v0.5.11/commands/cluster.html b/v0.5.11/commands/cluster.html new file mode 100644 index 00000000..516a4b6a --- /dev/null +++ b/v0.5.11/commands/cluster.html @@ -0,0 +1,168 @@ + + + + +The silverback.application
module contains the high-level implementation of the the user’s
+Silverback application, meant to be used to expose method handlers and other functionality.
The silverback.middlewares
module contains middleware intended to improve the usability of
+silverback as a whole, and add integrations for the silverback platform as well.
The silverback.runner
module contains implementations for running Silverback apps in a variety
+of different scenarios and trigger methods.
The silverback.subscriptions
module contains an implementation of a Websocket subscription queue,
+used for connected to an RPC node via websockets that implements the eth_subscribe
RPC method.
+ Searching for multiple words only shows matches that contain + all words. +
+ + + ++ + + + + +
In this guide, we are going to show you more details on how to build an application with Silverback.
+You should have a python project with Silverback installed.
+You can install Silverback via pip install silverback
Creating a Silverback Application is easy, to do so initialize the silverback.SilverbackApp
class:
from silverback import SilverbackApp
+
+app = SilverbackApp()
+
The SilverbackApp class handles state and configuration. +Through this class, we can hook up event handlers to be executed each time we encounter a new block or each time a specific event is emitted. +Initializing the app creates a network connection using the Ape configuration of your local project, making it easy to add a Silverback bot to your project in order to perform automation of necessary on-chain interactions required.
+However, by default an app has no configured event handlers, so it won’t be very useful.
+This is where adding event handlers is useful via the app.on_
method.
+This method lets us specify which event will trigger the execution of our handler as well as which handler to execute.
To add a block handler, you will do the following:
+from ape import chain
+
+@app.on_(chain.blocks)
+def handle_new_block(block):
+ ...
+
Inside of handle_new_block
you can define any logic that you want to handle each new block
detected by the silverback client.
+You can return any serializable data structure from this function and that will be stored in the results database as a trackable metric for the execution of this handler.
+Any errors you raise during this function will get captured by the client, and recorded as a failure to handle this block
.
Similarly to blocks, you can handle events emitted by a contract by adding an event handler:
+from ape import Contract
+
+TOKEN = Contract(<your token address here>)
+
+@app.on_(TOKEN.Transfer)
+def handle_token_transfer_events(transfer):
+ ...
+
Inside of handle_token_transfer_events
you can define any logic that you want to handle each new transfer
event that gets emitted by TOKEN.Transfer
detected by the silverback client.
+Again, you can return any serializable data structure from this function and that will be stored in the results database as a trackable metric for the execution of this handler.
+Any errors you raise during this function will get captured by the client, and recorded as a failure to handle this transfer
event log.
If you have heavier resources you want to load during startup, or want to initialize things like database connections, you can add a worker startup function like so:
+@app.on_worker_startup()
+def handle_on_worker_startup(state):
+ # Connect to DB, set initial state, etc
+ ...
+
+@app.on_worker_shutdown()
+def handle_on_worker_shutdown(state):
+ # cleanup resources, close connections cleanly, etc
+ ...
+
This function comes a parameter state
that you can use for storing the results of your startup computation or resources that you have provisioned.
It’s import to note that this is useful for ensuring that your workers (of which there can be multiple) have the resources necessary to properly handle any updates you want to make in your handler functions, such as connecting to the Telegram API, an SQL or NoSQL database connection, or something else. This function will run on every worker process.
+New in 0.2.0: These events moved from on_startup()
and on_shutdown()
for clarity.
The state
variable is also useful as this can be made available to each handler method so other stateful quantities can be maintained for other uses. Each distributed worker has its own instance of state.
To access the state from a handler, you must annotate context
as a dependency like so:
from typing import Annotated
+from taskiq import Context, TaskiqDepends
+
+@app.on_(chain.blocks)
+def block_handler(block, context: Annotated[Context, TaskiqDepends()]):
+ # Access state via context.state
+ ...
+
You can also add an application startup and shutdown handler that will be executed once upon every application startup. This may be useful for things like processing historical events since the application was shutdown or other one-time actions to perform at startup.
+@app.on_startup()
+def handle_on_startup(startup_state):
+ # Process missed events, etc
+ # process_history(start_block=startup_state.last_block_seen)
+ # ...or startup_state.last_block_processed
+ ...
+
+
+@app.on_shutdown()
+def handle_on_shutdown():
+ # Record final state, etc
+ ...
+
Changed in 0.2.0: The behavior of the @app.on_startup()
decorator and handler signature have changed. It is now executed only once upon application startup and worker events have moved on @app.on_worker_startup()
.
If configured, your bot with have app.signer
which is an Ape account that can sign arbitrary transactions you ask it to.
+To learn more about signing transactions with Ape, see the documentation.
Warning
+While not recommended, you can use keyfile accounts for automated signing. +See this guide to learn more about how to do that.
+Once you have programmed your bot, it’s really useful to be able to run it locally and validate that it does what you expect it to do.
+To run your bot locally, we have included a really useful cli command run
that takes care of connecting to the proper network, configuring signers (using your local Ape accounts), and starting up the application client and in-memory task queue workers.
# Run your bot on the Ethereum Sepolia testnet, with your own signer:
+$ silverback run my_bot:app --network :sepolia --account acct-name
+
It’s important to note that signers are optional, if not configured in the application then app.signer
will be None
.
+You can use this in your application to enable a “test execution” mode, something like this:
# Compute some metric that might lead to creating a transaction
+if app.signer:
+ # Execute a transaction via `sender=app.signer`
+else:
+ # Log what the transaction *would* have done, had a signer been enabled
+
Warning
+If you configure your application to use a signer, and that signer signs anything given to it, remember that you can lose substational amounts of funds if you deploy this to a production network. +Always test your applications throughly before deploying, and always use a dedicated key for production signing with your application in a remote setting.
+Note
+It is highly suggested to use a dedicated cloud signer plugin, such as ape-aws
for signing transactions in a cloud environment.
+Use segregated keys and limit your risk by controlling the amount of funds that key has access to at any given time.
Using only the silverback run ...
command in a default configuration executes everything in one process and the job queue is completely in-memory with a shared state.
+In some high volume environments, you may want to deploy your Silverback application in a distributed configuration using multiple processes to handle the messages at a higher rate.
The primary components are the client and workers. The client handles Silverback events (blocks and contract event logs) and creates jobs for the workers to process in an asynchronous manner.
+For this to work, you must configure a TaskIQ broker capable of distributed processing. +Additonally, it is highly suggested you should also configure a TaskIQ result backend in order to process and store the results of executing tasks.
+Note
+Without configuring a result backend, Silverback may not work as expected since your tasks will now suddenly return None
instead of the actual result.
For instance, with taskiq_redis
you could do something like this for the client:
export SILVERBACK_BROKER_CLASS="taskiq_redis:ListQueueBroker"
+export SILVERBACK_BROKER_KWARGS='{"queue_name": "taskiq", "url": "redis://127.0.0.1:6379"}'
+export SILVERBACK_RESULT_BACKEND_CLASS="taskiq_redis:RedisAsyncResultBackend"
+export SILVERBACK_RESULT_BACKEND_URI="redis://127.0.0.1:6379"
+
+silverback run "example:app" --network :mainnet:alchemy
+
And then the worker process with 2 worker subprocesses:
+export SILVERBACK_BROKER_CLASS="taskiq_redis:ListQueueBroker"
+export SILVERBACK_BROKER_KWARGS='{"url": "redis://127.0.0.1:6379"}'
+export SILVERBACK_RESULT_BACKEND_CLASS="taskiq_redis:RedisAsyncResultBackend"
+export SILVERBACK_RESULT_BACKEND_URI="redis://127.0.0.1:6379"
+
+silverback worker -w 2 "example:app"
+
The client will send tasks to the 2 worker subprocesses, and all task queue and results data will be go through Redis.
+TODO: Add backtesting mode w/ silverback test
Check out the Platform Deployment Userguide for more information on how to deploy your application to the Silverback Platform.
+In this guide, we are going to show you more details on how to deploy your application to the Silverback Platform.
+The Silverback Platform runs your Applications (or “Bots”) on dedicated managed application Clusters. +These Clusters will take care to orchestrate infrastructure, monitor, run your triggers, and collect metrics for your applications. +Each Cluster is bespoke for an individual or organization, and isolates your applications from others on different infrastructure.
+Before we deploy our Application, we have to create a Cluster. +If you haven’t yet, please sign up for Silverback at https://silverback.apeworx.io.
+Once you have signed up, you can actually create (and pay for) your Clusters from the Silverback CLI utility by first
+logging in to the Platform using silverback login
,
+and then using silverback cluster new
to follow the steps necessary to deploy it.
Note
+The Platform UI will let you create and manage Clusters using a graphical experience, which may be preferred. +The CLI experience is for those working locally who don’t want to visit the website, or are locally developing their applications.
+To connect to a cluster, you can use commands from the silverback cluster
subcommand group.
+For instance, to list all your available bots on your cluster, use silverback cluster bots list
.
+To obtain general information about your cluster, just use silverback cluster info
,
+or silverback cluster health
to see the current status of your Cluster.
If you have no bots, we will first have to containerize our Applications and upload them to a container registry that our Cluster is configured to access.
+Note
+Building a container for your application can be an advanced topic, we have included the silverback build
subcommand to help assist in generating Dockerfiles.
TODO: Add build process and describe silverback build --autogen
and silverback build --upgrade
TODO: Add how to debug containers using silverback run
w/ taskiq-redis
broker
Once you have created your bot application container image, you might know of some environment variables the image requires to run properly.
+Thanks to it’s flexible plugin system, ape plugins may also require specific environment variables to load as well.
+Silverback Clusters include an environment variable management system for exactly this purpose,
+which you can manage using silverback cluster vars
subcommand.
The environment variable management system makes use of a concept called “Variable Groups” which are distinct collections of environment variables meant to be used together. +These variable groups will help in managing the runtime environment of your Applications by allowing you to segregate different variables depending on each bot’s needs.
+To create an environment group, use the silverback cluster vars new
command and give it a name and a set of related variables.
+For instance, it may make sense to make a group of variables for your favorite Ape plugins or services, such as RPC Providers, Blockchain Data Indexers, Etherscan, etc.
+You might have a database connection that you want all your bots to access.
Warning
+All environment variables in Silverback Clusters are private, meaning they cannot be viewed after they are uploaded. +However, your Bots will have full access to their values from within their runtime environment, so be careful that you fully understand what you are sharing with your bots.
+Also, understand your build dependencies within your container and make sure you are not using any vulnerable or malicious packages.
+NEVER upload your private key in a plaintext format!
+Use Ape Account Plugins such as ape-aws
to safely manage access to your hosted keys.
Note
+The Etherscan plugin will not function without an API key in the cloud environment.
+This will likely create errors running your applications if you use Ape’s Contract
class.
To list your Variable Groups, use silverback cluster vars list
.
+To see information about a specific Variable Group, including the Environment Variables it includes, use silverback cluster vars info
+To remove a variable group, use silverback cluster vars remove
,
Note
+You can only remove a Variable Group if it is not referenced by any existing Bot.
+Once you have created all the Variable Group(s) that you need to operate your Bot, you can reference these groups by name when adding your Bot to the cluster.
+If you are using a private container registry to store your images, you will need to provide your bot with the necessary credentials to access it.
+First you will need to add your credentials to the cluster with the silverback cluster registry auth new
command.
Then you can provide the name of these credentials when creating your bot with the silverback cluster bots new
or silverback cluster bots update
commands.
You are finally ready to deploy your bot on the Cluster and get it running!
+To deploy your Bot, use the silverback cluster bots new
command and give your bot a name,
+container image, network to run on, an account alias (if you want to sign transactions w/ app.signer
),
+and any environment Variable Group(s) the bot needs.
+If everything validates successfully, the Cluster will begin orchestrating your deployment for you.
You should monitor the deployment and startup of your bot to make sure it enters the RUNNING state successfully.
+You can do this using the silverback cluster bots health
command.
Note
+It usually takes a minute or so for your bot to transition from PROVISIONING to STARTUP to the RUNNING state. +If there are any difficulties in downloading your container image, provisioning your desired infrastructure, or if your application encounters an error during the STARTUP phase, +the Bot will not enter into the RUNNING state and will be shut down gracefully into the STOPPED state.
+Once in the STOPPED state, you can make any adjustments to the environment Variable Group(s) or other runtime parameters in the Bot config;
+or, you can make code changes and deploy a new image for the Bot to use.
+Once ready, you can use the silverback cluster bots start
command to re-start your Bot.
If at any time you want to view the configuration of your bot, you can do so using the silverback cluster bots info
command.
+You can also update metadata or configuration of your bot using the silverback cluster bots update
command.
+Lastly, if you want to shutdown and delete your bot, you can do so using the silverback cluster bots remove
command.
Note
+Configuration updates do not redeploy your Bots automatically, you must manually stop and restart your bots for changes to take effect.
+Warning
+Removing a Bot will immediately trigger a SHUTDOWN if the Bot is not already STOPPED.
+Once your bot is successfully running in the RUNNING state, you can monitor your bot with a series of commands
+under the silverback cluster bots
subcommand group.
+We already saw how you can use the silverback cluster bots list
command to see all bots managed by your Cluster (running or not).
To see runtime health information about a specific bot, again use the silverback cluster bots health
command.
+You can view the logs that a specific bot is generating using the silverback cluster bots logs
command.
+Lastly, you can view unacknowledged errors that your bot has experienced while in the RUNNING state
+using the silverback cluster bots errors
command.
Warning
+Once in the RUNNING state, your Bot will not stop running unless it experiences a certain amount of errors in quick succession. +Any task execution that experiences an error will abort execution (and therefore not produce any metrics) but the Bot will not shutdown.
+All errors encountered during task exeuction are reported to the Cluster for later review by any users with appriopiate access.
+Tasks do not retry (by default), but updates to app.state
are maintained up until the point an error occurs.
It is important to keep track of these errors and ensure that none of them are in fact critical to the operation of your Application, +and to take corrective or preventative action if it is determined that it should be treated as a more critical failure condition.
+Note
+Your Bots can also be monitored from the Platform UI at https://silverback.apeworx.io.
+As we already saw, once a Bot is configured in a Cluster, we can control it using commands from the silverback cluster bots
subcommand group.
+For example, we can attempt to start a Bot that is not currently running (after making configuration or code changes)
+using the silverback cluster bots start
command.
+We can also stop a bot using silverback cluster bots stop
that is currently in the RUNNING state if we desire.
Note
+Controlling your bots can be done from the Platform UI at https://silverback.apeworx.io, if you have the right permissions to do so.
+TODO: Updating runtime parameters
+TODO: Downloading metrics from your Bot
+Silverback lets you create and deploy your own Python bots that respond to on-chain events. +The Silverback library leverages the Ape development framework as well as it’s ecosystem of plugins and packages to enable you to develop simple-yet-sophisticated automated applications that can listen and respond to live chain data.
+Silverback applications are excellent for use cases that involve continuously monitoring and responding to on-chain events, such as newly confirmed blocks or contract event logs.
+Some examples of these types of applications:
+Monitoring new pool creations, and depositing liquidity
Measuring trading activity of popular pools
Listening for large swaps to update a telegram group
Please read the development userguide for more information on how to develop an application.
+python3 version 3.10 or greater, python3-dev
Silverback relies heavily on the Ape development framework, so it’s worth it to familarize yourself with how to install Ape and it’s plugins using the Ape installation userguide.
+Note
+It is suggested that you use a virtual environment of your choosing, and then install the Silverback package via one of the following options.
+pip
You can install the latest release via pip
:
pip install silverback
+
setuptools
You can clone the repository and use setuptools
for the most up-to-date version:
git clone https://github.com/ApeWorX/silverback.git silverback
+cd silverback
+python3 setup.py install
+
Checkout the example to see how to use the library.
+Note
+The example makes use of the Ape Tokens plugin. +Be sure to properly configure your environment for the USDC and YFI tokens on Ethereum mainnet.
+To run your bot against a live network, this SDK includes a simple runner command you can use via:
+$ silverback run "example:app" --network :mainnet:alchemy
+
Note
+This runner uses an in-memory task broker by default. +If you want to learn more about what that means, please visit the development userguide.
+$ docker run --volume $PWD:/home/harambe/project --volume ~/.tokenlists:/home/harambe/.tokenlists apeworx/silverback:latest run "example:app" --network :mainnet
+
Note
+The Docker image we publish uses Python 3.11.
+Running the Quick Usage
and Docker Usage
with the provided example will fail if you do not have a fully-configured environment.
+Most common issues when using the SDK stem from the proper configuration of Ape plugins to unlock the behavior you desire.
You should use a provider that supports websockets to run silverback.
+If you want to use a hosted provider with websocket support like Alchemy to run this example, you will need a Alchemy API key for Ethereum mainnet.
+If you attempt to run the Docker Usage
command without supplying this key, you will get the following error:
$ docker run --volume $PWD:/home/harambe/project --volume ~/.tokenlists:/home/harambe/.tokenlists apeworx/silverback:latest run "example:app" --network :mainnet:alchemy
+Traceback (most recent call last):
+ ...
+ape_alchemy.exceptions.MissingProjectKeyError: Must set one of $WEB3_ALCHEMY_PROJECT_ID, $WEB3_ALCHEMY_API_KEY, $WEB3_ETHEREUM_MAINNET_ALCHEMY_PROJECT_ID, $WEB3_ETHEREUM_MAINNET_ALCHEMY_API_KEY.
+
Go to Alchemy, create an account, then create an application in their dashboard, and copy the API Key.
+Another requirement for the command from Docker Usage
to run the given example is that it uses ape-tokens plugin to look up token interfaces by symbol.
+In order for this to work, you should have installed and configured that plugin using a token list that includes both YFI and USDC on Ethereum mainnet.
+Doing this will give you a ~/.tokenlists
hidden folder in your home folder that you must mount into the docker container with the following flag:
... --volume ~/.tokenlists:/home/harambe/.tokenlists ...
+
Note
+It is suggested to install the 1inch tokenlist via ape tokens install tokens.1inch.eth
.
+See the ape-tokens README for more information.
To check that both of the tokens exist in your configured tokenlist, you can execute this command:
+$ ape tokens token-info YFI
+ Symbol: YFI
+ Name: yearn.finance
+ Chain ID: 1
+ Address: 0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e
+ Decimals: 18
+
+$ ape tokens token-info USDC
+ Symbol: USDC
+ Name: Circle USD
+ Chain ID: 1
+ Address: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
+ Decimals: 6
+
Note
+If you want, you can comment out the two functions exec_event1
and exec_event2
that handle the contract log events from these contracts if you do not have the configured tokenlist, then your command should work.
This project is under active development in preparation of the release of the Silverback Platform. +Things might not be in their final state and breaking changes may occur. +Comments, questions, criticisms and pull requests are welcomed.
+See Contributing for more information.
+