Skip to content

Commit

Permalink
Merge pull request #137 from ClipFinance/clip.finance
Browse files Browse the repository at this point in the history
Clip.finance: yield: retry on too many request
  • Loading branch information
nitish-91 committed May 16, 2024
2 parents df9ca46 + 7e37f6b commit 5b640a2
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions adapters/clip-finance/src/sdk/subgraphDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ interface UserSharesSnapshot {
shares1: Big;
}

function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}

export const getUserBalanceSnapshotAtBlock = async (
blockNumber: number,
address: string
Expand Down Expand Up @@ -69,20 +73,28 @@ export const getUserBalanceSnapshotAtBlock = async (
}
}
`;

let response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
if (response.status != 200) {
subgraphUrl = RESERVE_SUBGRAPH_URLS[CHAINS.LINEA];
let count = 0;
let response;
do {
response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
}
if (response.status != 200) {
subgraphUrl = RESERVE_SUBGRAPH_URLS[CHAINS.LINEA];
response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
}
if (response.status != 200) {
console.log("sharePrices fetching failed. Try again in 15 sec");
await delay(15000);
}
++count
} while ((response.status != 200) && (count < 10))

let data = await response.json();
let snapshots = data.data.sharePrices;
Expand Down Expand Up @@ -142,12 +154,22 @@ export const getUserBalanceSnapshotAtBlock = async (
}
}
`;

const response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
let count = 0;
let response;
do {
response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
if (response.status != 200) {
await delay(15000);
console.log("userShares fetching failed. Try again in 15 sec");
}
++count;
} while ((count < 10) && (response.status != 200)) {

}
let data = await response.json();
let snapshots = data.data.userShares;
for (const snapshot of snapshots) {
Expand Down Expand Up @@ -223,12 +245,21 @@ export const getUserBalanceSnapshotAtBlock = async (
}
}
`;

const response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});

let count = 0;
let response;
do {
response = await fetch(subgraphUrl, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
if (response.status != 200) {
console.log("sharesTokenSharesCounts fetching failed. Try again in 15 sec");
await delay(15000)
}
++count;
} while ((count < 10) && (response.status != 200));
let data = await response.json();
let snapshots = data.data.sharesTokenSharesCounts;
let strategyRouterTotalShares: Big = Big(0);
Expand Down

0 comments on commit 5b640a2

Please sign in to comment.