Metadata-Version: 2.1
Name: llamapay
Version: 0.1.0
Summary: llamapay: ape sdk for llamapay
Home-page: https://github.com/banteg/ape-llamapay
Author: banteg
Author-email: banteg@pm.me
License: Apache-2.0
Keywords: ethereum
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.7,<4
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ape-tokens (>=0.2.0)
Requires-Dist: ape-ens (>=0.2.0)
Requires-Dist: eth-ape (>=0.2.7.dev)
Requires-Dist: importlib-metadata ; python_version < "3.8"
Provides-Extra: dev
Requires-Dist: pytest (<7.0,>=6.0) ; extra == 'dev'
Requires-Dist: pytest-xdist ; extra == 'dev'
Requires-Dist: pytest-cov ; extra == 'dev'
Requires-Dist: hypothesis (<7.0,>=6.2.0) ; extra == 'dev'
Requires-Dist: black (>=21.3.0) ; extra == 'dev'
Requires-Dist: mypy (<1.0,>=0.910) ; extra == 'dev'
Requires-Dist: flake8 (<4.0,>=3.8.3) ; extra == 'dev'
Requires-Dist: isort (<6.0,>=5.9.3) ; extra == 'dev'
Requires-Dist: setuptools ; extra == 'dev'
Requires-Dist: wheel ; extra == 'dev'
Requires-Dist: twine ; extra == 'dev'
Requires-Dist: commitizen ; extra == 'dev'
Requires-Dist: pre-commit ; extra == 'dev'
Requires-Dist: pytest-watch ; extra == 'dev'
Requires-Dist: IPython ; extra == 'dev'
Requires-Dist: ipdb ; extra == 'dev'
Provides-Extra: lint
Requires-Dist: black (>=21.3.0) ; extra == 'lint'
Requires-Dist: mypy (<1.0,>=0.910) ; extra == 'lint'
Requires-Dist: flake8 (<4.0,>=3.8.3) ; extra == 'lint'
Requires-Dist: isort (<6.0,>=5.9.3) ; extra == 'lint'
Provides-Extra: release
Requires-Dist: setuptools ; extra == 'release'
Requires-Dist: wheel ; extra == 'release'
Requires-Dist: twine ; extra == 'release'
Provides-Extra: test
Requires-Dist: pytest (<7.0,>=6.0) ; extra == 'test'
Requires-Dist: pytest-xdist ; extra == 'test'
Requires-Dist: pytest-cov ; extra == 'test'
Requires-Dist: hypothesis (<7.0,>=6.2.0) ; extra == 'test'

# ape-llamapay

Manage [LlamaPay](https://llamapay.io) payment streams effortlessly from [Ape Framework](https://www.apeworx.io).

## Quick Usage

You can use this SDK in `ape console` or in ape scripts. A short example:

```python
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`:
```python
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`:
```python
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:
```python
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:
```python
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:
```python
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](https://www.python.org/downloads) version 3.7 or greater, python3-dev

## Installation

### via `pip`

You can install the latest release via [`pip`](https://pypi.org/project/pip/):

```bash
pip install llamapay
```

### via `setuptools`

You can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version:

```bash
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](LICENSE).


