Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
ed36363
Initial fees rework
MissingNO57 May 8, 2025
f20600f
Refactor
MissingNO57 May 8, 2025
2febf8c
Lint fix
MissingNO57 May 9, 2025
6a45d03
Fix
MissingNO57 May 9, 2025
3e9f479
Fix
MissingNO57 May 9, 2025
931a08a
Fix
MissingNO57 May 9, 2025
308f5c9
fix
MissingNO57 May 9, 2025
1a0e099
Fixes
MissingNO57 May 9, 2025
09bf50d
Tx fees rework
MissingNO57 May 9, 2025
b961ecb
Rework
MissingNO57 May 9, 2025
ffe2a63
Circular import fix
MissingNO57 May 9, 2025
0455da1
Linting fixes
MissingNO57 May 12, 2025
51f9d4a
Fixes
MissingNO57 May 12, 2025
6d94bd3
Moving tx fees
MissingNO57 May 12, 2025
2397400
fixes
MissingNO57 May 12, 2025
98e169c
Fix
MissingNO57 May 12, 2025
6366b3d
Fix
MissingNO57 May 12, 2025
f5016b6
Rework
MissingNO57 May 14, 2025
2920818
Optional account for online seal
MissingNO57 May 14, 2025
f84b805
fix
MissingNO57 May 16, 2025
e3a5122
Merge branch 'main' of github.com:fetchai/cosmpy into refactor/tx_fees
MissingNO57 May 16, 2025
7bc5b96
Rework
MissingNO57 May 16, 2025
26c5e68
Docs fix
MissingNO57 May 16, 2025
1fe7ce2
Fixes
MissingNO57 May 16, 2025
2215ae4
Fix
MissingNO57 May 16, 2025
84ea62c
Docs fix
MissingNO57 May 16, 2025
9db9b66
Refactoring: Relocating types to more suited locations
pbukva May 17, 2025
efe1355
Fix
MissingNO57 May 18, 2025
1dc509e
Fix
MissingNO57 May 18, 2025
5e632dd
Making the `account` param optional in ithe `simulate_tx(...)` function
pbukva May 20, 2025
b37308e
Refactor TxFee (getter/setter properties), adding 'to_coins(...)' fun…
pbukva May 22, 2025
534c1b0
Gen docs
pbukva May 22, 2025
0acfa33
Making speell checker happy
pbukva May 22, 2025
6748ca3
Making spell check happy again
pbukva May 22, 2025
e7a6dfd
Merge branch 'refactor/tx_fees' into refactor/tx_fees__pb
pbukva May 22, 2025
75d2210
Impl. alignment with Cosmos-SDk 'Coins' type (API and behaviour)
pbukva May 22, 2025
3f4db1c
Impl. additiona and subtraction for Coins type
pbukva May 23, 2025
1684f92
Fixing typing of derived methods for math. operators
pbukva May 23, 2025
8e1bccc
Refactor
MissingNO57 May 23, 2025
f7cf0f9
Isort
MissingNO57 May 23, 2025
9d84d9e
Flipping things to use aerial Coin & Coins
pbukva May 27, 2025
be275c5
Fixing mypy barking at wrong tree
pbukva May 27, 2025
844a026
Adding Coins.canonicalise() method and ditching Coins.sort_coins()
pbukva May 27, 2025
5b1de0c
Regenerate docs
pbukva May 27, 2025
187b70b
Make lint happy
pbukva May 27, 2025
83852e5
Making pylint happy again
pbukva May 27, 2025
71add1f
Making lint happu once again
pbukva May 27, 2025
f1920ec
Making linting happy once more
pbukva May 27, 2025
d40b33c
Tests and fixes
MissingNO57 May 27, 2025
c4bbe18
Improvements
MissingNO57 May 27, 2025
f137d55
Refactoring a few things
pbukva May 27, 2025
f53bbd6
Messing with functionality fixes and imports
pbukva May 27, 2025
ee945b1
Ditching unnecessary code
pbukva May 27, 2025
f76f88a
Extended tests
MissingNO57 May 27, 2025
ba5627a
Refactoring conversion
pbukva May 27, 2025
4e4049b
Merge branch 'refactor/tx_fees__pb' of github.com:fetchai/cosmpy into…
MissingNO57 May 27, 2025
d4def7c
Lint fix
MissingNO57 May 27, 2025
454dd15
Improvements and fixes
MissingNO57 May 27, 2025
6b4b2bd
Fixing pylint
pbukva May 27, 2025
1167f58
Making docs lint happy
pbukva May 27, 2025
f0042c4
Fixing canonicalise (ensuring that zero amount coins are dropped)
pbukva May 27, 2025
9dd6807
Spell fix
MissingNO57 May 28, 2025
549d5b7
Merge branch 'refactor/tx_fees__pb' of github.com:fetchai/cosmpy into…
MissingNO57 May 28, 2025
3afca63
Making spellchecker happy
pbukva May 28, 2025
c5ecb41
Merge branch 'refactor/tx_fees__pb' of https://github.com/fetchai/cos…
pbukva May 28, 2025
8a6a23e
granter payer string fix
MissingNO57 May 28, 2025
ae9ebab
Ensuring canonicalisation of Coins in high level aerial API
pbukva May 28, 2025
758ffd3
Adding canonicalisation in to 'Coins.to_proto()'
pbukva May 28, 2025
7f8729b
Attempt to resolve the dependencies linting issue
pbukva May 28, 2025
4ccef90
Attempt to resolve the dependencies linting issue
pbukva May 28, 2025
f6601af
Revert "Attempt to resolve the dependencies linting issue"
pbukva May 28, 2025
688cb2d
poetry lock
pbukva May 28, 2025
fc66995
dependencies and poetry lock again
pbukva May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,10 @@ perf
mitigations
radix
readme
TxFee
CoinProto
canonicalise
iadd
isub
repr
nanomobx
4 changes: 4 additions & 0 deletions cosmpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
# ------------------------------------------------------------------------------

