Skip to content

Commit

Permalink
Merge pull request #63 from keyko-io/feat/swap_usd_amount
Browse files Browse the repository at this point in the history
amount usd swaps
  • Loading branch information
ialberquilla committed Oct 31, 2021
2 parents b8b4098 + cbfb79e commit 8477917
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 3 deletions.
7 changes: 6 additions & 1 deletion deficrawler/config/balancer-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"poolId",
"address"
],
"amount_usd": [
"id"
],
"timestamp": [
"timestamp"
]
Expand All @@ -48,7 +51,9 @@
"pool": "poolAddress"
}
},
"transformations": {}
"transformations": {
"amount_usd": "na"
}
}
}
}
3 changes: 3 additions & 0 deletions deficrawler/config/dodoex-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"pair",
"id"
],
"amount_usd": [
"volumeUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/pancakeswap-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/pangolin-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/quickswap-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/sushiswap-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/traderjoe-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/ubeswap-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/uniswap-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"pair",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
3 changes: 3 additions & 0 deletions deficrawler/config/uniswap-3.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"pool",
"id"
],
"amount_usd": [
"amountUSD"
],
"timestamp": [
"timestamp"
]
Expand Down
9 changes: 8 additions & 1 deletion deficrawler/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(self):
"rates_units_aave": self.rates_units_aave,
"rates_units_comp": self.rates_units_comp,
"rates_na": self.rates_na,
"to_int": self.to_int
"to_int": self.to_int,
"na": self.na
}

def transform(self, element, common_field, protocol_field, transformations, query_elements):
Expand Down Expand Up @@ -333,3 +334,9 @@ def to_int(self, common_field, element, protocol_field, query_elements):
*query_elements[common_field])

return int(ele)

def na(self, common_field, element, protocol_field, query_elements):
"""
Returns NA for non applicable field
"""
return 'NA'
22 changes: 21 additions & 1 deletion tests/int/test_swaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def test_swap_uniswap_2_eth():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand Down Expand Up @@ -63,6 +65,7 @@ def test_swap_shushi_1_eth():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -77,7 +80,7 @@ def test_swap_shushi_1_eth():
def test_swap_shushi_1_bsc():
shushi = Dex(protocol="SushiSwap", chain="bsc", version=1)
swaps = shushi.get_data_from_date_range(
'04/05/2021 00:00:00', '04/05/2021 0:31:30', "swap")
'05/05/2021 00:00:00', '05/05/2021 0:31:30', "swap")
assert(swaps[0]['tx_id'] != "")
assert(swaps[0]['protocol'] == "SushiSwap")
assert(swaps[0]['chain'] == "bsc")
Expand All @@ -86,6 +89,7 @@ def test_swap_shushi_1_bsc():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) >= 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -103,6 +107,7 @@ def test_swap_shushi_1_polygon():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -120,6 +125,7 @@ def test_swap_shushi_1_celo():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -137,6 +143,7 @@ def test_swap_shushi_1_fantom():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -154,6 +161,7 @@ def test_swap_uniswap_3_eth():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -171,6 +179,7 @@ def test_swap_uniswap_3_optimism():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand Down Expand Up @@ -207,6 +216,7 @@ def test_swap_balancer_2_eth():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(swaps[0]['amount_usd'] == 'NA')
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -225,6 +235,7 @@ def test_swap_balancer_2_polygon():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(swaps[0]['amount_usd'] == 'NA')
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -243,6 +254,7 @@ def test_swap_balancer_2_arbitrum():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(swaps[0]['amount_usd'] == 'NA')
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -261,6 +273,7 @@ def test_swap_pancakeswap_2_bsc():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) >= 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -279,6 +292,7 @@ def test_swap_quickswap_1_polygon():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -297,6 +311,7 @@ def test_swap_pangolin_1_avalanche():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -315,6 +330,7 @@ def test_swap_traderjoe_1_avalanche():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -333,6 +349,7 @@ def test_swap_dodoex_2_ethereum():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -351,6 +368,7 @@ def test_swap_dodoex_2_polygon():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -369,6 +387,7 @@ def test_swap_dodoex_2_bsc():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) > 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)
Expand All @@ -387,6 +406,7 @@ def test_swap_dodoex_2_arbitrum():
assert(swaps[0]['from_token'] != "")
assert(swaps[0]['to_token'] != "")
assert(swaps[0]['pool'] != "")
assert(float(swaps[0]['amount_usd']) >= 0)
assert(float(swaps[0]['from_token_amount']) > 0)
assert(float(swaps[0]['to_token_amount']) > 0)
assert(float(swaps[0]['timestamp']) > 0)

0 comments on commit 8477917

Please sign in to comment.