-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
894 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,33 @@ | ||
{ | ||
"name": "overnight-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", | ||
"ethers": "^5.7.2", | ||
"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,111 @@ | ||
import { CHAINS, PROTOCOLS, SNAPSHOTS_BLOCKS, OVN_CONTRACTS, LP_LYNEX, LP_LYNEX_SYMBOL, USD_PLUS_SYMBOL, USD_PLUS_LINEA, USDT_PLUS_SYMBOL, USDT_PLUS_LINEA } from "./sdk/config"; | ||
import { getLPValueByUserAndPoolFromPositions, getUserTVLByBlock, getRebaseForUsersByPoolAtBlock, getTimestampAtBlock } from "./sdk/subgraphDetails"; | ||
|
||
(BigInt.prototype as any).toJSON = function () { | ||
return this.toString(); | ||
}; | ||
|
||
import fs from 'fs'; | ||
import { write } from 'fast-csv'; | ||
|
||
interface CSVRow { | ||
block_number: string; | ||
timestamp: string; | ||
user_address: string; | ||
token_address: string; | ||
token_balance: string; | ||
token_symbol: string; | ||
} | ||
|
||
const getData = async () => { | ||
const csvRows: CSVRow[] = []; | ||
const csvRows_rebase: CSVRow[] = []; | ||
|
||
for (let block of SNAPSHOTS_BLOCKS) { | ||
const timestamp = new Date(await getTimestampAtBlock(block)).toISOString(); | ||
const positions = await getUserTVLByBlock({ | ||
blockNumber: block, | ||
blockTimestamp: Number(timestamp), | ||
}); | ||
|
||
console.log("Positions: ", positions.length); | ||
let lpValueByUsers = getLPValueByUserAndPoolFromPositions(positions); | ||
|
||
lpValueByUsers.forEach((value, key) => { | ||
value.forEach((lpValue) => { | ||
const lpValueStr = lpValue.toString(); | ||
// Accumulate CSV row data | ||
csvRows.push({ | ||
user_address: key, | ||
token_address: LP_LYNEX, | ||
token_symbol: LP_LYNEX_SYMBOL, | ||
token_balance: lpValueStr, | ||
block_number: block.toString(), | ||
timestamp | ||
}); | ||
}) | ||
}); | ||
} | ||
|
||
for (let [index, block] of SNAPSHOTS_BLOCKS.entries()) { | ||
if (!SNAPSHOTS_BLOCKS[index + 1]) continue; | ||
console.log(`Blocks: ${block} -> ${SNAPSHOTS_BLOCKS[index + 1]}`); | ||
|
||
const positionsRebaseUsd = await getRebaseForUsersByPoolAtBlock({ | ||
blockNumberFrom: block, | ||
blockNumberTo: SNAPSHOTS_BLOCKS[index + 1], | ||
token: OVN_CONTRACTS.USDPLUS | ||
}); | ||
|
||
const positionsRebaseUsdt = await getRebaseForUsersByPoolAtBlock({ | ||
blockNumberFrom: block, | ||
blockNumberTo: SNAPSHOTS_BLOCKS[index + 1], | ||
token: OVN_CONTRACTS.USDTPLUS | ||
}); | ||
|
||
console.log(`Block: ${block}`); | ||
console.log("positionsRebase: ", positionsRebaseUsd.size); | ||
|
||
// all results are counted for the END block | ||
const timestamp = new Date(await getTimestampAtBlock(SNAPSHOTS_BLOCKS[index + 1])).toISOString(); | ||
|
||
positionsRebaseUsd.forEach((value, key) => { | ||
csvRows_rebase.push({ | ||
user_address: key, | ||
token_symbol: USD_PLUS_SYMBOL, | ||
token_balance: value, | ||
token_address: USD_PLUS_LINEA, | ||
block_number: SNAPSHOTS_BLOCKS[index + 1].toString(), | ||
timestamp | ||
}); | ||
}); | ||
|
||
positionsRebaseUsdt.forEach((value, key) => { | ||
csvRows_rebase.push({ | ||
user_address: key, | ||
token_symbol: USDT_PLUS_SYMBOL, | ||
token_balance: value, | ||
token_address: USDT_PLUS_LINEA, | ||
block_number: SNAPSHOTS_BLOCKS[index + 1].toString(), | ||
timestamp | ||
}); | ||
}); | ||
} | ||
|
||
console.log(csvRows_rebase.length, '__csvRows_rebase') | ||
|
||
// Write the CSV output to a file | ||
const ws = fs.createWriteStream('outputData.csv'); | ||
const ws_rebase = fs.createWriteStream('outputData_rebase.csv'); | ||
write(csvRows, { headers: true }).pipe(ws).on('finish', () => { | ||
console.log("CSV file has been written."); | ||
}); | ||
write(csvRows_rebase, { headers: true }).pipe(ws_rebase).on('finish', () => { | ||
console.log("CSV file has been written."); | ||
}); | ||
}; | ||
|
||
getData().then(() => { | ||
console.log("Done"); | ||
}); | ||
|
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,223 @@ | ||
|
||
export const ERC20_ABI = [ | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'name', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'string', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: false, | ||
inputs: [ | ||
{ | ||
name: '_spender', | ||
type: 'address', | ||
}, | ||
{ | ||
name: '_value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'approve', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'bool', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'totalSupply', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'uint256', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: false, | ||
inputs: [ | ||
{ | ||
name: '_from', | ||
type: 'address', | ||
}, | ||
{ | ||
name: '_to', | ||
type: 'address', | ||
}, | ||
{ | ||
name: '_value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'transferFrom', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'bool', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'decimals', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'uint8', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
name: '_owner', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'balanceOf', | ||
outputs: [ | ||
{ | ||
name: 'balance', | ||
type: 'uint256', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [], | ||
name: 'symbol', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'string', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: false, | ||
inputs: [ | ||
{ | ||
name: '_to', | ||
type: 'address', | ||
}, | ||
{ | ||
name: '_value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'transfer', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'bool', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
}, | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
name: '_owner', | ||
type: 'address', | ||
}, | ||
{ | ||
name: '_spender', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'allowance', | ||
outputs: [ | ||
{ | ||
name: '', | ||
type: 'uint256', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
payable: true, | ||
stateMutability: 'payable', | ||
type: 'fallback', | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: 'owner', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: true, | ||
name: 'spender', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: false, | ||
name: 'value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'Approval', | ||
type: 'event', | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: 'from', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: true, | ||
name: 'to', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: false, | ||
name: 'value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'Transfer', | ||
type: 'event', | ||
}, | ||
]; |
Oops, something went wrong.