TradeSuccess

Documentation for eth_defi.trade.TradeSuccess Python class.

class TradeSuccess

Bases: eth_defi.trade.TradeResult

Describe the result of a successful Uniswap swap.

See eth_defi.uniswap_v2.analysis.analyse_trade_by_receipt()

Attributes summary

intent_based

Did we use a third party intent service for this swap.

transfer_event_count

Did we generate some excessive transfer events during the swap.

untaxed_amount_out

For Uniswap v2 swaps were token tax applies.

path

Routing path that was used for this trade.

amount_in

How much token swas swapped from

amount_out_min

What was the expected minimum output with slippage tolerance

amount_out

What was the actual output

price

The price of the trade in some order.

amount_in_decimals

Token information bookkeeping

amount_out_decimals

Token information bookkeeping

token0

Uniswap v3 pool token 0

token1

Uniswap v3 pool token 1

lp_fee_paid

How much was the LP fee

Methods summary

__init__(gas_used, effective_gas_price, ...)

get_cost_of_gas()

This will return the gas cost of the transaction in blockchain's native currency e.g.

get_effective_gas_price_gwei()

get_human_price([reverse_token_order])

Get the executed price of this trade in a human-readable form.

get_tax()

Get Uniswap v2 style token tax.

path: Optional[List[eth_typing.evm.HexAddress]]

Routing path that was used for this trade.

Should be lowercased.

amount_in: int

How much token swas swapped from

amount_out_min: int | None

What was the expected minimum output with slippage tolerance

amount_out: int

What was the actual output

price: decimal.Decimal

The price of the trade in some order.

  • Uniswap v2: Overall price paid as in token (first in the path) to out token (last in the path).

  • Uniswap v3: depends on ticks and order of token0 and token1 in the underlying pool smart contract

Price includes any fees paid during the order routing path.

Note that you get inverse price, if you route ETH-USD or USD-ETH e.g. are you doing buy or sell.

See also get_human_price()

amount_in_decimals: int

Token information bookkeeping

amount_out_decimals: int

Token information bookkeeping

token0: eth_defi.token.TokenDetails | None

Uniswap v3 pool token 0

Needed to calculate reverse token order.

token1: eth_defi.token.TokenDetails | None

Uniswap v3 pool token 1

Needed to calculate reverse token order.

lp_fee_paid: float | None

How much was the LP fee

Note: this is the raw amount in terms of the amount in token

intent_based: bool | None = None

Did we use a third party intent service for this swap.

E.g. Enso.

We might not be analyse fees and path directly.

untaxed_amount_out: int | None = None

For Uniswap v2 swaps were token tax applies.

Set to None if could not be determined.

transfer_event_count: int = 0

Did we generate some excessive transfer events during the swap.

Usually a sign of some rigging mechanism.

get_human_price(reverse_token_order=False)

Get the executed price of this trade in a human-readable form.

This depends on:

  • If we are on Uniswap v2 or v3

  • If we do buy or sell

  • If quote token is token0 or token1 in Uniswap v3 pool

Example:

# TODO
pass
Parameters

reverse_token_order

Base and quote token order.

Quote token should be natural quote token like USD or ETH based token of the trade. If reverse_token_order is set quote token is token0 of the pool, otherwise token1.

Return type

decimal.Decimal

get_tax()

Get Uniswap v2 style token tax.

Returns

Tax in bps. Always negative.

0 if no tax.

None if could not determined.

Return type

float | None

__init__(gas_used, effective_gas_price, path, amount_in, amount_out_min, amount_out, price, amount_in_decimals, amount_out_decimals, token0, token1, lp_fee_paid, intent_based=None, untaxed_amount_out=None, transfer_event_count=0)
Parameters
Return type

None

get_cost_of_gas()

This will return the gas cost of the transaction in blockchain’s native currency e.g. in ETH on Ethereum.

Return type

decimal.Decimal