From 8f0f19d953b1f70a9875ee3e1b18e2567885625b Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 02:12:52 +0200 Subject: [PATCH 01/18] feat: katana -> starknet-devnet --- .env.example | 2 +- .github/workflows/checks.yml | 2 +- poetry.lock | 11 +++++------ pragma/tests/api_client_test.py | 7 +++---- pragma/tests/client_test.py | 2 +- pragma/tests/constants.py | 8 ++++---- pragma/tests/fetchers_test.py | 6 +++--- pragma/tests/fixtures/devnet.py | 28 ++++++++++++++-------------- pragma/tests/update_client_test.py | 4 ++-- pyproject.toml | 2 +- stagecoach/jobs/tests/conftest.py | 4 ++-- 11 files changed, 37 insertions(+), 39 deletions(-) diff --git a/.env.example b/.env.example index bbb851af..4e426bcb 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ KAIKO_API_KEY= -FORK_NETWORK=mainnet +NETWORK_FORK=mainnet TESTNET_ACCOUNT_ADDRESS= TESTNET_PRIVATE_KEY= \ No newline at end of file diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c0f9c8b4..b72a14ba 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -151,7 +151,7 @@ jobs: - name: Run tests env: KAIKO_API_KEY: ${{ secrets.KAIKO_API_KEY }} - FORK_NETWORK: mainnet + NETWORK_FORK: mainnet TESTNET_ACCOUNT_ADDRESS: ${{ secrets.TESTNET_ACCOUNT_ADDRESS }} TESTNET_PRIVATE_KEY: ${{ secrets.TESTNET_PRIVATE_KEY }} run: | diff --git a/poetry.lock b/poetry.lock index 2ad09aa0..0bdd631c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "aiohttp" @@ -2509,7 +2509,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -2904,12 +2903,12 @@ files = [ [[package]] name = "starknet-py" -version = "0.20.0" +version = "0.22.0" description = "A python SDK for Starknet" optional = false -python-versions = ">=3.8,<3.13" +python-versions = "<3.13,>=3.8" files = [ - {file = "starknet_py-0.20.0.tar.gz", hash = "sha256:b144775e5ba175f66e404a990bbcec73c4e24ce8c8d6e434a393d20aa7386c0b"}, + {file = "starknet_py-0.22.0.tar.gz", hash = "sha256:d94eef6a4bdb69dfc56036b8a7072a81df30948a72b96dd38184c69223ff396c"}, ] [package.dependencies] @@ -3404,4 +3403,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.10" -content-hash = "3aa53b35e8dec61cd22c7073aa09fc1bc54cc63c40f90773d86541dfc556f8b9" +content-hash = "cee7fa97a7021cc265d94354f3eafbceace73f6865b0ca71fece4c511aaf566f" diff --git a/pragma/tests/api_client_test.py b/pragma/tests/api_client_test.py index c0cef345..1229e3de 100644 --- a/pragma/tests/api_client_test.py +++ b/pragma/tests/api_client_test.py @@ -39,11 +39,11 @@ def forked_client(request, module_mocker, pytestconfig) -> Client: rpc_url = RPC_URLS[network][random.randint(0, len(RPC_URLS[network]) - 1)] command = [ - "katana", - "--rpc-url", + "starknet-devnet", + "--fork-network", str(rpc_url), "--chain-id", - "SN_MAIN", + "MAINNET", "--host", "127.0.0.1", "--port", @@ -52,7 +52,6 @@ def forked_client(request, module_mocker, pytestconfig) -> Client: str(1), "--seed", str(1), - "--disable-fee", ] if block_number is not None: print(f"forking katana at block {block_number}") diff --git a/pragma/tests/client_test.py b/pragma/tests/client_test.py index 0a573255..5e9c6498 100644 --- a/pragma/tests/client_test.py +++ b/pragma/tests/client_test.py @@ -77,7 +77,7 @@ async def declare_deploy_oracle( ], auto_estimate=True, ) - await deploy_result.wait_for_acceptance() + # await deploy_result.wait_for_acceptance() return declare_result, deploy_result, deploy_result_registry diff --git a/pragma/tests/constants.py b/pragma/tests/constants.py index 284e7848..a82184de 100644 --- a/pragma/tests/constants.py +++ b/pragma/tests/constants.py @@ -40,10 +40,10 @@ def find_repo_root(start_directory: Path) -> Path: # -------------------------------- TESTNET ------------------------------------- TESTNET_ACCOUNT_PRIVATE_KEY = ( - "0x100801800000000310080180000000010030000000000005106801800206800" + "0xc10662b7b247c7cecf7e8a30726cff12" ) TESTNET_ACCOUNT_ADDRESS = ( - "0x4d75495e10ee26cae76478b6e491646ff0a10e0a062db1555131e47b07b7d24" + "0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201" ) # 0x61910356c5adf66efb65ec3df5d07a6e5e6e7c8b59f15a13eda7a34c8d1ecc4 @@ -72,10 +72,10 @@ def find_repo_root(start_directory: Path) -> Path: # ----------------------------------------------------------------------------- DEVNET_PRE_DEPLOYED_ACCOUNT_ADDRESS = ( - "0x4d75495e10ee26cae76478b6e491646ff0a10e0a062db1555131e47b07b7d24" + "0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201" ) DEVNET_PRE_DEPLOYED_ACCOUNT_PRIVATE_KEY = ( - "0x100801800000000310080180000000010030000000000005106801800206800" + "0xc10662b7b247c7cecf7e8a30726cff12" ) MAX_FEE = int(1e16) diff --git a/pragma/tests/fetchers_test.py b/pragma/tests/fetchers_test.py index e3def9f0..88c7b7cf 100644 --- a/pragma/tests/fetchers_test.py +++ b/pragma/tests/fetchers_test.py @@ -49,8 +49,8 @@ def forked_client(request) -> Client: rpc_url = RPC_URLS[network][random.randint(0, len(RPC_URLS[network]) - 1)] command = [ - "katana", - "--rpc-url", + "starknet-devnet", + "--fork-network", str(rpc_url), "--host", "127.0.0.1", @@ -60,7 +60,7 @@ def forked_client(request) -> Client: str(1), "--seed", str(1), - "--disable-fee", + , ] if block_number is not None: print(f"forking katana at block {block_number}") diff --git a/pragma/tests/fixtures/devnet.py b/pragma/tests/fixtures/devnet.py index 0457e82a..7a37ac1e 100644 --- a/pragma/tests/fixtures/devnet.py +++ b/pragma/tests/fixtures/devnet.py @@ -53,9 +53,9 @@ def fork_start_devnet(): def start_devnet_command_unix(devnet_port: int) -> List[str]: command = [ - "katana", + "starknet-devnet", "--chain-id", - "SN_MAIN", + "MAINNET", "--host", "127.0.0.1", "--port", @@ -64,7 +64,7 @@ def start_devnet_command_unix(devnet_port: int) -> List[str]: str(1), "--seed", str(1), - "--disable-fee", + ] return command @@ -72,9 +72,9 @@ def start_devnet_command_unix(devnet_port: int) -> List[str]: def start_devnet_command_windows(devnet_port: int) -> List[str]: return [ "wsl", - "katana", + "starknet-devnet", "--chain-id", - "SN_MAIN", + "MAINNET", "--host", "127.0.0.1", "--port", @@ -87,12 +87,12 @@ def start_devnet_command_windows(devnet_port: int) -> List[str]: def start_fork_devnet_command_unix(devnet_port: int) -> List[str]: - fork_network = os.getenv("FORK_NETWORK") + fork_network = os.getenv("NETWORK_FORK") rpc_url = RPC_URLS[fork_network][random.randint(0, len(RPC_URLS[fork_network]) - 1)] command = [ - "katana", + "starknet-devnet", "--chain-id", - "SN_MAIN", + "MAINNET", "--host", "127.0.0.1", "--port", @@ -101,24 +101,24 @@ def start_fork_devnet_command_unix(devnet_port: int) -> List[str]: str(1), "--seed", str(1), - "--rpc-url", + "--fork-network", str(rpc_url), - "--disable-fee", + ] return command def start_fork_devnet_command_windows(devnet_port: int) -> List[str]: - fork_network = os.getenv("FORK_NETWORK") + fork_network = os.getenv("NETWORK_FORK") rpc_url = RPC_URLS[fork_network][random.randint(0, len(RPC_URLS[fork_network]) - 1)] return [ "wsl", - "katana", + "starknet-devnet", "--chain-id", - "SN_MAIN", - "--rpc-url", + "MAINNET", + "--fork-network", str(rpc_url), "--port", str(devnet_port), diff --git a/pragma/tests/update_client_test.py b/pragma/tests/update_client_test.py index d7501f43..179b909a 100644 --- a/pragma/tests/update_client_test.py +++ b/pragma/tests/update_client_test.py @@ -35,7 +35,7 @@ async def pragma_fork_client( address_and_private_key: Tuple[str, str], ) -> PragmaClient: # TODO(#000): refactor this - fork_network = os.getenv("FORK_NETWORK") + fork_network = os.getenv("NETWORK_FORK") deployments = get_deployments( fork_network if fork_network != "devnet" else "mainnet" ) @@ -86,7 +86,7 @@ async def test_update_oracle( pragma_fork_client: PragmaClient, declare_oracle: DeclareResult ): # TODO(#000): refactor this - fork_network = os.getenv("FORK_NETWORK") + fork_network = os.getenv("NETWORK_FORK") deployments = get_deployments( fork_network if fork_network != "devnet" else "sepolia" ) diff --git a/pyproject.toml b/pyproject.toml index bd0857be..25764bae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ packages = [{ include = "pragma" }] [tool.poetry.dependencies] python = ">=3.9,<3.10" -"starknet.py" = "0.20.0" +"starknet.py" = "0.22.0" cairo-lang = "^0.12" typer = "0.6.1" deprecated = "^1.2.14" diff --git a/stagecoach/jobs/tests/conftest.py b/stagecoach/jobs/tests/conftest.py index 72ef29f2..1038ff6f 100644 --- a/stagecoach/jobs/tests/conftest.py +++ b/stagecoach/jobs/tests/conftest.py @@ -45,8 +45,8 @@ def devnet_node(module_mocker, port) -> str: rpc_url = RPC_URLS["testnet"][random.randint(0, len(RPC_URLS["testnet"]) - 1)] command = [ - "katana", - "--rpc-url", + "starknet-devnet", + "--fork-network", str(rpc_url), "--host", "127.0.0.1", From 0c4e74a11f222b0bccda0187093a30260845eb17 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 02:25:10 +0200 Subject: [PATCH 02/18] feat: CI --- .github/workflows/checks.yml | 14 +++++++------- pragma/tests/fixtures/misc.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b72a14ba..d2ea65ca 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -132,15 +132,15 @@ jobs: - name: Install rust run: | curl https://sh.rustup.rs -sSf | sh -s -- -y + source $HOME/.cargo/env - - name: Install dojoup + - name: Verify Rust and Cargo installation run: | - curl -L https://install.dojoengine.org | bash - - - name: Install dojo - run: |- - /home/runner/.config/.dojo/bin/dojoup -v 0.6.1-alpha.3 - sudo mv /home/runner/.config/.dojo/bin/katana /usr/local/bin/ + rustc --version + cargo --version + + - name: Install starknet-devnet + run: cargo install starknet-devnet # ====================== RUN TESTS ====================== # diff --git a/pragma/tests/fixtures/misc.py b/pragma/tests/fixtures/misc.py index 77281f73..75b606f3 100644 --- a/pragma/tests/fixtures/misc.py +++ b/pragma/tests/fixtures/misc.py @@ -14,7 +14,7 @@ def pytest_addoption(parser): action="store", default="", help="The block number to fork from. See: " - "https://book.dojoengine.org/toolchain/katana/reference.html", + "https://0xspaceshard.github.io/starknet-devnet-rs/docs/forking", ) parser.addoption( "--client", From 8a73503236e2e9180c706636e4e1fefc71cab06e Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 02:25:23 +0200 Subject: [PATCH 03/18] feat: comments --- CONTRIBUTING.md | 13 ++++++++----- pragma/tests/fetchers_test.py | 5 ++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 669ce724..f0ecddff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,14 +13,17 @@ poetry install ## Running Tests Locally -1. Install katana +1. Install Rust ```shell -curl -L https://install.dojoengine.org | bash -source /Users//.zshenv -dojoup +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -2. Now, you can run tests: +2. Install Starknet-devnet +```shell +cargo install starknet-devnet +``` + +3. Now, you can run tests: ```shell coverage run -m pytest --net=devnet --client=full_node -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError pragma/tests ``` diff --git a/pragma/tests/fetchers_test.py b/pragma/tests/fetchers_test.py index 88c7b7cf..fc41a6ab 100644 --- a/pragma/tests/fetchers_test.py +++ b/pragma/tests/fetchers_test.py @@ -38,7 +38,7 @@ def forked_client(request) -> Client: """ - This module-scope fixture prepares a forked katana + This module-scope fixture prepares a forked starknet client for e2e testing. :return: a starknet Client @@ -60,10 +60,9 @@ def forked_client(request) -> Client: str(1), "--seed", str(1), - , ] if block_number is not None: - print(f"forking katana at block {block_number}") + print(f"forking starknet at block {block_number}") command.extend(["--fork-block-number", str(block_number)]) subprocess.Popen(command) time.sleep(10) From 3faaaf2d696859644097a4c33898a140efd14b9a Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 07:42:44 +0200 Subject: [PATCH 04/18] fix: vrf tests --- pragma/core/mixins/randomness.py | 2 +- pragma/tests/vrf_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pragma/core/mixins/randomness.py b/pragma/core/mixins/randomness.py index a12bd707..14bc1894 100644 --- a/pragma/core/mixins/randomness.py +++ b/pragma/core/mixins/randomness.py @@ -405,7 +405,7 @@ async def handle_random( if is_pending else await self.full_node_client.get_block(block_number="latest") ) - block_hash = block.parent_block_hash + block_hash = block.parent_hash seed = ( event.request_id.to_bytes(8, sys.byteorder) diff --git a/pragma/tests/vrf_test.py b/pragma/tests/vrf_test.py index 0ab6f638..e6f736a7 100644 --- a/pragma/tests/vrf_test.py +++ b/pragma/tests/vrf_test.py @@ -309,7 +309,7 @@ async def test_fails_gas_limit( assert pending_reqs == [] status = await vrf_pragma_client.get_request_status(caller_address, 3) - assert status.variant == "OUT_OF_GAS" + assert status.variant == "REFUNDED" balance_after = await vrf_pragma_client.get_balance(caller_address) @@ -329,7 +329,7 @@ async def test_balance_evolution( request_id = 4 seed = 1 - callback_fee_limit = 3248900000000000 + callback_fee_limit = 59600000000000 callback_address = example_randomness.address publish_delay = 0 calldata = [0x1234, 0x1434, 314141] From dca1cf493bdb0ea3c15ab878399ce6f59aa5ebad Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 07:46:24 +0200 Subject: [PATCH 05/18] fix: format code --- pragma/tests/constants.py | 8 ++------ pragma/tests/fixtures/devnet.py | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pragma/tests/constants.py b/pragma/tests/constants.py index a82184de..6738c550 100644 --- a/pragma/tests/constants.py +++ b/pragma/tests/constants.py @@ -39,9 +39,7 @@ def find_repo_root(start_directory: Path) -> Path: # -------------------------------- TESTNET ------------------------------------- -TESTNET_ACCOUNT_PRIVATE_KEY = ( - "0xc10662b7b247c7cecf7e8a30726cff12" -) +TESTNET_ACCOUNT_PRIVATE_KEY = "0xc10662b7b247c7cecf7e8a30726cff12" TESTNET_ACCOUNT_ADDRESS = ( "0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201" ) @@ -74,9 +72,7 @@ def find_repo_root(start_directory: Path) -> Path: DEVNET_PRE_DEPLOYED_ACCOUNT_ADDRESS = ( "0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201" ) -DEVNET_PRE_DEPLOYED_ACCOUNT_PRIVATE_KEY = ( - "0xc10662b7b247c7cecf7e8a30726cff12" -) +DEVNET_PRE_DEPLOYED_ACCOUNT_PRIVATE_KEY = "0xc10662b7b247c7cecf7e8a30726cff12" MAX_FEE = int(1e16) diff --git a/pragma/tests/fixtures/devnet.py b/pragma/tests/fixtures/devnet.py index 7a37ac1e..b1bd28dc 100644 --- a/pragma/tests/fixtures/devnet.py +++ b/pragma/tests/fixtures/devnet.py @@ -64,7 +64,6 @@ def start_devnet_command_unix(devnet_port: int) -> List[str]: str(1), "--seed", str(1), - ] return command @@ -103,7 +102,6 @@ def start_fork_devnet_command_unix(devnet_port: int) -> List[str]: str(1), "--fork-network", str(rpc_url), - ] return command From 7bcbe88f8f9c7cd58eb437dd367f650cad5406ba Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 09:45:38 +0200 Subject: [PATCH 06/18] fix :vrf constants definition --- pragma/tests/constants.py | 2 +- pragma/tests/vrf_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pragma/tests/constants.py b/pragma/tests/constants.py index 6738c550..96e08949 100644 --- a/pragma/tests/constants.py +++ b/pragma/tests/constants.py @@ -163,7 +163,7 @@ def find_repo_root(start_directory: Path) -> Path: ORACLE_DECIMALS = 8 ORACLE_FEE_PRICE = 100000000000 MAX_PREMIUM_FEE = 100000000 -ESTIMATED_FEE_MULTIPLIER = 1.5 +ESTIMATED_FEE_MULTIPLIER = 2.5 SAMPLE_SPOT_ENTRIES = [ SpotEntry( pair_id="ETH/USD", diff --git a/pragma/tests/vrf_test.py b/pragma/tests/vrf_test.py index e6f736a7..115f3182 100644 --- a/pragma/tests/vrf_test.py +++ b/pragma/tests/vrf_test.py @@ -329,7 +329,7 @@ async def test_balance_evolution( request_id = 4 seed = 1 - callback_fee_limit = 59600000000000 + callback_fee_limit = 49600000000000 callback_address = example_randomness.address publish_delay = 0 calldata = [0x1234, 0x1434, 314141] From e8a62a8d80a876202bdb8854163231b54e6867ab Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 09:46:54 +0200 Subject: [PATCH 07/18] feat: support for v3 transactions --- pragma/core/contract.py | 23 ++++++--- pragma/core/mixins/oracle.py | 51 +++++++++++++------ pragma/tests/api_client_test.py | 4 +- pragma/tests/client_test.py | 16 +++--- pragma/tests/publisher_test.py | 6 +-- stagecoach/jobs/publishers/custom/app.py | 2 +- .../jobs/publishers/starknet_publisher/app.py | 6 +++ 7 files changed, 73 insertions(+), 35 deletions(-) diff --git a/pragma/core/contract.py b/pragma/core/contract.py index 723c3896..ef39424c 100644 --- a/pragma/core/contract.py +++ b/pragma/core/contract.py @@ -2,7 +2,7 @@ from starknet_py.contract import Contract as StarknetContract from starknet_py.contract import ContractFunction, InvokeResult -from starknet_py.net.client_models import SentTransactionResponse +from starknet_py.net.client_models import SentTransactionResponse, ResourceBounds class Contract(StarknetContract): @@ -21,6 +21,8 @@ async def invoke_( *args, max_fee: Optional[int] = None, auto_estimate: bool = False, + enable_strk_fees: Optional[bool] = False, + l1_resource_bounds : Optional[ResourceBounds] = None, callback: Optional[Callable[[SentTransactionResponse], None]] = None, **kwargs, ) -> InvokeResult: @@ -29,18 +31,25 @@ async def invoke_( This is useful for tracking the nonce changes """ - prepared_call = self.prepare_invoke_v1(*args, **kwargs) + prepared_call = self.prepare_invoke_v3(*args, **kwargs) if enable_strk_fees else self.prepare_invoke_v1(*args,**kwargs) # transfer ownership to the prepared call self = prepared_call if max_fee is not None: self.max_fee = max_fee - transaction = await self.get_account.sign_invoke_v1( - calls=self, - max_fee=self.max_fee, - auto_estimate=auto_estimate, + transaction = ( + await self.get_account.sign_invoke_v3( + calls=self, + l1_resource_bounds = l1_resource_bounds, + auto_estimate=auto_estimate, + ) + if enable_strk_fees + else await self.get_account.sign_invoke_v1( + calls=self, max_fee=max_fee, auto_estimate=auto_estimate + ) ) + response = await self._client.send_transaction(transaction) if callback: await callback(transaction.nonce, response.transaction_hash) @@ -59,4 +68,4 @@ async def invoke_( # patch contract function to use new invoke function -ContractFunction.invoke_v1 = invoke_ +ContractFunction.invoke = invoke_ diff --git a/pragma/core/mixins/oracle.py b/pragma/core/mixins/oracle.py index 8137b644..fb5bb3f9 100644 --- a/pragma/core/mixins/oracle.py +++ b/pragma/core/mixins/oracle.py @@ -8,6 +8,8 @@ from starknet_py.contract import InvokeResult from starknet_py.net.account.account import Account from starknet_py.net.client import Client +from starknet_py.net.client_models import ResourceBounds + from pragma.core.contract import Contract from pragma.core.entry import Entry, FutureEntry, SpotEntry @@ -43,6 +45,9 @@ async def publish_spot_entry( publisher: int, volume: int = 0, max_fee: int = int(1e18), + enable_strk_fees: Optional[bool] = False, + l1_resource_bounds: Optional[ResourceBounds] = None, + auto_estimate: Optional[bool] = False ) -> InvokeResult: if not self.is_user_client: raise AttributeError( @@ -50,7 +55,7 @@ async def publish_spot_entry( "You may do this by invoking " "self._setup_account_client(private_key, account_contract_address)" ) - invocation = await self.oracle.functions["publish_data"].invoke_v1( + invocation = await self.oracle.functions["publish_data"].invoke( new_entry={ "Spot": { "base": { @@ -64,6 +69,9 @@ async def publish_spot_entry( } }, max_fee=max_fee, + l1_resource_bounds = l1_resource_bounds, + auto_estimate = auto_estimate, + enable_strk_fees=enable_strk_fees ) return invocation @@ -72,6 +80,9 @@ async def publish_many( entries: List[Entry], pagination: Optional[int] = 40, max_fee=int(1e18), + enable_strk_fees: Optional[bool] = True, + l1_resource_bounds: Optional[ResourceBounds] = None, + auto_estimate: Optional[bool] = False ) -> List[InvokeResult]: if len(entries) == 0: logger.warning("Skipping publishing as entries array is empty") @@ -84,11 +95,12 @@ async def publish_many( index = 0 while index < len(serialized_spot_entries): entries_subset = serialized_spot_entries[index : index + pagination] - invocation = await self.oracle.functions[ - "publish_data_entries" - ].invoke_v1( + invocation = await self.oracle.functions["publish_data_entries"].invoke( new_entries=[{"Spot": entry} for entry in entries_subset], + enable_strk_fees=enable_strk_fees, max_fee=max_fee, + l1_resource_bounds = l1_resource_bounds, + auto_estimate= auto_estimate, callback=self.track_nonce, ) index += pagination @@ -100,9 +112,12 @@ async def publish_many( hex(invocation.hash), ) elif len(serialized_spot_entries) > 0: - invocation = await self.oracle.functions["publish_data_entries"].invoke_v1( + invocation = await self.oracle.functions["publish_data_entries"].invoke( new_entries=[{"Spot": entry} for entry in serialized_spot_entries], max_fee=max_fee, + enable_strk_fees=enable_strk_fees, + l1_resource_bounds = l1_resource_bounds, + auto_estimate= auto_estimate, callback=self.track_nonce, ) invocations.append(invocation) @@ -119,11 +134,12 @@ async def publish_many( index = 0 while index < len(serialized_future_entries): entries_subset = serialized_future_entries[index : index + pagination] - invocation = await self.oracle.functions[ - "publish_data_entries" - ].invoke_v1( + invocation = await self.oracle.functions["publish_data_entries"].invoke( new_entries=[{"Future": entry} for entry in entries_subset], max_fee=max_fee, + enable_strk_fees=enable_strk_fees, + l1_resource_bounds = l1_resource_bounds, + auto_estimate= auto_estimate, callback=self.track_nonce, ) index += pagination @@ -135,9 +151,12 @@ async def publish_many( hex(invocation.hash), ) elif len(serialized_future_entries) > 0: - invocation = await self.oracle.functions["publish_data_entries"].invoke_v1( + invocation = await self.oracle.functions["publish_data_entries"].invoke( new_entries=[{"Future": entry} for entry in serialized_future_entries], max_fee=max_fee, + enable_strk_fees=enable_strk_fees, + l1_resource_bounds = l1_resource_bounds, + auto_estimate= auto_estimate, callback=self.track_nonce, ) invocations.append(invocation) @@ -296,7 +315,7 @@ async def set_checkpoint( "You may do this by invoking " "self._setup_account_client(private_key, account_contract_address)" ) - invocation = await self.oracle.functions["set_checkpoint"].invoke_v1( + invocation = await self.oracle.functions["set_checkpoint"].invoke( DataType(DataTypes.SPOT, pair_id, None).serialize(), aggregation_mode.serialize(), max_fee=max_fee, @@ -317,7 +336,7 @@ async def set_future_checkpoint( "You may do this by invoking " "self._setup_account_client(private_key, account_contract_address)" ) - invocation = await self.oracle.functions["set_checkpoint"].invoke_v1( + invocation = await self.oracle.functions["set_checkpoint"].invoke( DataType(DataTypes.FUTURE, pair_id, expiry_timestamp).serialize(), aggregation_mode.serialize(), max_fee=max_fee, @@ -345,7 +364,7 @@ async def set_future_checkpoints( index = 0 while index < len(pair_ids): pair_ids_subset = pair_ids[index : index + pagination] - invocation = await self.oracle.functions["set_checkpoints"].invoke_v1( + invocation = await self.oracle.functions["set_checkpoints"].invoke( pair_ids_subset, expiry_timestamps, aggregation_mode.serialize(), @@ -359,7 +378,7 @@ async def set_future_checkpoints( hex(invocation.hash), ) else: - invocation = await self.oracle.functions["set_checkpoints"].invoke_v1( + invocation = await self.oracle.functions["set_checkpoints"].invoke( pair_ids, expiry_timestamps, aggregation_mode.serialize(), @@ -387,7 +406,7 @@ async def set_checkpoints( index = 0 while index < len(pair_ids): pair_ids_subset = pair_ids[index : index + pagination] - invocation = await self.oracle.set_checkpoints.invoke_v1( + invocation = await self.oracle.set_checkpoints.invoke( [ DataType(DataTypes.SPOT, pair_id, None).serialize() for pair_id in pair_ids_subset @@ -403,7 +422,7 @@ async def set_checkpoints( hex(invocation.hash), ) else: - invocation = await self.oracle.set_checkpoints.invoke_v1( + invocation = await self.oracle.set_checkpoints.invoke( [ DataType(DataTypes.SPOT, pair_id, None).serialize() for pair_id in pair_ids @@ -423,7 +442,7 @@ async def update_oracle( implementation_hash: int, max_fee=int(1e18), ) -> InvokeResult: - invocation = await self.oracle.functions["upgrade"].invoke_v1( + invocation = await self.oracle.functions["upgrade"].invoke( implementation_hash, max_fee=max_fee, ) diff --git a/pragma/tests/api_client_test.py b/pragma/tests/api_client_test.py index 1229e3de..155e54f2 100644 --- a/pragma/tests/api_client_test.py +++ b/pragma/tests/api_client_test.py @@ -27,7 +27,7 @@ @pytest.fixture(scope="module") def forked_client(request, module_mocker, pytestconfig) -> Client: """ - This module-scope fixture prepares a forked katana + This module-scope fixture prepares a forked starknet client for e2e testing. :return: a starknet Client @@ -54,7 +54,7 @@ def forked_client(request, module_mocker, pytestconfig) -> Client: str(1), ] if block_number is not None: - print(f"forking katana at block {block_number}") + print(f"forking starknet at block {block_number}") command.extend(["--fork-block-number", str(block_number)]) subprocess.Popen(command) # pylint: disable=consider-using-with time.sleep(10) diff --git a/pragma/tests/client_test.py b/pragma/tests/client_test.py index 5e9c6498..39620b79 100644 --- a/pragma/tests/client_test.py +++ b/pragma/tests/client_test.py @@ -15,6 +15,8 @@ from pragma.core.utils import str_to_felt from pragma.tests.constants import CURRENCIES, PAIRS from pragma.tests.utils import read_contract, wait_for_acceptance +from starknet_py.net.client_models import ResourceBounds + PUBLISHER_NAME = "PRAGMA" @@ -216,7 +218,7 @@ async def test_client_oracle_mixin_spot(pragma_client: PragmaClient): ETH_PAIR, 200, timestamp + 10, SOURCE_1, publisher_name, volume=20 ) - invocations = await pragma_client.publish_many([spot_entry_1, spot_entry_2]) + invocations = await pragma_client.publish_many([spot_entry_1, spot_entry_2], auto_estimate= True) await invocations[len(invocations) - 1].wait_for_acceptance() # Fails for UNKNOWN source unknown_source = "UNKNOWN" @@ -246,7 +248,8 @@ async def test_client_oracle_mixin_spot(pragma_client: PragmaClient): ETH_PAIR, 100, timestamp + 450, SOURCE_1, publisher_name, volume=10 ) try: - invocations = await pragma_client.publish_many([spot_entry_future]) + invocations = await pragma_client.publish_many([spot_entry_future], l1_resource_bounds = ResourceBounds(max_price_per_unit=500 * 10**9, + max_amount=10**7)) except TransactionRevertedError as err: # err_msg = "Execution was reverted; failure reason: [0x54696d657374616d7020697320696e2074686520667574757265]" err_msg = "Unknown Starknet error" @@ -264,7 +267,7 @@ async def test_client_oracle_mixin_spot(pragma_client: PragmaClient): ETH_PAIR, 200, timestamp + 30, SOURCE_2, publisher_name, volume=20 ) - invocations = await pragma_client.publish_many([spot_entry_1, spot_entry_2]) + invocations = await pragma_client.publish_many([spot_entry_1, spot_entry_2], auto_estimate= True) await invocations[len(invocations) - 1].wait_for_acceptance() res = await pragma_client.get_spot(ETH_PAIR) assert res.price == 150 @@ -301,7 +304,7 @@ async def test_client_oracle_mixin_future(pragma_client: PragmaClient): volume=20000, ) - invocations = await pragma_client.publish_many([future_entry_1, future_entry_2]) + invocations = await pragma_client.publish_many([future_entry_1, future_entry_2], auto_estimate= True) await invocations[len(invocations) - 1].wait_for_acceptance() # Check entries entries = await pragma_client.get_future_entries( @@ -332,7 +335,7 @@ async def test_client_oracle_mixin_future(pragma_client: PragmaClient): volume=20, ) - invocations = await pragma_client.publish_many([future_entry_1, future_entry_2]) + invocations = await pragma_client.publish_many([future_entry_1, future_entry_2], auto_estimate = True) await invocations[len(invocations) - 1].wait_for_acceptance() res = await pragma_client.get_future(ETH_PAIR, expiry_timestamp) assert res.price == 150 @@ -351,7 +354,8 @@ async def test_client_oracle_mixin_future(pragma_client: PragmaClient): volume=10, ) try: - await pragma_client.publish_many([future_entry_future]) + await pragma_client.publish_many([future_entry_future],l1_resource_bounds = ResourceBounds(max_price_per_unit=500 * 10**9, + max_amount=10**7)) except TransactionRevertedError as err: # err_msg = "Execution was reverted; failure reason: [0x54696d657374616d7020697320696e2074686520667574757265]" err_msg = "Unknown Starknet error" diff --git a/pragma/tests/publisher_test.py b/pragma/tests/publisher_test.py index 9aa048b0..a96be1af 100644 --- a/pragma/tests/publisher_test.py +++ b/pragma/tests/publisher_test.py @@ -91,7 +91,7 @@ async def test_publisher_client_spot(pragma_client: PragmaClient): # Publish SPOT data print(data) - await publisher.publish_many(data, pagination=PAGINATION) + await publisher.publish_many(data, pagination=PAGINATION, auto_estimate=True) @pytest.mark.asyncio @@ -118,7 +118,7 @@ async def test_publisher_client_future(pragma_client: PragmaClient): d for d in data_async if isinstance(d, FutureEntry) ] print(data_list) - await publisher.publish_many(data_list, pagination=PAGINATION) + await publisher.publish_many(data_list, pagination=PAGINATION, auto_estimate=True) @pytest.mark.asyncio @@ -149,7 +149,7 @@ async def test_publisher_client_all_assets(pragma_client: PragmaClient): data = [d for d in data if isinstance(d, Entry)] print(data) - await publisher.publish_many(data, pagination=PAGINATION) + await publisher.publish_many(data, pagination=PAGINATION, auto_estimate=True) def asset_valid_data_type(data: Sequence[Entry], data_type: Entry): diff --git a/stagecoach/jobs/publishers/custom/app.py b/stagecoach/jobs/publishers/custom/app.py index d8680ef3..955e4422 100644 --- a/stagecoach/jobs/publishers/custom/app.py +++ b/stagecoach/jobs/publishers/custom/app.py @@ -62,7 +62,7 @@ async def publish_all(assets): # Use your own custom logic _entries = fetch_entries(assets) - await publisher_client.publish_many(_entries, max_fee=int(max_fee)) + await publisher_client.publish_many(_entries, max_fee=int(max_fee), auto_estimate=True) logger.info("Publishing the following entries:") for entry in _entries: diff --git a/stagecoach/jobs/publishers/starknet_publisher/app.py b/stagecoach/jobs/publishers/starknet_publisher/app.py index a7c63193..fe0eccdb 100644 --- a/stagecoach/jobs/publishers/starknet_publisher/app.py +++ b/stagecoach/jobs/publishers/starknet_publisher/app.py @@ -44,6 +44,7 @@ PAGINATION = os.environ.get("PAGINATION") RPC_URL = os.environ.get("RPC_URL") MAX_FEE = int(os.getenv("MAX_FEE", int(1e17))) +ENABLE_STRK_FEES = os.environ.get("ENABLE_STRK_FEES", "False") DEVIATION_THRESHOLD = float(os.getenv("DEVIATION_THRESHOLD", 0.01)) FREQUENCY_SECONDS = int(os.getenv("FREQUENCY_SECONDS", 60)) @@ -164,10 +165,15 @@ async def _handler(assets): _entries = await publisher_client.fetch() print("entries", _entries) + + enable_strk_fees = enable_strk_fees.lower() in ("true", "1", "yes") + + print(f"ENABLE_STRK_FEES is set to: {enable_strk_fees}") response = await publisher_client.publish_many( _entries, pagination=PAGINATION, max_fee=MAX_FEE, + auto_estimate= True # For safety or should we switch to l1_resource_bounds for cost ? ) print( From 3a6bdb911f4e7c1bd1e670d29ed953e9dd5a63fa Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 09:49:16 +0200 Subject: [PATCH 08/18] fix: Disable strk payments as default --- pragma/core/mixins/oracle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pragma/core/mixins/oracle.py b/pragma/core/mixins/oracle.py index fb5bb3f9..a28e776a 100644 --- a/pragma/core/mixins/oracle.py +++ b/pragma/core/mixins/oracle.py @@ -80,7 +80,7 @@ async def publish_many( entries: List[Entry], pagination: Optional[int] = 40, max_fee=int(1e18), - enable_strk_fees: Optional[bool] = True, + enable_strk_fees: Optional[bool] = False, l1_resource_bounds: Optional[ResourceBounds] = None, auto_estimate: Optional[bool] = False ) -> List[InvokeResult]: From 10fe69fb3798edba2f8e2fb8d3c03257bfa13e3a Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 10:05:59 +0200 Subject: [PATCH 09/18] fix: format code --- pragma/core/contract.py | 10 ++++-- pragma/core/mixins/oracle.py | 26 +++++++-------- pragma/tests/client_test.py | 32 ++++++++++++++----- stagecoach/jobs/publishers/custom/app.py | 4 ++- .../jobs/publishers/starknet_publisher/app.py | 2 +- 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/pragma/core/contract.py b/pragma/core/contract.py index ef39424c..d0596f70 100644 --- a/pragma/core/contract.py +++ b/pragma/core/contract.py @@ -22,7 +22,7 @@ async def invoke_( max_fee: Optional[int] = None, auto_estimate: bool = False, enable_strk_fees: Optional[bool] = False, - l1_resource_bounds : Optional[ResourceBounds] = None, + l1_resource_bounds: Optional[ResourceBounds] = None, callback: Optional[Callable[[SentTransactionResponse], None]] = None, **kwargs, ) -> InvokeResult: @@ -31,7 +31,11 @@ async def invoke_( This is useful for tracking the nonce changes """ - prepared_call = self.prepare_invoke_v3(*args, **kwargs) if enable_strk_fees else self.prepare_invoke_v1(*args,**kwargs) + prepared_call = ( + self.prepare_invoke_v3(*args, **kwargs) + if enable_strk_fees + else self.prepare_invoke_v1(*args, **kwargs) + ) # transfer ownership to the prepared call self = prepared_call @@ -41,7 +45,7 @@ async def invoke_( transaction = ( await self.get_account.sign_invoke_v3( calls=self, - l1_resource_bounds = l1_resource_bounds, + l1_resource_bounds=l1_resource_bounds, auto_estimate=auto_estimate, ) if enable_strk_fees diff --git a/pragma/core/mixins/oracle.py b/pragma/core/mixins/oracle.py index a28e776a..ee497110 100644 --- a/pragma/core/mixins/oracle.py +++ b/pragma/core/mixins/oracle.py @@ -47,7 +47,7 @@ async def publish_spot_entry( max_fee: int = int(1e18), enable_strk_fees: Optional[bool] = False, l1_resource_bounds: Optional[ResourceBounds] = None, - auto_estimate: Optional[bool] = False + auto_estimate: Optional[bool] = False, ) -> InvokeResult: if not self.is_user_client: raise AttributeError( @@ -69,9 +69,9 @@ async def publish_spot_entry( } }, max_fee=max_fee, - l1_resource_bounds = l1_resource_bounds, - auto_estimate = auto_estimate, - enable_strk_fees=enable_strk_fees + l1_resource_bounds=l1_resource_bounds, + auto_estimate=auto_estimate, + enable_strk_fees=enable_strk_fees, ) return invocation @@ -82,7 +82,7 @@ async def publish_many( max_fee=int(1e18), enable_strk_fees: Optional[bool] = False, l1_resource_bounds: Optional[ResourceBounds] = None, - auto_estimate: Optional[bool] = False + auto_estimate: Optional[bool] = False, ) -> List[InvokeResult]: if len(entries) == 0: logger.warning("Skipping publishing as entries array is empty") @@ -99,8 +99,8 @@ async def publish_many( new_entries=[{"Spot": entry} for entry in entries_subset], enable_strk_fees=enable_strk_fees, max_fee=max_fee, - l1_resource_bounds = l1_resource_bounds, - auto_estimate= auto_estimate, + l1_resource_bounds=l1_resource_bounds, + auto_estimate=auto_estimate, callback=self.track_nonce, ) index += pagination @@ -116,8 +116,8 @@ async def publish_many( new_entries=[{"Spot": entry} for entry in serialized_spot_entries], max_fee=max_fee, enable_strk_fees=enable_strk_fees, - l1_resource_bounds = l1_resource_bounds, - auto_estimate= auto_estimate, + l1_resource_bounds=l1_resource_bounds, + auto_estimate=auto_estimate, callback=self.track_nonce, ) invocations.append(invocation) @@ -138,8 +138,8 @@ async def publish_many( new_entries=[{"Future": entry} for entry in entries_subset], max_fee=max_fee, enable_strk_fees=enable_strk_fees, - l1_resource_bounds = l1_resource_bounds, - auto_estimate= auto_estimate, + l1_resource_bounds=l1_resource_bounds, + auto_estimate=auto_estimate, callback=self.track_nonce, ) index += pagination @@ -155,8 +155,8 @@ async def publish_many( new_entries=[{"Future": entry} for entry in serialized_future_entries], max_fee=max_fee, enable_strk_fees=enable_strk_fees, - l1_resource_bounds = l1_resource_bounds, - auto_estimate= auto_estimate, + l1_resource_bounds=l1_resource_bounds, + auto_estimate=auto_estimate, callback=self.track_nonce, ) invocations.append(invocation) diff --git a/pragma/tests/client_test.py b/pragma/tests/client_test.py index 39620b79..6613e9f3 100644 --- a/pragma/tests/client_test.py +++ b/pragma/tests/client_test.py @@ -218,7 +218,9 @@ async def test_client_oracle_mixin_spot(pragma_client: PragmaClient): ETH_PAIR, 200, timestamp + 10, SOURCE_1, publisher_name, volume=20 ) - invocations = await pragma_client.publish_many([spot_entry_1, spot_entry_2], auto_estimate= True) + invocations = await pragma_client.publish_many( + [spot_entry_1, spot_entry_2], auto_estimate=True + ) await invocations[len(invocations) - 1].wait_for_acceptance() # Fails for UNKNOWN source unknown_source = "UNKNOWN" @@ -248,8 +250,12 @@ async def test_client_oracle_mixin_spot(pragma_client: PragmaClient): ETH_PAIR, 100, timestamp + 450, SOURCE_1, publisher_name, volume=10 ) try: - invocations = await pragma_client.publish_many([spot_entry_future], l1_resource_bounds = ResourceBounds(max_price_per_unit=500 * 10**9, - max_amount=10**7)) + invocations = await pragma_client.publish_many( + [spot_entry_future], + l1_resource_bounds=ResourceBounds( + max_price_per_unit=500 * 10**9, max_amount=10**7 + ), + ) except TransactionRevertedError as err: # err_msg = "Execution was reverted; failure reason: [0x54696d657374616d7020697320696e2074686520667574757265]" err_msg = "Unknown Starknet error" @@ -267,7 +273,9 @@ async def test_client_oracle_mixin_spot(pragma_client: PragmaClient): ETH_PAIR, 200, timestamp + 30, SOURCE_2, publisher_name, volume=20 ) - invocations = await pragma_client.publish_many([spot_entry_1, spot_entry_2], auto_estimate= True) + invocations = await pragma_client.publish_many( + [spot_entry_1, spot_entry_2], auto_estimate=True + ) await invocations[len(invocations) - 1].wait_for_acceptance() res = await pragma_client.get_spot(ETH_PAIR) assert res.price == 150 @@ -304,7 +312,9 @@ async def test_client_oracle_mixin_future(pragma_client: PragmaClient): volume=20000, ) - invocations = await pragma_client.publish_many([future_entry_1, future_entry_2], auto_estimate= True) + invocations = await pragma_client.publish_many( + [future_entry_1, future_entry_2], auto_estimate=True + ) await invocations[len(invocations) - 1].wait_for_acceptance() # Check entries entries = await pragma_client.get_future_entries( @@ -335,7 +345,9 @@ async def test_client_oracle_mixin_future(pragma_client: PragmaClient): volume=20, ) - invocations = await pragma_client.publish_many([future_entry_1, future_entry_2], auto_estimate = True) + invocations = await pragma_client.publish_many( + [future_entry_1, future_entry_2], auto_estimate=True + ) await invocations[len(invocations) - 1].wait_for_acceptance() res = await pragma_client.get_future(ETH_PAIR, expiry_timestamp) assert res.price == 150 @@ -354,8 +366,12 @@ async def test_client_oracle_mixin_future(pragma_client: PragmaClient): volume=10, ) try: - await pragma_client.publish_many([future_entry_future],l1_resource_bounds = ResourceBounds(max_price_per_unit=500 * 10**9, - max_amount=10**7)) + await pragma_client.publish_many( + [future_entry_future], + l1_resource_bounds=ResourceBounds( + max_price_per_unit=500 * 10**9, max_amount=10**7 + ), + ) except TransactionRevertedError as err: # err_msg = "Execution was reverted; failure reason: [0x54696d657374616d7020697320696e2074686520667574757265]" err_msg = "Unknown Starknet error" diff --git a/stagecoach/jobs/publishers/custom/app.py b/stagecoach/jobs/publishers/custom/app.py index 955e4422..ae96a7c1 100644 --- a/stagecoach/jobs/publishers/custom/app.py +++ b/stagecoach/jobs/publishers/custom/app.py @@ -62,7 +62,9 @@ async def publish_all(assets): # Use your own custom logic _entries = fetch_entries(assets) - await publisher_client.publish_many(_entries, max_fee=int(max_fee), auto_estimate=True) + await publisher_client.publish_many( + _entries, max_fee=int(max_fee), auto_estimate=True + ) logger.info("Publishing the following entries:") for entry in _entries: diff --git a/stagecoach/jobs/publishers/starknet_publisher/app.py b/stagecoach/jobs/publishers/starknet_publisher/app.py index fe0eccdb..e0828639 100644 --- a/stagecoach/jobs/publishers/starknet_publisher/app.py +++ b/stagecoach/jobs/publishers/starknet_publisher/app.py @@ -173,7 +173,7 @@ async def _handler(assets): _entries, pagination=PAGINATION, max_fee=MAX_FEE, - auto_estimate= True # For safety or should we switch to l1_resource_bounds for cost ? + auto_estimate=True, # For safety or should we switch to l1_resource_bounds for cost ? ) print( From 484f95c252a9ceb0c07e61163a52cece62a8c9d3 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 11:31:38 +0200 Subject: [PATCH 10/18] fix: auto estimate excluded from v2 --- pragma/core/contract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pragma/core/contract.py b/pragma/core/contract.py index d0596f70..d3a6800c 100644 --- a/pragma/core/contract.py +++ b/pragma/core/contract.py @@ -50,7 +50,7 @@ async def invoke_( ) if enable_strk_fees else await self.get_account.sign_invoke_v1( - calls=self, max_fee=max_fee, auto_estimate=auto_estimate + calls=self, max_fee=max_fee ) ) From 225da8dadce4abfdcb54db9a154e8766ec339dcd Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 11:31:54 +0200 Subject: [PATCH 11/18] fix: format code --- pragma/core/contract.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pragma/core/contract.py b/pragma/core/contract.py index d3a6800c..c3d629ba 100644 --- a/pragma/core/contract.py +++ b/pragma/core/contract.py @@ -49,9 +49,7 @@ async def invoke_( auto_estimate=auto_estimate, ) if enable_strk_fees - else await self.get_account.sign_invoke_v1( - calls=self, max_fee=max_fee - ) + else await self.get_account.sign_invoke_v1(calls=self, max_fee=max_fee) ) response = await self._client.send_transaction(transaction) From 5c342aa886639710704b56be8e9fda885c6bc8dd Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 12:35:26 +0200 Subject: [PATCH 12/18] fix: ci --- pragma/tests/api_client_test.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pragma/tests/api_client_test.py b/pragma/tests/api_client_test.py index 155e54f2..96637e7c 100644 --- a/pragma/tests/api_client_test.py +++ b/pragma/tests/api_client_test.py @@ -249,13 +249,13 @@ async def test_async_api_client_spot_404_error(forked_client): + f"{quote_asset}/{base_asset}" ) mock.get(url, status=404) - result = await api_client.get_entry( - f'{asset["pair"][0]}/{asset["pair"][1]}' - ) - error = PragmaAPIError( - f"Unable to GET /v1/data for pair {quote_asset}/{base_asset}" - ) - assert result == error + # Use pytest.raises to capture the exception + with pytest.raises(PragmaAPIError) as exc_info: + await api_client.get_entry(f'{quote_asset}/{base_asset}') + + # Assert the error message or other details if needed + assert str(exc_info.value) == f"Unable to GET /v1/data for pair {quote_asset}/{base_asset}" + @mock.patch("time.time", mock.MagicMock(return_value=12345)) @@ -334,13 +334,13 @@ async def test_async_api_client_ohlc_404_error(forked_client): + f"{quote_asset}/{base_asset}" ) mock.get(url, status=404) - result = await api_client.api_get_ohlc( - f'{asset["pair"][0]}/{asset["pair"][1]}' + # Use pytest.raises to capture the exception + with pytest.raises(PragmaAPIError) as exc_info: + await api_client.api_get_ohlc(f'{asset["pair"][0]}/{asset["pair"][1]}' ) - error = PragmaAPIError( - f"Failed to get OHLC data for pair {quote_asset}/{base_asset}" - ) - assert result == error + + # Assert the error message or other details if needed + assert str(exc_info.value) == f"Failed to get OHLC data for pair {quote_asset}/{base_asset}" # @mock.patch("time.time", mock.MagicMock(return_value=12345)) From 8f265d7283a11c94fa8feaed93403298a6782ead Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 12:35:41 +0200 Subject: [PATCH 13/18] fix: format code --- pragma/tests/api_client_test.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pragma/tests/api_client_test.py b/pragma/tests/api_client_test.py index 96637e7c..ce920b0a 100644 --- a/pragma/tests/api_client_test.py +++ b/pragma/tests/api_client_test.py @@ -251,11 +251,13 @@ async def test_async_api_client_spot_404_error(forked_client): mock.get(url, status=404) # Use pytest.raises to capture the exception with pytest.raises(PragmaAPIError) as exc_info: - await api_client.get_entry(f'{quote_asset}/{base_asset}') + await api_client.get_entry(f"{quote_asset}/{base_asset}") # Assert the error message or other details if needed - assert str(exc_info.value) == f"Unable to GET /v1/data for pair {quote_asset}/{base_asset}" - + assert ( + str(exc_info.value) + == f"Unable to GET /v1/data for pair {quote_asset}/{base_asset}" + ) @mock.patch("time.time", mock.MagicMock(return_value=12345)) @@ -336,11 +338,13 @@ async def test_async_api_client_ohlc_404_error(forked_client): mock.get(url, status=404) # Use pytest.raises to capture the exception with pytest.raises(PragmaAPIError) as exc_info: - await api_client.api_get_ohlc(f'{asset["pair"][0]}/{asset["pair"][1]}' - ) + await api_client.api_get_ohlc(f'{asset["pair"][0]}/{asset["pair"][1]}') # Assert the error message or other details if needed - assert str(exc_info.value) == f"Failed to get OHLC data for pair {quote_asset}/{base_asset}" + assert ( + str(exc_info.value) + == f"Failed to get OHLC data for pair {quote_asset}/{base_asset}" + ) # @mock.patch("time.time", mock.MagicMock(return_value=12345)) From a804b23599a111569c69741de5ace9535d45cf20 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 12:42:49 +0200 Subject: [PATCH 14/18] fix: parameter --- stagecoach/jobs/publishers/starknet_publisher/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stagecoach/jobs/publishers/starknet_publisher/app.py b/stagecoach/jobs/publishers/starknet_publisher/app.py index e0828639..4c079ed6 100644 --- a/stagecoach/jobs/publishers/starknet_publisher/app.py +++ b/stagecoach/jobs/publishers/starknet_publisher/app.py @@ -173,6 +173,7 @@ async def _handler(assets): _entries, pagination=PAGINATION, max_fee=MAX_FEE, + enable_strk_fees=enable_strk_fees, auto_estimate=True, # For safety or should we switch to l1_resource_bounds for cost ? ) From 1993f7a82c261f545fb5a000cfc6dd24b881abe2 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 13:18:41 +0200 Subject: [PATCH 15/18] fix: revert comment --- pragma/tests/client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pragma/tests/client_test.py b/pragma/tests/client_test.py index 6613e9f3..146a11ed 100644 --- a/pragma/tests/client_test.py +++ b/pragma/tests/client_test.py @@ -79,7 +79,7 @@ async def declare_deploy_oracle( ], auto_estimate=True, ) - # await deploy_result.wait_for_acceptance() + await deploy_res#ult.wait_for_acceptance() return declare_result, deploy_result, deploy_result_registry From 807733561e1d57e9fc1e088cb55dac79af7d7939 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 13:19:12 +0200 Subject: [PATCH 16/18] fix: format code --- pragma/tests/client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pragma/tests/client_test.py b/pragma/tests/client_test.py index 146a11ed..d18fa209 100644 --- a/pragma/tests/client_test.py +++ b/pragma/tests/client_test.py @@ -79,7 +79,7 @@ async def declare_deploy_oracle( ], auto_estimate=True, ) - await deploy_res#ult.wait_for_acceptance() + await deploy_res # ult.wait_for_acceptance() return declare_result, deploy_result, deploy_result_registry From d58684b9261624097f0c7ff75513972f118ad229 Mon Sep 17 00:00:00 2001 From: JordyRo1 Date: Wed, 26 Jun 2024 13:58:18 +0200 Subject: [PATCH 17/18] fix: wait for acceptance --- pragma/tests/client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pragma/tests/client_test.py b/pragma/tests/client_test.py index d18fa209..bcccaf56 100644 --- a/pragma/tests/client_test.py +++ b/pragma/tests/client_test.py @@ -79,7 +79,7 @@ async def declare_deploy_oracle( ], auto_estimate=True, ) - await deploy_res # ult.wait_for_acceptance() + await deploy_result.wait_for_acceptance() return declare_result, deploy_result, deploy_result_registry From bc59f596525ab04a6318631dd54f859640ac350b Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 26 Jun 2024 14:04:29 +0200 Subject: [PATCH 18/18] Update stagecoach/jobs/publishers/starknet_publisher/app.py --- stagecoach/jobs/publishers/starknet_publisher/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stagecoach/jobs/publishers/starknet_publisher/app.py b/stagecoach/jobs/publishers/starknet_publisher/app.py index 4c079ed6..d06fbb60 100644 --- a/stagecoach/jobs/publishers/starknet_publisher/app.py +++ b/stagecoach/jobs/publishers/starknet_publisher/app.py @@ -166,7 +166,7 @@ async def _handler(assets): _entries = await publisher_client.fetch() print("entries", _entries) - enable_strk_fees = enable_strk_fees.lower() in ("true", "1", "yes") + enable_strk_fees = ENABLE_STRK_FEES.lower() in ("true", "1", "yes") print(f"ENABLE_STRK_FEES is set to: {enable_strk_fees}") response = await publisher_client.publish_many(