llamapay: ape sdk for llamapay
Project description
ape-llamapay
Manage LlamaPay payment streams effortlessly from Ape Framework.
Quick Usage
You can use this SDK in ape console
or in ape scripts. A short example:
from llamapay import Factory
factory = Factory()
factory.create_stream('banteg.eth', '1000 DAI/month', sender=accounts.load('dev'))
If deployment exists on the connected network, it will be automatically picked up.
A Factory
is a registry and deployer of new pools. Each Pool
manages all streams of a specific token. A Stream
stores metadata like source
, target
, rate
and allows operations on streams.
You can find pools by token address or symbol, courtesy of ape-tokens
:
factory.pools
factory.create_pool('YFI')
factory.get_pool('DAI')
You can find streams from event logs and filter them by source
or target
, including their ENS names, courtesy of ape-ens
:
pool.all_streams
pool.find_streams(source='ychad.eth')
pool.find_streams(target='wentokyo.eth')
To fund your streams you will need to deposit funds into a pool:
pool.get_balance('ychad.eth')
# infinite approve (optional)
pool.approve(sender=dev)
# auto approves the requested amount
pool.deposit('1000 DAI', sender=dev)
# withdraw all
pool.withdraw(sender=dev)
# withdraw some
pool.withdraw(Decimal('500'), sender=dev)
Token amounts can be specified as int
for wei, Decimal
for tokens, or str
to be converted by ape-tokens
based on their decimals.
It is easiest to prepare a stream from the Pool
instance:
stream = pool.make_stream(source=dev, target=crush, rate='1000 DAI/month')
You can specify the rate as int
for the internal 1e20 tokens per second representation or use a simple str
format of amount symbol/duration
like 1 YFI/week
or 200,000 UNI/year
.
Now that you have a Stream
prepared, you can create it:
stream.create(sender=dev)
stream.pause(sender=dev)
stream.cancel(sender=dev)
stream.replace(new_stream, sender=dev)
stream.modify(target=new_crush, sender=dev)
stream.modify(rate=stream.rate * 2, sender=dev)
# check your withdrawable balance
stream.balance
# push tokens to recipient or withdraw them if you are one (these methods are the same)
stream.send(sender=dev)
stream.withdraw(sender=dev)
Dependencies
- python3 version 3.7 or greater, python3-dev
Installation
via pip
You can install the latest release via pip
:
pip install llamapay
via setuptools
You can clone the repository and use setuptools
for the most up-to-date version:
git clone https://github.com/banteg/ape-llamapay.git
cd ape-llamapay
python3 setup.py install
Development
This project is in development and should be considered a beta. Things might not be in their final state and breaking changes may occur. Comments, questions, criticisms and pull requests are welcomed.
License
This project is licensed under the Apache 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file llamapay-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: llamapay-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/35.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4883c869c78499e9070b353e07d7911711916f1606d493800808a6ea4942ce5a |
|
MD5 | d334da6b96b323b23cf8b94962d9633c |
|
BLAKE2b-256 | 76afef16312ae92cb80aecc2be44e0d0e11e7d9da5eae5101e4d28afc2e9de12 |