-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: zero values and math rounding
- Loading branch information
Showing
9 changed files
with
2,479 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "mendi-tvl", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node dist/index.js", | ||
"compile": "tsc", | ||
"watch": "tsc -w", | ||
"clear": "rm -rf dist" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@types/big.js": "^6.2.2", | ||
"big.js": "^6.2.1", | ||
"bignumber.js": "^9.1.2", | ||
"csv-parser": "^3.0.0", | ||
"decimal.js-light": "^2.5.1", | ||
"fast-csv": "^5.0.1", | ||
"jsbi": "^4.3.0", | ||
"tiny-invariant": "^1.3.1", | ||
"toformat": "^2.0.0", | ||
"viem": "^2.8.13" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.17", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { CHAINS, PROTOCOLS, SNAPSHOTS_BLOCKS } from "./sdk/config"; | ||
import { | ||
getLPValueByUserAndPoolFromActivities, | ||
getActivitiesForAddressByPoolAtBlock, | ||
getTimestampAtBlock, | ||
} from "./sdk/subgraphDetails"; | ||
|
||
(BigInt.prototype as any).toJSON = function () { | ||
return this.toString(); | ||
}; | ||
|
||
import fs from "fs"; | ||
import { write } from "fast-csv"; | ||
import { getMarketInfos } from "./sdk/marketDetails"; | ||
import { exit } from "process"; | ||
import { bigMath } from "./sdk/abi/helpers"; | ||
|
||
interface CSVRow { | ||
block_number: string; | ||
timestamp: string; | ||
user_address: string; | ||
token_address: string; | ||
token_balance: string; | ||
token_symbol: string; | ||
} | ||
|
||
const getData = async () => { | ||
const marketInfos = await getMarketInfos( | ||
"0x1b4d3b0421ddc1eb216d230bc01527422fb93103" | ||
); | ||
|
||
const csvRows: CSVRow[] = []; | ||
|
||
for (let block of SNAPSHOTS_BLOCKS) { | ||
const { tokens, accountBorrows } = | ||
await getActivitiesForAddressByPoolAtBlock( | ||
block, | ||
"", | ||
"", | ||
CHAINS.LINEA, | ||
PROTOCOLS.MENDI | ||
); | ||
|
||
console.log(`Block: ${block}`); | ||
console.log("Tokens: ", tokens.length); | ||
console.log("Account Borrows: ", accountBorrows.length); | ||
|
||
let lpValueByUsers = getLPValueByUserAndPoolFromActivities( | ||
tokens, | ||
accountBorrows | ||
); | ||
|
||
const timestamp = new Date(await getTimestampAtBlock(block)).toISOString(); | ||
|
||
lpValueByUsers.forEach((value, owner) => { | ||
value.forEach((amount, market) => { | ||
if (bigMath.abs(amount) < 1) return; | ||
|
||
const marketInfo = marketInfos.get(market.toLowerCase()); | ||
|
||
// Accumulate CSV row data | ||
csvRows.push({ | ||
user_address: owner, | ||
token_address: marketInfo?.underlyingAddress ?? "", | ||
token_symbol: marketInfo?.underlyingSymbol ?? "", | ||
token_balance: (amount / BigInt(1e18)).toString(), | ||
block_number: block.toString(), | ||
timestamp, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
// Write the CSV output to a file | ||
const ws = fs.createWriteStream("outputData.csv"); | ||
write(csvRows, { headers: true }) | ||
.pipe(ws) | ||
.on("finish", () => { | ||
console.log("CSV file has been written."); | ||
}); | ||
}; | ||
|
||
getData().then(() => { | ||
console.log("Done"); | ||
}); |
Oops, something went wrong.