Skip to main content

Test automated trades on the Mach exchange.

Project description

Cross Chain Trade Test (CCTT)

Test automated trades between multiple chains on Mach.

PyPI

Test PyPI

Overview

Test automated trades on Mach. Specify a start chain and symbol, and a policy determining how the destination token will be chosen (randomize chain and symbol, randomize chain and fix symbol). In each trade, the test wallet's entire balance of the source token will be sold for the destination token, and then the destination token because the new source token for the next trade. This continues until the script is killed by the user.

Usage

  1. Install

    python -m pip install mach-cctt
    
  2. Usage

    cctt --help
    
  3. Example

    # The script will create log files and an account data file. Make a working directory for it.
    mkdir cctt/ && cd cctt/
    
    # Set password to avoid being prompted
    # export CCTT_PASSWORD="abc"
    
    cctt import # Import account
    cctt decrypt # Show public/private key
    cctt balances # Show account balances
    
    # Trade USDC on random chains, starting from optimism-USDC
    cctt run --source optimism-USDC --destination-policy fixed:USDC
    
    # Trade between random tokens on random chains, starting from arbitrum-USDT
    cctt run --source arbitrum-USDT --destination-policy random
    
    # If the --source is empty, then an appropriate source with a non-zero balance is chosen for you.
    cctt run --source --destination-policy random
    

    Notes:

    • You need to have a gas on every chain, or a gas of exactly 0 on chains that you do not wish the testing script to trade on, which will cause those chains to be disabled.
    • The --source token should be one that you hold a non-zero balance of in your wallet. If you set it to empty, it will be automatically chosen as any token with a non-zero balance in the wallet.
    • There is a known issue with trades filling for a single tick less than the order was placed at. As a preventative measure, any token balance of 1 tick in the wallet is treated as an empty balance.

Log Files

There are 4 log files created by the application:

  • app.log - everything
  • delayed_transactions.log - the source funds where not withdrawn in time
  • stuck_transactions.log - the source funds were withdrawn but the destination funds were not received in time
  • improper_fill.log - the trade filled on the source chain for 1 tick less than the order was placed for. This has been observed to happen primarily to USDM (on multiple chains)

Account File

A plaintext JSON file storing your account encrypted with your password will be created once you first generate or import a wallet. By default this file is called account.json but you can give a path to your own file via the --file PATH flag. This file is required to be present for any operation other than importing or generating a new wallet.

Development

Requirements

You need the just command runner and either Python 3.12.5+ with virtualenv, or pyenv.

Setup

  1. Clone the repository

    git clone https://github.com/tristeroresearch/cross-chain-trade-test.git
    cd cross-chain-trade-test
    
  2. Create and activate a virtual environment

    Using venv:

    python -m venv .venv
    source .venv/bin/activate
    

    Or using pyenv:

    pyenv virtualenv 3.12.5 cctt
    pyenv activate
    
  3. Install dependencies

    just init
    
  4. View available recipes

    just -l
    

    Note that there are recipes that allow you to run the application in-source without needed to build and package to PyPI first:

    just account_file=account.json import <private key> # Import a new account
    just decrypt # Show public and private key
    just balances # List balances of account
    just source=arbitrum-USDC policy=random run # Run the trade tester, starting from arbitrum-USDC and trading to random tokens
    just wallet=<public key> withdraw # Withdraw funds from the stored account to the given wallet
    
  5. Building

    just build
    

Packaging

Make sure to bump the version number in pyproject.toml.

To upload to the test PyPI:

just upload-test

To upload to the main PyPI:

just upload

TODO

  • Special logging for high-slippage orders
  • Put all the AAVE stuff behind a feature flag (adds too many big dependencies)
  • Switch over to new transactions module
  • drain_eth is being skipped during withdrawals as we aren't calculating L1 gas fees, making it impossible to determine the amount to withdraw
  • Use type 2 (EIP 1559) txs
  • Resolve duplication between transfers.py and transactions.py
  • Use Quote class from backend and deserialize with pydantic
  • Unit tests

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mach_cctt-0.0.51.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

mach_cctt-0.0.51-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file mach_cctt-0.0.51.tar.gz.

File metadata

  • Download URL: mach_cctt-0.0.51.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for mach_cctt-0.0.51.tar.gz
Algorithm Hash digest
SHA256 b4f52a13dbbcd6dc5327f53bc16598f5c4c6e21562edb163a66c8b60127646b2
MD5 6542fc779a7c68aba8685464b4692770
BLAKE2b-256 10da84108bf5ca0dbd347e1089b5b789e4ae2a00dbe424c95cfcefdd55724e78

See more details on using hashes here.

File details

Details for the file mach_cctt-0.0.51-py3-none-any.whl.

File metadata

  • Download URL: mach_cctt-0.0.51-py3-none-any.whl
  • Upload date:
  • Size: 51.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for mach_cctt-0.0.51-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0e8f734a1272bbf29af437e1ac376de3a83e49e18c86319cda52db88a78996
MD5 6fa3908d1d0aaf60734a67a471c46a83
BLAKE2b-256 1e00d5186892938d1be17b5c20d14b5d47fb4e0e64b00b1c167ab158e1cd310d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page