"""Cosmpy source code."""

# NOTE: This import is here in order to fix issue with descriptor not being imported inside of autogenerated google
# protobuf modules which depends on it.
from google.protobuf import descriptor as _ # noqa: F401
147 changes: 25 additions & 122 deletions cosmpy/aerial/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,47 @@
import json
import math
import time
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from decimal import Decimal
from typing import Any, Dict, List, Optional, Tuple

import certifi
import grpc
from dateutil.parser import isoparse
from google.protobuf.timestamp_pb2 import Timestamp
Comment thread
pbukva marked this conversation as resolved.

from cosmpy.aerial import cast_to_int
from cosmpy.aerial.client.bank import create_bank_send_msg
from cosmpy.aerial.client.distribution import create_withdraw_delegator_reward
from cosmpy.aerial.client.staking import (
StakingPosition,
StakingSummary,
UnbondingPositions,
Validator,
ValidatorStatus,
create_delegate_msg,
create_redelegate_msg,
create_undelegate_msg,
)
from cosmpy.aerial.client.utils import (
TxFee,
ensure_timedelta,
get_paginated,
prepare_and_broadcast_basic_transaction,
)
from cosmpy.aerial.coins import Coin
from cosmpy.aerial.config import NetworkConfig
from cosmpy.aerial.exceptions import NotFoundError, QueryTimeoutError
from cosmpy.aerial.gas import GasStrategy, SimulationGasStrategy
from cosmpy.aerial.tx import Transaction, TxState
from cosmpy.aerial.tx_helpers import MessageLog, SubmittedTx, TxResponse
from cosmpy.aerial.types import Account, Block
from cosmpy.aerial.urls import Protocol, parse_url
from cosmpy.aerial.wallet import Wallet
from cosmpy.auth.rest_client import AuthRestClient
from cosmpy.bank.rest_client import BankRestClient
from cosmpy.common.rest_client import RestClient
from cosmpy.cosmwasm.rest_client import CosmWasmRestClient
from cosmpy.crypto.address import Address
from cosmpy.crypto.hashfuncs import sha256
from cosmpy.distribution.rest_client import DistributionRestClient
from cosmpy.params.rest_client import ParamsRestClient
from cosmpy.protos.cosmos.auth.v1beta1.auth_pb2 import BaseAccount
Expand Down Expand Up @@ -119,109 +123,6 @@
COSMOS_SDK_DEC_COIN_PRECISION = 10**18


