### Example Help Call Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb A commented-out example demonstrating how to use Python's built-in `help()` function to get documentation for the first curve object in the `CC` container. ```python #help(CC[0]) ``` -------------------------------- ### Example Pair Help Call Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb A commented-out example demonstrating how to use Python's built-in `help()` function to get documentation for the pair object associated with the first curve in the `CC` container. ```python #help(CC[0].pairo) ``` -------------------------------- ### Starting Unfocused Pairwise Arbitrage Bot (Command Line) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/README.md Example command line configuration to start the bot for unfocused pairwise arbitrage across multiple exchanges, similar to the Carbon-focused example but using `multi_pairwise_all` mode. ```commandline poetry run python main.py --arb_mode=multi_pairwise_all --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" ``` -------------------------------- ### Starting Triangular Carbon-focused Arbitrage Bot (Command Line) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/README.md Example command line configuration to start the bot for triangular arbitrage, specifically focusing on Carbon, using the `multi_triangle` arbitrage mode. ```commandline poetry run python main.py --arb_mode=multi_triangle --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" ``` -------------------------------- ### Starting Carbon-focused Pairwise Arbitrage Bot (Command Line) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/README.md Example command line configuration to start the bot focusing on Carbon and other exchanges for pairwise arbitrage, including specific settings for block fetching, logging, polling, and flashloan tokens. ```commandline poetry run python main.py --arb_mode=multi --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" ``` -------------------------------- ### Installing Fastlane Bot with Poetry (Bash) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/README.md Clones the Fastlane Bot repository from GitHub, navigates into the directory, installs Poetry, and then uses Poetry to install the project dependencies within a virtual environment. ```Bash git clone https://github.com/bancorprotocol/fastlane-bot cd fastlane-bot pip install poetry poetry install ``` -------------------------------- ### Examples of Initializing Carbon Orders in Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb Presents various examples of calling the CPC.from_carbon method to initialize Carbon orders, showcasing different combinations of price parameters (pa/pb or A/B), price quoting direction (isdydx), and the role of tkny (base or quote). Requires CPC and m (math). ```python CPC.from_carbon(yint=1, y=1, pa=1800, pb=2200, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False)\nCPC.from_carbon(yint=1, y=1, A=1/10, B=m.sqrt(1/2000), pair="ETH/USDC", tkny="ETH", fee=0, cid="2", descr="Carbon", isdydx=True)\nCPC.from_carbon(yint=1, y=1, pa=3100, pb=2900, pair="ETH/USDC", tkny="USDC", fee=0, cid="3", descr="Carbon", isdydx=True)\nCPC.from_carbon(yint=1, y=1, A=10, B=m.sqrt(3000), pair="ETH/USDC", tkny="USDC", fee=0, cid="4", descr="Carbon", isdydx=True) ``` -------------------------------- ### Example Usage of swap_eq Function (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/analysis/202401 Solidly/202401 Solidly.ipynb Demonstrates how to call the `swap_eq` function with example values for `x` and `k` and prints the result. Requires the `swap_eq` function to be defined. ```Python x_value = 1 # Replace with the desired value of x k_value = 1 # Replace with the desired value of k print(swap_eq(x_value, k_value)) ``` -------------------------------- ### Example: Pickling the Optimizer (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb Shows how to use the 'pickle' method on the CPCArbOptimizer object to serialize its state to a file. Includes examples with and without adding a timestamp to the filename. The code is commented out. ```python # O.pickle("delme") # O.pickle("delme", addts=False) ``` -------------------------------- ### Example: Creating Curve Container and Optimizer (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb Demonstrates how to create multiple ConstantProductCurve instances and aggregate them into a CPCContainer. It then initializes a CPCArbOptimizer with this container. The code is commented out, indicating it's an example or inactive test. ```python # N=5 # curves = [ # CPC.from_xy(x=1, y=2000, pair="ETH/USDC"), # CPC.from_xy(x=1, y=2200, pair="ETH/USDC"), # CPC.from_xy(x=1, y=2400, pair="ETH/USDC"), # ] # # note: the below is a bit icky as the same curve objects are added multiple times # CC = CPCContainer(curves*N) # O = CPCArbOptimizer(CC) # O.CC.asdf() ``` -------------------------------- ### Example Usage of price_eq Function (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/analysis/202401 Solidly/202401 Solidly.ipynb Provides an example of how to call the `price_eq` function with specific values for `x` and `k`. It prints the calculated price (derivative) at that point. Requires the `price_eq` function to be defined. ```Python x_value = 1 # Replace with the desired value of x k_value = 1 # Replace with the desired value of k print(price_eq(x_value, k_value)) ``` -------------------------------- ### Initialize MargPOptimizer Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_055_Optimization.ipynb Initializes the `MargPOptimizer` with a set of curves (`CC`) and asserts that the optimizer correctly stores the provided curves. This is a basic setup step for using the gradient descent optimizer. ```Python O = MargPOptimizer(curves=CC) assert len(O.curves) == len(CC) ``` -------------------------------- ### Running Optimizer Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Initializes the MargPOptimizer with raw curve data (CCRaw) and runs the optimization process. It uses the raw target token and raw price data as parameters. This step is a preliminary check to ensure the optimizer can run. ```python O = MargPOptimizer(CCRaw) r = O.optimize(sfc=TARGET_TOKEN_RAW, params=dict(pstart=PRICES_RAW)) r ``` -------------------------------- ### Setup for Running Solidly Notebooks (Shell) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/analysis/202401 Solidly/README.md These shell commands create symbolic links from the main fastlane_bot directory to the current directory for the 'invariants' library and the 'testing.py' script, which are dependencies for the Solidly analysis notebooks. It also adds these linked files to the .gitignore to prevent them from being committed. ```Shell ln -s ../../../fastlane_bot/tools/invariants invariants ln -s ../../../fastlane_bot/testing.py testing.py echo invariants >>.gitignore echo testing.py >>.gitignore ``` -------------------------------- ### Example: Unpickling the Optimizer (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb Demonstrates how to deserialize a previously pickled CPCArbOptimizer object from a file using the 'unpickle' method. The code is commented out, suggesting it's an example or inactive test. ```python # O.unpickle("delme") ``` -------------------------------- ### Exporting Poetry Dependencies to Requirements.txt (Bash) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/README.md Exports the project dependencies managed by Poetry into a standard requirements.txt file, excluding hashes, for backward compatibility or alternative installation methods. ```Bash poetry export --without-hashes --format=requirements.txt > requirements.txt ``` -------------------------------- ### Importing and Version Check for Fastlane Bot Tools (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb This snippet attempts to import core classes like SimplePair, ConstantProductCurve, CPCContainer, PairOptimizer, and MargPOptimizer from the `fastlane_bot.tools` package, with a fallback to `tools`. It then prints the name, version, and date of each imported class to verify the loaded versions. ```Python try: from fastlane_bot.tools.simplepair import SimplePair from fastlane_bot.tools.cpc import ConstantProductCurve, CPCContainer from fastlane_bot.tools.optimizer import PairOptimizer, MargPOptimizer except: from tools.simplepair import SimplePair from tools.cpc import ConstantProductCurve, CPCContainer from tools.optimizer import PairOptimizer, MargPOptimizer CPC = ConstantProductCurve import pandas as pd print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(SimplePair)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPC)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPCContainer)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(PairOptimizer)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(MargPOptimizer)) ``` -------------------------------- ### Example: Listing Pickle Files (Shell) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb A commented-out shell command intended to list files ending with '.pickle' in the current directory. This is likely used in an interactive environment like a Jupyter notebook to verify the output of the pickling operations. ```shell # !ls *.pickle ``` -------------------------------- ### Iterate and Print Arbitrage Cycle Pairs (USDC Start) - Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_004_GraphCode.ipynb Iterates through the detected arbitrage cycles in the current ArbGraph instance and prints the sequence of asset pairs within each cycle, starting the sequence from the 'USDC' node. ```python for C in AG.cycles(): print(f"==={C}===") for c in C.pairs(start_val=AG.n("USDC")): print(c) ``` -------------------------------- ### Display Prices and Optimal Price Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_055_Optimization.ipynb Displays the initial prices (`PRICES`) and the optimal price found by the optimizer (`r.p_optimal`). This helps visualize the difference between the starting and ending price states after the optimization attempt. ```Python PRICES, r.p_optimal ``` -------------------------------- ### Printing Curve Summary Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Prints a summary of the loaded curve data, including the total number of curves, the unique normalized pairs present, and the identified target token. This provides a quick overview of the dataset. ```python print("Num curves: ", len(CC)) print("Pairs: ", set(c.pairo.primary_n for c in CC)) print("Target token: ", TARGET_TOKEN) ``` -------------------------------- ### Providing Token Prices in Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb This snippet demonstrates how to define a dictionary (`PRICES_RAW`) containing current token prices. The dictionary keys are token addresses, and the values are their respective prices. These prices are used by the bot, likely for calculations or strategy execution. All relevant tokens must be included, and prices should be in the same numeraire. ```python PRICES_RAW = { '0x8E870D67F660D95d5be530380D0eC0bd388289E1': 0.0003087360213944532, '0x514910771AF9Ca656af840dff83E8264EcF986CA': 0.004372219704179475, '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE': 1 } ``` -------------------------------- ### Preprocessing Data Containers Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Creates the main `CPCContainer` (CC) by applying the `replace_tokens` function to the raw curve data (CCRaw). It also creates a `PRICES` dictionary using token tickers and sets the final `TARGET_TOKEN` using the ticker. This step standardizes the data for further analysis. ```python CC = CPCContainer.from_dicts([replace_tokens(d) for d in CCRaw.asdicts()]) PRICES = {TOKENS[addr]:price for addr, price in PRICES_RAW.items()} TARGET_TOKEN = TOKENS[TARGET_TOKEN_RAW] PRICES ``` -------------------------------- ### Running Optimizer with Debug Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Initializes the `MargPOptimizer` with the preprocessed curve data (`CC`) and runs the optimization process. This execution includes various debug flags (`verbose`, `debug`, `debug_j`, `debug_dtkn`, `debug_dtkn2`) to provide detailed output for troubleshooting and analysis. ```python O = MargPOptimizer(CC) r = O.optimize(sfc="ETH", params=dict( pstart=PRICES, verbose=True, debug=True, debug_j=True, debug_dtkn=True, debug_dtkn2=True, )) r ``` -------------------------------- ### Defining Tokens and Target Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Defines the token addresses and their corresponding tickers in a dictionary. Sets the raw target token using the first key from the TOKENS dictionary. This configuration is essential for identifying the assets the bot will work with. ```python TOKENS = { "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE": "ETH", "0x514910771AF9Ca656af840dff83E8264EcF986CA": "LINK", "0x8E870D67F660D95d5be530380D0eC0bd388289E1": "USDP", } TARGET_TOKEN_RAW = list(TOKENS)[0] TARGET_TOKEN_RAW ``` -------------------------------- ### Example Function Name Conversion Call (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/ConvertNBTest.ipynb Demonstrates calling the `funcn` function with a specific title string containing the `[NOTEST]` marker to show how a function name is generated. ```python funcn("A notest title [NOTEST]") ``` -------------------------------- ### Importing Testing Utilities (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_000_Template.ipynb Imports necessary testing utilities from `fastlane_bot.testing` or `tools.testing`, including handling potential import errors. This code is intended to run before any test sections are executed, providing required functions like `iseq` and `raises`. Includes commented-out code related to configuration, plotting, and version checking. ```python # from fastlane_bot.config import Config try: #from fastlane_bot.tools.moo import meh from fastlane_bot.testing import * except: #from tools.moo import meh from tools.testing import * # print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(meh)) # plt.style.use('seaborn-dark') # plt.rcParams['figure.figsize'] = [12,6] # from fastlane_bot import __VERSION__ # require("2.0", __VERSION__) ``` -------------------------------- ### Creating Cycle and Testing Iteration (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_004_GraphCode.ipynb Creates a `Cycle` object from a list of numbers. Demonstrates iterating through the cycle's items and pairs using the `items()` and `pairs()` methods, showing how to specify a starting index or value for iteration. ```python C = ag.Cycle([1,2,3,4,5]) assert len(C) == 5 assert [x for x in C.items()] == [1, 2, 3, 4, 5, 1] assert [x for x in C.items(start_ix=3)] == [4, 5, 1, 2, 3, 4] assert [x for x in C.items(start_val=3)] == [3, 4, 5, 1, 2, 3] assert [p for p in C.pairs()] == [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)] ``` -------------------------------- ### Calculating Effective Price Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Calculates the approximate effective price of LINK in terms of USDP based on specific liquidity values from overlapping curves. This provides insight into the market price established by these curves. ```python 3239.013043/228.716777 ``` -------------------------------- ### Example Usage of Numerical Swap Equation - Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/analysis/202401 Solidly/202401 Solidly-Freeze01.ipynb Demonstrates how to use the `swap_eq` function (note: the comment says `swap_eq2` but the code calls `swap_eq`) with specific numerical values for `x` and `k`. It prints the calculated value of `y`, showing a practical application of the numerical swap function. ```python x_value = 1 # Replace with the desired value of x k_value = 1 # Replace with the desired value of k print(swap_eq(x_value, k_value)) ``` -------------------------------- ### Importing Modules and Printing Versions (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb Imports necessary classes like ConstantProductCurve and CPCArbOptimizer from either the installed package or local tools directory using a try/except block. It then prints the version and date for the imported CPC and CPCArbOptimizer classes. ```python try: from fastlane_bot.tools.cpc import ConstantProductCurve as CPC, CPCContainer from fastlane_bot.tools.optimizer import CPCArbOptimizer, cp, time from fastlane_bot.testing import * except: from tools.cpc import ConstantProductCurve as CPC, CPCContainer from tools.optimizer import CPCArbOptimizer, cp, time from tools.testing import * print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPC)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPCArbOptimizer)) import json #plt.style.use('seaborn-dark') plt.rcParams['figure.figsize'] = [12,6] # from fastlane_bot import __VERSION__ # require("2.0", __VERSION__) ``` -------------------------------- ### Defining Price Calculation Function Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Defines a helper function `p` to calculate the price of a base token (`tknb`) in terms of a quote token (`tknq`), using either a provided pair string or separate token arguments. It defaults to using the global `PRICES` dictionary. ```python def p(pair=None, *, tknb=None, tknq=None, prices=None): """price of tknb in terms of tknq""" if not pair is None: tknb, tknq = pair.split("/") p = prices or PRICES return p[tknb]/p[tknq] ``` -------------------------------- ### Importing DictVector and Testing Utilities (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_065_InvariantsDictVector.ipynb Imports the `DictVector` module (aliased as `dv`) and testing utilities from either the installed package structure or a local path. This setup allows the script to access the necessary vector operations and assertion functions. ```python try: import fastlane_bot.tools.invariants.vector as dv from fastlane_bot.testing import * except: import tools.invariants.vector as dv from tools.testing import * ``` -------------------------------- ### Commented Out MargPOptimizer Help - Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_055_Optimization.ipynb A commented-out line showing how to access the help documentation for the MargPOptimizer class, likely used during development or exploration. ```python #help(MargPOptimizer) ``` -------------------------------- ### Placeholder Statement in NOTEST Section (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_000_Template.ipynb A simple `pass` statement used as a placeholder within a section marked `[NOTEST]`. Code in `[NOTEST]` sections is not converted into test functions and is typically used for setup, data loading, or plotting that is not part of the automated tests. ```python pass ``` -------------------------------- ### Defining Trading Curves in Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb This snippet shows how to define a list of trading curves, specifically using `ConstantProductCurve` objects. Each object represents a liquidity pool or trading mechanism with parameters like `k`, `x`, `y_act`, `pair`, `cid`, `fee`, and `params`. This list (`CurvesRaw`) serves as input for the bot's curve processing. ```python CurvesRaw = [ ConstantProductCurve(k=27518385.40998667, x=1272.2926367501436, x_act=0, y_act=2000.9999995236503, alpha=0.5, pair='0x514910771AF9Ca656af840dff83E8264EcF986CA/0x8E870D67F660D95d5be530380D0eC0bd388289E1', cid='0x425d5d4ad7243f88d9f4cde8da52863b45af1f64e05bede1299909bcaa6c52d1-0', fee=2000, descr='carbon_v1 0x514910771AF9Ca656af840dff83E8264EcF986CA\/0x8E870D67F660D95d5be530380D0eC0bd388289E1 2000', constr='carb', params={'exchange': 'carbon_v1', 'y': 2000.9999995236503, 'yint': 2000.9999995236503, 'A': 0.38144823884371704, 'B': 3.7416573867739373, 'pa': 16.99999999999995, 'pb': 13.99999999999997}), ConstantProductCurve(k=6.160500599566333e+18, x=11099999985.149971, x_act=0, y_act=55.50000002646446, alpha=0.5, pair='0x8E870D67F660D95d5be530380D0eC0bd388289E1/0x514910771AF9Ca656af840dff83E8264EcF986CA', cid='0x425d5d4ad7243f88d9f4cde8da52863b45af1f64e05bede1299909bcaa6c52d1-1', fee=2000, descr='carbon_v1 0x514910771AF9Ca656af840dff83E8264EcF986CA\/0x8E870D67F660D95d5be530380D0eC0bd388289E1 2000', constr='carb', params={'exchange': 'carbon_v1', 'y': 55.50000002646446, 'yint': 55.50000002646446, 'A': 0, 'B': 0.22360678656963742, 'pa': 0.04999999999999889, 'pb': 0.04999999999999889}), ConstantProductCurve(k=14449532.299465338, x=57487.82879658422, x_act=0, y_act=5.0, alpha=0.5, pair='0x514910771AF9Ca656af840dff83E8264EcF986CA/0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', cid='0x3fcccfe0063b71fc973fab8dea39b6be9da80125910c10e57b924b3e4687295a-0', fee=2000, descr='carbon_v1 0x514910771AF9Ca656af840dff83E8264EcF986CA/0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE 2000', constr='carb', params={'exchange': 'carbon_v1', 'y': 5.0, 'yint': 8.582730309868262, 'A': 0.002257868117407469, 'B': 0.06480740698407672, 'pa': 0.004497751124437756, 'pb': 0.004199999999999756}), ConstantProductCurve(k=14456757.06563651, x=251.4750925240284, x_act=0, y_act=807.9145301701096, alpha=0.5, pair='0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE/0x514910771AF9Ca656af840dff83E8264EcF986CA', cid='0x3fcccfe0063b71fc973fab8dea39b6be9da80125910c10e57b924b3e4687295a-1', fee=2000, descr='carbon_v1 0x514910771AF9Ca656af840dff83E8264EcF986CA/0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE 2000', constr='carb', params={'exchange': 'carbon_v1', 'y': 807.9145301701096, 'yint': 1974.7090228584536, 'A': 0.519359008452966, 'B': 14.907119849998594, 'pa': 237.97624997025295, 'pb': 222.22222222222211}), ConstantProductCurve(k=56087178.30932376, x=131.6236694086859, x_act=0, y_act=15920.776548455418, alpha=0.5, pair='0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE/0x8E870D67F660D95d5be530380D0eC0bd388289E1', cid='0x6cc4b198ec4cf17fdced081b5611279be73e200711238068b5340e606ba86646-0', fee=2000, descr='carbon_v1 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE\/0x8E870D67F660D95d5be5340e606ba86646-1 2000', constr='carb', params={'exchange': 'carbon_v1', 'y': 15920.776548455418, 'yint': 32755.67010983316, 'A': 4.373757425036729, 'B': 54.77225575051648, 'pa': 3498.2508745627138, 'pb': 2999.9999999999854}), ConstantProductCurve(k=56059148.73497429, x=426117.72306081816, x_act=0, y_act=5.0, alpha=0.5, pair='0x8E870D67F660D95d5be530380D0eC0bd388289E1/0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', cid='0x6cc4b198ec4cf17fdced081b5611279be73e200711238068b5340e606ba86646-1', fee=2000, descr='carbon_v1 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE\/0x8E870D67F660D95d5be5340e606ba86646-1 2000', constr='carb', params={'exchange': 'carbon_v1', 'y': 5.0, 'yint': 10.106093048875099, 'A': 0.0013497708452092638, 'B': 0.016903085094568837, 'pa': 0.0003331667499582927, 'pb': 0.0002857142857142352}) ] CCRaw = CPCContainer(CurvesRaw) ``` -------------------------------- ### Initializing Mock QueryInterface (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/fastlane_bot/modes/tests/test_pairwise_single.ipynb This snippet prepares pool data by converting pool objects to dictionaries and extracting unique exchange names. It then initializes a mock `QueryInterface` instance using this data and assigns it to `setup_bot.db`, simulating a database connection for testing purposes. ```python state = [pool.__dict__ for pool in pools] exchanges = list({ex['exchange_name'] for ex in state}) mock_qi = QueryInterface(state=state, ConfigObj=C, exchanges=exchanges) setup_bot.db = mock_qi ``` -------------------------------- ### Initialize Carbon Order (A/B, dy/dx, tkny=quote) in Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_003_Serialization.ipynb Provides an example of initializing a Carbon order using A and B price parameters, where prices are quoted as dy/dx (isdydx=True) and the tkny is the quote token. Asserts verify the initial state and calculated price range. Requires CPC, iseq, and m (math). ```python c = CPC.from_carbon(yint=2000, y=2000, A=10, B=m.sqrt(3000), pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True)\nassert c.y_act == 2000\nassert c.x_act == 0\nassert iseq(c.p_min, 3000)\nprint("pa", c.p_max, (10+m.sqrt(c.p_min))**2)\nassert iseq(c.p_max, (10+m.sqrt(c.p_min))**2)\nassert iseq(1/c.p, 1/c.p_max) ``` -------------------------------- ### Generating Curve Data Dictionary Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/OptimizerTesting.ipynb Generates a list of dictionaries, where each dictionary contains detailed information about a specific curve. It calculates and includes metrics like shortened CID, exchange type, pair, market price, curve price range, liquidity, and total liquidity in the target token. ```python PRICE_DECIMALS = 2 curvedata = [dict( cid0 = f"{c.cid[2:6]}{c.cid[-2:]}", exch = c.params['exchange'], pair = c.pairo.primary_n, mktp = round(p(c.pairo.primary_n), PRICE_DECIMALS), bs = c.buysell(), tkn = c.pairo.primary_tknb, p = round(c.primaryp(), PRICE_DECIMALS), p_min = round(c.p_min_primary(), PRICE_DECIMALS), p_max = round(c.p_max_primary(), PRICE_DECIMALS), tknp = p(tknb=c.pairo.primary_tknb, tknq=TARGET_TOKEN), wbp = max(int((c.p_max_primary()/c.p_min_primary() - 1)*10000), 1), liq = round(c.tvl(tkn=c.pairo.primary_tknb), 2), liqtt = round(c.x_act*p(tknb=c.tknx, tknq=TARGET_TOKEN) + c.y_act*p(tknb=c.tkny, tknq=TARGET_TOKEN), 2), ) for c in CC] #curvedata ``` -------------------------------- ### Optimizing Asymmetric Curves with MargPOptimizer - Python Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/resources/NBTest/NBTest_055_Optimization.ipynb Runs the MargPOptimizer on the asymmetric curves (CCas2) targeting WETH, providing a starting price hint (pstart). It asserts various properties of the optimization result (r) including no error, method, target token, resulting token tuple, negative WETH change, and specific numerical results for the outcome, optimal price, and token changes, allowing for specified epsilons. ```python r = O.optimize("WETH", params={"pstart": {" ``` -------------------------------- ### Asserting QueryInterface Functionality (Python) Source: https://github.com/bancorprotocol/fastlane-bot/blob/main/fastlane_bot/modes/tests/test_pairwise_single.ipynb This snippet contains assertions to verify that `setup_bot.db` is an instance of `QueryInterface`. It then calls `get_pools()` on the interface and asserts that the returned list is not empty, is indeed a list, and contains objects of the expected pool types from `fastlane_bot`. ```python assert (str(type(setup_bot.db)) == "") pools = setup_bot.db.get_pools() assert (len(pools) > 0) assert isinstance(pools, list) assert all((str(type(pool)).startswith("