Пример #1
0
            if metadata['takerToken'] != 'ETH':
                continue
        fees = 0
        if args.fees:
            # Can't differentiate fees from assets in the following scenarios.
            if metadata['makerToken'] == 'ETH':
                continue
            if metadata['side'] == 'buy' and metadata['takerToken'] == 'ETH':
                continue
            # Express fees in units of gas
            fees = int(swap['protocolFee']) - int(
                metadata['swapResult']['ethBalance'])
            fees = max(0, fees // int(swap['gasPrice']))
        costs[url] = gas = metadata['swapResult']['gasUsed'] + fees
    if len(urls) == len(list(costs.keys())):
        value = get_max_value(swap)
        for url in costs:
            costs_by_url_by_value[url] = costs_by_url_by_value.get(url, {})
            costs_by_url_by_value[url][value] = costs_by_url_by_value[url].get(
                value, [])
            costs_by_url_by_value[url][value].append(costs[url])

sns.catplot(
    x='value',
    y='gas used',
    hue='url',
    data=pd.DataFrame(
        [[
            url, max_value,
            sum(costs_by_url_by_value[url].get(max_value, [])) /
            (len(costs_by_url_by_value[url].get(max_value, [])) or 1)
Пример #2
0
                 for d in data]
            ], )))
print(f'Found {len(sources)} sources')

data_by_source = {
    s: [
        d for d in data
        if len(d['sources']) == 1 and d['sources'][0]['name'] == s
    ]
    for s in sources
}

df_values = []
for s in sources:
    for d in data_by_source[s]:
        df_values.append([s, get_max_value(d), float(get_slippage(d))])

tokens = sorted(
    set([
        *(d['metadata']['makerToken'] for d in data),
        *(d['metadata']['takerToken'] for d in data)
    ]))
sns.catplot(
    x='source',
    y='slippage',
    hue='swap value',
    data=pd.DataFrame(
        df_values,
        columns=['source', 'swap value', 'slippage'],
    ),
    kind='bar',
Пример #3
0
args = get_program_args()
data = [d for d in load_ab_data(args.path) if len(list(d.keys())) > 1]
print(f'Loaded {len(data)} data items')

urls = sorted(set(itertools.chain(*(d.keys() for d in data))))

sns.catplot(
    x='swap value',
    y='accuracy',
    hue='url',
    data=pd.DataFrame(
        [[
            url,
            float(d[url]['metadata']['swapResult']['boughtAmount']) /
            float(d[url]['buyAmount']) if d.get(url) else None,
            get_max_value(d[url]) if d.get(url) else None,
        ] for url, d in itertools.product(urls, data)],
        columns=['url', 'accuracy', 'swap value'],
    ),
    kind='bar',
    errcolor='black',
    errwidth=1,
    capsize=.1,
    order=[max_value for min_value, max_value in VALUES],
    legend=True,
    legend_out=False,
)

for t, url in zip(plt.gca().get_legend().texts, urls):
    t.set_text(url)
plt.xticks(list(range(len(VALUES))),
Пример #4
0
print(f'Loaded {len(data)} data items')

tokens = sorted(
    set([
        *(d['metadata']['makerToken'] for d in data),
        *(d['metadata']['takerToken'] for d in data)
    ]))
sns.catplot(
    x='token',
    y='slippage',
    hue='swap value',
    data=pd.DataFrame(
        [
            *([
                d['metadata']['takerToken'],
                get_max_value(d),
                float(get_slippage(d)),
            ] for d in data), *([
                d['metadata']['makerToken'],
                get_max_value(d),
                float(get_slippage(d)),
            ] for d in data)
        ],
        columns=['token', 'swap value', 'slippage'],
    ),
    kind='bar',
    errcolor='black',
    errwidth=1,
    capsize=.1,
    order=tokens,
    legend=True,
    return True


args = get_program_args()
data = [
    d for d in load_ab_data(args.path) if are_valid_swaps(args, d.values())
]
print(f'Loaded {len(data)} data items')

count_by_value_by_url = {}
for d in data:
    best_swap_url = max(d.keys(), key=lambda k: get_realized_price(d[k]))
    worst_swap_url = min(d.keys(), key=lambda k: get_realized_price(d[k]))
    if best_swap_url == worst_swap_url:
        continue
    best_swap = d[best_swap_url]
    worst_swap = d[worst_swap_url]
    best_price = get_realized_price(best_swap)
    worst_price = get_realized_price(worst_swap)
    bps = (best_price - worst_price) / worst_price * 1e4
    value = get_max_value(d[best_swap_url])

    count_by_value_by_url[value] = count_by_value_by_url.get(value, {})
    count_by_value_by_url[value][best_swap_url] = count_by_value_by_url[
        value].get(best_swap_url, 0)
    count_by_value_by_url[value][worst_swap_url] = count_by_value_by_url[
        value].get(worst_swap_url, 0)
    count_by_value_by_url[value][best_swap_url] += 1

print(count_by_value_by_url)
args = get_program_args()
data = [d for d in load_ab_data(args.path) if len(list(d.keys())) > 1]
print(f'Loaded {len(data)} data items')

urls = sorted(set(itertools.chain(*(d.keys() for d in data))))

sns.catplot(
    x='swap value',
    y='response time',
    hue='url',
    data=pd.DataFrame(
        [[
            url,
            d[url]['metadata']['responseTime'],
            get_max_value(d[url]),
        ] for url, d in itertools.product(urls, data)],
        columns=['url', 'response time', 'swap value'],
    ),
    kind='bar',
    errcolor='black',
    errwidth=1,
    capsize=.1,
    order=[max_value for min_value, max_value in VALUES],
    legend=True,
    legend_out=False,
)

for t, url in zip(plt.gca().get_legend().texts, urls):
    t.set_text(url)
plt.xticks(list(range(len(VALUES))),