@dataclass
class Account:
"""Account."""

address: Address
number: int
sequence: int


@dataclass
class StakingPosition:
"""Staking positions."""

validator: Address
amount: int
reward: int
reward_dec: Decimal


@dataclass
class UnbondingPositions:
"""Unbonding positions."""

validator: Address
amount: int


@dataclass
class Validator:
"""Validator."""

address: Address # the operators address
tokens: int # The total amount of tokens for the validator
moniker: str
status: ValidatorStatus


@dataclass
class Coin:
"""Coins."""

amount: int
denom: str


@dataclass
class StakingSummary:
"""Get the staking summary."""

current_positions: List[StakingPosition]
unbonding_positions: List[UnbondingPositions]

@property
def total_staked(self) -> int:
"""Get the total staked amount."""
return sum(map(lambda p: p.amount, self.current_positions))

@property
def total_rewards(self) -> int:
"""Get the total rewards."""
return sum(map(lambda p: p.reward, self.current_positions))

@property
def total_unbonding(self) -> int:
"""total unbonding."""
return sum(map(lambda p: p.amount, self.unbonding_positions))


@dataclass
class Block:
"""Block."""

height: int
time: datetime
chain_id: str
tx_hashes: List[str]

@staticmethod
def from_proto(block: Any) -> "Block":
"""Parse the block.

:param block: block as Any
:return: parsed block as Block
"""
return Block(
height=int(block.header.height),
time=Block._parse_timestamp(block.header.time),
tx_hashes=[sha256(tx).hex().upper() for tx in block.data.txs],
chain_id=block.header.chain_id,
)

@staticmethod
def _parse_timestamp(timestamp: Timestamp):
"""Parse the timestamp.

:param timestamp: timestamp
:return: parsed timestamp
"""
return datetime.fromtimestamp(timestamp.seconds, tz=timezone.utc) + timedelta(
microseconds=timestamp.nanos // 1000
)


class LedgerClient:
"""Ledger client."""

