Skip to content

Commit

Permalink
Merge pull request #64 from matt5346/overnight-rebase
Browse files Browse the repository at this point in the history
Overnight rebase
  • Loading branch information
nitish-91 authored Apr 24, 2024
2 parents 3f2c95c + fdda803 commit 4537785
Show file tree
Hide file tree
Showing 7 changed files with 1,266 additions and 625 deletions.
842 changes: 268 additions & 574 deletions adapters/overnight/outputData.csv

Large diffs are not rendered by default.

442 changes: 442 additions & 0 deletions adapters/overnight/outputData_rebase.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions adapters/overnight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"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",
Expand Down
87 changes: 68 additions & 19 deletions adapters/overnight/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CHAINS, LP_LYNEX_SYMBOL, LP_LYNEX, PROTOCOLS, SNAPSHOTS_BLOCKS } from "./sdk/config";
import { getLPValueByUserAndPoolFromPositions, getPositionsForAddressByPoolAtBlock, getTimestampAtBlock } from "./sdk/subgraphDetails";
import { 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();
Expand All @@ -19,40 +19,89 @@ interface CSVRow {

const getData = async () => {
const csvRows: CSVRow[] = [];

const csvRows_rebase: CSVRow[] = [];

for (let block of SNAPSHOTS_BLOCKS) {
const positions = await getPositionsForAddressByPoolAtBlock(
block, "", "", CHAINS.LINEA, PROTOCOLS.OVN
);
const timestamp = new Date(await getTimestampAtBlock(block)).toISOString();
const positions = await getUserTVLByBlock({
blockNumber: block,
blockTimestamp: Number(timestamp),
});

console.log(`Block: ${block}`);
console.log("Positions: ", positions.length);

let lpValueByUsers = getLPValueByUserAndPoolFromPositions(positions);

const timestamp = new Date(await getTimestampAtBlock(block)).toISOString();

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
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
});
})
});
}

// counting rebase by blocks range
// [0, 100, 200] -> gonna be counted like [0, 100] + [100, 200]
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("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
});
});
}

// 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(() => {
Expand Down
223 changes: 223 additions & 0 deletions adapters/overnight/src/sdk/abi.ts
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',
},
];
Loading

0 comments on commit 4537785

Please sign in to comment.