Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pricing issues in uniswap-v2 #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uniswap-v2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build:

.PHONY: run
run:
substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml graph_out -s 10008300
substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_events_entity -s 10008300
.PHONY: pack
pack:
substreams pack ./substreams.yaml
26 changes: 13 additions & 13 deletions uniswap-v2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ type LiquidityPool @entity {
cumulativeVolumeUSD: BigDecimal!

" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [String!]!
inputTokenBalances: [BigInt!]!

" Weights of input tokens in the liquidity pool in percentage values. For example, 50/50 for Uniswap pools, 48.2/51.8 for a Curve pool, 10/10/80 for a Balancer pool "
inputTokenWeights: [String!]!
inputTokenWeights: [BigDecimal!]!

" Total supply of output token. Note that certain DEXes don't have an output token (e.g. Bancor) "
outputTokenSupply: BigInt
Expand Down Expand Up @@ -515,19 +515,19 @@ type LiquidityPoolDailySnapshot @entity {
dailyVolumeUSD: BigDecimal!

" All trade volume occurred in a given day for a specific input token, in native amount. The ordering should be the same as the pool's `inputTokens` field. "
dailyVolumeByTokenAmount: [String!]!
dailyVolumeByTokenAmount: [BigInt!]!

" All trade volume occurred in a given day for a specific input token, in USD. The ordering should be the same as the pool's `inputTokens` field. "
dailyVolumeByTokenUSD: [String!]!
dailyVolumeByTokenUSD: [BigDecimal!]!

" All historical trade volume occurred in this pool, in USD "
cumulativeVolumeUSD: BigDecimal!

" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [String!]!
inputTokenBalances: [BigInt!]!

" Weights of input tokens in the liquidity pool in percentage values. For example, 50/50 for Uniswap pools, 48.2/51.8 for a Curve pool, 10/10/80 for a Balancer pool "
inputTokenWeights: [String!]!
inputTokenWeights: [BigDecimal!]!

" Total supply of output token. Note that certain DEXes don't have an output token (e.g. Bancor) "
outputTokenSupply: BigInt
Expand All @@ -544,7 +544,7 @@ type LiquidityPoolDailySnapshot @entity {
" Per-block reward token emission as of the current block normalized to a day, in USD value. This should be ideally calculated as the theoretical rate instead of the realized amount. "
rewardTokenEmissionsUSD: [BigDecimal!]

_inputTokenPrices: [String!]
_inputTokenPrices: [BigDecimal!]
}

type LiquidityPoolHourlySnapshot @entity {
Expand Down Expand Up @@ -590,19 +590,19 @@ type LiquidityPoolHourlySnapshot @entity {
hourlyVolumeUSD: BigDecimal!

" All trade volume occurred in a given hour for a specific input token, in native amount. The ordering should be the same as the pool's `inputTokens` field. "
hourlyVolumeByTokenAmount: [String!]!
hourlyVolumeByTokenAmount: [BigInt!]!

" All trade volume occurred in a given hour for a specific input token, in USD. The ordering should be the same as the pool's `inputTokens` field. "
hourlyVolumeByTokenUSD: [String!]!
hourlyVolumeByTokenUSD: [BigDecimal!]!

" All historical trade volume occurred in this pool, in USD "
cumulativeVolumeUSD: BigDecimal!

" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [String!]!
inputTokenBalances: [BigInt!]!

" Weights of input tokens in the liquidity pool in percentage values. For example, 50/50 for Uniswap pools, 48.2/51.8 for a Curve pool, 10/10/80 for a Balancer pool "
inputTokenWeights: [String!]!
inputTokenWeights: [BigDecimal!]!

" Total supply of output token. Note that certain DEXes don't have an output token (e.g. Bancor) "
outputTokenSupply: BigInt
Expand Down Expand Up @@ -690,7 +690,7 @@ type Deposit implements Event @entity {
outputToken: Token

" Amount of input tokens in the token's native unit "
inputTokenAmounts: [String!]!
inputTokenAmounts: [BigInt!]!

" Amount of output tokens in the token's native unit "
outputTokenAmount: BigInt
Expand Down Expand Up @@ -734,7 +734,7 @@ type Withdraw implements Event @entity {
outputToken: Token

" Amount of input tokens in the token's native unit "
inputTokenAmounts: [String!]!
inputTokenAmounts: [BigInt!]!

" Amount of output tokens in the token's native unit "
outputTokenAmount: BigInt
Expand Down
23 changes: 23 additions & 0 deletions uniswap-v2/src/common/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,26 @@ pub const WHITELIST_TOKENS: [&str; 21] = [
"0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", // AAVE
"0xfe2e637202056d30016725477c5da089ab0a043a", // sETH2
];

pub const BLACKLISTED_TOKENS: [&str; 12] = [
"0x9d1555d8cb3c846bb4f7d5b1b1080872c3166676", // Wrapped Mirror SLV Token
"0x76306f029f8f99effe509534037ba7030999e3cf", // Acreage
"0x9d86f93ff837b80032e3fd7b3f8e1aacc25d3d80", // MIR EAEUnion
"0xb611920d44324655335b5e11ebc9c929faddfbaf", // Lawa USD
"0x0698dda3c390ff92722f9eed766d8b1727621df9", // Ethereum2Proof-of-stake
"0x35bd8472ed2da9eed980e49b8b92ccbcf625adbd", // Enreich
"0xf2bae67cc0b4642b9bc71264cc878598cb0722bd", // Nicaragua Canal
"0x2b591e99afe9f32eaa6214f7b7629768c40eeb39", // HEX
"0x9bb6fd000109e24eb38b0deb806382ff9247e478", // hex.bet
"0x57bfb100498f5ce6c54298f0730f1bc9b67addd6", // MAGGIE
"0x72e5390edb7727e3d4e3436451dadaff675dbcc0", // Hanu Yokia
"0x395c8db957d743a62ac3aaaa4574553bcf2380b3", // ulock.eth Wrapped Ether
];

pub const BLACKLISTED_POOLS: [&str; 5] = [
"0x1f447690a6ddf18400533b705516159e1312f892",
"0x340a5a2f73ebaa181ec2826802fdf8ed21fc759a",
"0x6a9e7f087a7d1057dd36a84ae148dac2c07ea67e",
"0x13bb5add7fd43c52d987e2c320f95d4b5e9cfa5f",
"0x1693c24445895bd8f4d5a327eafa0263191ed906",
];
45 changes: 24 additions & 21 deletions uniswap-v2/src/modules/11_store_cumulative_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@ pub fn store_cumulative_fields(
for delta in volume_deltas.deltas {
if let Some(pool_address) = StoreKey::Volume.get_pool(&delta.key) {
let volume = utils::delta_value(&delta);
output_store.add(
delta.ordinal,
StoreKey::CumulativeVolumeUSD.get_unique_pool_key(&pool_address),
&volume,
);

let (supply_side_revenue, protocol_side_revenue) = utils::calculate_revenue(volume);
output_store.add(
delta.ordinal,
StoreKey::CumulativeSupplySideRevenueUSD.get_unique_pool_key(&pool_address),
&supply_side_revenue,
);
output_store.add(
delta.ordinal,
StoreKey::CumulativeProtocolSideRevenueUSD.get_unique_pool_key(&pool_address),
&protocol_side_revenue,
);
output_store.add(
delta.ordinal,
StoreKey::CumulativeTotalRevenueUSD.get_unique_pool_key(&pool_address),
&(supply_side_revenue + protocol_side_revenue),
);
if utils::is_valid_amount(&volume) {
output_store.add(
delta.ordinal,
StoreKey::CumulativeVolumeUSD.get_unique_pool_key(&pool_address),
&volume,
);

let (supply_side_revenue, protocol_side_revenue) = utils::calculate_revenue(volume);
output_store.add(
delta.ordinal,
StoreKey::CumulativeSupplySideRevenueUSD.get_unique_pool_key(&pool_address),
&supply_side_revenue,
);
output_store.add(
delta.ordinal,
StoreKey::CumulativeProtocolSideRevenueUSD.get_unique_pool_key(&pool_address),
&protocol_side_revenue,
);
output_store.add(
delta.ordinal,
StoreKey::CumulativeTotalRevenueUSD.get_unique_pool_key(&pool_address),
&(supply_side_revenue + protocol_side_revenue),
);
}
}
}
}
11 changes: 6 additions & 5 deletions uniswap-v2/src/modules/12_map_liquidity_pool_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ fn create_liquidity_pool(
ordinal,
StoreKey::Token0Balance.get_unique_pool_key(&pool_address),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
input_token_balances_store
.get_at(
ordinal,
StoreKey::Token1Balance.get_unique_pool_key(&pool_address),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
],
)
.change("inputTokenWeights", vec!["0.5".to_string(); 2])
.change(
"inputTokenWeights",
vec![BigDecimal::try_from("0.5").unwrap(); 2],
)
.change(
"outputTokenSupply",
output_token_supply_store
Expand Down
46 changes: 22 additions & 24 deletions uniswap-v2/src/modules/14_map_liquidity_pool_snapshots_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ fn create_liquidity_pool_daily_snapshot(
vec![&pool_address, &pool.token0_address()],
),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
volume_by_token_amount_store
.get_at(
ordinal,
Expand All @@ -206,8 +205,7 @@ fn create_liquidity_pool_daily_snapshot(
vec![&pool_address, &pool.token1_address()],
),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
],
)
.change(
Expand All @@ -222,7 +220,7 @@ fn create_liquidity_pool_daily_snapshot(
),
)
.unwrap_or(BigDecimal::zero())
.to_string(),
.with_prec(20),
daily_and_hourly_fields_store
.get_at(
ordinal,
Expand All @@ -232,7 +230,7 @@ fn create_liquidity_pool_daily_snapshot(
),
)
.unwrap_or(BigDecimal::zero())
.to_string(),
.with_prec(20),
],
)
.change(
Expand All @@ -252,18 +250,19 @@ fn create_liquidity_pool_daily_snapshot(
ordinal,
StoreKey::Token0Balance.get_unique_pool_key(&pool_address),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
balances_store
.get_at(
ordinal,
StoreKey::Token1Balance.get_unique_pool_key(&pool_address),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
],
)
.change("inputTokenWeights", vec!["0.5".to_string(); 2])
.change(
"inputTokenWeights",
vec![BigDecimal::try_from("0.5").unwrap(); 2],
)
.change(
"outputTokenSupply",
pool_supply_store
Expand All @@ -282,14 +281,14 @@ fn create_liquidity_pool_daily_snapshot(
StoreKey::TokenPrice.get_unique_pool_key(&pool.token0_address()),
)
.unwrap_or(BigDecimal::zero())
.to_string(),
.with_prec(20),
prices_store
.get_at(
ordinal,
StoreKey::TokenPrice.get_unique_pool_key(&pool.token1_address()),
)
.unwrap_or(BigDecimal::zero())
.to_string(),
.with_prec(20),
],
)
.change("blockNumber", block_number)
Expand Down Expand Up @@ -416,8 +415,7 @@ fn create_liquidity_pool_hourly_snapshot(
vec![&pool_address, &pool.token0_address()],
),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
volume_by_token_amount_store
.get_at(
ordinal,
Expand All @@ -426,8 +424,7 @@ fn create_liquidity_pool_hourly_snapshot(
vec![&pool_address, &pool.token1_address()],
),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
],
)
.change(
Expand All @@ -442,7 +439,7 @@ fn create_liquidity_pool_hourly_snapshot(
),
)
.unwrap_or(BigDecimal::zero())
.to_string(),
.with_prec(20),
daily_and_hourly_fields_store
.get_at(
ordinal,
Expand All @@ -452,7 +449,7 @@ fn create_liquidity_pool_hourly_snapshot(
),
)
.unwrap_or(BigDecimal::zero())
.to_string(),
.with_prec(20),
],
)
.change(
Expand All @@ -472,18 +469,19 @@ fn create_liquidity_pool_hourly_snapshot(
ordinal,
StoreKey::Token0Balance.get_unique_pool_key(&pool_address),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
balances_store
.get_at(
ordinal,
StoreKey::Token1Balance.get_unique_pool_key(&pool_address),
)
.unwrap_or(BigInt::zero())
.to_string(),
.unwrap_or(BigInt::zero()),
],
)
.change("inputTokenWeights", vec!["0.5".to_string(); 2])
.change(
"inputTokenWeights",
vec![BigDecimal::try_from("0.5").unwrap(); 2],
)
.change(
"outputTokenSupply",
pool_supply_store
Expand Down
15 changes: 10 additions & 5 deletions uniswap-v2/src/modules/18_map_protocol_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ fn create_protocol(
ordinal,
StoreKey::TotalValueLockedUSD.get_unique_protocol_key(),
)
.unwrap_or(BigDecimal::zero()),
.unwrap_or(BigDecimal::zero())
.with_prec(20),
)
.change(
"cumulativeVolumeUSD",
Expand All @@ -75,7 +76,8 @@ fn create_protocol(
ordinal,
StoreKey::CumulativeVolumeUSD.get_unique_protocol_key(),
)
.unwrap_or(BigDecimal::zero()),
.unwrap_or(BigDecimal::zero())
.with_prec(20),
)
.change(
"cumulativeSupplySideRevenueUSD",
Expand All @@ -84,7 +86,8 @@ fn create_protocol(
ordinal,
StoreKey::CumulativeSupplySideRevenueUSD.get_unique_protocol_key(),
)
.unwrap_or(BigDecimal::zero()),
.unwrap_or(BigDecimal::zero())
.with_prec(20),
)
.change(
"cumulativeProtocolSideRevenueUSD",
Expand All @@ -93,7 +96,8 @@ fn create_protocol(
ordinal,
StoreKey::CumulativeProtocolSideRevenueUSD.get_unique_protocol_key(),
)
.unwrap_or(BigDecimal::zero()),
.unwrap_or(BigDecimal::zero())
.with_prec(20),
)
.change(
"cumulativeTotalRevenueUSD",
Expand All @@ -102,7 +106,8 @@ fn create_protocol(
ordinal,
StoreKey::CumulativeTotalRevenueUSD.get_unique_protocol_key(),
)
.unwrap_or(BigDecimal::zero()),
.unwrap_or(BigDecimal::zero())
.with_prec(20),
)
.change("cumulativeUniqueUsers", 0)
.change("totalPoolCount", 0);
Expand Down
Loading