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
116
117
118
119
120
121
122
123
124
import fs from 'fs'
import { task } from 'hardhat/config'
import { getChainId } from '@eth-optimism/core-utils'
import { isSameConfig, getDrippieConfig, addChecksum } from '../src'
task('install-drippie-config-multisig')
.addParam('safe', 'address of the Gnosis Safe to execute this bundle')
.addParam('outfile', 'where to write the bundle JSON file')
.setAction(async (args, hre) => {
if (!hre.ethers.utils.isAddress(args.safe)) {
throw new Error(`given safe is not an address: ${args.safe}`)
}
console.log(`connecting to Drippie...`)
const Drippie = await hre.ethers.getContractAt(
'Drippie',
(
await hre.deployments.get('Drippie')
).address
)
console.log(`loading local version of Drippie config for network...`)
const config = await getDrippieConfig(hre)
// Gnosis Safe transaction bundle.
const bundle: any = {
version: '1.0',
chainId: (await getChainId(hre.ethers.provider)).toString(),
createdAt: Date.now(),
meta: {
name: 'Transactions Batch',
description: '',
txBuilderVersion: '1.8.0',
createdFromSafeAddress: args.safe,
createdFromOwnerAddress: '',
},
transactions: [],
}
console.log(`generating transaction bundle...`)
for (const [dripName, dripConfig] of Object.entries(config)) {
console.log(`checking config for drip: ${dripName}`)
const drip = await Drippie.drips(dripName)
if (drip.status === 0) {
console.log(`drip does not exist yet: ${dripName}`)
console.log(`adding drip creation to bundle...`)
bundle.transactions.push({
to: Drippie.address,
value: '0',
data: null,
contractMethod: {
inputs: [
{ internalType: 'string', name: '_name', type: 'string' },
{
components: [
{
internalType: 'uint256',
name: 'interval',
type: 'uint256',
},
{
internalType: 'contract IDripCheck',
name: 'dripcheck',
type: 'address',
},
{ internalType: 'bytes', name: 'checkparams', type: 'bytes' },
{
components: [
{
internalType: 'address payable',
name: 'target',
type: 'address',
},
{ internalType: 'bytes', name: 'data', type: 'bytes' },
{
internalType: 'uint256',
name: 'value',
type: 'uint256',
},
],
internalType: 'struct Drippie.DripAction[]',
name: 'actions',
type: 'tuple[]',
},
],
internalType: 'struct Drippie.DripConfig',
name: '_config',
type: 'tuple',
},
],
name: 'create',
payable: false,
},
contractInputsValues: {
_name: dripName,
_config: JSON.stringify([
hre.ethers.BigNumber.from(dripConfig.interval).toString(),
dripConfig.dripcheck,
dripConfig.checkparams,
dripConfig.actions.map((action) => {
return [
action.target,
action.data,
hre.ethers.BigNumber.from(action.value).toString(),
]
}),
]),
},
})
} else if (!isSameConfig(dripConfig, drip.config)) {
console.log(`drip exists but local config is different: ${dripName}`)
console.log(`drips cannot be modified for security reasons`)
console.log(`please do not modify the local config for existing drips`)
console.log(`you can archive the old drip and create another`)
} else {
console.log(`drip is already installed`)
}
}
console.log(`writing bundle to ${args.outfile}...`)
fs.writeFileSync(args.outfile, JSON.stringify(addChecksum(bundle), null, 2))
})