Skip to content

Commit

Permalink
Merge pull request #2 from dexie-space/release/1.8.1
Browse files Browse the repository at this point in the history
release 1.8.1
  • Loading branch information
kimsk authored Jun 11, 2023
2 parents 5fe6ea4 + da2ed0f commit 615fc82
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ In most cases the default configuration should be sufficient. However, if you wa
```sh
export CHIA_ROOT="~/.chia/mainnet"
export DEXIE_URL="https://dexie.space"
export DEXIE_API_URL="https://api.dexie.space/v1"
export DEXIE_API_URL="https://api.dexie.space/v1/"
export DEXIE_DB_PATH="/dexie_db"
```

Expand Down Expand Up @@ -95,6 +95,7 @@ Run any command with the `--help` option to see all available functionality.
--verify-only -vo Only verify the claim, don't actually claim
--yes -y Skip claim confirmation
--verbose -v Display verbose output
--target -t Specify a target address to claim rewards to
--help Show help and exit
```

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[tool.poetry]
name = "dexie-rewards"
version = "1.8.0"
version = "1.8.1"
description = "dexie-rewards is a Python CLI helper tool designed automatically to claim dexie liquidity rewards for offers created using the official Chia Wallet."
authors = ["Dexie Contributors <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
packages = [{ include = "dexie_rewards", from = "src" }]

[tool.poetry.dependencies]
python = "^3.11"
python = ">=3.10"
rich-click = "^1.6.1"
aiomisc = "^17.0.9"
aiohttp = "^3.8.4"
Expand Down
2 changes: 1 addition & 1 deletion src/dexie_rewards/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]


dexie_mainnet = "https://dexie.space/"
dexie_mainnet = "https://dexie.space"
dexie_testnet = "https://testnet.dexie.space"
dexie_local = "http://localhost:3000"

Expand Down
6 changes: 2 additions & 4 deletions src/dexie_rewards/decorators/with_wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ async def with_rpc_client(*args, **kwargs): # type: ignore
self_hostname, rpc_port, chia_root, chia_config
)
return await run_rpc(rpc_client, f, *args, **kwargs) # type: ignore
except Exception:
Console(stderr=True, style="bold red").print(
"Unable to connect to wallet"
)
except Exception as e:
Console(stderr=True, style="bold red").print(f"wallet rpc error: {e}")
sys.exit(1)

return with_rpc_client
Expand Down
50 changes: 41 additions & 9 deletions src/dexie_rewards/rewards/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey

from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.bech32m import encode_puzzle_hash
from chia.util.bech32m import decode_puzzle_hash, encode_puzzle_hash

from ..config import dexie_blue
from ..services import dexie_db as dexie_db
from ..utils import wait_for_synced_wallet
from .utils import (
Expand All @@ -22,7 +23,16 @@
)
from ..types.offer_reward import OfferReward

console = Console()

class ChiaWalletAddressParamType(click.ParamType):
name = "address"

def convert(self, value, param, ctx):
try:
puzzle_hash: bytes32 = decode_puzzle_hash(value)
return puzzle_hash
except ValueError:
self.fail(f"Invalid Chia Wallet Address: {value}", param, ctx)


@click.command("claim", short_help="Claim all offers with dexie rewards")
Expand Down Expand Up @@ -60,20 +70,34 @@
default=False,
show_default=True,
)
@click.option(
"-t",
"--target",
"target_puzzle_hash",
help="Specify a target address to claim rewards to",
type=ChiaWalletAddressParamType(),
required=False,
)
def claim_cmds(
fingerprint: Optional[int],
verify_only: bool,
skip_confirm: bool,
verbose: bool,
target_puzzle_hash: Optional[bytes32],
) -> None:
asyncio.run(claim_cmds_async(fingerprint, verify_only, skip_confirm, verbose))
asyncio.run(
claim_cmds_async(
fingerprint, verify_only, skip_confirm, verbose, target_puzzle_hash
)
)


async def claim_cmds_async(
fingerprint: Optional[int],
verify_only: bool,
skip_confirm: bool,
verbose: bool,
target_puzzle_hash: Optional[bytes32],
) -> None:
try:
console = Console(file=StringIO()) if not verbose else Console()
Expand All @@ -95,23 +119,31 @@ async def claim_cmds_async(
if not Confirm.ask("Claim all?"):
return

claims = await create_claims(offers_rewards)
ret: Any = {
"claims": claims,
}
claims = await create_claims(offers_rewards, target_puzzle_hash)
ret: Any = {"claims": claims}
if target_puzzle_hash is not None:
ret["target_puzzle_hash"] = target_puzzle_hash.hex()

if verify_only:
ret["verify_only"] = True

if verbose:
if target_puzzle_hash is not None:
console.print(
f"target puzzle hash:",
style=f"bold {dexie_blue} underline",
)
console.print(f"0x{target_puzzle_hash.hex()}")

console.print(
"\nclaims request payload:", style="bold dodger_blue2 underline"
"\nclaims request payload:", style=f"bold {dexie_blue} underline"
)
console.print_json(json.dumps(ret, indent=4))

result = await claim_rewards(ret)

if verbose or verify_only:
console.print("\nclaims result:", style="bold dodger_blue2 underline")
console.print("\nclaims result:", style=f"bold {dexie_blue} underline")
if verbose:
console.print_json(json.dumps(result, indent=4))
else:
Expand Down
24 changes: 15 additions & 9 deletions src/dexie_rewards/rewards/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rich.console import Console
from rich.table import Table
from rich.text import Text
from typing import Any, Dict, List, Tuple
from typing import Any, Dict, List, Optional, Tuple
import time
import traceback

Expand All @@ -16,18 +16,17 @@
from ..types.offer_reward import OfferReward


async def create_claims(offers_rewards: List[OfferReward]) -> List[Any]:
async def create_claims(
offers_rewards: List[OfferReward], target_puzzle_hash: Optional[bytes32]
) -> List[Any]:
timestamp = int(time.time())
claims = []
for offer_reward in offers_rewards:
(
public_key,
signature,
signing_mode,
) = await sign_claim(
(public_key, signature, signing_mode,) = await sign_claim(
offer_reward.offer_id,
timestamp,
offer_reward.maker_puzzle_hash,
target_puzzle_hash,
)

# return offer hash, signature, pk, and puzzle hash
Expand Down Expand Up @@ -93,9 +92,16 @@ async def get_offers_with_claimable_rewards(


async def sign_claim(
offer_id: str, timestamp: int, maker_puzzle_hash: bytes32
offer_id: str,
timestamp: int,
maker_puzzle_hash: bytes32,
target_puzzle_hash: Optional[bytes32],
) -> Tuple[str, str, str]:
message = f"Claim dexie liquidity rewards for offer {offer_id} ({timestamp})"
message = (
f"Claim dexie liquidity rewards for offer {offer_id} ({timestamp})"
if target_puzzle_hash is None
else f"Claim dexie liquidity rewards for offer {offer_id} to {target_puzzle_hash} ({timestamp})"
)
return await wallet_rpc_client.sign_message_by_puzzle_hash(
maker_puzzle_hash, message
)
Expand Down
6 changes: 5 additions & 1 deletion src/dexie_rewards/services/wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ async def get_synced(wallet_rpc_client: WalletRpcClient) -> bool:
@with_wallet_rpc_client(self_hostname, wallet_rpc_port, chia_root, chia_config)
async def get_all_offers(wallet_rpc_client: WalletRpcClient) -> List[TradeRecord]:
return await wallet_rpc_client.get_all_offers(
include_completed=True, exclude_taken_offers=True, file_contents=True, start=0, end=1000
include_completed=True,
exclude_taken_offers=True,
file_contents=True,
start=0,
end=1000,
)


Expand Down
4 changes: 2 additions & 2 deletions src/dexie_rewards/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import asyncio
from rich.console import Console
from rich.progress import (
Progress,
SpinnerColumn,
TextColumn,
TimeElapsedColumn,
)
import time

from typing import Optional

Expand Down Expand Up @@ -60,6 +60,6 @@ async def wait_for_synced_wallet(
while True:
if await is_wallet_synced(fingerprint):
break
time.sleep(2)
await asyncio.sleep(2)

return fingerprint

0 comments on commit 615fc82

Please sign in to comment.