Skip to content

Commit

Permalink
Adding in agent0 signature to extra data on trade calls (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
slundqui authored Jun 4, 2024
1 parent e7e2c22 commit 04cd2da
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
10 changes: 8 additions & 2 deletions src/agent0/core/hyperdrive/interactive/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class Config:
"""
preview_before_trade: bool = False
"""Whether to preview the position before executing a trade. Defaults to False."""
txn_receipt_timeout: float | None = None
"""The timeout for waiting for a transaction receipt in seconds. Defaults to 120."""

# Logging and crash reporting
log_to_rollbar: bool = False
Expand Down Expand Up @@ -117,6 +115,10 @@ class Config:
The experiment's stateful random number generator. Defaults to creating a generator from
the provided random seed if not set.
"""

# Txn config
txn_receipt_timeout: float | None = None
"""The timeout for waiting for a transaction receipt in seconds. Defaults to 120."""
gas_limit: int | None = None
"""
The maximum gas to use when executing transactions. This gas limit controls
Expand All @@ -125,6 +127,10 @@ class Config:
"""
# TODO we only use gas_limit currently for policy trades and `create_checkpoint` in advance time,
# need to propagate this to other trades
txn_signature: bytes | None = None
"""
The signature for transactions. Defaults to `0xa0`.
"""

def __post_init__(self):
"""Create the random number generator if not set."""
Expand Down
1 change: 1 addition & 0 deletions src/agent0/core/hyperdrive/interactive/hyperdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _initialize(self, chain: Chain, hyperdrive_address: ChecksumAddress, name: s
rpc_uri=chain.rpc_uri,
web3=chain._web3, # pylint: disable=protected-access
txn_receipt_timeout=self.chain.config.txn_receipt_timeout,
txn_signature=self.chain.config.txn_signature,
)

# Register the username if it was provided
Expand Down
22 changes: 11 additions & 11 deletions src/agent0/ethpy/hyperdrive/interface/_contract_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async def _async_open_long(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)

Expand Down Expand Up @@ -233,7 +233,7 @@ async def _async_open_long(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)
try:
Expand Down Expand Up @@ -289,7 +289,7 @@ async def _async_close_long(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)

Expand Down Expand Up @@ -318,7 +318,7 @@ async def _async_close_long(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)
try:
Expand Down Expand Up @@ -378,7 +378,7 @@ async def _async_open_short(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)

Expand Down Expand Up @@ -407,7 +407,7 @@ async def _async_open_short(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)
try:
Expand Down Expand Up @@ -462,7 +462,7 @@ async def _async_close_short(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)

Expand Down Expand Up @@ -491,7 +491,7 @@ async def _async_close_short(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)
try:
Expand Down Expand Up @@ -552,7 +552,7 @@ async def _async_add_liquidity(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)

Expand Down Expand Up @@ -618,7 +618,7 @@ async def _async_remove_liquidity(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)
# To catch any solidity errors, we always preview transactions on the current block
Expand Down Expand Up @@ -684,7 +684,7 @@ async def _async_redeem_withdraw_shares(
( # IHyperdrive.Options
agent_checksum_address, # destination
as_base_option, # asBase
bytes(0), # extraData
interface.txn_signature, # extraData
),
)
# To catch any solidity errors, we always preview transactions on the current block
Expand Down
21 changes: 15 additions & 6 deletions src/agent0/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
_calc_time_stretch,
)

AGENT0_SIGNATURE = bytes.fromhex("a0")

if TYPE_CHECKING:
from eth_account.signers.local import LocalAccount
from eth_typing import BlockNumber, ChecksumAddress
from web3 import Web3

# We expect to have many instance attributes & public methods since this is a large API.
# pylint: disable=too-many-lines
# pylint: disable=too-many-instance-attributes
Expand All @@ -73,12 +80,6 @@
# pylint: disable=protected-access


if TYPE_CHECKING:
from eth_account.signers.local import LocalAccount
from eth_typing import BlockNumber, ChecksumAddress
from web3 import Web3


class HyperdriveReadInterface:
"""Read-only end-point API for interfacing with a deployed Hyperdrive pool."""

Expand All @@ -91,6 +92,7 @@ def __init__(
web3: Web3 | None = None,
read_retry_count: int | None = None,
txn_receipt_timeout: float | None = None,
txn_signature: bytes | None = None,
) -> None:
"""Initialize the HyperdriveReadInterface API.
Expand All @@ -109,7 +111,14 @@ def __init__(
The number of times to retry the read call if it fails. Defaults to 5.
txn_receipt_timeout: float | None, optional
The timeout for waiting for a transaction receipt in seconds. Defaults to 120.
txn_signature: bytes | None, optional
The signature for transactions. Defaults to `0xa0`.
"""
if txn_signature is None:
self.txn_signature = AGENT0_SIGNATURE
else:
self.txn_signature = txn_signature

# Handle defaults for config and addresses.
self.hyperdrive_address = hyperdrive_address

Expand Down
17 changes: 10 additions & 7 deletions src/agent0/ethpy/hyperdrive/interface/read_write_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
)
from .read_interface import HyperdriveReadInterface

# We have no control over the number of arguments since it is specified by the smart contracts
# pylint: disable=too-many-arguments
# ruff: noqa: PLR0913
# We only worry about protected access for anyone outside of this folder.
# pylint: disable=protected-access


if TYPE_CHECKING:
from eth_account.signers.local import LocalAccount
from eth_typing import BlockNumber, ChecksumAddress
Expand All @@ -33,6 +26,12 @@

from agent0.ethpy.hyperdrive.receipt_breakdown import ReceiptBreakdown

# We have no control over the number of arguments since it is specified by the smart contracts
# pylint: disable=too-many-arguments
# ruff: noqa: PLR0913
# We only worry about protected access for anyone outside of this folder.
# pylint: disable=protected-access


class HyperdriveReadWriteInterface(HyperdriveReadInterface):
"""Read-write end-point API for interfacing with a deployed Hyperdrive pool."""
Expand All @@ -45,6 +44,7 @@ def __init__(
read_retry_count: int | None = None,
write_retry_count: int | None = None,
txn_receipt_timeout: float | None = None,
txn_signature: bytes | None = None,
) -> None:
"""Initialize the primary endpoint for users to execute transactions on Hyperdrive smart contracts.
Expand All @@ -63,13 +63,16 @@ def __init__(
The number of times to retry the transact call if it fails. Defaults to no retries.
txn_receipt_timeout: float | None, optional
The timeout for waiting for a transaction receipt in seconds. Defaults to 120.
txn_signature: bytes | None, optional
The signature for transactions. Defaults to `0xa0`.
"""
super().__init__(
hyperdrive_address=hyperdrive_address,
rpc_uri=rpc_uri,
web3=web3,
read_retry_count=read_retry_count,
txn_receipt_timeout=txn_receipt_timeout,
txn_signature=txn_signature,
)
self.write_retry_count = write_retry_count

Expand Down

0 comments on commit 04cd2da

Please sign in to comment.