-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from sanbir/new-aggregated-distributors-query
New aggregated distributors query
- Loading branch information
Showing
8 changed files
with
74 additions
and
37 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
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
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
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
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,34 @@ | ||
import { logger } from "./logger" | ||
import { getIsContract } from "./getIsContract" | ||
import { getFeeDistributorContract } from "./getFeeDistributorContract" | ||
import { ethers } from "ethers" | ||
|
||
export async function getLastDistributionDate(fdAddress: string) : Promise<Date | null> { | ||
logger.info('getLastDistributionDate started for ' + fdAddress) | ||
|
||
const isContract = await getIsContract(fdAddress) | ||
if (!isContract) { | ||
return null | ||
} | ||
|
||
const fd = getFeeDistributorContract(fdAddress) | ||
|
||
const logs = await fd.queryFilter(fd.filters.FeeDistributor__Withdrawn(), 19009010, "latest") | ||
|
||
if (logs.length === 0) { | ||
return null | ||
} | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL) | ||
|
||
const withdrawalDates = await Promise.all(logs.map(async (log) => { | ||
const block = await provider.getBlock(log.blockNumber) | ||
return new Date(block.timestamp * 1000) // Convert Unix timestamp to JavaScript Date | ||
})); | ||
|
||
const maxDate = withdrawalDates.reduce((max, date) => date > max ? date : max) | ||
|
||
logger.info('getLastDistributionDate finished for ' + fdAddress) | ||
|
||
return maxDate | ||
} |
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
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
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 |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import {logger} from "../helpers/logger"; | ||
import {ethers} from "ethers"; | ||
import {getSsvNetworkContract} from "../helpers/getSsvNetworkContract"; | ||
import { sleep } from "../helpers/sleep" | ||
|
||
export async function getSsvPubKeysPerProxy(proxyAddress: string) { // same for 3.1 | ||
export async function getSsvPubKeysPerProxy(proxyAddress: string): Promise<string[]> { // same for 3.1 | ||
logger.info('getSsvPubKeysPerProxy started for ' + proxyAddress) | ||
|
||
const ssvNetwork = getSsvNetworkContract() | ||
|
||
const logs = await ssvNetwork.queryFilter(ssvNetwork.filters.ValidatorAdded(proxyAddress)) | ||
try { | ||
const logs = await ssvNetwork.queryFilter(ssvNetwork.filters.ValidatorAdded(proxyAddress), 19326041, "latest") | ||
|
||
const publicKeys: string[] = logs.map(log => log.args?.publicKey) | ||
const publicKeys: string[] = logs.map(log => log.args?.publicKey) | ||
|
||
logger.info('getSsvPubKeysPerProxy finished for ' + proxyAddress) | ||
logger.info('getSsvPubKeysPerProxy finished for ' + proxyAddress) | ||
|
||
return publicKeys | ||
return publicKeys | ||
} catch (error) { | ||
logger.error(error) | ||
|
||
logger.info('Sleeping for 5 sec...') | ||
await sleep(5000) | ||
logger.info('Re-trying ' + proxyAddress) | ||
|
||
return await getSsvPubKeysPerProxy(proxyAddress) | ||
} | ||
} |