diff --git a/packages/know-your-cosigners-service/routes/getSafeTransactions.ts b/packages/know-your-cosigners-service/routes/getSafeTransactions.ts index d061807..90d057e 100644 --- a/packages/know-your-cosigners-service/routes/getSafeTransactions.ts +++ b/packages/know-your-cosigners-service/routes/getSafeTransactions.ts @@ -1,4 +1,10 @@ -import { BlockField, HypersyncClient, Query, TransactionField, TransactionSelection } from '@envio-dev/hypersync-client' +import { + BlockField, + HypersyncClient, + Query, + TransactionField, + TransactionSelection +} from '@envio-dev/hypersync-client' import { Request, Response } from 'express' export async function getTransactions(req: Request, res: Response) { @@ -9,33 +15,34 @@ export async function getTransactions(req: Request, res: Response) { res.status(400).send('400 Bad Request') return } - + let transactionQuery: TransactionSelection[] | undefined = undefined if (safe) { - transactionQuery = [{ - to: [safe as string], // Safe address - sighash: ['0x6a761202'] // execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes) - }] + transactionQuery = [ + { + to: [safe as string], // Safe address + sighash: ['0x6a761202'] // execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes) + } + ] } if (signer) { - transactionQuery = [{ - from: [signer as string], // Signer address - }] + transactionQuery = [ + { + from: [signer as string] // Signer address + } + ] } const client = HypersyncClient.new({ url: `https://${chainId}.hypersync.xyz` }) - + const query: Query = { fromBlock: Number(nextBlock), transactions: transactionQuery, fieldSelection: { - block: [ - BlockField.Number, - BlockField.Timestamp - ], + block: [BlockField.Number, BlockField.Timestamp], transaction: [ TransactionField.BlockNumber, TransactionField.Hash, @@ -48,9 +55,9 @@ export async function getTransactions(req: Request, res: Response) { ] } } - + const result = await client.get(query) - + const blocks = result.data.blocks const txs = result.data.transactions @@ -59,15 +66,16 @@ export async function getTransactions(req: Request, res: Response) { value: tx.value?.toString(), gasUsed: tx.gasUsed?.toString(), gasPrice: tx.gasPrice?.toString(), - timestamp: blocks.find(b => tx.blockNumber === b.number)?.timestamp + timestamp: blocks.find((b) => tx.blockNumber === b.number)?.timestamp })) - const nextBlockNumber = result.nextBlock > result.archiveHeight! - ? undefined - : result.nextBlock + const nextBlockNumber = + result.nextBlock > result.archiveHeight! ? undefined : result.nextBlock + + console.log( + `signer: ${signer}, safe: ${safe}, fromBlock: ${query.fromBlock}, transactions: ${transactions.length}` + ) - console.log(`signer: ${signer}, safe: ${safe}, fromBlock: ${query.fromBlock}, transactions: ${transactions.length}`) - res.status(200).send({ transactions, nextBlock: nextBlockNumber diff --git a/packages/know-your-cosigners-web/src/components/TxsFrequencyChart.tsx b/packages/know-your-cosigners-web/src/components/TxsFrequencyChart.tsx index 52a72b3..16f71b1 100644 --- a/packages/know-your-cosigners-web/src/components/TxsFrequencyChart.tsx +++ b/packages/know-your-cosigners-web/src/components/TxsFrequencyChart.tsx @@ -78,7 +78,6 @@ export default function TxsFrequencyChart(props: TxFreqChartProps) { : (timePeriod === 'yearly') ? date.getFullYear() : date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + ('0' + date.getDate()).slice(-2) - // + ('0' + date.getHours()).slice(-2) + ':00:00' // Hourly tally[dateString] = (tally[dateString] || 0) + 1 }) @@ -121,7 +120,6 @@ export default function TxsFrequencyChart(props: TxFreqChartProps) { const xScale = d3.scaleTime() .domain([minDate, maxDate]) .range([(barWidth / 2), width - (barWidth / 2)]) - //.range([0, width]) .nice() const yScale = d3.scaleLinear() diff --git a/packages/know-your-cosigners-web/src/logic/envio.ts b/packages/know-your-cosigners-web/src/logic/envio.ts index 3f4c8cf..8c408cf 100644 --- a/packages/know-your-cosigners-web/src/logic/envio.ts +++ b/packages/know-your-cosigners-web/src/logic/envio.ts @@ -18,26 +18,22 @@ export async function getEnvioTransactions({ let transactions: Transaction[] = [] let nextBlock = 0 while (nextBlock !== undefined) { - const URL = (signerAddress) + const URL = signerAddress ? `${SERVICE_URL}/transactions?signer=${signerAddress}&chainId=${chainId}&nextBlock=${nextBlock}` : `${SERVICE_URL}/transactions?safe=${safeAddress}&chainId=${chainId}&nextBlock=${nextBlock}` - const request = await fetch( - URL, - { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json' - } + const request = await fetch(URL, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' } - ) + }) const response = await request.json() transactions = transactions.concat(response.transactions) nextBlock = response.nextBlock } return transactions - } - catch(error: any) { + } catch (error: any) { return [] } } diff --git a/packages/know-your-cosigners-web/src/logic/safe.ts b/packages/know-your-cosigners-web/src/logic/safe.ts index fe2a884..a6f4a57 100644 --- a/packages/know-your-cosigners-web/src/logic/safe.ts +++ b/packages/know-your-cosigners-web/src/logic/safe.ts @@ -3,7 +3,10 @@ import { SafeTransaction } from '@/types' import { createPublicClient, getContract, http } from 'viem' import { mainnet } from 'viem/chains' -export async function getOwners(safeAddress: string, chainId: number): Promise { +export async function getOwners( + safeAddress: string, + chainId: number +): Promise { if (chainId !== 1) { throw new Error('Network not supported.') } @@ -12,7 +15,7 @@ export async function getOwners(safeAddress: string, chainId: number): Promise { try { let transactions: SafeTransaction[] = [] let next = `https://safe-transaction-${chainName}.safe.global/api/v1/safes/${safeAddress}/multisig-transactions` while (next) { - const request = await fetch( - next, - { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json' - } + const request = await fetch(next, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' } - ) + }) const response = await request.json() transactions = transactions.concat(response.results) next = response.next console.log(transactions.length, next) } return transactions - } - catch(error: any) { + } catch (error: any) { return [] } } diff --git a/packages/know-your-cosigners-web/src/logic/statistics.ts b/packages/know-your-cosigners-web/src/logic/statistics.ts index a9eb975..1c33f33 100644 --- a/packages/know-your-cosigners-web/src/logic/statistics.ts +++ b/packages/know-your-cosigners-web/src/logic/statistics.ts @@ -17,30 +17,33 @@ export function getSignersStatistics( let totalSafeTxExecuted = 0 let totalTxExecuted = 0 - for(let i = 0; i < signerTransactions.length; i++) { + for (let i = 0; i < signerTransactions.length; i++) { const tx = signerTransactions[i] if (!isSameAddress(signerAddress, tx.from)) { continue } - - const isSafeTx = tx.to && isSameAddress(tx.to, safeAddress) - && isSameAddress(tx.from, signerAddress) - && tx.input.startsWith('0x6a761202') - + + const isSafeTx = + tx.to && + isSameAddress(tx.to, safeAddress) && + isSameAddress(tx.from, signerAddress) && + tx.input.startsWith('0x6a761202') + totalGasUsed += BigInt(tx.gasUsed) totalSafeGasUsed += isSafeTx ? BigInt(tx.gasUsed) : BigInt(0) totalTxFees += BigInt(tx.gasUsed) * BigInt(tx.gasPrice) - totalSafeTxFees += isSafeTx ? BigInt(tx.gasUsed) * BigInt(tx.gasPrice) : BigInt(0) + totalSafeTxFees += isSafeTx + ? BigInt(tx.gasUsed) * BigInt(tx.gasPrice) + : BigInt(0) totalTxExecuted += 1 totalSafeTxExecuted += isSafeTx ? 1 : 0 } const totalSafeTxSigned = safeTxServiceTransactions.filter( - tx => ( + (tx) => tx.isExecuted && tx.isSuccessful && - tx.confirmations.some(o => isSameAddress(o.owner, signerAddress)) - ) + tx.confirmations.some((o) => isSameAddress(o.owner, signerAddress)) ).length console.log(signerAddress, totalSafeTxSigned) diff --git a/packages/know-your-cosigners-web/src/types/index.ts b/packages/know-your-cosigners-web/src/types/index.ts index b5b2bdd..4eb21d7 100644 --- a/packages/know-your-cosigners-web/src/types/index.ts +++ b/packages/know-your-cosigners-web/src/types/index.ts @@ -1,4 +1,3 @@ - export type Transaction = { blockNumber: number hash: string @@ -34,10 +33,12 @@ export type SafeTransaction = { isExecuted: boolean isSuccessful?: boolean confirmationsRequired: number - confirmations: [{ - owner: string - submissionDate: string - signature: string - }] + confirmations: [ + { + owner: string + submissionDate: string + signature: string + } + ] signatures?: string }