-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add list and claim management commands
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import click | ||
from ape.types import AddressType | ||
from ape_ethereum import multicall | ||
from ape.cli import NetworkBoundCommand, network_option, account_option | ||
from apepay import StreamManager | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
""" | ||
Utlilities for viewing and claiming ApePay streams | ||
""" | ||
|
||
|
||
@cli.command(cls=NetworkBoundCommand) | ||
@network_option() | ||
@click.option("--start-block", type=int) | ||
@click.argument("address", type=AddressType) | ||
def list_unclaimed(network, start_block, address): | ||
sm = StreamManager(address=address) | ||
for stream in sm.unclaimed_streams(start_block=start_block): | ||
click.echo( | ||
f"{stream.creator}/{stream.stream_id}: " | ||
f"{stream.amount_unlocked / 10 ** stream.token.decimals()} " | ||
f"{stream.token.symbol()}" | ||
) | ||
|
||
|
||
@cli.command(cls=NetworkBoundCommand) | ||
@network_option() | ||
@account_option() | ||
@click.option("--start-block", type=int) | ||
@click.option("--batch-size", type=int, default=256) | ||
@click.argument("address", type=AddressType) | ||
def claim(network, account, start_block, batch_size, address): | ||
""" | ||
Claim unclaimed streams for the admin, using multicall (anyone can claim) | ||
""" | ||
sm = StreamManager(address=address) | ||
unclaimed_streams = sm.unclaimed_streams(start_block=start_block) | ||
more_streams = True | ||
|
||
while more_streams: | ||
tx = multicall.Transaction() | ||
|
||
for _ in range(batch_size): | ||
try: | ||
stream = next(unclaimed_streams) | ||
except StopIteration: | ||
more_streams = False | ||
break | ||
|
||
tx.add(sm.contract.claim, stream.creator, stream.stream_id) | ||
|
||
tx(sender=account) |