Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon committed May 7, 2024
2 parents 3973dc1 + e31e3dd commit 06caa25
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 231 deletions.
11 changes: 7 additions & 4 deletions adapters/connext/src/utils/getUserTvlByBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCompositeBalances, getLpAccountBalanceAtBlock } from "./subgraph";
import { getBlock, getCompositeBalances, getLpAccountBalanceAtBlock } from "./subgraph";
import { BlockData, OutputDataSchemaRow } from "./types";

export const getUserTVLByBlock = async (blocks: BlockData): Promise<OutputDataSchemaRow[]> => {
Expand All @@ -9,13 +9,16 @@ export const getUserTVLByBlock = async (blocks: BlockData): Promise<OutputDataSc
// get the composite balances
const composite = await getCompositeBalances(data);

// get block info
const { timestamp } = await getBlock(blockNumber);

// format into output
const results: OutputDataSchemaRow[] = [];
composite.forEach(({ block, modified, account, underlyingBalances, underlyingTokens }) => {
composite.forEach(({ account, underlyingBalances, underlyingTokens }) => {
results.push(...underlyingBalances.map((b, i) => {
const formatted: OutputDataSchemaRow = {
timestamp: +modified,
block_number: +block,
timestamp: +timestamp.toString(),
block_number: blockNumber,
user_address: account.id,
token_address: underlyingTokens[i],
token_balance: BigInt(b),
Expand Down
7 changes: 6 additions & 1 deletion adapters/connext/src/utils/subgraph.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PoolInformation, getPoolInformationFromLpToken } from "./cartographer";
import { LpAccountBalanceHourly, SubgraphResult } from "./types";
import { linea } from "viem/chains";
import { createPublicClient, formatUnits, http, parseUnits } from "viem";
import { createPublicClient, http, parseUnits } from "viem";

export const CONNEXT_SUBGRAPH_QUERY_URL = "https://api.goldsky.com/api/public/project_clssc64y57n5r010yeoly05up/subgraphs/amarok-stableswap-analytics/1.0/gn";
export const LINEA_CHAIN_ID = 59144;
Expand Down Expand Up @@ -209,3 +209,8 @@ const appendSubgraphData = (data: LpAccountBalanceHourly[], existing: Map<string
})
}

export const getBlock = async (blockNumber: number) => {
const client = createPublicClient({ chain: linea, transport: http() });
const block = await client.getBlock({ blockNumber: BigInt(blockNumber) });
return block;
}
4 changes: 3 additions & 1 deletion adapters/lyve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"author": "",
"license": "UNLICENSED",
"dependencies": {
"fast-csv": "^5.0.1",
"csv-parser": "^3.0.0",
"fast-csv": "^5.0.1",
"lodash": "^4.17.21",
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@types/lodash": "^4.17.1",
"@types/node": "^20.11.30",
"typescript": "^5.4.3"
}
Expand Down
Loading

0 comments on commit 06caa25

Please sign in to comment.