Skip to content

Commit

Permalink
stats-worker: add linea
Browse files Browse the repository at this point in the history
  • Loading branch information
shanefontaine committed Nov 9, 2023
1 parent fe03ba4 commit 74cddf5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
26 changes: 21 additions & 5 deletions packages/stats-worker/src/BonderStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class BonderStats {
dbData.optimismFeesAmount,
dbData.novaFeesAmount,
dbData.baseFeesAmount,
dbData.lineaFeesAmount,
dbData.ethereumFeesAmount,
dbData.totalFeesAmount,
startDate
Expand Down Expand Up @@ -275,6 +276,7 @@ class BonderStats {
Number(dbData.optimismTxFees || 0) +
Number(dbData.novaTxFees || 0) +
Number(dbData.baseTxFees || 0) +
Number(dbData.lineaTxFees || 0) +
Number(dbData.ethereumTxFees || 0)) *
ethPrice
console.log(dbData.totalFees)
Expand All @@ -288,6 +290,7 @@ class BonderStats {
dbData.optimismTxFees,
dbData.novaTxFees,
dbData.baseTxFees,
dbData.lineaTxFees,
dbData.ethereumTxFees,
dbData.totalFees,
dbData.ethPrice,
Expand Down Expand Up @@ -656,7 +659,11 @@ class BonderStats {
dbData.baseBlockNumber,
dbData.baseCanonicalAmount,
dbData.baseHTokenAmount,
dbData.baseNativeAmount
dbData.baseNativeAmount,
dbData.lineaBlockNumber,
dbData.lineaCanonicalAmount,
dbData.lineaHTokenAmount,
dbData.lineaNativeAmount
)
console.log(
day,
Expand Down Expand Up @@ -1205,6 +1212,8 @@ class BonderStats {
(dbData.novaHTokenAmount || 0) +
(dbData.baseCanonicalAmount || 0) +
(dbData.baseHTokenAmount || 0) +
(dbData.lineaCanonicalAmount || 0) +
(dbData.lineaHTokenAmount || 0) +
dbData.ethereumCanonicalAmount +
(dbData.stakedAmount - dbData.unstakedAmount) -
dbData.initialCanonicalAmount -
Expand All @@ -1229,26 +1238,33 @@ class BonderStats {
let nativeTokenDebt =
dbData.polygonNativeAmount * dbData.maticPriceUsd +
dbData.gnosisNativeAmount * dbData.xdaiPriceUsd +
(dbData.ethereumNativeAmount +
(
dbData.ethereumNativeAmount +
dbData.optimismNativeAmount +
dbData.arbitrumNativeAmount +
dbData.arbitrumAliasAmount +
dbData.arbitrumMessengerWrapperAmount +
(dbData.novaNativeAmount || 0) * (dbData.baseNativeAmount || 0)) *
(dbData.novaNativeAmount || 0) +
(dbData.baseNativeAmount || 0) +
(dbData.lineaNativeAmount || 0)
) *
dbData.ethPriceUsd

if (token === 'ETH') {
nativeTokenDebt =
(dbData.polygonNativeAmount * dbData.maticPriceUsd) /
dbData.ethPriceUsd +
(dbData.gnosisNativeAmount * dbData.xdaiPriceUsd) / dbData.ethPriceUsd +
(dbData.ethereumNativeAmount +
(
dbData.ethereumNativeAmount +
dbData.optimismNativeAmount +
dbData.arbitrumNativeAmount +
dbData.arbitrumAliasAmount +
dbData.arbitrumMessengerWrapperAmount +
(dbData.novaNativeAmount || 0) +
(dbData.baseNativeAmount || 0))
(dbData.baseNativeAmount || 0) +
(dbData.lineaNativeAmount || 0)
)
}

nativeTokenDebt = nativeStartingTokenAmount - nativeTokenDebt
Expand Down
43 changes: 38 additions & 5 deletions packages/stats-worker/src/Db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class Db {
base_canonical_amount NUMERIC,
base_hToken_amount NUMERIC,
base_native_amount NUMERIC
linea_block_number INTEGER,
linea_canonical_amount NUMERIC,
linea_hToken_amount NUMERIC,
linea_native_amount NUMERIC
)`)
if (argv.resetBonderFeesDb) {
this.db.run(`DROP TABLE IF EXISTS bonder_fees`)
Expand All @@ -126,6 +130,7 @@ class Db {
optimism_fees_amount NUMERIC NOT NULL,
nova_fees_amount NUMERIC NOT NULL,
base_fees_amount NUMERIC NOT NULL,
linea_fees_amount NUMERIC NOT NULL,
ethereum_fees_amount NUMERIC NOT NULL,
total_fees_amount NUMERIC NOT NULL,
timestamp INTEGER NOT NULL
Expand All @@ -142,6 +147,8 @@ class Db {
arbitrum_tx_fees NUMERIC NOT NULL,
optimism_tx_fees NUMERIC NOT NULL,
nova_tx_fees NUMERIC NOT NULL,
base_tx_fees NUMERIC NOT NULL,
linea_tx_fees NUMERIC NOT NULL,
ethereum_tx_fees NUMERIC NOT NULL,
total_tx_fees NUMERIC NOT NULL,
eth_price_usd NUMERIC NOT NULL,
Expand Down Expand Up @@ -269,6 +276,20 @@ class Db {
'ALTER TABLE bonder_balances ADD COLUMN base_native_amount NUMERIC;'
)
}
this.migrations[21] = () => {
this.db.run(
'ALTER TABLE bonder_balances ADD COLUMN linea_block_number INTEGER;'
)
this.db.run(
'ALTER TABLE bonder_balances ADD COLUMN linea_canonical_amount NUMERIC;'
)
this.db.run(
'ALTER TABLE bonder_balances ADD COLUMN linea_hToken_amount NUMERIC;'
)
this.db.run(
'ALTER TABLE bonder_balances ADD COLUMN linea_native_amount NUMERIC;'
)
}

if (argv.migrations && !migrationRan) {
const migrationsToRun = JSON.parse(argv.migrations)
Expand Down Expand Up @@ -550,11 +571,15 @@ class Db {
baseBlockNumber: number,
baseCanonicalAmount: number = 0,
baseHTokenAmount: number = 0,
baseNativeAmount: number = 0
baseNativeAmount: number = 0,
lineaBlockNumber: number,
lineaCanonicalAmount: number = 0,
lineaHTokenAmount: number = 0,
lineaNativeAmount: number = 0
) {
await this.tilReady()
const stmt = this.db.prepare(
'INSERT OR REPLACE INTO bonder_balances VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
'INSERT OR REPLACE INTO bonder_balances VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
)
stmt.run(
uuid(),
Expand Down Expand Up @@ -610,7 +635,11 @@ class Db {
baseBlockNumber,
baseCanonicalAmount,
baseHTokenAmount,
baseNativeAmount
baseNativeAmount,
lineaBlockNumber,
lineaCanonicalAmount,
lineaHTokenAmount,
lineaNativeAmount
)
stmt.finalize()
}
Expand All @@ -623,13 +652,14 @@ class Db {
optimismFees: number = 0,
novaFees: number = 0,
baseFees: number = 0,
lineaFees: number = 0,
ethereumFees: number = 0,
totalFees: number = 0,
timestamp: number = 0
) {
await this.tilReady()
const stmt = this.db.prepare(
'INSERT OR REPLACE INTO bonder_fees VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'
'INSERT OR REPLACE INTO bonder_fees VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
)
stmt.run(
uuid(),
Expand All @@ -640,6 +670,7 @@ class Db {
optimismFees,
novaFees,
baseFees,
lineaFees,
ethereumFees,
totalFees,
timestamp
Expand All @@ -656,6 +687,7 @@ class Db {
optimismTxFees: number = 0,
novaTxFees: number = 0,
baseTxFees: number = 0,
lineaTxFees: number = 0,
ethereumTxFees: number = 0,
totalFees: number = 0,
ethPriceUsd: number = 0,
Expand All @@ -665,7 +697,7 @@ class Db {
) {
await this.tilReady()
const stmt = this.db.prepare(
'INSERT OR REPLACE INTO bonder_tx_fees VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
'INSERT OR REPLACE INTO bonder_tx_fees VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
)
stmt.run(
uuid(),
Expand All @@ -676,6 +708,7 @@ class Db {
optimismTxFees,
novaTxFees,
baseTxFees,
lineaTxFees,
ethereumTxFees,
totalFees,
ethPriceUsd,
Expand Down

0 comments on commit 74cddf5

Please sign in to comment.