Skip to content

refactor: Tx fees granting rework#413

Closed
MissingNO57 wants to merge 31 commits into
mainfrom
refactor/tx_fees
Closed

refactor: Tx fees granting rework#413
MissingNO57 wants to merge 31 commits into
mainfrom
refactor/tx_fees

Conversation

@MissingNO57

Copy link
Copy Markdown
Contributor

Proposed Changes

[describe the changes here...]

Linked Issues

[if applicable, add links to issues resolved by this PR]

Types of changes

What type of change does this pull request make (put an x in the boxes that apply)?

  • Bug fix (non-breaking change that fixes an issue).
  • New feature added (non-breaking change that adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to stop working as expected).
  • Documentation update.
  • Something else (e.g., tests, scripts, example, deployment, infrastructure).

Checklist

Put an x in the boxes that apply:

  • I have read the CONTRIBUTING guide
  • Checks and tests pass locally

If applicable

  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that code coverage does not decrease
  • I have added/updated the documentation

Further comments

[if this is a relatively large or complex change, kick off a discussion by explaining why you chose the solution you did, what alternatives you considered, etc...]

@MissingNO57 MissingNO57 requested a review from lrahmani May 9, 2025 15:01
@MissingNO57 MissingNO57 requested review from jrriehl and pbukva as code owners May 9, 2025 15:01
@github-actions

github-actions Bot commented May 12, 2025

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 6748ca3):

https://fetch-docs-preview--pr413-refactor-tx-fees-5frisnzj.web.app

(expires Sat, 24 May 2025 13:36:27 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f2de39fd4e81249941960b74fbab0a62d90d69f8

Comment thread cosmpy/aerial/tx.py Outdated
Comment on lines +77 to +98
class TxFee:
"""Cosmos SDK TxFee abstraction."""

def __init__(
self,
amount: List["Coin"], # type: ignore # noqa: F821
gas_limit: int,
granter: Optional[Address] = None,
payer: Optional[Address] = None,
):
"""Init the Transaction fee class.

:param amount: tx fee amount
:param gas_limit: gas limit
:param granter: transaction fee granter, defaults to None
:param payer: transaction fee payer, defaults to None
:returns initialised TxFee
"""
self.amount = amount
self.gas_limit = gas_limit
self.granter = granter
self.payer = payer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class TxFee:
"""Cosmos SDK TxFee abstraction."""
def __init__(
self,
amount: List["Coin"], # type: ignore # noqa: F821
gas_limit: int,
granter: Optional[Address] = None,
payer: Optional[Address] = None,
):
"""Init the Transaction fee class.
:param amount: tx fee amount
:param gas_limit: gas limit
:param granter: transaction fee granter, defaults to None
:param payer: transaction fee payer, defaults to None
:returns initialised TxFee
"""
self.amount = amount
self.gas_limit = gas_limit
self.granter = granter
self.payer = payer
@dataclass
class TxFee:
"""Cosmos SDK TxFee abstraction."""
amount: Option[List["Coin"]] # type: ignore # noqa: F821
gas_limit: Option[int]
granter: Optional[Address] = None
payer: Optional[Address] = None

Comment thread cosmpy/aerial/tx.py Outdated
Comment on lines +101 to +107
def from_fixed_amount(
cls,
amount: str,
gas_limit: int = 0,
granter: Optional[Address] = None,
payer: Optional[Address] = None,
) -> "TxFee":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def from_fixed_amount(
cls,
amount: str,
gas_limit: int = 0,
granter: Optional[Address] = None,
payer: Optional[Address] = None,
) -> "TxFee":
def from_gas_price(
cls,
gas_price: float,
gas_limit: int,
granter: Optional[Address] = None,
payer: Optional[Address] = None,
) -> "TxFee":

Comment thread cosmpy/aerial/tx.py Outdated
Comment on lines +147 to +187
@classmethod
def from_simulation(
cls,
client: "LedgerClient", # type: ignore # noqa: F821
tx: "Transaction", # type: ignore # noqa: F821
sender: "Wallet", # type: ignore # noqa: F821
amount: Optional[str] = None,
granter: Optional[Address] = None,
payer: Optional[Address] = None,
account: Optional["Account"] = None, # type: ignore # noqa: F821
memo: Optional[str] = None,
) -> Tuple["TxFee", Optional["Account"]]: # type: ignore # noqa: F821
"""Estimate transaction fees based on either a provided amount, gas limit, or simulation.

:param client: Ledger client
:param tx: The transaction
:param sender: The transaction sender
:param amount: Transaction fee amount, defaults to None
:param granter: Transaction fee granter, defaults to None
:param payer: Transaction fee payer, defaults to None
:param account: The account
:param memo: Transaction memo, defaults to None
:return: Tuple[TxFee, Optional[Account]]
"""
# Ensure we have the account info
account = account or client.query_account(sender.address())

# Simulate transaction to get gas and amount
gas_limit, estimated_amount = simulate_tx(client, tx, sender, account, memo)

# Use estimated amount if not provided
amount = amount or estimated_amount

fee = cls(
amount=parse_coins(amount),
gas_limit=gas_limit,
granter=granter,
payer=payer,
)

return fee, account

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would relocate this method to the Tx class - it feels like it would fit there better than here.

Comment thread cosmpy/aerial/tx.py Outdated
payer: Optional[Address] = None,
account: Optional["Account"] = None, # type: ignore # noqa: F821
memo: Optional[str] = None,
) -> Tuple["TxFee", Optional["Account"]]: # type: ignore # noqa: F821

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the Tx instance to the returned tuple = the return value would contain modified & sealed Tx instance with filled in Fee instance from simulation.

Suggested change
) -> Tuple["TxFee", Optional["Account"]]: # type: ignore # noqa: F821
) -> Tuple[Tx, "TxFee", Optional["Account"]]: # type: ignore # noqa: F821

Comment thread cosmpy/aerial/tx.py Outdated
self._msgs.append(msg)
return self

def online_seal(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be extended to be able to use multiple senders - it would require multiple senders and accounts. If we do that we should consider where to store queried accounts to avoid unnecessary querying.

@MissingNO57 MissingNO57 mentioned this pull request May 22, 2025
10 tasks
@MissingNO57 MissingNO57 changed the base branch from feat/fee_grant to main May 28, 2025 10:00
@MissingNO57

Copy link
Copy Markdown
Contributor Author

Closed in favour of #415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants