Skip to content

Commit

Permalink
[IND-416] Add default fee for v4 python client (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
dydxwill authored Oct 13, 2023
1 parent 16a2c9a commit 5f388cf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
3 changes: 3 additions & 0 deletions v4-client-py/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# IDE
.idea/
12 changes: 6 additions & 6 deletions v4-client-py/v4_client_py/chain/aerial/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def prepare_and_broadcast_basic_transaction(
gas_limit: Optional[int] = None,
memo: Optional[str] = None,
broadcast_mode: BroadcastMode = None,
fee: int = 5000,
) -> SubmittedTx:
"""Prepare and broadcast basic transaction.
Expand All @@ -27,17 +28,16 @@ def prepare_and_broadcast_basic_transaction(
:param account: The account
:param gas_limit: The gas limit
:param memo: Transaction memo, defaults to None
:param broadcast_mode: Broadcast mode, defaults to None
:param fee: Transaction fee, defaults to 5000. Denomination is determined by the network config.
:return: broadcast transaction
"""
# query the account information for the sender
if account is None:
account = client.query_account(sender.address())

if gas_limit is not None:
# simply build the fee from the provided gas limit
fee = client.estimate_fee_from_gas(gas_limit)
else:
if gas_limit is None:

# we need to build up a representative transaction so that we can accurately simulate it
tx.seal(
Expand All @@ -50,12 +50,12 @@ def prepare_and_broadcast_basic_transaction(
tx.complete()

# simulate the gas and fee for the transaction
gas_limit, fee = client.estimate_gas_and_fee_for_tx(tx)
gas_limit, _ = client.estimate_gas_and_fee_for_tx(tx)

# finally, build the final transaction that will be executed with the correct gas and fee values
tx.seal(
SigningCfg.direct(sender.public_key(), account.sequence),
fee=fee,
fee=f"{fee}{client.network_config.fee_denomination}",
gas_limit=gas_limit,
memo=memo,
)
Expand Down
27 changes: 21 additions & 6 deletions v4-client-py/v4_client_py/chain/aerial/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ def fetchai_dorado_testnet(cls) -> "NetworkConfig":
faucet_url="https://faucet-dorado.fetch.ai",
)

@classmethod
def fetch_dydx_testnet(cls) -> "NetworkConfig":
"""Dydx testnet.
:return: Network configuration
"""
return NetworkConfig(
chain_id="dydx",
url="grpc+https://v4.testnet.dydx.exchange",
fee_minimum_gas_price=5000000000,
fee_denomination="dv4tnt",
staking_denomination="dv4tnt",
faucet_url="http://faucet.v4testnet.dydx.exchange",
)

@classmethod
def fetchai_alpha_testnet(cls):
"""Get the fetchai alpha testnet.
Expand All @@ -88,12 +103,12 @@ def fetchai_beta_testnet(cls):
raise RuntimeError("No beta testnet available")

@classmethod
def fetchai_stable_testnet(cls):
"""Get the fetchai stable testnet.
def fetch_dydx_stable_testnet(cls):
"""Get the dydx stable testnet.
:return: fetchai stable testnet. For now dorado is fetchai stable testnet.
:return: dydx stable testnet.
"""
return cls.fetchai_dorado_testnet()
return cls.fetch_dydx_testnet()

@classmethod
def fetchai_mainnet(cls) -> "NetworkConfig":
Expand Down Expand Up @@ -129,7 +144,7 @@ def latest_stable_testnet(cls) -> "NetworkConfig":
:return: latest stable testnet
"""
warnings.warn(
"latest_stable_testnet is deprecated, use fetchai_stable_testnet instead",
"latest_stable_testnet is deprecated, use fetch_dydx_stable_testnet instead",
DeprecationWarning,
)
return cls.fetchai_stable_testnet()
return cls.fetch_dydx_stable_testnet()
1 change: 1 addition & 0 deletions v4-client-py/v4_client_py/clients/modules/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def send_message(
gas_limit=gas_limit,
memo=None,
broadcast_mode=broadcast_mode if (broadcast_mode != None) else self.default_broadcast_mode(msg),
fee=0 if zeroFee else 5000,
)

def place_order(
Expand Down

0 comments on commit 5f388cf

Please sign in to comment.