Closed czarcas7ic closed 1 week ago
The pool_swaps_per_block_inc.py
script for Osmosis network pool swaps has been enhanced to automate swapping across different pool types (GAMM, CL, CW) and manage concurrent transactions effectively. Key additions include wallet management functions, transaction generation, and broadcasting. Tweaks to constants and settings ensure efficient operation and concurrent execution.
File(s) | Change Summary |
---|---|
scripts/pool_swaps_per_block_inc.py |
Introduced new functions for creating, seeding wallets, handling transactions, and retrieving statuses. Updated various constants and settings related to pool types and transaction configuration. |
sequenceDiagram
participant User
participant Script
User ->> Script: Start script execution
Script ->> Blockchain: Retrieve status
alt Wallet Exists
Script ->> Blockchain: Get Account Info
else Wallet Missing
Script ->> Blockchain: Create Wallet
Script ->> Blockchain: Seed Wallet
end
Script ->> Blockchain: Get Pool Info
Script ->> Blockchain: Get Non-OSMO Pool Asset
loop Over Blocks
Script ->> Blockchain: Generate and Sign Tx
Script ->> Blockchain: Broadcast Tx
Script ->> Blockchain: Wait For Next Block
end
Script ->> User: Complete
sequenceDiagram
participant Script
participant Blockchain
Script ->> Blockchain: Check Wallet Existence
alt Wallet Missing
Script ->> Blockchain: Create Wallet
Script ->> Blockchain: Seed Wallet
end
Script ->> Blockchain: Initialize Wallet Sequences
These diagrams illustrate the primary interactions and control flow for pool swapping and wallet management within the enhanced script.
scripts/pool_swaps_per_block_inc.py
327-327: f-string without any placeholders Remove extraneous `f` prefix (F541)
scripts/pool_swaps_per_block_inc.py (3)
`83-85`: **Ensure command execution safety.** The `run_command` function uses `subprocess.run`, which is potentially vulnerable to command injection if not properly sanitized. Ensure that commands passed to this function are either hardcoded, sanitized, or securely parameterized to prevent security vulnerabilities. [SECURITY] --- `88-105`: **Good use of concurrency in wallet management.** The `create_wallets` function effectively utilizes `ThreadPoolExecutor` to handle wallet creation and seeding concurrently. This is a good practice in Python for managing multiple I/O-bound tasks simultaneously, which can significantly improve the script's performance. --- `327-327`: **Remove extraneous f-string prefix.** The f-string on line 327 is used without placeholders. This is unnecessary and can be removed for clarity. ```diff - print(f"Generating and signing transactions prior to broadcasting...") + print("Generating and signing transactions prior to broadcasting...") ```Tools
Ruff
327-327: f-string without any placeholders Remove extraneous `f` prefix (F541)
Thanks for approval, I think I am going to migrate this to go though, will respond here soon with decision.
Closing in favor of a way better golang side solution!
Closes: #XXX
What is the purpose of the change
The current flow of this script is as follows:
We first have a list of pool IDs that have OSMO as one of the assets in the pool. This is to simplify the logic of determining what the non-OSMO asset is, and not having to worry about seeding wallets with with every possible asset. The idea is, each block, we swap over one more pool, until we have swapped over all pools.
Ex. If we have 2 GAMM pools, 2 CL pools, and 1 CW pool: Block 1: Swap over GAMM pool 1 Block 2: Swap over GAMM pool 1, GAMM pool 2 Block 3: Swap over GAMM pool 1, GAMM pool 2, CL pool 1 Block 4: Swap over GAMM pool 1, GAMM pool 2, CL pool 1, CL pool 2 Block 5: Swap over GAMM pool 1, GAMM pool 2, CL pool 1, CL pool 2, CW pool 1
The script creates and seeds as many wallets as their are pools. On the first run, it will seed all wallets. On subsequent runs, if the wallets exist and have sufficient balance, they will not be seeded for speed. The reason for using many wallets instead of incrementing the sequence number on a single wallet is because the single wallet must be submitted in a single threaded manner, in the order of the sequence number. With 2 second blocks, as we get more and more pools, the likelihood of going over the 2 second block time increases. With multiple wallets, we can submit transactions concurrently since there are no sequence number conflicts.
Some notes:
Its recommended to run this script on a machine with a good amount of CPU cores, as the script will submit transactions concurrently for each pool. The more cores, the faster the script will run. With a 16 vCPU machine, and 65 pool entires, only the last 3 blocks had a 2 block delay.
You should use one of the lo-test1 - lo-test10 KEYRING_NAME keys since they are seeded with OSMO from in-place-testnet.
The script works with the given five CW pools, but adding other CW pools might require some extra logic to handle their different query responses.
Lastly, to run this script, you would do the following:
make localnet-keys
make install
the v26 (or higher) osmosisd binary, as that is what will be used to run this scriptSome TODOs:
Testing and Verifying
I have run this script on several in place testnets.