Expand Down Expand Up @@ -372,7 +273,7 @@ def send_tokens(
denom: str,
sender: Wallet,
memo: Optional[str] = None,
gas_limit: Optional[int] = None,
fee: Optional[TxFee] = None,
timeout_height: Optional[int] = None,
) -> SubmittedTx:
"""Send tokens.
Expand All @@ -382,7 +283,7 @@ def send_tokens(
:param denom: denom
:param sender: sender
:param memo: memo, defaults to None
:param gas_limit: gas limit, defaults to None
:param fee: transaction fee, defaults to None
:param timeout_height: timeout height, defaults to None
:return: prepare and broadcast the transaction and transaction details
"""
Expand All @@ -396,7 +297,7 @@ def send_tokens(
self,
tx,
sender,
gas_limit=gas_limit,
fee=fee,
memo=memo,
timeout_height=timeout_height,
)
Expand Down Expand Up @@ -499,7 +400,7 @@ def delegate_tokens(
amount: int,
sender: Wallet,
memo: Optional[str] = None,
gas_limit: Optional[int] = None,
fee: Optional[TxFee] = None,
timeout_height: Optional[int] = None,
) -> SubmittedTx:
"""Delegate tokens.
Expand All @@ -508,7 +409,7 @@ def delegate_tokens(
:param amount: amount
:param sender: sender
:param memo: memo, defaults to None
:param gas_limit: gas limit, defaults to None
:param fee: transaction fee, defaults to None
:param timeout_height: timeout height, defaults to None
:return: prepare and broadcast the transaction and transaction details
"""
Expand All @@ -526,7 +427,7 @@ def delegate_tokens(
self,
tx,
sender,
gas_limit=gas_limit,
fee=fee,
memo=memo,
timeout_height=timeout_height,
)
Expand All @@ -538,7 +439,7 @@ def redelegate_tokens(
amount: int,
sender: Wallet,
memo: Optional[str] = None,
gas_limit: Optional[int] = None,
fee: Optional[TxFee] = None,
timeout_height: Optional[int] = None,
) -> SubmittedTx:
"""Redelegate tokens.
Expand All @@ -548,7 +449,7 @@ def redelegate_tokens(
:param amount: amount
:param sender: sender
:param memo: memo, defaults to None
:param gas_limit: gas limit, defaults to None
:param fee: transaction fee, defaults to None
:param timeout_height: timeout height, defaults to None
:return: prepare and broadcast the transaction and transaction details
"""
Expand All @@ -567,7 +468,7 @@ def redelegate_tokens(
self,
tx,
sender,
gas_limit=gas_limit,
fee=fee,
memo=memo,
timeout_height=timeout_height,
)
Expand All @@ -578,7 +479,7 @@ def undelegate_tokens(
amount: int,
sender: Wallet,
memo: Optional[str] = None,
gas_limit: Optional[int] = None,
fee: Optional[TxFee] = None,
timeout_height: Optional[int] = None,
) -> SubmittedTx:
"""Undelegate tokens.
Expand All @@ -587,7 +488,7 @@ def undelegate_tokens(
:param amount: amount
:param sender: sender
:param memo: memo, defaults to None
:param gas_limit: gas limit, defaults to None
:param fee: transaction fee, defaults to None
:param timeout_height: timeout height, defaults to None
:return: prepare and broadcast the transaction and transaction details
"""
Expand All @@ -605,7 +506,7 @@ def undelegate_tokens(
self,
tx,
sender,
gas_limit=gas_limit,
fee=fee,
memo=memo,
timeout_height=timeout_height,
)
Expand All @@ -615,15 +516,15 @@ def claim_rewards(
validator: Address,
sender: Wallet,
memo: Optional[str] = None,
gas_limit: Optional[int] = None,
fee: Optional[TxFee] = None,
timeout_height: Optional[int] = None,
) -> SubmittedTx:
"""claim rewards.

:param validator: validator
:param sender: sender
:param memo: memo, defaults to None
:param gas_limit: gas limit, defaults to None
:param fee: transaction fee, defaults to None
:param timeout_height: timeout height, defaults to None
:return: prepare and broadcast the transaction and transaction details
"""
Expand All @@ -634,7 +535,7 @@ def claim_rewards(
self,
tx,
sender,
gas_limit=gas_limit,
fee=fee,
memo=memo,
timeout_height=timeout_height,
)
Expand All @@ -647,6 +548,7 @@ def estimate_gas_for_tx(self, tx: Transaction) -> int:
"""
return self._gas_strategy.estimate_gas(tx)

# NOTE(pb): We should come up with a mechanism how this method (or a new one) can return also `Coin`, resp. `Coins`.
def estimate_fee_from_gas(self, gas_limit: int) -> str:
"""Estimate fee from gas.

Expand All @@ -656,6 +558,7 @@ def estimate_fee_from_gas(self, gas_limit: int) -> str:
fee = math.ceil(gas_limit * self.network_config.fee_minimum_gas_price)
return f"{fee}{self.network_config.fee_denomination}"

# NOTE(pb): We should come up with a mechanism how this method (or a new one) can return also `Coin`, resp. `Coins`.
def estimate_gas_and_fee_for_tx(self, tx: Transaction) -> Tuple[int, str]:
"""Estimate gas and fee for transaction.

Expand Down
Loading
Loading