-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (52 loc) · 1.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs/promises')
const safe = "https://safe-transaction-mainnet.safe.global/api/"
async function main() {
let safeAddress = process.argv[2]
let txs = []
let next = `${safe}v1/safes/${safeAddress}/all-transactions/?` + new URLSearchParams({
executed: "true",
queued: "false",
})
// Paginate through Safe txs
console.log('Fetching Safe transactions . . .')
while(next)
await fetch(next).then(res => res.json())
.then(json => {
next = json.next
txs = txs.concat(json.results)
})
// Filter for duplicate transaction hashes (from batch execution), undefined executors, and starting timestamp
console.log('Processing transactions . . .')
const prevDate = new Date(process.argv[3] * 1000)
txs = txs.filter((el, i) =>
i === txs.findIndex((t => (
t.transactionHash === el.transactionHash
))) && el.executor && new Date(el.executionDate) > prevDate)
// Sum fees from each address
let refunds = []
txs.forEach(el => {
let index = refunds.findIndex(val => val.to === el.executor)
if(index === -1)
refunds.push({
to: el.executor,
value: parseInt(el.fee),
})
else
refunds[index].value += parseInt(el.fee)
})
// Convert fee numbers to strings
refunds.forEach(el => el.value = el.value.toString())
let output = {
chainId: "1",
createdAt: new Date().getTime(),
meta: {
name: "Gaswoman Transaction Bundle",
},
transactions: refunds,
}
// Write output file
console.log('Writing output to refunds.json. . .')
await fs.writeFile('./refunds.json', JSON.stringify(output))
console.log(refunds)
}
main()