From 8edc1d0e342bb6c9d3dc431e7e69145cf1a2daeb Mon Sep 17 00:00:00 2001 From: Will Liu Date: Wed, 11 Oct 2023 14:04:06 -0700 Subject: [PATCH 1/5] add fee logic --- v4-client-py/v4_client_py/chain/aerial/client/utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/v4-client-py/v4_client_py/chain/aerial/client/utils.py b/v4-client-py/v4_client_py/chain/aerial/client/utils.py index a220281e..ce6886f2 100644 --- a/v4-client-py/v4_client_py/chain/aerial/client/utils.py +++ b/v4-client-py/v4_client_py/chain/aerial/client/utils.py @@ -18,6 +18,7 @@ def prepare_and_broadcast_basic_transaction( gas_limit: Optional[int] = None, memo: Optional[str] = None, broadcast_mode: BroadcastMode = None, + fee: Optional[str] = "5000dv4tnt", ) -> SubmittedTx: """Prepare and broadcast basic transaction. @@ -34,10 +35,7 @@ def prepare_and_broadcast_basic_transaction( 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( @@ -50,7 +48,7 @@ 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( From acd7bf77a505599b51bd193e44c9002571f3f7eb Mon Sep 17 00:00:00 2001 From: Will Liu Date: Thu, 12 Oct 2023 09:45:03 -0700 Subject: [PATCH 2/5] set fee to 0 if placing orders --- v4-client-py/v4_client_py/clients/modules/post.py | 1 + 1 file changed, 1 insertion(+) diff --git a/v4-client-py/v4_client_py/clients/modules/post.py b/v4-client-py/v4_client_py/clients/modules/post.py index 68b93ffc..c78d7ec5 100644 --- a/v4-client-py/v4_client_py/clients/modules/post.py +++ b/v4-client-py/v4_client_py/clients/modules/post.py @@ -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="0dv4tnt" if zeroFee else "5000dv4tnt", ) def place_order( From 370c301697516102c8b677a3cb10a63b7a1011f1 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Thu, 12 Oct 2023 10:06:25 -0700 Subject: [PATCH 3/5] address cmt --- v4-client-py/.gitignore | 3 +++ v4-client-py/v4_client_py/chain/aerial/client/utils.py | 6 +++--- v4-client-py/v4_client_py/clients/constants.py | 3 +++ v4-client-py/v4_client_py/clients/modules/post.py | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/v4-client-py/.gitignore b/v4-client-py/.gitignore index b6e47617..3efd499f 100644 --- a/v4-client-py/.gitignore +++ b/v4-client-py/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# IDE +.idea/ diff --git a/v4-client-py/v4_client_py/chain/aerial/client/utils.py b/v4-client-py/v4_client_py/chain/aerial/client/utils.py index ce6886f2..cffb8f7f 100644 --- a/v4-client-py/v4_client_py/chain/aerial/client/utils.py +++ b/v4-client-py/v4_client_py/chain/aerial/client/utils.py @@ -3,7 +3,7 @@ from datetime import timedelta from typing import Any, Callable, List, Optional, Union -from v4_client_py.clients.constants import BroadcastMode +from v4_client_py.clients.constants import BroadcastMode, DEFAULT_TOKEN from v4_proto.cosmos.base.query.v1beta1.pagination_pb2 import PageRequest @@ -18,7 +18,7 @@ def prepare_and_broadcast_basic_transaction( gas_limit: Optional[int] = None, memo: Optional[str] = None, broadcast_mode: BroadcastMode = None, - fee: Optional[str] = "5000dv4tnt", + fee: Optional[int] = 5000, ) -> SubmittedTx: """Prepare and broadcast basic transaction. @@ -53,7 +53,7 @@ def prepare_and_broadcast_basic_transaction( # 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}{DEFAULT_TOKEN}", gas_limit=gas_limit, memo=memo, ) diff --git a/v4-client-py/v4_client_py/clients/constants.py b/v4-client-py/v4_client_py/clients/constants.py index 4a1ba0ba..e8bb4543 100644 --- a/v4-client-py/v4_client_py/clients/constants.py +++ b/v4-client-py/v4_client_py/clients/constants.py @@ -96,6 +96,9 @@ BECH32_PREFIX = 'dydx' +# ------------ DEFAULT TOKEN ------------ +DEFAULT_TOKEN = "dv4tnt" + class BroadcastMode(Enum): BroadcastTxSync = 0 BroadcastTxCommit = 1 diff --git a/v4-client-py/v4_client_py/clients/modules/post.py b/v4-client-py/v4_client_py/clients/modules/post.py index c78d7ec5..f77a91bb 100644 --- a/v4-client-py/v4_client_py/clients/modules/post.py +++ b/v4-client-py/v4_client_py/clients/modules/post.py @@ -57,7 +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="0dv4tnt" if zeroFee else "5000dv4tnt", + fee=0 if zeroFee else 5000, ) def place_order( From 1d0bac4805a6a34abbc29a84c02785ec1f502309 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Thu, 12 Oct 2023 14:59:37 -0700 Subject: [PATCH 4/5] update --- .../v4_client_py/chain/aerial/client/utils.py | 8 +++++--- .../v4_client_py/chain/aerial/config.py | 17 ++++++++++++++++- v4-client-py/v4_client_py/clients/constants.py | 3 --- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/v4-client-py/v4_client_py/chain/aerial/client/utils.py b/v4-client-py/v4_client_py/chain/aerial/client/utils.py index cffb8f7f..e711b6a7 100644 --- a/v4-client-py/v4_client_py/chain/aerial/client/utils.py +++ b/v4-client-py/v4_client_py/chain/aerial/client/utils.py @@ -3,7 +3,7 @@ from datetime import timedelta from typing import Any, Callable, List, Optional, Union -from v4_client_py.clients.constants import BroadcastMode, DEFAULT_TOKEN +from v4_client_py.clients.constants import BroadcastMode from v4_proto.cosmos.base.query.v1beta1.pagination_pb2 import PageRequest @@ -18,7 +18,7 @@ def prepare_and_broadcast_basic_transaction( gas_limit: Optional[int] = None, memo: Optional[str] = None, broadcast_mode: BroadcastMode = None, - fee: Optional[int] = 5000, + fee: int = 5000, ) -> SubmittedTx: """Prepare and broadcast basic transaction. @@ -28,6 +28,8 @@ 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 :return: broadcast transaction """ @@ -53,7 +55,7 @@ def prepare_and_broadcast_basic_transaction( # 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=f"{fee}{DEFAULT_TOKEN}", + fee=f"{fee}{client.network_config.fee_denomination}", gas_limit=gas_limit, memo=memo, ) diff --git a/v4-client-py/v4_client_py/chain/aerial/config.py b/v4-client-py/v4_client_py/chain/aerial/config.py index 3e8ff627..3adf9db7 100644 --- a/v4-client-py/v4_client_py/chain/aerial/config.py +++ b/v4-client-py/v4_client_py/chain/aerial/config.py @@ -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. @@ -93,7 +108,7 @@ def fetchai_stable_testnet(cls): :return: fetchai stable testnet. For now dorado is fetchai stable testnet. """ - return cls.fetchai_dorado_testnet() + return cls.fetch_dydx_testnet() @classmethod def fetchai_mainnet(cls) -> "NetworkConfig": diff --git a/v4-client-py/v4_client_py/clients/constants.py b/v4-client-py/v4_client_py/clients/constants.py index e8bb4543..4a1ba0ba 100644 --- a/v4-client-py/v4_client_py/clients/constants.py +++ b/v4-client-py/v4_client_py/clients/constants.py @@ -96,9 +96,6 @@ BECH32_PREFIX = 'dydx' -# ------------ DEFAULT TOKEN ------------ -DEFAULT_TOKEN = "dv4tnt" - class BroadcastMode(Enum): BroadcastTxSync = 0 BroadcastTxCommit = 1 From 55c10c9c1147ddd999722ce66110e8bc05d688b8 Mon Sep 17 00:00:00 2001 From: Will Liu Date: Fri, 13 Oct 2023 10:35:05 -0700 Subject: [PATCH 5/5] address cmts --- v4-client-py/v4_client_py/chain/aerial/client/utils.py | 2 +- v4-client-py/v4_client_py/chain/aerial/config.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/v4-client-py/v4_client_py/chain/aerial/client/utils.py b/v4-client-py/v4_client_py/chain/aerial/client/utils.py index e711b6a7..a4ed6ebc 100644 --- a/v4-client-py/v4_client_py/chain/aerial/client/utils.py +++ b/v4-client-py/v4_client_py/chain/aerial/client/utils.py @@ -29,7 +29,7 @@ def prepare_and_broadcast_basic_transaction( :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 + :param fee: Transaction fee, defaults to 5000. Denomination is determined by the network config. :return: broadcast transaction """ diff --git a/v4-client-py/v4_client_py/chain/aerial/config.py b/v4-client-py/v4_client_py/chain/aerial/config.py index 3adf9db7..18732289 100644 --- a/v4-client-py/v4_client_py/chain/aerial/config.py +++ b/v4-client-py/v4_client_py/chain/aerial/config.py @@ -103,10 +103,10 @@ 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.fetch_dydx_testnet() @@ -144,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()