-
Notifications
You must be signed in to change notification settings - Fork 601
/
safe.js
115 lines (98 loc) · 2.75 KB
/
safe.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
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
const fs = require('fs');
const ethers = require('ethers');
const { gray, yellow } = require('chalk');
const { EthersAdapter } = require('@gnosis.pm/safe-core-sdk');
const Safe = require('@gnosis.pm/safe-core-sdk').default;
const SafeServiceClient = require('@gnosis.pm/safe-service-client').default;
require('dotenv').config();
const { getUsers } = require('.');
const {
confirmAction,
ensureDeploymentPath,
ensureNetwork,
getDeploymentPathForNetwork,
loadAndCheckRequiredSources,
loadConnections,
stringify,
} = require('./publish/src/util');
(async function() {
const network = 'mainnet';
const safeAddress = getUsers({ network, user: 'owner' }).address;
ensureNetwork(network);
const deploymentPath = getDeploymentPathForNetwork({ network });
ensureDeploymentPath(deploymentPath);
const { ownerActions, ownerActionsFile } = loadAndCheckRequiredSources({
network,
deploymentPath,
});
const {
providerUrl,
privateKey,
// explorerLinkPrefix,
} = loadConnections({
network,
// useFork,
// useOvm,
});
const provider = new ethers.providers.JsonRpcProvider(providerUrl);
const signer = new ethers.Wallet(privateKey, provider);
const ethAdapter = new EthersAdapter({
ethers,
signer,
});
const safeSdk = await Safe.create({
ethAdapter,
safeAddress,
});
const transactions = Object.values(ownerActions)
.filter(({ complete }) => !complete)
.map(({ target, data }) => ({
to: target,
data,
value: '0',
}));
if (!transactions.length) {
console.log(gray('No transactions to submit in owner-actions'));
return;
}
try {
await confirmAction(
gray(
'Found',
yellow(transactions.length),
'incomplete transactions to stage to safe',
yellow(safeAddress),
'on network',
yellow(network),
'. Continue (y/n)? '
)
);
} catch (err) {
console.log(gray('Operation cancelled'));
return;
}
const safeTransaction = await safeSdk.createTransaction(...transactions);
const txHash = await safeSdk.getTransactionHash(safeTransaction);
const signature = await safeSdk.signTransactionHash(txHash);
const safeService = new SafeServiceClient(
`https://safe-transaction${network === 'sepolia' ? '.sepolia' : ''}.gnosis.io`
);
try {
await safeService.proposeTransaction(safeAddress, safeTransaction.data, txHash, signature);
console.log(
gray(
'Submitted a batch of',
yellow(transactions.length),
'transactions to the safe',
yellow(safeAddress)
)
);
const ownerActionsMutated = Object.entries(ownerActions).reduce((prev, [key, value]) => {
prev[key] = Object.assign({}, value, { complete: true });
return prev;
}, {});
fs.writeFileSync(ownerActionsFile, stringify(ownerActionsMutated));
} catch (err) {
console.log(require('util').inspect(err, true, null, true));
}
})();