def test_get_trades_from_tx_swaps_3(): """Three swaps that can't be aggregated""" trades = get_trades_from_tx_swaps(TEST_SWAPS_TX_3) expected_trades = [ AMMTrade( trade_type=TradeType.BUY, base_asset=A_REN, quote_asset=A_WETH, amount=AssetAmount(FVal('3197.944466059874991601')), rate=Price(FVal('0.0006852525749766945789823189473')), trade_index=0, swaps=[TEST_SWAPS_TX_3[0]], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_SNX, quote_asset=A_REN, amount=AssetAmount(FVal('186.643670114899291543')), rate=Price(FVal('17.13395618555459553468367999')), trade_index=1, swaps=[TEST_SWAPS_TX_3[1]], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_SNX, amount=AssetAmount(FVal('2.283067259355947642')), rate=Price(FVal('81.75127970936394514208635428')), trade_index=2, swaps=[TEST_SWAPS_TX_3[2]], ), ] assert trades == expected_trades
def test_get_trades_from_tx_swaps_3(): """Three swaps that can't be aggregated""" trades = get_trades_from_tx_swaps(TEST_SWAPS_TX_3) expected_trades = [ AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('REN'), quote_asset=EthereumToken('WETH'), amount=AssetAmount(FVal('3197.944466059874991601')), rate=Price(FVal('1459.315931843101752940385571')), trade_index=0, swaps=[TEST_SWAPS_TX_3[0]], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('SNX'), quote_asset=EthereumToken('REN'), amount=AssetAmount(FVal('186.643670114899291543')), rate=Price(FVal('0.05836363704741385665599011674')), trade_index=1, swaps=[TEST_SWAPS_TX_3[1]], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('WETH'), quote_asset=EthereumToken('SNX'), amount=AssetAmount(FVal('2.283067259355947642')), rate=Price(FVal('0.01223222441966811342243170654')), trade_index=2, swaps=[TEST_SWAPS_TX_3[2]], ), ] assert trades == expected_trades
def add_trades_from_swaps( swaps: List[AMMSwap], trades: List[AMMTrade], both_in: bool, quote_assets: Sequence[Tuple[Any, ...]], token_amount: AssetAmount, token: Union[EthereumToken, UnknownEthereumToken], trade_index: int, ) -> List[AMMTrade]: bought_amount = AssetAmount(token_amount / 2) if both_in else token_amount for entry in quote_assets: quote_asset = entry[0] sold_amount = entry[1] rate = sold_amount / bought_amount trade = AMMTrade( trade_type=TradeType.BUY, base_asset=token, quote_asset=quote_asset, amount=bought_amount, rate=rate, swaps=swaps, trade_index=trade_index, ) trades.append(trade) trade_index += 1 return trades
def test_get_trade_with_1_token_pool( rotkehlchen_api_server, ethereum_accounts, # pylint: disable=unused-argument rotki_premium_credentials, # pylint: disable=unused-argument start_with_valid_premium, # pylint: disable=unused-argument ): """ Test the special case of a swap within an 1 token pool. This can probably happen if the controller has since removed tokens from the pool. """ rotki = rotkehlchen_api_server.rest_api.rotkehlchen setup = setup_balances( rotki, ethereum_accounts=ethereum_accounts, btc_accounts=None, original_queries=['zerion', 'logs', 'blocknobytime'], ) with ExitStack() as stack: # patch ethereum/etherscan to not autodetect tokens setup.enter_ethereum_patches(stack) response = requests.get( api_url_for(rotkehlchen_api_server, 'balancertradeshistoryresource'), json={ 'from_timestamp': 1621358338, 'to_timestamp': 1621358340, }, ) result = assert_proper_response_with_result(response) db_trades = rotki.data.db.get_amm_swaps() assert len(db_trades) == 29 address_trades = result[BALANCER_TEST_ADDR4] assert len(address_trades) == 1 assert address_trades[0] == AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_WBTC, amount=AssetAmount(FVal('0.205421420618533148')), rate=Price(FVal('0.07606382992071615428519015532')), trade_index=0, swaps=[ AMMSwap( tx_hash='0x4f9e0d8aa660a5d3db276a1ade038f7027f29838dd22d5276571d2e4ea7131ae', # noqa: E501 log_index=84, address=string_to_ethereum_address(BALANCER_TEST_ADDR4), # noqa: E501 from_address=string_to_ethereum_address('0xFD3dFB524B2dA40c8a6D703c62BE36b5D8540626'), # noqa: E501 to_address=string_to_ethereum_address('0x582818356331877553F3E9Cf9557b48e5DdbD54a'), # noqa: E501 timestamp=Timestamp(1621358339), location=Location.BALANCER, token0=A_WBTC, token1=A_WETH, amount0_in=AssetAmount(FVal('0.01562514')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('0.205421420618533148')), ), ], ).serialize()
def test_get_trades_from_tx_swaps_2(): """Two swaps that can be aggregated""" trades = get_trades_from_tx_swaps(TEST_SWAPS_TX_2) expected_trades = [ AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('WETH'), quote_asset=EthereumToken('USDC'), amount=AssetAmount(FVal('8.05955457343053505')), rate=Price(FVal('0.0006498998936028010652666316885')), trade_index=0, swaps=TEST_SWAPS_TX_2, ), ] assert trades == expected_trades
def test_get_trades_from_tx_swaps_1(): """Single swap""" trades = get_trades_from_tx_swaps(TEST_SWAPS_TX_1) expected_trades = [ AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('AMPL'), quote_asset=EthereumToken('USDC'), amount=AssetAmount(FVal('14285.153512382')), rate=Price(FVal('1.151914744569445582155783413')), trade_index=0, swaps=TEST_SWAPS_TX_1, ), ] assert trades == expected_trades
def test_get_trades_from_tx_swaps_2(): """Two swaps that can be aggregated""" trades = get_trades_from_tx_swaps(TEST_SWAPS_TX_2) expected_trades = [ AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_USDC, amount=AssetAmount(FVal('8.05955457343053505')), rate=Price(FVal('1538.698513176199118305140044')), trade_index=0, swaps=TEST_SWAPS_TX_2, ), ] assert trades == expected_trades
def test_get_trades_from_tx_swaps_1(): """Single swap""" trades = get_trades_from_tx_swaps(TEST_SWAPS_TX_1) expected_trades = [ AMMTrade( trade_type=TradeType.BUY, base_asset=A_AMPL, quote_asset=A_USDC, amount=AssetAmount(FVal('14285.153512382')), rate=Price(FVal('0.8681198020203941533693340847')), trade_index=0, swaps=TEST_SWAPS_TX_1, ), ] assert trades == expected_trades
def calculate_trade_from_swaps( swaps: List[AMMSwap], trade_index: int = 0, ) -> AMMTrade: """Given a list of 1 or more AMMSwap (swap) return an AMMTrade (trade). The trade is calculated using the first swap token (QUOTE) and last swap token (BASE). Be aware that any token data in between will be ignored for calculating the trade. Examples: [USDC -> AMPL] BASE_QUOTE pair is AMPL_USDC. [USDC -> AMPL, AMPL -> WETH] BASE_QUOTE pair is WETH_USDC. [USDC -> AMPL, AMPL -> WETH, WETH -> USDC] BASE_QUOTE pair is USDC_USDC. May raise DeserializationError """ assert len(swaps) != 0, "Swaps can't be an empty list here" if swaps[0].amount0_in == ZERO: # Prevent a division by zero error when creating the trade. # Swaps with `tokenIn` amount (<AMMSwap>.amount0_in) equals to zero are # not expected nor supported. The function `deserialize_swap` will raise # a DeserializationError, preventing to store them in the DB. In case # of having a zero amount it means the db data was corrupted. log.error( 'Failed to deserialize swap from db. First swap amount0_in is zero', swaps=swaps, ) raise DeserializationError('First swap amount0_in is zero.') amm_trade = AMMTrade( trade_type=TradeType.BUY, # AMMTrade is always a buy base_asset=swaps[-1].token1, quote_asset=swaps[0].token0, amount=swaps[-1].amount1_out, rate=Price(swaps[-1].amount1_out / swaps[0].amount0_in), swaps=swaps, trade_index=trade_index, ) return amm_trade
def get_balancer_test_addr2_expected_trades(): """In a function since the new(unknown) assets needs to have been loaded in the DB""" A_WCRES = EthereumToken.initialize( # noqa: N806 address=string_to_ethereum_address( '0xa0afAA285Ce85974c3C881256cB7F225e3A1178a'), decimals=18, symbol='wCRES', ) return [ AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_AAVE, amount=AssetAmount(FVal('1.616934038985744521')), rate=Price(FVal('6.963972908793392530935439799')), trade_index=1, swaps=[ AMMSwap( tx_hash= '0x3c457da9b541ae39a7dc781ab04a03938b98b5649512aec2a2d32635c9bbf589', # noqa: E501 log_index=24, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x7c90a3cd7Ec80dd2F633ed562480AbbEEd3bE546' ), # noqa: E501 timestamp=Timestamp(1607008178), location=Location.BALANCER, token0=A_AAVE, token1=A_WETH, amount0_in=AssetAmount(FVal('11.260284842802604032')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('1.616934038985744521')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_AAVE, quote_asset=A_WETH, amount=AssetAmount(FVal('11.260286362820602094')), rate=Price(FVal('0.1416068599966922676173010716')), trade_index=0, swaps=[ AMMSwap( tx_hash= '0x3c457da9b541ae39a7dc781ab04a03938b98b5649512aec2a2d32635c9bbf589', # noqa: E501 log_index=18, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x70985E557aE0CD6dC88189a532e54FbC61927BAd' ), # noqa: E501 timestamp=Timestamp(1607008178), location=Location.BALANCER, token0=A_WETH, token1=A_AAVE, amount0_in=AssetAmount(FVal('1.594533794502600192')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('11.260286362820602094')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_SYN, amount=AssetAmount(FVal('1.352902561458047718')), rate=Price(FVal('724.4303350385182691258363763')), trade_index=0, swaps=[ AMMSwap( tx_hash= '0x5e235216cb03e4eb234014f5ccf3efbfddd40c4576424e2a8204f1d12b96ed35', # noqa: E501 log_index=143, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x8982E9bBf7AC6A49c434aD81D2fF8e16895318e5' ), # noqa: E501 timestamp=Timestamp(1607008218), location=Location.BALANCER, token0=A_SYN, token1=A_WETH, amount0_in=AssetAmount(FVal('980.08365587152306176')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('1.352902561458047718')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_WCRES, amount=AssetAmount(FVal('0.205709519074945018')), rate=Price(FVal('232.7409943164679514496089589')), trade_index=0, swaps=[ AMMSwap( tx_hash= '0xf54be824b4619777f1db0e3da91b0cd52f6dba730c95a75644e2b085e6ab9824', # noqa: E501 log_index=300, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x10996eC4f3E7A1b314EbD966Fa8b1ad0fE0f8307' ), # noqa: E501 timestamp=Timestamp(1607009877), location=Location.BALANCER, token0=A_WCRES, token1=A_WETH, amount0_in=AssetAmount(FVal('47.87703800986513408')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('0.205709519074945018')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_API3, quote_asset=A_WETH, amount=AssetAmount(FVal('295.881648100500428692')), rate=Price(FVal('0.003346787723157288562491614498')), trade_index=0, swaps=[ AMMSwap( tx_hash= '0xfed4e15051e3ce4dc0d2816f719701e5920e40bf41614b5feaa3c5a6a0186c03', # noqa: E501 log_index=22, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x997c0fc9578a8194EFDdE2E0cD7aa6A69cFCD7c1' ), # noqa: E501 timestamp=Timestamp(1607010888), location=Location.BALANCER, token0=A_WETH, token1=A_API3, amount0_in=AssetAmount(FVal('0.990253067370299904')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('295.881648100500428692')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_MFT, amount=AssetAmount(FVal('0.686544199299304057')), rate=Price(FVal('243775.0324093115004367119900')), trade_index=0, swaps=[ AMMSwap( tx_hash= '0xf0147c4b81098676c08ae20ae5bf8f8b60d0ad79eec484f3f93ac6ab49a3c51c', # noqa: E501 log_index=97, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x2Eb6CfbFFC8785Cd0D9f2d233d0a617bF4269eeF' ), # noqa: E501 timestamp=Timestamp(1607015059), location=Location.BALANCER, token0=A_MFT, token1=A_WETH, amount0_in=AssetAmount(FVal('167362.334434612660404224')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('0.686544199299304057')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_WETH, quote_asset=A_AAVE, amount=AssetAmount(FVal('3.055412574642681758')), rate=Price(FVal('6.916116208273240607778771150')), trade_index=1, swaps=[ AMMSwap( tx_hash= '0x67c0e9a0fdd002d0b9d1cca0c8e4ca4d30435bbf57bbf0091396275efaea414b', # noqa: E501 log_index=37, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x0E552307659E70bF61f918f96AA880Cdec40d7E2' ), # noqa: E501 timestamp=Timestamp(1607015339), location=Location.BALANCER, token0=A_AAVE, token1=A_WETH, amount0_in=AssetAmount(FVal('21.131588430448123904')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('3.055412574642681758')), ), ], ), AMMTrade( trade_type=TradeType.BUY, base_asset=A_AAVE, quote_asset=A_WETH, amount=AssetAmount(FVal('21.131588567541018817')), rate=Price(FVal('0.1435213742524287826717337545')), trade_index=0, swaps=[ AMMSwap( tx_hash= '0x67c0e9a0fdd002d0b9d1cca0c8e4ca4d30435bbf57bbf0091396275efaea414b', # noqa: E501 log_index=31, address=string_to_ethereum_address( '0x029f388aC4D5C8BfF490550ce0853221030E822b' ), # noqa: E501 from_address=string_to_ethereum_address( '0x0000000000007F150Bd6f54c40A34d7C3d5e9f56' ), # noqa: E501 to_address=string_to_ethereum_address( '0x7c90a3cd7Ec80dd2F633ed562480AbbEEd3bE546' ), # noqa: E501 timestamp=Timestamp(1607015339), location=Location.BALANCER, token0=A_WETH, token1=A_AAVE, amount0_in=AssetAmount(FVal('3.0328346313504')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('21.131588567541018817')), ), ], ), ]
def get_expected_trades(): """Function so no price (unknown) assets can be resolved only when existing in the DB""" address = string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121') return [AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), quote_asset=EthereumToken('0x4b4D2e899658FB59b1D518b68fe836B100ee8958'), amount=AssetAmount(FVal('796.857811')), rate=Price(FVal('0.0008323741932057006980885326353')), trade_index=0, swaps=[AMMSwap( tx_hash='0x962d904d75c751fbff316f7a2ed280bd93241d5088d747a4f26fe7437813512f', log_index=141, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121'), timestamp=Timestamp(1609308616), location=Location.SUSHISWAP, token0=EthereumToken('0x4b4D2e899658FB59b1D518b68fe836B100ee8958'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(FVal('0.663283877530785731')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('796.857811')), )], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), quote_asset=EthereumToken('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), amount=AssetAmount(FVal('2.223721994593087248')), rate=Price(FVal('1124.241252314216598775470692')), trade_index=0, swaps=[AMMSwap( tx_hash='0x90f68af0ebbbb8d4938a4fbd07a70862e806124abd907d1225f25a10afda0180', log_index=26, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x06da0fd433C1A5d7a4faa01111c044910A184553'), timestamp=Timestamp(1609303966), location=Location.SUSHISWAP, token0=EthereumToken('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), token1=EthereumToken('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), amount0_in=AssetAmount(FVal('2500')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('3.410623314913014194')), ), AMMSwap( tx_hash='0x90f68af0ebbbb8d4938a4fbd07a70862e806124abd907d1225f25a10afda0180', log_index=29, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0xC9cB53B48A2f3A9e75982685644c1870F1405CCb'), timestamp=Timestamp(1609303966), location=Location.SUSHISWAP, token0=EthereumToken('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(FVal('3.410623314913014194')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('2474.601464')), ), AMMSwap( tx_hash='0x90f68af0ebbbb8d4938a4fbd07a70862e806124abd907d1225f25a10afda0180', log_index=32, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121'), timestamp=Timestamp(1609303966), location=Location.SUSHISWAP, token0=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(ZERO), amount1_in=AssetAmount(FVal('2474.601464')), amount0_out=AssetAmount(FVal('2.223721994593087248')), amount1_out=AssetAmount(ZERO), )], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), quote_asset=EthereumToken('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), amount=AssetAmount(FVal('1.925851508322134245')), rate=Price(FVal('1012.539124420295894184748806')), trade_index=0, swaps=[AMMSwap( tx_hash='0xa54bf4c68d435e3c8f432fd7e62b7f8aca497a831a3d3fca305a954484ddd7b2', log_index=205, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x06da0fd433C1A5d7a4faa01111c044910A184553'), timestamp=Timestamp(1609301469), location=Location.SUSHISWAP, token0=EthereumToken('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), token1=EthereumToken('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), amount0_in=AssetAmount(FVal('1950')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('2.6455727132446468')), ), AMMSwap( tx_hash='0xa54bf4c68d435e3c8f432fd7e62b7f8aca497a831a3d3fca305a954484ddd7b2', log_index=208, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0xC9cB53B48A2f3A9e75982685644c1870F1405CCb'), timestamp=Timestamp(1609301469), location=Location.SUSHISWAP, token0=EthereumToken('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(FVal('2.6455727132446468')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('1936.810111')), ), AMMSwap( tx_hash='0xa54bf4c68d435e3c8f432fd7e62b7f8aca497a831a3d3fca305a954484ddd7b2', log_index=211, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121'), timestamp=Timestamp(1609301469), location=Location.SUSHISWAP, token0=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(ZERO), amount1_in=AssetAmount(FVal('1936.810111')), amount0_out=AssetAmount(FVal('1.925851508322134245')), amount1_out=AssetAmount(ZERO), )], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), quote_asset=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), amount=AssetAmount(FVal('951.611472')), rate=Price(FVal('0.001050849038104071952592013309')), trade_index=0, swaps=[AMMSwap( tx_hash='0xb3cea8179e8bc349661f265937187403ae4914c108d118889d026bac1fbec4e9', log_index=9, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121'), timestamp=Timestamp(1609296759), location=Location.SUSHISWAP, token0=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(FVal('1')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('951.611472')), )], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), quote_asset=EthereumToken('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), amount=AssetAmount(FVal('1')), rate=Price(FVal('511.20342')), trade_index=0, swaps=[AMMSwap( tx_hash='0x0ccec8fd15c8d3ab923ee4a2406778f22769e74da20b19a35e614bfead6bab8d', log_index=242, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x06da0fd433C1A5d7a4faa01111c044910A184553'), timestamp=Timestamp(1609294923), location=Location.SUSHISWAP, token0=EthereumToken('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), token1=EthereumToken('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), amount0_in=AssetAmount(FVal('511.20342')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('0.690577933591789501')), ), AMMSwap( tx_hash='0x0ccec8fd15c8d3ab923ee4a2406778f22769e74da20b19a35e614bfead6bab8d', log_index=245, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0xC9cB53B48A2f3A9e75982685644c1870F1405CCb'), timestamp=Timestamp(1609294923), location=Location.SUSHISWAP, token0=EthereumToken('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(FVal('0.690577933591789501')), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('506.399839')), ), AMMSwap( tx_hash='0x0ccec8fd15c8d3ab923ee4a2406778f22769e74da20b19a35e614bfead6bab8d', log_index=248, address=address, from_address=string_to_ethereum_address('0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'), to_address=string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121'), timestamp=Timestamp(1609294923), location=Location.SUSHISWAP, token0=EthereumToken('0x368B3a58B5f49392e5C9E4C998cb0bB966752E51'), token1=EthereumToken('0xdAC17F958D2ee523a2206206994597C13D831ec7'), amount0_in=AssetAmount(ZERO), amount1_in=AssetAmount(FVal('506.399839')), amount0_out=AssetAmount(FVal('1')), amount1_out=AssetAmount(ZERO), )], )]
assert lp_asset['user_balance']['amount'] assert lp_asset['user_balance']['usd_value'] EXPECTED_TRADES = [AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('USDT'), quote_asset=EthereumToken('WETH'), amount=AssetAmount(FVal('20632.012923')), rate=Price(FVal('0.002665760253508154513092246380')), trade_index=0, swaps=[AMMSwap( tx_hash='0x13723c8b286ec56e95b00e091557e6a76f723d20a52503d2e08df5867d942b51', log_index=319, address=deserialize_ethereum_address('0x21d05071cA08593e13cd3aFD0b4869537e015C92'), from_address=deserialize_ethereum_address('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'), to_address=deserialize_ethereum_address('0x21d05071cA08593e13cd3aFD0b4869537e015C92'), timestamp=Timestamp(1603180607), location=Location.UNISWAP, token0=EthereumToken('WETH'), token1=EthereumToken('USDT'), amount0_in=AssetAmount(FVal(55)), amount1_in=AssetAmount(ZERO), amount0_out=AssetAmount(ZERO), amount1_out=AssetAmount(FVal('20632.012923')), )], ), AMMTrade( trade_type=TradeType.BUY, base_asset=EthereumToken('DAI'), quote_asset=EthereumToken('WETH'), amount=AssetAmount(FVal('1411.453463704718081611')),