-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpauseComptroller.js
More file actions
108 lines (92 loc) · 2.78 KB
/
Copy pathpauseComptroller.js
File metadata and controls
108 lines (92 loc) · 2.78 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
const { ethers } = require("ethers");
const {
DefenderRelaySigner,
DefenderRelayProvider,
} = require("defender-relay-client/lib/ethers");
const Safe = require("@gnosis.pm/safe-core-sdk").default;
const { EthersAdapter } = require("@gnosis.pm/safe-core-sdk");
const formatUnits = ethers.utils.formatUnits;
const parseUnits = ethers.utils.parseUnits;
const COMPTROLLER_ADDR = "0x85FD0fA5Cc2f0B3A12C146C5B5A37d9e269b3Ba8";
const SAFE_ADDRESS = "0x55C296592acDb317050c84C5eBF4eecCa85a0D8f";
exports.handler = async function (payload) {
const results = [];
const content = payload.request.body;
// console.log({ content });
const events = content.matchReasons;
// console.log({ events });
for (const evt of events) {
// add custom logic for matching here
const sentinel = content.sentinel;
// console.log({ sentinel });
// console.log({ args: evt.args });
if (sentinel.chainId == 42) {
const { from, to, value } = evt.params;
// console.log({ params: evt.params });
const provider = new DefenderRelayProvider(payload);
const signer = new DefenderRelaySigner(payload, provider, {
speed: "fast",
});
const comptroller = new ethers.Contract(
COMPTROLLER_ADDR,
COMPTROLLER_ABI,
signer
);
const isPaused = await comptroller.paused();
if (!isPaused) {
const ethAdapterSigner = new EthersAdapter({
ethers,
signer: signer,
});
const safeSdk = await Safe.create({
ethAdapter: ethAdapterSigner,
safeAddress: SAFE_ADDRESS,
});
const transaction = {
to: COMPTROLLER_ADDR,
value: "0",
data: comptroller.interface.encodeFunctionData("pause()"),
};
// console.log({ transaction });
const safeTransaction = await safeSdk.createTransaction(transaction);
// console.log({ safeTransaction });
await safeSdk.signTransaction(safeTransaction);
const txResponse = await safeSdk.executeTransaction(safeTransaction);
// console.log({ txResponse });
results.push({
timestamp: parseInt(new Date().getTime() / 1000),
claimAmount: formatUnits(value),
tx: txResponse.hash,
});
} else {
results.push({
timestamp: parseInt(new Date().getTime() / 1000),
claimAmount: formatUnits(value),
});
}
}
}
return { results };
};
const COMPTROLLER_ABI = [
{
inputs: [],
name: "paused",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "pause",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];