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

linehub fix for blockNumbers older then subgraph block start #312

Merged
merged 2 commits into from
Oct 31, 2024
Merged
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
25 changes: 20 additions & 5 deletions adapters/linehub/src/sdk/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export const getV2UserPositionsAtBlock = async (blockNumber: number): Promise<Us
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
})
const { data: { liquidityPositions } } = await response.json();

const jsonData = await response.json();

let liquidityPositions: V2Position[] = [];
if (jsonData?.data?.liquidityPositions) {
liquidityPositions = jsonData.data.liquidityPositions
}

result.push(...liquidityPositions.map((position: V2Position) => {
const { reserve0, reserve1 } = getV2PositionReserves(position)
Expand Down Expand Up @@ -107,7 +113,6 @@ export const getTradeLiquidityForAddressByPoolAtBlock = async (blockNumber: numb
let skip = 0;
let fetchNext = true;
let result: any[] = [];
let _stores: any[] = [];
while (fetchNext) {
let query = `{
liquidities(where: {period: "user" amountDelta_gt: 1 } ${blockQuery} orderBy: createTimestamp, first:1000,skip:${skip}) {
Expand All @@ -124,8 +129,14 @@ export const getTradeLiquidityForAddressByPoolAtBlock = async (blockNumber: numb
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
const { data: { liquidities, stores } } = await response.json();
_stores = stores

const jsonData = await response.json();

let liquidities = []
if (jsonData?.data?.liquidities) {
liquidities = jsonData.data.liquidities
}

result = result.concat(liquidities)

if (liquidities.length < 1000) {
Expand Down Expand Up @@ -244,8 +255,12 @@ export const getV3UserPositionsAtBlock = async (blockNumber: number): Promise<Us
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
})
const jsonData = await response.json();

const { data: { positions } } = await response.json();
let positions: V3Position[] = [];
if (jsonData?.data?.positions) {
positions = jsonData.data.positions
}

result.push(...positions.map((position: V3Position) => {
const { reserve0, reserve1 } = getV3PositionReserves(position)
Expand Down
5 changes: 5 additions & 0 deletions adapters/linehub/test/sample_hourly_blocks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
number,timestamp
3041467,1711023841
6985794,1721374858
10453513,1728336884
11453160,1730371800
19 changes: 19 additions & 0 deletions adapters/linehub/test/sample_output_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
block_number,timestamp,user_address,token_address,token_balance,token_symbol,usd_price
6985794,1721374858,0x7e8fd89851d666cfa3824102e8033da73a58235b,0x4af15ec2a0bd43db75dd04e62faa3b8ef36b00d5,4018512226963123,,0
6985794,1721374858,0x7e8fd89851d666cfa3824102e8033da73a58235b,0xa219439258ca9da29e9cc4ce5596924745e12b93,4239,,0
6985794,1721374858,0x921a712e6433177001e0c1d1cd5cbd84e1ac26cb,0x4af15ec2a0bd43db75dd04e62faa3b8ef36b00d5,3651716042344296,,0
6985794,1721374858,0x921a712e6433177001e0c1d1cd5cbd84e1ac26cb,0xa219439258ca9da29e9cc4ce5596924745e12b93,3852,,0
6985794,1721374858,0x2fb7f6f02e86daeb1f6b429a697eccbe1f204c5b,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,5194144,,0
6985794,1721374858,0x2fb7f6f02e86daeb1f6b429a697eccbe1f204c5b,0xa219439258ca9da29e9cc4ce5596924745e12b93,4465534,,0
6985794,1721374858,0x2fb7f6f02e86daeb1f6b429a697eccbe1f204c5b,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,36965208985650,,0
6985794,1721374858,0x67c9ac4a17a1e874d95c91e35abf28756572a8b4,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,4700693,,0
11453160,1730371800,0xf3891f2992945923003556cf7a5fe938113981ab,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,12158579,,0
11453160,1730371800,0x9e7dc81657b34f0bfd95ffc5f224424caddefb94,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,41902696900947488,,0
11453160,1730371800,0x59ea9ed47ccaf5c1e7f247e9c6b950bf49f9bf74,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,177626295,,0
11453160,1730371800,0xa1ca490a686227811aea407cfc04462c5ca6581e,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,254437628241,,0
11453160,1730371800,0xfeab83188c7a337b48bc7375c5e43915401f8c4c,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,658,,0
11453160,1730371800,0xd8c510dafab5e3c967d54b663a6f09aaafe079ad,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,7951175882532730,,0
11453160,1730371800,0xe3852ff09de17aa9edc5dbebe201623fb9902027,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,1590235176506546,,0
11453160,1730371800,0xc009a558ac7bb7748a738c9128c4726e5966aeb9,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,8030687641358057,,0
11453160,1730371800,0xfbfc3a9e2775c2ea42556719f9cd69aa17953810,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,152915228913484,,0
11453160,1730371800,0x3aa6fcc9c6686d6d0befcc8bb88ec1dd85877358,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,9255168727268097,,0
Loading