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
import { task } from 'hardhat/config'
import { LedgerSigner } from '@ethersproject/hardware-wallets'
import { PopulatedTransaction } from 'ethers'
import '@nomiclabs/hardhat-ethers'
import 'hardhat-deploy'
import { isSameConfig, getDrippieConfig } from '../src'
task('install-drippie-config').setAction(async (args, hre) => {
console.log(`connecting to ledger...`)
const signer = new LedgerSigner(
hre.ethers.provider,
'default',
hre.ethers.utils.defaultPath
)
console.log(`connecting to Drippie...`)
const Drippie = await hre.ethers.getContractAt(
'Drippie',
(
await hre.deployments.get('Drippie')
).address,
signer
)
console.log(`loading local version of Drippie config for network...`)
const config = await getDrippieConfig(hre)
// Need this to deal with annoying Ethers/Ledger 1559 issue.
const sendtx = async (tx: PopulatedTransaction): Promise<void> => {
const gas = await signer.estimateGas(tx)
tx.type = 1
tx.gasLimit = gas
const ret = await signer.sendTransaction(tx)
console.log(`sent tx: ${ret.hash}`)
console.log(`waiting for tx to be confirmed...`)
await ret.wait()
console.log(`tx confirmed`)
}
console.log(`installing Drippie config file...`)
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(`creating drip...`)
const tx = await Drippie.populateTransaction.create(dripName, dripConfig)
await sendtx(tx)
} 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(`config is fully installed`)
})