-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
115 lines (96 loc) · 3.01 KB
/
index.js
File metadata and controls
115 lines (96 loc) · 3.01 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Kafka } from '@upstash/kafka'
import { ethers } from "ethers"
export class Dragon {
kafka = new Kafka({
url: 'https://distinct-mallard-8932-us1-rest-kafka.upstash.io',
username: 'ZGlzdGluY3QtbWFsbGFyZC04OTMyJHlygI3oyKeaIdw5j9SIVL6gRCNm1tPTEbk',
password:
'aM8YECeyHqENyMri8L7uCRrYvkYg77XFb3R1BE08RF1croHMp-TxQnlrGDJzMcP6lYMPKg==',
})
constructor(contractName, abi) {
this.contractName = contractName
this.abi = abi
}
_ingest = (message, topic) => {
const p = this.kafka.producer()
console.log(message)
return p.produce(topic, JSON.stringify(message))
}
_fetchSig = async (error) => {
const errorSig = error.data.originalError.data
const req = await fetch(
`https://sig.eth.samczsun.com/api/v1/signatures?all=true&function=${errorSig}`,
)
const data = req.json()
return data
}
_getSignatureNames = (obj) => {
return Object.values(obj)[0]?.map((e) => {
return e.name
})[0]
}
async error(error, transaction) {
const errorSig = await this._fetchSig(error)
const message = {
error: {
eventErrors: this._getSignatureNames(errorSig.result.event),
transactionError: this._getSignatureNames(errorSig.result.function),
},
transaction: transaction,
contract: this.contractName,
}
return this._ingest(message, "errors")
}
async wallet(address, value) {
try{
// Import environment variables
const baseUrl = "https://cors-anywhere.herokuapp.com/https://goerli.ethereum.coinbasecloud.net";
const username = "7BDXXFEFG5X5NAYXYWML";
const password = "SNGZTWLEPV2VYHSWDSEPPRQIQQFT7Z6QAG3NWNBH";
// Create node provider using project credentials
const provider = new ethers.providers.JsonRpcProvider({
url: baseUrl,
user: username,
password : password
})
const balance = await provider.getBalance(address)
const message = {
wallet: address,
txsValue: ethers.utils.formatEther(ethers.BigNumber.from(value).toBigInt()),
balance: ethers.utils.formatEther(balance.toBigInt())
}
return this._ingest(message, "wallets")
} catch (e) {
return JSON.stringify(e)
}
}
intents() {
return `intents`
}
}
// const dd = new Dragon("contract2", 'someABI')
// // test error
// const pp = {
// transaction: {
// from: '0x0aaA82DfDF58D1e7e2DA272eda4942e27d787f4b',
// to: '0x84866CCf525128a8290c10031CEf0B4B98EA5C69',
// value: { type: 'BigNumber', hex: '0x1ff973cafa8000' },
// data:
// '0x457391e56f5d5c68e12b6b17d29e7a7a7c5e4e9f301d00e68abeb312b3b911b3f43dda22',
// accessList: null,
// },
// error: {
// code: -32603,
// message: 'execution reverted',
// data: {
// originalError: {
// code: 3,
// data: '0xf0a42d4c',
// message: 'execution reverted',
// },
// },
// },
// }
// console.log(dd.error(pp.error, pp.transaction))
// // test wallet
// console.log(dd.wallet(pp.transaction.from, pp.transaction.value.hex))